11 Plotter of face structure
12 @todo have not been implemented yet
20 description, time_stamp_evaluation,
25 additional_includes="",
31 Construct the block plotter
33 plot_cell_data: Boolean
34 Shall I plot cell data or vertex data. If you map the patches onto
35 vertex data, then I have to decrease the dofs pre axis, as we basically
40 mapping: Series of d-tuples which describe how to distort quadrature/sampling
41 points within a reference cube/square. Can be empty alternatively.
43 select_dofs: [Int] or None
44 You can make the plotter only plot some of the dofs of interest
47 super(PlotPatchesOverFacesInPeanoBlockFormat,self).
__init__(descend_invocation_order=1,parallel=
False)
49 valid_datatypes = {
"float",
"double",
"long double",
"_Float16",
"std::float16_t",
"__bf16",
"std::bfloat16_t"}
54 self.
d[
"FILENAME" ] = filename
55 self.
d[
"GUARD_PREDICATE" ] = guard
59 dofs_per_axis = patch.dim[0]
61 self.
d[
"DOFS_PER_AXIS" ] = str(dofs_per_axis)
64 self.
d[
"PLOTTED_UNKNOWNS" ] = str(patch.no_of_unknowns)
66 self.
d[
"PLOTTED_UNKNOWNS" ] = str(len(select_dofs))
67 self.
d[
"UNKNOWNS" ] = str(patch.no_of_unknowns)
68 self.
d[
"SELECT_DOFS" ] = select_dofs
70 self.
d[
"NAME" ] = dataset_name
71 self.
d[
"DESCRIPTION" ] = description
72 self.
d[
"METADATA" ] = metadata
74 self.
d[
"MAPPING_2D"] =
"double* mapping = nullptr;"
75 self.
d[
"MAPPING_3D"] =
"double* mapping = nullptr;"
78 self.
d[
"MAPPING_2D"] =
"double mapping[" + str(2*dofs_per_axis*dofs_per_axis) +
"] = {"
79 self.
d[
"MAPPING_3D"] =
"double mapping[" + str(3*dofs_per_axis*dofs_per_axis*dofs_per_axis) +
"] = {"
85 if counter<dofs_per_axis*dofs_per_axis:
86 self.
d[
"MAPPING_2D"] += separator + str(i[0])
87 self.
d[
"MAPPING_2D"] +=
", " + str(i[1])
88 self.
d[
"MAPPING_2D"] +=
"\n"
89 self.
d[
"MAPPING_3D"] += separator + str(i[0])
90 self.
d[
"MAPPING_3D"] +=
", " + str(i[1])
92 self.
d[
"MAPPING_3D"] +=
", " + str(i[2])
94 self.
d[
"MAPPING_3D"] +=
", 0.0"
95 self.
d[
"MAPPING_3D"] +=
"\n"
98 self.
d[
"MAPPING_2D"] +=
"};"
99 self.
d[
"MAPPING_3D"] +=
"};"
103 print(
"Error: patch plotter requires patch to have same dimension along all coordinate axes")
105 if dataType
not in valid_datatypes:
106 raise Exception(
"Chosen datatype " + dataType +
" for plotting of patches is not a recognized choice.")
108 self.
d[
"PRECISION" ] = precision
109 self.
d[
"DATATYPE" ] = dataType
110 self.
d[
"TIMESTAMP" ] = time_stamp_evaluation
113 __Template_Constructor =
"""
115 _dataWriter = nullptr;
116 _treeNumber = treeNumber;
118 logDebug( "PlotGrid2PlotGridInPeanoBlockFormat1()", "created tree instance for " << treeNumber );
126 __Template_EndTraversal =
"""
127 assertion1( _dataWriter!=nullptr, _treeNumber );
128 assertion1( _writer!=nullptr, _treeNumber );
130 _dataWriter->close();
131 _writer->writeToFile();
136 _dataWriter = nullptr;
146 return " return std::vector< peano4::grid::GridControlEvent >();\n"
150 return __name__.replace(
".py",
"").replace(
".",
"_")
159 Used if we have data associated with the cell centres of the small patch
160 associated with a face.
163 __Template_TouchFaceFirstTime_CellPlot =
"""
164 int vertexIndices[TwoPowerD];
166 const double PatchScaling = 1.0;
168 assertion( _writer!=nullptr );
169 assertion( _dataWriter!=nullptr );
171 const int patchIndex = _writer->plotPatch(
172 marker.x() - marker.h() * PatchScaling * 0.5,
173 marker.h() * PatchScaling
176 int cellIndex = _dataWriter->getFirstCellWithinPatch(patchIndex);
179 dfor(k,{{DOFS_PER_AXIS}}) {
180 {% if SELECT_DOFS==None %}
181 {{DATATYPE}}* data = fineGridCell{{NAME}}.value + currentDoF;
183 {{DATATYPE}} data[] = {
184 fineGridCell{{NAME}}.value[ currentDoF + {{SELECT_DOFS[0]}} ]
185 {% for i in SELECT_DOFS[1:] %}
186 , fineGridCell{{NAME}}.value[ currentDoF + {{i}} ]
190 _dataWriter->plotCell( cellIndex, data );
192 currentDoF += {{UNKNOWNS}};
199 Used if we have data associated with the vertices of the small patch
200 associated with a face.
203 __Template_TouchFaceFirstTime_VertexPlot =
"""
204 int vertexIndices[TwoPowerD];
206 const double PatchScaling = 1.0;
208 assertion( _writer!=nullptr );
209 assertion( _dataWriter!=nullptr );
211 const int patchIndex = _writer->plotPatch(
212 marker.x() - marker.h() * PatchScaling * 0.5,
213 marker.h() * PatchScaling
216 int vertexIndex = _dataWriter->getFirstVertexWithinPatch(patchIndex);
219 dfor(k,{{DOFS_PER_AXIS}}) {
220 {% if SELECT_DOFS==None %}
221 {{DATATYPE}}* data = fineGridCell{{NAME}}.value + currentDoF;
223 {{DATATYPE}} data[] = {
224 fineGridCell{{NAME}}.value[ currentDoF + {{SELECT_DOFS[0]}} ]
225 {% for i in SELECT_DOFS[1:] %}
226 , fineGridCell{{NAME}}.value[ currentDoF + {{i}} ]
230 _dataWriter->plotVertex( vertexIndex, data );
232 currentDoF += {{UNKNOWNS}};
237 __Template_BeginTraversal_Generic =
"""
238 tarch::mpi::Lock lock( _semaphore );
240 static int counter = -1;
243 std::ostringstream snapshotFileName;
244 snapshotFileName << "{{FILENAME}}-" << counter;
246 if (tarch::mpi::Rank::getInstance().getNumberOfRanks()>1 ) {
247 snapshotFileName << "-rank-" << tarch::mpi::Rank::getInstance().getRank();
250 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
251 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
252 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::AppendNewData,
265 __Template_BeginTraversal_CellPlot = __Template_BeginTraversal_Generic +
"""
266 _dataWriter = _writer->createCellDataWriter( "{{NAME}}", {{DOFS_PER_AXIS}}, {{PLOTTED_UNKNOWNS}}, "{{DESCRIPTION}}", "{{METADATA}}", mapping );
267 _dataWriter->setPrecision( {{PRECISION}} );
271 __Template_BeginTraversal_VertexPlot = __Template_BeginTraversal_Generic +
"""
272 _dataWriter = _writer->createVertexDataWriter( "{{NAME}}", {{DOFS_PER_AXIS}}, {{PLOTTED_UNKNOWNS}}, "{{DESCRIPTION}}", "{{METADATA}}", mapping );
273 _dataWriter->setPrecision( {{PRECISION}} );
279 if operation_name==ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME
and self.
_plot_cell_data:
281 if operation_name==ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME
and not self.
_plot_cell_data:
283 if operation_name==ActionSet.OPERATION_BEGIN_TRAVERSAL
and self.
_plot_cell_data:
285 if operation_name==ActionSet.OPERATION_BEGIN_TRAVERSAL
and not self.
_plot_cell_data:
287 if operation_name==ActionSet.OPERATION_END_TRAVERSAL:
293 if operation_name==ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME:
294 return self.
d[
"GUARD_PREDICATE" ]
301 static tarch::mpi::BooleanSemaphore _semaphore;
305 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter* _writer;
306 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::CellDataWriter* _dataWriter;
310 static tarch::mpi::BooleanSemaphore _semaphore;
314 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter* _writer;
315 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::VertexDataWriter* _dataWriter;
321#include "tarch/plotter/griddata/blockstructured/PeanoTextPatchFileWriter.h"
322#include "tarch/multicore/Lock.h"
323#include "tarch/multicore/BooleanSemaphore.h"
324#include "tarch/mpi/Lock.h"
325#include "tarch/mpi/BooleanSemaphore.h"
326#include "peano4/utils/Loop.h"
327#include "peano4/parallel/SpacetreeSet.h"
333tarch::mpi::BooleanSemaphore """ + full_qualified_classname +
"""::_semaphore;
Action set (reactions to events)