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
35#include <boost/core/ignore_unused.hpp>
36
38
39using namespace std;
40
41namespace Nektar
42{
43namespace SolverUtils
44{
45
49
50/**
51 *
52 */
55 const std::weak_ptr<EquationSystem> &pEquation, const ParamMap &pParams)
56 : Filter(pSession, pEquation)
57{
58 // ThresholdValue
59 auto it = pParams.find("ThresholdValue");
60 ASSERTL0(it != pParams.end(), "Missing parameter 'ThresholdValue'.");
61 LibUtilities::Equation equ1(m_session->GetInterpreter(), it->second);
63
64 // InitialValue
65 it = pParams.find("InitialValue");
66 ASSERTL0(it != pParams.end(), "Missing parameter 'InitialValue'.");
67 LibUtilities::Equation equ2(m_session->GetInterpreter(), it->second);
68 m_initialValue = equ2.Evaluate();
69
70 // StartTime
71 it = pParams.find("StartTime");
72 m_startTime = 0.0;
73 if (it != pParams.end())
74 {
75 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
76 m_startTime = equ.Evaluate();
77 }
78
79 // OutputFile
80 it = pParams.find("OutputFile");
81 m_outputFile = pSession->GetSessionName() + "_max.fld";
82 if (it != pParams.end())
83 {
84 m_outputFile = it->second;
85 }
86
87 // ThresholdVar
88 it = pParams.find("ThresholdVar");
90 if (it != pParams.end())
91 {
92 std::string var = it->second.c_str();
93 std::vector<string> varlist = pSession->GetVariables();
94 auto x = std::find(varlist.begin(), varlist.end(), var);
95 ASSERTL0(x != varlist.end(),
96 "Specified variable " + var +
97 " in ThresholdMin filter is not available.");
98 m_thresholdVar = x - varlist.begin();
99 }
100
102}
103
104/**
105 *
106 */
108{
109}
110
111/**
112 *
113 */
116 const NekDouble &time)
117{
118 boost::ignore_unused(time);
119
120 m_threshold = Array<OneD, NekDouble>(pFields[m_thresholdVar]->GetNpoints(),
122}
123
124/**
125 *
126 */
129 const NekDouble &time)
130{
131 if (time < m_startTime)
132 {
133 return;
134 }
135
136 int i;
137 NekDouble timestep =
138 pFields[m_thresholdVar]->GetSession()->GetParameter("TimeStep");
139
140 for (i = 0; i < pFields[m_thresholdVar]->GetNpoints(); ++i)
141 {
142 if (m_threshold[i] < timestep &&
143 pFields[m_thresholdVar]->GetPhys()[i] > m_thresholdValue)
144 {
145 m_threshold[i] = time;
146 }
147 }
148}
149
150/**
151 *
152 */
155 const NekDouble &time)
156{
157 boost::ignore_unused(time);
158
159 std::stringstream vOutputFilename;
160 vOutputFilename << m_outputFile << ".fld";
161
162 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
163 pFields[0]->GetFieldDefinitions();
164 std::vector<std::vector<NekDouble>> FieldData(FieldDef.size());
165
166 Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
167 pFields[0]->FwdTransLocalElmt(m_threshold, vCoeffs);
168
169 // copy Data into FieldData and set variable
170 for (int i = 0; i < FieldDef.size(); ++i)
171 {
172 // Could do a search here to find correct variable
173 FieldDef[i]->m_fields.push_back("m");
174 pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], vCoeffs);
175 }
176
177 m_fld->Write(vOutputFilename.str(), FieldDef, FieldData);
178}
179
180/**
181 *
182 */
184{
185 return true;
186}
187
188} // namespace SolverUtils
189} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
static std::shared_ptr< FieldIO > CreateDefault(const LibUtilities::SessionReaderSharedPtr session)
Returns an object for the default FieldIO method.
Definition: FieldIO.cpp:197
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:85
std::map< std::string, std::string > ParamMap
Definition: Filter.h:67
NekDouble m_thresholdValue
Value of threshold.
static std::string className
Name of the class.
LibUtilities::FieldIOSharedPtr m_fld
FieldIO object for writing data.
virtual 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.
virtual SOLVER_UTILS_EXPORT ~FilterThresholdMin()
SOLVER_UTILS_EXPORT FilterThresholdMin(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
std::string m_outputFile
File into which to write output data.
virtual SOLVER_UTILS_EXPORT void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
Initialises the filter.
virtual 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.
virtual 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.
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_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()
Definition: Filter.cpp:41
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:453
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble