Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 namespace Nektar
39 {
40  namespace SolverUtils
41  {
43 
46  const std::map<std::string, std::string> &pParams) :
47  Filter(pSession)
48  {
49  ASSERTL0(pParams.find("ThresholdValue") != pParams.end(),
50  "Missing parameter 'ThresholdValue'.");
51  m_thresholdValue = atof(pParams.find("ThresholdValue")->second.c_str());
52  ASSERTL0(pParams.find("InitialValue") != pParams.end(),
53  "Missing parameter 'InitialValue'.");
54  m_initialValue = atof(pParams.find("InitialValue")->second.c_str());
55  ASSERTL0(!(pParams.find("OutputFile")->second.empty()),
56  "Missing parameter 'OutputFile'.");
57  m_outputFile = pParams.find("OutputFile")->second;
59 
60  }
61 
63  {
64 
65  }
66 
67  void FilterThresholdMax::v_Initialise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
68  {
69  m_threshold = Array<OneD, NekDouble> (pFields[0]->GetNpoints(), m_initialValue);
70  }
71 
72  void FilterThresholdMax::v_Update(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
73  {
74  int i;
75  NekDouble timestep = pFields[0]->GetSession()->GetParameter("TimeStep");
76 
77  for (i = 0; i < pFields[0]->GetNpoints(); ++i)
78  {
79  if (m_threshold[i] < timestep && pFields[0]->GetPhys()[i] > m_thresholdValue)
80  {
81  m_threshold[i] = time;
82  }
83  }
84  }
85 
86  void FilterThresholdMax::v_Finalise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
87  {
88  std::stringstream vOutputFilename;
89  vOutputFilename << m_outputFile << ".fld";
90 
91  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
92  = pFields[0]->GetFieldDefinitions();
93  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
94 
95  Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
96  pFields[0]->FwdTrans_IterPerExp(m_threshold, vCoeffs);
97 
98  // copy Data into FieldData and set variable
99  for(int i = 0; i < FieldDef.size(); ++i)
100  {
101  // Could do a search here to find correct variable
102  FieldDef[i]->m_fields.push_back("m");
103  pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], vCoeffs);
104  }
105 
106  m_fld->Write(vOutputFilename.str(),FieldDef,FieldData);
107 
108  }
109 
111  {
112  return true;
113  }
114  }
115 }