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(
"OutputFrequency");
73 if (it == pParams.end())
84 it = pParams.find(
"RestartFile");
85 if (it == pParams.end())
91 ASSERTL0(it->second.length() > 0,
"Missing parameter 'RestartFile'.");
92 if (it->second.find_last_of(
'.') != std::string::npos)
98 std::stringstream outname;
99 outname << it->second <<
".fld";
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()));
334 nfield = (n < pFields.size()) ? n : 0;
340 m_fieldMetaData[
"InitialTime"] = boost::lexical_cast<std::string>(time);
346 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
347 std::vector<std::vector<NekDouble>> fieldData;
351 fld->Import(
m_restartFile, fieldDef, fieldData, fieldMetaData);
359 for (k = 0; k < pFields.size(); ++k)
361 if (pFields[k]->GetSession()->GetVariable(k) ==
m_variables[j])
372 for (
int i = 0; i < fieldData.size(); ++i)
374 pFields[nfield]->ExtractDataToCoeffs(
380 if (fieldMetaData.count(
"NumberOfFieldDumps"))
382 m_numSamples = atoi(fieldMetaData[
"NumberOfFieldDumps"].c_str());
389 if (fieldMetaData.count(
"InitialTime"))
395 if (fieldMetaData.count(
"FilterFileNum"))
397 m_outputIndex = atoi(fieldMetaData[
"FilterFileNum"].c_str());
413 int nfield = pFields.size();
415 for (
int n = 0; n < nfield; ++n)
417 m_variables[n] = pFields[n]->GetSession()->GetVariable(n);
421 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
422 for (
int n = 0; n < nfield; ++n)
424 coeffs[n] = pFields[n]->GetCoeffs();
427 auto equ =
m_equ.lock();
428 ASSERTL0(equ,
"Weak pointer expired");
445 int nfield = pFields.size();
446 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
447 for (
int n = 0; n < nfield; ++n)
449 coeffs[n] = pFields[n]->GetCoeffs();
452 auto equ =
m_equ.lock();
453 ASSERTL0(equ,
"Weak pointer expired");
454 equ->ExtraFldOutput(coeffs, variables);
476 if (
m_session->GetComm()->GetRank() == 0 &&
477 m_session->DefinesCmdLineArgument(
"verbose"))
479 std::cout <<
"Sample: " << std::setw(8) << std::left
481 << std::left << currentPhase << std::endl;
535 std::stringstream tmpOutname;
544 tmpOutname << name << suffix << ext;
548 tmpOutname << name <<
"_" << dump << suffix << ext;
557 for (
int i = 0; i <
m_modules.size(); ++i)
559 if (
m_modules[i]->GetModulePriority() == priority)
586 for (
int i = 0; i < modcmds.size(); ++i)
589 std::vector<std::string> tmp1;
593 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
595 if (i == modcmds.size() - 1)
597 module.first = eOutputModule;
606 if (tmp1.size() == 1)
608 int dot = tmp1[0].find_last_of(
'.') + 1;
609 std::string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
611 tmp1.push_back(std::string(
"outfile=") + tmp1[0]);
615 module.second = tmp1[1];
616 tmp1.push_back(std::string(
"outfile=") + tmp1[0]);
622 module.first = eProcessModule;
623 module.second = tmp1[0];
632 for (
int j = offset; j < tmp1.size(); ++j)
634 std::vector<std::string> tmp2;
635 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
637 if (tmp2.size() == 1)
639 mod->RegisterConfig(tmp2[0]);
641 else if (tmp2.size() == 2)
643 mod->RegisterConfig(tmp2[0], tmp2[1]);
647 std::cerr <<
"ERROR: Invalid module configuration: format is "
648 <<
"either :arg or :arg=val" << std::endl;
659 for (
int i = 0; i <
m_modules.size(); ++i)
661 ++modulesCount[
m_modules[i]->GetModulePriority()];
668 module.first = eProcessModule;
669 module.second = std::string("equispacedoutput");
684 m_f->m_graph = pFields[0]->GetGraph();
685 m_f->m_comm =
m_f->m_session->GetComm();
689 m_f->m_numHomogeneousDir = 0;
692 m_f->m_numHomogeneousDir = 1;
696 m_f->m_numHomogeneousDir = 2;
700 m_f->m_exp[0] = pFields[0];
705 nfield = (n < pFields.size()) ? n : 0;
709 m_f->m_exp[n]->SetWaveSpace(
false);
712 "pFields[nfield] does not have the "
713 "same number of coefficients as m_outFields[n]");
715 m_f->m_exp[n]->ExtractCoeffsToCoeffs(pFields[nfield],
m_outFields[n],
716 m_f->m_exp[n]->UpdateCoeffs());
718 m_f->m_exp[n]->BwdTrans(
m_f->m_exp[n]->GetCoeffs(),
719 m_f->m_exp[n]->UpdatePhys());
729 for (
int i = 0; i < modules.size(); ++i)
731 ++modulesCount[modules[i]->GetModulePriority()];
741 std::stringstream ss;
743 for (
int i = 0; i < modules.size(); ++i)
748 modules[i]->GetModulePriority() ==
eCreateExp ||
749 modules[i]->GetModulePriority() ==
eFillExp ||
750 modules[i]->GetModulePriority() ==
eCreatePts)
752 ss << modules[i]->GetModuleName() <<
" ";
755 ss <<
"not compatible with FilterFieldConvert.";
763 std::stringstream ss;
765 for (
int i = 0; i < modules.size(); ++i)
769 ss << modules[i]->GetModuleName() <<
" ";
772 ss <<
"is not compatible with module(s): ";
773 for (
int i = 0; i < modules.size(); ++i)
777 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.
SOLVER_UTILS_EXPORT 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)
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)
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 void v_OutputField(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, int dump=-1)
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)