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

Implementation of adjoint equation

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 1, 2019, 09:28
Default Implementation of adjoint equation
  #1
New Member
 
Alexis Courtais
Join Date: Feb 2018
Posts: 3
Rep Power: 8
Berilmun is on a distinguished road
Hi everyone,


I am trying to implement the following equation within OpenFOAM (Ua is the adjoint velocity) :

- \nu \DeltaUa+Ua\nabla U- (\nabla Ua) U + \nabla pa = -2 \nu\DeltaU


I tried the following implementation but I'm not sure it computes the adjoint equation above


Code:
       

  volTensorField gradU (fvc::grad(U));
  volVectorField adjointTransposeConvection2(gradU.T() & Ua); 

  tmp<fvVectorMatrix> tUaEqn
  (
        fvm::div(-phi, Ua)
        +fvm::Sp(fvc::div(phi),Ua)
        + adjointTransposeConvection2
        +turbulence->divDevReff(Ua)
         ==
         fvOptions(Ua)
            );

            fvVectorMatrix& UaEqn = tUaEqn.ref();

            UaEqn.relax();

            fvOptions.constrain(UaEqn);

            solve(UaEqn == -fvc::grad(pa)-2*tau*fvc::laplacian(nu,U));
Do you have any tip about this implementation ?



Thanks in advance.
Berilmun
Berilmun is offline   Reply With Quote

Old   February 1, 2019, 11:02
Default
  #2
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 12
massive_turbulence is on a distinguished road
Quote:
Originally Posted by Berilmun View Post
Hi everyone,


I am trying to implement the following equation within OpenFOAM (Ua is the adjoint velocity) :

- \nu \DeltaUa+Ua\nabla U- (\nabla Ua) U + \nabla pa = -2 \nu\DeltaU


I tried the following implementation but I'm not sure it computes the adjoint equation above


Code:
       

  volTensorField gradU (fvc::grad(U));
  volVectorField adjointTransposeConvection2(gradU.T() & Ua); 

  tmp<fvVectorMatrix> tUaEqn
  (
        fvm::div(-phi, Ua)
        +fvm::Sp(fvc::div(phi),Ua)
        + adjointTransposeConvection2
        +turbulence->divDevReff(Ua)
         ==
         fvOptions(Ua)
            );

            fvVectorMatrix& UaEqn = tUaEqn.ref();

            UaEqn.relax();

            fvOptions.constrain(UaEqn);

            solve(UaEqn == -fvc::grad(pa)-2*tau*fvc::laplacian(nu,U));
Do you have any tip about this implementation ?



Thanks in advance.
Berilmun
Did you mix up Nabla and Delta for this part fvm::div(-phi, Ua) or the Laplacian and Divergence?
massive_turbulence is offline   Reply With Quote

Old   February 3, 2019, 11:18
Default
  #3
New Member
 
Alexis Courtais
Join Date: Feb 2018
Posts: 3
Rep Power: 8
Berilmun is on a distinguished road
The convection term - \nu \DeltaUa is described by the term turbulence->divDevReff(Ua) in the code. The term fvm::div(-phi,Ua) is only modelling - (\nabla Ua) U. That's the point on which i'm not sure in my implementation.

Thank you for the reply.
Berilmun is offline   Reply With Quote

Old   February 3, 2019, 14:59
Default
  #4
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 12
massive_turbulence is on a distinguished road
Quote:
Originally Posted by Berilmun View Post
The convection term - \nu \DeltaUa is described by the term turbulence->divDevReff(Ua) in the code. The term fvm::div(-phi,Ua) is only modelling - (\nabla Ua) U. That's the point on which i'm not sure in my implementation.

Thank you for the reply.
The call to "turbulence->divDevReff(Ua) " is more than just \nu \DeltaUa

Code:
template<class BasicTurbulenceModel>
 Foam::tmp<Foam::fvVectorMatrix>
 Foam::linearViscousStress<BasicTurbulenceModel>::divDevRhoReff
 (
     volVectorField& U
 ) const
 {
     return
     (
       - fvc::div((this->alpha_*this->rho_*this->nuEff())*dev2(T(fvc::grad(U))))
       - fvm::laplacian(this->alpha_*this->rho_*this->nuEff(), U)
     );
 }
Above code is line 91 from https://www.openfoam.com/documentati...8C_source.html

nuEff() is the effective viscosity.

dev2 is line 115 from https://www.openfoam.com/documentati...8C_source.html

Just use -fvm::laplacian(nu, Ua).
massive_turbulence is offline   Reply With Quote

Old   February 3, 2019, 16:21
Default
  #5
New Member
 
Alexis Courtais
Join Date: Feb 2018
Posts: 3
Rep Power: 8
Berilmun is on a distinguished road
Quote:
Originally Posted by massive_turbulence View Post
The call to "turbulence->divDevReff(Ua) " is more than just \nu \DeltaUa

Code:
template<class BasicTurbulenceModel>
 Foam::tmp<Foam::fvVectorMatrix>
 Foam::linearViscousStress<BasicTurbulenceModel>::divDevRhoReff
 (
     volVectorField& U
 ) const
 {
     return
     (
       - fvc::div((this->alpha_*this->rho_*this->nuEff())*dev2(T(fvc::grad(U))))
       - fvm::laplacian(this->alpha_*this->rho_*this->nuEff(), U)
     );
 }
Above code is line 91 from https://www.openfoam.com/documentati...8C_source.html

nuEff() is the effective viscosity.

dev2 is line 115 from https://www.openfoam.com/documentati...8C_source.html

Just use -fvm::laplacian(nu, Ua).
I'm working without turbulence model. I put "laminar" in my turbulenceProperties dictionary, so turbulence->divDevReff(Ua) will give me the same results than fvm::laplacian(Ua) ? I'm not right? I tried both and it gives me the same results. But you are right, it's better to put directly -fvm::laplacian(Ua). Thanks.
Do you have a tip to modeling the term (\nabla Ua)U?
Berilmun is offline   Reply With Quote

Old   February 4, 2019, 15:33
Default
  #6
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 12
massive_turbulence is on a distinguished road
Quote:
Originally Posted by Berilmun View Post
I'm working without turbulence model. I put "laminar" in my turbulenceProperties dictionary, so turbulence->divDevReff(Ua) will give me the same results than fvm::laplacian(Ua) ? I'm not right? I tried both and it gives me the same results. But you are right, it's better to put directly -fvm::laplacian(Ua). Thanks.
Do you have a tip to modeling the term (\nabla Ua)U?
My guess is it would be something like this fvm::Sp(fvc::laplacian(Ua), U)?

from here Understanding fvm::Sp()

What exactly is that term by the way, is Ua the flux?
massive_turbulence 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
Convective term in heat equation for rotating solids vabishek OpenFOAM Programming & Development 8 June 24, 2020 11:10
Current conservation equation implementation miguelmontenegro Fluent UDF and Scheme Programming 0 May 8, 2018 06:04
mass flow in is not equal to mass flow out saii CFX 12 March 19, 2018 05:21
Pressure distribution on a wall darazsbence CFX 17 October 6, 2015 10:38
Diffusion Equation izardy amiruddin Main CFD Forum 2 July 4, 2002 08:14


All times are GMT -4. The time now is 14:34.