12 For development purposes, we add a way to print the exact solution
13 from the cells to a file.
15 We do this lazily, without concerning ourselves with what indices
16 are available to us over mpi ranks.
18 We store everything in a std::vector, and print it out to file when
22 templateTouchCellFirstTime =
"""
23 if ( fineGridCell{{SOLVER_NAME}}PETScData.getType() == celldata::{{SOLVER_NAME}}PETScData::Type::Interior )
25 std::pair<int,int> localCellIndex = std::make_pair(_spacetreeId, fineGridCell{{SOLVER_NAME}}PETScData.getUnknownBaseNumber());
26 int globalCellIndex = repositories::{{SOLVER_INSTANCE}}.getLocalToGlobalMap().getGlobalIndex(localCellIndex, ::petsc::LocalToGlobalMap::Type::Cell);
29 for (int i=0; i<repositories::{{SOLVER_INSTANCE}}.DoFsPerCell; i++)
31 // we will want this to be get exactSol
32 exactSolutionAtEachCellDof[globalCellIndex+i] = fineGridCell{{SOLVER_NAME}}.getExactSol(i);
37 templateEndTraversal =
"""
38 std::ofstream outfile("./exactSol.txt");
39 for (const auto& s:exactSolutionAtEachCellDof) outfile << s << "\\n";
48Initialise vertex-associated degrees of freedom
50The initialisation requires a solver object, as we have to know what C++
51object this solver will produce.
53solver: petsc.solvers.CollocatedLowOrderDiscretisation or similar solver where
54 degrees of freedom are assigned exclusively to the vertices.
57 super( PlotExactSolution, self ).
__init__()
59 self.
d[
"SOLVER_INSTANCE"] = solver.instance_name()
60 self.
d[
"SOLVER_NAME"] = solver.typename()
65Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
67Only touchVertexFirstTime is an event where this action set actually
68does something: It inserts the template TemplateInitVertex and
69replaces it with entries from the dictionary. The latter is befilled
74 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
78 if operation_name==peano4.solversteps.ActionSet.OPERATION_END_TRAVERSAL:
87 Configure name of generated C++ action set
89 This action set will end up in the directory observers with a name that
90 reflects how the observer (initialisation) is mapped onto this action
91 set. The name pattern is ObserverName2ActionSetIdentifier where this
92 routine co-determines the ActionSetIdentifier. We make is reflect the
96 return __name__.replace(
".py",
"").replace(
".",
"_")
102 The action set that Peano will generate that corresponds to this class
103 should not be modified by users and can safely be overwritten every time
104 we run the Python toolkit.
113 Add some additional includes
115 We need the solver repository here as we access hte solver object, and we
116 also need access to all of Peano's d-dimensional for loops.
120#include "../repositories/SolverRepository.h"
121#include "peano4/utils/Loop.h"
128 Return attributes as copied and pasted into the generated class.
130 Please note that action sets are not persistent, i.e. there is one
131 object creation per grid sweep per tree.
136 std::vector<double> exactSolutionAtEachCellDof;
141 _spacetreeId = treeNumber;
142 exactSolutionAtEachCellDof.resize(
143 repositories::{{SOLVER_INSTANCE}}.getLocalToGlobalMap().getTotalNumberOfCells()
148 return jinja2.Template(body).render(**self.
d)
For development purposes, we add a way to print the exact solution from the cells to a file.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_action_set_name(self)
Configure name of generated C++ action set.
__init__(self, solver)
Initialise vertex-associated degrees of freedom.
user_should_modify_template(self)
The action set that Peano will generate that corresponds to this class should not be modified by user...
get_constructor_body(self)
Define a tailored constructor body.
get_body_of_operation(self, operation_name)
Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
get_includes(self)
Add some additional includes.
str templateTouchCellFirstTime
Action set (reactions to events)