Peano
Loading...
Searching...
No Matches
CellIntegral3D.py
Go to the documentation of this file.
1def cellIntegral(patchData: "CellData<double, double>&") -> "void":
2 N = Integer("patchData.numberOfCells")
3 t = DataBlock([[0, N]], "patchData.t", "double")
4 dt = DataBlock([[0, N]], "patchData.dt", "double")
5 h = DataBlock([[0, N]], "patchData.cellSize", "tarch::la::Vector<3, double>")
6 x = DataBlock([[0, N]], "patchData.cellCentre", "tarch::la::Vector<3, double>")
7
8 input = DataBlock([[0, NumberOfUnknowns + NumberOfAuxiliaryVariables], [0, DGOrder + 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, N]], "patchData.QIn")
9 output = DataBlock([[0, NumberOfUnknowns + NumberOfAuxiliaryVariables], [0, DGOrder + 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, N]], "patchData.QOut")
10
11 output = 0.0
12 mass_matrix_1d = DiagonalMatrix(DGOrder + 1, "SolverType::MassMatrixDiagonal1d")
13 mass_matrix_2d = kroneckerProduct(mass_matrix_1d, mass_matrix_1d)
14 mass_matrix_3d = kroneckerProduct(mass_matrix_2d, mass_matrix_1d)
15 identity_matrix = DiagonalMatrix(DGOrder + 1, 1.0)
16
17 quadrature_positions = DataBlock([[0, 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, N]], eval("getQuadraturePoint", index, x, h, DGOrder, "SolverType::QuadraturePoints1d"), "tarch::la::Vector<3, double>")
18
19 if EvaluateSource:
20 source = DataBlock([[0, NumberOfUnknowns], [0, DGOrder + 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, N]], eval("sourceTerm", input, quadrature_positions, t, dt))
21 output = output + h(0) * h(1) * h(2) * mass_matrix_3d * source
22
23 if EvaluateFlux:
24 flux_x = DataBlock([[0, NumberOfUnknowns], [0, DGOrder + 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, N]], eval("flux", input, quadrature_positions, t, dt, 0))
25 flux_y = DataBlock([[0, NumberOfUnknowns], [0, DGOrder + 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, N]], eval("flux", input, quadrature_positions, t, dt, 1))
26 flux_z = DataBlock([[0, NumberOfUnknowns], [0, DGOrder + 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, N]], eval("flux", input, quadrature_positions, t, dt, 2))
27
28 mass_matrix_x_2d = kroneckerProduct(mass_matrix_1d, mass_matrix_1d)
29 mass_matrix_x = kroneckerProduct(mass_matrix_x_2d, identity_matrix)
30 mass_matrix_y_2d = kroneckerProduct(mass_matrix_1d, identity_matrix)
31 mass_matrix_y = kroneckerProduct(mass_matrix_y_2d, mass_matrix_1d)
32 mass_matrix_z_2d = kroneckerProduct(identity_matrix, mass_matrix_1d)
33 mass_matrix_z = kroneckerProduct(mass_matrix_z_2d, mass_matrix_1d)
34
35 stiffness_matrix_1d = Matrix(DGOrder + 1, DGOrder + 1, "SolverType::StiffnessOperator1d")
36 stiffness_matrix_x_2d = kroneckerProduct(stiffness_matrix_1d, identity_matrix)
37 stiffness_matrix_z = kroneckerProduct(stiffness_matrix_x_2d, identity_matrix)
38
39 stiffness_matrix_y_2d = kroneckerProduct(identity_matrix, stiffness_matrix_1d)
40 stiffness_matrix_y = kroneckerProduct(stiffness_matrix_y_2d, identity_matrix)
41
42 stiffness_matrix_z_2d = kroneckerProduct(identity_matrix, identity_matrix)
43 stiffness_matrix_x = kroneckerProduct(stiffness_matrix_z_2d, stiffness_matrix_1d)
44
45 matrixVectorProduct(stiffness_matrix_x, flux_x, flux_x_contribution)
46 matrixVectorProduct(stiffness_matrix_y, flux_y, flux_y_contribution)
47 matrixVectorProduct(stiffness_matrix_z, flux_z, flux_z_contribution)
48
49 flux_x_contribution = h(1) * h(2) * mass_matrix_x * flux_x_contribution
50 flux_y_contribution = h(0) * h(2) * mass_matrix_y * flux_y_contribution
51 flux_z_contribution = h(0) * h(1) * mass_matrix_z * flux_z_contribution
52
53 output[0:NumberOfUnknowns, :, :] = output[0:NumberOfUnknowns, :, :] + flux_x_contribution + flux_y_contribution + flux_z_contribution
54
55 if EvaluateNonconservativeProduct:
56 derivative_matrix_1d = Matrix(DGOrder + 1, DGOrder + 1, "SolverType::DerivativeOperator1d")
57 derivative_matrix_x_2d = kroneckerProduct(derivative_matrix_1d, identity_matrix)
58 derivative_matrix_z = kroneckerProduct(derivative_matrix_x_2d, identity_matrix)
59
60 derivative_matrix_y_2d = kroneckerProduct(identity_matrix, derivative_matrix_1d)
61 derivative_matrix_y = kroneckerProduct(derivative_matrix_y_2d, identity_matrix)
62
63 derivative_matrix_z_2d = kroneckerProduct(identity_matrix, identity_matrix)
64 derivative_matrix_x = kroneckerProduct(derivative_matrix_z_2d, derivative_matrix_1d)
65
66 matrixVectorProduct(derivative_matrix_x, input, gradient_x)
67 matrixVectorProduct(derivative_matrix_y, input, gradient_y)
68 matrixVectorProduct(derivative_matrix_z, input, gradient_z)
69 gradient_x = gradient_x / h(0)
70 gradient_y = gradient_y / h(1)
71 gradient_z = gradient_z / h(2)
72
73 nonconservative_product_x = DataBlock([[0, NumberOfUnknowns], [0, DGOrder + 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, N]], eval("nonconservativeProduct", input, gradient_x, quadrature_positions, t, dt, 0))
74 nonconservative_product_y = DataBlock([[0, NumberOfUnknowns], [0, DGOrder + 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, N]], eval("nonconservativeProduct", input, gradient_y, quadrature_positions, t, dt, 1))
75 nonconservative_product_z = DataBlock([[0, NumberOfUnknowns], [0, DGOrder + 1], [0, DGOrder + 1], [0, DGOrder + 1], [0, N]], eval("nonconservativeProduct", input, gradient_z, quadrature_positions, t, dt, 2))
76
77 output[0:NumberOfUnknowns, :, :] = output[0:NumberOfUnknowns, :, :] - h(0) * h(1) * h(2) * mass_matrix_3d * (nonconservative_product_x + nonconservative_product_y + nonconservative_product_z)
tarch::la::DynamicMatrix kroneckerProduct(const tarch::la::DynamicMatrix &lhs, const tarch::la::DynamicMatrix &rhs)
Wrapper around static routine, so I don't have to use full-qualified name.