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

URF ramp function object

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 25, 2020, 21:53
Default URF ramp function object
  #1
Senior Member
 
Join Date: Nov 2010
Location: USA
Posts: 1,232
Rep Power: 24
me3840 is on a distinguished road
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;
    #};
}
it seems while the runTime object exists in the solver (simpleFoam.C) the function objects aren't getting a reference to it, as during the run I get:
Code:
functionObjectTemplate.C:147:26: error: ‘runTime’ was not declared in this scope
         const scalar t = runTime.time().value();
I've tried various formulations of:
Code:
obr_.lookupObject<Time>("runTime")
but that doesn't seem to work?

Can anyone give me some tips to get going?
me3840 is offline   Reply With Quote

Old   February 26, 2020, 01:31
Default
  #2
Senior Member
 
Yogesh Bapat
Join Date: Oct 2010
Posts: 102
Rep Power: 15
ybapat is on a distinguished road
Try using mesh.time() which returns time object reference. You can check fvMesh.H.
ybapat is offline   Reply With Quote

Old   February 29, 2020, 11:48
Default
  #3
Senior Member
 
Join Date: Nov 2010
Location: USA
Posts: 1,232
Rep Power: 24
me3840 is on a distinguished road
Brilliant, that works. Thank you. Now I need to figure some things out on actually updating the URF value. More to come I suppose.
me3840 is offline   Reply With Quote

Old   February 29, 2020, 16:00
Default
  #4
Senior Member
 
Join Date: Nov 2010
Location: USA
Posts: 1,232
Rep Power: 24
me3840 is on a distinguished road
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);
However I get the error:


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?
me3840 is offline   Reply With Quote

Old   March 8, 2020, 09:57
Default
  #5
Senior Member
 
Join Date: Nov 2010
Location: USA
Posts: 1,232
Rep Power: 24
me3840 is on a distinguished road
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.
me3840 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
[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


All times are GMT -4. The time now is 21:07.