MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
maia::sbp::mortar Namespace Reference

Functions

MBool readCSV (std::string path, MFloat *mat)
 Reads csv from path to MFloatMatrix. More...
 
void readProjectionCoeffs (std::string path, MFloatMatrix &projBn, MFloatVector &projIn)
 Reads coeffficients from csv files for Carpenter operators. More...
 
void calcMortarProjectionMatrixPSBP (const MString sourceOp, const MString targetOp, const MInt sourceNoNodes, const MInt targetNoNodes, MFloat *const f, MFloat *const b)
 Reads projection coefficients and stores them. More...
 
void calcMortarProjectionMatrixHSBPCarpenter (const MInt noNodes, const MFloat *const sourceIntWeights, MFloat *const forwardLower, MFloat *const forwardUpper, MFloat *const backwardLower, MFloat *const backwardUpper)
 Constructs h-refinement projection operator according to Carpenter. More...
 
void calcMortarProjectionMatrixHSBP (const MInt noNodes, const MString sbpOperator, MFloat *const forwardLower, MFloat *const forwardUpper, MFloat *const backwardLower, MFloat *const backwardUpper)
 Reads and constructs h-refinement projection operator. More...
 

Variables

const MBool forward = true
 
const MBool reverse = false
 
const MInt lower = 0
 
const MInt upper = 1
 

Function Documentation

◆ calcMortarProjectionMatrixHSBP()

void maia::sbp::mortar::calcMortarProjectionMatrixHSBP ( const MInt  noNodes,
const MString  sbpOperator,
MFloat *const  forwardLower,
MFloat *const  forwardUpper,
MFloat *const  backwardLower,
MFloat *const  backwardUpper 
)
inline
Author
Julian Vorspohl j.vor.nosp@m.spoh.nosp@m.l@aia.nosp@m..rwt.nosp@m.h-aac.nosp@m.hen..nosp@m.de
Date
2019-05-11
Parameters
[in]noNodesNumber of nodes 1D
[in]sbpOperatorUsed SBP operator
[out]forwardLowerProjection operator
[out]forwardUpperProjection operator
[out]backwardLowerProjection operator
[out]backwardUpperProjection operator

Definition at line 331 of file sbpcartesianmortar.h.

333 {
334 std::string path = "./operatorsSBP/projection/h/";
335
336 std::string pathF = path + sbpOperator + "/" + std::to_string(noNodes) + "_f.csv";
337 std::string pathB = path + sbpOperator + "/" + std::to_string(noNodes) + "_b.csv";
338
339 MFloatMatrix f(2 * noNodes, noNodes);
340 MFloatMatrix b(noNodes, 2 * noNodes);
341
342 auto fRead = readCSV(pathF, &f[0]);
343 auto bRead = readCSV(pathB, &b[0]);
344
345 if(!fRead || !bRead) {
346 std::cerr << "H projection matrix for " << noNodes << " nodes NOT CALCULATED" << std::endl;
347 f.set(0);
348 b.set(0);
349 }
350
351 // Split operators into upper and lower part
352 MFloatMatrix fl(forwardLower, noNodes, noNodes);
353 MFloatMatrix fu(forwardUpper, noNodes, noNodes);
354 MFloatMatrix bl(backwardLower, noNodes, noNodes);
355 MFloatMatrix bu(backwardUpper, noNodes, noNodes);
356
357 for(MInt i = 0; i < noNodes; i++) {
358 for(MInt j = 0; j < noNodes; j++) {
359 fl(i, j) = f(i, j);
360 fu(i, j) = f(i + noNodes, j);
361 bl(i, j) = b(i, j);
362 bu(i, j) = b(i, j + noNodes);
363 }
364 }
365}
int32_t MInt
Definition: maiatypes.h:62

◆ calcMortarProjectionMatrixHSBPCarpenter()

void maia::sbp::mortar::calcMortarProjectionMatrixHSBPCarpenter ( const MInt  noNodes,
const MFloat *const  sourceIntWeights,
MFloat *const  forwardLower,
MFloat *const  forwardUpper,
MFloat *const  backwardLower,
MFloat *const  backwardUpper 
)
inline
Author
Julian Vorspohl j.vor.nosp@m.spoh.nosp@m.l@aia.nosp@m..rwt.nosp@m.h-aac.nosp@m.hen..nosp@m.de
Date
2019-05-11
Parameters
[in]noNodesNumber of nodes 1D
[in]sourceIntWeightsIntegration weights of used SBP operator
[out]forwardLowerProjection operator
[out]forwardUpperProjection operator
[out]backwardLowerProjection operator
[out]backwardUpperProjection operator

Definition at line 226 of file sbpcartesianmortar.h.

231 {
232 // Create targetIntWeight by stacking up sourceIntWeight
233 // Since wInt is unscaled we don't need to apply any factor here
234 MFloatVector targetIntWeights(2 * noNodes);
235
236 for(MInt i = 0; i < noNodes; i++) {
237 targetIntWeights(i) = sourceIntWeights[i];
238 targetIntWeights(i + noNodes) = sourceIntWeights[i];
239 }
240
241 MFloatMatrix stenBn;
242 MFloatVector coeffsIn;
243 std::string path = "./operatorsSBP/projection/s204/";
244 readProjectionCoeffs(path, stenBn, coeffsIn);
245
246 // TODO labels:DG s = #coeffs, carpenter s + 1 = #coeffs
247 const MInt s = coeffsIn.dim0();
248 const MInt q = stenBn.dim0();
249 const MInt r = stenBn.dim1();
250
251 // Create inner stencil
252 // Coeffs: 1 2 3
253 // Stencil 3 2 1 2 3
254 MFloatVector stenIn(2 * s - 1);
255 for(MInt i = 0; i < s; i++) {
256 stenIn(s - 1 + i) = coeffsIn(i);
257 stenIn(s - 1 - i) = coeffsIn(i);
258 }
259
260 MFloatMatrix f(2 * noNodes, noNodes);
261 MFloatMatrix b(noNodes, 2 * noNodes);
262
263 b.set(0.0);
264 f.set(0.0);
265
266 if(r > 2 * noNodes || 2 * q > noNodes || 2 * s - 1 > 2 * noNodes) {
267 return;
268 }
269
270 // Set upper boundary solver
271 for(MInt i = 0; i < q; i++) {
272 for(MInt j = 0; j < r; j++) {
273 b(i, j) = stenBn(i, j);
274 }
275 }
276
277 // Set inner stencil
278 MInt k = 2 * q - s + 1;
279 for(MInt i = q; i < noNodes / 2; i++) {
280 for(MInt j = 0; j < 2 * s - 1; j++) {
281 b(i, j + k) = stenIn(j);
282 }
283 k += 2;
284 }
285
286 // Mirror
287 for(MInt i = 0; i < noNodes; i++) {
288 for(MInt j = 0; j < 2 * noNodes; j++) {
289 b(noNodes - i - 1, 2 * noNodes - j - 1) = b(i, j);
290 }
291 }
292
293 // Create foward operator by applying the H-Compatibility condition eq.
294 // Apply dx scale factor since wInt is unscaled.
295 // For the 1:2 href case it's always 2
296 // TODO labels:DG scale beforehand
297 for(MInt i = 0; i < noNodes; i++) {
298 for(MInt j = 0; j < 2 * noNodes; j++) {
299 f(j, i) = b(i, j) * sourceIntWeights[i] / targetIntWeights(j) * 2;
300 }
301 }
302
303 // Split operators into upper and lower part
304 MFloatMatrix fl(forwardLower, noNodes, noNodes);
305 MFloatMatrix fu(forwardUpper, noNodes, noNodes);
306 MFloatMatrix bl(backwardLower, noNodes, noNodes);
307 MFloatMatrix bu(backwardUpper, noNodes, noNodes);
308
309 for(MInt i = 0; i < noNodes; i++) {
310 for(MInt j = 0; j < noNodes; j++) {
311 fl(i, j) = f(i, j);
312 fu(i, j) = f(i + noNodes, j);
313 bl(i, j) = b(i, j);
314 bu(i, j) = b(i, j + noNodes);
315 }
316 }
317}
size_type dim0() const
Return the size of dimension 0.
Definition: tensor.h:366
size_type dim1() const
Return the size of dimension 1.
Definition: tensor.h:380

◆ calcMortarProjectionMatrixPSBP()

void maia::sbp::mortar::calcMortarProjectionMatrixPSBP ( const MString  sourceOp,
const MString  targetOp,
const MInt  sourceNoNodes,
const MInt  targetNoNodes,
MFloat *const  f,
MFloat *const  b 
)
inline
Author
Julian Vorspohl j.vor.nosp@m.spoh.nosp@m.l@aia.nosp@m..rwt.nosp@m.h-aac.nosp@m.hen..nosp@m.de
Date
2019-05-11
Parameters
[in]sourceOpSBP operator of source side
[in]targetOpSBP operator of target side
[in]sourceNoNodesNumber of nodes on source side
[in]targetNoNodesNumber of nodes on target side
[out]fforward projection operator
[out]bbackward projection operator

Definition at line 185 of file sbpcartesianmortar.h.

190 {
191 std::string dir = "./operatorsSBP/projection/p/";
192 std::string name = sourceOp.substr(sourceOp.find('/') + 1) + targetOp.substr(targetOp.find('/') + 1);
193
194 std::string pathF = dir + name + "/" + std::to_string(sourceNoNodes) + "_" + std::to_string(targetNoNodes) + "_f.csv";
195 std::string pathB = dir + name + "/" + std::to_string(sourceNoNodes) + "_" + std::to_string(targetNoNodes) + "_b.csv";
196
197 auto fRead = readCSV(pathF, f);
198 auto bRead = readCSV(pathB, b);
199
200 if(!fRead || !bRead) {
201 std::cerr << "P projection matrix for " << sourceOp << " with " << sourceNoNodes << " nodes to " << targetOp
202 << " with " << targetNoNodes << " nodes NOT CALCULATED" << std::endl;
203 MFloatMatrix fMatrix(f, targetNoNodes, sourceNoNodes);
204 MFloatMatrix bMatrix(b, sourceNoNodes, targetNoNodes);
205 fMatrix.set(0);
206 bMatrix.set(0);
207 } else {
208 MFloatMatrix fMatrix(f, targetNoNodes, sourceNoNodes);
209 MFloatMatrix bMatrix(b, sourceNoNodes, targetNoNodes);
210 }
211}

◆ readCSV()

MBool maia::sbp::mortar::readCSV ( std::string  path,
MFloat mat 
)
inline
Author
Julian Vorspohl j.vor.nosp@m.spoh.nosp@m.l@aia.nosp@m..rwt.nosp@m.h-aac.nosp@m.hen..nosp@m.de
Date
2019-05-11
Parameters
[in]pathPath to csv
[out]matMatrix of read coefficients
Returns
true if read successfully

Definition at line 37 of file sbpcartesianmortar.h.

37 {
38 std::vector<std::vector<MFloat>> data;
39 std::ifstream stream(path);
40
41 if(stream.fail()) {
42 std::cerr << "File doesn't exist: " << path << "\n";
43 return false;
44 }
45
46 MInt l = 0;
47 while(stream) {
48 l++;
49 std::string s;
50 if(!getline(stream, s)) break;
51 if(s[0] != '#') {
52 std::istringstream ss(s);
53 std::vector<MFloat> record;
54
55 while(ss) {
56 std::string line;
57 if(!getline(ss, line, ',')) break;
58 record.push_back(std::stof(line));
59 }
60 data.push_back(record);
61 }
62 }
63
64 if(!stream.eof()) {
65 std::cerr << "Could not read file " << path << "\n";
66 return false;
67 }
68
69 const MInt m = data.size();
70 const MInt n = data[0].size();
71
72 MFloatMatrix matrix(mat, m, n);
73
74 for(MInt i = 0; i < m; i++) {
75 for(MInt j = 0; j < n; j++) {
76 matrix(i, j) = data[i][j];
77 }
78 }
79
80 return true;
81}

◆ readProjectionCoeffs()

void maia::sbp::mortar::readProjectionCoeffs ( std::string  path,
MFloatMatrix projBn,
MFloatVector projIn 
)
inline
Author
Julian Vorspohl j.vor.nosp@m.spoh.nosp@m.l@aia.nosp@m..rwt.nosp@m.h-aac.nosp@m.hen..nosp@m.de
Date
2019-05-11
Parameters
[in]pathPath to coefficients
[out]projBnMatrix of boundary coefficients
[out]projInVector of inner stencil

Definition at line 93 of file sbpcartesianmortar.h.

93 {
94 projIn = MFloatVector(2);
95 projIn.set(0.2);
96
97 std::string bnFileName = path + "bn.csv";
98 std::string inFileName = path + "in.csv";
99
100 std::vector<std::vector<MFloat>> bnData;
101 std::ifstream bnFile(bnFileName);
102 MInt l = 0;
103
104 while(bnFile) {
105 l++;
106 std::string s;
107 if(!getline(bnFile, s)) break;
108 if(s[0] != '#') {
109 std::istringstream ss(s);
110 std::vector<MFloat> record;
111
112 while(ss) {
113 std::string line;
114 if(!getline(ss, line, ',')) break;
115 record.push_back(std::stof(line));
116 }
117 bnData.push_back(record);
118 }
119 }
120
121 if(!bnFile.eof()) {
122 std::cerr << "Could not read file " << bnFileName << "\n";
123 std::__throw_invalid_argument("File not found.");
124 }
125
126 std::vector<std::vector<MFloat>> inData;
127 std::ifstream inFile(inFileName);
128 l = 0;
129
130 while(inFile) {
131 l++;
132 std::string s;
133 if(!getline(inFile, s)) break;
134 if(s[0] != '#') {
135 std::istringstream ss(s);
136 std::vector<MFloat> record;
137
138 while(ss) {
139 std::string line;
140 if(!getline(ss, line, ',')) break;
141 record.push_back(std::stof(line));
142 }
143 inData.push_back(record);
144 }
145 }
146
147 if(!inFile.eof()) {
148 std::cerr << "Could not read file " << inFileName << "\n";
149 std::__throw_invalid_argument("File not found.");
150 }
151
152 const MInt q = bnData.size();
153 const MInt r = bnData[0].size();
154
155 projBn = MFloatMatrix(q, r);
156
157 for(MInt i = 0; i < q; i++) {
158 for(MInt j = 0; j < r; j++) {
159 projBn(i, j) = bnData[i][j];
160 }
161 }
162
163 const MInt numInternal = inData.size();
164
165 projIn = MFloatVector(numInternal);
166
167 for(MInt i = 0; i < numInternal; i++) {
168 projIn(i) = inData[i][0];
169 }
170}
void set(const T &value)
Initializes tensor to constant value.
Definition: tensor.h:271
size_type size() const
Returns the size of the array as product of all five dimensions (i.e. not the actual array size but t...
Definition: tensor.h:206
std::istream & getline(std::istream &input, std::string &line)
Definition: cpptoml.h:1519
maia::tensor::Tensor< MFloat > MFloatMatrix
Definition: tensor.h:1098
maia::tensor::Tensor< MFloat > MFloatVector
Definition: tensor.h:1095

Variable Documentation

◆ forward

const MBool maia::sbp::mortar::forward = true

Definition at line 21 of file sbpcartesianmortar.h.

◆ lower

const MInt maia::sbp::mortar::lower = 0

Definition at line 23 of file sbpcartesianmortar.h.

◆ reverse

const MBool maia::sbp::mortar::reverse = false

Definition at line 22 of file sbpcartesianmortar.h.

◆ upper

const MInt maia::sbp::mortar::upper = 1

Definition at line 24 of file sbpcartesianmortar.h.