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

Error in compiling new viscosity model

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 15, 2021, 20:26
Default Error in compiling new viscosity model
  #1
Member
 
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 5
Venky_94 is on a distinguished road
Hey I'm trying to compile a new viscosity model (the equation is attached in the image).
I'm modifying the cross power law model and changing the calcNu() function as below.

Code:
Foam::tmp<Foam::volScalarField>
Foam::viscosityModels::APL::calcNu() const
{
	if (strainRate() <= 0) 
    {
	return pow(pow(mu0_,p_)+pow(K_*pow(scalar(0.00000000001),(n_-1)),p_),pow(p_,-1))/density_;
	}
    else 
    {
	return pow(pow(mu0_,p_)+pow(K_*pow(dimensionedScalar("one", dimTime, 1.0)*strainRate(),(n_-1)),p_),pow(p_,-1))/density_;
	}
}
My aim is to avoid unrealistic values during startup when velocity is zero, which is why I want to implement an if loop where the strain rate is replaced by a very small value during startup after which my actual equation should kick in.

The issue I'm facing is that I don't understand how to implement the if loop for the volVectorField of strainRate and I'm getting the below error. Could someone suggest a workaround or way to do this?

Quote:
viscosityModels/APL/APL.C:56:19: error: no match for ‘operator<=’ (operand types are ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ and ‘int’)
if (strainRate() <= 0)
~~~~~~~~~~~~~^~~~
Attached Images
File Type: jpg Viscosity Model Equation.jpg (8.5 KB, 9 views)
Venky_94 is offline   Reply With Quote

Old   September 16, 2021, 05:52
Default
  #2
New Member
 
Mathias Poulsen
Join Date: Feb 2018
Location: Denmark
Posts: 9
Rep Power: 8
SvenBent is on a distinguished road
Hi.

From the error you can see that you are trying compare an entire field to a single integer value.
One way to solve the problem is to use neg0 and pos to differentiate between the negative and positive strain rate.

Code:
Foam::viscosityModels::APL::calcNu() const
{
	const volScalarField& sRate = strainRate();

        return(
            neg0(sRate) * (
            pow(pow(mu0_,p_)+pow(K_*pow(scalar(0.00000000001),(n_-1)),p_),pow(p_,-1))/density_
                        ) *
            pos(sRate)* ( 
            pow(pow(mu0_,p_)+pow(K_*pow(dimensionedScalar("one", dimTime, 1.0)*sRate,(n_-1)),p_),pow(p_,-1))/density_
                        )
            );
}
Best regards
Mathias

Quote:
Originally Posted by Venky_94 View Post
Hey I'm trying to compile a new viscosity model (the equation is attached in the image).
I'm modifying the cross power law model and changing the calcNu() function as below.

Code:
Foam::tmp<Foam::volScalarField>
Foam::viscosityModels::APL::calcNu() const
{
	if (strainRate() <= 0) 
    {
	return pow(pow(mu0_,p_)+pow(K_*pow(scalar(0.00000000001),(n_-1)),p_),pow(p_,-1))/density_;
	}
    else 
    {
	return pow(pow(mu0_,p_)+pow(K_*pow(dimensionedScalar("one", dimTime, 1.0)*strainRate(),(n_-1)),p_),pow(p_,-1))/density_;
	}
}
My aim is to avoid unrealistic values during startup when velocity is zero, which is why I want to implement an if loop where the strain rate is replaced by a very small value during startup after which my actual equation should kick in.

The issue I'm facing is that I don't understand how to implement the if loop for the volVectorField of strainRate and I'm getting the below error. Could someone suggest a workaround or way to do this?
SvenBent is offline   Reply With Quote

Old   September 16, 2021, 13:04
Default
  #3
Member
 
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 5
Venky_94 is on a distinguished road
Quote:
Originally Posted by SvenBent View Post
Hi.

From the error you can see that you are trying compare an entire field to a single integer value.
One way to solve the problem is to use neg0 and pos to differentiate between the negative and positive strain rate.

Code:
Foam::viscosityModels::APL::calcNu() const
{
	const volScalarField& sRate = strainRate();

        return(
            neg0(sRate) * (
            pow(pow(mu0_,p_)+pow(K_*pow(scalar(0.00000000001),(n_-1)),p_),pow(p_,-1))/density_
                        ) *
            pos(sRate)* ( 
            pow(pow(mu0_,p_)+pow(K_*pow(dimensionedScalar("one", dimTime, 1.0)*sRate,(n_-1)),p_),pow(p_,-1))/density_
                        )
            );
}
Best regards
Mathias
Thanks Mathias. I tried out the change you suggested and my simulation does not go beyond the '0' time step. However it helped me understand the issue very clearly though. When the initial velocity field is set as uniform(0 0 0), the strain rate is 0 at some points, where the viscosity values blow up to infinity because of the asymptotic part of the equation. I'm able to get the simulation running as expected if the initial velocity field is set to anything but 0 [for example, uniform(0.000000001 0 0)].

I compiled the code as below and identified that the issue is when the strain rate values are 0. All I need right now is a way to replace the strain rate by a very small positive value (say 1.0E-17) in the equation wherever it is 0.

Code:
Foam::tmp<Foam::volScalarField>
Foam::viscosityModels::APL::calcNu() const
{
	return pow(pow(mu0_,p_)+pow(K_*pow(dimensionedScalar("one", dimTime, 1.0)*strainRate(),(n_-1)),p_),pow(p_,-1))/density_;
}
I'd be grateful if you could suggest a way to do that.
Venky_94 is offline   Reply With Quote

Old   September 16, 2021, 13:30
Default
  #4
New Member
 
Mathias Poulsen
Join Date: Feb 2018
Location: Denmark
Posts: 9
Rep Power: 8
SvenBent is on a distinguished road
You should be able to use:
Code:
return pow(pow(mu0_,p_)+pow(K_*pow(dimensionedScalar("one", dimTime, 1.0)*max(strainRate(),vSmall),(n_-1)),p_),pow(p_,-1))/density_;
SvenBent is offline   Reply With Quote

Old   September 16, 2021, 14:46
Default
  #5
Member
 
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 5
Venky_94 is on a distinguished road
Quote:
Originally Posted by SvenBent View Post
You should be able to use:
Code:
return pow(pow(mu0_,p_)+pow(K_*pow(dimensionedScalar("one", dimTime, 1.0)*max(strainRate(),vSmall),(n_-1)),p_),pow(p_,-1))/density_;
Thanks a lot. I just had to replace vSmall with a dimensionedscalar with the units of strainrate and it's running perfectly.
Venky_94 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
[IHFOAM] The IHFOAM Thread Phicau OpenFOAM Community Contributions 392 September 8, 2023 18:10
interFoam wave propagation and explosion of Courant number and residuals ChiaraViola OpenFOAM Running, Solving & CFD 1 June 26, 2019 05:36
New Viscosity Model - Best Practice for Temporary Values MaSch OpenFOAM Programming & Development 6 March 16, 2018 03:51
Using a new implemented viscosity model with simpleFoam TemC OpenFOAM Running, Solving & CFD 6 March 8, 2017 03:07
Time constant in Herschel-Bulkley viscosity model Mikel6 Main CFD Forum 0 October 17, 2016 04:52


All times are GMT -4. The time now is 23:40.