37#include <boost/algorithm/string/classification.hpp>
38#include <boost/algorithm/string/predicate.hpp>
39#include <boost/algorithm/string/split.hpp>
40#include <boost/core/ignore_unused.hpp>
41#include <boost/program_options.hpp>
53 const std::weak_ptr<EquationSystem> &pEquation,
const ParamMap &pParams)
54 :
Filter(pSession, pEquation)
59 auto it = pParams.find(
"OutputFile");
60 if (it == pParams.end())
62 std::stringstream outname;
63 outname <<
m_session->GetSessionName() <<
".fld";
68 ASSERTL0(it->second.length() > 0,
"Missing parameter 'OutputFile'.");
69 if (it->second.find_last_of(
'.') != std::string::npos)
75 std::stringstream outname;
76 outname << it->second <<
".fld";
82 it = pParams.find(
"RestartFile");
83 if (it == pParams.end())
89 ASSERTL0(it->second.length() > 0,
"Missing parameter 'RestartFile'.");
90 if (it->second.find_last_of(
'.') != std::string::npos)
96 std::stringstream outname;
97 outname << it->second <<
".fld";
103 it = pParams.find(
"OutputFrequency");
104 if (it == pParams.end())
119 it = pParams.find(
"PhaseAverage");
120 if (it == pParams.end())
126 std::string sOption = it->second.c_str();
128 (boost::iequals(sOption,
"yes"));
133 auto itPeriod = pParams.find(
"PhaseAveragePeriod");
134 auto itPhase = pParams.find(
"PhaseAveragePhase");
138 (itPeriod != pParams.end() && itPhase != pParams.end()),
139 "The phase sampling feature requires both 'PhaseAveragePeriod' and "
140 "'PhaseAveragePhase' to be set.");
152 "PhaseAveragePeriod must be greater than 0.");
154 "PhaseAveragePhase must be between 0 and 1.");
157 it = pParams.find(
"SampleFrequency");
158 if (it == pParams.end())
173 if (
m_session->GetComm()->GetRank() == 0 &&
174 m_session->DefinesCmdLineArgument(
"verbose"))
176 std::cout <<
"Phase sampling activated with period "
179 <<
"Sampling within a tolerance of "
192 m_f = std::shared_ptr<Field>(
new Field());
193 std::vector<std::string> modcmds;
195 std::stringstream moduleStream;
196 it = pParams.find(
"Modules");
197 if (it != pParams.end())
199 moduleStream.str(it->second);
201 while (!moduleStream.fail())
204 moduleStream >> sMod;
205 if (!moduleStream.fail())
207 modcmds.push_back(sMod);
215 std::vector<std::string> tmp;
220 it = pParams.find(
"options");
221 if (it != pParams.end())
225 std::vector<char *> argv;
227 strargv =
"dummy " + it->second;
228 strargv.push_back((
char)0);
230 for (
size_t i = 0; strargv[i]; ++i)
232 if (strargv[i] !=
' ' && flag)
234 argv.push_back(&strargv[i]);
238 if (strargv[i] ==
' ')
245 po::options_description desc(
"Available options");
250 "Produce this help message.")
252 "Print the list of available modules.")
253 (
"output-points,n", po::value<int>(),
254 "Output at n equipspaced points along the "
255 "collapsed coordinates (for .dat, .vtu).")
256 (
"output-points-hom-z", po::value<int>(),
257 "Number of planes in the z-direction for output of "
258 "Homogeneous 1D expansion(for .dat, .vtu).")
260 "Write error of fields for regression checking")
262 "Force the output to be written without any checks")
263 (
"range,r", po::value<std::string>(),
264 "Define output range i.e. (-r xmin,xmax,ymin,ymax,zmin,zmax) "
265 "in which any vertex is contained.")
267 "Do not use equispaced output.")
268 (
"nparts", po::value<int>(),
269 "Define nparts if running serial problem to mimic "
270 "parallel run with many partitions.")
271 (
"npz", po::value<int>(),
272 "Used to define number of partitions in z for Homogeneous1D "
273 "expansions for parallel runs.")
274 (
"npt", po::value<int>(),
275 "Used to define number of partitions in time for Parareal runs. ")
276 (
"onlyshape", po::value<std::string>(),
277 "Only use element with defined shape type i.e. -onlyshape "
279 (
"part-only", po::value<int>(),
280 "Partition into specified npart partitions and exit")
281 (
"part-only-overlapping", po::value<int>(),
282 "Partition into specified npart overlapping partitions and exit")
283 (
"modules-opt,p", po::value<std::string>(),
284 "Print options for a module.")
285 (
"module,m", po::value<std::vector<std::string> >(),
286 "Specify modules which are to be used.")
287 (
"useSessionVariables",
288 "Use variables defined in session for output")
289 (
"useSessionExpansion",
290 "Use expansion defined in session.")
292 "Enable verbose mode.");
295 po::options_description hidden(
"Hidden options");
299 (
"input-file", po::value<std::vector<std::string> >(),
303 po::options_description cmdline_options;
304 cmdline_options.add(hidden).add(desc);
306 po::options_description visible(
"Allowed options");
309 po::positional_options_description
p;
310 p.add(
"input-file", -1);
314 po::store(po::command_line_parser(argc, &(argv[0]))
315 .options(cmdline_options)
321 catch (
const std::exception &e)
323 std::cerr << e.what() << std::endl;
327 m_vm.insert(std::make_pair(
"forceoutput", po::variable_value()));
347 nfield = (n < pFields.size()) ? n : 0;
353 m_fieldMetaData[
"InitialTime"] = boost::lexical_cast<std::string>(time);
359 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fieldDef;
360 std::vector<std::vector<NekDouble>> fieldData;
364 fld->Import(
m_restartFile, fieldDef, fieldData, fieldMetaData);
372 for (k = 0; k < pFields.size(); ++k)
374 if (pFields[k]->GetSession()->GetVariable(k) ==
m_variables[j])
385 for (
int i = 0; i < fieldData.size(); ++i)
387 pFields[nfield]->ExtractDataToCoeffs(
393 if (fieldMetaData.count(
"NumberOfFieldDumps"))
395 m_numSamples = atoi(fieldMetaData[
"NumberOfFieldDumps"].c_str());
402 if (fieldMetaData.count(
"InitialTime"))
408 if (fieldMetaData.count(
"FilterFileNum"))
410 m_outputIndex = atoi(fieldMetaData[
"FilterFileNum"].c_str());
426 int nfield = pFields.size();
428 for (
int n = 0; n < nfield; ++n)
430 m_variables[n] = pFields[n]->GetSession()->GetVariable(n);
434 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
435 for (
int n = 0; n < nfield; ++n)
437 coeffs[n] = pFields[n]->GetCoeffs();
440 auto equ =
m_equ.lock();
441 ASSERTL0(equ,
"Weak pointer expired");
456 int nfield = pFields.size();
457 std::vector<Array<OneD, NekDouble>> coeffs(nfield);
458 for (
int n = 0; n < nfield; ++n)
460 coeffs[n] = pFields[n]->GetCoeffs();
463 auto equ =
m_equ.lock();
464 ASSERTL0(equ,
"Weak pointer expired");
465 equ->ExtraFldOutput(coeffs, variables);
487 if (
m_session->GetComm()->GetRank() == 0 &&
488 m_session->DefinesCmdLineArgument(
"verbose"))
490 std::cout <<
"Sample: " << std::setw(8) << std::left
492 << std::left << currentPhase << std::endl;
525 boost::ignore_unused(pFields, time);
547 std::stringstream outname;
554 outname <<
name << suffix << ext;
558 outname <<
name <<
"_" << dump << suffix << ext;
566 for (
int i = 0; i <
m_modules.size(); ++i)
568 if (
m_modules[i]->GetModulePriority() == priority)
595 for (
int i = 0; i < modcmds.size(); ++i)
598 std::vector<std::string> tmp1;
602 boost::split(tmp1, modcmds[i], boost::is_any_of(
":"));
604 if (i == modcmds.size() - 1)
615 if (tmp1.size() == 1)
617 int dot = tmp1[0].find_last_of(
'.') + 1;
618 std::string ext = tmp1[0].substr(dot, tmp1[0].length() - dot);
620 tmp1.push_back(std::string(
"outfile=") + tmp1[0]);
624 module.second = tmp1[1];
625 tmp1.push_back(std::string(
"outfile=") + tmp1[0]);
632 module.second = tmp1[0];
641 for (
int j = offset; j < tmp1.size(); ++j)
643 std::vector<std::string> tmp2;
644 boost::split(tmp2, tmp1[j], boost::is_any_of(
"="));
646 if (tmp2.size() == 1)
648 mod->RegisterConfig(tmp2[0]);
650 else if (tmp2.size() == 2)
652 mod->RegisterConfig(tmp2[0], tmp2[1]);
656 std::cerr <<
"ERROR: Invalid module configuration: format is "
657 <<
"either :arg or :arg=val" << std::endl;
668 for (
int i = 0; i <
m_modules.size(); ++i)
670 ++modulesCount[
m_modules[i]->GetModulePriority()];
678 module.second = std::string(
"equispacedoutput");
693 m_f->m_graph = pFields[0]->GetGraph();
694 m_f->m_comm =
m_f->m_session->GetComm();
698 m_f->m_numHomogeneousDir = 0;
701 m_f->m_numHomogeneousDir = 1;
705 m_f->m_numHomogeneousDir = 2;
709 m_f->m_exp[0] = pFields[0];
714 nfield = (n < pFields.size()) ? n : 0;
718 m_f->m_exp[n]->SetWaveSpace(
false);
721 "pFields[nfield] does not have the "
722 "same number of coefficients as m_outFields[n]");
724 m_f->m_exp[n]->ExtractCoeffsToCoeffs(pFields[nfield],
m_outFields[n],
725 m_f->m_exp[n]->UpdateCoeffs());
727 m_f->m_exp[n]->BwdTrans(
m_f->m_exp[n]->GetCoeffs(),
728 m_f->m_exp[n]->UpdatePhys());
738 for (
int i = 0; i < modules.size(); ++i)
740 ++modulesCount[modules[i]->GetModulePriority()];
750 std::stringstream ss;
752 for (
int i = 0; i < modules.size(); ++i)
757 modules[i]->GetModulePriority() ==
eCreateExp ||
758 modules[i]->GetModulePriority() ==
eFillExp ||
759 modules[i]->GetModulePriority() ==
eCreatePts)
761 ss << modules[i]->GetModuleName() <<
" ";
764 ss <<
"not compatible with FilterFieldConvert.";
772 std::stringstream ss;
774 for (
int i = 0; i < modules.size(); ++i)
778 ss << modules[i]->GetModuleName() <<
" ";
781 ss <<
"is not compatible with module(s): ";
782 for (
int i = 0; i < modules.size(); ++i)
786 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.
virtual 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
virtual SOLVER_UTILS_EXPORT ~FilterFieldConvert()
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)
virtual SOLVER_UTILS_EXPORT void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
NekDouble m_phaseTolerance
unsigned int m_numSamples
virtual 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)
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_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::weak_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
void CreateModules(std::vector< std::string > &modcmds)
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
virtual 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()
The above copyright notice and this permission notice shall be included.
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)