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

Iterating through a field leads to not matching dimensions at some point of the loop

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 31, 2022, 11:17
Default Iterating through a field leads to not matching dimensions at some point of the loop
  #1
Member
 
Join Date: Jan 2022
Location: Germany
Posts: 72
Rep Power: 4
überschwupper is on a distinguished road
Dear Foamers,


I cannot wrap my mind around this problem. I have initialised a dimensionedScalar(dimMass/dimTime, 0) and then I want to integrate over all cells if a condition is met. But everytime the loop starts or is running through all cells at some point a conflict with not matching dimensions occurs.


The code looks like this:


Code:
dimensionedScalar intPhiVap("intPhiVap", dimMass/dimTime, 0);


forAll(mesh_.C(), celli)
{
    if (alpha1()[celli] < alphaCutOff_)
    {
        intPhiVap.value() += (1.0-alpha1()[celli])*phi[celli]*mesh_.V();

    }

}
Unfortunately this snippet returns an error at some time (lets say whenn celli=1000), that dimensions are different
Code:
dimensions [0 0 0 0 0 0 0] = [1 0 -1 0 0 0 0]
From function bool Foam::dimensionSet::operator=(const Foam::dimensionSet&) const
Since the above equation has no assignment operator (and I expect this is a check done by dimensioned<Type> Class)I checked which dimensions intPhiVap.value() has and it has no dimensions and is of type scalar/double. Since phi*mesh.V() is kg/s I thought about changing this line to
Code:
intPhiVap += (1.0-alpha1()[celli])*phi[celli]*mesh_.V();
But this results into following error directly after the if condition (so at the first iteration step)
Code:
Different dimensions for +=      dimensions : [1 0 -1 0 0 0 0] = [0 0 0 0 0 0 0]       

From function bool Foam::dimensionSet::operator+=(const Foam::dimensionSet&) const
Thats why I wanted to avoid the += operator and I changed the line to
Code:
intPhiVap = (1.0-alpha1()[celli])*phi[celli]*mesh_.V() + intPhiVap;
But this was followed by another error
Code:
--> FOAM FATAL ERROR: 
LHS and RHS of + have different dimensions
     dimensions : [0 0 0 0 0 0 0] + [1 0 -1 0 0 0 0]


    From function Foam::dimensionSet Foam::operator+(const Foam::dimensionSet&, const Foam::dimensionSet&)
Which is strange, because the product results in the dimensions of kg/s and so does intPhiVap. So I tried

Code:
intPhiVap = (1.0-alpha1()[celli])*phi[celli]*mesh_.V() + intPhiVap.value();
As expected this results into following error:
Code:
--> FOAM FATAL ERROR: 
Different dimensions for =
     dimensions : [1 0 -1 0 0 0 0] = [0 0 0 0 0 0 0]


     From function bool Foam::dimensionSet::operator=(const Foam::dimensionSet&) const
Next try was:

Code:
intPhiVap.value() = (1.0-alpha1()[celli])*phi[celli]*mesh_.V() + intPhiVap.value();
The result was, that the for loop was running further and has not interrupted directly at first step, but the error message was then:
Code:
--> FOAM FATAL ERROR: 
Different dimensions for =
     dimensions : [0 0 0 0 0 0 0] = [1 0 -1 0 0 0 0]


     From function bool Foam::dimensionSet::operator=(const Foam::dimensionSet&) const
I dont understand why nothing of above is working. It feels so arbitrary. I mean the product of the RHS should always has the dimensions kg/s and so should the LHS. But it seems, that the for-loop allows exceptions to this. I expect, that the issue arises, when the product is 0 for the dimension mismatch on the LHS and when the product is not 0 then on the RHS, but I have no clue. But how should it be possible? iterating through a field should always return the same dimensions, no matter what value is saved in that space..


I really hope someone has an idea how tofix this. Thank you all in advance

Last edited by überschwupper; September 1, 2022 at 02:34.
überschwupper is offline   Reply With Quote

Old   September 1, 2022, 08:40
Default
  #2
Member
 
Join Date: Jan 2022
Location: Germany
Posts: 72
Rep Power: 4
überschwupper is on a distinguished road
I'm not sure if the upper problem is solved but it seems like I have found a work around specificly for my work.


The above code snippet was inside a function that should return a Pair<dimensionedScalar>, but asap the single values are written, dimension mismatch is occuring.
Code:
Pair<dimensionedScalar> calcPhis()
//Code
return Pair<dimensionedScalar>
(
    intPhiLiq,
    intPhiVap
);


Pair intPhis(calcPhis);
nevertheless, i dont have a clue, why this rises an error of dimension mismatch..
überschwupper 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
Access volume field in the boundary condition of a point field peyman.havaej OpenFOAM Programming & Development 0 July 31, 2020 12:10
[Gmsh] Problem with Gmsh nishant_hull OpenFOAM Meshing & Mesh Conversion 23 August 5, 2015 02:09
[Gmsh] Gmsh and samplesurface touf OpenFOAM Meshing & Mesh Conversion 2 December 10, 2007 02:27
CFX4.3 -build analysis form Chie Min CFX 5 July 12, 2001 23:19
Grid refinement with wall functions Mark Render Main CFD Forum 8 May 2, 2000 07:09


All times are GMT -4. The time now is 03:58.