11 This writer writes a fixed number of unknown per cell
13 Originally, I had considered this plotter to be used if you have a Finite
14 Volume-type discretisation with N unknowns associated to a cell. However, it
15 turns out that there might be other use cases: People might want to add N
16 unknowns but actually specify that these unknowns are distributed in a certain
17 way. So you can alter the meta information, but per default it is set to one
18 vector of entries per cell. If you want to visualise patch data, I still
19 recommend to use the tailored patch data writer, which plays nicely together
20 with the Python data model.
23 NoMetaFile =
"no-meta-file"
24 CountTimeSteps =
"count-time-steps"
32 time_stamp_evaluation,
33 number_of_unknows_per_cell=1,
34 guard_predicate="true",
35 additional_includes=""
38 Plot only the grid structure
41 Name of the output file
43 vertex_unknown: (DaStGen) object tied to a vertex
44 The object you have associated with a vertex and that you want to print.
45 The code will access its name via
47 fineGridCell{CELL_UNKNOWN_NAME}
49 in the generated source code
51 getter: String (C++ code)
52 Getter acting on the vertex. Could be something alike getU() for example.
53 If there's no getter but you want to directly access the data, remove
54 any brackets from the passed string.
56 time_stamp_evaluation: String
57 C++ expression returning a double. This is used to write the time series
58 file for a series of snapshots. Pass in "0" if you solve a stationary
61 number_of_unknows_per_cell: Integer
62 Has to match to the getter. You can hand in a CastToDouble which instructs the
63 plotter to explicitly cast the entry to double.
65 super( PlotCellDataInPeanoBlockFormat, self ).
__init__()
68 self.
d[
"FILENAME" ] = filename
69 self.
d[
"CELL_UNKNOWN_NAME" ] = cell_unknown.name
70 self.
d[
"GETTER" ] = getter
71 self.
d[
"NUMBER_OF_UNKNOWNS_PER_CELL" ] = number_of_unknows_per_cell
72 self.
d[
"DESCRIPTION" ] = description
73 self.
d[
"TIMESTAMP" ] = time_stamp_evaluation
74 self.
d[
"GUARD_PREDICATE" ] = guard_predicate
75 self.
d[
"META_DATA" ] =
""
79 __Template_Constructor =
"""
81 _dataWriter = nullptr;
82 _treeNumber = treeNumber;
84 // An MPI lock (critical section) would be important!
86 logDebug( "PlotGrid2PlotGridInPeanoBlockFormat1()", "created tree instance for " << treeNumber );
94 __Template_EndTraversal =
"""
95 assertion(_dataWriter!=nullptr);
96 assertion1(_dataWriter!=nullptr,_treeNumber);
99 _writer->writeToFile();
104 _dataWriter = nullptr;
114 return " return std::vector< peano4::grid::GridControlEvent >();\n"
118 return __name__.replace(
".py",
"").replace(
".",
"_")
125 Template_TouchCellFirstTime =
"""
126if ( {{GUARD_PREDICATE}} ) {
127 int cellIndex = _writer->plotPatch(
128 marker.x()-0.5 * marker.h(),
132 {% if NUMBER_OF_UNKNOWNS_PER_CELL<0 %}
133 double data = static_cast<double>(fineGridCell{{CELL_UNKNOWN_NAME}}.{{GETTER}});
135 auto data = fineGridCell{{CELL_UNKNOWN_NAME}}.{{GETTER}};
137 _dataWriter->plotCell( cellIndex, data );
142 __Template_BeginTraversal =
"""
143 tarch::mpi::Lock lock( _semaphore );
145 static int counter = -1;
148 std::ostringstream snapshotFileName;
149 snapshotFileName << "{{FILENAME}}-" << counter;
151 if (tarch::mpi::Rank::getInstance().getNumberOfRanks()>1 ) {
152 snapshotFileName << "-rank-" << tarch::mpi::Rank::getInstance().getRank();
155 {% if TIMESTAMP==\"""" + NoMetaFile +
"""\" %}
156 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
157 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
158 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::NoIndexFile,
161 {% elif TIMESTAMP==\"""" + CountTimeSteps +
"""\" %}
162 static int timeStep = -1;
164 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
165 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
166 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::AppendNewData,
170 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
171 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
172 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::AppendNewData,
177 _dataWriter = _writer->createCellDataWriter(
178 "{{CELL_UNKNOWN_NAME}}",
180 {% if NUMBER_OF_UNKNOWNS_PER_CELL<0 %}
181 1, // records per cell
183 {{NUMBER_OF_UNKNOWNS_PER_CELL}},
193 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
195 if operation_name==ActionSet.OPERATION_BEGIN_TRAVERSAL:
197 if operation_name==ActionSet.OPERATION_END_TRAVERSAL:
204 static tarch::mpi::BooleanSemaphore _semaphore;
208 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter* _writer;
209 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::CellDataWriter* _dataWriter;
215#include "tarch/plotter/griddata/blockstructured/PeanoTextPatchFileWriter.h"
216#include "tarch/mpi/Lock.h"
217#include "tarch/mpi/BooleanSemaphore.h"
218#include "tarch/multicore/Lock.h"
219#include "tarch/multicore/BooleanSemaphore.h"
220#include "peano4/utils/Loop.h"
221#include "peano4/parallel/SpacetreeSet.h"
227tarch::mpi::BooleanSemaphore """ + full_qualified_classname +
"""::_semaphore;
Action set (reactions to events)