Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FilterEnergy.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File FilterEnergy.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: Output kinetic energy and enstrophy.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #include <iomanip>
37 
39 
40 namespace Nektar
41 {
42  namespace SolverUtils
43  {
45  RegisterCreatorFunction("Energy", FilterEnergy::create);
46 
49  const std::map<std::string, std::string> &pParams) :
50  Filter(pSession), m_index(0), m_homogeneous(false), m_planes()
51  {
52  std::string outName;
53  if (pParams.find("OutputFile") == pParams.end())
54  {
55  outName = m_session->GetSessionName();
56  }
57  else
58  {
59  ASSERTL0(!(pParams.find("OutputFile")->second.empty()),
60  "Missing parameter 'OutputFile'.");
61  outName = pParams.find("OutputFile")->second;
62  }
63 
64  m_comm = pSession->GetComm();
65  outName += ".eny";
66  if (m_comm->GetRank() == 0)
67  {
68  m_outFile.open(outName.c_str());
69  ASSERTL0(m_outFile.good(), "Unable to open: '" + outName + "'");
70  }
71 
72  ASSERTL0(pParams.find("OutputFrequency") != pParams.end(),
73  "Missing parameter 'OutputFrequency'.");
74  m_outputFrequency = atoi(
75  pParams.find("OutputFrequency")->second.c_str());
76  }
77 
79  {
80 
81  }
82 
84  const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields,
85  const NekDouble &time)
86  {
87  m_index = 0;
89 
90  ASSERTL0(pFields[0]->GetExpType() != MultiRegions::e3DH2D,
91  "Homogeneous 2D expansion not supported"
92  "for energy filter");
93 
94  if (pFields[0]->GetExpType() == MultiRegions::e3DH1D)
95  {
96  m_homogeneous = true;
97  }
98 
99  // Calculate area/volume of domain.
100  if (m_homogeneous)
101  {
102  m_planes = pFields[0]->GetZIDs();
103  areaField = pFields[0]->GetPlane(0);
104  }
105  else
106  {
107  areaField = pFields[0];
108  }
109 
110  Array<OneD, NekDouble> inarray(areaField->GetNpoints(), 1.0);
111  m_area = areaField->Integral(inarray);
112 
113  if (m_homogeneous)
114  {
116  }
117 
118  // Output values at initial time.
119  v_Update(pFields, time);
120  }
121 
123  const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields,
124  const NekDouble &time)
125  {
126  int i, nPoints = pFields[0]->GetNpoints(), nPlanePts = 0;
127 
128  if (m_homogeneous)
129  {
130  nPlanePts = pFields[0]->GetPlane(0)->GetNpoints();
131  }
132 
133  m_index++;
134  if (m_index % m_outputFrequency > 0)
135  {
136  return;
137  }
138 
139  // Calculate kinetic energy.
140  NekDouble Ek = 0.0;
141  Array<OneD, NekDouble> tmp(nPoints);
142  Array<OneD, Array<OneD, NekDouble> > u(3);
143  for (i = 0; i < 3; ++i)
144  {
145  if (m_homogeneous)
146  {
147  pFields[i]->HomogeneousBwdTrans(pFields[i]->GetPhys(), tmp);
148  }
149  else
150  {
151  tmp = pFields[i]->GetPhys();
152  }
153 
154  u[i] = Array<OneD, NekDouble>(nPoints);
155  Vmath::Vcopy(nPoints, tmp, 1, u[i], 1);
156  Vmath::Vmul (nPoints, tmp, 1, tmp, 1, tmp, 1);
157 
158  if (m_homogeneous)
159  {
160  pFields[i]->HomogeneousFwdTrans(tmp, tmp);
161  Ek += pFields[i]->GetPlane(0)->Integral(tmp) * 2.0 * M_PI;
162  }
163  else
164  {
165  Ek += pFields[i]->Integral(tmp);
166  }
167  }
168 
169  Ek /= 2.0*m_area;
170 
171  if (m_comm->GetRank() == 0)
172  {
173  m_outFile << setw(10) << time << setw(20) << Ek;
174  }
175 
176  bool waveSpace[3] = {
177  pFields[0]->GetWaveSpace(),
178  pFields[1]->GetWaveSpace(),
179  pFields[2]->GetWaveSpace()
180  };
181 
182  if (m_homogeneous)
183  {
184  for (i = 0; i < 3; ++i)
185  {
186  pFields[i]->SetWaveSpace(false);
187  }
188  }
189 
190  // First calculate vorticity field.
191  Array<OneD, NekDouble> tmp2(nPoints), tmp3(nPoints);
192  Vmath::Zero(nPoints, tmp, 1);
193  for (i = 0; i < 3; ++i)
194  {
195  int f1 = (i+2) % 3, c2 = f1;
196  int c1 = (i+1) % 3, f2 = c1;
197  pFields[f1]->PhysDeriv(c1, u[f1], tmp2);
198  pFields[f2]->PhysDeriv(c2, u[f2], tmp3);
199  Vmath::Vsub (nPoints, tmp2, 1, tmp3, 1, tmp2, 1);
200  Vmath::Vvtvp(nPoints, tmp2, 1, tmp2, 1, tmp, 1, tmp, 1);
201  }
202 
203  if (m_homogeneous)
204  {
205  for (i = 0; i < 3; ++i)
206  {
207  pFields[i]->SetWaveSpace(waveSpace[i]);
208  }
209  pFields[0]->HomogeneousFwdTrans(tmp, tmp);
210  Ek = pFields[0]->GetPlane(0)->Integral(tmp) * 2 * M_PI;
211  }
212  else
213  {
214  Ek = pFields[0]->Integral(tmp);
215  }
216 
217  Ek /= 2.0*m_area;
218 
219  if (m_comm->GetRank() == 0)
220  {
221  m_outFile << setw(20) << Ek << endl;
222  }
223  }
224 
226  const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields,
227  const NekDouble &time)
228  {
229  m_outFile.close();
230  }
231 
233  {
234  return true;
235  }
236  }
237 }