|
[Sponsors] |
June 27, 2016, 18:39 |
How to solve nonlinear equation.
|
#1 |
New Member
Charles
Join Date: Jun 2016
Posts: 2
Rep Power: 0 |
Hi Foamers,
I'm trying to solve a modified Poisson's equation that has an exponential term. The equation looks like this: fvm::laplacian(V) = exp(V) + exp(-V) + constant. From what I understand, the exp terms are actually explicit terms and are not being treated implicitly. Is there anyway to treat the exponential terms implicitly? Thanks! |
|
June 28, 2016, 08:35 |
|
#2 | |
Senior Member
Hesam
Join Date: Feb 2015
Posts: 139
Rep Power: 11 |
Quote:
I think you can use polynomial estimation of this functions and extract V from it for implicit solution. |
||
June 28, 2016, 19:30 |
|
#3 |
New Member
Charles
Join Date: Jun 2016
Posts: 2
Rep Power: 0 |
Is there any way to avoid a polynomial approximation?
I'm expecting the exponential to vary from 10^3 to 10^7, so I don't expect polynomial approximations to be accurate. On a side note, I'm not sure how to code in an implicit squared term. As far as I know, only linear terms can be implicit. Do you know of a way to code in an implicit, nonlinear term? |
|
July 3, 2016, 18:52 |
|
#4 | |
Member
Bruno Blais
Join Date: Sep 2013
Location: Canada
Posts: 64
Rep Power: 13 |
Hello,
You will need to use sub-cycling and solve the equation iteratively until it converges. What you could do is start with an approximation or use a relaxation method. i.e : - Start with an estimate of V - Calculate V(i+1) - Relax V(i+1) Recalculate V etc. Quote:
|
||
September 24, 2016, 18:00 |
|
#5 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Hey Bruno
Can u describe a little bit your cycle: HTML Code:
- Start with an estimate of V- Calculate V(i+1)- Relax V(i+1)Recalculate V I have used the following snippet for solving it: Code:
solve ( fvm::laplacian(phi) == beta * sinh(phi) ); Code:
fvScalarMatrix phiEqn ( fvm::laplacian(phi) - beta * sinh(phi) ); phiEqn.relax(); phiEqn.solve(); Code:
relaxationFactors { equations { phi 0.3; phiFinal 1; } } Regards Last edited by babakflame; September 27, 2016 at 13:14. |
|
September 25, 2016, 16:22 |
|
#6 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hi Bobi,
I am not sure but I think that Bruno means exactly what you describe with - lets say - 500 outer loops. You go out of the loops if the residual is reached (your solution is converged for that time step). After that, go on in time and to the same procedure.
__________________
Keep foaming, Tobias Holzmann |
|
September 25, 2016, 16:37 |
|
#7 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Hey Tobi,
Thanks for your reply. I am thinking of using previous iterations for the right hand side of the equation : Code:
solve ( fvm::laplacian(phi) == beta * sinh(phi) ); http://www.cfd-online.com/Forums/ope...tml#post619187 I used Code:
fieldName.oldTime() Code:
fieldName.storePrevIter(); fieldName.prevIter() |
|
September 25, 2016, 17:01 |
|
#8 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hi Bobi,
if you first solve your equation and relax your quantity, than you do not relax the equation, you relax the field. It is different. I can not tell you in a accurate way (because I never jumped into that area and only have some feeling) but for example, we do not relax the pressure equation. We relax the field. I think there is somehow a physical meaning behind, that I can not tell you. By the way. The equation: Code:
fvm::laplacian(V) = sinh(V) If you want to solve this equation explicit you have do to it like: Code:
fvc::laplacian(V) = sinh(V) Code:
fvc::div(fvc::grad(V)) = sinh(V) You can have a look into my Gray-Scott-Foam ... Here I solved explicit and implicit and if I remember correct, I had to use the function there.
__________________
Keep foaming, Tobias Holzmann |
|
September 25, 2016, 23:11 |
|
#9 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Dear Tobi
Many thanks for your reply. I think you are completely correct. The following snippet: Code:
solve ( fvm::laplacian(phi) == beta * sinh(phi) ); in which is the iteration number. Since, I replaced the right hand side of above equation with Code:
phi.prevIter() So I assume that when using explicit terms in iterative methods, its always previous iteration values (It should be, since Implicit matrix of coeffiecients should assume them as known values). I looked into this thread written by u regarding Gray-Scott Foam: http://www.cfd-online.com/Forums/ope...ott-model.html However, It seems that the links in your post didn't lead me to your solver. It says its under construction. BTW, the fully explicit method: Code:
solve ( fvc::laplacian(phi) == beta * sinh(phi) ); I have searched OpenFoam forum and found out that the only way that exponential term can be written implicitly is: Code:
solve ( fvm::laplacian(phi) == fvm::Sp(beta * sinh(phi) / phi, phi) ); I am still interested to make the right hand side more implicit. Pickard's method (http://www.cfd-online.com/Wiki/Sourc..._linearization) or adding a term to both sides :http://www.cfd-online.com/Forums/openfoam-programming-development/176413-source-term-modification-poisson-equation-does-not-affect-results-2.html#post619187 are possible thoughts. Finally, please check the provided link to your valuable Gray-Scott model. Regards Last edited by babakflame; September 26, 2016 at 01:03. |
|
September 26, 2016, 03:01 |
|
#10 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hi ,
my Homepage is not available at the moment. I am doing some stuff. Today it will be available again. I think in a few hours. To the stuff of non-linear terms... I think your solution is not correct. Non-linear terms like: can be treated fully explicit (the easiest way) like: Code:
== V * V //- Explicit | old time Code:
== fvm::Sp(V, V)
__________________
Keep foaming, Tobias Holzmann |
|
September 26, 2016, 09:05 |
|
#11 | |
Member
Bruno Blais
Join Date: Sep 2013
Location: Canada
Posts: 64
Rep Power: 13 |
The formulation you mentioned, that is :
Code:
solve ( fvm::laplacian(phi) == fvm::Sp(beta * sinh(phi) / phi, phi) ); What you need to do is relax your equation a lot more than by 0.3. Lets say you are solving : Code:
solve ( fvm::laplacian(phi) == beta*sinh(phi) ); Another thing you could try to do is to first solve the equation with the Taylor expansion of the source partially implicitely in order to get a good estimate and then solve the full equation with the right member explicit. Another way could be to solve transient version of this equation, which is an indirect way or relaxing the way you solve the equation. Quote:
|
||
September 26, 2016, 22:54 |
|
#12 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Hey,
@ Tobi Many thanks for the discussion Tobi. HTML Code:
I think your solution is not correct. Code:
solve ( fvm::laplacian(phi) == fvm::Sp(beta * sinh(phi) / phi, phi) ); by myself too, since it is highly unstable. What I did up to now as a modification for the primary equation in previous posts is using this modifications to my fvSolution file: Code:
phi { solver smoothSolver; smoother GaussSeidel; preconditioner DIC; tolerance 1e-11; relTol 0.2; } Code:
solve ( fvm::laplacian(phi) == beta * sinh(phi) // fvm::laplacian(phi) - beta * (phi + (1/6)*pow(phi,3) + (1/120)*pow(phi,5) + (1/362880)*pow(phi,9) + (1/39916800)*pow(phi,11)) ); BTW, I am gonna take a look at the your Gray-Scott model soon @ Bruno Thanks bruno for your comments. As I mentioned above, I figured it out that the Code:
solve ( fvm::laplacian(phi) == fvm::Sp(beta * sinh(phi) / phi, phi) ); All in all, Thanks for discussions. Regards |
|
October 1, 2016, 17:31 |
|
#13 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
Hey Tobi,
I looked at your solver, It seems that you had a non-linear term in your equation, however, I couldn't find the source code. When I click on the link, it directs me to the following link: https://bitbucket.org/shor-ty/flameletmodel Which I assume is the solver both of us were using before. @ Bruno Still can not get your idea for looping. If you can make it coded, could be judged better, Otherwise just an idea HTML Code:
You will need a very low relaxation factor if beta is large. Something like 1e-2, 1e-3 or even less. HTML Code:
Another thing you could try to do is to first solve the equation with the Taylor expansion of the source partially implicitely in order to get a good estimate and then solve the full equation with the right member explicit. Another way could be to solve transient version of this equation, which is an indirect way or relaxing the way you solve the equation. However, on the contrary to Bruno post, OpenFoam does have a solver capable of handling stiff non-linear equations: Code:
solver smoothSolver; smoother GaussSeidel; preconditioner DIC; tolerance 1e-11; relTol 0.2; |
|
October 3, 2016, 09:18 |
|
#14 | |
Member
Bruno Blais
Join Date: Sep 2013
Location: Canada
Posts: 64
Rep Power: 13 |
I think a little bit more manners would be appreciated in your answer.
First, Code:
solver smoothSolver; smoother GaussSeidel; preconditioner DIC; tolerance 1e-11; relTol 0.2; If you wish to obtain a solution to a non-linear system, you need to use an iterative process such as Newton's method (2nd order convergence rate, more sensitive to initial conditions ) or using Picard's method (slower convergence). For Newton method you can use an explicit version of the jacobian (that is, you know the equation of the jacobian and you write it down) or a numerical version of it (which is akin to a secant method) HTML Code:
The relaxation factor u propose is somehow illogical, since increases the time of simulation 100 times. As for the code to the loop, it is identical to using relaxation, with a while loop around the relaxation to check for convergence. Regards, BB Quote:
|
||
October 3, 2016, 13:19 |
|
#15 |
Senior Member
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16 |
@ Bruno
I believe that general CFD ideas might be more helpful in the following forum: http://www.cfd-online.com/Forums/main/ You can easily share your ideas there. In this forum, when I want to give some hints to people, I prefer to do it with samples, since people might have problems in the coding way not necessarily general CFD ideas. HTML Code:
Still can not get your idea for looping. If you can make it coded, could be judged better Anyway, I don't want to continue this, good luck with your ideas. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Solve a non-differential equation | agustinvo | OpenFOAM Programming & Development | 3 | January 18, 2016 10:22 |
Calculation of the Governing Equations | Mihail | CFX | 7 | September 7, 2014 07:27 |
solve only transport equation and not Navier-Stokes | cosine | CFX | 2 | November 19, 2011 03:58 |
stability and nonlinear equation. | bnedse | Main CFD Forum | 3 | March 2, 2004 13:23 |
Qeustion: to solve nonlinear ODE | Peter | Main CFD Forum | 1 | April 1, 2003 06:47 |