Peano
Loading...
Searching...
No Matches
PatchToDoubleArray.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
4import os
5
6from .DoF import DoFAssociation
7
8class FloatTypes():
9 def __init__(self, float_type):
10 if float_type=="float":
11 self.cpp = "float"
12 self.mpi = "MPI_FLOAT"
14 elif float_type=="double":
15 self.cpp = "double"
16 self.mpi = "MPI_DOUBLE"
18 elif float_type=="long double":
19 self.cpp = "long double"
20 self.mpi = "MPI_LONG_DOUBLE"
22 elif float_type=="_Float16":
23 self.cpp = "_Float16"
24 self.mpi = "MPI_BYTE"
26 elif float_type=="std::float16_t":
27 self.cpp = "std::float16_t"
28 self.mpi = "MPI_BYTE"
30 elif float_type=="__bf16":
31 self.cpp = "__bf16"
32 self.mpi = "MPI_BYTE"
34 elif float_type=="std::bfloat16_t":
35 self.cpp = "std::bfloat16_t"
36 self.mpi = "MPI_BYTE"
38 else:
39 raise Exception("Float type " + float_type + " not recognized")
40
41
43 """
44
45 Very simple converter which maps the patch 1:1 onto a double array.
46 By default, I leave all the MPI merges empty though obviously the
47 merges often are plain copying over along faces (see the discussion
48 on Finite Volumes in the guidebook). If you need any proper MPI
49 handling, use merge_method_definition to inject it. Depending
50 on how you use your patch (as cell or face or vertex data structure)
51 the thing you pass has the respective semantics. The most popular
52 default merge implementation is the one you find in the blockstructured
53 toolbox.
54
55 """
56 def __init__(self,patch, float_type="double"):
57 """
58
59 includes Includes to be added to the generated file. This is something
60 totally different than get_header_file_include(). You will need to set
61 something here if your send/receive conditions, e.g., call other stuff.
62
63 """
64 self.data = patch
66 self.send_condition = "true"
68 # @todo Das ist voellig falsch. Das sollte direkt im Patch sitzen und nicht im generator
69 self.load_store_compute_flag = "::peano4::grid::LoadStoreComputeFlag::LoadFromInputStream_ProvideToCalculations_StoreToOutputStream"
70 self.includes = ""
71 self.float_type = FloatTypes(float_type)
72
73
74 def __str__(self):
75 result = """Map to double array
76 - send condition: """ + self.send_condition + """
77 - receive/merge condition: """ + self.receive_and_merge_condition + """
78 - load/store/compute flag: """ + self.load_store_compute_flag + """
79 - merge criterion: """
80
81 if self.merge_method_definition!="":
82 result += """user-defined
83"""
84 else:
85 result += """nop
86"""
87 return result
88
89
91 return "peano4::stacks::STDVectorStack< " + self.data.get_full_qualified_type() + " >";
92
93
95 """
96
97 This is the include statement for the data container. It is not something
98 directly generated but how to use the generated code.
99
100 """
101 return """
102#include "peano4/stacks/STDVectorStack.h"
103#include \"""" + self.data.namespace[-1] + "/" + self.data.name + """.h"
104"""
105
106
108 d = {
109 "CARDINALITY_2D": str( int( self.data.no_of_unknowns*self.data.dim[0]*self.data.dim[1] )),
110 "CARDINALITY_3D": str( int( self.data.no_of_unknowns*self.data.dim[0]*self.data.dim[1]*self.data.dim[2] )),
111 "MERGE_METHOD_DECLARATIONS": "",
112 "MERGE_METHOD_DEFINITIONS": "",
113 "SEND_CONDITION": self.send_condition,
114 "RECEIVE_AND_MERGE_CONDITION": self.receive_and_merge_condition,
115 "INCLUDES": self.includes,
116 "DATA_ASSOCIATION": int(self.data.association),
117 "MERGE_METHOD_DEFINITION": self.merge_method_definition,
118 "LOAD_STORE_COMPUTE_FLAG": self.load_store_compute_flag,
119 "FLOAT_TYPE": self.float_type.cpp,
120 "MPI_FLOAT_TYPE": self.float_type.mpi,
121 "MPI_ELEMENTS_PER_FLOAT": self.float_type.number_of_mpi_types_per_element,
122 "ADDITIONAL_LOAD_STORE_ARGUMENTS": self.data.additional_load_and_store_arguments
123 }
124 return d
125
126
127
128 def construct_output(self,output):
130 """
131 Pass in a version of output
132 """
133 output.makefile.add_cpp_file( self.data.subdirectory + self.data.namespace[-1] + "/" + self.data.name + ".cpp", generated=True )
134 templatefile_prefix = os.path.realpath(__file__).replace( ".pyc", "" ).replace( ".py", "" )
136 templatefile_prefix+".template.h",
137 templatefile_prefix+".template.cpp",
138 self.data.name,
139 self.data.namespace,
140 self.data.subdirectory + self.data.namespace[-1],
141 d,
142 True)
143 output.add(generated_files)
Very simple converter which maps the patch 1:1 onto a double array.
get_header_file_include(self)
This is the include statement for the data container.
__init__(self, patch, float_type="double")
includes Includes to be added to the generated file.