13 Very simple plotter that should be used in combination with Patches.
14 Patches with varying datatypes are supported via the "dataType" parameter,
15 but this defaults to doubles. This parameter should contain the C-style-
16 name of the type of the variable in the patch, e.g. float, double, etc.
17 This plotter works only for cell patches, i.e. patches associated with
18 faces or vertices are not supported.
20 At the moment, I can only plot one dataset (patch type) per plotter.
21 In theory, the underlying Peano plotter however could dump multiple
24 Also, this dump expects incoming data to be AoS.
31 description, time_stamp_evaluation,
36 additional_includes="",
40 restart_preprocess=False):
43 Construct the block plotter
45 plot_cell_data: Boolean
46 Shall I plot cell data or vertex data. If you map the patches onto
47 vertex data, then I have to decrease the dofs pre axis, as we basically
52 mapping: Series of d-tuples which describe how to distort quadrature/sampling
53 points within a reference cube/square. Can be empty alternatively.
55 select_dofs: [Int] or None
56 You can make the plotter only plot some of the dofs of interest
59 super(PlotPatchesInPeanoBlockFormat,self).
__init__(descend_invocation_order=1,parallel=
False)
61 valid_datatypes = {
"float",
"double",
"long double",
"_Float16",
"std::float16_t",
"__bf16",
"std::bfloat16_t"}
66 self.
d[
"FILENAME" ] = filename
67 self.
d[
"GUARD_PREDICATE" ] = guard
71 dofs_per_axis = patch.dim[0]
73 self.
d[
"DOFS_PER_AXIS" ] = str(dofs_per_axis)
76 self.
d[
"PLOTTED_UNKNOWNS" ] = str(patch.no_of_unknowns)
78 self.
d[
"PLOTTED_UNKNOWNS" ] = str(len(select_dofs))
79 self.
d[
"UNKNOWNS" ] = str(patch.no_of_unknowns)
80 self.
d[
"SELECT_DOFS" ] = select_dofs
82 self.
d[
"NAME" ] = dataset_name
83 self.
d[
"DESCRIPTION" ] = description
84 self.
d[
"METADATA" ] = metadata
86 self.
d[
"MAPPING_2D"] =
"double* mapping = nullptr;"
87 self.
d[
"MAPPING_3D"] =
"double* mapping = nullptr;"
90 self.
d[
"MAPPING_2D"] =
"double mapping[" + str(2*dofs_per_axis*dofs_per_axis) +
"] = {"
91 self.
d[
"MAPPING_3D"] =
"double mapping[" + str(3*dofs_per_axis*dofs_per_axis*dofs_per_axis) +
"] = {"
97 if counter<dofs_per_axis*dofs_per_axis:
98 self.
d[
"MAPPING_2D"] += separator + str(i[0])
99 self.
d[
"MAPPING_2D"] +=
", " + str(i[1])
100 self.
d[
"MAPPING_2D"] +=
"\n"
101 self.
d[
"MAPPING_3D"] += separator + str(i[0])
102 self.
d[
"MAPPING_3D"] +=
", " + str(i[1])
104 self.
d[
"MAPPING_3D"] +=
", " + str(i[2])
106 self.
d[
"MAPPING_3D"] +=
", 0.0"
107 self.
d[
"MAPPING_3D"] +=
"\n"
110 self.
d[
"MAPPING_2D"] +=
"};"
111 self.
d[
"MAPPING_3D"] +=
"};"
115 print(
"Error: patch plotter requires patch to have same dimension along all coordinate axes")
117 if dataType
not in valid_datatypes:
118 raise Exception(
"Chosen datatype " + dataType +
" for plotting of patches is not a recognized choice.")
120 self.
d[
"PRECISION" ] = precision
121 self.
d[
"DATATYPE" ] = dataType
122 self.
d[
"TIMESTAMP" ] = time_stamp_evaluation
127 __Template_Constructor =
"""
129 _dataWriter = nullptr;
130 _treeNumber = treeNumber;
132 logDebug( "PlotGrid2PlotGridInPeanoBlockFormat1()", "created tree instance for " << treeNumber );
140 __Template_EndTraversal =
"""
141 assertion1( _dataWriter!=nullptr, _treeNumber );
142 assertion1( _writer!=nullptr, _treeNumber );
144 _dataWriter->close();
145 _writer->writeToFile();
150 _dataWriter = nullptr;
160 return " return std::vector< peano4::grid::GridControlEvent >();\n"
164 return __name__.replace(
".py",
"").replace(
".",
"_")
171 __Template_TouchCellFirstTime_CellPlot =
"""
172 if ( {{GUARD_PREDICATE}} ) {
173 int vertexIndices[TwoPowerD];
175 const double PatchScaling = 1.0;
177 assertion( _writer!=nullptr );
178 assertion( _dataWriter!=nullptr );
180 const int patchIndex = _writer->plotPatch(
181 marker.x() - marker.h() * PatchScaling * 0.5,
182 marker.h() * PatchScaling
185 int cellIndex = _dataWriter->getFirstCellWithinPatch(patchIndex);
188 dfor(k,{{DOFS_PER_AXIS}}) {
189 {% if SELECT_DOFS==None %}
190 {{DATATYPE}}* data = fineGridCell{{NAME}}.value + currentDoF;
192 {{DATATYPE}} data[] = {
193 fineGridCell{{NAME}}.value[ currentDoF + {{SELECT_DOFS[0]}} ]
194 {% for i in SELECT_DOFS[1:] %}
195 , fineGridCell{{NAME}}.value[ currentDoF + {{i}} ]
199 _dataWriter->plotCell( cellIndex, data );
201 currentDoF += {{UNKNOWNS}};
209 __Template_TouchCellFirstTime_VertexPlot =
"""
210 if ( {{GUARD_PREDICATE}} ) {
211 int vertexIndices[TwoPowerD];
213 const double PatchScaling = 1.0;
215 assertion( _writer!=nullptr );
216 assertion( _dataWriter!=nullptr );
218 const int patchIndex = _writer->plotPatch(
219 marker.x() - marker.h() * PatchScaling * 0.5,
220 marker.h() * PatchScaling
223 int vertexIndex = _dataWriter->getFirstVertexWithinPatch(patchIndex);
226 dfor(k,{{DOFS_PER_AXIS}}) {
227 {% if SELECT_DOFS==None %}
228 {{DATATYPE}}* data = fineGridCell{{NAME}}.value + currentDoF;
230 {{DATATYPE}} data[] = {
231 fineGridCell{{NAME}}.value[ currentDoF + {{SELECT_DOFS[0]}} ]
232 {% for i in SELECT_DOFS[1:] %}
233 , fineGridCell{{NAME}}.value[ currentDoF + {{i}} ]
237 _dataWriter->plotVertex( vertexIndex, data );
239 currentDoF += {{UNKNOWNS}};
244 __Template_BeginTraversal_Generic =
"""
245 std::ostringstream snapshotFileName;
246 snapshotFileName << "{{FILENAME}}-" << counter;
248 if (tarch::mpi::Rank::getInstance().getNumberOfRanks()>1 ) {
249 snapshotFileName << "-rank-" << tarch::mpi::Rank::getInstance().getRank();
252 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
253 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
254 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::AppendNewData,
265 __Template_BeginTraversal_Generic_Restart =
"""
266 tarch::mpi::Lock lock( _semaphore );
268 static int counter = -1;
271 static bool preprocessFinished=false;
272 if (not preprocessFinished){
273 if ( tarch::mpi::Rank::getInstance().isGlobalMaster()){
274 counter=tarch::plotter::griddata::blockstructured::restartPreprocess("{{FILENAME}}", CheckpointTimeStamp);
276 MPI_Bcast(&counter, 1, MPI_INT, 0, MPI_COMM_WORLD);
277 preprocessFinished=true;
280"""+__Template_BeginTraversal_Generic
282 __Template_BeginTraversal_Generic =
"""
283 tarch::mpi::Lock lock( _semaphore );
285 static int counter = -1;
288"""+__Template_BeginTraversal_Generic
291 __Template_BeginTraversal_CellPlot = __Template_BeginTraversal_Generic +
"""
292 _dataWriter = _writer->createCellDataWriter( "{{NAME}}", {{DOFS_PER_AXIS}}, {{PLOTTED_UNKNOWNS}}, "{{DESCRIPTION}}", "{{METADATA}}", mapping );
293 _dataWriter->setPrecision( {{PRECISION}} );
295 __Template_BeginTraversal_CellPlot_Restart = __Template_BeginTraversal_Generic_Restart +
"""
296 _dataWriter = _writer->createCellDataWriter( "{{NAME}}", {{DOFS_PER_AXIS}}, {{PLOTTED_UNKNOWNS}}, "{{DESCRIPTION}}", "{{METADATA}}", mapping );
297 _dataWriter->setPrecision( {{PRECISION}} );
300 __Template_BeginTraversal_VertexPlot = __Template_BeginTraversal_Generic +
"""
301 _dataWriter = _writer->createVertexDataWriter( "{{NAME}}", {{DOFS_PER_AXIS}}, {{PLOTTED_UNKNOWNS}}, "{{DESCRIPTION}}", "{{METADATA}}", mapping );
302 _dataWriter->setPrecision( {{PRECISION}} );
304 __Template_BeginTraversal_VertexPlot_Restart = __Template_BeginTraversal_Generic_Restart +
"""
305 _dataWriter = _writer->createVertexDataWriter( "{{NAME}}", {{DOFS_PER_AXIS}}, {{PLOTTED_UNKNOWNS}}, "{{DESCRIPTION}}", "{{METADATA}}", mapping );
306 _dataWriter->setPrecision( {{PRECISION}} );
311 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
and self.
_plot_cell_data:
313 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
and not self.
_plot_cell_data:
316 if operation_name==ActionSet.OPERATION_BEGIN_TRAVERSAL
and self.
_plot_cell_data:
322 if operation_name==ActionSet.OPERATION_BEGIN_TRAVERSAL
and not self.
_plot_cell_data:
328 if operation_name==ActionSet.OPERATION_END_TRAVERSAL:
336 static tarch::mpi::BooleanSemaphore _semaphore;
340 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter* _writer;
341 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::CellDataWriter* _dataWriter;
345 static tarch::mpi::BooleanSemaphore _semaphore;
349 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter* _writer;
350 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::VertexDataWriter* _dataWriter;
356#include "tarch/plotter/griddata/blockstructured/PeanoTextPatchFileWriter.h"
357#include "tarch/multicore/Lock.h"
358#include "tarch/multicore/BooleanSemaphore.h"
359#include "tarch/mpi/Lock.h"
360#include "tarch/mpi/BooleanSemaphore.h"
361#include "peano4/utils/Loop.h"
362#include "peano4/parallel/SpacetreeSet.h"
368tarch::mpi::BooleanSemaphore """ + full_qualified_classname +
"""::_semaphore;
Action set (reactions to events)