Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // 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 drops below a threshold value.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 
38 namespace Nektar
39 {
40 namespace SolverUtils
41 {
42 
45  "ThresholdMin", FilterThresholdMin::create);
46 
47 
48 /**
49  *
50  */
53  const ParamMap &pParams)
54  : Filter(pSession)
55 {
56  ParamMap::const_iterator it;
57 
58  // ThresholdValue
59  it = pParams.find("ThresholdValue");
60  ASSERTL0(it != pParams.end(), "Missing parameter 'ThresholdValue'.");
61  LibUtilities::Equation equ1(m_session, it->second);
62  m_thresholdValue = equ1.Evaluate();
63 
64  // InitialValue
65  it = pParams.find("InitialValue");
66  ASSERTL0(it != pParams.end(), "Missing parameter 'InitialValue'.");
67  LibUtilities::Equation equ2(m_session, 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, 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");
89  m_thresholdVar = 0;
90  if (it != pParams.end())
91  {
92  std::string var = it->second.c_str();
93  std::vector<string> varlist = pSession->GetVariables();
94  std::vector<string>::const_iterator x;
95  ASSERTL0((x=std::find(varlist.begin(), varlist.end(), var))
96  != varlist.end(),
97  "Specified variable " + var +
98  " in ThresholdMin filter is not available.");
99  m_thresholdVar = x - varlist.begin();
100  }
101 
103  ::AllocateSharedPtr(pSession->GetComm());
104 }
105 
106 
107 /**
108  *
109  */
111 {
112 
113 }
114 
115 
116 /**
117  *
118  */
121  const NekDouble &time)
122 {
124  pFields[m_thresholdVar]->GetNpoints(), m_initialValue);
125 }
126 
127 
128 /**
129  *
130  */
133  const NekDouble &time)
134 {
135  if (time < m_startTime)
136  {
137  return;
138  }
139 
140  int i;
141  NekDouble timestep = pFields[m_thresholdVar]->GetSession()->GetParameter("TimeStep");
142 
143  for (i = 0; i < pFields[m_thresholdVar]->GetNpoints(); ++i)
144  {
145  if (m_threshold[i] < timestep &&
146  pFields[m_thresholdVar]->GetPhys()[i] > m_thresholdValue)
147  {
148  m_threshold[i] = time;
149  }
150  }
151 }
152 
153 
154 /**
155  *
156  */
159  const NekDouble &time)
160 {
161  std::stringstream vOutputFilename;
162  vOutputFilename << m_outputFile << ".fld";
163 
164  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
165  = pFields[0]->GetFieldDefinitions();
166  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
167 
168  Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
169  pFields[0]->FwdTrans_IterPerExp(m_threshold, vCoeffs);
170 
171  // copy Data into FieldData and set variable
172  for(int i = 0; i < FieldDef.size(); ++i)
173  {
174  // Could do a search here to find correct variable
175  FieldDef[i]->m_fields.push_back("m");
176  pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], vCoeffs);
177  }
178 
179  m_fld->Write(vOutputFilename.str(),FieldDef,FieldData);
180 }
181 
182 
183 /**
184  *
185  */
187 {
188  return true;
189 }
190 
191 }
192 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
NekDouble m_startTime
Time at which to start recording.
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
static std::string className
Name of the class.
virtual SOLVER_UTILS_EXPORT void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
Initialises the filter.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const ParamMap &pParams)
Creates an instance of this class.
virtual SOLVER_UTILS_EXPORT bool v_IsTimeDependent()
Indicate that this filter is time dependent.
NekDouble m_thresholdValue
Value of threshold.
NekDouble Evaluate() const
Definition: Equation.h:102
int m_thresholdVar
Variable on which to detect threshold.
double NekDouble
NekDouble m_initialValue
Initial value of storage.
SOLVER_UTILS_EXPORT FilterThresholdMin(const LibUtilities::SessionReaderSharedPtr &pSession, const ParamMap &pParams)
std::map< std::string, std::string > ParamMap
Definition: Filter.h:67
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:84
std::string m_outputFile
File into which to write output data.
virtual SOLVER_UTILS_EXPORT ~FilterThresholdMin()
virtual SOLVER_UTILS_EXPORT void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
For each point in domain test if solution is below threshold.
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)
Finalise the filter and write out data.
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:315
FilterFactory & GetFilterFactory()
Definition: Filter.cpp:42
Array< OneD, NekDouble > m_threshold
Storage for recording when each point in domain drops below threshold.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215