CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   SU2 (https://www.cfd-online.com/Forums/su2/)
-   -   Adding Custom Source Terms to Euler Equations (https://www.cfd-online.com/Forums/su2/227968-adding-custom-source-terms-euler-equations.html)

gab781 June 15, 2020 14:58

Adding Custom Source Terms to Euler Equations
 
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.

pcg June 16, 2020 07:38

The code has that feature already, the relevant options are:
BODY_FORCE= YES
BODY_FORCE_VECTOR= ( 0.0, -9.81, 0.0 )

jaydm26 August 18, 2020 13:51

Sorry to make this thread active again. Is there such a functionality for the heat equation?

pcg August 18, 2020 16:32

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.

jaydm26 August 19, 2020 00:26

I am open to modifying the code. I just need some guidance on what to modify as I am novice at SU2.

pcg August 19, 2020 03:40

Ok, describe exactly what you want simulate and I'll tell you what to change.

jaydm26 August 19, 2020 12:20

Thank you for helping me out! I am looking to simulate a solid heat conduction with internal heat generation that is time varying.

pcg August 20, 2020 05:12

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).

jaydm26 August 20, 2020 12:21

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.


All times are GMT -4. The time now is 12:50.