Peano
Loading...
Searching...
No Matches
PlotDGDataInPeanoBlockFormat.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
5import jinja2
6
7
9
10 def __init__(self,
11 solver
12 ):
13 """
14
15 Plot the DG mesh
16
17 """
18 super( PlotDGDataInPeanoBlockFormat, self ).__init__()
19
20 self.d = {}
21 self.d["SOLVER_INSTANCE"] = solver.instance_name()
22 self.d["SOLVER_NAME"] = solver.typename()
23 #self.d[ "FILENAME" ] = filename
24 #self.d[ "CELL_UNKNOWN_NAME" ] = cell_unknown.name
25 #self.d[ "GETTER" ] = getter
26 #self.d[ "NUMBER_OF_UNKNOWNS_PER_CELL" ] = number_of_unknows_per_cell
27 #self.d[ "DESCRIPTION" ] = description
28 #self.d[ "TIMESTAMP" ] = time_stamp_evaluation
29 #self.d[ "GUARD_PREDICATE" ] = guard_predicate
30 #self.d[ "META_DATA" ] = ""
31 #self.additional_includes = additional_includes
32
33
34 __Template_Constructor = """
35 _writer = nullptr;
36 _valueWriter = nullptr;
37 _rhsWriter = nullptr;
38 _treeNumber = treeNumber;
39
40 // An MPI lock (critical section) would be important!
41
42 logDebug( "PlotGrid2PlotGridInPeanoBlockFormat1()", "created tree instance for " << treeNumber );
43"""
44
45
47 return self.__Template_Constructor.format(**self.d)
48
49
50 __Template_EndTraversal = """
51 assertion(_valueWriter!=nullptr);
52 assertion1(_valueWriter!=nullptr,_treeNumber);
53
54 assertion(_rhsWriter!=nullptr);
55 assertion1(_rhsWriter!=nullptr,_treeNumber);
56
57 _valueWriter->close();
58 _rhsWriter->close();
59 _writer->writeToFile();
60
61 delete _valueWriter;
62 delete _rhsWriter;
63 delete _writer;
64
65 _valueWriter = nullptr;
66 _rhsWriter = nullptr;
67 _writer = nullptr;
68"""
69
71 return ""
72
73
75 return " return std::vector< peano4::grid::GridControlEvent >();\n"
76
77
79 return __name__.replace(".py", "").replace(".", "_")
80
81
83 return False
84
85
86 Template_TouchCellFirstTime = """
87if (fineGridCell{{SOLVER_NAME}}PETScData.getType() == celldata::{{SOLVER_NAME}}PETScData::Type::Interior) {
88 int patchIndex = _writer->plotPatch(
89 marker.x()-0.5 * marker.h(),
90 marker.h()
91 );
92
93 int valuePatchVertexIndex = _valueWriter->getFirstVertexWithinPatch(patchIndex);
94 int rhsPatchVertexIndex = _rhsWriter->getFirstVertexWithinPatch(patchIndex);
95
96 assertionEquals(valuePatchVertexIndex, rhsPatchVertexIndex);
97
98
99 int currentDoF = 0;
100 dfor(k,repositories::{{SOLVER_INSTANCE}}.Order+1) {
101 double* value = fineGridCell{{SOLVER_NAME}}.getValue().data();
102 double* rhs = fineGridCell{{SOLVER_NAME}}.getRhs().data();
103 _valueWriter->plotVertex( valuePatchVertexIndex, value+currentDoF );
104 _rhsWriter->plotVertex( rhsPatchVertexIndex, rhs+currentDoF );
105 valuePatchVertexIndex++;
106 rhsPatchVertexIndex++;
107 currentDoF += repositories::{{SOLVER_INSTANCE}}.CellUnknowns;
108 }
109
110}
111"""
112
113
114 __Template_BeginTraversal = """
115 tarch::mpi::Lock lock( _semaphore );
116
117 std::ostringstream snapshotFileName;
118 snapshotFileName << "{{SOLVER_NAME}}";
119
120 if (tarch::mpi::Rank::getInstance().getNumberOfRanks()>1 ) {
121 snapshotFileName << "-rank-" << tarch::mpi::Rank::getInstance().getRank();
122 }
123
124 _writer = new tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter(
125 Dimensions, snapshotFileName.str(), "{{FILENAME}}",
126 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::IndexFileMode::NoIndexFile,
127 0.0
128 );
129
130 _valueWriter = _writer->createVertexDataWriter(
131 "value",
132 repositories::{{SOLVER_INSTANCE}}.Order+1, // nodes per axis
133 repositories::{{SOLVER_INSTANCE}}.CellUnknowns,
134 "Solution",
135 "Solution as delivered through PETSc"
136 );
137 _rhsWriter = _writer->createVertexDataWriter(
138 "rhs",
139 repositories::{{SOLVER_INSTANCE}}.Order+1, // nodes per axis
140 repositories::{{SOLVER_INSTANCE}}.CellUnknowns,
141 "Right-hand side",
142 "Nodal right-hand side value"
143 );
144"""
145
146
147 def get_body_of_operation(self,operation_name):
148 result = "\n"
149 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
150 result = jinja2.Template( self.Template_TouchCellFirstTime).render(**self.d)
151 if operation_name==ActionSet.OPERATION_BEGIN_TRAVERSAL:
152 result = jinja2.Template( self.__Template_BeginTraversal).render(**self.d)
153 if operation_name==ActionSet.OPERATION_END_TRAVERSAL:
154 result = jinja2.Template( self.__Template_EndTraversal).render(**self.d)
155 return result
156
157
158 def get_attributes(self):
159 return """
160 static tarch::mpi::BooleanSemaphore _semaphore;
161
162 int _treeNumber;
163
164 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter* _writer;
165 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::VertexDataWriter* _valueWriter;
166 tarch::plotter::griddata::blockstructured::PeanoTextPatchFileWriter::VertexDataWriter* _rhsWriter;
167"""
168
169
170 def get_includes(self):
171 return """
172#include "tarch/plotter/griddata/blockstructured/PeanoTextPatchFileWriter.h"
173#include "tarch/mpi/Lock.h"
174#include "tarch/mpi/BooleanSemaphore.h"
175#include "tarch/multicore/Lock.h"
176#include "tarch/multicore/BooleanSemaphore.h"
177#include "peano4/utils/Loop.h"
178#include "peano4/parallel/SpacetreeSet.h"
179#include "../repositories/SolverRepository.h"
180"""
181
182
183 def get_static_initialisations(self,full_qualified_classname):
184 return """
185tarch::mpi::BooleanSemaphore """ + full_qualified_classname + """::_semaphore;
186"""
187
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.
Action set (reactions to events)
Definition ActionSet.py:6