38 std::vector<std::vector<MFloat>> data;
39 std::ifstream stream(path);
42 std::cerr <<
"File doesn't exist: " << path <<
"\n";
50 if(!getline(stream, s))
break;
52 std::istringstream ss(s);
53 std::vector<MFloat> record;
57 if(!getline(ss, line,
','))
break;
58 record.push_back(std::stof(line));
60 data.push_back(record);
65 std::cerr <<
"Could not read file " << path <<
"\n";
69 const MInt m = data.size();
70 const MInt n = data[0].size();
74 for(
MInt i = 0; i < m; i++) {
75 for(
MInt j = 0; j < n; j++) {
76 matrix(i, j) = data[i][j];
97 std::string bnFileName = path +
"bn.csv";
98 std::string inFileName = path +
"in.csv";
100 std::vector<std::vector<MFloat>> bnData;
101 std::ifstream bnFile(bnFileName);
107 if(!getline(bnFile, s))
break;
109 std::istringstream ss(s);
110 std::vector<MFloat> record;
114 if(!getline(ss, line,
','))
break;
115 record.push_back(std::stof(line));
117 bnData.push_back(record);
122 std::cerr <<
"Could not read file " << bnFileName <<
"\n";
123 std::__throw_invalid_argument(
"File not found.");
126 std::vector<std::vector<MFloat>> inData;
127 std::ifstream inFile(inFileName);
133 if(!getline(inFile, s))
break;
135 std::istringstream ss(s);
136 std::vector<MFloat> record;
140 if(!getline(ss, line,
','))
break;
141 record.push_back(std::stof(line));
143 inData.push_back(record);
148 std::cerr <<
"Could not read file " << inFileName <<
"\n";
149 std::__throw_invalid_argument(
"File not found.");
152 const MInt q = bnData.size();
153 const MInt r = bnData[0].size();
157 for(
MInt i = 0; i < q; i++) {
158 for(
MInt j = 0; j < r; j++) {
159 projBn(i, j) = bnData[i][j];
163 const MInt numInternal = inData.
size();
167 for(
MInt i = 0; i < numInternal; i++) {
168 projIn(i) = inData[i][0];
187 const MInt sourceNoNodes,
188 const MInt targetNoNodes,
191 std::string dir =
"./operatorsSBP/projection/p/";
192 std::string name = sourceOp.substr(sourceOp.find(
'/') + 1) + targetOp.substr(targetOp.find(
'/') + 1);
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";
197 auto fRead =
readCSV(pathF, f);
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;
227 const MFloat*
const sourceIntWeights,
228 MFloat*
const forwardLower,
229 MFloat*
const forwardUpper,
230 MFloat*
const backwardLower,
231 MFloat*
const backwardUpper) {
236 for(
MInt i = 0; i < noNodes; i++) {
237 targetIntWeights(i) = sourceIntWeights[i];
238 targetIntWeights(i + noNodes) = sourceIntWeights[i];
243 std::string path =
"./operatorsSBP/projection/s204/";
255 for(
MInt i = 0; i < s; i++) {
256 stenIn(s - 1 + i) = coeffsIn(i);
257 stenIn(s - 1 - i) = coeffsIn(i);
266 if(r > 2 * noNodes || 2 * q > noNodes || 2 * s - 1 > 2 * noNodes) {
271 for(
MInt i = 0; i < q; i++) {
272 for(
MInt j = 0; j < r; j++) {
273 b(i, j) = stenBn(i, j);
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);
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);
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;
309 for(
MInt i = 0; i < noNodes; i++) {
310 for(
MInt j = 0; j < noNodes; j++) {
312 fu(i, j) = f(i + noNodes, j);
314 bu(i, j) =
b(i, j + noNodes);
332 MFloat*
const forwardUpper,
MFloat*
const backwardLower,
333 MFloat*
const backwardUpper) {
334 std::string path =
"./operatorsSBP/projection/h/";
336 std::string pathF = path + sbpOperator +
"/" + std::to_string(noNodes) +
"_f.csv";
337 std::string pathB = path + sbpOperator +
"/" + std::to_string(noNodes) +
"_b.csv";
342 auto fRead =
readCSV(pathF, &f[0]);
345 if(!fRead || !bRead) {
346 std::cerr <<
"H projection matrix for " << noNodes <<
" nodes NOT CALCULATED" << std::endl;
357 for(
MInt i = 0; i < noNodes; i++) {
358 for(
MInt j = 0; j < noNodes; j++) {
360 fu(i, j) = f(i + noNodes, j);
362 bu(i, j) =
b(i, j + noNodes);
size_type dim0() const
Return the size of dimension 0.
size_type dim1() const
Return the size of dimension 1.
void set(const T &value)
Initializes tensor to constant value.
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...
std::basic_string< char > MString
MBool readCSV(std::string path, MFloat *mat)
Reads csv from path to MFloatMatrix.
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.
void readProjectionCoeffs(std::string path, MFloatMatrix &projBn, MFloatVector &projIn)
Reads coeffficients from csv files for Carpenter operators.
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.
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.
Namespace for auxiliary functions/classes.
maia::tensor::Tensor< MFloat > MFloatMatrix
maia::tensor::Tensor< MFloat > MFloatVector