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

Force solver to stop if dictionary is not found in functionObject

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 24, 2022, 06:46
Default Force solver to stop if dictionary is not found in functionObject
  #1
New Member
 
Join Date: Feb 2022
Posts: 25
Rep Power: 4
theBananaTrick is on a distinguished road
Hello,

I am trying to create a solver as a functionObject (FO) utility in OF2106.

As such, I am trying to read values from a IOdictionary in the constant directory.

I have modified the public inheritance of the FO to inherit publicly form the IOdictionary class.

Code:
class myFOSolver
:
    public fvMeshFunctionObject, public IOdictionary
{
Now, I need to initialize the IOdictionary part of this FO.

With "standard" initialization:

Code:
    IOdictionary
    (
        IOobject
        (
            "myPropertiesDict",
            mesh_.time().constant(),
            mesh_,
            IOobject::MUST_READ, 
            IOobject::NO_WRITE
        )
    );
The solver will just tell me that the dictionary does not exist and moves on.


I created a function to initialize the dictionary as:

Code:
Foam::IOdictionary Foam::functionObjects::myFOSolver::init()
{
 
    bool checkDict
    (
        IOobject
        (
            "myPropertiesDict",
            mesh_.time().constant(),
            mesh_,
            IOobject::MUST_READ, 
            IOobject::NO_WRITE,
            false
        ).typeHeaderOk<IOdictionary>()
    );
 
    if (!checkDict)
    {
        FatalErrorInFunction
            << "Dictionary does not exist in " << mesh_.time().constant() << "directory " << nl << nl 
            << abort(FatalError);
    }
 
    IOdictionary dict
    (
        IOobject
        (
            "myPropertiesDict",
            mesh_.time().constant(),
            mesh_,
            IOobject::MUST_READ, 
            IOobject::NO_WRITE
        )
    );
    
    return dict;
}
Is it possible to set the behavior upon construction of the IOdictionary to make the solver stop if the dictionary cannot be read? Or is initializing it throw a function the only way? If so, what is the purpose of using "MUST_READ" if it will not force the whole solver to stop?


I just get the following:


Code:
Starting time loop

--> FOAM Warning : 
cannot find file "/home/bananaTrick/Desktop/myCase/constant/myPropertiesDict

Last edited by theBananaTrick; February 24, 2022 at 13:30.
theBananaTrick is offline   Reply With Quote

Old   February 24, 2022, 15:34
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
What it actually does is surrounding the construction in a try/catch block and discards the function object out of the list is there was a problem. You can customise that for all function objects or individual ones in the functions specification.
https://www.openfoam.com/documentati...t.html#details

you have the choice of default/warn/error/strict.

So many options because everyone has a different situation, or some function objects might be critical but others just "nice to have"
theBananaTrick likes this.
olesen is offline   Reply With Quote

Old   February 24, 2022, 15:42
Default
  #3
New Member
 
Join Date: Feb 2022
Posts: 25
Rep Power: 4
theBananaTrick is on a distinguished road
Thank you for the help!

With this, I also cleared several lines of code
theBananaTrick 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
[RapidCFD] Discussion thread on how to install and use RapidCFD newoscar OpenFOAM Community Contributions 88 May 17, 2024 09:39
Running UDF with Supercomputer roi247 FLUENT 4 October 15, 2015 13:41
injection problem Mark New FLUENT 0 August 4, 2013 01:30
Regarding FoamX running Kindly help out hariya03 OpenFOAM Pre-Processing 0 April 18, 2008 04:26
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 06:51


All times are GMT -4. The time now is 05:51.