Nektar++
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. More...
 
- 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. More...
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
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. More...
 
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. More...
 
virtual void v_OutputFromExp (po::variables_map &vm)=0
 Write from m_exp to output file. More...
 
virtual void v_OutputFromData (po::variables_map &vm)=0
 Write from data to output file. More...
 
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 void v_Process (po::variables_map &vm)
 
virtual std::string v_GetModuleName ()
 
virtual std::string v_GetModuleDescription ()
 
virtual ModulePriority v_GetModulePriority ()
 
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. More...
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 
std::set< std::string > m_allowedFiles
 List of allowed file formats. More...
 

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. More...
 

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 47 of file OutputFileBase.cpp.

47 : OutputModule(f)
48{
49 m_requireEquiSpaced = false;
50 m_prohibitWrite = false;
51 m_config["writemultiplefiles"] = ConfigOption(
52 true, "0",
53 "Write multiple files in parallel or when using nparts option");
54}
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 56 of file OutputFileBase.cpp.

57{
58}

Member Function Documentation

◆ ConvertExpToEquispaced()

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

Definition at line 316 of file OutputFileBase.cpp.

317{
318 // Information to create new expansion
319 int numFields = m_f->m_exp.size();
320 m_f->m_fielddef = m_f->m_exp[0]->GetFieldDefinitions();
321
322 // Set points to equispaced
323 int nPointsNew = 0;
324 if (vm.count("output-points"))
325 {
326 nPointsNew = vm["output-points"].as<int>();
327 }
328 m_f->m_graph->SetExpansionInfoToEvenlySpacedPoints(nPointsNew);
329
330 // Save original expansion
331 vector<MultiRegions::ExpListSharedPtr> expOld = m_f->m_exp;
332
333 // Create new expansion
334 m_f->m_exp[0] = m_f->SetUpFirstExpList(m_f->m_numHomogeneousDir, true);
335 for (int i = 1; i < numFields; ++i)
336 {
337 m_f->m_exp[i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
338 }
339
340 // Extract result to new expansion
341 for (int i = 0; i < numFields; ++i)
342 {
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());
347 }
348
349 // Extract boundary expansion if needed
350 if (m_f->m_writeBndFld)
351 {
352 Array<OneD, const MultiRegions::ExpListSharedPtr> BndExpOld;
354
355 for (int i = 0; i < numFields; ++i)
356 {
357 BndExpOld = expOld[i]->GetBndCondExpansions();
358 for (int j = 0; j < BndExpOld.size(); ++j)
359 {
360 BndExp = m_f->m_exp[i]->UpdateBndCondExpansion(j);
361 BndExp->ExtractCoeffsToCoeffs(BndExpOld[j],
362 BndExpOld[j]->GetCoeffs(),
363 BndExp->UpdateCoeffs());
364 }
365 }
366 }
367
368 m_f->m_fielddef = std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
369
370 // Make a note so that we know that the fielddefs have now been setup.
371 m_equispacedSetup = true;
372}
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 419 of file OutputFileBase.cpp.

420{
421 int coordim =
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"};
425
426 // Set up storage for coordinates
427 Array<OneD, Array<OneD, NekDouble>> coords(coordim);
428 for (int i = 0; i < coordim; ++i)
429 {
430 coords[i] = Array<OneD, NekDouble>(totpoints);
431 }
432
433 // Get coordinates
434 if (coordim == 1)
435 {
436 m_f->m_exp[0]->GetCoords(coords[0]);
437 }
438 else if (coordim == 2)
439 {
440 m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
441 }
442 else
443 {
444 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
445 }
446
447 for (int j = 0; j < coordim; ++j)
448 {
449 NekDouble l2err = m_f->m_exp[0]->L2(coords[j]);
450 NekDouble linferr = m_f->m_exp[0]->Linf(coords[j]);
451
452 if (m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
453 {
454 cout << "L 2 error (variable " << coordVars[j] << ") : " << l2err
455 << endl;
456
457 cout << "L inf error (variable " << coordVars[j]
458 << ") : " << linferr << endl;
459 }
460 }
461
462 for (int j = 0; j < m_f->m_exp.size(); ++j)
463 {
464 NekDouble l2err = m_f->m_exp[j]->L2(m_f->m_exp[j]->GetPhys());
465 NekDouble linferr = m_f->m_exp[j]->Linf(m_f->m_exp[j]->GetPhys());
466
467 if (m_f->m_comm->GetSpaceComm()->TreatAsRankZero() &&
468 m_f->m_variables.size() > 0)
469 {
470 cout << "L 2 error (variable " << m_f->m_variables[j]
471 << ") : " << l2err << endl;
472
473 cout << "L inf error (variable " << m_f->m_variables[j]
474 << ") : " << linferr << endl;
475 }
476 }
477}
double NekDouble

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

Referenced by v_Process().

◆ PrintErrorFromPts()

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

Definition at line 374 of file OutputFileBase.cpp.

375{
376 int coordim = m_f->m_fieldPts->GetDim();
377 std::string coordVars[] = {"x", "y", "z"};
378
379 vector<string> variables = m_f->m_variables;
380 variables.insert(variables.begin(), coordVars, coordVars + coordim);
381 // Get fields and coordinates
382 Array<OneD, Array<OneD, NekDouble>> fields(variables.size());
383
384 // We can just grab everything from points. This should be a
385 // reference, not a copy.
386 m_f->m_fieldPts->GetPts(fields);
387 for (int i = 0; i < fields.size(); ++i)
388 {
389 // calculate L2 and Linf value
390 int npts = fields[i].size();
391
392 NekDouble l2err = 0.0;
393 NekDouble linferr = 0.0;
394 for (int j = 0; j < npts; ++j)
395 {
396 l2err += fields[i][j] * fields[i][j];
397 linferr = max(linferr, fabs(fields[i][j]));
398 }
399
400 m_f->m_comm->GetSpaceComm()->AllReduce(l2err, LibUtilities::ReduceSum);
401 m_f->m_comm->GetSpaceComm()->AllReduce(npts, LibUtilities::ReduceSum);
402 m_f->m_comm->GetSpaceComm()->AllReduce(linferr,
404
405 l2err /= npts;
406 l2err = sqrt(l2err);
407
408 if (m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
409 {
410 cout << "L 2 error (variable " << variables[i] << ") : " << l2err
411 << endl;
412
413 cout << "L inf error (variable " << variables[i]
414 << ") : " << linferr << endl;
415 }
416 }
417}
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294

References Nektar::FieldUtils::Module::m_f, 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...
Definition: ErrorUtil.hpp:202

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 60 of file OutputFileBase.cpp.

61{
62 m_f->SetUpExp(vm);
63
64 string filename = m_config["outfile"].as<string>();
65
66 if (filename == "")
67 {
68 m_prohibitWrite = true;
69 }
70
71 if (m_f->m_fieldPts != LibUtilities::NullPtsField)
72 {
73 ASSERTL0(!m_f->m_writeBndFld, "Boundary can't be obtained from pts.");
74 if (WriteFile(filename, vm))
75 {
77
78 if (vm.count("error"))
79 {
81 }
82 }
83 }
84 else if (m_f->m_exp.size())
85 {
86 // reset expansion definition to use equispaced points if required.
87 if (m_requireEquiSpaced && (vm.count("no-equispaced") == 0) &&
88 m_f->m_exp[0]->GetNumElmts() != 0 && !m_equispacedSetup)
89 {
91 }
92 if (m_f->m_writeBndFld)
93 {
94 if (m_f->m_verbose &&
95 m_f->m_comm->GetSpaceComm()->TreatAsRankZero())
96 {
97 cout << "\t" << GetModuleName()
98 << ": Writing boundary file(s): ";
99 for (int i = 0; i < m_f->m_bndRegionsToWrite.size(); ++i)
100 {
101 cout << m_f->m_bndRegionsToWrite[i];
102 if (i < m_f->m_bndRegionsToWrite.size() - 1)
103 {
104 cout << ", ";
105 }
106 }
107 cout << endl;
108 }
109
110 int nfields = m_f->m_variables.size();
111 int normdim = m_f->m_graph->GetMeshDimension();
112
113 // Prepare for normals output
114 if (m_f->m_addNormals)
115 {
116 // Prepare for creating expansions for normals
117 m_f->m_exp.resize(nfields + normdim);
118
119 // Include normal name in m_variables
120 string normstr[3] = {"Norm_x", "Norm_y", "Norm_z"};
121 for (int j = 0; j < normdim; ++j)
122 {
123 m_f->m_exp[nfields + j] =
124 m_f->AppendExpList(m_f->m_numHomogeneousDir);
125 m_f->m_variables.push_back(normstr[j]);
126 }
127 }
128
129 // Move m_exp to a new expansion vector
130 vector<MultiRegions::ExpListSharedPtr> exp(m_f->m_exp.size());
131 exp.swap(m_f->m_exp);
132
133 Array<OneD, Array<OneD, const MultiRegions::ExpListSharedPtr>>
134 BndExp(exp.size());
135 for (int i = 0; i < exp.size(); ++i)
136 {
137 BndExp[i] = exp[i]->GetBndCondExpansions();
138 }
139
140 // get hold of partition boundary regions so we can match it to
141 // desired region extraction
142 SpatialDomains::BoundaryConditions bcs(m_f->m_session,
143 exp[0]->GetGraph());
145 bcs.GetBoundaryRegions();
146 map<int, int> BndRegionMap;
147 map<int, LibUtilities::CommSharedPtr> BndRegionComm;
148 int cnt = 0;
149 for (auto &breg_it : bregions)
150 {
151 BndRegionMap[breg_it.first] = cnt++;
152 BndRegionComm[breg_it.first] =
153 bcs.GetBoundaryCommunicators()[breg_it.first];
154 }
155
156 // find ending of output file and insert _b1, _b2
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);
160
161 // Store temporary communicator
162 LibUtilities::CommSharedPtr tmpComm = m_f->m_comm;
163
164 for (int i = 0; i < m_f->m_bndRegionsToWrite.size(); ++i)
165 {
166 string outname =
167 name + "_b" +
168 boost::lexical_cast<string>(m_f->m_bndRegionsToWrite[i]) +
169 "." + ext;
170
171 if (!WriteFile(outname, vm))
172 {
173 continue;
174 }
175 RegisterConfig("outfile", outname);
176
177 if (BndRegionMap.count(m_f->m_bndRegionsToWrite[i]) == 1)
178 {
179 m_f->m_comm = BndRegionComm[m_f->m_bndRegionsToWrite[i]];
180
181 int Border = BndRegionMap[m_f->m_bndRegionsToWrite[i]];
182
183 // set up m_exp to point to boundary expansion
184 for (int j = 0; j < exp.size(); ++j)
185 {
186 m_f->m_exp[j] = BndExp[j][Border];
187 }
188
189 for (int j = 0; j < exp.size(); ++j)
190 {
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());
194 }
195
196 if (m_f->m_addNormals)
197 {
198 // Get normals
199 Array<OneD, Array<OneD, NekDouble>> NormPhys;
200 exp[0]->GetBoundaryNormals(Border, NormPhys);
201
202 // add normal coefficients to expansions
203 for (int j = 0; j < normdim; ++j)
204 {
205 m_f->m_exp[nfields + j] =
206 BndExp[nfields + j][Border];
208 m_f->m_exp[nfields + j]->GetTotPoints(),
209 NormPhys[j], 1,
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());
214 }
215 }
216 v_OutputFromExp(vm);
217 // output error for regression checking.
218 if (vm.count("error"))
219 {
221 }
222
223 // Reset communicator
224 m_f->m_comm = tmpComm;
225 }
226
227 // put outfile back to filename in case of nparts option
228 RegisterConfig("outfile", filename);
229 }
230 // Restore m_exp
231 exp.swap(m_f->m_exp);
232 }
233 else
234 {
235 if (WriteFile(filename, vm))
236 {
237 v_OutputFromExp(vm);
238 // output error for regression checking.
239 if (vm.count("error"))
240 {
242 }
243 }
244 }
245 }
246 else if (m_f->m_data.size())
247 {
248 ASSERTL0(!m_f->m_writeBndFld, "Boundary extraction requires xml file.");
249 if (WriteFile(filename, vm))
250 {
252 }
253 }
254}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
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 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:210
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825

References ASSERTL0, ConvertExpToEquispaced(), 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, CellMLToNektar.pycml::name, 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 256 of file OutputFileBase.cpp.

257{
258 if (m_prohibitWrite)
259 {
260 return true;
261 }
262
263 // Get path to file. If procid was defined, get the full name to avoid
264 // checking files from other partitions
265 fs::path outFile;
266 if (vm.count("nparts"))
267 {
268 outFile = GetFullOutName(filename, vm);
269 }
270 else
271 {
272 outFile = GetPath(filename, vm);
273 }
274
276 if (m_f->m_comm)
277 {
278 comm = m_f->m_comm;
279 }
280 else
281 {
282 comm = LibUtilities::GetCommFactory().CreateInstance("Serial", 0, 0);
283 }
284
285 int count = fs::exists(outFile) ? 1 : 0;
286 comm->GetSpaceComm()->AllReduce(count, LibUtilities::ReduceSum);
287
288 int writeFile = 1;
289 if (count && (vm.count("force-output") == 0))
290 {
291 if (vm.count("nparts") == 0) // do not do check if --nparts is enabled.
292 {
293 writeFile = 0; // set to zero for reduce all to be correct.
294
295 if (comm->GetSpaceComm()->TreatAsRankZero())
296 {
297 string answer;
298 cout << "Did you wish to overwrite " << outFile << " (y/n)? ";
299 getline(cin, answer);
300 if (answer.compare("y") == 0)
301 {
302 writeFile = 1;
303 }
304 else
305 {
306 cout << "Not writing file '" << filename
307 << "' because it already exists" << endl;
308 }
309 }
310 comm->GetSpaceComm()->AllReduce(writeFile, LibUtilities::ReduceSum);
311 }
312 }
313 return (writeFile == 0) ? false : true;
314}
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 CellMLToNektar.enum::answer, 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