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 // 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 
43 std::string FilterThresholdMin::className =
45  "ThresholdMin", FilterThresholdMin::create);
46 
47 
48 /**
49  *
50  */
53  const std::map<std::string, std::string> &pParams)
54  : Filter(pSession)
55 {
56  ASSERTL0(pParams.find("ThresholdValue") != pParams.end(),
57  "Missing parameter 'ThresholdValue'.");
58  m_thresholdValue = atof(pParams.find("ThresholdValue")->second.c_str());
59  ASSERTL0(pParams.find("InitialValue") != pParams.end(),
60  "Missing parameter 'InitialValue'.");
61  m_initialValue = atof(pParams.find("InitialValue")->second.c_str());
62  ASSERTL0(!(pParams.find("OutputFile")->second.empty()),
63  "Missing parameter 'OutputFile'.");
64  m_outputFile = pParams.find("OutputFile")->second;
65 
66  if (pParams.find("StartTime") != pParams.end())
67  {
68  m_startTime = atof(pParams.find("StartTime")->second.c_str());
69  }
70 
72  pSession->GetComm());
73 
74 }
75 
76 
77 /**
78  *
79  */
81 {
82 
83 }
84 
85 
86 /**
87  *
88  */
91  const NekDouble &time)
92 {
93  m_threshold = Array<OneD, NekDouble> (pFields[0]->GetNpoints(),
95 }
96 
97 
98 /**
99  *
100  */
103  const NekDouble &time)
104 {
105  if (time < m_startTime)
106  {
107  return;
108  }
109 
110  int i;
111  NekDouble timestep = pFields[0]->GetSession()->GetParameter("TimeStep");
112 
113  for (i = 0; i < pFields[0]->GetNpoints(); ++i)
114  {
115  if (m_threshold[i] < timestep &&
116  pFields[0]->GetPhys()[i] < m_thresholdValue)
117  {
118  m_threshold[i] = time;
119  }
120  }
121 }
122 
123 
124 /**
125  *
126  */
129  const NekDouble &time)
130 {
131  std::stringstream vOutputFilename;
132  vOutputFilename << m_outputFile << ".fld";
133 
134  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
135  = pFields[0]->GetFieldDefinitions();
136  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
137 
138  Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
139  pFields[0]->FwdTrans_IterPerExp(m_threshold, vCoeffs);
140 
141  // copy Data into FieldData and set variable
142  for(int i = 0; i < FieldDef.size(); ++i)
143  {
144  // Could do a search here to find correct variable
145  FieldDef[i]->m_fields.push_back("m");
146  pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], vCoeffs);
147  }
148 
149  m_fld->Write(vOutputFilename.str(),FieldDef,FieldData);
150 
151 }
152 
153 
154 /**
155  *
156  */
158 {
159  return true;
160 }
161 
162 }
163 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:135
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::map< std::string, std::string > &pParams)
Creates an instance of this class.
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:50
virtual SOLVER_UTILS_EXPORT bool v_IsTimeDependent()
Indicate that this filter is time dependent.
NekDouble m_thresholdValue
Value of threshold.
double NekDouble
NekDouble m_initialValue
Initial value of storage.
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.
SOLVER_UTILS_EXPORT FilterThresholdMin(const LibUtilities::SessionReaderSharedPtr &pSession, const std::map< std::string, std::string > &pParams)
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