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)
91 m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
94 <<
": Writing boundary file(s): ";
95 for (
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
97 cout <<
m_f->m_bndRegionsToWrite[i];
98 if (i < m_f->m_bndRegionsToWrite.size() - 1)
106 int nfields =
m_f->m_variables.size();
107 int normdim =
m_f->m_graph->GetMeshDimension();
110 if (
m_f->m_addNormals)
113 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]];
180 for (
int j = 0; j < exp.size(); ++j)
182 m_f->m_exp[j] = BndExp[j][Border];
185 for (
int j = 0; j < exp.size(); ++j)
187 m_f->m_exp[j] = BndExp[j][Border];
188 m_f->m_exp[j]->BwdTrans(
m_f->m_exp[j]->GetCoeffs(),
189 m_f->m_exp[j]->UpdatePhys());
192 if (
m_f->m_addNormals)
196 exp[0]->GetBoundaryNormals(Border, NormPhys);
199 for (
int j = 0; j < normdim; ++j)
201 m_f->m_exp[nfields + j] =
202 BndExp[nfields + j][Border];
204 m_f->m_exp[nfields + j]->GetTotPoints(),
206 m_f->m_exp[nfields + j]->UpdatePhys(), 1);
207 m_f->m_exp[nfields + j]->FwdTransLocalElmt(
208 m_f->m_exp[nfields + j]->GetPhys(),
209 m_f->m_exp[nfields + j]->UpdateCoeffs());
214 if (vm.count(
"error"))
220 m_f->m_comm = tmpComm;
227 exp.swap(
m_f->m_exp);
235 if (vm.count(
"error"))
242 else if (
m_f->m_data.size())
244 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary extraction requires xml file.");
257 if (vm.count(
"nparts"))
263 outFile =
GetPath(filename, vm);
276 int count = fs::exists(outFile) ? 1 : 0;
280 if (count && (vm.count(
"forceoutput") == 0))
282 if (vm.count(
"nparts") == 0)
286 if (comm->GetSpaceComm()->TreatAsRankZero())
289 cout <<
"Did you wish to overwrite " << outFile <<
" (y/n)? ";
291 if (
answer.compare(
"y") == 0)
297 cout <<
"Not writing file '" << filename
298 <<
"' because it already exists" << endl;
304 return (writeFile == 0) ? false :
true;
310 int numFields =
m_f->m_exp.size();
311 m_f->m_fielddef =
m_f->m_exp[0]->GetFieldDefinitions();
315 if (vm.count(
"output-points"))
317 nPointsNew = vm[
"output-points"].as<
int>();
319 m_f->m_graph->SetExpansionInfoToEvenlySpacedPoints(nPointsNew);
322 vector<MultiRegions::ExpListSharedPtr> expOld =
m_f->m_exp;
325 m_f->m_exp[0] =
m_f->SetUpFirstExpList(
m_f->m_numHomogeneousDir,
true);
326 for (
int i = 1; i < numFields; ++i)
328 m_f->m_exp[i] =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
332 for (
int i = 0; i < numFields; ++i)
334 m_f->m_exp[i]->ExtractCoeffsToCoeffs(expOld[i], expOld[i]->GetCoeffs(),
335 m_f->m_exp[i]->UpdateCoeffs());
336 m_f->m_exp[i]->BwdTrans(
m_f->m_exp[i]->GetCoeffs(),
337 m_f->m_exp[i]->UpdatePhys());
340 if (
m_f->m_writeBndFld)
345 for (
int i = 0; i < numFields; ++i)
347 BndExpOld = expOld[i]->GetBndCondExpansions();
348 for (
int j = 0; j < BndExpOld.size(); ++j)
350 BndExp =
m_f->m_exp[i]->UpdateBndCondExpansion(j);
351 BndExp->ExtractCoeffsToCoeffs(BndExpOld[j],
352 BndExpOld[j]->GetCoeffs(),
353 BndExp->UpdateCoeffs());
357 m_f->m_fielddef = std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
362 int coordim =
m_f->m_fieldPts->GetDim();
363 std::string coordVars[] = {
"x",
"y",
"z"};
365 vector<string> variables =
m_f->m_variables;
366 variables.insert(variables.begin(), coordVars, coordVars + coordim);
372 m_f->m_fieldPts->GetPts(fields);
373 for (
int i = 0; i < fields.size(); ++i)
376 int npts = fields[i].size();
380 for (
int j = 0; j < npts; ++j)
382 l2err += fields[i][j] * fields[i][j];
383 linferr = max(linferr, fabs(fields[i][j]));
388 m_f->m_comm->GetSpaceComm()->AllReduce(linferr,
394 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
396 cout <<
"L 2 error (variable " << variables[i] <<
") : " << l2err
399 cout <<
"L inf error (variable " << variables[i]
400 <<
") : " << linferr << endl;
408 m_f->m_exp[0]->GetExp(0)->GetCoordim() +
m_f->m_numHomogeneousDir;
409 int totpoints =
m_f->m_exp[0]->GetTotPoints();
410 std::string coordVars[] = {
"x",
"y",
"z"};
414 for (
int i = 0; i < coordim; ++i)
422 m_f->m_exp[0]->GetCoords(coords[0]);
424 else if (coordim == 2)
426 m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
430 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
433 for (
int j = 0; j < coordim; ++j)
438 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
440 cout <<
"L 2 error (variable " << coordVars[j] <<
") : " << l2err
443 cout <<
"L inf error (variable " << coordVars[j]
444 <<
") : " << linferr << endl;
448 for (
int j = 0; j <
m_f->m_exp.size(); ++j)
453 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero() &&
454 m_f->m_variables.size() > 0)
456 cout <<
"L 2 error (variable " <<
m_f->m_variables[j]
457 <<
") : " << l2err << endl;
459 cout <<
"L inf error (variable " <<
m_f->m_variables[j]
460 <<
") : " << 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)
fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
virtual ~OutputFileBase()
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.
fs::path GetPath(std::string &filename, po::variables_map &vm)
virtual 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
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.