41 #include <boost/format.hpp>
54 "Write multiple files in parallel or when using nparts option");
65 string filename =
m_config[
"outfile"].as<
string>();
69 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary can't be obtained from pts.");
74 if (vm.count(
"error"))
80 else if (
m_f->m_exp.size())
84 m_f->m_exp[0]->GetNumElmts() != 0)
88 if (
m_f->m_writeBndFld)
90 if (
m_f->m_verbose &&
m_f->m_comm->TreatAsRankZero())
93 <<
": Writing boundary file(s): ";
94 for (
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
96 cout <<
m_f->m_bndRegionsToWrite[i];
97 if (i < m_f->m_bndRegionsToWrite.size() - 1)
105 int nfields =
m_f->m_variables.size();
106 int normdim =
m_f->m_graph->GetMeshDimension();
109 if (
m_f->m_addNormals)
112 m_f->m_exp.resize(nfields + normdim);
116 string normstr[3] = {
"Norm_x",
"Norm_y",
"Norm_z"};
117 for (
int j = 0; j < normdim; ++j)
119 m_f->m_exp[nfields + j] =
120 m_f->AppendExpList(
m_f->m_numHomogeneousDir);
121 m_f->m_variables.push_back(normstr[j]);
126 vector<MultiRegions::ExpListSharedPtr> exp(
m_f->m_exp.size());
127 exp.swap(
m_f->m_exp);
131 for (
int i = 0; i < exp.size(); ++i)
133 BndExp[i] = exp[i]->GetBndCondExpansions();
142 map<int, int> BndRegionMap;
143 map<int, LibUtilities::CommSharedPtr> BndRegionComm;
145 for (
auto &breg_it : bregions)
147 BndRegionMap[breg_it.first] = cnt++;
148 BndRegionComm[breg_it.first] =
153 int dot = filename.find_last_of(
'.') + 1;
154 string ext = filename.substr(dot, filename.length() - dot);
155 string name = filename.substr(0, dot - 1);
160 for (
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
164 boost::lexical_cast<string>(
m_f->m_bndRegionsToWrite[i]) +
173 if (BndRegionMap.count(
m_f->m_bndRegionsToWrite[i]) == 1)
175 m_f->m_comm = BndRegionComm[
m_f->m_bndRegionsToWrite[i]];
177 int Border = BndRegionMap[
m_f->m_bndRegionsToWrite[i]];
179 for (
int j = 0; j < exp.size(); ++j)
181 m_f->m_exp[j] = BndExp[j][Border];
182 m_f->m_exp[j]->BwdTrans(
m_f->m_exp[j]->GetCoeffs(),
183 m_f->m_exp[j]->UpdatePhys());
186 if (
m_f->m_addNormals)
190 exp[0]->GetBoundaryNormals(Border, NormPhys);
193 for (
int j = 0; j < normdim; ++j)
195 m_f->m_exp[nfields + j] =
196 BndExp[nfields + j][Border];
198 m_f->m_exp[nfields + j]->GetTotPoints(),
200 m_f->m_exp[nfields + j]->UpdatePhys(), 1);
201 m_f->m_exp[nfields + j]->FwdTrans_IterPerExp(
202 m_f->m_exp[nfields + j]->GetPhys(),
203 m_f->m_exp[nfields + j]->UpdateCoeffs());
208 if (vm.count(
"error"))
214 m_f->m_comm = tmpComm;
221 exp.swap(
m_f->m_exp);
229 if (vm.count(
"error"))
236 else if (
m_f->m_data.size())
238 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary extraction requires xml file.");
251 if (vm.count(
"nparts"))
257 outFile =
GetPath(filename, vm);
270 int count = fs::exists(outFile) ? 1 : 0;
274 if (count && (vm.count(
"forceoutput") == 0))
276 if (vm.count(
"nparts") == 0)
281 if (comm->TreatAsRankZero())
284 cout <<
"Did you wish to overwrite " << outFile <<
" (y/n)? ";
286 if (
answer.compare(
"y") == 0)
292 cout <<
"Not writing file " << filename
293 <<
" because it already exists" << endl;
299 return (writeFile == 0) ? false :
true;
305 int numFields =
m_f->m_exp.size();
306 m_f->m_fielddef =
m_f->m_exp[0]->GetFieldDefinitions();
310 if (vm.count(
"output-points"))
312 nPointsNew = vm[
"output-points"].as<
int>();
314 m_f->m_graph->SetExpansionInfoToEvenlySpacedPoints(nPointsNew);
317 vector<MultiRegions::ExpListSharedPtr> expOld =
m_f->m_exp;
319 m_f->m_exp[0] =
m_f->SetUpFirstExpList(
m_f->m_numHomogeneousDir,
true);
320 for (
int i = 1; i < numFields; ++i)
322 m_f->m_exp[i] =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
325 for (
int i = 0; i < numFields; ++i)
327 m_f->m_exp[i]->ExtractCoeffsToCoeffs(expOld[i], expOld[i]->GetCoeffs(),
328 m_f->m_exp[i]->UpdateCoeffs());
329 m_f->m_exp[i]->BwdTrans(
m_f->m_exp[i]->GetCoeffs(),
330 m_f->m_exp[i]->UpdatePhys());
333 if (
m_f->m_writeBndFld)
337 for (
int i = 0; i < numFields; ++i)
339 BndExpOld = expOld[i]->GetBndCondExpansions();
340 for (
int j = 0; j < BndExpOld.size(); ++j)
342 BndExp =
m_f->m_exp[i]->UpdateBndCondExpansion(j);
344 BndExp->ExtractCoeffsToCoeffs(BndExpOld[j],
345 BndExpOld[j]->GetCoeffs(),
346 BndExp->UpdateCoeffs());
350 m_f->m_fielddef = std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
355 int coordim =
m_f->m_fieldPts->GetDim();
356 std::string coordVars[] = {
"x",
"y",
"z"};
358 vector<string> variables =
m_f->m_variables;
359 variables.insert(variables.begin(), coordVars, coordVars + coordim);
365 m_f->m_fieldPts->GetPts(fields);
366 for (
int i = 0; i < fields.size(); ++i)
369 int npts = fields[i].size();
373 for (
int j = 0; j < npts; ++j)
375 l2err += fields[i][j] * fields[i][j];
376 linferr = max(linferr, fabs(fields[i][j]));
386 if (
m_f->m_comm->TreatAsRankZero())
388 cout <<
"L 2 error (variable " << variables[i] <<
") : " << l2err
391 cout <<
"L inf error (variable " << variables[i]
392 <<
") : " << linferr << endl;
400 m_f->m_exp[0]->GetExp(0)->GetCoordim() +
m_f->m_numHomogeneousDir;
401 int totpoints =
m_f->m_exp[0]->GetTotPoints();
402 std::string coordVars[] = {
"x",
"y",
"z"};
406 for (
int i = 0; i < coordim; ++i)
414 m_f->m_exp[0]->GetCoords(coords[0]);
416 else if (coordim == 2)
418 m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
422 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
425 for (
int j = 0; j < coordim; ++j)
430 if (
m_f->m_comm->TreatAsRankZero())
432 cout <<
"L 2 error (variable " << coordVars[j] <<
") : " << l2err
435 cout <<
"L inf error (variable " << coordVars[j]
436 <<
") : " << linferr << endl;
440 for (
int j = 0; j <
m_f->m_exp.size(); ++j)
445 if (
m_f->m_comm->TreatAsRankZero() &&
m_f->m_variables.size() > 0)
447 cout <<
"L 2 error (variable " <<
m_f->m_variables[j]
448 <<
") : " << l2err << endl;
450 cout <<
"L inf error (variable " <<
m_f->m_variables[j]
451 <<
") : " << linferr << endl;
#define ASSERTL0(condition, msg)
FIELD_UTILS_EXPORT void RegisterConfig(std::string key, std::string value="")
Register a configuration option with a module.
FieldSharedPtr m_f
Field object.
std::map< std::string, ConfigOption > m_config
List of configuration values.
virtual void OutputFromPts(po::variables_map &vm)=0
Write from pts to output file.
bool WriteFile(std::string &filename, po::variables_map &vm)
virtual fs::path GetFullOutName(std::string &filename, po::variables_map &vm)=0
virtual fs::path GetPath(std::string &filename, po::variables_map &vm)=0
virtual void OutputFromData(po::variables_map &vm)=0
Write from data to output file.
virtual void Process(po::variables_map &vm)
Write fld to output file.
virtual ~OutputFileBase()
void ConvertExpToEquispaced(po::variables_map &vm)
virtual std::string GetModuleName()
virtual void OutputFromExp(po::variables_map &vm)=0
Write from m_exp 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
The above copyright notice and this permission notice shall be included.
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.