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(
"RestartFile");
80 if (it == pParams.end())
86 ASSERTL0(it->second.length() > 0,
"Missing parameter 'RestartFile'.");
87 if (it->second.find_last_of(
'.') != std::string::npos)
93 std::stringstream outname;
94 outname << it->second <<
".fld";
100 it = pParams.find(
"OutputFrequency");
101 if (it == pParams.end())
116 it = pParams.find(
"PhaseAverage");
117 if (it == pParams.end())
123 std::string sOption = it->second.c_str();
125 (boost::iequals(sOption,
"yes"));
130 auto itPeriod = pParams.find(
"PhaseAveragePeriod");
131 auto itPhase = pParams.find(
"PhaseAveragePhase");
135 (itPeriod != pParams.end() && itPhase != pParams.end()),
136 "The phase sampling feature requires both 'PhaseAveragePeriod' and "
137 "'PhaseAveragePhase' to be set.");
149 "PhaseAveragePeriod must be greater than 0.");
151 "PhaseAveragePhase must be between 0 and 1.");
154 it = pParams.find(
"SampleFrequency");
155 if (it == pParams.end())
170 if (
m_session->GetComm()->GetRank() == 0 &&
171 m_session->DefinesCmdLineArgument(
"verbose"))
173 std::cout <<
"Phase sampling activated with period "
176 <<
"Sampling within a tolerance of "
189 m_f = std::shared_ptr<Field>(
new Field());
190 std::vector<std::string> modcmds;
192 std::stringstream moduleStream;
193 it = pParams.find(
"Modules");
194 if (it != pParams.end())
196 moduleStream.str(it->second);
198 while (!moduleStream.fail())
201 moduleStream >> sMod;
202 if (!moduleStream.fail())
204 modcmds.push_back(sMod);
212 std::vector<std::string> tmp;
217 it = pParams.find(
"options");
218 if (it != pParams.end())
222 std::vector<char *> argv;
224 strargv =
"dummy " + it->second;
225 strargv.push_back((
char)0);
227 for (
size_t i = 0; strargv[i]; ++i)
229 if (strargv[i] !=
' ' && flag)
231 argv.push_back(&strargv[i]);
235 if (strargv[i] ==
' ')
242 po::options_description desc(
"Available options");
247 "Produce this help message.")
249 "Print the list of available modules.")
250 (
"output-points,n", po::value<int>(),
251 "Output at n equipspaced points along the "
252 "collapsed coordinates (for .dat, .vtu).")
253 (
"output-points-hom-z", po::value<int>(),
254 "Number of planes in the z-direction for output of "
255 "Homogeneous 1D expansion(for .dat, .vtu).")
257 "Write error of fields for regression checking")
259 "Force the output to be written without any checks")
260 (
"range,r", po::value<std::string>(),
261 "Define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) "
262 "in which any vertex is contained.")
264 "Do not use equispaced output.")
265 (
"nparts", po::value<int>(),
266 "Define nparts if running serial problem to mimic "
267 "parallel run with many partitions.")
268 (
"npz", po::value<int>(),
269 "Used to define number of partitions in z for Homogeneous1D "
270 "expansions for parallel runs.")
271 (
"npt", po::value<int>(),
272 "Used to define number of partitions in time for Parareal runs. ")
273 (
"onlyshape", po::value<std::string>(),
274 "Only use element with defined shape type i.e. -onlyshape "
276 (
"part-only", po::value<int>(),
277 "Partition into specified npart partitions and exit")
278 (
"part-only-overlapping", po::value<int>(),
279 "Partition into specified npart overlapping partitions and exit")
280 (
"modules-opt,p", po::value<std::string>(),
281 "Print options for a module.")
282 (
"module,m", po::value<std::vector<std::string> >(),
283 "Specify modules which are to be used.")
284 (
"use-session-variables",
285 "Use variables defined in session for output")
286 (
"use-session-expansion",
287 "Use expansion defined in session.")
289 "Enable verbose mode.");
292 po::options_description hidden(
"Hidden options");
296 (
"input-file", po::value<std::vector<std::string> >(),
300 po::options_description cmdline_options;
301 cmdline_options.add(hidden).add(desc);
303 po::options_description visible(
"Allowed options");
306 po::positional_options_description
p;
307 p.add(
"input-file", -1);
311 po::store(po::command_line_parser(argc, &(argv[0]))
312 .options(cmdline_options)
318 catch (
const std::exception &e)
320 std::cerr << e.what() << std::endl;
324 m_vm.insert(std::make_pair(
"force-output", po::variable_value()));
344 nfield = (n < pFields.size()) ? n : 0;
350 m_fieldMetaData[
"InitialTime"] = boost::lexical_cast<std::string>(time);
356 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
357 std::vector<std::vector<NekDouble>> fieldData;
361 fld->Import(
m_restartFile, fieldDef, fieldData, fieldMetaData);
369 for (k = 0; k < pFields.size(); ++k)
371 if (pFields[k]->GetSession()->GetVariable(k) ==
m_variables[j])
382 for (
int i = 0; i < fieldData.size(); ++i)
384 pFields[nfield]->ExtractDataToCoeffs(
390 if (fieldMetaData.count(
"NumberOfFieldDumps"))
392 m_numSamples = atoi(fieldMetaData[
"NumberOfFieldDumps"].c_str());
399 if (fieldMetaData.count(
"InitialTime"))
405 if (fieldMetaData.count(
"FilterFileNum"))
407 m_outputIndex = atoi(fieldMetaData[
"FilterFileNum"].c_str());
423 int nfield = pFields.size();
425 for (
int n = 0; n < nfield; ++n)
427 m_variables[n] = pFields[n]->GetSession()->GetVariable(n);
431 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
432 for (
int n = 0; n < nfield; ++n)
434 coeffs[n] = pFields[n]->GetCoeffs();
437 auto equ =
m_equ.lock();
438 ASSERTL0(equ,
"Weak pointer expired");
453 int nfield = pFields.size();
454 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
455 for (
int n = 0; n < nfield; ++n)
457 coeffs[n] = pFields[n]->GetCoeffs();
460 auto equ =
m_equ.lock();
461 ASSERTL0(equ,
"Weak pointer expired");
462 equ->ExtraFldOutput(coeffs, variables);
484 if (
m_session->GetComm()->GetRank() == 0 &&
485 m_session->DefinesCmdLineArgument(
"verbose"))
487 std::cout <<
"Sample: " << std::setw(8) << std::left
489 << std::left << currentPhase << std::endl;
543 std::stringstream outname;
550 outname <<
name << suffix << ext;
554 outname <<
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
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)