CHeatSolver::CHeatSolver(CGeometry *geometry, CConfig *config) : CSolver() { unsigned short nMarker, iVar; unsigned long iPoint; int rank = MASTER_NODE; #ifndef NO_MPI rank = MPI::COMM_WORLD.Get_rank(); #endif nPoint = geometry->GetnPoint(); nPointDomain = geometry->GetnPointDomain(); nDim = geometry->GetnDim(); nMarker = config->GetnMarker_All(); node = new CVariable*[nPoint]; nVar = 1; Residual = new double[nVar]; Residual_RMS = new double[nVar]; Solution = new double[nVar]; Res_Sour = new double[nVar]; Residual_Max = new double[nVar]; Point_Max = new unsigned long[nVar]; /*--- Point to point stiffness matrix (only for triangles)---*/ StiffMatrix_Elem = new double*[nDim+1]; for (iVar = 0; iVar < nDim+1; iVar++) { StiffMatrix_Elem[iVar] = new double [nDim+1]; } StiffMatrix_Node = new double*[nVar]; for (iVar = 0; iVar < nVar; iVar++) { StiffMatrix_Node[iVar] = new double [nVar]; } /*--- Initialization of matrix structures ---*/ StiffMatrixSpace.Initialize(nPoint, nPointDomain, nVar, nVar, geometry); StiffMatrixTime.Initialize(nPoint, nPointDomain, nVar, nVar, geometry); if (rank == MASTER_NODE) cout << "Initialize jacobian structure (Linear Elasticity)." << endl; Jacobian.Initialize(nPoint, nPointDomain, nVar, nVar, geometry); /*--- Initialization of linear solver structures ---*/ LinSysSol.Initialize(nPoint, nPointDomain, nVar, 0.0); LinSysRes.Initialize(nPoint, nPointDomain, nVar, 0.0); LinSysAux.Initialize(nPoint, nPointDomain, nVar, 0.0); /*--- Heat coefficient for all of the markers ---*/ CHeat = new double[config->GetnMarker_All()]; Total_CHeat = 0.0; /*--- Check for a restart (not really used), initialize from zero otherwise ---*/ bool restart = (config->GetRestart()); if (!restart) { for (iPoint = 0; iPoint < nPoint; iPoint++) { /*--- Zero initial condition for testing source terms & forcing BCs ---*/ Solution[0] = 0.0; Solution[1] = 0.0; node[iPoint] = new CHeatVariable(Solution, nDim, nVar, config); /*--- Copy solution to old containers if using dual time ---*/ if (config->GetUnsteady_Simulation() == DT_STEPPING_1ST) { node[iPoint]->Set_Solution_time_n(); } else if (config->GetUnsteady_Simulation() == DT_STEPPING_2ND) { node[iPoint]->Set_Solution_time_n(); node[iPoint]->Set_Solution_time_n1(); } } } else { cout << "Heat restart file not currently configured!!" << endl; cout << "Press any key to exit..." << endl; cin.get(); exit(1); string mesh_filename = config->GetSolution_FlowFileName(); ifstream restart_file; char *cstr; cstr = new char [mesh_filename.size()+1]; strcpy (cstr, mesh_filename.c_str()); restart_file.open(cstr, ios::in); if (restart_file.fail()) { cout << "There is no Heat restart file!!" << endl; cout << "Press any key to exit..." << endl; cin.get(); exit(1); } unsigned long index; string text_line; for(unsigned long iPoint = 0; iPoint < nPoint; iPoint++) { getline(restart_file,text_line); istringstream point_line(text_line); point_line >> index >> Solution[0] >> Solution[1]; node[iPoint] = new CHeatVariable(Solution, nDim, nVar, config); } restart_file.close(); } }
CDiscAdjSolver::CDiscAdjSolver(CGeometry *geometry, CConfig *config, CSolver *direct_solver, unsigned short Kind_Solver, unsigned short iMesh) : CSolver(){ unsigned short iVar, iMarker, iDim; bool restart = config->GetRestart(); unsigned long iVertex, iPoint, index; string text_line, mesh_filename; ifstream restart_file; string filename, AdjExt; su2double dull_val; int rank = MASTER_NODE; #ifdef HAVE_MPI MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif nVar = direct_solver->GetnVar(); nDim = geometry->GetnDim(); /*-- Store some information about direct solver ---*/ this->KindDirect_Solver = Kind_Solver; this->direct_solver = direct_solver; nMarker = config->GetnMarker_All(); nPoint = geometry->GetnPoint(); nPointDomain = geometry->GetnPointDomain(); /*--- Allocate the node variables ---*/ node = new CVariable*[nPoint]; /*--- Define some auxiliary vectors related to the residual ---*/ Residual = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Residual[iVar] = 1.0; Residual_RMS = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Residual_RMS[iVar] = 1.0; Residual_Max = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Residual_Max[iVar] = 1.0; /*--- Define some structures for locating max residuals ---*/ Point_Max = new unsigned long[nVar]; for (iVar = 0; iVar < nVar; iVar++) Point_Max[iVar] = 0; Point_Max_Coord = new su2double*[nVar]; for (iVar = 0; iVar < nVar; iVar++) { Point_Max_Coord[iVar] = new su2double[nDim]; for (iDim = 0; iDim < nDim; iDim++) Point_Max_Coord[iVar][iDim] = 0.0; } /*--- Define some auxiliary vectors related to the solution ---*/ Solution = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Solution[iVar] = 1e-16; /*--- Sensitivity definition and coefficient in all the markers ---*/ CSensitivity = new su2double* [nMarker]; for (iMarker = 0; iMarker < nMarker; iMarker++) { CSensitivity[iMarker] = new su2double [geometry->nVertex[iMarker]]; } Sens_Geo = new su2double[nMarker]; Sens_Mach = new su2double[nMarker]; Sens_AoA = new su2double[nMarker]; Sens_Press = new su2double[nMarker]; Sens_Temp = new su2double[nMarker]; for (iMarker = 0; iMarker < nMarker; iMarker++) { Sens_Geo[iMarker] = 0.0; Sens_Mach[iMarker] = 0.0; Sens_AoA[iMarker] = 0.0; Sens_Press[iMarker] = 0.0; Sens_Temp[iMarker] = 0.0; for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++){ CSensitivity[iMarker][iVertex] = 0.0; } } /*--- Check for a restart and set up the variables at each node appropriately. Coarse multigrid levels will be intitially set to the farfield values bc the solver will immediately interpolate the solution from the finest mesh to the coarser levels. ---*/ if (!restart || (iMesh != MESH_0)) { /*--- Restart the solution from zero ---*/ for (iPoint = 0; iPoint < nPoint; iPoint++) node[iPoint] = new CDiscAdjVariable(Solution, nDim, nVar, config); } else { /*--- Restart the solution from file information ---*/ mesh_filename = config->GetSolution_AdjFileName(); filename = config->GetObjFunc_Extension(mesh_filename); restart_file.open(filename.data(), ios::in); /*--- In case there is no file ---*/ if (restart_file.fail()) { if (rank == MASTER_NODE) cout << "There is no adjoint restart file!! " << filename.data() << "."<< endl; exit(EXIT_FAILURE); } /*--- In case this is a parallel simulation, we need to perform the Global2Local index transformation first. ---*/ long *Global2Local; Global2Local = new long[geometry->GetGlobal_nPointDomain()]; /*--- First, set all indices to a negative value by default ---*/ for (iPoint = 0; iPoint < geometry->GetGlobal_nPointDomain(); iPoint++) { Global2Local[iPoint] = -1; } /*--- Now fill array with the transform values only for local points ---*/ for (iPoint = 0; iPoint < nPointDomain; iPoint++) { Global2Local[geometry->node[iPoint]->GetGlobalIndex()] = iPoint; } /*--- Read all lines in the restart file ---*/ long iPoint_Local; unsigned long iPoint_Global = 0;\ /*--- Skip coordinates ---*/ unsigned short skipVars = nDim; /*--- Skip flow adjoint variables ---*/ if (Kind_Solver == RUNTIME_TURB_SYS){ skipVars += nDim+2; } /*--- The first line is the header ---*/ getline (restart_file, text_line); while (getline (restart_file, text_line)) { istringstream point_line(text_line); /*--- Retrieve local index. If this node from the restart file lives on a different processor, the value of iPoint_Local will be -1. Otherwise, the local index for this node on the current processor will be returned and used to instantiate the vars. ---*/ iPoint_Local = Global2Local[iPoint_Global]; if (iPoint_Local >= 0) { point_line >> index; for (iVar = 0; iVar < skipVars; iVar++){ point_line >> dull_val;} for (iVar = 0; iVar < nVar; iVar++){ point_line >> Solution[iVar];} node[iPoint_Local] = new CDiscAdjVariable(Solution, nDim, nVar, config); } iPoint_Global++; } /*--- Instantiate the variable class with an arbitrary solution at any halo/periodic nodes. The initial solution can be arbitrary, because a send/recv is performed immediately in the solver. ---*/ for (iPoint = nPointDomain; iPoint < nPoint; iPoint++) { node[iPoint] = new CDiscAdjVariable(Solution, nDim, nVar, config); } /*--- Close the restart file ---*/ restart_file.close(); /*--- Free memory needed for the transformation ---*/ delete [] Global2Local; }
CWaveSolver::CWaveSolver(CGeometry *geometry, CConfig *config) : CSolver() { unsigned short nMarker, iDim, iVar, nLineLets; int rank = MASTER_NODE; #ifdef HAVE_MPI MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif nPoint = geometry->GetnPoint(); nPointDomain = geometry->GetnPointDomain(); nDim = geometry->GetnDim(); nMarker = config->GetnMarker_All(); node = new CVariable*[nPoint]; nVar = 2; // solve as a 2 eq. system Residual = new double[nVar]; Residual_RMS = new double[nVar]; Solution = new double[nVar]; Res_Sour = new double[nVar]; Residual_Max = new double[nVar]; /*--- Define some structures for locating max residuals ---*/ Point_Max = new unsigned long[nVar]; for (iVar = 0; iVar < nVar; iVar++) Point_Max[iVar] = 0; Point_Max_Coord = new double*[nVar]; for (iVar = 0; iVar < nVar; iVar++) { Point_Max_Coord[iVar] = new double[nDim]; for (iDim = 0; iDim < nDim; iDim++) Point_Max_Coord[iVar][iDim] = 0.0; } /*--- Point to point stiffness matrix (only for triangles)---*/ StiffMatrix_Elem = new double*[nDim+1]; for (iVar = 0; iVar < nDim+1; iVar++) { StiffMatrix_Elem[iVar] = new double [nDim+1]; } StiffMatrix_Node = new double*[nVar]; for (iVar = 0; iVar < nVar; iVar++) { StiffMatrix_Node[iVar] = new double [nVar]; } /*--- Initialization of matrix structures ---*/ StiffMatrixSpace.Initialize(nPoint, nPointDomain, nVar, nVar, true, geometry, config); StiffMatrixTime.Initialize(nPoint, nPointDomain, nVar, nVar, true, geometry, config); Jacobian.Initialize(nPoint, nPointDomain, nVar, nVar, true, geometry, config); if ((config->GetKind_Linear_Solver_Prec() == LINELET) || (config->GetKind_Linear_Solver() == SMOOTHER_LINELET)) { nLineLets = Jacobian.BuildLineletPreconditioner(geometry, config); if (rank == MASTER_NODE) cout << "Compute linelet structure. " << nLineLets << " elements in each line (average)." << endl; } /*--- Initialization of linear solver structures ---*/ LinSysSol.Initialize(nPoint, nPointDomain, nVar, 0.0); LinSysRes.Initialize(nPoint, nPointDomain, nVar, 0.0); /* Wave strength coefficient for all of the markers */ CWave = new double[config->GetnMarker_All()]; Total_CWave = 0.0; /* Check for a restart (not really used), initialize from zero otherwise */ bool restart = (config->GetRestart()); if (!restart) { double *Coord, Radius; for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) { /*--- Set up the initial condition for the drum problem ---*/ Coord = geometry->node[iPoint]->GetCoord(); Radius = 0.0; for (unsigned short iDim = 0; iDim < nDim; iDim++) Radius += Coord[iDim]*Coord[iDim]; Radius = sqrt(Radius); /*--- Symmetrically plucked drum ---*/ // Solution[0] = 1.0 - Radius; // Solution[1] = 0.0; /*--- Off-center strike ---*/ // if ((Radius > 0.4) && (Radius < 0.6)) { // Solution[0] = 10.0; // } else // Solution[0] = 0.0; // Solution[1] = 0.0; /*--- Struck drum ---*/ // Solution[0] = 0.0; // Solution[1] = -1.0; /*--- Zero initial condition for testing source terms & forcing BCs ---*/ Solution[0] = 0.0; Solution[1] = 0.0; node[iPoint] = new CWaveVariable(Solution, nDim, nVar, config); /* Copy solution to old containers if using dual time */ if (config->GetUnsteady_Simulation() == DT_STEPPING_1ST) { node[iPoint]->Set_Solution_time_n(); } else if (config->GetUnsteady_Simulation() == DT_STEPPING_2ND) { node[iPoint]->Set_Solution_time_n(); node[iPoint]->Set_Solution_time_n1(); } } } else { cout << "Wave restart file not currently configured!!" << endl; exit(EXIT_FAILURE); string mesh_filename = config->GetSolution_FlowFileName(); ifstream restart_file; char *cstr; cstr = new char [mesh_filename.size()+1]; strcpy (cstr, mesh_filename.c_str()); restart_file.open(cstr, ios::in); if (restart_file.fail()) { if (rank == MASTER_NODE) cout << "There is no wave restart file!!" << endl; exit(EXIT_FAILURE); } unsigned long index; string text_line; for(unsigned long iPoint = 0; iPoint < nPoint; iPoint++) { getline(restart_file,text_line); istringstream point_line(text_line); point_line >> index >> Solution[0] >> Solution[1]; node[iPoint] = new CWaveVariable(Solution, nDim, nVar, config); } restart_file.close(); } }
void CWaveSolver::LoadRestart(CGeometry **geometry, CSolver ***solver, CConfig *config, int val_iter) { int rank; #ifdef HAVE_MPI MPI_Comm_rank(MPI_COMM_WORLD, &rank); #else rank = MASTER_NODE; #endif /*--- Restart the solution from file information ---*/ string restart_filename = config->GetRestart_WaveFileName(); unsigned long iPoint, index, nFlowIter, adjIter, flowIter; char buffer[50]; string UnstExt, text_line; ifstream restart_file; /*--- For the unsteady adjoint, we integrate backwards through physical time, so load in the direct solution files in reverse. ---*/ if (config->GetUnsteady_Simulation() && config->GetWrt_Unsteady()) { nFlowIter = config->GetnExtIter(); adjIter = config->GetExtIter(); flowIter = nFlowIter - adjIter - 1; unsigned short lastindex = restart_filename.find_last_of("."); restart_filename = restart_filename.substr(0, lastindex); if ((int(flowIter) >= 0) && (int(flowIter) < 10)) sprintf (buffer, "_0000%d.dat", int(flowIter)); if ((int(flowIter) >= 10) && (int(flowIter) < 100)) sprintf (buffer, "_000%d.dat", int(flowIter)); if ((int(flowIter) >= 100) && (int(flowIter) < 1000)) sprintf (buffer, "_00%d.dat", int(flowIter)); if ((int(flowIter) >= 1000) && (int(flowIter) < 10000)) sprintf (buffer, "_0%d.dat", int(flowIter)); if (int(flowIter) >= 10000) sprintf (buffer, "_%d.dat", int(flowIter)); UnstExt = string(buffer); restart_filename.append(UnstExt); } else { flowIter =config->GetExtIter(); unsigned short lastindex = restart_filename.find_last_of("."); restart_filename = restart_filename.substr(0, lastindex); if ((int(flowIter) >= 0) && (int(flowIter) < 10)) sprintf (buffer, "_0000%d.dat", int(flowIter)); if ((int(flowIter) >= 10) && (int(flowIter) < 100)) sprintf (buffer, "_000%d.dat", int(flowIter)); if ((int(flowIter) >= 100) && (int(flowIter) < 1000)) sprintf (buffer, "_00%d.dat", int(flowIter)); if ((int(flowIter) >= 1000) && (int(flowIter) < 10000)) sprintf (buffer, "_0%d.dat", int(flowIter)); if (int(flowIter) >= 10000) sprintf (buffer, "_%d.dat", int(flowIter)); UnstExt = string(buffer); restart_filename.append(UnstExt); } /*--- Open the flow solution from the restart file ---*/ if (rank == MASTER_NODE) cout << "Reading in the direct wave solution from iteration " << flowIter << "." << endl;; restart_file.open(restart_filename.data(), ios::in); /*--- In case there is no file ---*/ if (restart_file.fail()) { if (rank == MASTER_NODE) cout << "There is no wave restart file!!" << endl; exit(EXIT_FAILURE); } /*--- Read the restart file ---*/ for(iPoint = 0; iPoint < geometry[MESH_0]->GetnPoint(); iPoint++) { getline(restart_file,text_line); istringstream point_line(text_line); point_line >> index >> Solution[0] >> Solution[1]; node[iPoint]->SetSolution_Direct(Solution); } /*--- Close the restart file ---*/ restart_file.close(); }
CHeatSolver::CHeatSolver(CGeometry *geometry, CConfig *config) : CSolver() { unsigned short iDim, iVar, nLineLets; unsigned long iPoint; int rank = MASTER_NODE; #ifdef HAVE_MPI MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif nPoint = geometry->GetnPoint(); nPointDomain = geometry->GetnPointDomain(); nDim = geometry->GetnDim(); node = new CVariable*[nPoint]; nVar = 1; Residual = new su2double[nVar]; Residual_RMS = new su2double[nVar]; Solution = new su2double[nVar]; Res_Sour = new su2double[nVar]; Residual_Max = new su2double[nVar]; Point_Max = new unsigned long[nVar]; Point_Max_Coord = new su2double*[nVar]; for (iVar = 0; iVar < nVar; iVar++) { Point_Max_Coord[iVar] = new su2double[nDim]; for (iDim = 0; iDim < nDim; iDim++) Point_Max_Coord[iVar][iDim] = 0.0; } /*--- Point to point stiffness matrix (only for triangles)---*/ StiffMatrix_Elem = new su2double*[nDim+1]; for (iVar = 0; iVar < nDim+1; iVar++) { StiffMatrix_Elem[iVar] = new su2double [nDim+1]; } StiffMatrix_Node = new su2double*[nVar]; for (iVar = 0; iVar < nVar; iVar++) { StiffMatrix_Node[iVar] = new su2double [nVar]; } /*--- Initialization of matrix structures ---*/ StiffMatrixSpace.Initialize(nPoint, nPointDomain, nVar, nVar, true, geometry, config); StiffMatrixTime.Initialize(nPoint, nPointDomain, nVar, nVar, true, geometry, config); if (rank == MASTER_NODE) cout << "Initialize Jacobian structure (Linear Elasticity)." << endl; Jacobian.Initialize(nPoint, nPointDomain, nVar, nVar, true, geometry, config); if ((config->GetKind_Linear_Solver_Prec() == LINELET) || (config->GetKind_Linear_Solver() == SMOOTHER_LINELET)) { nLineLets = Jacobian.BuildLineletPreconditioner(geometry, config); if (rank == MASTER_NODE) cout << "Compute linelet structure. " << nLineLets << " elements in each line (average)." << endl; } /*--- Initialization of linear solver structures ---*/ LinSysSol.Initialize(nPoint, nPointDomain, nVar, 0.0); LinSysRes.Initialize(nPoint, nPointDomain, nVar, 0.0); LinSysAux.Initialize(nPoint, nPointDomain, nVar, 0.0); /*--- Heat coefficient for all of the markers ---*/ CHeat = new su2double[config->GetnMarker_All()]; Total_CHeat = 0.0; /*--- Check for a restart (not really used), initialize from zero otherwise ---*/ bool restart = (config->GetRestart()); if (!restart) { for (iPoint = 0; iPoint < nPoint; iPoint++) { /*--- Zero initial condition for testing source terms & forcing BCs ---*/ Solution[0] = 0.0; Solution[1] = 0.0; node[iPoint] = new CHeatVariable(Solution, nDim, nVar, config); /*--- Copy solution to old containers if using dual time ---*/ if (config->GetUnsteady_Simulation() == DT_STEPPING_1ST) { node[iPoint]->Set_Solution_time_n(); } else if (config->GetUnsteady_Simulation() == DT_STEPPING_2ND) { node[iPoint]->Set_Solution_time_n(); node[iPoint]->Set_Solution_time_n1(); } } } else { cout << "Heat restart file not currently configured!!" << endl; string mesh_filename = config->GetSolution_FlowFileName(); ifstream restart_file; char *cstr; cstr = new char [mesh_filename.size()+1]; strcpy (cstr, mesh_filename.c_str()); restart_file.open(cstr, ios::in); if (restart_file.fail()) { cout << "There is no Heat restart file!!" << endl; exit(EXIT_FAILURE); } unsigned long index; string text_line; for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) { getline(restart_file, text_line); istringstream point_line(text_line); point_line >> index >> Solution[0] >> Solution[1]; node[iPoint] = new CHeatVariable(Solution, nDim, nVar, config); } restart_file.close(); } }
/** @param line Un segment de droite @param point Un point @return true si le point appartient au segment de droite, false sinon */ bool QET::lineContainsPoint(const QLineF &line, const QPointF &point) { if (point == line.p1()) return(true); QLineF point_line(line.p1(), point); if (point_line.unitVector() != line.unitVector()) return(false); return(point_line.length() <= line.length()); }
void CHeatSolver::GetRestart(CGeometry *geometry, CConfig *config) { #ifndef NO_MPI int rank = MPI::COMM_WORLD.Get_rank(); #else int rank = MASTER_NODE; #endif /*--- Restart the solution from file information ---*/ string restart_filename = config->GetRestart_HeatFileName(); unsigned long iPoint, index, nFlowIter, adjIter, flowIter; char buffer[50]; string UnstExt, text_line; ifstream restart_file; /*--- For the unsteady adjoint, we integrate backwards through physical time, so load in the direct solution files in reverse. ---*/ if (config->GetUnsteady_Simulation() && config->GetWrt_Unsteady()) { nFlowIter = config->GetnExtIter(); adjIter = config->GetExtIter(); flowIter = nFlowIter - adjIter - 1; restart_filename.erase (restart_filename.end()-4, restart_filename.end()); if ((int(flowIter) >= 0) && (int(flowIter) < 10)) sprintf (buffer, "_0000%d.dat", int(flowIter)); if ((int(flowIter) >= 10) && (int(flowIter) < 100)) sprintf (buffer, "_000%d.dat", int(flowIter)); if ((int(flowIter) >= 100) && (int(flowIter) < 1000)) sprintf (buffer, "_00%d.dat", int(flowIter)); if ((int(flowIter) >= 1000) && (int(flowIter) < 10000)) sprintf (buffer, "_0%d.dat", int(flowIter)); if (int(flowIter) >= 10000) sprintf (buffer, "_%d.dat", int(flowIter)); UnstExt = string(buffer); restart_filename.append(UnstExt); } else { flowIter =config->GetExtIter(); restart_filename.erase (restart_filename.end()-4, restart_filename.end()); if ((int(flowIter) >= 0) && (int(flowIter) < 10)) sprintf (buffer, "_0000%d.dat", int(flowIter)); if ((int(flowIter) >= 10) && (int(flowIter) < 100)) sprintf (buffer, "_000%d.dat", int(flowIter)); if ((int(flowIter) >= 100) && (int(flowIter) < 1000)) sprintf (buffer, "_00%d.dat", int(flowIter)); if ((int(flowIter) >= 1000) && (int(flowIter) < 10000)) sprintf (buffer, "_0%d.dat", int(flowIter)); if (int(flowIter) >= 10000) sprintf (buffer, "_%d.dat", int(flowIter)); UnstExt = string(buffer); restart_filename.append(UnstExt); } /*--- Open the flow solution from the restart file ---*/ if (rank == MASTER_NODE) cout << "Reading in the direct heat solution from iteration " << flowIter << "." << endl;; restart_file.open(restart_filename.data(), ios::in); /*--- In case there is no file ---*/ if (restart_file.fail()) { cout << "There is no Heat restart file!!" << endl; cout << "Press any key to exit..." << endl; cin.get(); exit(1); } /*--- Read the restart file ---*/ for(iPoint = 0; iPoint < geometry->GetnPoint(); iPoint++) { getline(restart_file,text_line); istringstream point_line(text_line); point_line >> index >> Solution[0] >> Solution[1]; node[iPoint]->SetSolution_Direct(Solution); } /*--- Close the restart file ---*/ restart_file.close(); }
CHeatSolver::CHeatSolver(CGeometry *geometry, CConfig *config) : CSolver() { unsigned short nMarker, iVar; nPoint = geometry->GetnPoint(); nPointDomain = geometry->GetnPointDomain(); nDim = geometry->GetnDim(); nMarker = config->GetnMarker_All(); node = new CVariable*[nPoint]; nVar = 2; // solve as a 2 eq. system Residual = new double[nVar]; Residual_RMS = new double[nVar]; Solution = new double[nVar]; Res_Sour = new double[nVar]; Residual_Max = new double[nVar]; Point_Max = new unsigned long[nVar]; /*--- Point to point stiffness matrix (only for triangles)---*/ StiffMatrix_Elem = new double*[nDim+1]; for (iVar = 0; iVar < nDim+1; iVar++) { StiffMatrix_Elem[iVar] = new double [nDim+1]; } StiffMatrix_Node = new double*[nVar]; for (iVar = 0; iVar < nVar; iVar++) { StiffMatrix_Node[iVar] = new double [nVar]; } /*--- Initialization of matrix structures ---*/ StiffMatrixSpace.Initialize(nPoint, nPointDomain, nVar, nVar, geometry); StiffMatrixTime.Initialize(nPoint, nPointDomain, nVar, nVar, geometry); Jacobian.Initialize(nPoint, nPointDomain, nVar, nVar, geometry); /*--- Initialization of linear solver structures ---*/ LinSysSol.Initialize(nPoint, nPointDomain, nVar, 0.0); LinSysRes.Initialize(nPoint, nPointDomain, nVar, 0.0); /* Heat strength coefficient for all of the markers */ CHeat = new double[config->GetnMarker_All()]; Total_CHeat = 0.0; /* Check for a restart (not really used), initialize from zero otherwise */ bool restart = (config->GetRestart()); if (!restart) { double *Coord, Radius; for (unsigned long iPoint = 0; iPoint < nPoint; iPoint++) { /*--- Set up the initial condition for the drum problem ---*/ Coord = geometry->node[iPoint]->GetCoord(); Radius = 0.0; for (unsigned short iDim = 0; iDim < nDim; iDim++) Radius += Coord[iDim]*Coord[iDim]; Radius = sqrt(Radius); /*--- Symmetrically plucked drum ---*/ // Solution[0] = 1.0 - Radius; // Solution[1] = 0.0; /*--- Off-center strike ---*/ // if ((Radius > 0.4) && (Radius < 0.6)) { // Solution[0] = 10.0; // } else // Solution[0] = 0.0; // Solution[1] = 0.0; /*--- Struck drum ---*/ // Solution[0] = 0.0; // Solution[1] = -1.0; /*--- Zero initial condition for testing source terms & forcing BCs ---*/ Solution[0] = 0.0; Solution[1] = 0.0; node[iPoint] = new CHeatVariable(Solution, nDim, nVar, config); /* Copy solution to old containers if using dual time */ if (config->GetUnsteady_Simulation() == DT_STEPPING_1ST) { node[iPoint]->Set_Solution_time_n(); } else if (config->GetUnsteady_Simulation() == DT_STEPPING_2ND) { node[iPoint]->Set_Solution_time_n(); node[iPoint]->Set_Solution_time_n1(); } } } else { cout << "Heat restart file not currently configured!!" << endl; cout << "Press any key to exit..." << endl; cin.get(); exit(1); string mesh_filename = config->GetSolution_FlowFileName(); ifstream restart_file; char *cstr; cstr = new char [mesh_filename.size()+1]; strcpy (cstr, mesh_filename.c_str()); restart_file.open(cstr, ios::in); if (restart_file.fail()) { cout << "There is no Heat restart file!!" << endl; cout << "Press any key to exit..." << endl; cin.get(); exit(1); } unsigned long index; string text_line; for(unsigned long iPoint = 0; iPoint < nPoint; iPoint++) { getline(restart_file,text_line); istringstream point_line(text_line); point_line >> index >> Solution[0] >> Solution[1]; node[iPoint] = new CHeatVariable(Solution, nDim, nVar, config); } restart_file.close(); } /* Load all of the matrices and Jacobians that are fixed */ /* during the simulation in order to save effort. */ //SetTime_Matrix(geometry, config); }
CDiscAdjFEASolver::CDiscAdjFEASolver(CGeometry *geometry, CConfig *config, CSolver *direct_solver, unsigned short Kind_Solver, unsigned short iMesh) : CSolver(){ unsigned short iVar, iMarker, iDim; bool restart = config->GetRestart(); bool fsi = config->GetFSI_Simulation(); restart = false; unsigned long iVertex, iPoint, index; string text_line, mesh_filename; ifstream restart_file; string filename, AdjExt; su2double dull_val; bool dynamic = (config->GetDynamic_Analysis() == DYNAMIC); bool compressible = (config->GetKind_Regime() == COMPRESSIBLE); bool incompressible = (config->GetKind_Regime() == INCOMPRESSIBLE); nVar = direct_solver->GetnVar(); nDim = geometry->GetnDim(); /*-- Store some information about direct solver ---*/ this->KindDirect_Solver = Kind_Solver; this->direct_solver = direct_solver; nMarker = config->GetnMarker_All(); nPoint = geometry->GetnPoint(); nPointDomain = geometry->GetnPointDomain(); /*-- Store number of markers with a normal load boundary condition ---*/ normalLoads = NULL; nMarker_nL = 0; // nMarker_nL = 0; // for (iMarker = 0; iMarker < nMarker; iMarker++) { // switch (config->GetMarker_All_KindBC(iMarker)) { // case LOAD_BOUNDARY: // nMarker_nL += 1; // break; // } // } // // normalLoads = new su2double[nMarker_nL]; // /*--- Store the value of the normal loads ---*/ // for (iMarker = 0; iMarker < nMarker; iMarker++) { // switch (config->GetMarker_All_KindBC(iMarker)) { // case LOAD_BOUNDARY: // normalLoads[iMarker] = config->GetLoad_Value(config->GetMarker_All_TagBound(iMarker)); // break; // } // } /*--- Allocate the node variables ---*/ node = new CVariable*[nPoint]; /*--- Define some auxiliary vectors related to the residual ---*/ Residual = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Residual[iVar] = 1.0; Residual_RMS = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Residual_RMS[iVar] = 1.0; Residual_Max = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Residual_Max[iVar] = 1.0; /*--- Define some structures for locating max residuals ---*/ Point_Max = new unsigned long[nVar]; for (iVar = 0; iVar < nVar; iVar++) Point_Max[iVar] = 0; Point_Max_Coord = new su2double*[nVar]; for (iVar = 0; iVar < nVar; iVar++) { Point_Max_Coord[iVar] = new su2double[nDim]; for (iDim = 0; iDim < nDim; iDim++) Point_Max_Coord[iVar][iDim] = 0.0; } /*--- Define some auxiliary vectors related to the residual for problems with a BGS strategy---*/ if (fsi){ Residual_BGS = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Residual_BGS[iVar] = 1.0; Residual_Max_BGS = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Residual_Max_BGS[iVar] = 1.0; /*--- Define some structures for locating max residuals ---*/ Point_Max_BGS = new unsigned long[nVar]; for (iVar = 0; iVar < nVar; iVar++) Point_Max_BGS[iVar] = 0; Point_Max_Coord_BGS = new su2double*[nVar]; for (iVar = 0; iVar < nVar; iVar++) { Point_Max_Coord_BGS[iVar] = new su2double[nDim]; for (iDim = 0; iDim < nDim; iDim++) Point_Max_Coord_BGS[iVar][iDim] = 0.0; } } /*--- Define some auxiliary vectors related to the solution ---*/ Solution = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Solution[iVar] = 1e-16; SolRest = NULL; if (dynamic) SolRest = new su2double[3 * nVar]; else SolRest = new su2double[nVar]; Solution_Vel = NULL; Solution_Accel = NULL; if (dynamic){ Solution_Vel = new su2double[nVar]; Solution_Accel = new su2double[nVar]; for (iVar = 0; iVar < nVar; iVar++) Solution_Vel[iVar] = 1e-16; for (iVar = 0; iVar < nVar; iVar++) Solution_Accel[iVar] = 1e-16; } /*--- Sensitivity definition and coefficient in all the markers ---*/ CSensitivity = new su2double* [nMarker]; for (iMarker = 0; iMarker < nMarker; iMarker++) { CSensitivity[iMarker] = new su2double [geometry->nVertex[iMarker]]; } Sens_E = new su2double[nMarker]; Sens_Nu = new su2double[nMarker]; Sens_nL = new su2double[nMarker]; for (iMarker = 0; iMarker < nMarker; iMarker++) { Sens_E[iMarker] = 0.0; Sens_Nu[iMarker] = 0.0; Sens_nL[iMarker] = 0.0; for (iVertex = 0; iVertex < geometry->nVertex[iMarker]; iVertex++){ CSensitivity[iMarker][iVertex] = 0.0; } } /*--- Check for a restart and set up the variables at each node appropriately. Coarse multigrid levels will be intitially set to the farfield values bc the solver will immediately interpolate the solution from the finest mesh to the coarser levels. ---*/ if (!restart || (iMesh != MESH_0)) { if (dynamic){ /*--- Restart the solution from zero ---*/ for (iPoint = 0; iPoint < nPoint; iPoint++) node[iPoint] = new CDiscAdjFEAVariable(Solution, Solution_Accel, Solution_Vel, nDim, nVar, config); } else{ /*--- Restart the solution from zero ---*/ for (iPoint = 0; iPoint < nPoint; iPoint++) node[iPoint] = new CDiscAdjFEAVariable(Solution, nDim, nVar, config); } } else { /*--- Restart the solution from file information ---*/ mesh_filename = config->GetSolution_AdjFEMFileName(); filename = config->GetObjFunc_Extension(mesh_filename); restart_file.open(filename.data(), ios::in); /*--- In case there is no file ---*/ if (restart_file.fail()) { SU2_MPI::Error(string("There is no adjoint restart file ") + filename, CURRENT_FUNCTION); } /*--- In case this is a parallel simulation, we need to perform the Global2Local index transformation first. ---*/ long *Global2Local; Global2Local = new long[geometry->GetGlobal_nPointDomain()]; /*--- First, set all indices to a negative value by default ---*/ for (iPoint = 0; iPoint < geometry->GetGlobal_nPointDomain(); iPoint++) { Global2Local[iPoint] = -1; } /*--- Now fill array with the transform values only for local points ---*/ for (iPoint = 0; iPoint < nPointDomain; iPoint++) { Global2Local[geometry->node[iPoint]->GetGlobalIndex()] = iPoint; } /*--- Read all lines in the restart file ---*/ long iPoint_Local; unsigned long iPoint_Global = 0;\ /*--- Skip coordinates ---*/ unsigned short skipVars = nDim; /*--- Skip flow adjoint variables ---*/ if (Kind_Solver == RUNTIME_TURB_SYS){ if (compressible){ skipVars += nDim + 2; } if (incompressible){ skipVars += nDim + 1; } } /*--- The first line is the header ---*/ getline (restart_file, text_line); while (getline (restart_file, text_line)) { istringstream point_line(text_line); /*--- Retrieve local index. If this node from the restart file lives on a different processor, the value of iPoint_Local will be -1. Otherwise, the local index for this node on the current processor will be returned and used to instantiate the vars. ---*/ iPoint_Local = Global2Local[iPoint_Global]; if (iPoint_Local >= 0) { point_line >> index; for (iVar = 0; iVar < skipVars; iVar++){ point_line >> dull_val;} for (iVar = 0; iVar < nVar; iVar++){ point_line >> Solution[iVar];} if (dynamic){ for (iVar = 0; iVar < nVar; iVar++){ point_line >> Solution_Vel[iVar];} for (iVar = 0; iVar < nVar; iVar++){ point_line >> Solution_Accel[iVar];} node[iPoint_Local] = new CDiscAdjFEAVariable(Solution, Solution_Accel, Solution_Vel, nDim, nVar, config); } else{ node[iPoint_Local] = new CDiscAdjFEAVariable(Solution, nDim, nVar, config); } } iPoint_Global++; }