19 This writer writes a fixed number of unknown per cell
21 Originally, I had considered this plotter to be used if you have a Finite
22 Volume-type discretisation with N unknowns associated to a cell. However, it
23 turns out that there might be other use cases: People might want to add N
24 unknowns but actually specify that these unknowns are distributed in a certain
25 way. So you can alter the meta information, but per default it is set to one
26 vector of entries per cell. If you want to visualise patch data, I still
27 recommend to use the tailored patch data writer, which plays nicely together
28 with the Python data model.
31 NoMetaFile =
"no-meta-file"
32 CountTimeSteps =
"count-time-steps"
40 time_stamp_evaluation,
41 number_of_unknows_per_cell=1,
42 guard_predicate="true",
43 additional_includes=""
46 Plot only the grid structure
49 Name of the output file
51 vertex_unknown: (DaStGen) object tied to a vertex
52 The object you have associated with a vertex and that you want to print.
53 The code will access its name via
55 fineGridCell{CELL_UNKNOWN_NAME}
57 in the generated source code
59 getter: String (C++ code)
60 Getter acting on the vertex. Could be something alike getU() for example.
61 If there's no getter but you want to directly access the data, remove
62 any brackets from the passed string.
64 time_stamp_evaluation: String
65 C++ expression returning a double. This is used to write the time series
66 file for a series of snapshots. Pass in "0" if you solve a stationary
69 number_of_unknows_per_cell: Integer
70 Has to match to the getter. You can hand in a CastToDouble which instructs the
71 plotter to explicitly cast the entry to double.
73 super( PlotCellDataInPeanoBlockFormat, self ).
__init__()
76 self.
d[
"FILENAME" ] = filename
77 self.
d[
"CELL_UNKNOWN_NAME" ] = cell_unknown.name
78 self.
d[
"GETTER" ] = getter
79 self.
d[
"NUMBER_OF_UNKNOWNS_PER_CELL" ] = number_of_unknows_per_cell
80 self.
d[
"DESCRIPTION" ] = description
81 self.
d[
"TIMESTAMP" ] = time_stamp_evaluation
82 self.
d[
"GUARD_PREDICATE" ] = guard_predicate
83 self.
d[
"META_DATA" ] =
""
87 __Template_Constructor =
"""
89 _dataWriter = nullptr;
90 _treeNumber = treeNumber;
92 // An MPI lock (critical section) would be important!
94 logDebug( "PlotGrid2PlotGridInPeanoBlockFormat1()", "created tree instance for " << treeNumber );
102 __Template_EndTraversal =
"""
103 assertion(_dataWriter!=nullptr);
104 assertion1(_dataWriter!=nullptr,_treeNumber);
106 _dataWriter->close();
107 _writer->writeToFile();
112 _dataWriter = nullptr;
122 return " return std::vector< peano4::grid::GridControlEvent >();\n"
126 return __name__.replace(
".py",
"").replace(
".",
"_")
133 Template_TouchCellFirstTime =
"""
134 int cellIndex = _writer->plotPatch(
135 marker.x()-0.5 * marker.h(),
139 {% if NUMBER_OF_UNKNOWNS_PER_CELL<0 %}
140 double data = static_cast<double>(fineGridCell{{CELL_UNKNOWN_NAME}}.{{GETTER}});
142 auto data = fineGridCell{{CELL_UNKNOWN_NAME}}.{{GETTER}};
144 _dataWriter->plotCell( cellIndex, data );
148 __Template_BeginTraversal =
"""
149 tarch::mpi::Lock lock( _semaphore );
151 static int counter = -1;
154 std::ostringstream snapshotFileName;
155 snapshotFileName << "{{FILENAME}}-" << counter;
157 if (tarch::mpi::Rank::getInstance().getNumberOfRanks()>1 ) {
158 snapshotFileName << "-rank-" << tarch::mpi::Rank::getInstance().getRank();
161 {% if TIMESTAMP==\"""" + NoMetaFile +
"""\" %}
162 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
163 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
164 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::NoIndexFile,
167 {% elif TIMESTAMP==\"""" + CountTimeSteps +
"""\" %}
168 static int timeStep = -1;
170 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
171 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
172 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::AppendNewData,
176 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
177 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
178 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::AppendNewData,
183 _dataWriter = _writer->createCellDataWriter(
184 "{{CELL_UNKNOWN_NAME}}",
186 {% if NUMBER_OF_UNKNOWNS_PER_CELL<0 %}
187 1, // records per cell
189 {{NUMBER_OF_UNKNOWNS_PER_CELL}},
199 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
201 if operation_name==ActionSet.OPERATION_BEGIN_TRAVERSAL:
203 if operation_name==ActionSet.OPERATION_END_TRAVERSAL:
209 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
210 return self.
d[
"GUARD_PREDICATE" ]
216 static tarch::mpi::BooleanSemaphore _semaphore;
220 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter* _writer;
221 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::CellDataWriter* _dataWriter;
227#include "tarch/plotter/griddata/blockstructured/PeanoTextPatchFileWriter.h"
228#include "tarch/mpi/Lock.h"
229#include "tarch/mpi/BooleanSemaphore.h"
230#include "tarch/multicore/Lock.h"
231#include "tarch/multicore/BooleanSemaphore.h"
232#include "peano4/utils/Loop.h"
233#include "peano4/parallel/SpacetreeSet.h"
239tarch::mpi::BooleanSemaphore """ + full_qualified_classname +
"""::_semaphore;
Action set (reactions to events)