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 if ( {{GUARD_PREDICATE}} ) {
165 int vertexIndices[TwoPowerD];
167 const double PatchScaling = 1.0;
169 assertion( _writer!=nullptr );
170 assertion( _dataWriter!=nullptr );
172 const int patchIndex = _writer->plotPatch(
173 marker.x() - marker.h() * PatchScaling * 0.5,
174 marker.h() * PatchScaling
177 int cellIndex = _dataWriter->getFirstCellWithinPatch(patchIndex);
180 dfor(k,{{DOFS_PER_AXIS}}) {
181 {% if SELECT_DOFS==None %}
182 {{DATATYPE}}* data = fineGridCell{{NAME}}.value + currentDoF;
184 {{DATATYPE}} data[] = {
185 fineGridCell{{NAME}}.value[ currentDoF + {{SELECT_DOFS[0]}} ]
186 {% for i in SELECT_DOFS[1:] %}
187 , fineGridCell{{NAME}}.value[ currentDoF + {{i}} ]
191 _dataWriter->plotCell( cellIndex, data );
193 currentDoF += {{UNKNOWNS}};
201 Used if we have data associated with the vertices of the small patch
202 associated with a face.
205 __Template_TouchFaceFirstTime_VertexPlot =
"""
206 if ( {{GUARD_PREDICATE}} ) {
207 int vertexIndices[TwoPowerD];
209 const double PatchScaling = 1.0;
211 assertion( _writer!=nullptr );
212 assertion( _dataWriter!=nullptr );
214 const int patchIndex = _writer->plotPatch(
215 marker.x() - marker.h() * PatchScaling * 0.5,
216 marker.h() * PatchScaling
219 int vertexIndex = _dataWriter->getFirstVertexWithinPatch(patchIndex);
222 dfor(k,{{DOFS_PER_AXIS}}) {
223 {% if SELECT_DOFS==None %}
224 {{DATATYPE}}* data = fineGridCell{{NAME}}.value + currentDoF;
226 {{DATATYPE}} data[] = {
227 fineGridCell{{NAME}}.value[ currentDoF + {{SELECT_DOFS[0]}} ]
228 {% for i in SELECT_DOFS[1:] %}
229 , fineGridCell{{NAME}}.value[ currentDoF + {{i}} ]
233 _dataWriter->plotVertex( vertexIndex, data );
235 currentDoF += {{UNKNOWNS}};
241 __Template_BeginTraversal_Generic =
"""
242 tarch::mpi::Lock lock( _semaphore );
244 static int counter = -1;
247 std::ostringstream snapshotFileName;
248 snapshotFileName << "{{FILENAME}}-" << counter;
250 if (tarch::mpi::Rank::getInstance().getNumberOfRanks()>1 ) {
251 snapshotFileName << "-rank-" << tarch::mpi::Rank::getInstance().getRank();
254 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
255 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
256 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::AppendNewData,
269 __Template_BeginTraversal_CellPlot = __Template_BeginTraversal_Generic +
"""
270 _dataWriter = _writer->createCellDataWriter( "{{NAME}}", {{DOFS_PER_AXIS}}, {{PLOTTED_UNKNOWNS}}, "{{DESCRIPTION}}", "{{METADATA}}", mapping );
271 _dataWriter->setPrecision( {{PRECISION}} );
275 __Template_BeginTraversal_VertexPlot = __Template_BeginTraversal_Generic +
"""
276 _dataWriter = _writer->createVertexDataWriter( "{{NAME}}", {{DOFS_PER_AXIS}}, {{PLOTTED_UNKNOWNS}}, "{{DESCRIPTION}}", "{{METADATA}}", mapping );
277 _dataWriter->setPrecision( {{PRECISION}} );
283 if operation_name==ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME
and self.
_plot_cell_data:
285 if operation_name==ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME
and not self.
_plot_cell_data:
287 if operation_name==ActionSet.OPERATION_BEGIN_TRAVERSAL
and self.
_plot_cell_data:
289 if operation_name==ActionSet.OPERATION_BEGIN_TRAVERSAL
and not self.
_plot_cell_data:
291 if operation_name==ActionSet.OPERATION_END_TRAVERSAL:
299 static tarch::mpi::BooleanSemaphore _semaphore;
303 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter* _writer;
304 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::CellDataWriter* _dataWriter;
308 static tarch::mpi::BooleanSemaphore _semaphore;
312 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter* _writer;
313 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::VertexDataWriter* _dataWriter;
319#include "tarch/plotter/griddata/blockstructured/PeanoTextPatchFileWriter.h"
320#include "tarch/multicore/Lock.h"
321#include "tarch/multicore/BooleanSemaphore.h"
322#include "tarch/mpi/Lock.h"
323#include "tarch/mpi/BooleanSemaphore.h"
324#include "peano4/utils/Loop.h"
325#include "peano4/parallel/SpacetreeSet.h"
331tarch::mpi::BooleanSemaphore """ + full_qualified_classname +
"""::_semaphore;
Action set (reactions to events)