MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
dgcartesianmortar.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef DGMORTAR_H_
8#define DGMORTAR_H_
9
10#include "INCLUDE/maiatypes.h"
11#include "UTIL/tensor.h"
13
14#include <string>
15
16namespace maia {
17namespace dg {
18namespace mortar {
19
20
21const MBool forward = true;
22const MBool reverse = false;
23const MInt lower = 0;
24const MInt upper = 1;
25
26
63inline void calcMortarProjectionMatrixP(const MInt sourcePolyDeg,
64 const MFloat* const sourceNodes,
65 const MFloat* const sourceBaryWeights,
66 const MInt targetPolyDeg,
67 const MFloat* const targetNodes,
68 MFloat* const matrix) {
69 const MInt sourceNoNodes = sourcePolyDeg + 1;
70 const MInt targetNoNodes = targetPolyDeg + 1;
71
72 // Matrix is Lagrange polynomials of source polynomial degree evaluated at
73 // nodes of target polynomial degree
74 for(MInt i = 0; i < targetNoNodes; i++) {
76 targetNodes[i], sourcePolyDeg, sourceNodes, sourceBaryWeights, &matrix[i * sourceNoNodes]);
77 }
78}
79
80
106inline void calcMortarProjectionMatrixHForward(const MInt polyDeg,
107 const MFloat* const nodes,
108 const MFloat* const wBary,
109 const MInt position,
110 MFloat* const matrix) {
111 const MInt noNodes = polyDeg + 1;
112
113 // Forward matrix is the Lagrange polynomials evaluated at other nodes
114 const MFloat shift = (position == dg::mortar::lower) ? -0.5 : 0.5;
115 for(MInt i = 0; i < noNodes; i++) {
117 0.5 * nodes[i] + shift, polyDeg, nodes, wBary, &matrix[i * noNodes]);
118 }
119}
120
121
160inline void calcMortarProjectionMatrixHReverse(const MInt polyDeg,
161 const MFloat* const nodes,
162 const MFloat* const wBary,
163 const MInt position,
164 MFloat* const matrix) {
165 const MInt noNodes = polyDeg + 1;
166
167 // Calculate nodes and quadrature weights for projection (always Gauss)
168 MFloatVector projectionNodes;
169 MFloatVector projectionWInt;
170 projectionNodes.resize(noNodes);
171 projectionWInt.resize(noNodes);
172 maia::dg::interpolation::calcLegendreGaussNodesAndWeights(polyDeg, &projectionNodes[0], &projectionWInt[0]);
173
174 // Calculate barycentric weights for projection nodes
175 MFloatVector projectionWBary;
176 projectionWBary.resize(noNodes);
177 maia::dg::interpolation::calcBarycentricWeights(polyDeg, &projectionNodes[0], &projectionWBary[0]);
178
179 // Calculate projection matrix from mortar element to coarse element in projection nodes
180 const MFloat shift = (position == dg::mortar::lower) ? -0.5 : 0.5;
181 MFloatTensor mortarToCoarseElement(noNodes, noNodes);
182 for(MInt i = 0; i < noNodes; i++) {
184 polyDeg,
185 &projectionNodes[0],
186 &projectionWBary[0],
187 &mortarToCoarseElement(i, 0));
188 }
189
190 // Transpose and multiply
191 for(MInt i = 0; i < noNodes; i++) {
192 for(MInt j = 0; j < i + 1; j++) {
193 const MFloat temp = mortarToCoarseElement(i, j);
194 mortarToCoarseElement(i, j) = 0.5 * mortarToCoarseElement(j, i) * projectionWInt[j] / projectionWInt[i];
195 mortarToCoarseElement(j, i) = 0.5 * temp * projectionWInt[i] / projectionWInt[j];
196 }
197 }
198
199
200 // Transformation matrix from grid to projection nodes (this is the identity when using Gauss
201 // nodes anyways)
202 MFloatTensor p2dg(noNodes, noNodes);
203 calcMortarProjectionMatrixP(polyDeg, &projectionNodes[0], &projectionWBary[0], polyDeg, nodes, &p2dg[0]);
204
205 // Transformation matrix from projection to grid nodes (this is the identity when using Gauss
206 // nodes anyways)
207 MFloatTensor dg2p(noNodes, noNodes);
208 calcMortarProjectionMatrixP(polyDeg, nodes, wBary, polyDeg, &projectionNodes[0], &dg2p[0]);
209
210 // The total projection matrix m is a product of the transformation matrices to(dg2p) and
211 // from(p2dg) quadrature nodes and the projection matrix in quadrature nodes, in this order: m =
212 // p2dg * mortarToCoarseElement * dg2p (where "*" denotes a matrix-matrix product)
213 MFloatTensor m(matrix, noNodes, noNodes);
214 m.set(0.0);
215 for(MInt q = 0; q < noNodes; q++) {
216 for(MInt j = 0; j < noNodes; j++) {
217 for(MInt i = 0; i < noNodes; i++) {
218 for(MInt n = 0; n < noNodes; n++) {
219 m(q, j) += p2dg(q, i) * mortarToCoarseElement(i, n) * dg2p(n, j);
220 }
221 }
222 }
223 }
224}
225
226} // namespace mortar
227} // namespace dg
228} // namespace maia
229
230#endif // define DGMORTAR_H_
void set(const T &value)
Initializes tensor to constant value.
Definition: tensor.h:271
size_type resize(size_type n0, size_type n1=1, size_type n2=1, size_type n3=1, size_type n4=1)
Deletes the old data structure and creates a new one with the requested dimensions.
Definition: tensor.h:230
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58
void calcLagrangeInterpolatingPolynomials(const MFloat x, const MInt polyDeg, const MFloat *nodes, const MFloat *wBary, MFloat *polynomials)
Calculates the values of the Lagrangian polynomials l_j for a given point x in [-1,...
void calcBarycentricWeights(MInt Nmax, const MFloat *nodes, MFloat *weights)
Calculates the barycentric weights for Lagrange interpolation at thei specified nodes.
void calcLegendreGaussNodesAndWeights(MInt Nmax, MFloat *nodes, MFloat *wInt)
Calculate the Gauss integration nodes and weight for the Legendre polynomials on the interval [-1,...
void calcMortarProjectionMatrixHReverse(const MInt polyDeg, const MFloat *const nodes, const MFloat *const wBary, const MInt position, MFloat *const matrix)
void calcMortarProjectionMatrixHForward(const MInt polyDeg, const MFloat *const nodes, const MFloat *const wBary, const MInt position, MFloat *const matrix)
void calcMortarProjectionMatrixP(const MInt sourcePolyDeg, const MFloat *const sourceNodes, const MFloat *const sourceBaryWeights, const MInt targetPolyDeg, const MFloat *const targetNodes, MFloat *const matrix)
Namespace for auxiliary functions/classes.