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/)
-   -   New viscosity model with an "if/else" condition on the strain rate. (https://www.cfd-online.com/Forums/openfoam-programming-development/185039-new-viscosity-model-if-else-condition-strain-rate.html)

TemC March 17, 2017 04:39

New viscosity model with an "if/else" condition on the strain rate.
 
4 Attachment(s)
Morning foamers,

I hope you are all doing well...

I'm trying to adapt the Herschel-Bulkley viscosity model available in OpenFoam.

Basically the original model (attachment 1) states:

" apparentViscosity = min (nu0_, (k_^n + tau0_)/strainRate) "


What I want to do is the following :

" if (strainRate < tau0_/nu0_)
apparentViscosity = nu0_
else
apparentViscosity = (k_^n + tau0_)/strainRate
"

Attachment 2 shows how I'am currently trying to implement it.

When trying to execute the "wmake libso" command, I got the message described in Attachments 3 and 4.

Obvioulsly there is something that I haven't understood yet, but I don't know what.

Any comment/suggestion about what may be uncorrect?

Thanks in advance and have a nice weekend.

Regards.

Zeppo March 17, 2017 11:47

First of all please post your code as text not screenshots to save us some efforts in copying/editing it in our replies.

The error localizes in this line
Code:

if (sr() < tau0_/nu0_)
{
    ...

Replace it with
Code:

if (sr() < List<dimensionedScalar>(sr().size(), tau0_/nu0_))
{
    ...

or
Code:

forAll(sr(), i)
{
    if (sr()[i] < tau0_/nu0_)
    {
        ...

https://cpp.openfoam.org/v3/a07619_source.html

TemC March 17, 2017 13:18

2 Attachment(s)
Sir thank you very much for your reply

I made the modifications as you suggested. The first attachment is my file ''newModel.C" . The second one is the new message I get while trying to compile. Should I change another line of code?

Thanks again for time.

Regards.

Zeppo March 17, 2017 14:12

Code:

if (sr() < List<dimensionedScalar>(sr().size(), tau0_/nu0_))
{
    ...


tooran February 27, 2020 13:09

2 Attachment(s)
Quote:

Originally Posted by Zeppo (Post 641200)
First of all please post your code as text not screenshots to save us some efforts in copying/editing it in our replies.

The error localizes in this line
Code:

if (sr() < tau0_/nu0_)
{
    ...

Replace it with
Code:

if (sr() < List<dimensionedScalar>(sr().size(), tau0_/nu0_))
{
    ...

or
Code:

forAll(sr(), i)
{
    if (sr()[i] < tau0_/nu0_)
    {
        ...

https://cpp.openfoam.org/v3/a07619_source.html


















Hi,
I want to change the HerschelBulkley viscosity model . I want to add a if-condition as follows:
if strain rate is greater than gama (gama is a variable which read from the input) then calculate viscosity according to ....
so I write the following code :


//*************************************

if (sr() < List<dimensionedScalar>(sr().size(), gama_))
{
return...






Attachment 75163

Attachment 75164Attachment 75163

Attachment 75164





When I write "wmake libso" it shows me the following error :


error: no match for ‘operator<’ (operand types are ‘const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>’ and ‘Foam::List<Foam::dimensioned<double> >’)
if (sr() < List<dimensionedScalar>(sr().size(), gama_))





Could you please help me?

tooran February 27, 2020 13:12

2 Attachment(s)
Hi,
I want to change the HerschelBulkley viscosity model . I want to add a if-condition as follows:
if strain rate is greater than gama (gama is a variable which read from the input) then calculate viscosity according to ....
so I write the following code :


//*************************************

if (sr() < List<dimensionedScalar>(sr().size(), gama_))
{
return...









When I write "wmake libso" it shows me the following error :


error: no match for ‘operator<’ (operand types are ‘const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>’ and ‘Foam::List<Foam::dimensioned<double> >’)
if (sr() < List<dimensionedScalar>(sr().size(), gama_))





Could you please help me?


Attachment 75165

Attachment 75166

Zeppo March 28, 2020 08:14

Code:

if (sr() < List<scalar>(sr().size(), gama_))
{


tooran March 29, 2020 17:15

Thanks for your comment
I used your words and add following lines.

tmp<volScalarField> tmpEtat = min(
nu0_,
(tau0_ + k_*rtone*pow(tone*sr(), n_))
/(max(sr(), dimensionedScalar ("vSmall", dimless/dimTime, VSMALL)))
);


forAll (sr(), cellI) //loop through cell centres


if (sr() < List<scalar>(sr().size(), gama_.value()))
{


tmpEtat.ref()[cellI] =
min
(
nu0_.value(),
(tau0_.value() + k_.value()*rtone.value()*pow(tone.value()*sr.ref()[cellI], n_.value()))
/(max(sr()[cellI], 0.0002))
);
}

else {
tmpEtat.ref()[cellI] =
min
(
nu0_.value(),
(tau0ll_.value() + kll_.value()*rtone.value()*pow(tone.value()*sr.ref ()[cellI], n_.value()))
/(max(sr()[cellI], 0.0002))
);
}


return tmpEtat;


The library compiled but the results are strange at the outlet boundary.

Zeppo March 29, 2020 17:45

Go for this:
Code:

forAll(sr(), cellI)
{
    tmpEtat.ref()[cellI] = min
    (
        nu0_.value(),
        tau0_.value() +
        (sr()[cellI] < gama_.value() ? k_.value() : kll_.value())
      * rtone.value()*pow(tone.value()*sr.ref()[cellI], n_.value())
      / max(sr()[cellI], 0.0002)
    );
}


tooran March 29, 2020 17:57

Quote:

Originally Posted by Zeppo (Post 763445)
Go for this:
Code:

forAll(sr(), cellI)
{
    tmpEtat.ref()[cellI] = min
    (
        nu0_.value(),
        tau0_.value() +
        (sr()[cellI] < gama_.value() ? k_.value() : kll_.value())
      * rtone.value()*pow(tone.value()*sr.ref()[cellI], n_.value())
      / max(sr()[cellI], 0.0002)
    );
}




Thanks for your replying ,But I should use tau0_ll too.
I think the code does not aply zero geadient condition for tmpEta at outlet


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