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

Assessing a variable from one custom lib to anther

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 24, 2022, 00:53
Default Assessing a variable from one custom lib to anther
  #1
Senior Member
 
TWB
Join Date: Mar 2009
Posts: 414
Rep Power: 19
quarkz is on a distinguished road
Hi,

I have a custom lib for the mesh rotation. In the lib, there's an "angle" variable which changes with time.

I have another lib which requires this "angle" variable. Currently, I'm outputting it to a file and the 2nd lib which read from this file.

However, I feel that it is not efficient and necessary. Is it possible for the 2nd lib to read the "angle" variable from the 1st lib?

I searched thru the forum but didn't find what I need exactly, although there's some info.

I have tried to add the 1st lib into the options inside the Make dir of the 2nd lib. But then how do I call its variables?

Thanks in advance.
quarkz is offline   Reply With Quote

Old   June 24, 2022, 08:10
Default
  #2
New Member
 
Pere
Join Date: Mar 2022
Location: Mallorca
Posts: 16
Rep Power: 4
katiuskas is on a distinguished road
Hello there! I have recently faced the same exact issue. I solved it based on this post. In a nutshell, you need to create a IOdictionary to transfer info between classes. You can also take a look at my post to see my particular implementation.

Best of luck with your project!
katiuskas is offline   Reply With Quote

Old   June 25, 2022, 10:37
Default
  #3
Senior Member
 
TWB
Join Date: Mar 2009
Posts: 414
Rep Power: 19
quarkz is on a distinguished road
Hi katiuskas,

thanks for the solution. I will take a close look and try to implement it.

Btw, is the IOdictionary something like an internal variable storage space? Or is it an actual file used for output and input?
quarkz is offline   Reply With Quote

Old   June 25, 2022, 10:47
Default
  #4
New Member
 
Pere
Join Date: Mar 2022
Location: Mallorca
Posts: 16
Rep Power: 4
katiuskas is on a distinguished road
Quote:
Originally Posted by quarkz View Post
Hi katiuskas,

thanks for the solution. I will take a close look and try to implement it.

Btw, is the IOdictionary something like an internal variable storage space? Or is it an actual file used for output and input?
Hello quarkz,

I'm quite new to IOobjects. The IOobject class and objectRegistry wiki entries are a good place to start. For a more comprehensive (but shorter) explanation, this post also helped me. From my current understanding, IOdictionaries are part of an hierarchical database called objectRegistry, which allows standardized input/output. Answering your original question, these input-output operations could be made through external files, though it is not mandatory (OpenFOAM just handles it internally). In my example, I do not write the data into any external file.

Hope this helps.
katiuskas is offline   Reply With Quote

Old   June 27, 2022, 05:39
Default
  #5
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Don't be completely mislead from the name regIOobject. While this is largely used from IO of objects (like the name suggests), you can also tag the objects as NO_READ and NO_WRITE, which means that they will not normally be written at all.


You can think of the objectRegistry to be something like a large database that either holds ("registers") references to various objects, or can also "own" the objects (ie, is responsible for their storage). Provided your class derives from regIOobject, it is a candidate for registering into the objectRegistry. This allows various types of objects (eg, an IOdictionary, volScalarField, volVectorField) all to be stored or registered on the objectRegistry, since they all have the same common regIOobject base class, even although they store completely different types of data.


If your model is registered on the objectRegistry (in many places making it a MeshObject is the easier) you will be able to lookup by name/type elsewhere in the code (thus pretending it is a global variable).


Lots of places in OpenFOAM using this, you will not need to dig very far.
olesen is offline   Reply With Quote

Old   June 28, 2022, 03:21
Default
  #6
Senior Member
 
TWB
Join Date: Mar 2009
Posts: 414
Rep Power: 19
quarkz is on a distinguished road
Hi katiuskas,

I tried to the 1st part of your code:

Code:
void Foam::sixDoFRigidBodyMotion::createDict()
...
into my code.

However, I'm not sure where to add in. Given my poor c++ knowledge, I tried to add in to the constructor location but I kept getting errors. My constructor part is:

Code:
Foam::solidBodyMotionFunctions::rotatingMotion_1dof_pitch_newmark2::rotatingMotion_1dof_pitch_newmark2
(
    const dictionary& SBMFCoeffs,
    const Time& runTime
)
:
    rhoInf_(SBMFCoeffs_.getOrDefault<scalar>("rhoInf", 1.0)),

    ...
    rhoName_(SBMFCoeffs.lookupOrDefault<word>("rho", "rho")),

    )
    
{
    read(SBMFCoeffs);

}
So where should I add your part in?

Thanks.
quarkz 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
How to limit a variable ash OpenFOAM Running, Solving & CFD 1 June 26, 2008 21:32
error in COMSOL:'ERROR:6164 Duplicate Variable' bhushas COMSOL 1 May 30, 2008 05:35
Problems with additional variable Krishna Premi CFX 1 October 29, 2007 09:19
Env variable not set gruber2 OpenFOAM Installation 5 December 30, 2005 05:27
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 21:09


All times are GMT -4. The time now is 03:28.