CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > SU2

Adding Custom Source Terms to Euler Equations

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 15, 2020, 15:58
Default Adding Custom Source Terms to Euler Equations
  #1
New Member
 
Gabriel Giampa
Join Date: Jun 2020
Posts: 1
Rep Power: 0
gab781 is on a distinguished road
Hi all,

I'm new to CFD and su2. I'm trying to modify the c++ code to include the presence of a gravitational source term in the compressible Euler equations (SU2 Solver: EULER). There seems to be some old posts on the forum on the topic, but from many years back, and all point to files in the source code which have either changed name or simply do not exist anymore.

I know that CEulerSolver.cpp has a void CEulerSolver::Source_Template method which also informs the programmer to first implement the source term in CNumerics.cpp. Does anyone have any experience with this kind of situation? I'm not sure what kind of syntax I should be using or how exactly to implement this source term.
gab781 is offline   Reply With Quote

Old   June 16, 2020, 08:38
Default
  #2
pcg
Senior Member
 
Pedro Gomes
Join Date: Dec 2017
Posts: 466
Rep Power: 13
pcg is on a distinguished road
The code has that feature already, the relevant options are:
BODY_FORCE= YES
BODY_FORCE_VECTOR= ( 0.0, -9.81, 0.0 )
pcg is offline   Reply With Quote

Old   August 18, 2020, 14:51
Default
  #3
New Member
 
Join Date: Aug 2020
Posts: 4
Rep Power: 6
jaydm26 is on a distinguished road
Sorry to make this thread active again. Is there such a functionality for the heat equation?
jaydm26 is offline   Reply With Quote

Old   August 18, 2020, 17:32
Default
  #4
pcg
Senior Member
 
Pedro Gomes
Join Date: Dec 2017
Posts: 466
Rep Power: 13
pcg is on a distinguished road
No, I don't think we have anything that acts specifically on the heat equation (of the heat solver) nor on the energy equation (of the flow solvers).
If you are open to modify the code, this is a simple thing to do.
pcg is offline   Reply With Quote

Old   August 19, 2020, 01:26
Default
  #5
New Member
 
Join Date: Aug 2020
Posts: 4
Rep Power: 6
jaydm26 is on a distinguished road
I am open to modifying the code. I just need some guidance on what to modify as I am novice at SU2.
jaydm26 is offline   Reply With Quote

Old   August 19, 2020, 04:40
Default
  #6
pcg
Senior Member
 
Pedro Gomes
Join Date: Dec 2017
Posts: 466
Rep Power: 13
pcg is on a distinguished road
Ok, describe exactly what you want simulate and I'll tell you what to change.
pcg is offline   Reply With Quote

Old   August 19, 2020, 13:20
Default
  #7
New Member
 
Join Date: Aug 2020
Posts: 4
Rep Power: 6
jaydm26 is on a distinguished road
Thank you for helping me out! I am looking to simulate a solid heat conduction with internal heat generation that is time varying.
jaydm26 is offline   Reply With Quote

Old   August 20, 2020, 06:12
Default
  #8
pcg
Senior Member
 
Pedro Gomes
Join Date: Dec 2017
Posts: 466
Rep Power: 13
pcg is on a distinguished road
In CHeatSolver.hpp you need to declare the method
Code:
void Source_Residual(CGeometry *geometry,
                     CSolver **solver_container,
                     CNumerics **numerics_container,
                     CConfig *config,
                     unsigned short iMesh) override;
because that solver does not have it yet. If a solver has a method with this signature it will be automatically called during the spatial integration phase.

The implementation should be placed in CHeatSolver.cpp, something like:
Code:
void CHeatSolver::Source_Residual(CGeometry *geometry,
                                  CSolver **solver_container,
                                  CNumerics **numerics_container,
                                  CConfig *config,
                                  unsigned short iMesh) {

  /*--- Current time. ---*/
  const auto dt = config->GetDelta_UnstTimeND();
  const su2double t = config->GetTimeIter() * dt;

  for (auto iPoint = 0ul; iPoint < nPointDomain; iPoint++) {

    /*--- Some geometrical properties you may/will need. ---*/
    const auto V = geometry->nodes->GetVolume(iPoint);
    const auto X = geometry->nodes->GetCoord(iPoint);
    //// x = X[0], y = X[1], z = X[2] (z does not exist in 2D) ////

    /*--- Temperature at this point. ---*/
    const auto T = nodes->GetSolution(iPoint,0);

    /*--- Compute the source term. ---*/
    const su2double source = ...

    /*--- Add the source to the residual. ---*/
    LinSysRes[iPoint] += source;

    /*--- If your source depends on temperature you can also update the, 
     * Jacobian matrix. Take care not to break diagonal dominance. ---*/
    Jacobian.AddVal2Diag(iPoint, dsource_dT);
  }
}
That should get you going, you need to recompile the code after making changes (https://su2code.github.io/docs_v7/Bu...2-Linux-MacOS/) after building it the first time it's enough to run "./ninja -C build install".

If you need more help, join the Slack channel (follow the link above and click the # on the top bar) and come to one of the developers meetings (Wednesdays at 4pm CET, everyone is welcome and usually there is no agenda, so plenty of time for random questions).
pcg is offline   Reply With Quote

Old   August 20, 2020, 13:21
Default
  #9
New Member
 
Join Date: Aug 2020
Posts: 4
Rep Power: 6
jaydm26 is on a distinguished road
Wow! This is amazing! Thank you for sharing the code. I will try to implement it and let you know. Also, thank you for sharing the Slack link.
jaydm26 is offline   Reply With Quote

Reply

Tags
euler equations, source term


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
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 17:02
Trouble compiling utilities using source-built OpenFOAM Artur OpenFOAM Programming & Development 14 October 29, 2013 11:59
centOS 5.6 : paraFoam not working yossi OpenFOAM Installation 2 October 9, 2013 02:41
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 11:57
Adding source terms to turbulent models makaveli_lcf OpenFOAM Running, Solving & CFD 0 June 8, 2009 10:34


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