Nektar++
FilterEnergy1D.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File FilterEnergy1D.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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Outputs orthogonal expansion of 1D elements.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/core/ignore_unused.hpp>
36 
39 
40 using namespace std;
41 
42 namespace Nektar
43 {
44 namespace SolverUtils
45 {
46 std::string FilterEnergy1D::className = GetFilterFactory().
47  RegisterCreatorFunction("Energy1D", FilterEnergy1D::create);
48 
49 /**
50  * @brief Set up filter with output file and frequency parameters.
51  *
52  * @param pSession Current session.
53  * @param pParams Map of parameters defined in XML file.
54  */
55 FilterEnergy1D::FilterEnergy1D(
57  const std::weak_ptr<EquationSystem> &pEquation,
58  const ParamMap &pParams) :
59  Filter(pSession, pEquation),
60  m_index(0)
61 {
62  ASSERTL0(pSession->GetComm()->GetSize() == 1,
63  "The 1D energy filter currently only works in serial.");
64 
65  std::string outName;
66 
67  // OutputFile
68  auto it = pParams.find("OutputFile");
69  if (it == pParams.end())
70  {
71  outName = m_session->GetSessionName();
72  }
73  else
74  {
75  ASSERTL0(it->second.length() > 0, "Missing parameter 'OutputFile'.");
76  outName = it->second;
77  }
78  outName += ".eny";
79  m_out.open(outName.c_str());
80 
81  // OutputFrequency
82  it = pParams.find("OutputFrequency");
83  if (it == pParams.end())
84  {
86  }
87  else
88  {
90  m_session->GetInterpreter(), it->second);
91  m_outputFrequency = round(equ.Evaluate());
92  }
93 }
94 
95 /**
96  * @brief Destructor.
97  */
99 {
100 
101 }
102 
103 /**
104  * @brief Initialize filter.
105  */
108  const NekDouble &time)
109 {
110  boost::ignore_unused(time);
111  ASSERTL0(pFields[0]->GetExp(0)->GetNumBases() == 1,
112  "The Energy 1D filter is only valid in 1D.");
113 }
114 
115 /**
116  * @brief Update filter output with the current timestep's orthogonal
117  * coefficients.
118  */
121  const NekDouble &time)
122 {
123  // Only output every m_outputFrequency
124  if ((m_index++) % m_outputFrequency)
125  {
126  return;
127  }
128 
129  int nElmt = pFields[0]->GetExpSize();
130 
131  // Loop over all elements
132  m_out << "##" << endl;
133  m_out << "## Time = " << time << endl;
134  m_out << "##" << endl;
135 
136  for (int i = 0; i < nElmt; ++i)
137  {
138  // Figure out number of modes in this expansion.
139  LocalRegions::ExpansionSharedPtr exp = pFields[0]->GetExp(i);
140  int nModes = exp->GetBasis(0)->GetNumModes();
141 
142  // Set uo basis key for orthogonal basis
144  LibUtilities::BasisKey bkeyOrth(
145  btype, nModes, exp->GetBasis(0)->GetPointsKey());
146 
147  // Get basis key for existing expansion
149  exp->GetBasis(0)->GetBasisType(),
150  exp->GetBasis(0)->GetNumModes(),
151  exp->GetBasis(0)->GetPointsKey());
152 
153  // Find coeffs for this element in the list of all coefficients
154  Array<OneD, NekDouble> coeffs =
155  pFields[0]->GetCoeffs() + pFields[0]->GetCoeff_Offset(i);
156 
157  // Storage for orthogonal coefficients
158  Array<OneD, NekDouble> coeffsOrth(nModes);
159 
160  // Project from coeffs -> orthogonal coeffs
161  LibUtilities::InterpCoeff1D(bkey, coeffs, bkeyOrth, coeffsOrth);
162 
163  // Write coeffs to file
164  m_out << "# Element " << i << " (ID "
165  << exp->GetGeom()->GetGlobalID() << ")" << endl;
166  for (int j = 0; j < nModes; ++j)
167  {
168  m_out << coeffsOrth[j] << endl;
169  }
170  }
171  m_out << endl;
172 }
173 
176  const NekDouble &time)
177 {
178  boost::ignore_unused(pFields, time);
179  m_out.close();
180 }
181 
183 {
184  return true;
185 }
186 }
187 }
virtual void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
void InterpCoeff1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
Definition: InterpCoeff.cpp:46
STL namespace.
std::ofstream m_out
Output file.
virtual void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
Update filter output with the current timestep&#39;s orthogonal coefficients.
SOLVER_UTILS_EXPORT ~FilterEnergy1D()
Destructor.
unsigned int m_index
Current index counter.
virtual void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
Initialize filter.
Principle Orthogonal Functions .
Definition: BasisType.h:45
double NekDouble
std::map< std::string, std::string > ParamMap
Definition: Filter.h:68
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:86
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:65
FilterFactory & GetFilterFactory()
Definition: Filter.cpp:41
Describes the specification for a Basis.
Definition: Basis.h:49
std::shared_ptr< SessionReader > SessionReaderSharedPtr
unsigned int m_outputFrequency
Output frequency.