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 
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  */
90  const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields,
91  const NekDouble &time)
92 {
93  m_threshold = Array<OneD, NekDouble> (pFields[0]->GetNpoints(),
95 }
96 
97 
98 /**
99  *
100  */
102  const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields,
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  */
128  const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields,
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 }