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/)
-   -   Read in Formula via Dictionary (https://www.cfd-online.com/Forums/openfoam-programming-development/165682-read-formula-via-dictionary.html)

hxaxtma January 23, 2016 07:43

Read in Formula via Dictionary
 
Hi guys,

quick question, I created an own Dict and reading in a formular via
Code:

word    cd(word(sensorDict.subDict("solving").lookup("cd")));
where cd is defined in the dict as:
Code:

cd            "1+10*Foam::exp(Re,0.66666667)";
Next I want to use this relation in my main loop, so I need to convert this word string to what exactly?

Thanks for help

hxaxtma January 25, 2016 03:28

Hi, I tried with
Code:

#include <cstdlib>
scalar cd_form=atof(cd.c_str());

Code is now compiling and it is printing the formula as string, but not using it as mathematical operator.

Any ideas?

chriss85 January 25, 2016 03:29

This means you will need to have a parser/interpreter. I'm not sure if there is one in OpenFOAM, yiou might have some luck with swak4Foam though.

marupio January 27, 2016 11:47

I think you might want equationReader.

swak4Foam could be suitable, but if you want to parse a user-entered equation and use it at your discretion within your application, then that is exactly what equationReader was intended for. Be careful, though... any interpreted equations will take longer to evaluate than hard-coded equations.


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