41#include <boost/format.hpp>
52 "Write multiple files in parallel or when using nparts option");
63 string filename =
m_config[
"outfile"].as<
string>();
67 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary can't be obtained from pts.");
72 if (vm.count(
"error"))
78 else if (
m_f->m_exp.size())
82 m_f->m_exp[0]->GetNumElmts() != 0)
86 if (
m_f->m_writeBndFld)
89 m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
92 <<
": Writing boundary file(s): ";
93 for (
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
95 cout <<
m_f->m_bndRegionsToWrite[i];
96 if (i < m_f->m_bndRegionsToWrite.size() - 1)
104 int nfields =
m_f->m_variables.size();
105 int normdim =
m_f->m_graph->GetMeshDimension();
108 if (
m_f->m_addNormals)
111 m_f->m_exp.resize(nfields + normdim);
114 string normstr[3] = {
"Norm_x",
"Norm_y",
"Norm_z"};
115 for (
int j = 0; j < normdim; ++j)
117 m_f->m_exp[nfields + j] =
118 m_f->AppendExpList(
m_f->m_numHomogeneousDir);
119 m_f->m_variables.push_back(normstr[j]);
124 vector<MultiRegions::ExpListSharedPtr> exp(
m_f->m_exp.size());
125 exp.swap(
m_f->m_exp);
129 for (
int i = 0; i < exp.size(); ++i)
131 BndExp[i] = exp[i]->GetBndCondExpansions();
140 map<int, int> BndRegionMap;
141 map<int, LibUtilities::CommSharedPtr> BndRegionComm;
143 for (
auto &breg_it : bregions)
145 BndRegionMap[breg_it.first] = cnt++;
146 BndRegionComm[breg_it.first] =
151 int dot = filename.find_last_of(
'.') + 1;
152 string ext = filename.substr(dot, filename.length() - dot);
153 string name = filename.substr(0, dot - 1);
158 for (
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
162 boost::lexical_cast<string>(
m_f->m_bndRegionsToWrite[i]) +
171 if (BndRegionMap.count(
m_f->m_bndRegionsToWrite[i]) == 1)
173 m_f->m_comm = BndRegionComm[
m_f->m_bndRegionsToWrite[i]];
175 int Border = BndRegionMap[
m_f->m_bndRegionsToWrite[i]];
178 for (
int j = 0; j < exp.size(); ++j)
180 m_f->m_exp[j] = BndExp[j][Border];
183 for (
int j = 0; j < exp.size(); ++j)
185 m_f->m_exp[j] = BndExp[j][Border];
186 m_f->m_exp[j]->BwdTrans(
m_f->m_exp[j]->GetCoeffs(),
187 m_f->m_exp[j]->UpdatePhys());
190 if (
m_f->m_addNormals)
194 exp[0]->GetBoundaryNormals(Border, NormPhys);
197 for (
int j = 0; j < normdim; ++j)
199 m_f->m_exp[nfields + j] =
200 BndExp[nfields + j][Border];
202 m_f->m_exp[nfields + j]->GetTotPoints(),
204 m_f->m_exp[nfields + j]->UpdatePhys(), 1);
205 m_f->m_exp[nfields + j]->FwdTransLocalElmt(
206 m_f->m_exp[nfields + j]->GetPhys(),
207 m_f->m_exp[nfields + j]->UpdateCoeffs());
212 if (vm.count(
"error"))
218 m_f->m_comm = tmpComm;
225 exp.swap(
m_f->m_exp);
233 if (vm.count(
"error"))
240 else if (
m_f->m_data.size())
242 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary extraction requires xml file.");
255 if (vm.count(
"nparts"))
261 outFile =
GetPath(filename, vm);
274 int count = fs::exists(outFile) ? 1 : 0;
278 if (count && (vm.count(
"force-output") == 0))
280 if (vm.count(
"nparts") == 0)
284 if (comm->GetSpaceComm()->TreatAsRankZero())
287 cout <<
"Did you wish to overwrite " << outFile <<
" (y/n)? ";
289 if (
answer.compare(
"y") == 0)
295 cout <<
"Not writing file '" << filename
296 <<
"' because it already exists" << endl;
302 return (writeFile == 0) ? false :
true;
308 int numFields =
m_f->m_exp.size();
309 m_f->m_fielddef =
m_f->m_exp[0]->GetFieldDefinitions();
313 if (vm.count(
"output-points"))
315 nPointsNew = vm[
"output-points"].as<
int>();
317 m_f->m_graph->SetExpansionInfoToEvenlySpacedPoints(nPointsNew);
320 vector<MultiRegions::ExpListSharedPtr> expOld =
m_f->m_exp;
323 m_f->m_exp[0] =
m_f->SetUpFirstExpList(
m_f->m_numHomogeneousDir,
true);
324 for (
int i = 1; i < numFields; ++i)
326 m_f->m_exp[i] =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
330 for (
int i = 0; i < numFields; ++i)
332 m_f->m_exp[i]->ExtractCoeffsToCoeffs(expOld[i], expOld[i]->GetCoeffs(),
333 m_f->m_exp[i]->UpdateCoeffs());
334 m_f->m_exp[i]->BwdTrans(
m_f->m_exp[i]->GetCoeffs(),
335 m_f->m_exp[i]->UpdatePhys());
338 if (
m_f->m_writeBndFld)
343 for (
int i = 0; i < numFields; ++i)
345 BndExpOld = expOld[i]->GetBndCondExpansions();
346 for (
int j = 0; j < BndExpOld.size(); ++j)
348 BndExp =
m_f->m_exp[i]->UpdateBndCondExpansion(j);
349 BndExp->ExtractCoeffsToCoeffs(BndExpOld[j],
350 BndExpOld[j]->GetCoeffs(),
351 BndExp->UpdateCoeffs());
355 m_f->m_fielddef = std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
360 int coordim =
m_f->m_fieldPts->GetDim();
361 std::string coordVars[] = {
"x",
"y",
"z"};
363 vector<string> variables =
m_f->m_variables;
364 variables.insert(variables.begin(), coordVars, coordVars + coordim);
370 m_f->m_fieldPts->GetPts(fields);
371 for (
int i = 0; i < fields.size(); ++i)
374 int npts = fields[i].size();
378 for (
int j = 0; j < npts; ++j)
380 l2err += fields[i][j] * fields[i][j];
381 linferr = max(linferr, fabs(fields[i][j]));
386 m_f->m_comm->GetSpaceComm()->AllReduce(linferr,
392 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
394 cout <<
"L 2 error (variable " << variables[i] <<
") : " << l2err
397 cout <<
"L inf error (variable " << variables[i]
398 <<
") : " << linferr << endl;
406 m_f->m_exp[0]->GetExp(0)->GetCoordim() +
m_f->m_numHomogeneousDir;
407 int totpoints =
m_f->m_exp[0]->GetTotPoints();
408 std::string coordVars[] = {
"x",
"y",
"z"};
412 for (
int i = 0; i < coordim; ++i)
420 m_f->m_exp[0]->GetCoords(coords[0]);
422 else if (coordim == 2)
424 m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
428 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
431 for (
int j = 0; j < coordim; ++j)
436 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
438 cout <<
"L 2 error (variable " << coordVars[j] <<
") : " << l2err
441 cout <<
"L inf error (variable " << coordVars[j]
442 <<
") : " << linferr << endl;
446 for (
int j = 0; j <
m_f->m_exp.size(); ++j)
451 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero() &&
452 m_f->m_variables.size() > 0)
454 cout <<
"L 2 error (variable " <<
m_f->m_variables[j]
455 <<
") : " << l2err << endl;
457 cout <<
"L inf error (variable " <<
m_f->m_variables[j]
458 <<
") : " << 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.