37#include <boost/algorithm/string/classification.hpp>
38#include <boost/algorithm/string/predicate.hpp>
39#include <boost/algorithm/string/split.hpp>
40#include <boost/program_options.hpp>
50 const std::shared_ptr<EquationSystem> &pEquation,
const ParamMap &pParams)
51 :
Filter(pSession, pEquation)
56 std::string ext =
".fld";
60 auto it = pParams.find(
"OutputStartTime");
61 if (it == pParams.end())
72 it = pParams.find(
"RestartFile");
73 if (it == pParams.end())
79 ASSERTL0(it->second.length() > 0,
"Missing parameter 'RestartFile'.");
80 if (it->second.find_last_of(
'.') != std::string::npos)
86 std::stringstream outname;
87 outname << it->second <<
".fld";
93 it = pParams.find(
"OutputFrequency");
94 if (it == pParams.end())
109 it = pParams.find(
"PhaseAverage");
110 if (it == pParams.end())
116 std::string sOption = it->second.c_str();
118 (boost::iequals(sOption,
"yes"));
123 auto itPeriod = pParams.find(
"PhaseAveragePeriod");
124 auto itPhase = pParams.find(
"PhaseAveragePhase");
128 (itPeriod != pParams.end() && itPhase != pParams.end()),
129 "The phase sampling feature requires both 'PhaseAveragePeriod' and "
130 "'PhaseAveragePhase' to be set.");
142 "PhaseAveragePeriod must be greater than 0.");
144 "PhaseAveragePhase must be between 0 and 1.");
147 it = pParams.find(
"SampleFrequency");
148 if (it == pParams.end())
163 if (
m_session->GetComm()->GetRank() == 0 &&
164 m_session->DefinesCmdLineArgument(
"verbose"))
166 std::cout <<
"Phase sampling activated with period "
169 <<
"Sampling within a tolerance of "
182 m_f = std::shared_ptr<Field>(
new Field());
183 std::vector<std::string> modcmds;
185 std::stringstream moduleStream;
186 it = pParams.find(
"Modules");
187 if (it != pParams.end())
189 moduleStream.str(it->second);
191 while (!moduleStream.fail())
194 moduleStream >> sMod;
195 if (!moduleStream.fail())
197 modcmds.push_back(sMod);
205 std::vector<std::string> tmp;
207 std::string outName = tmp[0];
208 ext = fs::path(outName).extension().string();
212 it = pParams.find(
"options");
213 if (it != pParams.end())
217 std::vector<char *> argv;
219 strargv =
"dummy " + it->second;
220 strargv.push_back((
char)0);
222 for (
size_t i = 0; strargv[i]; ++i)
224 if (strargv[i] !=
' ' && flag)
226 argv.push_back(&strargv[i]);
230 if (strargv[i] ==
' ')
237 po::options_description desc(
"Available options");
242 "Produce this help message.")
244 "Print the list of available modules.")
245 (
"output-points,n", po::value<int>(),
246 "Output at n equipspaced points along the "
247 "collapsed coordinates (for .dat, .vtu).")
248 (
"output-points-hom-z", po::value<int>(),
249 "Number of planes in the z-direction for output of "
250 "Homogeneous 1D expansion(for .dat, .vtu).")
252 "Write error of fields for regression checking")
254 "Force the output to be written without any checks")
255 (
"range,r", po::value<std::string>(),
256 "Define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) "
257 "in which any vertex is contained.")
259 "Do not use equispaced output.")
260 (
"nparts", po::value<int>(),
261 "Define nparts if running serial problem to mimic "
262 "parallel run with many partitions.")
263 (
"npz", po::value<int>(),
264 "Used to define number of partitions in z for Homogeneous1D "
265 "expansions for parallel runs.")
266 (
"npt", po::value<int>(),
267 "Used to define number of partitions in time for Parareal runs. ")
268 (
"onlyshape", po::value<std::string>(),
269 "Only use element with defined shape type i.e. -onlyshape "
271 (
"part-only", po::value<int>(),
272 "Partition into specified npart partitions and exit")
273 (
"part-only-overlapping", po::value<int>(),
274 "Partition into specified npart overlapping partitions and exit")
275 (
"modules-opt,p", po::value<std::string>(),
276 "Print options for a module.")
277 (
"module,m", po::value<std::vector<std::string> >(),
278 "Specify modules which are to be used.")
279 (
"use-session-variables",
280 "Use variables defined in session for output")
281 (
"use-session-expansion",
282 "Use expansion defined in session.")
284 "Enable verbose mode.");
287 po::options_description hidden(
"Hidden options");
291 (
"input-file", po::value<std::vector<std::string> >(),
295 po::options_description cmdline_options;
296 cmdline_options.add(hidden).add(desc);
298 po::options_description visible(
"Allowed options");
301 po::positional_options_description
p;
302 p.add(
"input-file", -1);
306 po::store(po::command_line_parser(argc, &(argv[0]))
307 .options(cmdline_options)
313 catch (
const std::exception &e)
315 std::cerr << e.what() << std::endl;
319 m_vm.insert(std::make_pair(
"force-output", po::variable_value()));
339 nfield = (n < pFields.size()) ? n : 0;
345 m_fieldMetaData[
"InitialTime"] = boost::lexical_cast<std::string>(time);
351 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
352 std::vector<std::vector<NekDouble>> fieldData;
356 fld->Import(
m_restartFile, fieldDef, fieldData, fieldMetaData);
364 for (k = 0; k < pFields.size(); ++k)
366 if (pFields[k]->GetSession()->GetVariable(k) ==
m_variables[j])
377 for (
int i = 0; i < fieldData.size(); ++i)
379 pFields[nfield]->ExtractDataToCoeffs(
385 if (fieldMetaData.count(
"NumberOfFieldDumps"))
387 m_numSamples = atoi(fieldMetaData[
"NumberOfFieldDumps"].c_str());
394 if (fieldMetaData.count(
"InitialTime"))
400 if (fieldMetaData.count(
"FilterFileNum"))
402 m_outputIndex = atoi(fieldMetaData[
"FilterFileNum"].c_str());
418 int nfield = pFields.size();
420 for (
int n = 0; n < nfield; ++n)
422 m_variables[n] = pFields[n]->GetSession()->GetVariable(n);
426 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
427 for (
int n = 0; n < nfield; ++n)
429 coeffs[n] = pFields[n]->GetCoeffs();
432 auto equ =
m_equ.lock();
433 ASSERTL0(equ,
"Weak pointer expired");
450 int nfield = pFields.size();
451 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
452 for (
int n = 0; n < nfield; ++n)
454 coeffs[n] = pFields[n]->GetCoeffs();
457 auto equ =
m_equ.lock();
458 ASSERTL0(equ,
"Weak pointer expired");
459 equ->ExtraFldOutput(coeffs, variables);
481 if (
m_session->GetComm()->GetRank() == 0 &&
482 m_session->DefinesCmdLineArgument(
"verbose"))
484 std::cout <<
"Sample: " << std::setw(8) << std::left
486 << std::left << currentPhase << std::endl;
540 std::stringstream tmpOutname;
549 tmpOutname <<
name << suffix << ext;
553 tmpOutname <<
name <<
"_" << dump << suffix << ext;
562 for (
int i = 0; i <
m_modules.size(); ++i)
564 if (
m_modules[i]->GetModulePriority() == priority)
591 for (
int i = 0; i < modcmds.size(); ++i)
594 std::vector<std::string> tmp1;
598 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
600 if (i == modcmds.size() - 1)
611 if (tmp1.size() == 1)
613 int dot = tmp1[0].find_last_of(
'.') + 1;
614 std::string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
616 tmp1.push_back(std::string(
"outfile=") + tmp1[0]);
620 module.second = tmp1[1];
621 tmp1.push_back(std::string(
"outfile=") + tmp1[0]);
628 module.second = tmp1[0];
637 for (
int j = offset; j < tmp1.size(); ++j)
639 std::vector<std::string> tmp2;
640 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
642 if (tmp2.size() == 1)
644 mod->RegisterConfig(tmp2[0]);
646 else if (tmp2.size() == 2)
648 mod->RegisterConfig(tmp2[0], tmp2[1]);
652 std::cerr <<
"ERROR: Invalid module configuration: format is "
653 <<
"either :arg or :arg=val" << std::endl;
664 for (
int i = 0; i <
m_modules.size(); ++i)
666 ++modulesCount[
m_modules[i]->GetModulePriority()];
674 module.second = std::string(
"equispacedoutput");
689 m_f->m_graph = pFields[0]->GetGraph();
690 m_f->m_comm =
m_f->m_session->GetComm();
694 m_f->m_numHomogeneousDir = 0;
697 m_f->m_numHomogeneousDir = 1;
701 m_f->m_numHomogeneousDir = 2;
705 m_f->m_exp[0] = pFields[0];
710 nfield = (n < pFields.size()) ? n : 0;
714 m_f->m_exp[n]->SetWaveSpace(
false);
717 "pFields[nfield] does not have the "
718 "same number of coefficients as m_outFields[n]");
720 m_f->m_exp[n]->ExtractCoeffsToCoeffs(pFields[nfield],
m_outFields[n],
721 m_f->m_exp[n]->UpdateCoeffs());
723 m_f->m_exp[n]->BwdTrans(
m_f->m_exp[n]->GetCoeffs(),
724 m_f->m_exp[n]->UpdatePhys());
734 for (
int i = 0; i < modules.size(); ++i)
736 ++modulesCount[modules[i]->GetModulePriority()];
746 std::stringstream ss;
748 for (
int i = 0; i < modules.size(); ++i)
753 modules[i]->GetModulePriority() ==
eCreateExp ||
754 modules[i]->GetModulePriority() ==
eFillExp ||
755 modules[i]->GetModulePriority() ==
eCreatePts)
757 ss << modules[i]->GetModuleName() <<
" ";
760 ss <<
"not compatible with FilterFieldConvert.";
768 std::stringstream ss;
770 for (
int i = 0; i < modules.size(); ++i)
774 ss << modules[i]->GetModuleName() <<
" ";
777 ss <<
"is not compatible with module(s): ";
778 for (
int i = 0; i < modules.size(); ++i)
782 ss << modules[i]->GetModuleName() <<
" ";
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
NekDouble Evaluate() const
static std::shared_ptr< FieldIO > CreateForFile(const LibUtilities::SessionReaderSharedPtr session, const std::string &filename)
Construct a FieldIO object for a given input filename.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
SOLVER_UTILS_EXPORT bool v_IsTimeDependent() override
virtual SOLVER_UTILS_EXPORT void v_ProcessSample(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, std::vector< Array< OneD, NekDouble > > &fieldcoeffs, const NekDouble &time)
std::string m_restartFile
static std::string className
Name of the class.
void CreateFields(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields)
unsigned int m_outputFrequency
unsigned int m_sampleFrequency
std::vector< std::string > m_variables
void CheckModules(std::vector< ModuleSharedPtr > &modules)
SOLVER_UTILS_EXPORT void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
NekDouble m_phaseTolerance
unsigned int m_numSamples
SOLVER_UTILS_EXPORT void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
virtual SOLVER_UTILS_EXPORT void v_FillVariablesName(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields)
virtual SOLVER_UTILS_EXPORT void v_PrepareOutput(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
SOLVER_UTILS_EXPORT ~FilterFieldConvert() override
void CreateModules(std::vector< std::string > &modcmds)
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation, const std::map< std::string, std::string > &pParams)
Creates an instance of this class.
SOLVER_UTILS_EXPORT FilterFieldConvert(const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
void OutputField(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, int dump=-1)
LibUtilities::FieldMetaDataMap m_fieldMetaData
NekDouble m_phaseSamplePeriod
NekDouble m_outputStartTime
std::vector< Array< OneD, NekDouble > > m_outFields
virtual SOLVER_UTILS_EXPORT NekDouble v_GetScale()
unsigned int m_outputIndex
virtual SOLVER_UTILS_EXPORT std::string v_GetFileSuffix()
NekDouble m_phaseSamplePhase
std::vector< ModuleSharedPtr > m_modules
SOLVER_UTILS_EXPORT void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
SOLVER_UTILS_EXPORT std::string SetupOutput(const std::string ext, const ParamMap &pParams)
LibUtilities::SessionReaderSharedPtr m_session
const std::weak_ptr< EquationSystem > m_equ
std::map< std::string, std::string > ParamMap
std::pair< ModuleType, std::string > ModuleKey
std::shared_ptr< Module > ModuleSharedPtr
ModuleFactory & GetModuleFactory()
std::shared_ptr< FieldIO > FieldIOSharedPtr
std::map< std::string, std::string > FieldMetaDataMap
std::shared_ptr< SessionReader > SessionReaderSharedPtr
static PtsFieldSharedPtr NullPtsField
FilterFactory & GetFilterFactory()
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)