65 string filename =
m_config[
"outfile"].as<
string>();
74 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary can't be obtained from pts.");
79 if (vm.count(
"error"))
85 else if (
m_f->m_exp.size())
93 if (
m_f->m_writeBndFld)
96 m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
99 <<
": Writing boundary file(s): ";
100 for (
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
102 cout <<
m_f->m_bndRegionsToWrite[i];
103 if (i < m_f->m_bndRegionsToWrite.size() - 1)
111 int nfields =
m_f->m_variables.size();
112 int normdim =
m_f->m_graph->GetMeshDimension();
115 if (
m_f->m_addNormals)
118 m_f->m_exp.resize(nfields + normdim);
121 string normstr[3] = {
"Norm_x",
"Norm_y",
"Norm_z"};
122 for (
int j = 0; j < normdim; ++j)
124 m_f->m_exp[nfields + j] =
125 m_f->AppendExpList(
m_f->m_numHomogeneousDir);
126 m_f->m_variables.push_back(normstr[j]);
131 vector<MultiRegions::ExpListSharedPtr> exp(
m_f->m_exp.size());
132 exp.swap(
m_f->m_exp);
136 for (
int i = 0; i < exp.size(); ++i)
138 BndExp[i] = exp[i]->GetBndCondExpansions();
147 map<int, int> BndRegionMap;
148 map<int, LibUtilities::CommSharedPtr> BndRegionComm;
152 std::set<int> ProcessBnd;
153 if (
m_f->m_session->DefinesTag(
"CreateBndRegions"))
156 vector<unsigned int> bndRegions;
159 m_f->m_session->GetTag(
"CreateBndRegions"), bndRegions),
160 "Failed to interpret bnd values string");
162 for (
auto &bnd : bndRegions)
164 if (bregions.count(bnd) == 1)
166 ProcessBnd.insert(bnd);
172 for (
auto &it : bregions)
174 ProcessBnd.insert(it.first);
179 for (
auto &breg_it : bregions)
181 if (ProcessBnd.count(breg_it.first))
183 BndRegionMap[breg_it.first] = cnt++;
184 BndRegionComm[breg_it.first] =
190 int dot = filename.find_last_of(
'.') + 1;
191 string ext = filename.substr(dot, filename.length() - dot);
192 string name = filename.substr(0, dot - 1);
197 for (
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
199 string outname = name +
"_b" +
200 std::to_string(
m_f->m_bndRegionsToWrite[i]) +
209 if (BndRegionMap.count(
m_f->m_bndRegionsToWrite[i]) == 1)
211 m_f->m_comm = BndRegionComm[
m_f->m_bndRegionsToWrite[i]];
213 int Border = BndRegionMap[
m_f->m_bndRegionsToWrite[i]];
216 for (
int j = 0; j < exp.size(); ++j)
218 m_f->m_exp[j] = BndExp[j][Border];
221 for (
int j = 0; j < exp.size(); ++j)
223 m_f->m_exp[j] = BndExp[j][Border];
224 m_f->m_exp[j]->BwdTrans(
m_f->m_exp[j]->GetCoeffs(),
225 m_f->m_exp[j]->UpdatePhys());
228 if (
m_f->m_addNormals)
232 exp[0]->GetBoundaryNormals(Border, NormPhys);
235 for (
int j = 0; j < normdim; ++j)
237 m_f->m_exp[nfields + j] =
238 BndExp[nfields + j][Border];
240 m_f->m_exp[nfields + j]->GetTotPoints(),
242 m_f->m_exp[nfields + j]->UpdatePhys(), 1);
243 m_f->m_exp[nfields + j]->FwdTransLocalElmt(
244 m_f->m_exp[nfields + j]->GetPhys(),
245 m_f->m_exp[nfields + j]->UpdateCoeffs());
250 if (vm.count(
"error"))
256 m_f->m_comm = tmpComm;
263 exp.swap(
m_f->m_exp);
271 if (vm.count(
"error"))
278 else if (
m_f->m_data.size())
280 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary extraction requires xml file.");
298 if (vm.count(
"nparts"))
304 outFile =
GetPath(filename, vm);
317 int count = fs::exists(outFile) ? 1 : 0;
321 if (count && (vm.count(
"force-output") == 0))
323 if (vm.count(
"nparts") == 0)
327 if (comm->GetSpaceComm()->TreatAsRankZero())
330 cout <<
"Did you wish to overwrite " << outFile <<
" (y/n)? ";
331 getline(cin, answer);
332 if (answer.compare(
"y") == 0)
338 cout <<
"Not writing file '" << filename
339 <<
"' because it already exists" << endl;
345 return (writeFile == 0) ? false :
true;
351 int numFields =
m_f->m_exp.size();
352 m_f->m_fielddef =
m_f->m_exp[0]->GetFieldDefinitions();
356 if (vm.count(
"output-points"))
358 nPointsNew = vm[
"output-points"].as<
int>();
360 m_f->m_graph->SetExpansionInfoToEvenlySpacedPoints(nPointsNew);
363 vector<MultiRegions::ExpListSharedPtr> expOld =
m_f->m_exp;
366 m_f->m_exp[0] =
m_f->SetUpFirstExpList(
m_f->m_numHomogeneousDir,
true);
367 for (
int i = 1; i < numFields; ++i)
369 m_f->m_exp[i] =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
373 for (
int i = 0; i < numFields; ++i)
375 m_f->m_exp[i]->ExtractCoeffsToCoeffs(expOld[i], expOld[i]->GetCoeffs(),
376 m_f->m_exp[i]->UpdateCoeffs());
377 m_f->m_exp[i]->BwdTrans(
m_f->m_exp[i]->GetCoeffs(),
378 m_f->m_exp[i]->UpdatePhys());
382 if (
m_f->m_writeBndFld)
387 for (
int i = 0; i < numFields; ++i)
389 BndExpOld = expOld[i]->GetBndCondExpansions();
390 for (
int j = 0; j < BndExpOld.size(); ++j)
392 BndExp =
m_f->m_exp[i]->UpdateBndCondExpansion(j);
393 BndExp->ExtractCoeffsToCoeffs(BndExpOld[j],
394 BndExpOld[j]->GetCoeffs(),
395 BndExp->UpdateCoeffs());
400 m_f->m_fielddef = std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
408 int coordim =
m_f->m_fieldPts->GetDim();
409 std::string coordVars[] = {
"x",
"y",
"z"};
411 vector<string> variables =
m_f->m_variables;
412 variables.insert(variables.begin(), coordVars, coordVars + coordim);
418 m_f->m_fieldPts->GetPts(fields);
419 for (
int i = 0; i < fields.size(); ++i)
422 int npts = fields[i].size();
426 for (
int j = 0; j < npts; ++j)
428 l2err += fields[i][j] * fields[i][j];
429 linferr =
max(linferr, fabs(fields[i][j]));
434 m_f->m_comm->GetSpaceComm()->AllReduce(linferr,
440 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
442 cout <<
"L 2 error (variable " << variables[i] <<
") : " << l2err
445 cout <<
"L inf error (variable " << variables[i]
446 <<
") : " << linferr << endl;
454 m_f->m_exp[0]->GetExp(0)->GetCoordim() +
m_f->m_numHomogeneousDir;
455 int totpoints =
m_f->m_exp[0]->GetTotPoints();
456 std::string coordVars[] = {
"x",
"y",
"z"};
460 for (
int i = 0; i < coordim; ++i)
468 m_f->m_exp[0]->GetCoords(coords[0]);
470 else if (coordim == 2)
472 m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
476 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
479 for (
int j = 0; j < coordim; ++j)
484 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
486 cout <<
"L 2 error (variable " << coordVars[j] <<
") : " << l2err
489 cout <<
"L inf error (variable " << coordVars[j]
490 <<
") : " << linferr << endl;
494 for (
int j = 0; j <
m_f->m_exp.size(); ++j)
499 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero() &&
500 m_f->m_variables.size() > 0)
502 cout <<
"L 2 error (variable " <<
m_f->m_variables[j]
503 <<
") : " << l2err << endl;
505 cout <<
"L inf error (variable " <<
m_f->m_variables[j]
506 <<
") : " << linferr << endl;
std::map< int, LibUtilities::CommSharedPtr > GetBoundaryCommunicators() const
const BoundaryRegionCollection & GetBoundaryRegions(void) const
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection