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

assigning dimension scalar

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 25, 2021, 11:27
Default assigning dimension scalar
  #1
New Member
 
John Kim
Join Date: Jan 2021
Posts: 22
Rep Power: 5
alexio97 is on a distinguished road
Hello openfoamers. I have a problem dealing with the dimension

thermalPhaseChangeModel
(
name,
thermalPhaseChangeProperties,
twoPhaseProperties,
T,
alpha1
),
Q_pc_
(
IOobject
(
"PhaseChangeHeat",
T_.time().timeName(),
T.mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
T.mesh(),
dimensionedScalar( "dummy", dimensionSet(1,-1,-3,0,0,0,0), 0 )
)
{

// reading rl and rv
thermalPhaseChangeProperties_.lookup("rl") >> rl;
thermalPhaseChangeProperties_.lookup("rv") >> rv;

correct();
}


// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //

void Foam::thermalPhaseChangeModels::EmpiricalRateParam eter::calcQ_pc()
{
const dimensionedScalar& rhol = twoPhaseProperties_.rho1();
const dimensionedScalar& rhov = twoPhaseProperties_.rho2();

forAll(alpha1_, cellI)
{
if (alpha1_[cellI] < 0.9 && alpha1_[cellI] > 0.01)
{
Q_pc_[cellI] = pos(T_[cellI] - T_sat_)*h_lv_*rl*alpha1_[cellI]*rhol*((T_[cellI] - T_sat_)/T_sat_) + neg(T_[cellI] -T_sat_)*h_lv_*rv*(1.0 - alpha1_[cellI])*rhov*((T_[cellI] - T_sat_)/T_sat_);


}

else
{
Q_pc_[cellI] = 0;
}
}

}

This is my code. The wmake works but when i run this solver, openfoam 2.4.0 thinks Q_pc_ as zero dimension. But as you can see, I made Q_pc_ to be (1,-1,-3,0,0,0,0). How can i solve this problem?


p.s error occurs like this
error: cannot convert ‘Foam::dimensioned<double>’ to ‘double’ in assignment
Q_pc_[cellI] = pos(T_[cellI] - T_sat_)*h_lv_*rl*alpha1_[cellI]*rhol*((T_[cellI] - T_sat_)/T_sat_) + neg(T_[cellI] -T_sat_)*h_lv_*rv*(1.0 - alpha1_[cellI])*rhov*((T_[cellI] - T_sat_)/T_sat_);

this error come when i run the program.
--> FOAM FATAL ERROR:
Different dimensions for =
dimensions : [1 -1 -3 0 0 0 0] = [0 0 0 0 0 0 0]
alexio97 is offline   Reply With Quote

Old   February 25, 2021, 14:37
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
If you use something like Q_pc[index], you are already bypassing dimension checks. Your dimensions are coming from somewhere else like rhol. Might want to use the .value() method there.
olesen is offline   Reply With Quote

Old   February 25, 2021, 15:06
Default
  #3
New Member
 
John Kim
Join Date: Jan 2021
Posts: 22
Rep Power: 5
alexio97 is on a distinguished road
Quote:
Originally Posted by olesen View Post
If you use something like Q_pc[index], you are already bypassing dimension checks. Your dimensions are coming from somewhere else like rhol. Might want to use the .value() method there.
Thank you for your reply You mean q_pc already has its dimension?
Then I have to make a code something like
(pos(T_[cellI] - T_sat_)*h_lv_*rl*alpha1_[cellI]*rhol*((T_[cellI] - T_sat_)/T_sat_) + neg(T_[cellI] -T_sat_)*h_lv_*rv*(1.0 - alpha1_[cellI])*rhov*((T_[cellI] - T_sat_)/T_sat_)).value() ??
alexio97 is offline   Reply With Quote

Old   February 25, 2021, 18:22
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by alexio97 View Post
Thank you for your reply You mean q_pc already has its dimension?
Then I have to make a code something like
(pos(T_[cellI] - T_sat_)*h_lv_*rl*alpha1_[cellI]*rhol*((T_[cellI] - T_sat_)/T_sat_) + neg(T_[cellI] -T_sat_)*h_lv_*rv*(1.0 - alpha1_[cellI])*rhov*((T_[cellI] - T_sat_)/T_sat_)).value() ??



It looks like your Q_pc is a volScalarField - when thinking of the rest, it would pay to take a look at some of the tutorial files (the various 0/ fields) to see what how they are structured. The volScalarField has the same things: dimensions, an internal field and the boundary patches. Within OpenFOAM, you usually work on the highest level, for example adding or multiplying these volume fields. The dimension checks are done once at the top level. At the lower-level of looping, you just have an "internal" field of values, eg a scalar for each cell. These don't have any dimensions, and you wouldn't really want to have dimension checking in the inner loop. So when you are referencing an internal value like Q_pc[cellId] you are just getting the scalar value. If you start to multiply these with things that _are_ dimensioned, such as a dimensionedScalar, things get a bit weird since the plain scalar doesn't have dimension. At that stage you would normally use the .value() on the dimensionedScalar to get its plain value.


Have a play around, and you'll get the idea. Not really easy to explain at a distance.
olesen is offline   Reply With Quote

Old   February 26, 2021, 03:27
Default
  #5
New Member
 
John Kim
Join Date: Jan 2021
Posts: 22
Rep Power: 5
alexio97 is on a distinguished road
Quote:
Originally Posted by olesen View Post
It looks like your Q_pc is a volScalarField - when thinking of the rest, it would pay to take a look at some of the tutorial files (the various 0/ fields) to see what how they are structured. The volScalarField has the same things: dimensions, an internal field and the boundary patches. Within OpenFOAM, you usually work on the highest level, for example adding or multiplying these volume fields. The dimension checks are done once at the top level. At the lower-level of looping, you just have an "internal" field of values, eg a scalar for each cell. These don't have any dimensions, and you wouldn't really want to have dimension checking in the inner loop. So when you are referencing an internal value like Q_pc[cellId] you are just getting the scalar value. If you start to multiply these with things that _are_ dimensioned, such as a dimensionedScalar, things get a bit weird since the plain scalar doesn't have dimension. At that stage you would normally use the .value() on the dimensionedScalar to get its plain value.


Have a play around, and you'll get the idea. Not really easy to explain at a distance.
Thank you for your kind reply. It was very helpful! The solver perfectly works right now.

Sincerely
John
alexio97 is offline   Reply With Quote

Reply

Tags
openfoam


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
problem during mpi in server: expected Scalar, found on line 0 the word 'nan' muth OpenFOAM Running, Solving & CFD 3 August 27, 2018 05:18
Division by zero exception - loop over scalarField Pat84 OpenFOAM Programming & Development 6 February 18, 2017 06:57
Issue symmetryPlane 2.5d extruded airfoil simulation 281419 OpenFOAM Running, Solving & CFD 5 November 28, 2015 14:09
Diverging solution in transonicMRFDyMFoam tsalter OpenFOAM Running, Solving & CFD 30 July 7, 2014 07:20
compressible flow in turbocharger riesotto OpenFOAM 50 May 26, 2014 02:47


All times are GMT -4. The time now is 16:14.