Nektar++
FilterThresholdMin.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: FilterThresholdMin.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Outputs time when solution first drops below a threshold value.
32//
33///////////////////////////////////////////////////////////////////////////////
34
36
37using namespace std;
38
39namespace Nektar::SolverUtils
40{
41
45
46/**
47 *
48 */
51 const std::shared_ptr<EquationSystem> &pEquation, const ParamMap &pParams)
52 : Filter(pSession, pEquation)
53{
54 // ThresholdValue
55 auto it = pParams.find("ThresholdValue");
56 ASSERTL0(it != pParams.end(), "Missing parameter 'ThresholdValue'.");
57 LibUtilities::Equation equ1(m_session->GetInterpreter(), it->second);
59
60 // InitialValue
61 it = pParams.find("InitialValue");
62 ASSERTL0(it != pParams.end(), "Missing parameter 'InitialValue'.");
63 LibUtilities::Equation equ2(m_session->GetInterpreter(), it->second);
64 m_initialValue = equ2.Evaluate();
65
66 // StartTime
67 it = pParams.find("StartTime");
68 m_startTime = 0.0;
69 if (it != pParams.end())
70 {
71 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
72 m_startTime = equ.Evaluate();
73 }
74
75 // OutputFile
76 std::string ext = "_min.fld";
77 m_outputFile = Filter::SetupOutput(ext, pParams);
78
79 // ThresholdVar
80 it = pParams.find("ThresholdVar");
82 if (it != pParams.end())
83 {
84 std::string var = it->second.c_str();
85 std::vector<string> varlist = pSession->GetVariables();
86 auto x = std::find(varlist.begin(), varlist.end(), var);
87 ASSERTL0(x != varlist.end(),
88 "Specified variable " + var +
89 " in ThresholdMin filter is not available.");
90 m_thresholdVar = x - varlist.begin();
91 }
92
94}
95
96/**
97 *
98 */
100{
101}
102
103/**
104 *
105 */
108 [[maybe_unused]] const NekDouble &time)
109{
110 m_threshold = Array<OneD, NekDouble>(pFields[m_thresholdVar]->GetNpoints(),
112}
113
114/**
115 *
116 */
119 const NekDouble &time)
120{
121 if (time < m_startTime)
122 {
123 return;
124 }
125
126 int i;
127 NekDouble timestep =
128 pFields[m_thresholdVar]->GetSession()->GetParameter("TimeStep");
129
130 for (i = 0; i < pFields[m_thresholdVar]->GetNpoints(); ++i)
131 {
132 if (m_threshold[i] < timestep &&
133 pFields[m_thresholdVar]->GetPhys()[i] > m_thresholdValue)
134 {
135 m_threshold[i] = time;
136 }
137 }
138}
139
140/**
141 *
142 */
145 [[maybe_unused]] const NekDouble &time)
146{
147 std::stringstream vOutputFilename;
148 vOutputFilename << m_outputFile << ".fld";
149
150 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
151 pFields[0]->GetFieldDefinitions();
152 std::vector<std::vector<NekDouble>> FieldData(FieldDef.size());
153
154 Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
155 pFields[0]->FwdTransLocalElmt(m_threshold, vCoeffs);
156
157 // copy Data into FieldData and set variable
158 for (int i = 0; i < FieldDef.size(); ++i)
159 {
160 // Could do a search here to find correct variable
161 FieldDef[i]->m_fields.push_back("m");
162 pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], vCoeffs);
163 }
164
165 m_fld->Write(vOutputFilename.str(), FieldDef, FieldData);
166}
167
168/**
169 *
170 */
172{
173 return true;
174}
175
176} // namespace Nektar::SolverUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
static std::shared_ptr< FieldIO > CreateDefault(const LibUtilities::SessionReaderSharedPtr session)
Returns an object for the default FieldIO method.
Definition: FieldIO.cpp:194
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
SOLVER_UTILS_EXPORT std::string SetupOutput(const std::string ext, const ParamMap &pParams)
Definition: Filter.h:139
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:93
std::map< std::string, std::string > ParamMap
Definition: Filter.h:66
NekDouble m_thresholdValue
Value of threshold.
static std::string className
Name of the class.
LibUtilities::FieldIOSharedPtr m_fld
FieldIO object for writing data.
SOLVER_UTILS_EXPORT void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
Finalise the filter and write out data.
NekDouble m_initialValue
Initial value of storage.
SOLVER_UTILS_EXPORT FilterThresholdMin(const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
std::string m_outputFile
File into which to write output data.
SOLVER_UTILS_EXPORT void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
Initialises the filter.
SOLVER_UTILS_EXPORT bool v_IsTimeDependent() override
Indicate that this filter is time dependent.
Array< OneD, NekDouble > m_threshold
Storage for recording when each point in domain drops below threshold.
SOLVER_UTILS_EXPORT void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
For each point in domain test if solution is below threshold.
SOLVER_UTILS_EXPORT ~FilterThresholdMin() override
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
Creates an instance of this class.
int m_thresholdVar
Variable on which to detect threshold.
NekDouble m_startTime
Time at which to start recording.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
FilterFactory & GetFilterFactory()
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:475
double NekDouble
STL namespace.