CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

porting solver from v5 to v7

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 20, 2020, 07:27
Default porting solver from v5 to v7
  #1
New Member
 
Dries van Oosten
Join Date: Nov 2017
Posts: 6
Rep Power: 9
dvoosten is on a distinguished road
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
dvoosten is offline   Reply With Quote

Old   May 20, 2020, 07:37
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   May 20, 2020, 07:42
Default
  #3
New Member
 
Dries van Oosten
Join Date: Nov 2017
Posts: 6
Rep Power: 9
dvoosten is on a distinguished road
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
dvoosten is offline   Reply With Quote

Old   May 20, 2020, 09:30
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   May 20, 2020, 10:44
Default
  #5
New Member
 
Dries van Oosten
Join Date: Nov 2017
Posts: 6
Rep Power: 9
dvoosten is on a distinguished road
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.
dvoosten is offline   Reply With Quote

Old   May 20, 2020, 11:06
Default
  #6
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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.
.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   May 20, 2020, 11:18
Default
  #7
New Member
 
Dries van Oosten
Join Date: Nov 2017
Posts: 6
Rep Power: 9
dvoosten is on a distinguished road
Ok. Thank you very much for the explanation!
dvoosten is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate library entries when running a solver with custom library francescomarra OpenFOAM Programming & Development 3 May 17, 2022 09:37
thobois class engineTopoChangerMesh error Peter_600 OpenFOAM 4 August 2, 2014 10:52
Divergence problem Smaras FLUENT 13 February 21, 2013 06:03
3d vof Smaras FLUENT 2 February 19, 2013 07:58
why the solver reject it? Anyone with experience? bearcat CFX 6 April 28, 2008 15:08


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