|
[Sponsors] |
Assessing a variable from one custom lib to anther |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
June 24, 2022, 00:53 |
Assessing a variable from one custom lib to anther
|
#1 |
Senior Member
TWB
Join Date: Mar 2009
Posts: 414
Rep Power: 19 |
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. |
|
June 24, 2022, 08:10 |
|
#2 |
New Member
Pere
Join Date: Mar 2022
Location: Mallorca
Posts: 16
Rep Power: 4 |
||
June 25, 2022, 10:37 |
|
#3 |
Senior Member
TWB
Join Date: Mar 2009
Posts: 414
Rep Power: 19 |
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? |
|
June 25, 2022, 10:47 |
|
#4 | |
New Member
Pere
Join Date: Mar 2022
Location: Mallorca
Posts: 16
Rep Power: 4 |
Quote:
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. |
||
June 27, 2022, 05:39 |
|
#5 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
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. |
|
June 28, 2022, 03:21 |
|
#6 |
Senior Member
TWB
Join Date: Mar 2009
Posts: 414
Rep Power: 19 |
Hi katiuskas,
I tried to the 1st part of your code: Code:
void Foam::sixDoFRigidBodyMotion::createDict() ... 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); } Thanks. |
|
|
|
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 |