66 def __init__(self,classname,namespace,subdirectory,implementation = None):
69 implementation Should be of type peano4.api.solversteps.ActionSet or
70 None. If it is None, then the generated stuff will be a
79 (peano4.api.solversteps.ActionSet.OPERATION_BEGIN_TRAVERSAL,
"void"),
80 (peano4.api.solversteps.ActionSet.OPERATION_END_TRAVERSAL,
"void")
135 def __generate_header(self,overwrite,directory):
138 default_overwrite =
True
140 default_overwrite =
False
142 if write_file(overwrite,default_overwrite,filename):
143 print(
"{} written by {}".format(filename, os.path.basename(inspect.getfile(self.
__class__))))
145 with open( filename,
"w" )
as outputfile:
147 include_guard =
"_{}_H_".format(full_qualified_classname.replace(
"::",
"_" ).upper())
149 outputfile.write(
"#ifndef {}\n#define {}\n\n\n".format(include_guard, include_guard))
151 outputfile.write(
"""
152#include "peano4/utils/Globals.h"
153#include "peano4/datamanagement/VertexEnumerator.h"
154#include "peano4/datamanagement/VertexMarker.h"
155#include "peano4/datamanagement/FaceEnumerator.h"
156#include "peano4/datamanagement/FaceMarker.h"
157#include "peano4/datamanagement/CellMarker.h"
158#include "peano4/grid/GridControlEvent.h"
159#include "tarch/la/Vector.h"
167 outputfile.write(
"\n\n" )
171 for i
in self.
namespace: outputfile.write(
"namespace " + i +
" {\n" )
172 outputfile.write(
" class {};\n".format(self.
classname))
173 for i
in self.
namespace: outputfile.write(
"}\n" )
175 outputfile.write(
"class " + full_qualified_classname +
"{\n" )
176 outputfile.write(
" private:\n" )
177 outputfile.write(
" static tarch::logging::Log _log;\n" )
180 outputfile.write(
" public:\n" )
181 outputfile.write(
"""
183 * Create action instance for one tree for one grid sweep
185 * <h2> Thread safety </h2>
187 * The creation of individual trees usually happens through peano4::parallel::SpacetreeSet::createObserverCloneIfRequired().
188 * This routine is called lazily when we start to traverse a subtree.
189 * Therefore, the creation of actions is not thread-safe.
192 * @param treeNumber Number of the spacetree for which we create the tree instance. Is
193 * smaller 0 if this is the prototype action used on a rank from which
194 * the real actions are constructed from.
197 outputfile.write(
" " + self.
classname +
"(int treeNumber);\n\n" )
198 outputfile.write(
" ~" + self.
classname +
"();\n\n" )
199 outputfile.write(
"""
200 std::vector< peano4::grid::GridControlEvent > createGridControlEventsForNextTraversal() const;
201 static void prepareTraversal();
202 static void unprepareTraversal();
206 outputfile.write(
"};\n\n\n" )
207 outputfile.write(
"#endif\n\n" )
212 def __generate_implementation(self,overwrite,directory):
215 default_overwrite =
True
217 default_overwrite =
False
218 if write_file(overwrite,default_overwrite,filename):
219 print(
"{} written by {}".format(filename, os.path.basename(inspect.getfile(self.
__class__))))
220 outputfile = open( filename,
"w" )
224 outputfile.write(
"#include \"" + self.
classname +
".h\"\n\n\n" )
229 outputfile.write(
"\n\n\n" )
233 outputfile.write(
"}\n\n\n" )
237 outputfile.write(
"}\n\n\n" )
239 outputfile.write(
"std::vector< peano4::grid::GridControlEvent > " + self.
__get_full_qualified_class_name() +
"::createGridControlEventsForNextTraversal() const {\n" )
240 outputfile.write( self.
implementation.get_implementation_of_createGridControlEventsForNextTraversal() )
241 outputfile.write(
"}\n\n\n" )
244 outputfile.write( self.
implementation.get_implementation_of_prepareTraversal() )
245 outputfile.write(
"}\n\n\n" )
248 outputfile.write( self.
implementation.get_implementation_of_unprepareTraversal() )
249 outputfile.write(
"}\n\n\n" )
252 outputfile.write( operation[1] )
253 outputfile.write(
" " )
256 outputfile.write(
" {\n" )
257 outputfile.write( self.
implementation.get_implementation_of_operation( operation[0] ) )
258 outputfile.write(
"\n" )
259 outputfile.write(
"}\n\n\n" )