Peano
Loading...
Searching...
No Matches
PlotGridInPeanoBlockFormat.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.solversteps.ActionSet import ActionSet
4
5
6import jinja2
7
8
10 NoMetaFile = "no-meta-file"
11 CountTimeSteps = "count-time-steps"
12
13 def __init__(self, filename, cell_unknown=None, time_stamp_evaluation=NoMetaFile, guard_predicate="true", additional_includes=""):
14 """
15 Plot only the grid structure
16
17 :Attibutes:
18
19 filename: String
20 Name of the output file.
21
22 cell_unknown: None or cell data
23 If you use cell unknowns, pass any unknown in. As we do not dump
24 any semantic information about unknowns, it does not matter which
25 one you choose. If you don't have cell unknowns at all, pass in
26 None.
27
28 time_stamp_evaluation: String
29 C++ expression returning a double. You can also hand in NoMetaFile
30 or CountTimeSteps.
31
32 """
33 super( PlotGridInPeanoBlockFormat, self ).__init__()
34
35 self.d = {}
36 self.d[ "FILENAME" ] = filename
37 self.d[ "CELL_WRAPPER" ] = "Cell"
38 if cell_unknown!=None:
39 self.d[ "CELL_WRAPPER" ] += cell_unknown.name
40 self.d[ "GUARD_PREDICATE" ] = guard_predicate
41 self.additional_includes = additional_includes
42 self.d[ "TIMESTAMP" ] = time_stamp_evaluation
43
44
45 __Template_Constructor = """
46 _writer = nullptr;
47 _dataWriter = nullptr;
48 _treeNumber = treeNumber;
49
50 // An MPI lock (critical section) would be important!
51
52 logDebug( "PlotGrid2PlotGridInPeanoBlockFormat1()", "created tree instance for " << treeNumber );
53"""
54
55
57 return self.__Template_Constructor.format(**self.d)
58
59
60 __Template_EndTraversal = jinja2.Template("""
61 assertion1(_dataWriter!=nullptr,_treeNumber);
62
63 _dataWriter->close();
64 _writer->writeToFile();
65
66 delete _dataWriter;
67 delete _writer;
68
69 _dataWriter = nullptr;
70 _writer = nullptr;
71""")
72
73
75 return ""
76
77
79 return " return std::vector< peano4::grid::GridControlEvent >();\n"
80
81
83 return __name__.replace(".py", "").replace(".", "_")
84
85
87 return False
88
89
90 __Template_TouchCellFirstTime = jinja2.Template("""
91 if ( {{GUARD_PREDICATE}} ) {
92 int vertexIndices[TwoPowerD];
93
94 int indices = _writer->plotPatch(
95 marker.x() - marker.h() * 0.5,
96 marker.h()
97 );
98
99 assertion( _dataWriter!=nullptr );
100
101 double markerData[] = {
102 marker.hasBeenRefined() ? 1.0 : 0.0,
103 marker.willBeRefined() ? 1.0 : 0.0,
104 marker.isLocal() ? 1.0 : 0.0,
105 marker.hasBeenEnclaveCell() ? 1.0 : 0.0,
106 marker.willBeEnclaveCell() ? 1.0 : 0.0
107 };
108 _dataWriter->plotCell(indices,markerData);
109 }
110""")
111
112
113 __Template_BeginTraversal = jinja2.Template("""
114 tarch::mpi::Lock lock( _semaphore );
115
116 static int counter = -1;
117 counter++;
118
119 std::ostringstream snapshotFileName;
120 snapshotFileName << "{{FILENAME}}-" << counter;
121
122 if (tarch::mpi::Rank::getInstance().getNumberOfRanks()>1 ) {
123 snapshotFileName << "-rank-" << tarch::mpi::Rank::getInstance().getRank();
124 }
125
126 {% if TIMESTAMP==\"""" + NoMetaFile + """\" %}
127 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
128 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
129 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::NoIndexFile,
130 0.0
131 );
132 {% elif TIMESTAMP==\"""" + CountTimeSteps + """\" %}
133 static int timeStep = -1;
134 timeStep++;
135 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
136 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
137 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::AppendNewData,
138 timeStep
139 );
140 {% else %}
141 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
142 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
143 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::AppendNewData,
144 {{TIMESTAMP}}
145 );
146 {% endif %}
147
148 _dataWriter = _writer->createCellDataWriter( "cell-marker", 1, 5, "is-refined,has-been-refined,local,enclave" );
149""")
150
151
152 def get_body_of_operation(self,operation_name):
153 result = "\n"
154 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
155 result = self.__Template_TouchCellFirstTime.render(**self.d)
156 if operation_name==ActionSet.OPERATION_BEGIN_TRAVERSAL:
157 result = self.__Template_BeginTraversal.render(**self.d)
158 if operation_name==ActionSet.OPERATION_END_TRAVERSAL:
159 result = self.__Template_EndTraversal.render(**self.d)
160 return result
161
162
163 def get_attributes(self):
164 return """
165 static tarch::mpi::BooleanSemaphore _semaphore;
166
167 int _treeNumber;
168
169 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter* _writer;
170 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::CellDataWriter* _dataWriter;
171"""
172
173
174 def get_includes(self):
175 return """
176#include "tarch/plotter/griddata/blockstructured/PeanoTextPatchFileWriter.h"
177#include "tarch/multicore/Lock.h"
178#include "tarch/multicore/BooleanSemaphore.h"
179#include "tarch/mpi/Lock.h"
180#include "tarch/mpi/BooleanSemaphore.h"
181#include "peano4/parallel/SpacetreeSet.h"
182""" + self.additional_includes
183
184
185 def get_static_initialisations(self,full_qualified_classname):
186 return """
187tarch::mpi::BooleanSemaphore """ + full_qualified_classname + """::_semaphore;
188"""
189
190
191
Action set (reactions to events)
Definition ActionSet.py:6
__init__(self, filename, cell_unknown=None, time_stamp_evaluation=NoMetaFile, guard_predicate="true", additional_includes="")
Plot only the grid structure.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_attributes(self)
Return attributes as copied and pasted into the generated class.