Nektar++
FilterThresholdMax.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: FilterThresholdMax.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 exceeds a threshold value.
32//
33///////////////////////////////////////////////////////////////////////////////
34
36
37using namespace std;
38
39namespace Nektar::SolverUtils
40{
41
45
48 const std::shared_ptr<EquationSystem> &pEquation, const ParamMap &pParams)
49 : Filter(pSession, pEquation)
50{
51 // ThresholdValue
52 auto it = pParams.find("ThresholdValue");
53 ASSERTL0(it != pParams.end(), "Missing parameter 'ThresholdValue'.");
54 LibUtilities::Equation equ1(m_session->GetInterpreter(), it->second);
56
57 // InitialValue
58 it = pParams.find("InitialValue");
59 ASSERTL0(it != pParams.end(), "Missing parameter 'InitialValue'.");
60 LibUtilities::Equation equ2(m_session->GetInterpreter(), it->second);
61 m_initialValue = equ2.Evaluate();
62
63 // StartTime
64 it = pParams.find("StartTime");
65 m_startTime = 0.0;
66 if (it != pParams.end())
67 {
68 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
69 m_startTime = equ.Evaluate();
70 }
71
72 // OutputFile
73 it = pParams.find("OutputFile");
74 m_outputFile = pSession->GetSessionName() + "_max.fld";
75 if (it != pParams.end())
76 {
77 m_outputFile = it->second;
78 }
79
80 // ThresholdVar
81 it = pParams.find("ThresholdVar");
83 if (it != pParams.end())
84 {
85 std::string var = it->second.c_str();
86 std::vector<string> varlist = pSession->GetVariables();
87 auto x = std::find(varlist.begin(), varlist.end(), var);
88 ASSERTL0(x != varlist.end(),
89 "Specified variable " + var +
90 " in ThresholdMax filter is not available.");
91 m_thresholdVar = x - varlist.begin();
92 }
93
95}
96
98{
99}
100
103 [[maybe_unused]] const NekDouble &time)
104{
105 m_threshold = Array<OneD, NekDouble>(pFields[m_thresholdVar]->GetNpoints(),
107}
108
111 const NekDouble &time)
112{
113 if (time < m_startTime)
114 {
115 return;
116 }
117
118 int i;
119 NekDouble timestep =
120 pFields[m_thresholdVar]->GetSession()->GetParameter("TimeStep");
121
122 for (i = 0; i < pFields[m_thresholdVar]->GetNpoints(); ++i)
123 {
124 if (m_threshold[i] < timestep &&
125 pFields[m_thresholdVar]->GetPhys()[i] > m_thresholdValue)
126 {
127 m_threshold[i] = time;
128 }
129 }
130}
131
134 [[maybe_unused]] const NekDouble &time)
135{
136 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
137 pFields[m_thresholdVar]->GetFieldDefinitions();
138 std::vector<std::vector<NekDouble>> FieldData(FieldDef.size());
139
140 Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
141 pFields[m_thresholdVar]->FwdTransLocalElmt(m_threshold, vCoeffs);
142
143 // copy Data into FieldData and set variable
144 for (int i = 0; i < FieldDef.size(); ++i)
145 {
146 // Could do a search here to find correct variable
147 FieldDef[i]->m_fields.push_back("m");
148 pFields[m_thresholdVar]->AppendFieldData(FieldDef[i], FieldData[i],
149 vCoeffs);
150 }
151
152 m_fld->Write(m_outputFile, FieldDef, FieldData);
153}
154
156{
157 return true;
158}
159} // 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:195
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:83
std::map< std::string, std::string > ParamMap
Definition: Filter.h:65
static std::string className
Name of the class.
LibUtilities::FieldIOSharedPtr m_fld
FieldIO object for writing data.
void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
Initialises the filter.
void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
For each point in domain test if solution is above threshold.
SOLVER_UTILS_EXPORT FilterThresholdMax(const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
Finalise the filter and write out data.
NekDouble m_startTime
Time at which to start recording.
std::string m_outputFile
File into which to write output data.
NekDouble m_initialValue
Initial value of storage.
Array< OneD, NekDouble > m_threshold
Storage for recording when each point in domain rises above threshold.
bool v_IsTimeDependent() override
Indicate that this filter is time dependent.
int m_thresholdVar
Variable on which to detect threshold.
NekDouble m_thresholdValue
Value of threshold.
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 ~FilterThresholdMax() override
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.