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 self.load_store_compute_flag = "::peano4::grid::LoadStoreComputeFlag::LoadFromInputStream_ProvideToCalculations_StoreToOutputStream"
69 self.includes = ""
70 self.float_type = FloatTypes(float_type)
71
72
73 def __str__(self):
74 result = """Map to double array
75 - send condition: """ + self.send_condition + """
76 - receive/merge condition: """ + self.receive_and_merge_condition + """
77 - load/store/compute flag: """ + self.load_store_compute_flag + """
78 - merge criterion: """
79
80 if self.merge_method_definition!="":
81 result += """user-defined
82"""
83 else:
84 result += """nop
85"""
86 return result
87
88
90 return "peano4::stacks::STDVectorStack< " + self.data.get_full_qualified_type() + " >";
91
92
94 """
95
96 This is the include statement for the data container. It is not something
97 directly generated but how to use the generated code.
98
99 """
100 return """
101#include "peano4/stacks/STDVectorStack.h"
102#include \"""" + self.data.namespace[-1] + "/" + self.data.name + """.h"
103"""
104
105
107 d = {
108 "CARDINALITY_2D": str( int( self.data.no_of_unknowns*self.data.dim[0]*self.data.dim[1] )),
109 "CARDINALITY_3D": str( int( self.data.no_of_unknowns*self.data.dim[0]*self.data.dim[1]*self.data.dim[2] )),
110 "MERGE_METHOD_DECLARATIONS": "",
111 "MERGE_METHOD_DEFINITIONS": "",
112 "SEND_CONDITION": self.send_condition,
113 "RECEIVE_AND_MERGE_CONDITION": self.receive_and_merge_condition,
114 "INCLUDES": self.includes,
115 "DATA_ASSOCIATION": int(self.data.association),
116 "MERGE_METHOD_DEFINITION": self.merge_method_definition,
117 "LOAD_STORE_COMPUTE_FLAG": self.load_store_compute_flag,
118 "FLOAT_TYPE": self.float_type.cpp,
119 "MPI_FLOAT_TYPE": self.float_type.mpi,
120 "MPI_ELEMENTS_PER_FLOAT": self.float_type.number_of_mpi_types_per_element,
121 "ADDITIONAL_LOAD_STORE_ARGUMENTS": self.data.additional_load_and_store_arguments
122 }
123 return d
124
125
126
127 def construct_output(self,output):
129 """
130 Pass in a version of output
131 """
132 output.makefile.add_cpp_file( self.data.subdirectory + self.data.namespace[-1] + "/" + self.data.name + ".cpp", generated=True )
133 templatefile_prefix = os.path.realpath(__file__).replace( ".pyc", "" ).replace( ".py", "" )
135 templatefile_prefix+".template.h",
136 templatefile_prefix+".template.cpp",
137 self.data.name,
138 self.data.namespace,
139 self.data.subdirectory + self.data.namespace[-1],
140 d,
141 True)
142 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.