|
[Sponsors] |
Reading non constant number of scalars from dictionary |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 10, 2021, 06:00 |
Reading non constant number of scalars from dictionary
|
#1 |
Member
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5 |
Hey,
I wrote a program to calculate some values out of a diameter d_p. This diameter is set inside a new dictionary - lets call it someProperties (similar to transportProperties). Now I would like to use more than one diameter to do the same calculation but the number of d_p should be variable e.g. d_p1, d_p2, d_p3, ... What I want is an array with all this diameters to loop over it so I donīt need to copy paste all my calculations for every single diameter. Is there any way initialize a list of dimensioned scalars with createFields.H? If not, how can I stick all single dimensioned scalars in of my dictionary to one list/array, ... for my program? Here is the snippet of createFields.H Code:
Info<< "Reading particle diameter d_p1\n" << endl; dimensionedScalar d_p1 ( CDRProperties.lookup("d_p1") ); Info<< "Reading particle diameter d_p2\n" << endl; dimensionedScalar d_p2 ( CDRProperties.lookup("d_p2") ); This is the someProperties dictionary: Code:
d_p1 d_p1 [0 1 0 0 0 0 0] 0.1E-06; d_p2 d_p2 [0 1 0 0 0 0 0] 100.0E-06; Thanks in advance Chris |
|
August 10, 2021, 12:14 |
|
#2 | |
Senior Member
|
Quote:
Code:
dimensionedScalar dp1 ( "dp1", dimTime, someDictionary.lookup("dp1") ); Code:
dimensionedScalar dp1 ( "dp1", dimensionSet(0, 1, 0, 0, 0,0,0), someDictionary.lookup("dp1") ); That being said, your someDictionary should look like dp1 1e-10; dp2 1e-29; dp3 100e-10; and in createFields.H or wherever you call it, allocate dimensions. Last edited by shereez234; August 10, 2021 at 12:18. Reason: improvement of answer |
||
August 12, 2021, 10:36 |
|
#3 |
Member
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5 |
Hello and thank you for the answer. The code you posted is for initialize a dimensionedScalar... what I am looking for is a diemnsionedScalar List or kind of array because I would like to loop over it.
The only working way I found out was this: Code:
dimensionedScalar d_p1 ( someProperties.lookup("d_p1") ); dimensionedScalar d_p2 ( someProperties.lookup("d_p2") ); dimensionedScalar d_p3 ( someProperties.lookup("d_p3") ); dimensioned<double> d_p[3]{d_p1,d_p2,d_p3}; But this seems to be very complicated. Isntīt there any way to read a list of values to an array directly? Thanks in advance Chris |
|
August 12, 2021, 16:11 |
|
#4 | |
Senior Member
|
Quote:
A list of scalars can be read easily. First initialize to size one with value one in createFields.H after that look it up from someDictionary Code:
scalarList dplist(1,1.0); someDictionary.lookup("mylist") >> dplist; Code:
mylist 4(1e-05 2.0 3.0 4.0); perhaps allocate later if they all have the same dimension? Here is another link: Storing arrays of dimensionedScalar |
||
August 13, 2021, 03:17 |
|
#5 |
Member
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5 |
Thank you very much. That was exactly what I was looking for.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] Can't Shake Erros: patch type 'patch' not constraint type 'empty' | BrendaEM | OpenFOAM Meshing & Mesh Conversion | 12 | April 3, 2022 18:32 |
Boundary condition problem (Freestream) | KAYANO | OpenFOAM Running, Solving & CFD | 5 | June 1, 2021 05:57 |
GenerateVolumeMesh Error - Surface Wrapper Self Interacting (?) | AndreP | STAR-CCM+ | 10 | August 2, 2018 07:48 |
Possible Bug in pimpleFoam (or createPatch) (or fluent3DMeshToFoam) | cfdonline2mohsen | OpenFOAM | 3 | October 21, 2013 09:28 |
writing execFlowFunctionObjects | immortality | OpenFOAM Post-Processing | 30 | September 15, 2013 06:16 |