CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   porting solver from v5 to v7 (https://www.cfd-online.com/Forums/openfoam-programming-development/227182-porting-solver-v5-v7.html)

dvoosten May 20, 2020 06:27

porting solver from v5 to v7
 
Hi everyone,



some time ago, I wrote a solver for OpenFOAM 5, which I now need to port to version 7. My problem is that the mesh.solver() method no longer exists version 7. I am thus stuck with this bit of code:

Code:

        // corrector for Yi
        solve
        (
            fvm::ddt(rho,Yi) - fvc::ddt(rho,Yi)
            +  fvm::div(phi,Yi) - fvc::div(phi,Yi),
            mesh.solver("Yi")
        );

To fix this, I tried changing it too:

Code:

        // corrector for Yi
        fvScalarMatrix YiEqn
        (
            fvm::ddt(rho,Yi) - fvc::ddt(rho,Yi)
            +  fvm::div(phi,Yi) - fvc::div(phi,Yi)
        );
        YiEqn.solve();

which does compile and run, but the simulation quickly fails with large negative temperatures. This probably means that the code I have now is in fact not doing what the old code did in v5. Can anybody help me with this?


best,
Dries

Tobi May 20, 2020 06:37

Dear Dries,

both codes are equal. The part mesh.solver("Yi"), just told FOAM which linear solver to use, here, the "Yi" dictionary is searched in the fvSolutions and these settings are applied. Both codes of you are identical in terms of equations. The difference is:
  • The first one constructs the matrix (temporary object) and solves it directly
  • The second one constructs an object of fvScalarMatrix (not temporary) and afterward solve the equation by explicitly telling object.solve()

However, I donīt get the idea of the equation? Implicit part - explicit part? Is this a numerical trick?

Both are equal.

dvoosten May 20, 2020 06:42

Dear Tobias,


thanks for your quick explanation. In that case, I will have to dig deeper to find out why the simulation is failing.


best,
Dries

Tobi May 20, 2020 08:30

Hi, I updated my previous message to improve quality and my english. Just one more comment.
You should be able to use your previous code still (https://cpp.openfoam.org/v6/namespac...0126875aa319):

Code:


const dictionary yourDict = ...; // Access to your dictionary --> mesh.solver("Yi")

// corrector for Yi
solve
(
    fvm::ddt(rho,Yi) - fvc::ddt(rho,Yi)
  + fvm::div(phi,Yi) - fvc::div(phi,Yi),
    yourDict
);

This should be similar to
Code:

solve
(
    fvm::ddt(rho,Yi) - fvc::ddt(rho,Yi)
  + fvm::div(phi,Yi) - fvc::div(phi,Yi),
    mesh.solver("Yi")
);

So it should work and must work according to the c++ doxygen source guide. However, maybe you have the latest dev line. Here things might be different.
Additionally, it would be good to know your compilation error. Nevertheless, both calculations are equal.

dvoosten May 20, 2020 09:44

If I understand your last suggestion correctly, this means that the mesh.solver() method if just the code that reads the dictionary in fvSolutions to find out what type of solver the user has specified.

Tobi May 20, 2020 10:06

Correct, if I got you right. The method solver() is a function that you apply onto the object named 'mesh'. This object is of type 'fvMesh' which includes the public derivative to the 'solutions' class in which the function solver() is defined.

This function returns a dictionary. The dictionary which is returned is based on the argument you provide. To be more precisely, the function is actually defined as 'solver(const word)'. What it does is to return the dictionary you set in the fvSolutions related to the word you set.

E.g., mesh.solver("h") will return the linear solver settings specified within the dictionary 'h' in the fvSolutions file. If there is no dict specified, you get an error.
.

dvoosten May 20, 2020 10:18

Ok. Thank you very much for the explanation!


All times are GMT -4. The time now is 00:10.