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/)
-   -   A trial of implementing of CVODE as ODESolver (https://www.cfd-online.com/Forums/openfoam-programming-development/97196-trial-implementing-cvode-odesolver.html)

Aleksey_R February 11, 2012 05:06

A trial of implementing of CVODE as ODESolver
 
1 Attachment(s)
Greetings, dear colleagues.

I tried to implement CVODE solver (from sundials-2.3) as ODESolver in OF-1.6-ext. In CVODE I used backward differencing (BDF). The library compiled successfully but when I try to compile some chemistry solver with BDF support I have an error on linking stage (undefined reference to ODESolver constructor).

I post the code just in case. If someone will handle with the error, I hope, the library could be useful for community.


Best regards, Aleksey.

adhiraj February 11, 2012 16:52

I have incorporated the CVODE stiff ODE solver into the ODESolvers in OpenFOAM 1.7, and it is very similar to your code. (It is based on the sample provided with sundials).
I think you are trying to make the BDF a library separate from the ODE library.
Why is this?
Why don't you add the BDF stuff to the ODESolvers directory,(similar to say RK4, so that under ODESolvers we have ODESolvers, RK,KRR4,SIBS and BDF) as it is based on ODESolver?
Then just edit the file named "files" and add the file $FOAM_SRC/ODE/ODESolvers/BDF/BDF.C" ?

Aleksey_R February 11, 2012 17:30

I tried to copy BDF to ODESolvers folder (which contains KRR4, SIBS, RK) and I've got the same result - the library libODE compiled successfully but when I tried to compile any solver I got an error on linking stage.

adhiraj February 11, 2012 19:48

Try putting the BDF under the ODESolvers directory, and remove the Make directory under BDF.
Edit the Make directory of ODE to add entries for BDF.
This means that there will only be one library built, and that will have SIBS+RK+BDF+KRR4, all selectable at runtime.

Aleksey_R February 12, 2012 08:17

Thank you for advise. I did it. And the compilation of libODE was successful, but the compilation of solvers wasn't. The same error on linking stage - undefined reference to ODESolver constructor.

Anyway, I managed to use CVODE in OpenFoam without using ODESolver.

Best regards, Aleksey.

adhiraj February 12, 2012 10:50

I am a bit confused now; what solver are you trying to build? Did you specify the libODE for each solver's Make directory?

jurich February 14, 2012 17:12

Aleksey,

I've been looking into implementing CVODE or LSODE in OF 2.0.x, and came across your post. In yours, the line in BDF.C:

f_data = new BDF(*this);

tries to implement BDF using a copy constructor, which you didn't implement. That should be why the linker complains "undefined reference to ODESolver constructor" when you try to build an application.

I think you should just be able to use:

f_data = this;

to get it working, but haven't tried it (I'm not running 1.6ext at the moment).

Also, I hope you're aware of alternateChemistryModel, which implements Cantera and sundials/cvode? If not, it might be worth looking for.

Regards.

adhiraj February 14, 2012 17:43

Quote:

Originally Posted by jurich (Post 344441)
Aleksey,

I've been looking into implementing CVODE or LSODE in OF 2.0.x, and came across your post. In yours, the line in BDF.C:

f_data = new BDF(*this);

tries to implement BDF using a copy constructor, which you didn't implement. That should be why the linker complains "undefined reference to ODESolver constructor" when you try to build an application.

I think you should just be able to use:

f_data = this;

to get it working, but haven't tried it (I'm not running 1.6ext at the moment).

Also, I hope you're aware of alternateChemistryModel, which implements Cantera and sundials/cvode? If not, it might be worth looking for.

Regards.

I am not sure of this. I have the same kind of new statement in my implementation and I get no errors, and the results also seem good.
Also, the error is about the ODESolver constructor, not the BDF constructor.

luiscardona April 14, 2012 03:59

1 Attachment(s)
Dear foamers,

After many failed attempts, I finally managed to implement BDF (CVODE solver) in OF-1.7.1 selectable at runTime like SIBS, RK and KRR4 based on the code posted before by Aleksey_R.

In order to use it please take into account that in the chemistryProperties dictionary in constant folder, you must set the inverse of eps (for example 20 for a eps of 0.05) so in ODESolver.C file the whole time step can be sent to CVODE solver. This happens because CVODE has its own way to calculate internal time step, so OpenFOAM time stepping routine must be overridden somehow. It is probably not the best way to achieve it... but it works!

In order to install this library just merge the content of the attached file the src/ODE folder and recompile using wmake libso. It is known to work with sundials 2.3.0 (the instructions about compiling sundials can be easily found in the forum)- In my case, I installed sundials on home folder-

Please try the solver and make your own tests (for example running ODETest app). So far in my tests, SIBS seems to be faster for my problem (chemical kinetics). Also if you can make a better-cleaner version of this solver, you can upload it and share it back with the community.

adhiraj April 14, 2012 09:37

Quote:

In order to use it please take into account that in the chemistryProperties dictionary in constant folder, you must set the inverse of eps (for example 20 for a eps of 0.05) so in ODESolver.C file the whole time step can be sent to CVODE solver. This happens because CVODE has its own way to calculate internal time step, so OpenFOAM time stepping routine must be overridden somehow.
I override that by specifying the initial chemical time scale as unity in the chemistryProperties file.
Quote:

So far in my tests, SIBS seems to be faster for my problem (chemical kinetics)
That is consistent with my observations. But for some problems SIBS crashes while solving the ODE.

JBUNSW February 27, 2014 06:00

Dear all,

I implemented SUNDIALS CVODE 2.7 in OpenFOAM 2.0.x. I pretty much followed the instructions given at this thread. However, my implementation is very slow when I use the built-in numerical jacobian feature of CVODE. I have explained the details here.

Any help is highly appreciated.

Jalal

JBUNSW March 6, 2014 20:53

Any help is highly appreciated.


All times are GMT -4. The time now is 02:32.