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)
168 boost::lexical_cast<string>(
m_f->m_bndRegionsToWrite[i]) +
177 if (BndRegionMap.count(
m_f->m_bndRegionsToWrite[i]) == 1)
179 m_f->m_comm = BndRegionComm[
m_f->m_bndRegionsToWrite[i]];
181 int Border = BndRegionMap[
m_f->m_bndRegionsToWrite[i]];
184 for (
int j = 0; j < exp.size(); ++j)
186 m_f->m_exp[j] = BndExp[j][Border];
189 for (
int j = 0; j < exp.size(); ++j)
191 m_f->m_exp[j] = BndExp[j][Border];
192 m_f->m_exp[j]->BwdTrans(
m_f->m_exp[j]->GetCoeffs(),
193 m_f->m_exp[j]->UpdatePhys());
196 if (
m_f->m_addNormals)
200 exp[0]->GetBoundaryNormals(Border, NormPhys);
203 for (
int j = 0; j < normdim; ++j)
205 m_f->m_exp[nfields + j] =
206 BndExp[nfields + j][Border];
208 m_f->m_exp[nfields + j]->GetTotPoints(),
210 m_f->m_exp[nfields + j]->UpdatePhys(), 1);
211 m_f->m_exp[nfields + j]->FwdTransLocalElmt(
212 m_f->m_exp[nfields + j]->GetPhys(),
213 m_f->m_exp[nfields + j]->UpdateCoeffs());
218 if (vm.count(
"error"))
224 m_f->m_comm = tmpComm;
231 exp.swap(
m_f->m_exp);
239 if (vm.count(
"error"))
246 else if (
m_f->m_data.size())
248 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary extraction requires xml file.");
266 if (vm.count(
"nparts"))
272 outFile =
GetPath(filename, vm);
285 int count = fs::exists(outFile) ? 1 : 0;
289 if (count && (vm.count(
"force-output") == 0))
291 if (vm.count(
"nparts") == 0)
295 if (comm->GetSpaceComm()->TreatAsRankZero())
298 cout <<
"Did you wish to overwrite " << outFile <<
" (y/n)? ";
300 if (
answer.compare(
"y") == 0)
306 cout <<
"Not writing file '" << filename
307 <<
"' because it already exists" << endl;
313 return (writeFile == 0) ? false :
true;
319 int numFields =
m_f->m_exp.size();
320 m_f->m_fielddef =
m_f->m_exp[0]->GetFieldDefinitions();
324 if (vm.count(
"output-points"))
326 nPointsNew = vm[
"output-points"].as<
int>();
328 m_f->m_graph->SetExpansionInfoToEvenlySpacedPoints(nPointsNew);
331 vector<MultiRegions::ExpListSharedPtr> expOld =
m_f->m_exp;
334 m_f->m_exp[0] =
m_f->SetUpFirstExpList(
m_f->m_numHomogeneousDir,
true);
335 for (
int i = 1; i < numFields; ++i)
337 m_f->m_exp[i] =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
341 for (
int i = 0; i < numFields; ++i)
343 m_f->m_exp[i]->ExtractCoeffsToCoeffs(expOld[i], expOld[i]->GetCoeffs(),
344 m_f->m_exp[i]->UpdateCoeffs());
345 m_f->m_exp[i]->BwdTrans(
m_f->m_exp[i]->GetCoeffs(),
346 m_f->m_exp[i]->UpdatePhys());
350 if (
m_f->m_writeBndFld)
355 for (
int i = 0; i < numFields; ++i)
357 BndExpOld = expOld[i]->GetBndCondExpansions();
358 for (
int j = 0; j < BndExpOld.size(); ++j)
360 BndExp =
m_f->m_exp[i]->UpdateBndCondExpansion(j);
361 BndExp->ExtractCoeffsToCoeffs(BndExpOld[j],
362 BndExpOld[j]->GetCoeffs(),
363 BndExp->UpdateCoeffs());
368 m_f->m_fielddef = std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
376 int coordim =
m_f->m_fieldPts->GetDim();
377 std::string coordVars[] = {
"x",
"y",
"z"};
379 vector<string> variables =
m_f->m_variables;
380 variables.insert(variables.begin(), coordVars, coordVars + coordim);
386 m_f->m_fieldPts->GetPts(fields);
387 for (
int i = 0; i < fields.size(); ++i)
390 int npts = fields[i].size();
394 for (
int j = 0; j < npts; ++j)
396 l2err += fields[i][j] * fields[i][j];
397 linferr = max(linferr, fabs(fields[i][j]));
402 m_f->m_comm->GetSpaceComm()->AllReduce(linferr,
408 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
410 cout <<
"L 2 error (variable " << variables[i] <<
") : " << l2err
413 cout <<
"L inf error (variable " << variables[i]
414 <<
") : " << linferr << endl;
422 m_f->m_exp[0]->GetExp(0)->GetCoordim() +
m_f->m_numHomogeneousDir;
423 int totpoints =
m_f->m_exp[0]->GetTotPoints();
424 std::string coordVars[] = {
"x",
"y",
"z"};
428 for (
int i = 0; i < coordim; ++i)
436 m_f->m_exp[0]->GetCoords(coords[0]);
438 else if (coordim == 2)
440 m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
444 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
447 for (
int j = 0; j < coordim; ++j)
452 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
454 cout <<
"L 2 error (variable " << coordVars[j] <<
") : " << l2err
457 cout <<
"L inf error (variable " << coordVars[j]
458 <<
") : " << linferr << endl;
462 for (
int j = 0; j <
m_f->m_exp.size(); ++j)
467 if (
m_f->m_comm->GetSpaceComm()->TreatAsRankZero() &&
468 m_f->m_variables.size() > 0)
470 cout <<
"L 2 error (variable " <<
m_f->m_variables[j]
471 <<
") : " << l2err << endl;
473 cout <<
"L inf error (variable " <<
m_f->m_variables[j]
474 <<
") : " << 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.