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

How to translate code to formula?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By simrego

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 7, 2021, 10:37
Question How to translate code to formula?
  #1
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
sprayFoam had a member function called SU, which calculates the transfferd kinetic energy from the particles to the gas. This function returned value code is listed as follows.

const DimensionedField<scalar, volMesh>
Vdt(mesh_.V()*this->db().time().deltaT());

/////////////////////////////////////////////////
UTrans()/Vdt - fvm::Sp(UCoeff()/Vdt, U) + UCoeff()/Vdt*U //If U is solved semiImplicitly
/////////////////////////////////////////////////
tmp<fvVectorMatrix> tfvm(new fvVectorMatrix(U, dimForce));
fvVectorMatrix& fvm = tfvm.ref();
fvm.source() = -UTrans()/(this->db().time().deltaT()) //Other condition
/////////////////////////////////////////////////
tmp<fvVectorMatrix>(new fvVectorMatrix(U, dimForce)) //Default value

where :// Sources

//- Momentum
autoPtr<DimensionedField<vector, volMesh>> UTrans_;

//- Coefficient for carrier phase U equation
autoPtr<DimensionedField<scalar, volMesh>> UCoeff_;

My question is how to translate the code to formula? Especially the first code.

Thanks a lots!
NewKid is offline   Reply With Quote

Old   July 7, 2021, 11:29
Default
  #2
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 668
Rep Power: 14
Tobermory will become famous soon enough
It's almost impossible to understand the code you quoted ... partly because you didn't embed it using the code tags, and partly becaus you edited it leaving out the crucial parts that explain the context. Luckily I found the code that you are referring to in https://cpp.openfoam.org/v8/Kinemati...e.html#l00420:

Code:
 template<class CloudType>
 inline Foam::tmp<Foam::fvVectorMatrix>
 Foam::KinematicCloud<CloudType>::SU(volVectorField& U) const
 {
     if (debug)
     {
      ...
     }
 
     if (solution_.coupled())
     {
         if (solution_.semiImplicit("U"))
         {
             const volScalarField::Internal
                 Vdt(mesh_.V()*this->db().time().deltaT());
 
             return UTrans()/Vdt - fvm::Sp(UCoeff()/Vdt, U) + UCoeff()/Vdt*U;
         }
         else
         {
             tmp<fvVectorMatrix> tfvm(new fvVectorMatrix(U, dimForce));
             fvVectorMatrix& fvm = tfvm.ref();
 
             fvm.source() = -UTrans()/(this->db().time().deltaT());
 
             return tfvm;
         }
     }
 
     return tmp<fvVectorMatrix>(new fvVectorMatrix(U, dimForce));
 }
So what is this doing? Well, this is calculating the source term that derives from the droplets, that is then used in the UEqn of the solver:

Code:
 tmp<fvVectorMatrix> tUEqn
 (
     fvm::ddt(rho, U) + fvm::div(phi, U)
   + MRF.DDt(rho, U)
   + turbulence->divDevTau(U)
  ==
     rho()*g
   + parcels.SU(U)
   + fvOptions(rho, U)
 );
If an implicit approach is being taken then it creates a volScalarField called Vdt (cell volume times timestep) and then generates an explicit source term using UTrans and Vdt. In fact, it's more cunning than that since part of the explicit source term is moved into the implicit source term (the fvm::Sp() term), and this is offset/negated by the last term on the line.

If the approach is not implicit, then it just calculates just an explicit source term.

Hopefully that should be enough for you to dig down into the details. Good luck!
Tobermory is offline   Reply With Quote

Old   July 7, 2021, 15:27
Default
  #3
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
Thanks!
I have already read the code. What I expect is the PDE/ODE expression "translated" from the code.
NewKid is offline   Reply With Quote

Old   July 7, 2021, 15:30
Default
  #4
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
By the way, I still use OpenFoam 4.X.
NewKid is offline   Reply With Quote

Old   July 7, 2021, 16:12
Default
  #5
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 668
Rep Power: 14
Tobermory will become famous soon enough
ok ... this routine calculates source term:

S_U = - \frac{T}{\delta t}

where T is the momentum transfer term. I would have thought that was obvious from what I have written above, and I was trying to help you understand the code so that you could solve it yourself next time ...
Tobermory is offline   Reply With Quote

Old   July 8, 2021, 03:19
Default
  #6
Senior Member
 
LT
Join Date: Dec 2010
Posts: 104
Rep Power: 15
NewKid is on a distinguished road
Thanks once again.
What I mean is the "translation" of those two sentences in the code.
const volScalarField::Internal
Vdt(mesh_.V()*this->db().time().deltaT());

return UTrans()/Vdt - fvm::Sp(UCoeff()/Vdt, U) + UCoeff()/Vdt*U;
Especially the last senetence. Is it right?
Su=Utrans/deltaT-UCoeff/Vdt*U + UCoeff/Vdt*U? where Vdt = V*deltaT, V is the droplet velocity?
That's the point I want to know.
Best regards!
NewKid is offline   Reply With Quote

Old   July 8, 2021, 03:59
Default
  #7
Senior Member
 
anonymous
Join Date: Jan 2016
Posts: 416
Rep Power: 14
simrego is on a distinguished road
Use CODE TAGS for these long stuff man.... It is impossible to read this...

No. mesh_.V() returns the cell volumes. So Vdt is the cell volume multiplied by the timestep. The velocity is usually called U everywhere.


BTW:
Code tags (You have to remove the spaces after first "CODE" !!! I just inserted so you can see the syntax):
[CODE ] void thisIsADumbCode(int, int) {...} [/CODE]
And it'll be:
Code:
 void thisIsADumbCode(int, int) {...}
Tobermory likes this.
simrego is offline   Reply With Quote

Old   July 8, 2021, 05:01
Default
  #8
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 668
Rep Power: 14
Tobermory will become famous soon enough
If you really want to dig into the code and understand it, then first up - well done, that's the only way you will really understand how OpenFOAM works; secondly - buckle up, since you've got a heck of a ride in front of you! The lot's to get your head around. One bit of advice is that the Doxygen pages are REALLY useful for finding code, and tracking down variables etc ... there is a version for v4:

https://cpp.openfoam.org/v4/classFoa...20320c31fba00c

the page I quoted has the class ref for V() - click on the metalink 186 to take you through to line 186 of the code etc. Also, read the header code in the associated .H files, and slowly you will start to build up the picture.

Good luck again.
Tobermory is offline   Reply With Quote

Reply

Tags
sprayfoam, su, utrans, ucoeff


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
[OpenFOAM] ParaView command in Foam-extend-4.1 mitu_94 ParaView 0 March 4, 2021 13:46
Fortran->Assembly : How to remove redundant non-vectorized code? aerosayan Main CFD Forum 6 November 20, 2020 05:37
The FOAM Documentation Project - SHUT-DOWN holger_marschall OpenFOAM 242 March 7, 2013 12:30
Error in CFX Solver Leuchte CFX 5 November 6, 2010 06:12
Small 3-D code Zdravko Stojanovic Main CFD Forum 2 July 19, 2010 10:11


All times are GMT -4. The time now is 07:56.