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 auto it = pParams.find(
"OutputFile");
57 if (it == pParams.end())
59 std::stringstream outname;
60 outname <<
m_session->GetSessionName() <<
".fld";
65 ASSERTL0(it->second.length() > 0,
"Missing parameter 'OutputFile'.");
66 if (it->second.find_last_of(
'.') != std::string::npos)
72 std::stringstream outname;
73 outname << it->second <<
".fld";
79 it = pParams.find(
"OutputStartTime");
80 if (it == pParams.end())
91 it = pParams.find(
"RestartFile");
92 if (it == pParams.end())
98 ASSERTL0(it->second.length() > 0,
"Missing parameter 'RestartFile'.");
99 if (it->second.find_last_of(
'.') != std::string::npos)
105 std::stringstream outname;
106 outname << it->second <<
".fld";
112 it = pParams.find(
"OutputFrequency");
113 if (it == pParams.end())
128 it = pParams.find(
"PhaseAverage");
129 if (it == pParams.end())
135 std::string sOption = it->second.c_str();
137 (boost::iequals(sOption,
"yes"));
142 auto itPeriod = pParams.find(
"PhaseAveragePeriod");
143 auto itPhase = pParams.find(
"PhaseAveragePhase");
147 (itPeriod != pParams.end() && itPhase != pParams.end()),
148 "The phase sampling feature requires both 'PhaseAveragePeriod' and "
149 "'PhaseAveragePhase' to be set.");
161 "PhaseAveragePeriod must be greater than 0.");
163 "PhaseAveragePhase must be between 0 and 1.");
166 it = pParams.find(
"SampleFrequency");
167 if (it == pParams.end())
182 if (
m_session->GetComm()->GetRank() == 0 &&
183 m_session->DefinesCmdLineArgument(
"verbose"))
185 std::cout <<
"Phase sampling activated with period "
188 <<
"Sampling within a tolerance of "
201 m_f = std::shared_ptr<Field>(
new Field());
202 std::vector<std::string> modcmds;
204 std::stringstream moduleStream;
205 it = pParams.find(
"Modules");
206 if (it != pParams.end())
208 moduleStream.str(it->second);
210 while (!moduleStream.fail())
213 moduleStream >> sMod;
214 if (!moduleStream.fail())
216 modcmds.push_back(sMod);
224 std::vector<std::string> tmp;
229 it = pParams.find(
"options");
230 if (it != pParams.end())
234 std::vector<char *> argv;
236 strargv =
"dummy " + it->second;
237 strargv.push_back((
char)0);
239 for (
size_t i = 0; strargv[i]; ++i)
241 if (strargv[i] !=
' ' && flag)
243 argv.push_back(&strargv[i]);
247 if (strargv[i] ==
' ')
254 po::options_description desc(
"Available options");
259 "Produce this help message.")
261 "Print the list of available modules.")
262 (
"output-points,n", po::value<int>(),
263 "Output at n equipspaced points along the "
264 "collapsed coordinates (for .dat, .vtu).")
265 (
"output-points-hom-z", po::value<int>(),
266 "Number of planes in the z-direction for output of "
267 "Homogeneous 1D expansion(for .dat, .vtu).")
269 "Write error of fields for regression checking")
271 "Force the output to be written without any checks")
272 (
"range,r", po::value<std::string>(),
273 "Define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) "
274 "in which any vertex is contained.")
276 "Do not use equispaced output.")
277 (
"nparts", po::value<int>(),
278 "Define nparts if running serial problem to mimic "
279 "parallel run with many partitions.")
280 (
"npz", po::value<int>(),
281 "Used to define number of partitions in z for Homogeneous1D "
282 "expansions for parallel runs.")
283 (
"npt", po::value<int>(),
284 "Used to define number of partitions in time for Parareal runs. ")
285 (
"onlyshape", po::value<std::string>(),
286 "Only use element with defined shape type i.e. -onlyshape "
288 (
"part-only", po::value<int>(),
289 "Partition into specified npart partitions and exit")
290 (
"part-only-overlapping", po::value<int>(),
291 "Partition into specified npart overlapping partitions and exit")
292 (
"modules-opt,p", po::value<std::string>(),
293 "Print options for a module.")
294 (
"module,m", po::value<std::vector<std::string> >(),
295 "Specify modules which are to be used.")
296 (
"use-session-variables",
297 "Use variables defined in session for output")
298 (
"use-session-expansion",
299 "Use expansion defined in session.")
301 "Enable verbose mode.");
304 po::options_description hidden(
"Hidden options");
308 (
"input-file", po::value<std::vector<std::string> >(),
312 po::options_description cmdline_options;
313 cmdline_options.add(hidden).add(desc);
315 po::options_description visible(
"Allowed options");
318 po::positional_options_description
p;
319 p.add(
"input-file", -1);
323 po::store(po::command_line_parser(argc, &(argv[0]))
324 .options(cmdline_options)
330 catch (
const std::exception &e)
332 std::cerr << e.what() << std::endl;
336 m_vm.insert(std::make_pair(
"force-output", po::variable_value()));
356 nfield = (n < pFields.size()) ? n : 0;
362 m_fieldMetaData[
"InitialTime"] = boost::lexical_cast<std::string>(time);
368 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
369 std::vector<std::vector<NekDouble>> fieldData;
373 fld->Import(
m_restartFile, fieldDef, fieldData, fieldMetaData);
381 for (k = 0; k < pFields.size(); ++k)
383 if (pFields[k]->GetSession()->GetVariable(k) ==
m_variables[j])
394 for (
int i = 0; i < fieldData.size(); ++i)
396 pFields[nfield]->ExtractDataToCoeffs(
402 if (fieldMetaData.count(
"NumberOfFieldDumps"))
404 m_numSamples = atoi(fieldMetaData[
"NumberOfFieldDumps"].c_str());
411 if (fieldMetaData.count(
"InitialTime"))
417 if (fieldMetaData.count(
"FilterFileNum"))
419 m_outputIndex = atoi(fieldMetaData[
"FilterFileNum"].c_str());
435 int nfield = pFields.size();
437 for (
int n = 0; n < nfield; ++n)
439 m_variables[n] = pFields[n]->GetSession()->GetVariable(n);
443 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
444 for (
int n = 0; n < nfield; ++n)
446 coeffs[n] = pFields[n]->GetCoeffs();
449 auto equ =
m_equ.lock();
450 ASSERTL0(equ,
"Weak pointer expired");
466 int nfield = pFields.size();
467 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
468 for (
int n = 0; n < nfield; ++n)
470 coeffs[n] = pFields[n]->GetCoeffs();
473 auto equ =
m_equ.lock();
474 ASSERTL0(equ,
"Weak pointer expired");
475 equ->ExtraFldOutput(coeffs, variables);
497 if (
m_session->GetComm()->GetRank() == 0 &&
498 m_session->DefinesCmdLineArgument(
"verbose"))
500 std::cout <<
"Sample: " << std::setw(8) << std::left
502 << std::left << currentPhase << std::endl;
556 std::stringstream outname;
563 outname <<
name << suffix << ext;
567 outname <<
name <<
"_" << dump << suffix << ext;
575 for (
int i = 0; i <
m_modules.size(); ++i)
577 if (
m_modules[i]->GetModulePriority() == priority)
604 for (
int i = 0; i < modcmds.size(); ++i)
607 std::vector<std::string> tmp1;
611 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
613 if (i == modcmds.size() - 1)
624 if (tmp1.size() == 1)
626 int dot = tmp1[0].find_last_of(
'.') + 1;
627 std::string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
629 tmp1.push_back(std::string(
"outfile=") + tmp1[0]);
633 module.second = tmp1[1];
634 tmp1.push_back(std::string(
"outfile=") + tmp1[0]);
641 module.second = tmp1[0];
650 for (
int j = offset; j < tmp1.size(); ++j)
652 std::vector<std::string> tmp2;
653 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
655 if (tmp2.size() == 1)
657 mod->RegisterConfig(tmp2[0]);
659 else if (tmp2.size() == 2)
661 mod->RegisterConfig(tmp2[0], tmp2[1]);
665 std::cerr <<
"ERROR: Invalid module configuration: format is "
666 <<
"either :arg or :arg=val" << std::endl;
677 for (
int i = 0; i <
m_modules.size(); ++i)
679 ++modulesCount[
m_modules[i]->GetModulePriority()];
687 module.second = std::string(
"equispacedoutput");
702 m_f->m_graph = pFields[0]->GetGraph();
703 m_f->m_comm =
m_f->m_session->GetComm();
707 m_f->m_numHomogeneousDir = 0;
710 m_f->m_numHomogeneousDir = 1;
714 m_f->m_numHomogeneousDir = 2;
718 m_f->m_exp[0] = pFields[0];
723 nfield = (n < pFields.size()) ? n : 0;
727 m_f->m_exp[n]->SetWaveSpace(
false);
730 "pFields[nfield] does not have the "
731 "same number of coefficients as m_outFields[n]");
733 m_f->m_exp[n]->ExtractCoeffsToCoeffs(pFields[nfield],
m_outFields[n],
734 m_f->m_exp[n]->UpdateCoeffs());
736 m_f->m_exp[n]->BwdTrans(
m_f->m_exp[n]->GetCoeffs(),
737 m_f->m_exp[n]->UpdatePhys());
747 for (
int i = 0; i < modules.size(); ++i)
749 ++modulesCount[modules[i]->GetModulePriority()];
759 std::stringstream ss;
761 for (
int i = 0; i < modules.size(); ++i)
766 modules[i]->GetModulePriority() ==
eCreateExp ||
767 modules[i]->GetModulePriority() ==
eFillExp ||
768 modules[i]->GetModulePriority() ==
eCreatePts)
770 ss << modules[i]->GetModuleName() <<
" ";
773 ss <<
"not compatible with FilterFieldConvert.";
781 std::stringstream ss;
783 for (
int i = 0; i < modules.size(); ++i)
787 ss << modules[i]->GetModuleName() <<
" ";
790 ss <<
"is not compatible with module(s): ";
791 for (
int i = 0; i < modules.size(); ++i)
795 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
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)