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 
35 #include <boost/core/ignore_unused.hpp>
36 
38 
39 using namespace std;
40 
41 namespace Nektar
42 {
43 namespace SolverUtils
44 {
45 
46 std::string FilterThresholdMax::className =
48  "ThresholdMax", FilterThresholdMax::create);
49 
50 FilterThresholdMax::FilterThresholdMax(
52  const std::weak_ptr<EquationSystem> &pEquation,
53  const ParamMap &pParams) :
54  Filter(pSession, pEquation)
55 {
56  // ThresholdValue
57  auto it = pParams.find("ThresholdValue");
58  ASSERTL0(it != pParams.end(), "Missing parameter 'ThresholdValue'.");
60  m_session->GetInterpreter(), it->second);
61  m_thresholdValue = equ1.Evaluate();
62 
63  // InitialValue
64  it = pParams.find("InitialValue");
65  ASSERTL0(it != pParams.end(), "Missing parameter 'InitialValue'.");
67  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  {
76  m_session->GetInterpreter(), it->second);
77  m_startTime = equ.Evaluate();
78  }
79 
80  // OutputFile
81  it = pParams.find("OutputFile");
82  m_outputFile = pSession->GetSessionName() + "_max.fld";
83  if (it != pParams.end())
84  {
85  m_outputFile = it->second;
86  }
87 
88  // ThresholdVar
89  it = pParams.find("ThresholdVar");
90  m_thresholdVar = 0;
91  if (it != pParams.end())
92  {
93  std::string var = it->second.c_str();
94  std::vector<string> varlist = pSession->GetVariables();
95  auto x = std::find(varlist.begin(), varlist.end(), var);
96  ASSERTL0(x != varlist.end(),
97  "Specified variable " + var +
98  " in ThresholdMax filter is not available.");
99  m_thresholdVar = x - varlist.begin();
100  }
101 
103 }
104 
106 {
107 
108 }
109 
112  const NekDouble &time)
113 {
114  boost::ignore_unused(time);
115 
117  pFields[m_thresholdVar]->GetNpoints(), m_initialValue);
118 }
119 
122  const NekDouble &time)
123 {
124  if (time < m_startTime)
125  {
126  return;
127  }
128 
129  int i;
130  NekDouble timestep = pFields[m_thresholdVar]->GetSession()->GetParameter("TimeStep");
131 
132  for (i = 0; i < pFields[m_thresholdVar]->GetNpoints(); ++i)
133  {
134  if (m_threshold[i] < timestep &&
135  pFields[m_thresholdVar]->GetPhys()[i] > m_thresholdValue)
136  {
137  m_threshold[i] = time;
138  }
139  }
140 }
141 
144  const NekDouble &time)
145 {
146  boost::ignore_unused(time);
147 
148  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
149  = pFields[m_thresholdVar]->GetFieldDefinitions();
150  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
151 
152  Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
153  pFields[m_thresholdVar]->FwdTrans_IterPerExp(m_threshold, vCoeffs);
154 
155  // copy Data into FieldData and set variable
156  for(int i = 0; i < FieldDef.size(); ++i)
157  {
158  // Could do a search here to find correct variable
159  FieldDef[i]->m_fields.push_back("m");
160  pFields[m_thresholdVar]->AppendFieldData(FieldDef[i], FieldData[i], vCoeffs);
161  }
162 
163  m_fld->Write(m_outputFile,FieldDef,FieldData);
164 
165 }
166 
168 {
169  return true;
170 }
171 }
172 }
Array< OneD, NekDouble > m_threshold
Storage for recording when each point in domain rises above threshold.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
virtual void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
Initialises the filter.
LibUtilities::FieldIOSharedPtr m_fld
FieldIO object for writing data.
int m_thresholdVar
Variable on which to detect threshold.
STL namespace.
virtual SOLVER_UTILS_EXPORT ~FilterThresholdMax()
NekDouble m_initialValue
Initial value of storage.
virtual bool v_IsTimeDependent()
Indicate that this filter is time dependent.
NekDouble m_thresholdValue
Value of threshold.
NekDouble m_startTime
Time at which to start recording.
double NekDouble
std::map< std::string, std::string > ParamMap
Definition: Filter.h:68
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:86
static std::shared_ptr< FieldIO > CreateDefault(const LibUtilities::SessionReaderSharedPtr session)
Returns an object for the default FieldIO method.
Definition: FieldIO.cpp:195
std::string m_outputFile
File into which to write output data.
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:358
FilterFactory & GetFilterFactory()
Definition: Filter.cpp:41
virtual void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
Finalise the filter and write out data.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
virtual void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
For each point in domain test if solution is above threshold.
std::shared_ptr< SessionReader > SessionReaderSharedPtr