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

Adding dimensionedScalars to dimensionedList

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 6, 2021, 12:00
Default Adding dimensionedScalars to dimensionedList
  #1
Member
 
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5
Pyrokrates is on a distinguished road
Hey,


I would like to add some dimensionedScalars which I read from a dictionary in /constant to a List of dimensionedScalars. Every code snipped I have tried out lead to a compilation error, or if compilated to a run time error (dimensions not equal).


Can somebody tell me, how to initialize it?


Here is some of my Code:


/constant/UD_Properties


Code:
d_p0         60.0E-09;
d_p1         70.0E-09;
d_p2         80.0E-09;
d_p3         100.0E-09;
createFields.H


Code:
dimensionedScalar d_p0("d_p0",dimensionSet(0, 1, 0, 0, 0, 0, 0),UD_Properties.lookup("d_p0"));
dimensionedScalar d_p1("d_p1",dimensionSet(0, 1, 0, 0, 0, 0, 0),UD_Properties.lookup("d_p1"));
dimensionedScalar d_p2("d_p2",dimensionSet(0, 1, 0, 0, 0, 0, 0),UD_Properties.lookup("d_p2"));
dimensionedScalar d_p3("d_p3",dimensionSet(0, 1, 0, 0, 0, 0, 0),UD_Properties.lookup("d_p3"));
I can use

Code:
dimensionedScalar d_p[4]{d_p0,d_p1,d_p2,d_p3};
which actually works but than I have an array and can not use forAll and stuff like that. What I would like to get is a List like the geometricField ones.


Thanks in advance


Pyro

Last edited by Pyrokrates; December 7, 2021 at 07:02.
Pyrokrates is offline   Reply With Quote

Old   December 8, 2021, 14:38
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,689
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Naive question, what breaks with a regular list?
Code:
List<dimensionedScalar> list(2);

list[0] = dimensionedScalar("d_p0", dimLength, dict);
list[1] = dimensionedScalar("d_p1", dimLength, dict);
...

The only thing might be a missing != or == operator? The operator< seems to be there and doesn't care about the dimensionSet.
olesen is offline   Reply With Quote

Old   December 9, 2021, 04:21
Default
  #3
Member
 
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5
Pyrokrates is on a distinguished road
Hi and thank you for the answer.


If I try to use this code, I get a runtime error with no matching dimensions. A print out tells me that the problem is the list which is initialized without any dimension so I cant set any list entry to a d_p value with dimensions...


Another interesting thing is that I get compilation warnings, the declaration of this form is deprecated since 2018-11. Thats why I tried out to change the input and read functions in my dictionaries which looks like this:

/constant/UD_Properties


Code:
d_p0      d_p0      [0 1 0 0 0 0 0] 60.0E-09; 
d_p1      d_p1      [0 1 0 0 0 0 0] 70.0E-09;
d_p2      d_p2      [0 1 0 0 0 0 0] 80.0E-09;
which I could read inside my createFields.H with


Code:
dimensionedScalar d_p0(CDRAProperties.lookup("d_p0"));
dimensionedScalar d_p1(CDRAProperties.lookup("d_p1"));
dimensionedScalar d_p2(CDRAProperties.lookup("d_p2"));
Both variants are not compatible with the coded line, you sent to me :/


Maybe there is a much easier way to read them??? All values of my list have the same dimensions which is guaranteed. The only part is the number of scalars... So for this, a loop with maybe 1 or 2 lines would be a better way if possible instead of copy pasting every single line.


Thanks in advance


Pyro
Pyrokrates is offline   Reply With Quote

Old   December 9, 2021, 14:06
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,689
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
It turns out that there a number of things that won't be working properly here. I think it is time to rethink your approach. Here are some general observations:

Dimension checking is normally used to ensure that you don't do something stupid. However in your case the List will be default initialized, which means that you have initially have dimless entries that you are trying to overwrite. Here is an OK, but ugly way to disable that checking locally:
Code:
List<dimensionedScalar> list(3); 

const int oldDimChecking = dimensionSet::debug; 
 dimensionSet::debug = false; 

 list[0] = dimensionedScalar("a", dimLength, 5); 
 list[1] = dimensionedScalar("b", dimMass, 2); 
 list[2] = dimensionedScalar("c", dimTemperature, 8); 

 dimensionSet::debug = oldDimChecking; 

 Info<< "have: " << list[2] << nl;

This runs, but doesn't produce what you expected:
Code:
have: c [0 0 0 0 0 0 0] 8

If we trace through all of the operations, we'll notice that only the value is copied but not the dimensions. In most cases this is what you would want since the dimensions should be identical and you don't want to be copying the extra 7 values for each and every operation.
We can force these to be overwritten too:

Code:
dimensionedScalar myval("c", dimTemperature, 8);


list[2].dimensions().reset(c.dimensions());

list[2] = c;
// OR 

//  list[2].value() = c.value();


Now getting somewhere, not particularly pleasant looking at this point. Before we get too excited about this, add a debug statement:
Code:
Info<< list << nl;


Loads of compiler errors, but if you trace to the origin you'll see that the missing "!=" operator is causing the problem. Okay, but should we add that in or give up?


At this point I would say that you should drop this approach. If you know that everything has the same dimension, then simply read and store the values only.
Another possibility would be a PtrList of dimensionedScalar. This should avoid most of the other problems, but looks slightly ugly in its own way.

olesen is offline   Reply With Quote

Old   December 10, 2021, 03:41
Default
  #5
Member
 
Chris
Join Date: Dec 2020
Posts: 45
Rep Power: 5
Pyrokrates is on a distinguished road
Hey,


thank you very much for the detailed answer. That helped me a lot. I will do some testing and see which of your methods fit best to me and my problem.

Only storing the values without dimension does not make sense for me (maybe i miss something)...
If I want to multiplay my scalar with a geometricField (volScalarField M (m), C (m^2)) like e.g. C = d_p[i] * M, than the solver would return the dimension error due to missing dimension of my diameter value... But like I said, thanks much and I will try out your mentioned methods.


Thanks


Pyro
Pyrokrates is offline   Reply With Quote

Reply

Tags
dimensionedlist


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
Adding refinement zone causes multiRegion case to fail boffin5 OpenFOAM Running, Solving & CFD 1 December 4, 2021 15:26
FOAM FATAL ERROR: Cannot find file "points" in directory "shell/polyMesh" amol_patel OpenFOAM Pre-Processing 22 October 29, 2021 13:34
chtMultiRegionFoam solver stops without any error amol_patel OpenFOAM Running, Solving & CFD 2 October 20, 2021 01:29
multiRegionHeater error ordinary OpenFOAM Running, Solving & CFD 2 June 9, 2020 17:43
conjugateHeatFoam + interFoam farhagim OpenFOAM Programming & Development 15 July 19, 2016 07:55


All times are GMT -4. The time now is 05:56.