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

Problem replacing fvm::laplacian with fvm::div(fvc::grad) in divDevRhoReff

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 10, 2020, 12:29
Question Problem replacing fvm::laplacian with fvm::div(fvc::grad) in divDevRhoReff
  #1
Member
 
Rishikesh
Join Date: Apr 2016
Posts: 63
Rep Power: 10
mrishi is on a distinguished road
I am working to change the default divDevRhoReff() defined in turbulenceModels/linearViscousStress.C. The change requires replacing the laplacian(U) operation with div(grad(U)). I change the content of divDevRhoReff(U) as follows:
Code:
 
template<class BasicTurbulenceModel>
Foam::tmp<Foam::fvVectorMatrix>
Foam::linearViscousStress<BasicTurbulenceModel>::divDevRhoReff
(
    volVectorField& U
) const
{
/*
    //first change
    Info<<"broken into two: nu + nut" <<endl;
    return
    (
      - fvc::div((this->alpha_*this->rho_*this->nu())*dev2(T(fvc::grad(U))))    //split
      - fvc::div((this->alpha_*this->rho_*this->nut())*dev2(T(fvc::grad(U))))   //split
      - fvm::laplacian(this->alpha_*this->rho_*this->nu(), U)   //not changed
      - fvm::laplacian(this->alpha_*this->rho_*this->nut(), U)
     );
//no issues as expected; some overhead due to repeated grad calculations.

 */
    //second change
    Info<<"changed fvm::laplacian to fvm::div(fvc::grad) for nut term" <<endl;
    const volTensorField A = fvc::grad(U); //to create type required by fvm::div
    const surfaceScalarField N = fvc::interpolate(this->nut()); //surfacescalarField required by fvm::div, created out of volScalarField nut
    return
    (
//      - fvc::div((this->alpha_*this->rho_*this->nu())*dev2(T(fvc::grad(U))))  //split
//      - fvc::div((this->alpha_*this->rho_*this->nut())*dev2(T(fvc::grad(U)))) //split
//        - fvm::laplacian(this->alpha_*this->rho_*this->nu(), U)       //not changed

        - fvm::div(N, fvc::grad(U)())                           // changed, removed alpha,rho to remove clutter.
//      - fvm::div(this->alpha_*this->rho_*(fvc::interpolate(this->nut())),A) //changed to div(grad(U)) instead of laplacian(U) , same as above
    );
}
In the code marked second change, I have commented out the non-problematic components so as to isolate the issue. It generates following error:
Code:
../turbulenceModels/lnInclude/linearViscousStress.C:120:5: error: could not convert ‘Foam::operator-(const Foam::tmp<Foam::fvMatrix<Type> >&) [with Type = Foam::Tensor<double>]()’ from ‘Foam::tmp<Foam::fvMatrix<Foam::Tensor<double> > >’ to ‘Foam::tmp<Foam::fvMatrix<Foam::Vector<double> > >’
The issue is type incompatibility of the fvMatrix thus created, which is of type Tensor instead of Vector. While the div operator is rank-reducing, I suppose doing this in an implicit form using fvm may create such an issue. How can I circumvent this situation while still creating a proper fvVectorMatrix which adds correctly to my UEqn.H?
PS: The reason I need to do this is because I need to carry out some operations on the grad(U) before calculating its final divergence. In other words, my nu cannot be taken out of the second derivative directly, so I cannot use laplacian(nut,U).
mrishi is offline   Reply With Quote

Old   August 13, 2020, 05:14
Default
  #2
Senior Member
 
anonymous
Join Date: Jan 2016
Posts: 416
Rep Power: 14
simrego is on a distinguished road
Hi!


First of all I think you should read about fvc and fvm. fvc is an explicit operator, while fmv is an implicit and based on your code I guess that you are not familiar with these.
Instead of fvm::div(fvc::grad(<your stuff>)) you should use: fvc::div(fvc::grad(<your stuff>)) and treat this term explicitly.
simrego is offline   Reply With Quote

Old   August 13, 2020, 15:49
Default
  #3
Senior Member
 
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16
Santiago is on a distinguished road
Quote:
Originally Posted by mrishi View Post
I am working to change the default divDevRhoReff() defined in turbulenceModels/linearViscousStress.C. The change requires replacing the laplacian(U) operation with div(grad(U)). I change the content of divDevRhoReff(U) as follows:
Code:
 
template<class BasicTurbulenceModel>
Foam::tmp<Foam::fvVectorMatrix>
Foam::linearViscousStress<BasicTurbulenceModel>::divDevRhoReff
(
    volVectorField& U
) const
{
/*
    //first change
    Info<<"broken into two: nu + nut" <<endl;
    return
    (
      - fvc::div((this->alpha_*this->rho_*this->nu())*dev2(T(fvc::grad(U))))    //split
      - fvc::div((this->alpha_*this->rho_*this->nut())*dev2(T(fvc::grad(U))))   //split
      - fvm::laplacian(this->alpha_*this->rho_*this->nu(), U)   //not changed
      - fvm::laplacian(this->alpha_*this->rho_*this->nut(), U)
     );
//no issues as expected; some overhead due to repeated grad calculations.

 */
    //second change
    Info<<"changed fvm::laplacian to fvm::div(fvc::grad) for nut term" <<endl;
    const volTensorField A = fvc::grad(U); //to create type required by fvm::div
    const surfaceScalarField N = fvc::interpolate(this->nut()); //surfacescalarField required by fvm::div, created out of volScalarField nut
    return
    (
//      - fvc::div((this->alpha_*this->rho_*this->nu())*dev2(T(fvc::grad(U))))  //split
//      - fvc::div((this->alpha_*this->rho_*this->nut())*dev2(T(fvc::grad(U)))) //split
//        - fvm::laplacian(this->alpha_*this->rho_*this->nu(), U)       //not changed

        - fvm::div(N, fvc::grad(U)())                           // changed, removed alpha,rho to remove clutter.
//      - fvm::div(this->alpha_*this->rho_*(fvc::interpolate(this->nut())),A) //changed to div(grad(U)) instead of laplacian(U) , same as above
    );
}
In the code marked second change, I have commented out the non-problematic components so as to isolate the issue. It generates following error:
Code:
../turbulenceModels/lnInclude/linearViscousStress.C:120:5: error: could not convert ‘Foam::operator-(const Foam::tmp<Foam::fvMatrix<Type> >&) [with Type = Foam::Tensor<double>]()’ from ‘Foam::tmp<Foam::fvMatrix<Foam::Tensor<double> > >’ to ‘Foam::tmp<Foam::fvMatrix<Foam::Vector<double> > >’
The issue is type incompatibility of the fvMatrix thus created, which is of type Tensor instead of Vector. While the div operator is rank-reducing, I suppose doing this in an implicit form using fvm may create such an issue. How can I circumvent this situation while still creating a proper fvVectorMatrix which adds correctly to my UEqn.H?
PS: The reason I need to do this is because I need to carry out some operations on the grad(U) before calculating its final divergence. In other words, my nu cannot be taken out of the second derivative directly, so I cannot use laplacian(nut,U).
I dont understand the reason why you would replace the laplacian with div-grad operator, assuming it was possible. It will be a slower and less precise operation.
Santiago is offline   Reply With Quote

Old   August 13, 2020, 15:54
Default
  #4
Senior Member
 
anonymous
Join Date: Jan 2016
Posts: 416
Rep Power: 14
simrego is on a distinguished road
Quote:
Originally Posted by Santiago View Post
I dont understand the reason why you would replace the laplacian with div-grad operator, assuming it was possible. It will be a slower and less precise operation.

I guess this is not his "final" code since he wrote:

"The reason I need to do this is because I need to carry out some operations on the grad(U) before calculating its final divergence."
simrego is offline   Reply With Quote

Old   August 13, 2020, 16:01
Default
  #5
Senior Member
 
Santiago Lopez Castano
Join Date: Nov 2012
Posts: 354
Rep Power: 16
Santiago is on a distinguished road
Quote:
Originally Posted by simrego View Post
I guess this is not his "final" code since he wrote:

"The reason I need to do this is because I need to carry out some operations on the grad(U) before calculating its final divergence."
then first what you need to manipulate is the snGrad class, and then use surfaceIntegrate to obtain the divergenge of said snGrad
Santiago is offline   Reply With Quote

Reply

Tags
fvm::div, fvm::laplacian, fvmatrix


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
SU2-7.0.1 on ubuntu 18.04 hyunko SU2 Installation 7 March 16, 2020 05:37
natural convection problem for a CHT problem Se-Hee CFX 2 June 10, 2007 07:29
Adiabatic and Rotating wall (Convection problem) ParodDav CFX 5 April 29, 2007 20:13
Periodic flow boundary condition problem sudha FLUENT 3 April 28, 2004 09:40
extremely simple problem... can you solve it properly? Mikhail Main CFD Forum 40 September 9, 1999 10:11


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