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

adding condition to own solver (error occurs)

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 23, 2021, 07:16
Default adding condition to own solver (error occurs)
  #1
New Member
 
John Kim
Join Date: Jan 2021
Posts: 22
Rep Power: 5
alexio97 is on a distinguished road
hello openfoamers.

I am trying to add condition
const dimensionedScalar& rhol = twoPhaseProperties_.rho1();
const dimensionedScalar& rhov = twoPhaseProperties_.rho2();

if (alpha1_<0.9 && alpha1_>0.01)
{
Q_pc_ = 1;
}
else
{
Q_pc_ = 0;
}

}

to my solver. But error
no match for ‘operator<’ (operand types are ‘const volScalarField {aka const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ and ‘double’)
occurs during allwmake.

Is there a way to solve this problem?
alexio97 is offline   Reply With Quote

Old   February 23, 2021, 08:00
Default
  #2
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
alpha1_ is a volScalarField and you want to compare it with a scalar. This does not work since no operator is defined for this. You have to loop over the whole field and compere each entry
mAlletto is offline   Reply With Quote

Old   February 23, 2021, 08:34
Default thanks for the reply
  #3
New Member
 
John Kim
Join Date: Jan 2021
Posts: 22
Rep Power: 5
alexio97 is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
alpha1_ is a volScalarField and you want to compare it with a scalar. This does not work since no operator is defined for this. You have to loop over the whole field and compere each entry
thanks for the reply! Then I have to make a code like this?
forAll(alpha1Cells, cellI)
{
if (alpha1[cellI] < 0.9 && alpha1[cellI] > 0.01)
Q_pc_ = 1;
else
Q_pc_[cellI] = 0;
}
alexio97 is offline   Reply With Quote

Old   February 23, 2021, 08:38
Default
  #4
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Code:
forAll(alpha1_, cellI)
{
    if (alpha1_[cellI] < 0.9 && alpha1_[cellI] > 0.01)
    {
        Q_pc_[cellI]= 1;
    }
    else
   {
        Q_pc_[cellI] = 0;
   {
}
Something like this
mAlletto is offline   Reply With Quote

Old   February 23, 2021, 08:46
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 mAlletto View Post
Code:
forAll(alpha1_, cellI)
{
    if (alpha1_[cellI] < 0.9 && alpha1_[cellI] > 0.01)
    {
        Q_pc_[cellI]= 1;
    }
    else
   {
        Q_pc_[cellI] = 0;
   {
}
Something like this
Thank you and I have one more question. I knew that i have to use const volScalarField& alpha1 but how can i get cell' alpha value? (like alpha1Cells). I noticed that
const volScalarField& alpha1 = alpha1();


scalarField& alpha1Cells = alpha1.internalField();

this doesn't work at openfoam 2.4.0
alexio97 is offline   Reply With Quote

Old   February 23, 2021, 09:39
Default
  #6
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
There were some changes regarding the name of the function which returns the reference to the internal field from 3.0 on. Just google
mAlletto is offline   Reply With Quote

Old   February 25, 2021, 11:34
Default
  #7
New Member
 
John Kim
Join Date: Jan 2021
Posts: 22
Rep Power: 5
alexio97 is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
Code:
forAll(alpha1_, cellI)
{
    if (alpha1_[cellI] < 0.9 && alpha1_[cellI] > 0.01)
    {
        Q_pc_[cellI]= 1;
    }
    else
   {
        Q_pc_[cellI] = 0;
   {
}
Something like this
Hello Michael, thanks for your reply. I tried your code and it worked. But i countered an error. Error is that if I apply Q_pc_ value with polynomials 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_);

The program thinks Q_pc_ as zero dimension. Can you help me to deal with the problem?
alexio97 is offline   Reply With Quote

Old   February 25, 2021, 11:50
Default
  #8
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Can you post the error
mAlletto is offline   Reply With Quote

Old   February 25, 2021, 11:52
Default
  #9
New Member
 
John Kim
Join Date: Jan 2021
Posts: 22
Rep Power: 5
alexio97 is on a distinguished road
Quote:
Originally Posted by mAlletto View Post
Can you post the error
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 is the error!
i think Q_pc_[cellI] = 0; is working well but the equation format does not work.
alexio97 is offline   Reply With Quote

Old   February 25, 2021, 12:04
Default
  #10
New Member
 
John Kim
Join Date: Jan 2021
Posts: 22
Rep Power: 5
alexio97 is on a distinguished road
Quote:
Originally Posted by alexio97 View Post
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 is the error!
i think Q_pc_[cellI] = 0; is working well but the equation format does not work.
my total code is like this

const word& name,
const dictionary& thermalPhaseChangeProperties,
const twoPhaseThermalMixture& twoPhaseProperties,
const volScalarField& T,
const volScalarField& alpha1
)
:
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;
}
}

}
alexio97 is offline   Reply With Quote

Old   February 25, 2021, 12:15
Default
  #11
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Look for the member function value()
mAlletto 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
Boundary condition for a baffle in the Laplacian mesh motion solver tecmul OpenFOAM Running, Solving & CFD 0 May 11, 2020 23:10
How can I use solution from one simulation as initial condition on a remote solver? Dano62 CFX 0 October 21, 2015 18:45
adding Porous media to lagrangian Solver kalyan OpenFOAM Programming & Development 0 September 19, 2014 08:41
Star cd es-ice solver error ernarasimman STAR-CD 2 September 12, 2014 01:01
Quarter Burner mesh with periosic condition SamCanuck FLUENT 2 August 31, 2011 12:34


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