Peano
Loading...
Searching...
No Matches
DGMatrices.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from copy import deepcopy
4
5import peano4.output
6
7from exahype2.solvers.MathUtils import MathUtils
8
9
10class DGMatrices(object):
11 def __init__(self, dictionary):
12 self.d = deepcopy(dictionary)
13
15 self, namespace, output, subdirectory, template_prefix, output_path
16 ):
17 if self.d["POLYNOMIAL_TYPE"] == "legendre":
18 # Get GL nodes
19 wGPN, xGPN = MathUtils.getGaussLegendre(self.d["NUMBER_OF_DOF"])
20 elif self.d["POLYNOMIAL_TYPE"] == "lobatto":
21 # Get GLL nodes
22 wGPN, xGPN = MathUtils.getGaussLobatto(self.d["NUMBER_OF_DOF"])
23 xGPN = xGPN[::-1]
24 else:
25 raise ValueError(
26 "Quadrature type " + self.d["POLYNOMIAL_TYPE"] + " not supported."
27 )
28
29 padSize = self.d["NUMBER_OF_DOF_PADDED"] - self.d["NUMBER_OF_DOF"]
30 self.d["nDofPad_seq"] = range(self.d["NUMBER_OF_DOF_PADDED"])
31 self.d["nDofPadTimesnDof_seq"] = range(
32 self.d["NUMBER_OF_DOF_PADDED"] * self.d["NUMBER_OF_DOF"]
33 )
34
35 # [FLCoeff 0...0]; [FRCoeff 0...0];
36 # right now FLCoeff, FRCoeff no pad (gives no benefit w.r.t libxsmm)
37 FLCoeff, _ = MathUtils.baseFunc1d(
38 0.0, xGPN, self.d["NUMBER_OF_DOF"]
39 ) # is also F0
40 FRCoeff, _ = MathUtils.baseFunc1d(1.0, xGPN, self.d["NUMBER_OF_DOF"])
41 self.d["FLCoeff"] = MathUtils.vectorPad(FLCoeff, padSize)
42 self.d["FRCoeff"] = MathUtils.vectorPad(FRCoeff, padSize)
43
44 # Matrices are stored in column major order (so the padding should be on the bottom rows)
45 # [ Mat ]
46 # [0...0]
47 # [0...0]
48 # Kxi
49 Kxi = MathUtils.assembleStiffnessMatrix(xGPN, wGPN, self.d["NUMBER_OF_DOF"])
50 self.d["Kxi"] = MathUtils.matrixPadAndFlatten_ColMajor(Kxi, padSize)
51 self.d["Kxi_T"] = MathUtils.matrixPadAndFlatten_RowMajor(
52 Kxi, padSize
53 ) # transpose
54
55 # iK1_T
56 iK1 = MathUtils.matrixInverse(
57 MathUtils.assembleK1(Kxi, xGPN, self.d["NUMBER_OF_DOF"])
58 )
59 self.d["iK1_T"] = MathUtils.matrixPadAndFlatten_RowMajor(
60 iK1, padSize
61 ) # transpose
62
63 # dudx
64 MM = MathUtils.assembleMassMatrix(xGPN, wGPN, self.d["NUMBER_OF_DOF"])
65 dudx = MathUtils.assembleDiscreteDerivativeOperator(MM, Kxi)
66 self.d["dudx"] = MathUtils.matrixPadAndFlatten_ColMajor(dudx, padSize)
67 self.d["dudx_T"] = MathUtils.matrixPadAndFlatten_RowMajor(
68 dudx, padSize
69 ) # transpose
70
71 # fineGridProjector1d
72 fineGridProjector1d_0 = MathUtils.assembleFineGridProjector1d(
73 xGPN, 0, self.d["NUMBER_OF_DOF"]
74 )
75 fineGridProjector1d_1 = MathUtils.assembleFineGridProjector1d(
76 xGPN, 1, self.d["NUMBER_OF_DOF"]
77 )
78 fineGridProjector1d_2 = MathUtils.assembleFineGridProjector1d(
79 xGPN, 2, self.d["NUMBER_OF_DOF"]
80 )
81 self.d["fineGridProjector1d_0"] = MathUtils.matrixPadAndFlatten_ColMajor(
82 fineGridProjector1d_0, padSize
83 )
84 self.d["fineGridProjector1d_1"] = MathUtils.matrixPadAndFlatten_ColMajor(
85 fineGridProjector1d_1, padSize
86 )
87 self.d["fineGridProjector1d_2"] = MathUtils.matrixPadAndFlatten_ColMajor(
88 fineGridProjector1d_2, padSize
89 )
90
91 # fineGridProjector1d_T_weighted
92 for i in range(self.d["NUMBER_OF_DOF"]):
93 for j in range(self.d["NUMBER_OF_DOF"]):
94 fineGridProjector1d_0[i][j] *= wGPN[j] / wGPN[i] / 3.0
95 fineGridProjector1d_1[i][j] *= wGPN[j] / wGPN[i] / 3.0
96 fineGridProjector1d_2[i][j] *= wGPN[j] / wGPN[i] / 3.0
97 self.d[
98 "fineGridProjector1d_T_weighted_0"
99 ] = MathUtils.matrixPadAndFlatten_RowMajor(fineGridProjector1d_0, padSize)
100 self.d[
101 "fineGridProjector1d_T_weighted_1"
102 ] = MathUtils.matrixPadAndFlatten_RowMajor(fineGridProjector1d_1, padSize)
103 self.d[
104 "fineGridProjector1d_T_weighted_2"
105 ] = MathUtils.matrixPadAndFlatten_RowMajor(fineGridProjector1d_2, padSize)
106
108 headfile_template=template_prefix + "DGMatrices.template.h",
109 cppfile_template=template_prefix + "DGMatrices.template.cpp",
110 classname=output_path + "/DGMatrices",
111 namespace=namespace,
112 subdirectory=subdirectory + ".",
113 dictionary=self.d,
114 default_overwrite=True,
115 apply_iteratively=True,
116 )
117 output.add(generated_kernels)
118 output.makefile.add_h_file(output_path + "/DGMatrices.h", generated=True)
119 output.makefile.add_cpp_file(output_path + "/DGMatrices.cpp", generated=True)
generate_kernels(self, namespace, output, subdirectory, template_prefix, output_path)
Definition DGMatrices.py:16