CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Writing Solvers (https://www.cfd-online.com/Forums/openfoam-solving/58263-writing-solvers.html)

bigphil November 11, 2008 06:16

Hi, I am new to OpenFOAM an
 
Hi,

I am new to OpenFOAM and I have gone through quite a few of the tutorial, but I would like to know is there anywhere I can find out about how to write a solver.

Any suggestions would be appreciated.

villet November 11, 2008 07:44

Here's a good start: http:/
 
Here's a good start:

http://openfoamwiki.net/index.php/Ho...ure_to_icoFoam

alex November 19, 2008 12:16

Hi Ville, What about after
 
Hi Ville,

What about after that? Looks like there are more questions than answers...
Any ideas?

Thanks,

Alex.

villet November 19, 2008 14:09

Hi Alex, depends what you w
 
Hi Alex,

depends what you want to do http://www.cfd-online.com/OpenFOAM_D...part/happy.gif For me the existing solvers and utilities are just examples. They use the OpenFOAM core libraries to read, solve and write stuff.

I know that getting deep into OpenFOAM takes time. Browse the existing code "examples", read the programmer's guide and make your own modifications http://www.cfd-online.com/OpenFOAM_D...part/happy.gif

Ville

alex November 19, 2008 15:08

yeah, that's how I feel... it'
 
yeah, that's how I feel... it's gonna be long and time consuming (but, hopefully, fun). I just wish there was a tutorial like "Let's make a solver for such and such problem using OpenFOAM libraries". But, since it's an open project, nobody wants to do it for free... arr

Alex

alex November 25, 2008 12:11

Hi Ville! I am not a CFD pe
 
Hi Ville!

I am not a CFD person, but I have become interested in using OpenFOAM in my research work (I am in the field of electrochemistry). I have gone through some tutorials and I think I have a general understanding how the program works. To start with a simple problem, I would like to use OpenFOAM to solve Fick's second law of diffusion, which has the form dC/dt = D*laplacian(C) (where C is the concentration and D is the diffusion coefficient of the species). Is there a standard solver available for such type of a problem, or would I have to create my own? Would laplacianFoam be appropriate? I hope you could help me since nobody seems to answer my questions...

Thank you very much!

Alex.

mathieu November 25, 2008 13:35

Hi Alex, laplacianFoam solv
 
Hi Alex,

laplacianFoam solves the following equation:

dT/dt = laplacian(DT,T)
= DT*laplacian(T) (when DT is constant)

To answer your question, I think laplacianFoam is VERY appropriate for your problem. If you use the solver directly, you'll have to make an analogy between the temperature T and the concentration C by doing some dimensional analysis (same thing for the diffusion coefficients...). Hope this helps,

Mathieu

alex November 25, 2008 16:59

Thank you Mathieu, I think thi
 
Thank you Mathieu, I think this is the right direction. I appreciate it!

alex November 28, 2008 15:03

Hi, I managed to make OpenF
 
Hi,

I managed to make OpenFoam solve a simple PDE dC/dt=laplacian(D, C) by modifying laplacianFoam. But now I am looking to solve a more difficult equation:

dC(x,y,t)/dt = laplacian(D, C)+(D/x)*(dC/dx).

Can someone give me a clue how could I modify laplacianFoam to incorporate this extra term?

Thank you,

Alex.

shah November 28, 2008 15:50

Hi, I am new to OpenFOAM a
 
Hi,

I am new to OpenFOAM and I have gone through user guide, but I want to implement Matrix-Vector multiplication (I have c++ code) in OpenFOAM. I would be grateful if somebody can help me or If someone has already implemented some algorithms in OpenFoam then I would like to request that implementation.
Any suggestions would be appreciated.
Thanks,
Shah

mathieu November 29, 2008 01:03

Hi Alex, This is what I wou
 
Hi Alex,

This is what I would try:

vector oneX(1,0,0);
volScalarField x = oneX & mesh.C();

do untill convergence
{
solve
(
fvm::ddt(C) = fvm::laplacian(D, C)+(D/x)*(oneX & fvc::grad(C))
)
}

Regards,

Mathieu

mathieu December 1, 2008 15:08

Sorry, I wrote "do until conve
 
Sorry, I wrote "do until convergence" for simplicity (pseudo code). The "do while" is clearly what you need here. To be more specific:

int iCorr = 0;
scalar initialResidual = 0;

do
{
fvVectorMatrix Eqn
(
fvm::ddt(C) = fvm::laplacian(D, C)+(D/x)*(oneX & fvc::grad(C))
);

initialResidual = Eqn.solve().initialResidual();


}
while (initialResidual > convergenceTolerance && ++iCorr < nCorr);


This is very similar to the procedure in the solver solidDisplacementFoam... The "convergence" loop is used to update the explicit term (fvc::grad(C)) at each iteration. Good luck !

Mathieu

mathieu December 1, 2008 20:28

For the readSolidDisplacementF
 
For the readSolidDisplacementFoamControls.H file, try the tutorial of solidDisplacementFoam and you should understand it (there are also some explanations in the user guide, in the tutorial section). The parameters are read in the fvSolution file. For the "void expression" error, try to isolate the problem by removing terms from the equation... it may have something to do with the (D/x)*(oneX & fvc::grad(C)) term but I can't say for sure... By the way, I think you should remove the "for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) " loop.

Mathieu

shinigamirem May 16, 2020 04:52

Hey Alex, i am trying to do the same as you did and i wanted to ask you, how you managed to modify the laplacian foam to solve Fick's second law?
I am trying to modify, but somehow it won't work :/
I tried to change the temperature to the concentration where i could find it as well i was going through the tutorial before on how to change a solver posted by villet.
I hope someone will read this as it was quite some time ago.


All times are GMT -4. The time now is 05:59.