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

Reading non constant number of scalars from dictionary

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 10, 2021, 06:00
Default Reading non constant number of scalars from dictionary
  #1
Member
 
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5
Pyrokrates is on a distinguished road
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
Pyrokrates is offline   Reply With Quote

Old   August 10, 2021, 12:14
Default
  #2
Senior Member
 
shereez234's Avatar
 
M Sereez
Join Date: Jan 2014
Location: England
Posts: 352
Blog Entries: 1
Rep Power: 13
shereez234 is on a distinguished road
Quote:
Originally Posted by Pyrokrates View Post
Hey,

Is there any way initialize a list of dimensioned scalars with createFields.H?
Code:
 dimensionedScalar dp1
    (
        "dp1",
        dimTime,
        someDictionary.lookup("dp1")
    );
If i remember correctly
Code:
 dimensionedScalar dp1
    (
        "dp1",
       dimensionSet(0, 1, 0, 0, 0,0,0),
        someDictionary.lookup("dp1")
    );
should work too.

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
shereez234 is offline   Reply With Quote

Old   August 12, 2021, 10:36
Default
  #3
Member
 
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5
Pyrokrates is on a distinguished road
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
Pyrokrates is offline   Reply With Quote

Old   August 12, 2021, 16:11
Default
  #4
Senior Member
 
shereez234's Avatar
 
M Sereez
Join Date: Jan 2014
Location: England
Posts: 352
Blog Entries: 1
Rep Power: 13
shereez234 is on a distinguished road
Quote:
Originally Posted by Pyrokrates View Post
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

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;
some dictionary
Code:
mylist 4(1e-05 2.0 3.0 4.0);
However, even this way, the dimensions are not allocated at read time of the scalar list.

perhaps allocate later if they all have the same dimension?

Here is another link:
Storing arrays of dimensionedScalar
shereez234 is offline   Reply With Quote

Old   August 13, 2021, 03:17
Default
  #5
Member
 
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5
Pyrokrates is on a distinguished road
Thank you very much. That was exactly what I was looking for.
Pyrokrates 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
[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


All times are GMT -4. The time now is 10:37.