CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   adding condition to own solver (error occurs) (https://www.cfd-online.com/Forums/openfoam-programming-development/234091-adding-condition-own-solver-error-occurs.html)

alexio97 February 23, 2021 06:16

adding condition to own solver (error occurs)
 
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?

mAlletto February 23, 2021 07:00

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

alexio97 February 23, 2021 07:34

thanks for the reply
 
Quote:

Originally Posted by mAlletto (Post 797032)
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;
}

mAlletto February 23, 2021 07:38

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

alexio97 February 23, 2021 07:46

Quote:

Originally Posted by mAlletto (Post 797036)
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

mAlletto February 23, 2021 08:39

There were some changes regarding the name of the function which returns the reference to the internal field from 3.0 on. Just google

alexio97 February 25, 2021 10:34

Quote:

Originally Posted by mAlletto (Post 797036)
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?

mAlletto February 25, 2021 10:50

Can you post the error

alexio97 February 25, 2021 10:52

Quote:

Originally Posted by mAlletto (Post 797249)
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 February 25, 2021 11:04

Quote:

Originally Posted by alexio97 (Post 797250)
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;
}
}

}

mAlletto February 25, 2021 11:15

Look for the member function value()


All times are GMT -4. The time now is 19:37.