Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Outputs time when solution first exceeds a threshold value.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 
38 using namespace std;
39 
40 namespace Nektar
41 {
42 namespace SolverUtils
43 {
44 
45 std::string FilterThresholdMax::className =
47  "ThresholdMax", FilterThresholdMax::create);
48 
49 FilterThresholdMax::FilterThresholdMax(
51  const ParamMap &pParams) :
52  Filter(pSession)
53 {
54  ParamMap::const_iterator it;
55 
56  // ThresholdValue
57  it = pParams.find("ThresholdValue");
58  ASSERTL0(it != pParams.end(), "Missing parameter 'ThresholdValue'.");
59  LibUtilities::Equation equ1(m_session, it->second);
60  m_thresholdValue = equ1.Evaluate();
61 
62  // InitialValue
63  it = pParams.find("InitialValue");
64  ASSERTL0(it != pParams.end(), "Missing parameter 'InitialValue'.");
65  LibUtilities::Equation equ2(m_session, it->second);
66  m_initialValue = equ2.Evaluate();
67 
68  // StartTime
69  it = pParams.find("StartTime");
70  m_startTime = 0.0;
71  if (it != pParams.end())
72  {
73  LibUtilities::Equation equ(m_session, it->second);
74  m_startTime = equ.Evaluate();
75  }
76 
77  // OutputFile
78  it = pParams.find("OutputFile");
79  m_outputFile = pSession->GetSessionName() + "_max.fld";
80  if (it != pParams.end())
81  {
82  m_outputFile = it->second;
83  }
84 
85  // ThresholdVar
86  it = pParams.find("ThresholdVar");
87  m_thresholdVar = 0;
88  if (it != pParams.end())
89  {
90  std::string var = it->second.c_str();
91  std::vector<string> varlist = pSession->GetVariables();
92  std::vector<string>::const_iterator x;
93  ASSERTL0((x=std::find(varlist.begin(), varlist.end(), var))
94  != varlist.end(),
95  "Specified variable " + var +
96  " in ThresholdMax filter is not available.");
97  m_thresholdVar = x - varlist.begin();
98  }
99 
101 }
102 
104 {
105 
106 }
107 
110  const NekDouble &time)
111 {
113  pFields[m_thresholdVar]->GetNpoints(), m_initialValue);
114 }
115 
118  const NekDouble &time)
119 {
120  if (time < m_startTime)
121  {
122  return;
123  }
124 
125  int i;
126  NekDouble timestep = pFields[m_thresholdVar]->GetSession()->GetParameter("TimeStep");
127 
128  for (i = 0; i < pFields[m_thresholdVar]->GetNpoints(); ++i)
129  {
130  if (m_threshold[i] < timestep &&
131  pFields[m_thresholdVar]->GetPhys()[i] > m_thresholdValue)
132  {
133  m_threshold[i] = time;
134  }
135  }
136 }
137 
140  const NekDouble &time)
141 {
142  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
143  = pFields[m_thresholdVar]->GetFieldDefinitions();
144  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
145 
146  Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
147  pFields[m_thresholdVar]->FwdTrans_IterPerExp(m_threshold, vCoeffs);
148 
149  // copy Data into FieldData and set variable
150  for(int i = 0; i < FieldDef.size(); ++i)
151  {
152  // Could do a search here to find correct variable
153  FieldDef[i]->m_fields.push_back("m");
154  pFields[m_thresholdVar]->AppendFieldData(FieldDef[i], FieldData[i], vCoeffs);
155  }
156 
157  m_fld->Write(m_outputFile,FieldDef,FieldData);
158 
159 }
160 
162 {
163  return true;
164 }
165 }
166 }
Array< OneD, NekDouble > m_threshold
Storage for recording when each point in domain rises above threshold.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
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.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
virtual bool v_IsTimeDependent()
Indicate that this filter is time dependent.
NekDouble m_thresholdValue
Value of threshold.
NekDouble Evaluate() const
Definition: Equation.h:102
NekDouble m_startTime
Time at which to start recording.
double NekDouble
std::map< std::string, std::string > ParamMap
Definition: Filter.h:67
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:84
static boost::shared_ptr< FieldIO > CreateDefault(const LibUtilities::SessionReaderSharedPtr session)
Returns an object for the default FieldIO method.
Definition: FieldIO.cpp:181
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:316
FilterFactory & GetFilterFactory()
Definition: Filter.cpp:42
virtual void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
Finalise the filter and write out data.
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.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215