
[Sponsors] 
January 30, 2013, 11:39 
Custom Source Terms

#1 
New Member
Join Date: Jan 2013
Posts: 12
Rep Power: 3 
I'm also interested in adding some custom source terms. Could you please explain the best approach to do that?


January 30, 2013, 11:51 

#2 
New Member
Amrita Lonkar
Join Date: Nov 2012
Posts: 14
Rep Power: 4 
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! Last edited by Amrita Lonkar; January 30, 2013 at 12:15. 

January 31, 2013, 01:34 

#3 
Member
Sean R. Copeland
Join Date: Jan 2013
Posts: 40
Rep Power: 3 
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. Regards, Sean 

February 18, 2013, 00:05 

#4 
New Member
Join Date: Jan 2013
Posts: 12
Rep Power: 3 
I need to use the xyz 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': Code:
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, dCx_dx,dCy_dy,dCz_dz,d2Ax_dxx,d2Ay_dyy,d2Az_dzz,dCore_dx,dCore_dy,dCore_dz, dCore_dxx,dCore_dyy,dCore_dzz,dP_dx,dP_dy,dP_dz,drho_u_dx,drho_u_dy,drho_u_dz, drho_v_dx,drho_v_dy,drho_v_dz,drho_w_dx,drho_w_dy,drho_w_dz,drho_u_dxx,drho_u_dyy, 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; 

February 20, 2013, 02:42 

#5 
Super Moderator
Thomas D. Economon
Join Date: Jan 2013
Location: Stanford, CA
Posts: 225
Rep Power: 4 
Hi,
Sounds like you are on the right track... An example might be setting the following in solution_direct_mean.cpp: Code:
/* Set coordinates */ solver>SetCoord(geometry>node[iPoint]>GetCoord(),geometry>node[iPoint]>GetCoord()); Hope this helps! 

February 28, 2013, 23:04 

#6 
New Member
Join Date: Jan 2013
Posts: 12
Rep Power: 3 
I've added the following code in the CEulerSolution::Source_Residual method:
Code:
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 */ solver>SetVolume(geometry>node[iPoint]>GetVolume()); /* Set coordinates for MMS */ solver>SetCoord(geometry>node[iPoint]>GetCoord(),geometry>node[iPoint]>GetCoord()); /* Compute Source term Residual */ solver>SetResidual(Residual, Jacobian_i, config); //MMS Modification /* Set Source Residual */ //node[iPoint]>SetRes_Sour(Residual); node[iPoint]>AddRes_Conv(Residual); } //added IF for MMS Modification } } 

March 18, 2013, 17:46 

#7 
New Member
Join Date: Jan 2013
Posts: 12
Rep Power: 3 
I'm also wondering if the source terms should be nondimensionalized. If so how are the solution variables nondimensionalized in the solver code?


March 24, 2013, 01:04 

#8  
Super Moderator
Francisco Palacios
Join Date: Jan 2013
Location: Stanford, CA
Posts: 258
Rep Power: 4 
Quote:
The nondimensionalization of the code is described in http://su2.stanford.edu/documents/SU2_AIAA_ASM2013.pdf Best, Francisco 

March 24, 2013, 22:02 

#9 
New Member
Join Date: Jan 2013
Posts: 12
Rep Power: 3 
I've been using that document, but it mentions an "internal document" by Prof. Feng Liu: "Nondimensionalization of the NavierStokes 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 nondimensionalization of the source terms (or there's a problem with this part of the code). 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
wmake compiling new solver  mksca  OpenFOAM Programming & Development  13  August 18, 2014 23:26 
groovyBC in openFOAM2.0 for parabolic velocity bc  ofslcm  OpenFOAM  22  August 26, 2013 12:06 
swak4foam building problem  GGerber  OpenFOAM  45  July 30, 2013 16:08 
funkySetFields compilation error  tayo  OpenFOAM  39  December 3, 2012 06:18 
Compiling gmshFoam with OpenFOAM1.5  BlGene  Open Source Meshers: Gmsh, Netgen, CGNS, ...  10  August 6, 2009 05:26 