41 #include <boost/format.hpp> 54 "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)
87 if (
m_f->m_writeBndFld)
89 if (
m_f->m_verbose &&
m_f->m_comm->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);
115 string normstr[3] = {
"Norm_x",
"Norm_y",
"Norm_z"};
116 for (
int j = 0; j < normdim; ++j)
118 m_f->m_exp[nfields + j] =
119 m_f->AppendExpList(
m_f->m_numHomogeneousDir);
120 m_f->m_variables.push_back(normstr[j]);
125 vector<MultiRegions::ExpListSharedPtr> exp(
m_f->m_exp.size());
126 exp.swap(
m_f->m_exp);
130 for (
int i = 0; i < exp.size(); ++i)
132 BndExp[i] = exp[i]->GetBndCondExpansions();
141 map<int, int> BndRegionMap;
142 map<int, LibUtilities::CommSharedPtr> BndRegionComm;
144 for (
auto &breg_it : bregions)
146 BndRegionMap[breg_it.first] = cnt++;
147 BndRegionComm[breg_it.first] =
148 bcs.GetBoundaryCommunicators()[breg_it.first];
152 int dot = filename.find_last_of(
'.') + 1;
153 string ext = filename.substr(dot, filename.length() - dot);
154 string name = filename.substr(0, dot - 1);
159 for (
int i = 0; i <
m_f->m_bndRegionsToWrite.size(); ++i)
163 boost::lexical_cast<
string>(
m_f->m_bndRegionsToWrite[i]) +
172 if (BndRegionMap.count(
m_f->m_bndRegionsToWrite[i]) == 1)
174 m_f->m_comm = BndRegionComm[
m_f->m_bndRegionsToWrite[i]];
176 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];
181 m_f->m_exp[j]->BwdTrans(
m_f->m_exp[j]->GetCoeffs(),
182 m_f->m_exp[j]->UpdatePhys());
185 if (
m_f->m_addNormals)
189 exp[0]->GetBoundaryNormals(Border, NormPhys);
192 for (
int j = 0; j < normdim; ++j)
194 m_f->m_exp[nfields + j] =
195 BndExp[nfields + j][Border];
197 m_f->m_exp[nfields + j]->GetTotPoints(),
199 m_f->m_exp[nfields + j]->UpdatePhys(), 1);
200 m_f->m_exp[nfields + j]->FwdTrans_IterPerExp(
201 m_f->m_exp[nfields + j]->GetPhys(),
202 m_f->m_exp[nfields + j]->UpdateCoeffs());
207 if (vm.count(
"error"))
213 m_f->m_comm = tmpComm;
220 exp.swap(
m_f->m_exp);
228 if (vm.count(
"error"))
235 else if (
m_f->m_data.size())
237 ASSERTL0(!
m_f->m_writeBndFld,
"Boundary extraction requires xml file.");
250 if (vm.count(
"nparts"))
256 outFile =
GetPath(filename, vm);
269 int count = fs::exists(outFile) ? 1 : 0;
273 if (count && (vm.count(
"forceoutput") == 0))
275 if (vm.count(
"nparts") == 0)
280 if (comm->TreatAsRankZero())
283 cout <<
"Did you wish to overwrite " << outFile <<
" (y/n)? ";
284 getline(cin, answer);
285 if (answer.compare(
"y") == 0)
291 cout <<
"Not writing file " << filename
292 <<
" because it already exists" << endl;
298 return (writeFile == 0) ? false :
true;
304 int numFields =
m_f->m_exp.size();
305 m_f->m_fielddef =
m_f->m_exp[0]->GetFieldDefinitions();
309 if (vm.count(
"output-points"))
311 nPointsNew = vm[
"output-points"].as<
int>();
313 m_f->m_graph->SetExpansionsToEvenlySpacedPoints(nPointsNew);
316 vector<MultiRegions::ExpListSharedPtr> expOld =
m_f->m_exp;
318 m_f->m_exp[0] =
m_f->SetUpFirstExpList(
m_f->m_numHomogeneousDir,
true);
319 for (
int i = 1; i < numFields; ++i)
321 m_f->m_exp[i] =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
324 for (
int i = 0; i < numFields; ++i)
326 m_f->m_exp[i]->ExtractCoeffsToCoeffs(expOld[i], expOld[i]->GetCoeffs(),
327 m_f->m_exp[i]->UpdateCoeffs());
328 m_f->m_exp[i]->BwdTrans(
m_f->m_exp[i]->GetCoeffs(),
329 m_f->m_exp[i]->UpdatePhys());
332 if (
m_f->m_writeBndFld)
336 for (
int i = 0; i < numFields; ++i)
338 BndExpOld = expOld[i]->GetBndCondExpansions();
339 for (
int j = 0; j < BndExpOld.num_elements(); ++j)
341 BndExp =
m_f->m_exp[i]->UpdateBndCondExpansion(j);
343 BndExp->ExtractCoeffsToCoeffs(BndExpOld[j],
344 BndExpOld[j]->GetCoeffs(),
345 BndExp->UpdateCoeffs());
353 int coordim =
m_f->m_fieldPts->GetDim();
354 std::string coordVars[] = {
"x",
"y",
"z"};
356 vector<string> variables =
m_f->m_variables;
357 variables.insert(variables.begin(), coordVars, coordVars + coordim);
363 m_f->m_fieldPts->GetPts(fields);
364 for (
int i = 0; i < fields.num_elements(); ++i)
367 int npts = fields[i].num_elements();
371 for (
int j = 0; j < npts; ++j)
373 l2err += fields[i][j] * fields[i][j];
374 linferr = max(linferr, fabs(fields[i][j]));
384 if (
m_f->m_comm->TreatAsRankZero())
386 cout <<
"L 2 error (variable " << variables[i] <<
") : " << l2err
389 cout <<
"L inf error (variable " << variables[i]
390 <<
") : " << linferr << endl;
398 m_f->m_exp[0]->GetExp(0)->GetCoordim() +
m_f->m_numHomogeneousDir;
399 int totpoints =
m_f->m_exp[0]->GetTotPoints();
400 std::string coordVars[] = {
"x",
"y",
"z"};
404 for (
int i = 0; i < coordim; ++i)
412 m_f->m_exp[0]->GetCoords(coords[0]);
414 else if (coordim == 2)
416 m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
420 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
423 for (
int j = 0; j < coordim; ++j)
428 if (
m_f->m_comm->TreatAsRankZero())
430 cout <<
"L 2 error (variable " << coordVars[j] <<
") : " << l2err
433 cout <<
"L inf error (variable " << coordVars[j]
434 <<
") : " << linferr << endl;
438 for (
int j = 0; j <
m_f->m_exp.size(); ++j)
443 if (
m_f->m_comm->TreatAsRankZero() &&
m_f->m_variables.size() > 0)
445 cout <<
"L 2 error (variable " <<
m_f->m_variables[j]
446 <<
") : " << l2err << endl;
448 cout <<
"L inf error (variable " <<
m_f->m_variables[j]
449 <<
") : " << linferr << endl;
#define ASSERTL0(condition, msg)
std::map< std::string, ConfigOption > m_config
List of configuration values.
Represents a command-line configuration option.
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
bool WriteFile(std::string &filename, po::variables_map &vm)
virtual void OutputFromPts(po::variables_map &vm)=0
Write from pts to output file.
std::shared_ptr< Field > FieldSharedPtr
virtual fs::path GetFullOutName(std::string &filename, po::variables_map &vm)=0
CommFactory & GetCommFactory()
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
void ConvertExpToEquispaced(po::variables_map &vm)
FIELD_UTILS_EXPORT void RegisterConfig(std::string key, std::string value="")
Register a configuration option with a module.
virtual void OutputFromData(po::variables_map &vm)=0
Write from data to output file.
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
virtual ~OutputFileBase()
virtual void OutputFromExp(po::variables_map &vm)=0
Write from m_exp to output file.
static PtsFieldSharedPtr NullPtsField
virtual std::string GetModuleName()
virtual void Process(po::variables_map &vm)
Write fld to output file.
virtual fs::path GetPath(std::string &filename, po::variables_map &vm)=0
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
const BoundaryRegionCollection & GetBoundaryRegions(void) const
Abstract base class for output modules.
FieldSharedPtr m_f
Field object.