
[Sponsors] 
July 21, 2010, 22:54 
Equation Reader released

#1 
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 15 
Hello Foamers,
I am pleased to announce the release of equationReader, an extension to OpenFOAM that allows you to use equations in a dictionary file. For instance, constant/transport properties can now be: Code:
nu [0 2 1 0 0 0 0] "3/(1+exp(0.5^2))"; For more details, please see the page on the wiki: http://openfoamwiki.net/index.php/Co...equationReader Share and enjoy! [EDIT: Sorry for the duplicate post. I thought this one had failed. Please use this thread for commenting.] Last edited by marupio; July 23, 2010 at 08:04. 

August 8, 2010, 11:59 
help me for decoding sonicFoam solver

#2 
Member

hi marupio
i am working sonicFoam solver in OpenFoam 1.6 the problem is iam unable to decode the equations in the solvers. especially p.eqn U.eqn h.eqn. if u can help me in this regard i will be thank full to you and i did not find any equation decoder from link which you have given. please help me out. 

August 8, 2010, 16:43 

#3 
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 15 
Hi kiran, thanks for the question. The equationReader extension allows OpenFOAM to read equations from a dictionary, such as transportProperties, or fvSchemes. It has nothing to do with the fvc and fvm namespaces that contain those elegant equations for the solver to work with. I was working on a few articles to explain these equations, but they are still in working form.
The equations are vector operators, so if you can find the vector or tensor forms of the equations for your solver, you'll have a better time translating them. Have a look at: http://www.openfoam.com/features/creatingsolvers.php It shows some translation. Good luck! 

June 26, 2011, 08:16 
Questions about equationReader

#4 
New Member
Caleb Miles
Join Date: Jun 2011
Posts: 13
Rep Power: 8 
Hello Marupio,
I have a few questions about equationReader. I would like to use equationReader's functionality to write a solver with some simple timedependent source terms in the momentum given by an analytical expression, like cos(a*t) where t is the current time, since the source term is a vector quantity would it be possible to add a source term of the form (A1*vector(1,0,0) + A2*vector(0,1,0) + A3*vector(0,0,1)) where A = (A1, A2, A3) is the vector I would like to add as a source term and A1, A2, A3 are defined in a dictionary. Also what is the best way to create a time dependent expression in the dictionary. Caleb 

June 26, 2011, 10:51 

#5 
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 15 
Hi Caleb,
(I was just looking through the wiki documentation, and it needs some improving!) First: adding time as a variable. I believe runTime is derived from dimensionedScalar, but I don't think you should add it directly, because its name changes at every timestep. I'd recommend something like this: Code:
eqns.addDataSource ( runTime.value(), "time", dimTime ); As for vector construction, you have the right principles... I haven't worked with the vectors much so I don't know if you have the right grammar. A1, A2 and A3 all get values from equationReader, so either they are actively updated, and you are using eqns.update(); or they are passively updated, such as: Code:
A1 = eqns.evaluate("A1"); A2 = eqns.evaluate("A2"); A3 = eqns.evaluate("A3"); Code:
// Before the solver loop, after equations are read label a1index = eqns.lookup("A1"); label a2index = eqns.lookup("A2"); label a3index = eqns.lookup("A3"); // Within solver loop A1 = eqns.evaluate(a1index); A2 = eqns.evaluate(a2index); A3 = eqns.evaluate(a3index); Code:
A1 "cos(piByTwo_ * time)"; A2 "sin(pi_ * time)"; A3 "tan(sqrt(time))"; Code:
eqns.addDataSource(myDict); eqns.readEquation(myDict, "A1"); eqns.readEquation(myDict, "A2"); eqns.readEquation(myDict, "A3"); Now, I need to update those instructions... 

June 26, 2011, 20:22 

#6 
New Member
Caleb Miles
Join Date: Jun 2011
Posts: 13
Rep Power: 8 
Hello Marupio,
Thank you for the quick reply. Just to be clear the code Code:
eqns.addDataSource( runTime.value(), "time", dimTime ); Code:
Code:
#include "IOequationReader.H" // ... IOEquationReader eqns( IOobject( "eqns", runTime.timeName(), runTime, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE // Set to NO_WRITE to suppress output ), false // set to true to show data sources in output file ); I will then add the dictionary containing my equations in the similar manner demonstrated in the demo after which I will read the equations using the syntax described above and then within the solver I will evaluate the equations? Thanks so much for your help. Caleb 

June 27, 2011, 08:05 

#7 
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 15 
That's right. Let me know if it doesn't work!


July 9, 2011, 01:30 
Position Dependent Equations

#8 
New Member
Caleb Miles
Join Date: Jun 2011
Posts: 13
Rep Power: 8 
Hello Marupio,
Thank you so much for all your previous help. I have another simple question, would this be the right way to go about implementing an equation that depends on position Code:
eqns.addDataSource( mesh.C().component(0), "x", dimLength ); Thank you so much for all of your help. Also nice changes to the wiki. Caleb 

July 9, 2011, 10:51 

#9 
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 15 
Hi caleb,
Thanks for the question. I think I should include time/space variables as default sources in future versions. Better yet, I should include vectors and tensors in the equations. When adding a data source, the one thing you have to ask yourself is: "Will that value always be at that same memory address?" Looking at your code, we have: Code:
eqns.addDataSource( mesh.C().component(0), "x", dimLength ); If your mesh isn't moving, the simple solution is to make it a permanent field, e.g.: Code:
// Before your main solver loop... perhaps in createFields.H volScalarField meshX("x", mesh.C().component(0)); eqns.addDataSource(meshX); Code:
// At the start of an iteration, just after the mesh has moved meshX = volScalarField("x", mesh.C().component(0)); 

July 9, 2011, 12:29 

#10 
New Member
Caleb Miles
Join Date: Jun 2011
Posts: 13
Rep Power: 8 
Hello Marupio,
Thanks for the help, you suggestion compiles fine. I have another related question, after using "x" in an equation, for example "cos(x)", defined in a dictionary would I then have to use "eqns.evaluateField" to evaluate the "cos(x)" equation. Caleb 

July 9, 2011, 13:05 

#11 
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 15 
Hi Caleb,
I really need to fix up the wiki documentation (haven't touched it yet)! Apparently my example for using the eqns.evaluateField() is totally wrong! Here's how you use it: Code:
// vs is a volScalarField that you want the result in eqns.evaluateField("nameOfCosXequation", vs); 

July 9, 2011, 23:59 

#12 
New Member
Caleb Miles
Join Date: Jun 2011
Posts: 13
Rep Power: 8 
Hello Marupio,
Thanks for the guidance. Do you know offhand how to define an empty volScalarField in a more elegant way than something like Code:
volScalarField Null1 = 0*mesh.C().component(0) Preferably, for readability, I would also like to avoid using an IOobject if at all possible. Caleb Last edited by calebamiles; July 10, 2011 at 01:10. 

July 10, 2011, 03:51 

#13  
New Member
Caleb Miles
Join Date: Jun 2011
Posts: 13
Rep Power: 8 
Hello Marupio,
I also have an error that perhaps you can sort out. I have a volScalarField called "bOneX" that I have initialized to all zeros. When I try Code:
eqns.evaluateField("b1X", bOneX); Quote:
Caleb 

July 10, 2011, 11:13 

#14 
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 15 
Hi Caleb,
Sorry, my bad. There's presently no evaluateField("equationName", putResultsHere) function. But there is a evaluateField(equationIndexNumber, putResultsHere) function. You can get the equationIndexNumber (which never changes once the equations are read in) using equationIndexNumber = lookup("equationName") As for the null volScalarField, you can lookup the constructors in GeometricField.H  they start at line 272. Most of them require IO objects... I think you should get used to seeing the IO object constructor. If you really don't want to see it, you could create a dummy volScalarField with the correct dimensions in createFields.H (using the full IOobject constructor), then use the renaming copy constructor in the solver body. 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Calculation of the Governing Equations  Mihail  CFX  7  September 7, 2014 06:27 
Constant velocity of the material  Sas  CFX  15  July 13, 2010 08:56 
Viscosity and the Energy Equation  Rich  Main CFD Forum  0  December 16, 2009 15:01 
mass flow in is not equal to mass flow out  saii  CFX  2  September 18, 2009 08:07 