|
[Sponsors] |
February 25, 2020, 21:53 |
URF ramp function object
|
#1 |
Senior Member
Join Date: Nov 2010
Location: USA
Posts: 1,232
Rep Power: 24 |
Hello all,
I am not that knowledgeable in deep OF programming, but am trying to learn. The 'simple' task I wanted to see if I could manage would be to create a URF ramp in time. This would of course be used in a steady-state simulation. The idea is the simulation would start with very low URFs for 10 iterations or so, then ramp rapidly to a final value 10-20 iterations later. I appears the URFs can only be controlled by modifying the dictionary in which they are stored and not set explicitly. At least, that's what I gather from solution.C. But I'll get to that eventually. To start off I am looking at making a function object which can just print the current time and perhaps do some calculation/logic with its value, but I'm not getting very far: Code:
updateURFs { libs ("libutilityFunctionObjects.so"); type coded; name updateURFs; codeWrite #{ Info << "running" << endl; const scalar t = runTime.time().value(); Info << t << endl; #}; } Code:
functionObjectTemplate.C:147:26: error: ‘runTime’ was not declared in this scope const scalar t = runTime.time().value(); Code:
obr_.lookupObject<Time>("runTime") Can anyone give me some tips to get going? |
|
February 26, 2020, 01:31 |
|
#2 |
Senior Member
Yogesh Bapat
Join Date: Oct 2010
Posts: 102
Rep Power: 15 |
Try using mesh.time() which returns time object reference. You can check fvMesh.H.
|
|
February 29, 2020, 11:48 |
|
#3 |
Senior Member
Join Date: Nov 2010
Location: USA
Posts: 1,232
Rep Power: 24 |
Brilliant, that works. Thank you. Now I need to figure some things out on actually updating the URF value. More to come I suppose.
|
|
February 29, 2020, 16:00 |
|
#4 |
Senior Member
Join Date: Nov 2010
Location: USA
Posts: 1,232
Rep Power: 24 |
Okay, so I've gotten a bit farther, but have a snag I don't understand fully.
I added to solution.C: Code:
void Foam::solution::updateEquationRelaxationFactor(const word& name, const scalar& value) { DebugInfo << "Updating equation relaxation factor for " << name << endl; if (eqnRelaxDict_.found(name)) { eqnRelaxDict_.add(name, value, true); } FatalIOErrorInFunction(eqnRelaxDict_) << "Cannot find equation relaxation factor for '" << name << "' or a suitable default value." << exit(FatalIOError); return; } and the associated declaration in solution.H, and that compiles fine. I can now call that from my functionObject with: Code:
mesh().updateEquationRelaxationFactor(eqName, value); Code:
functionObjectTemplate.C: In member function ‘virtual bool Foam::updateURFsFunctionObject::write()’: functionObjectTemplate.C:164:60: error: passing ‘const Foam::fvMesh’ as ‘this’ argument discards qualifiers [-fpermissive] mesh().updateEquationRelaxationFactor(eqName, value); Is this because the mesh() object is declared constant? This would certainly put a halt to my entire operation. However it seems that can't be true, as one can change the URF by writing to the fvSolution file as long as the dictionary update is allowed. Any hints? |
|
March 8, 2020, 09:57 |
|
#5 |
Senior Member
Join Date: Nov 2010
Location: USA
Posts: 1,232
Rep Power: 24 |
I was finally able to solve this. The mesh() object is not declared as constant, but at some point to the function object it was passed as const.
To remove this I perform a const_cast to a new reference to the mesh object. Then calling updateEquationRelaxationFactor() on that new reference works fine. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] refineWallLayer Error | Yuby | OpenFOAM Meshing & Mesh Conversion | 2 | November 11, 2021 11:04 |
foamToTecplot360 | thomasduerr | OpenFOAM Post-Processing | 121 | June 11, 2021 10:05 |
How to create a function object in OpenFoam that runs properly ? | mkhm | OpenFOAM Programming & Development | 1 | October 20, 2018 16:16 |
[blockMesh] Errors during blockMesh meshing | Madeleine P. Vincent | OpenFOAM Meshing & Mesh Conversion | 51 | May 30, 2016 10:51 |
[blockMesh] Axisymmetrical mesh | Rasmus Gjesing (Gjesing) | OpenFOAM Meshing & Mesh Conversion | 10 | April 2, 2007 14:00 |