CFD Online Discussion Forums

CFD Online Discussion Forums (
-   SU2 (
-   -   Custom Source Terms (

sss3700 January 30, 2013 11:39

Custom Source Terms
I'm also interested in adding some custom source terms. Could you please explain the best approach to do that?

Amrita Lonkar January 30, 2013 11:51

The best place to add new source terms to the flow equations is in the method called "Source_Template" in the file solution_direct_mean.cpp.

This method is directly connected to the rest of the code, which makes it easy to implement new source terms. You will have to specify the following option in the configuration file to activate it. SOUR_NUM_METHOD_FLOW= PIECEWISE_CONSTANT

I would also recommend that you download the new version of SU2 that will be available towards the mid of February for this particular problem, it will include some important changes to ease the implementation of new source terms.

Thanks again for your questions! Let me know if you need more assistance, we are very happy to help potential developers!

copeland January 31, 2013 01:34

Just a follow up on Amrita's comments:

The inviscid fluxes, viscous fluxes, and source terms are all handled independently of one another and you can see the structure by taking a look at CIntegration::Space_Integration in the integration_structure.cpp source code file. A selection of PIECEWISE_CONSTANT integration of the source terms allows for rapid implementation of new source terms in the CSource_Template class located in the numerics_source.cpp file.

There are plenty of examples of specialized source terms in numerics_source.cpp that you can reference as you input your own custom source terms.


sss3700 February 18, 2013 00:05

I need to use the x-y-z data for the current node in the calculation of my custom source terms. I'm trying to use the 'Coord_0' variable that I set with 'SetCoord' in 'solution_direct_mean.cpp'.

However, I get a segmentation fault when I try to use the 'Coord' variables in 'numerics_source.cpp'.

Excerpt from 'numerics_source.cpp':


void CSource_Template::SetResidual(double *val_residual, double **val_Jacobian_i, CConfig *config) {
double P,rho_u,rho_v,rho_w, xx, yy,zz,Beta_Sq,Core,L,K,A0,A1,A2,A3,
mx,my,mz, Ax,Ay,Az,dmx_dx,dmy_dy,dmz_dz,dAx_dx,dAy_dy,dAz_dz,dBx_dx,dBy_dy,dBz_dz,
drho_u_dzz,drho_v_dxx,drho_v_dyy,drho_v_dzz,drho_w_dxx,drho_w_dyy,drho_w_dzz, rho,
Beta_Squared, S1,S2,S3,S4,mu_tot;
cout << "Get Coordinates " <<endl;
xx = Coord_0[0];
yy = Coord_0[1];
zz = Coord_0[2];
cout << "Coordinates set" << endl;

economon February 20, 2013 02:42


Sounds like you are on the right track... An example might be setting the following in solution_direct_mean.cpp:


/*--- Set coordinates ---*/

and then these coordinates may be accessed in the source routine of the numerics class under the variable Coord_i, i.e. Coord_i[0], Coord_i[1], & Coord_i[2].

Hope this helps!

sss3700 February 28, 2013 23:04

I've added the following code in the CEulerSolution::Source_Residual method:


        if (MMS) {

          /*--- loop over points ---*/
          for (iPoint = 0; iPoint < geometry->GetnPointDomain(); iPoint++) {
              if ( !geometry->node[iPoint]->GetBoundary() ) {
                /*--- Set solution  ---*/
                solver->SetConservative(node[iPoint]->GetSolution(), node[iPoint]->GetSolution());

                /*--- Set incompressible density  ---*/
                solver->SetDensityInc(node[iPoint]->GetDensityInc(), node[iPoint]->GetDensityInc());
                /*--- Set beta squared  ---*/
                solver->SetBetaInc2(node[iPoint]->GetBetaInc2(), node[iPoint]->GetBetaInc2());

                /*--- Set control volume ---*/

                /*--- Set coordinates for MMS ---*/

                /*--- Compute Source term Residual ---*/
                solver->SetResidual(Residual, Jacobian_i, config); //MMS Modification

                /*--- Set Source Residual ---*/

              } //added IF for MMS Modification

Is this the correct approach for adding a constant source term?

sss3700 March 18, 2013 16:46

I'm also wondering if the source terms should be non-dimensionalized. If so how are the solution variables non-dimensionalized in the solver code?

fpalacios March 24, 2013 00:04


Originally Posted by sss3700 (Post 414795)
I'm also wondering if the source terms should be non-dimensionalized. If so how are the solution variables non-dimensionalized in the solver code?


The non-dimensionalization of the code is described in


sss3700 March 24, 2013 21:02

I've been using that document, but it mentions an "internal document" by Prof. Feng Liu: "Non-dimensionalization of the Navier-Stokes Equations" that might be the missing piece that I need.

I'm trying to write custom source terms so that I can conduct a verification of the order of accuracy of the code using the Method of Manufactured Solutions (MMS). So far it's not working, and I think it's due to the non-dimensionalization of the source terms (or there's a problem with this part of the code).

All times are GMT -4. The time now is 13:21.