41#include <boost/format.hpp>
53 "Write multiple files in parallel or when using nparts option");
64 string filename =
m_config[
"outfile"].as<
string>();
73 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary can't be obtained from pts.");
78 if (vm.count(
"error"))
84 else if (
m_f->m_exp.size())
92 if (
m_f->m_writeBndFld)
95 m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
98 <<
": Writing boundary file(s): ";
99 for (
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
101 cout <<
m_f->m_bndRegionsToWrite[i];
102 if (i < m_f->m_bndRegionsToWrite.size() - 1)
110 int nfields =
m_f->m_variables.size();
111 int normdim =
m_f->m_graph->GetMeshDimension();
114 if (
m_f->m_addNormals)
117 m_f->m_exp.resize(nfields + normdim);
120 string normstr[3] = {
"Norm_x",
"Norm_y",
"Norm_z"};
121 for (
int j = 0; j < normdim; ++j)
123 m_f->m_exp[nfields + j] =
124 m_f->AppendExpList(
m_f->m_numHomogeneousDir);
125 m_f->m_variables.push_back(normstr[j]);
130 vector<MultiRegions::ExpListSharedPtr> exp(
m_f->m_exp.size());
131 exp.swap(
m_f->m_exp);
135 for (
int i = 0; i < exp.size(); ++i)
137 BndExp[i] = exp[i]->GetBndCondExpansions();
146 map<int, int> BndRegionMap;
147 map<int, LibUtilities::CommSharedPtr> BndRegionComm;
149 for (
auto &breg_it : bregions)
151 BndRegionMap[breg_it.first] = cnt++;
152 BndRegionComm[breg_it.first] =
157 int dot = filename.find_last_of(
'.') + 1;
158 string ext = filename.substr(dot, filename.length() - dot);
159 string name = filename.substr(0, dot - 1);
164 for (
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
166 string outname =
name +
"_b" +
167 std::to_string(
m_f->m_bndRegionsToWrite[i]) +
176 if (BndRegionMap.count(
m_f->m_bndRegionsToWrite[i]) == 1)
178 m_f->m_comm = BndRegionComm[
m_f->m_bndRegionsToWrite[i]];
180 int Border = BndRegionMap[
m_f->m_bndRegionsToWrite[i]];
183 for (
int j = 0; j < exp.size(); ++j)
185 m_f->m_exp[j] = BndExp[j][Border];
188 for (
int j = 0; j < exp.size(); ++j)
190 m_f->m_exp[j] = BndExp[j][Border];
191 m_f->m_exp[j]->BwdTrans(
m_f->m_exp[j]->GetCoeffs(),
192 m_f->m_exp[j]->UpdatePhys());
195 if (
m_f->m_addNormals)
199 exp[0]->GetBoundaryNormals(Border, NormPhys);
202 for (
int j = 0; j < normdim; ++j)
204 m_f->m_exp[nfields + j] =
205 BndExp[nfields + j][Border];
207 m_f->m_exp[nfields + j]->GetTotPoints(),
209 m_f->m_exp[nfields + j]->UpdatePhys(), 1);
210 m_f->m_exp[nfields + j]->FwdTransLocalElmt(
211 m_f->m_exp[nfields + j]->GetPhys(),
212 m_f->m_exp[nfields + j]->UpdateCoeffs());
217 if (vm.count(
"error"))
223 m_f->m_comm = tmpComm;
230 exp.swap(
m_f->m_exp);
238 if (vm.count(
"error"))
245 else if (
m_f->m_data.size())
247 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary extraction requires xml file.");
265 if (vm.count(
"nparts"))
271 outFile =
GetPath(filename, vm);
284 int count = fs::exists(outFile) ? 1 : 0;
288 if (count && (vm.count(
"force-output") == 0))
290 if (vm.count(
"nparts") == 0)
294 if (comm->GetSpaceComm()->TreatAsRankZero())
297 cout <<
"Did you wish to overwrite " << outFile <<
" (y/n)? ";
299 if (
answer.compare(
"y") == 0)
305 cout <<
"Not writing file '" << filename
306 <<
"' because it already exists" << endl;
312 return (writeFile == 0) ? false :
true;
318 int numFields =
m_f->m_exp.size();
319 m_f->m_fielddef =
m_f->m_exp[0]->GetFieldDefinitions();
323 if (vm.count(
"output-points"))
325 nPointsNew = vm[
"output-points"].as<
int>();
327 m_f->m_graph->SetExpansionInfoToEvenlySpacedPoints(nPointsNew);
330 vector<MultiRegions::ExpListSharedPtr> expOld =
m_f->m_exp;
333 m_f->m_exp[0] =
m_f->SetUpFirstExpList(
m_f->m_numHomogeneousDir,
true);
334 for (
int i = 1; i < numFields; ++i)
336 m_f->m_exp[i] =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
340 for (
int i = 0; i < numFields; ++i)
342 m_f->m_exp[i]->ExtractCoeffsToCoeffs(expOld[i], expOld[i]->GetCoeffs(),
343 m_f->m_exp[i]->UpdateCoeffs());
344 m_f->m_exp[i]->BwdTrans(
m_f->m_exp[i]->GetCoeffs(),
345 m_f->m_exp[i]->UpdatePhys());
349 if (
m_f->m_writeBndFld)
354 for (
int i = 0; i < numFields; ++i)
356 BndExpOld = expOld[i]->GetBndCondExpansions();
357 for (
int j = 0; j < BndExpOld.size(); ++j)
359 BndExp =
m_f->m_exp[i]->UpdateBndCondExpansion(j);
360 BndExp->ExtractCoeffsToCoeffs(BndExpOld[j],
361 BndExpOld[j]->GetCoeffs(),
362 BndExp->UpdateCoeffs());
367 m_f->m_fielddef = std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
375 int coordim =
m_f->m_fieldPts->GetDim();
376 std::string coordVars[] = {
"x",
"y",
"z"};
378 vector<string> variables =
m_f->m_variables;
379 variables.insert(variables.begin(), coordVars, coordVars + coordim);
385 m_f->m_fieldPts->GetPts(fields);
386 for (
int i = 0; i < fields.size(); ++i)
389 int npts = fields[i].size();
393 for (
int j = 0; j < npts; ++j)
395 l2err += fields[i][j] * fields[i][j];
396 linferr = max(linferr, fabs(fields[i][j]));
401 m_f->m_comm->GetSpaceComm()->AllReduce(linferr,
407 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
409 cout <<
"L 2 error (variable " << variables[i] <<
") : " << l2err
412 cout <<
"L inf error (variable " << variables[i]
413 <<
") : " << linferr << endl;
421 m_f->m_exp[0]->GetExp(0)->GetCoordim() +
m_f->m_numHomogeneousDir;
422 int totpoints =
m_f->m_exp[0]->GetTotPoints();
423 std::string coordVars[] = {
"x",
"y",
"z"};
427 for (
int i = 0; i < coordim; ++i)
435 m_f->m_exp[0]->GetCoords(coords[0]);
437 else if (coordim == 2)
439 m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
443 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
446 for (
int j = 0; j < coordim; ++j)
451 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
453 cout <<
"L 2 error (variable " << coordVars[j] <<
") : " << l2err
456 cout <<
"L inf error (variable " << coordVars[j]
457 <<
") : " << linferr << endl;
461 for (
int j = 0; j <
m_f->m_exp.size(); ++j)
466 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero() &&
467 m_f->m_variables.size() > 0)
469 cout <<
"L 2 error (variable " <<
m_f->m_variables[j]
470 <<
") : " << l2err << endl;
472 cout <<
"L inf error (variable " <<
m_f->m_variables[j]
473 <<
") : " << linferr << endl;
#define ASSERTL0(condition, msg)
FIELD_UTILS_EXPORT void RegisterConfig(std::string key, std::string value="")
Register a configuration option with a module.
std::string GetModuleName()
FieldSharedPtr m_f
Field object.
std::map< std::string, ConfigOption > m_config
List of configuration values.
virtual void v_OutputFromExp(po::variables_map &vm)=0
Write from m_exp to output file.
bool WriteFile(std::string &filename, po::variables_map &vm)
~OutputFileBase() override
fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
void ConvertExpToEquispaced(po::variables_map &vm)
virtual void v_OutputFromData(po::variables_map &vm)=0
Write from data to output file.
virtual void v_OutputFromPts(po::variables_map &vm)=0
Write from pts to output file.
OutputFileBase(FieldSharedPtr f)
fs::path GetPath(std::string &filename, po::variables_map &vm)
void v_Process(po::variables_map &vm) override
Write fld to output file.
Abstract base class for output modules.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
std::map< int, LibUtilities::CommSharedPtr > GetBoundaryCommunicators() const
const BoundaryRegionCollection & GetBoundaryRegions(void) const
std::shared_ptr< Field > FieldSharedPtr
static PtsFieldSharedPtr NullPtsField
CommFactory & GetCommFactory()
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
scalarT< T > sqrt(scalarT< T > in)
Represents a command-line configuration option.