CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   SU2 (https://www.cfd-online.com/Forums/su2/)
-   -   Loading New Solution Variable into SU2? (https://www.cfd-online.com/Forums/su2/190204-loading-new-solution-variable-into-su2.html)

Vino July 7, 2017 10:43

Loading New Solution Variable into SU2?
 
Dear All,

I would like to add 6 new turbulent solution variables into su2 from an external file/modified restart file. These solution variables should be accessible to turbulent solver, but will remain unchanged during simulation.

Can someone please help me out on how to proceed with this implementation?

Thank you very much in advance.!!!

fpalacios August 20, 2017 10:40

Hi Vino, thanks for using SU2!
If you already have the variables in the SU2 restart file and you just want to read them the relevant subroutines are

void CTurbSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig *config, int val_iter, bool val_update_geo) in solver_direct_turbulent.cpp

void CSolver::Read_SU2_Restart_ASCII(CGeometry *geometry, CConfig *config, string val_filename) in solver_structure.cpp at the end of this subroutine you have

for (iPoint_Global = 0; iPoint_Global < geometry->GetGlobal_nPointDomain(); iPoint_Global++ ) {

getline (restart_file, text_line);

istringstream point_line(text_line);

/*--- Retrieve local index. If this node from the restart file lives
on the current processor, we will load and instantiate the vars. ---*/

iPoint_Local = geometry->GetGlobal_to_Local_Point(iPoint_Global);

if (iPoint_Local > -1) {

/*--- The PointID is not stored --*/

point_line >> index;

/*--- Store the solution (starting with node coordinates) --*/

for (iVar = 0; iVar < Restart_Vars[1]; iVar++)
point_line >> Restart_Data[counter*Restart_Vars[1] + iVar];

/*--- Increment our local point counter. ---*/

counter++;

}
}

where you read the restart file (ASCII) and store the result in

Restart_Data[counter*Restart_Vars[1] + iVar]

the size of Restart_Data is defined above

/*--- Set the number of variables, one per field in the
restart file (without including the PointID) ---*/

Restart_Vars[1] = (int)config->fields.size() - 1;

/*--- Allocate memory for the restart data. ---*/

Restart_Data = new passivedouble[Restart_Vars[1]*geometry->GetnPointDomain()];

In your case you should add

Restart_Vars[1] +=6;

only for the turbulence equation

then your go back to

void CTurbSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig *config, int val_iter, bool val_update_geo) in solver_direct_turbulent.cpp

and store the new data in Restart_Data in another variable that you can access like in the example:

if (iPoint_Local > -1) {

/*--- We need to store this point's data, so jump to the correct
offset in the buffer of data from the restart file and load it. ---*/

index = counter*Restart_Vars[1] + skipVars;
for (iVar = 0; iVar < nVar; iVar++) Solution[iVar] = Restart_Data[index+iVar];
node[iPoint_Local]->SetSolution(Solution);
iPoint_Global_Local++;

/*--- Increment the overall counter for how many points have been loaded. ---*/
counter++;
}

I hope this helps!

Thanks for using Su2,

Best,
Francisco

Vino August 20, 2017 10:58

Dear fpalacios,

Thank you very much for you detailed reply.


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