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

Storing arrays of dimensionedScalar

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 12, 2020, 11:50
Default Storing arrays of dimensionedScalar
  #1
New Member
 
Andrea Di Ronco
Join Date: Nov 2016
Location: Milano, Italy
Posts: 15
Rep Power: 5
Diro7 is on a distinguished road
Hello,

I'm trying to read from file and store a given number N of dimensioned scalar parameters, where N is defined at runtime by the user.
Such parameters have all the same dimensions (T^-1) and are supposed to be later used in a set of N equations (each of the same form, hence my wish to "vectorize" somehow the solver).

What I tried so far looks like this:
  1. read a scalar list from a dictionary entry and assign it to an auxiliary variable of type List<scalar>
  2. declare a List<dimensionedScalar> variable
  3. iterate over the List<scalar> variable and append to the List<dimensionedScalar> variable a corresponding dimensionedScalar with the desired dimensionSet.
Code:
dimensionSet dimLambda(0, 0, -1, 0, 0, 0, 0);

List<scalar> lambda_(dict.lookup("lambda"));

List<dimensionedScalar> lambda;

forAll(lambda_, i)
{
    lambda.append( dimensionedScalar("lambda" + name(i + 1), dimLambda, lambda_[i]) );
}
where the dict entry looks like this:

Code:
lambda              ( val1 val2 ... valN );
What I find is that the the code compiles and the dictionary is correctly read.
At runtime, however, I get this error:
Code:
--> FOAM FATAL ERROR: 
Different dimensions for =
     dimensions : [0 0 0 0 0 0 0] = [0 0 -1 0 0 0 0]


    From function bool Foam::dimensionSet::operator=(const Foam::dimensionSet&) const
    in file dimensionSet/dimensionSet.C at line 171.

FOAM aborting
which I guess occurs due to the append instruction in the forAll loop.

What am I doing wrong here?
Does anyone know alternative (i.e. simpler or more straightforward) ways to achieve my goal?

Thank you in advance for the help,
Andrea
Diro7 is offline   Reply With Quote

Old   February 13, 2020, 00:40
Default
  #2
Member
 
Yogesh Bapat
Join Date: Oct 2010
Posts: 73
Rep Power: 11
ybapat is on a distinguished road
You are assigning non-dimensional quantity to dimensional quantity. Dimensions should be consistent.
ybapat is offline   Reply With Quote

Old   February 13, 2020, 05:45
Default
  #3
New Member
 
Andrea Di Ronco
Join Date: Nov 2016
Location: Milano, Italy
Posts: 15
Rep Power: 5
Diro7 is on a distinguished road
Hi Yogesh!

Thank you for the reply.
You are right, the error seems to tell that what I'm trying to do somehow implies the assignment of a dimensioned quantity to a previous variable with different dimensions.

What I'm missing is why this happens and whether am I just doing something wrong or should I use a different approach.
Could you elaborate a little bit more, if you have any suggestion?

Andrea
Diro7 is offline   Reply With Quote

Old   February 13, 2020, 17:12
Default
  #4
HPE
Senior Member
 
Herpes Free Engineer
Join Date: Sep 2019
Posts: 298
Rep Power: 3
HPE is on a distinguished road
The dimensions of 'lambda' and 'lambda_' are not the same. Any arithmetic among 'dimensionedScalar's require having the same dimensions.

If the size 'lambda' is equal to the number of cells of your mesh, I would definitely use 'GeometricFields'/' instead of bare 'List'.

Note that you can also state the dimensions instead of using a dimensionSet, e.g. 'dimless/dimTime' instead of 'dimLambda'.
__________________
Kind regards,
HPE

The OpenFOAM community is the biggest contributor to OpenFOAM; not person A or B. Let's report bugs or issue feature requests in GitLab-OpenFOAM.

Please `design` your questions well. Such effort always pays off well for inquirers and `helpmate`s:
How to create a Minimal, Reproducible Example,
How to give enough info to get help.
HPE is offline   Reply With Quote

Old   February 14, 2020, 12:29
Default
  #5
New Member
 
Andrea Di Ronco
Join Date: Nov 2016
Location: Milano, Italy
Posts: 15
Rep Power: 5
Diro7 is on a distinguished road
Hi HPE,

thank you for the reply.


Quote:
Originally Posted by HPE View Post
The dimensions of 'lambda' and 'lambda_' are not the same. Any arithmetic among 'dimensionedScalar's require having the same dimensions
Yes, this is what the error says. Is there a way to instantiate a List<dimensionedScalar> object with the desired dimensions avoiding this behavior?


Quote:
Originally Posted by HPE View Post
If the size 'lambda' is equal to the number of cells of your mesh, I would definitely use 'GeometricFields'/' instead of bare 'List'.
In the original solver, I had several different 'lambda1', ... , 'lambdaN' dimensionedScalar parameters which were plugged in N analogous equations.
Now I would like to make it a bit more flexible by having the user specifying N at run-time without modifying the source code to change it.
Since OpenFOAM supports lists, it seemed quite straightforward to me to use them to aggregate analogous parameters with the same dimensions.
Since they are constant scalar parameters, I didn't see the need to store them as fields. How would you suggest to use GeometricFields?


Andrea
Diro7 is offline   Reply With Quote

Old   February 14, 2020, 16:56
Default
  #6
HPE
Senior Member
 
Herpes Free Engineer
Join Date: Sep 2019
Posts: 298
Rep Power: 3
HPE is on a distinguished road
Out of my head (for ESI-OF):

dimensionedScalar dS("dS", dimless/dimTime, dict.get<scalar>("dS"));

List<dimensionedScalar> dSL
(
10, // some size
dS
);
__________________
Kind regards,
HPE

The OpenFOAM community is the biggest contributor to OpenFOAM; not person A or B. Let's report bugs or issue feature requests in GitLab-OpenFOAM.

Please `design` your questions well. Such effort always pays off well for inquirers and `helpmate`s:
How to create a Minimal, Reproducible Example,
How to give enough info to get help.
HPE is offline   Reply With Quote

Old   February 15, 2020, 06:41
Default
  #7
New Member
 
Andrea Di Ronco
Join Date: Nov 2016
Location: Milano, Italy
Posts: 15
Rep Power: 5
Diro7 is on a distinguished road
Quote:
Originally Posted by HPE View Post
Out of my head (for ESI-OF):

dimensionedScalar dS("dS", dimless/dimTime, dict.get<scalar>("dS"));

List<dimensionedScalar> dSL
(
10, // some size
dS
);
I already tried something similar, but it doesn't work. It compiles but gives the usual run-time error complaining about dimensions.

I'm not very into OF implementation details, but it could seem like some sort of bug, as (if I'm getting it right, at least) from documentation List< T > should allow a
Code:
List (const label, const T &)
constructor, but dimensionedScalar type just seems not compatible for some reason.

Anyway, I'm speaking of OF7 and I don't know if other OF versions behave differently.

Andrea
Diro7 is offline   Reply With Quote

Old   February 23, 2020, 06:17
Default
  #8
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: http://olesenm.github.io/
Posts: 897
Rep Power: 25
olesen will become famous soon enougholesen will become famous soon enough
Quote:
Originally Posted by Diro7 View Post
I already tried something similar, but it doesn't work. It compiles but gives the usual run-time error complaining about dimensions.

I'm not very into OF implementation details, but it could seem like some sort of bug, as (if I'm getting it right, at least) from documentation List< T > should allow a
Code:
List (const label, const T &)
constructor, but dimensionedScalar type just seems not compatible for some reason.

Anyway, I'm speaking of OF7 and I don't know if other OF versions behave differently.

Andrea

If you are remotely interested in performance you should not be using a List of dimensionedScalar. This carries the overhead of a name and dimensions for every single element!



If you are using a mesh or something equivalent, you should consider a DimensionedField. If you need a List only (no mesh reference available), you can easily define your own Dimensioned List.


/mark
olesen is offline   Reply With Quote

Reply

Tags
array, dimensionedscalar, lists

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
dimensionedScalar not updating, stuck on initial values backscatter OpenFOAM Programming & Development 2 August 7, 2018 21:30
Division of a dimensionedScalar by a volScalar Field - Arithmetic Exception charles4allme OpenFOAM Pre-Processing 4 June 27, 2018 10:57
[OpenFOAM] Paraview arrays to numpy arrays francois ParaView 2 April 14, 2014 09:33
dimensionedScalar as class member Seeker OpenFOAM Programming & Development 2 March 29, 2013 06:57
converting from dimensionedScalar to volScalarField shash OpenFOAM Running, Solving & CFD 7 July 11, 2012 06:02


All times are GMT -4. The time now is 09:31.