6from .Helper
import write_file
8from .Overwrite
import Overwrite
13 def __init__(self,classname,namespace,subdirectory,implementation = None):
16 Implementation of an Action Set
18 Please consult peano4.solversteps.ActionSet for a description.
20 implementation Should be of type peano4.solversteps.Mapping or None. If
21 it is None, then the generated stuff will be a sole
29 (peano4.solversteps.ActionSet.OPERATION_BEGIN_TRAVERSAL,
"void"),
30 (peano4.solversteps.ActionSet.OPERATION_END_TRAVERSAL,
"void")
38 signature is a long tuple. The first entry is the name of the routine,
39 the second entry is the result type. From thereon, one entry gives the
40 name of an attribute, the second one the type.
45 for i
in self.
include_files: outputfile.write(
'#include "{}"\n'.format(i) )
50 while i<len(operation):
51 result += operation[i+1]
53 result += operation[i]
63 outputfile points to file, operation to an operation object as added by the solver step
66 outputfile.write(
" virtual " )
68 outputfile.write(
" " )
69 outputfile.write( operation[1] )
70 outputfile.write(
" ")
71 outputfile.write( operation[0] )
74 outputfile.write(
" = 0")
75 outputfile.write(
";\n\n")
78 full_qualified_classname =
""
80 full_qualified_classname += i
81 full_qualified_classname +=
"::"
82 full_qualified_classname += self.
classname
83 return full_qualified_classname
87 default_overwrite =
True
89 default_overwrite =
False
91 if write_file(overwrite,default_overwrite,filename):
93 print(
"{} written by {}".format(filename, os.path.basename(inspect.getfile(self.
__class__))))
95 with open( filename,
"w" )
as outputfile:
97 include_guard =
"_{}_H_".format(full_qualified_classname.replace(
"::",
"_" ).upper())
99 outputfile.write(
"#ifndef {}\n#define {}\n\n\n".format(include_guard, include_guard))
101 outputfile.write(
"""
102#include "peano4/utils/Globals.h"
103#include "peano4/datamanagement/VertexEnumerator.h"
104#include "peano4/datamanagement/VertexMarker.h"
105#include "peano4/datamanagement/FaceEnumerator.h"
106#include "peano4/datamanagement/FaceMarker.h"
107#include "peano4/datamanagement/CellMarker.h"
108#include "peano4/grid/GridControlEvent.h"
109#include "tarch/la/Vector.h"
117 outputfile.write(
"\n\n" )
121 for i
in self.
namespace: outputfile.write(
"namespace " + i +
" {\n" )
122 outputfile.write(
" class {};\n".format(self.
classname))
123 for i
in self.
namespace: outputfile.write(
"}\n" )
125 outputfile.write(
"class " + full_qualified_classname +
"{\n" )
126 outputfile.write(
" private:\n" )
127 outputfile.write(
" static tarch::logging::Log _log;\n" )
130 outputfile.write(
" public:\n" )
131 outputfile.write(
"""
133 * Create action instance for one tree for one grid sweep
135 * <h2> Thread safety </h2>
137 * The creation of individual trees usually happens through peano4::parallel::SpacetreeSet::createObserverCloneIfRequired().
138 * This routine is called lazily when we start to traverse a subtree.
139 * Therefore, the creation of actions is not thread-safe.
142 * @param treeNumber Number of the spacetree for which we create the tree instance. Is
143 * smaller 0 if this is the prototype action used on a rank from which
144 * the real actions are constructed from.
147 outputfile.write(
" " + self.
classname +
"(int treeNumber);\n\n" )
148 outputfile.write(
" ~" + self.
classname +
"();\n\n" )
149 outputfile.write(
"""
150 std::vector< peano4::grid::GridControlEvent > getGridControlEvents() const;
151 static void prepareTraversal();
152 static void unprepareTraversal();
156 outputfile.write(
"};\n\n\n" )
157 outputfile.write(
"#endif\n\n" )
164 default_overwrite =
True
166 default_overwrite =
False
167 if write_file(overwrite,default_overwrite,filename):
169 print(
"{} written by {}".format(filename, os.path.basename(inspect.getfile(self.
__class__))))
170 outputfile = open( filename,
"w" )
174 outputfile.write(
"#include \"" + self.
classname +
".h\"\n\n\n" )
179 outputfile.write(
"\n\n\n" )
183 outputfile.write(
"}\n\n\n" )
187 outputfile.write(
"}\n\n\n" )
190 outputfile.write( self.
implementation.get_body_of_getGridControlEvents() )
191 outputfile.write(
"}\n\n\n" )
194 outputfile.write( self.
implementation.get_body_of_prepareTraversal() )
195 outputfile.write(
"}\n\n\n" )
198 outputfile.write( self.
implementation.get_body_of_unprepareTraversal() )
199 outputfile.write(
"}\n\n\n" )
202 outputfile.write( operation[1] )
203 outputfile.write(
" " )
206 outputfile.write(
" {\n" )
207 outputfile.write( self.
implementation.get_body_of_operation( operation[0] ) )
208 outputfile.write(
"\n" )
209 outputfile.write(
"}\n\n\n" )
212 if not os.path.exists( directory +
"/" + self.
subdirectory ):
__generate_implementation(self, overwrite, directory)
__generate_includes(self, outputfile)
__generate_operation(self, outputfile, operation)
outputfile points to file, operation to an operation object as added by the solver step
generate(self, overwrite, directory)
add_operation(self, name, signature)
signature is a long tuple.
__get_full_qualified_class_name(self)
__generate_header(self, overwrite, directory)
__get_operation_arguments(self, operation)
__init__(self, classname, namespace, subdirectory, implementation=None)
Implementation of an Action Set.
Action set (reactions to events)