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 
56  if (pParams.find("StartTime") != pParams.end())
57  {
58  m_startTime = atof(pParams.find("StartTime")->second.c_str());
59  }
60 
61  m_outputFile = pSession->GetSessionName() + "_max.fld";
62  if (pParams.find("OutputFile") != pParams.end())
63  {
64  m_outputFile = pParams.find("OutputFile")->second;
65  }
66 
67  m_thresholdVar = 0;
68  if (pParams.find("ThresholdVar") != pParams.end())
69  {
70  std::string var = pParams.find("ThresholdVar")->second.c_str();
71  std::vector<string> varlist = pSession->GetVariables();
72  std::vector<string>::const_iterator x;
73  ASSERTL0((x=std::find(varlist.begin(), varlist.end(), var)) != varlist.end(),
74  "Specified variable " + var +
75  " in ThresholdMax filter is not available.");
76  m_thresholdVar = x - varlist.begin();
77  }
78 
80 
81  }
82 
84  {
85 
86  }
87 
88  void FilterThresholdMax::v_Initialise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
89  {
90  m_threshold = Array<OneD, NekDouble> (pFields[m_thresholdVar]->GetNpoints(), m_initialValue);
91  }
92 
93  void FilterThresholdMax::v_Update(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
94  {
95  if (time < m_startTime)
96  {
97  return;
98  }
99 
100  int i;
101  NekDouble timestep = pFields[m_thresholdVar]->GetSession()->GetParameter("TimeStep");
102 
103  for (i = 0; i < pFields[m_thresholdVar]->GetNpoints(); ++i)
104  {
105  if (m_threshold[i] < timestep && pFields[m_thresholdVar]->GetPhys()[i] > m_thresholdValue)
106  {
107  m_threshold[i] = time;
108  }
109  }
110  }
111 
112  void FilterThresholdMax::v_Finalise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
113  {
114  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
115  = pFields[m_thresholdVar]->GetFieldDefinitions();
116  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
117 
118  Array<OneD, NekDouble> vCoeffs(pFields[0]->GetNcoeffs());
119  pFields[m_thresholdVar]->FwdTrans_IterPerExp(m_threshold, vCoeffs);
120 
121  // copy Data into FieldData and set variable
122  for(int i = 0; i < FieldDef.size(); ++i)
123  {
124  // Could do a search here to find correct variable
125  FieldDef[i]->m_fields.push_back("m");
126  pFields[m_thresholdVar]->AppendFieldData(FieldDef[i], FieldData[i], vCoeffs);
127  }
128 
129  m_fld->Write(m_outputFile,FieldDef,FieldData);
130 
131  }
132 
134  {
135  return true;
136  }
137  }
138 }