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

accessing dimensionedScalar from coded BC

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 15, 2021, 12:46
Default accessing dimensionedScalar from coded BC
  #1
New Member
 
Raoul
Join Date: Apr 2021
Posts: 16
Rep Power: 5
rol97 is on a distinguished road
Hi everyone,

I am currently trying to access a dimensionedScalar from the coded bc, however I am a bit stuck.

Basically I am calculating the dimensionedScalar "myVar" within the solver, to then use it in the equations as a coefficient (so the value is never modified in the routine).

I also need such value in the BC, however I cannot access it through
Code:
db().lookupObject<dimensionedScalar>("myVar");
I have also tried to create the IOobject as

Code:
dimensionedScalar myVar
(
    IOobject
    (
        "myVar",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ_IF_MODIFIED,
        IOobject::NO_WRITE
    ),
    mesh,
    dimensionedScalar("myVar", dimensionSet(0,2,0,0,0,0,0), Foam::scalar(0))
);
but it does not even compile, as no matching function is present.

Do you have any advice for me?

Thanks in advance.
rol97 is offline   Reply With Quote

Old   November 18, 2021, 06:59
Default
  #2
New Member
 
Raoul
Join Date: Apr 2021
Posts: 16
Rep Power: 5
rol97 is on a distinguished road
Ok I have figured out this solution, which works fine for me. It is probably not the best option in terms of code optimization but here it is.

In the main code of the solver I evaluate my dimensionedScalar as:

Code:
dimensionedScalar A = <expression>;
Then I create the IOdictionary coeffsDict as:

Code:
IOdictionary coeffsDict
(
    IOobject
    (
        "coeffsDict",
        runTime.constant(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    )
);
where I store the value of the coefficients with:
Code:
coeffsDict.set( "a", A.value() );
At last, in the boundary conditions I get the value stored by means of:
Code:
dimensionedScalar A_
            (
                "A_",
                dimensionSet(0,2,0,0,0,0,0),
                db().lookupObject<IOdictionary>("coeffsDict").lookup("a")
            );
And here it is.
rol97 is offline   Reply With Quote

Old   November 19, 2021, 11:47
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by rol97 View Post
Hi everyone,

I am currently trying to access a dimensionedScalar from the coded bc, however I am a bit stuck.

Basically I am calculating the dimensionedScalar "myVar" within the solver, to then use it in the equations as a coefficient (so the value is never modified in the routine).

I also need such value in the BC, however I cannot access it through
Code:
db().lookupObject<dimensionedScalar>("myVar");
I have also tried to create the IOobject as

Code:
dimensionedScalar myVar
(
    IOobject
    (
        "myVar",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ_IF_MODIFIED,
        IOobject::NO_WRITE
    ),
    mesh,
    dimensionedScalar("myVar", dimensionSet(0,2,0,0,0,0,0), Foam::scalar(0))
);
but it does not even compile, as no matching function is present.

Do you have any advice for me?

Thanks in advance.

That will not work. All registered items must derive from a regIOobject. The closest you can have would be a UniformDimensionedField.
olesen is offline   Reply With Quote

Reply

Tags
boundaryconditions, dimensionedscalar


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
accessing 0 time directory in coded functionObject JM27 OpenFOAM Programming & Development 3 May 26, 2023 17:50
Accessing transportProperties from coded functionObject Shibi OpenFOAM Programming & Development 1 April 19, 2021 16:26
coded functionObjects behaving not as expected alexfells OpenFOAM 2 October 28, 2020 04:58
accessing 0 time directory in coded functionObject JM27 OpenFOAM Post-Processing 0 November 21, 2018 09:41
dimensionedScalar not updating, stuck on initial values backscatter OpenFOAM Programming & Development 2 August 7, 2018 21:30


All times are GMT -4. The time now is 17:36.