4from .AbstractRKFDActionSet
import AbstractRKFDActionSet
10 def __init__(self,solver,guard,grid_is_constructed, restart_from_checkpoint=False, loading_scheme="global-loading"):
11 AbstractRKFDActionSet.__init__(self,solver)
21 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
23 self.
_solver._init_dictionary_with_default_parameters(d)
24 self.
_solver.add_entries_to_text_replacement_dictionary(d)
25 d[
"PREDICATE" ] = self.
guard
27 d[
"CHECKPOINTFILELIST"] =
"CheckpointFilesOf" + self.
_solver._name
40 self.
_solver._init_dictionary_with_default_parameters(d)
41 self.
_solver.add_entries_to_text_replacement_dictionary(d)
42 d[
"PREDICATE" ] = self.
guard
44 d[
"CHECKPOINTFILELIST"] =
"CheckpointFilesOf" + self.
_solver._name
51 return __name__.replace(
".py",
"").replace(
".",
"_")
61#include "exahype2/fd/PatchUtils.h"
62#include "tarch/reader/PeanoTextPatchFileReader.h"
63""" + self.
_solver._get_default_includes() + self.
_solver.user_action_set_includes
69std::vector<double> """ + full_qualified_classname +
"""::domainDataFromFiles;
70std::vector<double> """ + full_qualified_classname +
"""::offsetIndex;
71int """ + full_qualified_classname +
"""::domainPatchCount=0;
75//std::unordered_map<std::tuple<double, double, double>, std::string, tarch::reader::offsetHash, tarch::reader::offsetEqual> """ + full_qualified_classname +
"""::OffsetIndexMap;
76//tarch::reader::CheckpointFilesManager """ + full_qualified_classname +
"""::subFilesManager(100*1024*1024*1024);
85 static std::vector<double> domainDataFromFiles;
86 static std::vector<double> offsetIndex;
87 static int domainPatchCount;
91 static inline std::map< tarch::la::Vector<Dimensions,double> , std::string, tarch::la::VectorCompare<Dimensions> > OffsetIndexMap{ tarch::la::VectorCompare<Dimensions>(1e-5) };
92 static constexpr size_t memoryLimit = 100ULL * 1024 * 1024 * 1024;
93 static inline tarch::reader::CheckpointFilesManager subFilesManager{memoryLimit};
98 TemplateInitialCondition =
"""
100 logTraceIn( "touchCellFirstTime(...)---InitialCondition" );
101 parallelDfor( volume, {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} ) {
102 int index = peano4::utils::dLinearised(volume,{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}) * ({{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}});
103 repositories::{{SOLVER_INSTANCE}}.initialCondition(
104 fineGridCell{{UNKNOWN_IDENTIFIER}}.value + index,
105 ::exahype2::fd::getGridCellCentre( marker.x(), marker.h(), {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}, volume),
106 ::exahype2::fd::getGridCellSize( marker.h(), {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} ),
107 {{GRID_IS_CONSTRUCTED}}
109 //index += {{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}};
112 // relevant for tracing et al which kicks in if and only if cell has been
114 fineGridCell{{SOLVER_NAME}}CellLabel.setHasUpdated(true);
116 logTraceOut( "touchCellFirstTime(...)---InitialCondition" );
123//loading-scheme: global-loading
125 logTraceIn( "touchCellFirstTime(...)---RestartingFromCheckpoint" );
128 tarch::la::Vector<2,double> offset;
129 const int totalCellCount={{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}*{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}};
131 tarch::la::Vector<3,double> offset;
132 const int totalCellCount={{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}*{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}*{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}};
135 for (int i=0;i<domainPatchCount;i++) {
136 bool FoundCell = false;
138 offset[0]=offsetIndex[i*2+0];
139 offset[1]=offsetIndex[i*2+1];
141 offset[0]=offsetIndex[i*3+0];
142 offset[1]=offsetIndex[i*3+1];
143 offset[2]=offsetIndex[i*3+2];
146 if ( tarch::la::equals( marker.x() - 0.5*marker.h(), offset, 1e-5) ) { FoundCell=true; }
149 parallelDfor( volume, {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} ) {
150 int index = peano4::utils::dLinearised(volume,{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}) * ({{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}});
151 for (int k=0; k<=({{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}}); k++){
152 fineGridCell{{UNKNOWN_IDENTIFIER}}.value[index+k]=domainDataFromFiles[i*({{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}})*totalCellCount+index+k];
159 fineGridCell{{SOLVER_NAME}}CellLabel.setTimeStamp(CheckpointTimeStamp);
160 fineGridCell{{SOLVER_NAME}}CellLabel.setHasUpdated(true);
161 logTraceOut( "touchCellFirstTime(...)---RestartingFromCheckpoint" );
166//loading-scheme: local-loading
167//warning: it only support 3D checkpointing file currently!
169 logTraceIn( "touchCellFirstTime(...)---RestartingFromCheckpoint" );
172 tarch::la::Vector<2,double> offset;
173 const int totalCellCount={{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}*{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}};
175 tarch::la::Vector<3,double> offset;
176 const int totalCellCount={{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}*{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}*{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}};
178 double patchDataFromFile[totalCellCount*({{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}})];
180 std::string targetCheckpointFileName=OffsetIndexMap[( marker.x() - 0.5*marker.h() )];
181 if (targetCheckpointFileName.empty()) {std::cout<<"Patch "<< marker.x() - 0.5*marker.h() << " do not see a correct file " << targetCheckpointFileName <<std::endl;}
182 //else {std::cout<<"Patch "<< marker.x() - 0.5*marker.h() << " should be in " << targetCheckpointFileName <<std::endl;}
184 const auto& lines = subFilesManager.getCheckpointFileData(targetCheckpointFileName);
185 bool PatchFound=false;
187 for (const auto& line : lines) {
188 if (line.find(" offset") == 0) {
189 std::istringstream iss(line);
190 std::string token; int index=0;
192 while (iss >> token) { try {offset[index]=std::stod(token); index++; } catch (...){ } }
193 if ( tarch::la::equals( marker.x() - 0.5*marker.h(), offset, 1e-6) ){ PatchFound=true; }
195 if ( PatchFound and (line.find(" ") == 0) ){
196 std::istringstream iss(line);
197 std::string token; int index=0;
199 while (iss >> token) { patchDataFromFile[index]=std::stod(token); index++; }
200 //std::cout<<"Found patch with "<< marker.x() - 0.5*marker.h() << " in " << targetCheckpointFileName <<std::endl;
205 parallelDfor( volume, {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}} ) {
206 int index = peano4::utils::dLinearised(volume,{{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}}) * ({{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}}) ;
207 for (int i=0; i<=({{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}}); i++){
208 fineGridCell{{UNKNOWN_IDENTIFIER}}.value[index+i]=patchDataFromFile[index+i];
212 fineGridCell{{SOLVER_NAME}}CellLabel.setTimeStamp(CheckpointTimeStamp);
213 fineGridCell{{SOLVER_NAME}}CellLabel.setHasUpdated(true);
214 logTraceOut( "touchCellFirstTime(...)---RestartingFromCheckpoint" );
221 tarch::reader::readInCheckpointFiles(CheckpointFilesOf{{SOLVER_NAME}}, domainDataFromFiles, offsetIndex,
222 {{NUMBER_OF_UNKNOWNS}}, {{NUMBER_OF_AUXILIARY_VARIABLES}}, Dimensions, {{NUMBER_OF_GRID_CELLS_PER_PATCH_PER_AXIS}});
224 domainPatchCount=offsetIndex.size()/2;
226 domainPatchCount=offsetIndex.size()/3;
232 tarch::reader::readInCheckpointOffsetIndex(OffsetIndexMap, CheckpointFilesOf{{SOLVER_NAME}});
get_static_initialisations(self, full_qualified_classname)
get_body_of_prepareTraversal(self)
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
str TemplateInitialCondition
__init__(self, solver, guard, grid_is_constructed, restart_from_checkpoint=False, loading_scheme="global-loading")
solver: ADERDG Reference to creating class
get_template_for_restart_preprocessing(self)
get_template_for_restarting(self)
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_includes(self)
Return include statements that you need.
get_attributes(self)
Return attributes as copied and pasted into the generated class.