|
[Sponsors] |
February 12, 2020, 11:50 |
Storing arrays of dimensionedScalar
|
#1 |
Member
Andrea Di Ronco
Join Date: Nov 2016
Location: Milano, Italy
Posts: 57
Rep Power: 10 |
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:
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]) ); } Code:
lambda ( val1 val2 ... valN ); 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 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 |
|
February 13, 2020, 00:40 |
|
#2 |
Senior Member
Yogesh Bapat
Join Date: Oct 2010
Posts: 102
Rep Power: 16 |
You are assigning non-dimensional quantity to dimensional quantity. Dimensions should be consistent.
|
|
February 13, 2020, 05:45 |
|
#3 |
Member
Andrea Di Ronco
Join Date: Nov 2016
Location: Milano, Italy
Posts: 57
Rep Power: 10 |
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 |
|
February 13, 2020, 17:12 |
|
#4 |
Senior Member
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 931
Rep Power: 13 |
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'.
__________________
The OpenFOAM community is the biggest contributor to OpenFOAM: User guide/Wiki-1/Wiki-2/Code guide/Code Wiki/Journal Nilsson/Guerrero/Holzinger/Holzmann/Nagy/Santos/Nozaki/Jasak/Primer Governance Bugs/Features: OpenFOAM (ESI-OpenCFD-Trademark) Bugs/Features: FOAM-Extend (Wikki-FSB) Bugs: OpenFOAM.org How to create a MWE New: Forkable OpenFOAM mirror |
|
February 14, 2020, 12:29 |
|
#5 | ||
Member
Andrea Di Ronco
Join Date: Nov 2016
Location: Milano, Italy
Posts: 57
Rep Power: 10 |
Hi HPE,
thank you for the reply. Quote:
Quote:
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 |
|||
February 14, 2020, 16:56 |
|
#6 |
Senior Member
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 931
Rep Power: 13 |
Out of my head (for ESI-OF):
dimensionedScalar dS("dS", dimless/dimTime, dict.get<scalar>("dS")); List<dimensionedScalar> dSL ( 10, // some size dS );
__________________
The OpenFOAM community is the biggest contributor to OpenFOAM: User guide/Wiki-1/Wiki-2/Code guide/Code Wiki/Journal Nilsson/Guerrero/Holzinger/Holzmann/Nagy/Santos/Nozaki/Jasak/Primer Governance Bugs/Features: OpenFOAM (ESI-OpenCFD-Trademark) Bugs/Features: FOAM-Extend (Wikki-FSB) Bugs: OpenFOAM.org How to create a MWE New: Forkable OpenFOAM mirror |
|
February 15, 2020, 06:41 |
|
#7 | |
Member
Andrea Di Ronco
Join Date: Nov 2016
Location: Milano, Italy
Posts: 57
Rep Power: 10 |
Quote:
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 &) Anyway, I'm speaking of OF7 and I don't know if other OF versions behave differently. Andrea |
||
February 23, 2020, 06:17 |
|
#8 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
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 |
||
Tags |
array, dimensionedscalar, lists |
|
|
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 |