Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
Nektar::FieldUtils::OutputFileBase Class Referenceabstract

Converter from fld to vtk. More...

#include <OutputFileBase.h>

Inheritance diagram for Nektar::FieldUtils::OutputFileBase:
[legend]

Public Member Functions

 OutputFileBase (FieldSharedPtr f)
 
 ~OutputFileBase () override
 
- Public Member Functions inherited from Nektar::FieldUtils::OutputModule
 OutputModule (FieldSharedPtr p_f)
 
FIELD_UTILS_EXPORT void OpenStream ()
 Open a file for output.
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
virtual ~Module ()=default
 
void Process (po::variables_map &vm)
 
std::string GetModuleName ()
 
std::string GetModuleDescription ()
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
std::vector< ModuleKeyGetModulePrerequisites ()
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::string value="")
 Register a configuration option with a module.
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module.
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set.
 
FIELD_UTILS_EXPORT void AddFile (std::string fileType, std::string fileName)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Protected Member Functions

void v_Process (po::variables_map &vm) override
 Write fld to output file.
 
std::string v_GetModuleName () override
 
std::string v_GetModuleDescription () override
 
ModulePriority v_GetModulePriority () override
 
virtual void v_OutputFromPts (po::variables_map &vm)=0
 Write from pts to output file.
 
virtual void v_OutputFromExp (po::variables_map &vm)=0
 Write from m_exp to output file.
 
virtual void v_OutputFromData (po::variables_map &vm)=0
 Write from data to output file.
 
virtual fs::path v_GetPath (std::string &filename, po::variables_map &vm)
 
fs::path GetPath (std::string &filename, po::variables_map &vm)
 
virtual fs::path v_GetFullOutName (std::string &filename, po::variables_map &vm)
 
fs::path GetFullOutName (std::string &filename, po::variables_map &vm)
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
virtual std::vector< ModuleKeyv_GetModulePrerequisites ()
 

Protected Attributes

bool m_requireEquiSpaced
 
bool m_prohibitWrite = false
 
bool m_equispacedSetup = false
 
- Protected Attributes inherited from Nektar::FieldUtils::OutputModule
std::ofstream m_fldFile
 Output stream.
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values.
 
std::set< std::string > m_allowedFiles
 List of allowed file formats.
 

Private Member Functions

bool WriteFile (std::string &filename, po::variables_map &vm)
 
void ConvertExpToEquispaced (po::variables_map &vm)
 
void PrintErrorFromPts ()
 
void PrintErrorFromExp ()
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object.
 

Detailed Description

Converter from fld to vtk.

Definition at line 45 of file OutputFileBase.h.

Constructor & Destructor Documentation

◆ OutputFileBase()

Nektar::FieldUtils::OutputFileBase::OutputFileBase ( FieldSharedPtr  f)

Definition at line 48 of file OutputFileBase.cpp.

48 : OutputModule(f)
49{
50 m_requireEquiSpaced = false;
51 m_prohibitWrite = false;
52 m_config["writemultiplefiles"] = ConfigOption(
53 true, "0",
54 "Write multiple files in parallel or when using nparts option");
55}
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition Module.h:272
OutputModule(FieldSharedPtr p_f)
Definition Module.cpp:66

References Nektar::FieldUtils::Module::m_config, m_prohibitWrite, and m_requireEquiSpaced.

◆ ~OutputFileBase()

Nektar::FieldUtils::OutputFileBase::~OutputFileBase ( )
override

Definition at line 57 of file OutputFileBase.cpp.

58{
59}

Member Function Documentation

◆ ConvertExpToEquispaced()

void Nektar::FieldUtils::OutputFileBase::ConvertExpToEquispaced ( po::variables_map &  vm)
private

Definition at line 348 of file OutputFileBase.cpp.

349{
350 // Information to create new expansion
351 int numFields = m_f->m_exp.size();
352 m_f->m_fielddef = m_f->m_exp[0]->GetFieldDefinitions();
353
354 // Set points to equispaced
355 int nPointsNew = 0;
356 if (vm.count("output-points"))
357 {
358 nPointsNew = vm["output-points"].as<int>();
359 }
360 m_f->m_graph->SetExpansionInfoToEvenlySpacedPoints(nPointsNew);
361
362 // Save original expansion
363 vector<MultiRegions::ExpListSharedPtr> expOld = m_f->m_exp;
364
365 // Create new expansion
366 m_f->m_exp[0] = m_f->SetUpFirstExpList(m_f->m_numHomogeneousDir, true);
367 for (int i = 1; i < numFields; ++i)
368 {
369 m_f->m_exp[i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
370 }
371
372 // Extract result to new expansion
373 for (int i = 0; i < numFields; ++i)
374 {
375 m_f->m_exp[i]->ExtractCoeffsToCoeffs(expOld[i], expOld[i]->GetCoeffs(),
376 m_f->m_exp[i]->UpdateCoeffs());
377 m_f->m_exp[i]->BwdTrans(m_f->m_exp[i]->GetCoeffs(),
378 m_f->m_exp[i]->UpdatePhys());
379 }
380
381 // Extract boundary expansion if needed
382 if (m_f->m_writeBndFld)
383 {
384 Array<OneD, const MultiRegions::ExpListSharedPtr> BndExpOld;
386
387 for (int i = 0; i < numFields; ++i)
388 {
389 BndExpOld = expOld[i]->GetBndCondExpansions();
390 for (int j = 0; j < BndExpOld.size(); ++j)
391 {
392 BndExp = m_f->m_exp[i]->UpdateBndCondExpansion(j);
393 BndExp->ExtractCoeffsToCoeffs(BndExpOld[j],
394 BndExpOld[j]->GetCoeffs(),
395 BndExp->UpdateCoeffs());
396 }
397 }
398 }
399
400 m_f->m_fielddef = std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
401
402 // Make a note so that we know that the fielddefs have now been setup.
403 m_equispacedSetup = true;
404}
FieldSharedPtr m_f
Field object.
Definition Module.h:239
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.

References m_equispacedSetup, and Nektar::FieldUtils::Module::m_f.

Referenced by v_Process().

◆ GetFullOutName()

fs::path Nektar::FieldUtils::OutputFileBase::GetFullOutName ( std::string &  filename,
po::variables_map &  vm 
)
inlineprotected

Definition at line 96 of file OutputFileBase.h.

97 {
98 return v_GetFullOutName(filename, vm);
99 }
virtual fs::path v_GetFullOutName(std::string &filename, po::variables_map &vm)

References v_GetFullOutName().

Referenced by Nektar::FieldUtils::OutputVtkBase::PrepareOutput(), WriteFile(), and Nektar::FieldUtils::OutputTecplot::WriteTecplotFile().

◆ GetPath()

fs::path Nektar::FieldUtils::OutputFileBase::GetPath ( std::string &  filename,
po::variables_map &  vm 
)
inlineprotected

◆ PrintErrorFromExp()

void Nektar::FieldUtils::OutputFileBase::PrintErrorFromExp ( )
private

Definition at line 451 of file OutputFileBase.cpp.

452{
453 int coordim =
454 m_f->m_exp[0]->GetExp(0)->GetCoordim() + m_f->m_numHomogeneousDir;
455 int totpoints = m_f->m_exp[0]->GetTotPoints();
456 std::string coordVars[] = {"x", "y", "z"};
457
458 // Set up storage for coordinates
459 Array<OneD, Array<OneD, NekDouble>> coords(coordim);
460 for (int i = 0; i < coordim; ++i)
461 {
462 coords[i] = Array<OneD, NekDouble>(totpoints);
463 }
464
465 // Get coordinates
466 if (coordim == 1)
467 {
468 m_f->m_exp[0]->GetCoords(coords[0]);
469 }
470 else if (coordim == 2)
471 {
472 m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
473 }
474 else
475 {
476 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
477 }
478
479 for (int j = 0; j < coordim; ++j)
480 {
481 NekDouble l2err = m_f->m_exp[0]->L2(coords[j]);
482 NekDouble linferr = m_f->m_exp[0]->Linf(coords[j]);
483
484 if (m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
485 {
486 cout << "L 2 error (variable " << coordVars[j] << ") : " << l2err
487 << endl;
488
489 cout << "L inf error (variable " << coordVars[j]
490 << ") : " << linferr << endl;
491 }
492 }
493
494 for (int j = 0; j < m_f->m_exp.size(); ++j)
495 {
496 NekDouble l2err = m_f->m_exp[j]->L2(m_f->m_exp[j]->GetPhys());
497 NekDouble linferr = m_f->m_exp[j]->Linf(m_f->m_exp[j]->GetPhys());
498
499 if (m_f->m_comm->GetSpaceComm()->TreatAsRankZero() &&
500 m_f->m_variables.size() > 0)
501 {
502 cout << "L 2 error (variable " << m_f->m_variables[j]
503 << ") : " << l2err << endl;
504
505 cout << "L inf error (variable " << m_f->m_variables[j]
506 << ") : " << linferr << endl;
507 }
508 }
509}

References Nektar::FieldUtils::Module::m_f.

Referenced by v_Process().

◆ PrintErrorFromPts()

void Nektar::FieldUtils::OutputFileBase::PrintErrorFromPts ( )
private

Definition at line 406 of file OutputFileBase.cpp.

407{
408 int coordim = m_f->m_fieldPts->GetDim();
409 std::string coordVars[] = {"x", "y", "z"};
410
411 vector<string> variables = m_f->m_variables;
412 variables.insert(variables.begin(), coordVars, coordVars + coordim);
413 // Get fields and coordinates
414 Array<OneD, Array<OneD, NekDouble>> fields(variables.size());
415
416 // We can just grab everything from points. This should be a
417 // reference, not a copy.
418 m_f->m_fieldPts->GetPts(fields);
419 for (int i = 0; i < fields.size(); ++i)
420 {
421 // calculate L2 and Linf value
422 int npts = fields[i].size();
423
424 NekDouble l2err = 0.0;
425 NekDouble linferr = 0.0;
426 for (int j = 0; j < npts; ++j)
427 {
428 l2err += fields[i][j] * fields[i][j];
429 linferr = max(linferr, fabs(fields[i][j]));
430 }
431
432 m_f->m_comm->GetSpaceComm()->AllReduce(l2err, LibUtilities::ReduceSum);
433 m_f->m_comm->GetSpaceComm()->AllReduce(npts, LibUtilities::ReduceSum);
434 m_f->m_comm->GetSpaceComm()->AllReduce(linferr,
436
437 l2err /= npts;
438 l2err = sqrt(l2err);
439
440 if (m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
441 {
442 cout << "L 2 error (variable " << variables[i] << ") : " << l2err
443 << endl;
444
445 cout << "L inf error (variable " << variables[i]
446 << ") : " << linferr << endl;
447 }
448 }
449}
scalarT< T > max(scalarT< T > lhs, scalarT< T > rhs)
Definition scalar.hpp:305
scalarT< T > sqrt(scalarT< T > in)
Definition scalar.hpp:290

References Nektar::FieldUtils::Module::m_f, tinysimd::max(), Nektar::LibUtilities::ReduceMax, Nektar::LibUtilities::ReduceSum, and tinysimd::sqrt().

Referenced by v_Process().

◆ v_GetFullOutName()

virtual fs::path Nektar::FieldUtils::OutputFileBase::v_GetFullOutName ( std::string &  filename,
po::variables_map &  vm 
)
inlineprotectedvirtual

Reimplemented in Nektar::FieldUtils::OutputFld, Nektar::FieldUtils::OutputPts, Nektar::FieldUtils::OutputTecplot, and Nektar::FieldUtils::OutputVtkBase.

Definition at line 90 of file OutputFileBase.h.

92 {
93 NEKERROR(ErrorUtil::efatal, "v_OutputFromExp not coded");
94 return fs::path();
95 }
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...

References Nektar::ErrorUtil::efatal, and NEKERROR.

Referenced by GetFullOutName().

◆ v_GetModuleDescription()

std::string Nektar::FieldUtils::OutputFileBase::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 60 of file OutputFileBase.h.

61 {
62 return "Writing file";
63 }

◆ v_GetModuleName()

std::string Nektar::FieldUtils::OutputFileBase::v_GetModuleName ( )
inlineoverrideprotectedvirtual

◆ v_GetModulePriority()

ModulePriority Nektar::FieldUtils::OutputFileBase::v_GetModulePriority ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 65 of file OutputFileBase.h.

66 {
67 return eOutput;
68 }

References Nektar::FieldUtils::eOutput.

◆ v_GetPath()

virtual fs::path Nektar::FieldUtils::OutputFileBase::v_GetPath ( std::string &  filename,
po::variables_map &  vm 
)
inlineprotectedvirtual

Reimplemented in Nektar::FieldUtils::OutputFld, Nektar::FieldUtils::OutputPts, Nektar::FieldUtils::OutputTecplot, and Nektar::FieldUtils::OutputVtkBase.

Definition at line 79 of file OutputFileBase.h.

81 {
82 NEKERROR(ErrorUtil::efatal, "v_GetPath not coded");
83 return fs::path();
84 }

References Nektar::ErrorUtil::efatal, and NEKERROR.

Referenced by GetPath().

◆ v_OutputFromData()

virtual void Nektar::FieldUtils::OutputFileBase::v_OutputFromData ( po::variables_map &  vm)
protectedpure virtual

◆ v_OutputFromExp()

virtual void Nektar::FieldUtils::OutputFileBase::v_OutputFromExp ( po::variables_map &  vm)
protectedpure virtual

◆ v_OutputFromPts()

virtual void Nektar::FieldUtils::OutputFileBase::v_OutputFromPts ( po::variables_map &  vm)
protectedpure virtual

◆ v_Process()

void Nektar::FieldUtils::OutputFileBase::v_Process ( po::variables_map &  vm)
overrideprotectedvirtual

Write fld to output file.

Reimplemented from Nektar::FieldUtils::Module.

Reimplemented in Nektar::FieldUtils::OutputTecplot.

Definition at line 61 of file OutputFileBase.cpp.

62{
63 m_f->SetUpExp(vm);
64
65 string filename = m_config["outfile"].as<string>();
66
67 if (filename == "")
68 {
69 m_prohibitWrite = true;
70 }
71
72 if (m_f->m_fieldPts != LibUtilities::NullPtsField)
73 {
74 ASSERTL0(!m_f->m_writeBndFld, "Boundary can't be obtained from pts.");
75 if (WriteFile(filename, vm))
76 {
78
79 if (vm.count("error"))
80 {
82 }
83 }
84 }
85 else if (m_f->m_exp.size())
86 {
87 // reset expansion definition to use equispaced points if required.
88 if (m_requireEquiSpaced && (vm.count("no-equispaced") == 0) &&
89 m_f->m_exp[0]->GetNumElmts() != 0 && !m_equispacedSetup)
90 {
92 }
93 if (m_f->m_writeBndFld)
94 {
95 if (m_f->m_verbose &&
96 m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
97 {
98 cout << "\t" << GetModuleName()
99 << ": Writing boundary file(s): ";
100 for (int i = 0; i < m_f->m_bndRegionsToWrite.size(); ++i)
101 {
102 cout << m_f->m_bndRegionsToWrite[i];
103 if (i < m_f->m_bndRegionsToWrite.size() - 1)
104 {
105 cout << ", ";
106 }
107 }
108 cout << endl;
109 }
110
111 int nfields = m_f->m_variables.size();
112 int normdim = m_f->m_graph->GetMeshDimension();
113
114 // Prepare for normals output
115 if (m_f->m_addNormals)
116 {
117 // Prepare for creating expansions for normals
118 m_f->m_exp.resize(nfields + normdim);
119
120 // Include normal name in m_variables
121 string normstr[3] = {"Norm_x", "Norm_y", "Norm_z"};
122 for (int j = 0; j < normdim; ++j)
123 {
124 m_f->m_exp[nfields + j] =
125 m_f->AppendExpList(m_f->m_numHomogeneousDir);
126 m_f->m_variables.push_back(normstr[j]);
127 }
128 }
129
130 // Move m_exp to a new expansion vector
131 vector<MultiRegions::ExpListSharedPtr> exp(m_f->m_exp.size());
132 exp.swap(m_f->m_exp);
133
134 Array<OneD, Array<OneD, const MultiRegions::ExpListSharedPtr>>
135 BndExp(exp.size());
136 for (int i = 0; i < exp.size(); ++i)
137 {
138 BndExp[i] = exp[i]->GetBndCondExpansions();
139 }
140
141 // get hold of partition boundary regions so we can match it to
142 // desired region extraction
143 SpatialDomains::BoundaryConditions bcs(m_f->m_session,
144 exp[0]->GetGraph());
146 bcs.GetBoundaryRegions();
147 map<int, int> BndRegionMap;
148 map<int, LibUtilities::CommSharedPtr> BndRegionComm;
149
150 // when using extract we may not have defined all boundary regions
151 // so identify that here
152 std::set<int> ProcessBnd;
153 if (m_f->m_session->DefinesTag("CreateBndRegions"))
154 {
155 // evaluate bnd regions to be generated
156 vector<unsigned int> bndRegions;
157 ASSERTL0(
159 m_f->m_session->GetTag("CreateBndRegions"), bndRegions),
160 "Failed to interpret bnd values string");
161
162 for (auto &bnd : bndRegions)
163 {
164 if (bregions.count(bnd) == 1)
165 {
166 ProcessBnd.insert(bnd);
167 }
168 }
169 }
170 else
171 {
172 for (auto &it : bregions)
173 {
174 ProcessBnd.insert(it.first);
175 }
176 }
177
178 int cnt = 0;
179 for (auto &breg_it : bregions)
180 {
181 if (ProcessBnd.count(breg_it.first))
182 {
183 BndRegionMap[breg_it.first] = cnt++;
184 BndRegionComm[breg_it.first] =
185 bcs.GetBoundaryCommunicators()[breg_it.first];
186 }
187 }
188
189 // find ending of output file and insert _b1, _b2
190 int dot = filename.find_last_of('.') + 1;
191 string ext = filename.substr(dot, filename.length() - dot);
192 string name = filename.substr(0, dot - 1);
193
194 // Store temporary communicator
195 LibUtilities::CommSharedPtr tmpComm = m_f->m_comm;
196
197 for (int i = 0; i < m_f->m_bndRegionsToWrite.size(); ++i)
198 {
199 string outname = name + "_b" +
200 std::to_string(m_f->m_bndRegionsToWrite[i]) +
201 "." + ext;
202
203 if (!WriteFile(outname, vm))
204 {
205 continue;
206 }
207 RegisterConfig("outfile", outname);
208
209 if (BndRegionMap.count(m_f->m_bndRegionsToWrite[i]) == 1)
210 {
211 m_f->m_comm = BndRegionComm[m_f->m_bndRegionsToWrite[i]];
212
213 int Border = BndRegionMap[m_f->m_bndRegionsToWrite[i]];
214
215 // set up m_exp to point to boundary expansion
216 for (int j = 0; j < exp.size(); ++j)
217 {
218 m_f->m_exp[j] = BndExp[j][Border];
219 }
220
221 for (int j = 0; j < exp.size(); ++j)
222 {
223 m_f->m_exp[j] = BndExp[j][Border];
224 m_f->m_exp[j]->BwdTrans(m_f->m_exp[j]->GetCoeffs(),
225 m_f->m_exp[j]->UpdatePhys());
226 }
227
228 if (m_f->m_addNormals)
229 {
230 // Get normals
231 Array<OneD, Array<OneD, NekDouble>> NormPhys;
232 exp[0]->GetBoundaryNormals(Border, NormPhys);
233
234 // add normal coefficients to expansions
235 for (int j = 0; j < normdim; ++j)
236 {
237 m_f->m_exp[nfields + j] =
238 BndExp[nfields + j][Border];
240 m_f->m_exp[nfields + j]->GetTotPoints(),
241 NormPhys[j], 1,
242 m_f->m_exp[nfields + j]->UpdatePhys(), 1);
243 m_f->m_exp[nfields + j]->FwdTransLocalElmt(
244 m_f->m_exp[nfields + j]->GetPhys(),
245 m_f->m_exp[nfields + j]->UpdateCoeffs());
246 }
247 }
248 v_OutputFromExp(vm);
249 // output error for regression checking.
250 if (vm.count("error"))
251 {
253 }
254
255 // Reset communicator
256 m_f->m_comm = tmpComm;
257 }
258
259 // put outfile back to filename in case of nparts option
260 RegisterConfig("outfile", filename);
261 }
262 // Restore m_exp
263 exp.swap(m_f->m_exp);
264 }
265 else
266 {
267 if (WriteFile(filename, vm))
268 {
269 v_OutputFromExp(vm);
270 // output error for regression checking.
271 if (vm.count("error"))
272 {
274 }
275 }
276 }
277 }
278 else if (m_f->m_data.size())
279 {
280 ASSERTL0(!m_f->m_writeBndFld, "Boundary extraction requires xml file.");
281 if (WriteFile(filename, vm))
282 {
284 }
285 }
286}
#define ASSERTL0(condition, msg)
FIELD_UTILS_EXPORT void RegisterConfig(std::string key, std::string value="")
Register a configuration option with a module.
Definition Module.cpp:100
std::string GetModuleName()
Definition Module.h:200
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)
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.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
static PtsFieldSharedPtr NullPtsField
Definition PtsField.h:185
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition Comm.h:55
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition Conditions.h:249
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:825

References ASSERTL0, ConvertExpToEquispaced(), Nektar::ParseUtils::GenerateVector(), Nektar::SpatialDomains::BoundaryConditions::GetBoundaryCommunicators(), Nektar::SpatialDomains::BoundaryConditions::GetBoundaryRegions(), Nektar::FieldUtils::Module::GetModuleName(), Nektar::FieldUtils::Module::m_config, m_equispacedSetup, Nektar::FieldUtils::Module::m_f, m_prohibitWrite, m_requireEquiSpaced, Nektar::LibUtilities::NullPtsField, PrintErrorFromExp(), PrintErrorFromPts(), Nektar::FieldUtils::Module::RegisterConfig(), v_OutputFromData(), v_OutputFromExp(), v_OutputFromPts(), Vmath::Vcopy(), and WriteFile().

Referenced by Nektar::FieldUtils::OutputTecplot::v_Process().

◆ WriteFile()

bool Nektar::FieldUtils::OutputFileBase::WriteFile ( std::string &  filename,
po::variables_map &  vm 
)
private

Definition at line 288 of file OutputFileBase.cpp.

289{
290 if (m_prohibitWrite)
291 {
292 return true;
293 }
294
295 // Get path to file. If procid was defined, get the full name to avoid
296 // checking files from other partitions
297 fs::path outFile;
298 if (vm.count("nparts"))
299 {
300 outFile = GetFullOutName(filename, vm);
301 }
302 else
303 {
304 outFile = GetPath(filename, vm);
305 }
306
308 if (m_f->m_comm)
309 {
310 comm = m_f->m_comm;
311 }
312 else
313 {
314 comm = LibUtilities::GetCommFactory().CreateInstance("Serial", 0, 0);
315 }
316
317 int count = fs::exists(outFile) ? 1 : 0;
318 comm->GetSpaceComm()->AllReduce(count, LibUtilities::ReduceSum);
319
320 int writeFile = 1;
321 if (count && (vm.count("force-output") == 0))
322 {
323 if (vm.count("nparts") == 0) // do not do check if --nparts is enabled.
324 {
325 writeFile = 0; // set to zero for reduce all to be correct.
326
327 if (comm->GetSpaceComm()->TreatAsRankZero())
328 {
329 string answer;
330 cout << "Did you wish to overwrite " << outFile << " (y/n)? ";
331 getline(cin, answer);
332 if (answer.compare("y") == 0)
333 {
334 writeFile = 1;
335 }
336 else
337 {
338 cout << "Not writing file '" << filename
339 << "' because it already exists" << endl;
340 }
341 }
342 comm->GetSpaceComm()->AllReduce(writeFile, LibUtilities::ReduceSum);
343 }
344 }
345 return (writeFile == 0) ? false : true;
346}
fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
fs::path GetPath(std::string &filename, po::variables_map &vm)
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
CommFactory & GetCommFactory()

References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), Nektar::LibUtilities::GetCommFactory(), GetFullOutName(), GetPath(), Nektar::FieldUtils::Module::m_f, m_prohibitWrite, and Nektar::LibUtilities::ReduceSum.

Referenced by v_Process().

Member Data Documentation

◆ m_equispacedSetup

bool Nektar::FieldUtils::OutputFileBase::m_equispacedSetup = false
protected

Definition at line 103 of file OutputFileBase.h.

Referenced by ConvertExpToEquispaced(), and v_Process().

◆ m_prohibitWrite

bool Nektar::FieldUtils::OutputFileBase::m_prohibitWrite = false
protected

◆ m_requireEquiSpaced

bool Nektar::FieldUtils::OutputFileBase::m_requireEquiSpaced
protected