|
[Sponsors] |
dimensionedScalar of createField declaration and initialization |
![]() |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
![]() |
![]() |
#1 |
New Member
Reza
Join Date: Jun 2012
Posts: 27
Rep Power: 14 ![]() |
Hi,
lets say I have a file called "myProproperties" in the constant directory of my case file where the file has an entry like: myProp { myVariable [0 1 0 0 0 0 0] 1; } now, in the solver (for simplicity lets say myIcoFoam) I should add the following: IOdictionary myProperties ( IOobject ( "myProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) ); const dictionary& myVariable(myProperties.subDict("myProp")) dimensionedScalar myVar ( "myVar", dimLength, myVariable.lookup("myVar") ); So, when I do it like that, I am declaring the variable myVar and initialize it directly. Now lets say I just want to declare my variables and initialize it later. I looked into the "dimensionedType.C" which I assume is the template class for dimensionedScalar and I found the following constructor: dimensioned (const word &, const dimensioned< Type > &) so I declared my variable as: myVar("myVar", dimLength) up to here everything was OK but then I needed to initialize the variable and the problem appeared here!!! Firstly, I could not find a member function which can initialize the variable just created! Looking at the member function of the class it suggest there is a function called "lookupOrAddToDict" but whatever I tried did not worked! so basically I am wondering how one can keep the initialization of the variable separate from declaration. Thank you. |
|
![]() |
![]() |
![]() |
![]() |
#2 |
Senior Member
|
Hi,
What is wrong with value method (https://cpp.openfoam.org/v5/classFoa...ba781bfdf927)? I.e. you do something like: Code:
myVar.value() = 10; |
|
![]() |
![]() |
![]() |
![]() |
#3 |
New Member
Reza
Join Date: Jun 2012
Posts: 27
Rep Power: 14 ![]() |
Hi Alexey,
the value() function as it is stated, returns a reference (const or non-const) to value but in my case I want to initialize it with the value aviable in the dictionary (the value 1 in "myProperties" [0 1 0 0 0 0 0] 1). |
|
![]() |
![]() |
![]() |
![]() |
#4 |
Senior Member
|
Hi,
You can assign through non-const reference. There is read method (https://cpp.openfoam.org/v5/classFoa...a32b6551dc7847), if you would like to read value from dictionary. I.e. Code:
myVar.read(myProperties) |
|
![]() |
![]() |
![]() |
Tags |
createfields.h, dimensioned< type >, dimensionedscalar, dimensionedtype class |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pointer Initialization | SprayStef | OpenFOAM Programming & Development | 0 | December 17, 2014 13:58 |
Variable Declaration And Initialization | mart.hein | OpenFOAM Programming & Development | 2 | March 8, 2011 10:42 |