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 // 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 orthogonal expansion of 1D elements.
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
38 
39 namespace Nektar
40 {
41 namespace SolverUtils
42 {
44  RegisterCreatorFunction("Energy1D", FilterEnergy1D::create);
45 
46 /**
47  * @brief Set up filter with output file and frequency parameters.
48  *
49  * @param pSession Current session.
50  * @param pParams Map of parameters defined in XML file.
51  */
54  const ParamMap &pParams) :
55  Filter(pSession),
56  m_index(0)
57 {
58  ASSERTL0(pSession->GetComm()->GetSize() == 1,
59  "The 1D energy filter currently only works in serial.");
60 
61  ParamMap::const_iterator it;
62  std::string outName;
63 
64  // OutputFile
65  it = pParams.find("OutputFile");
66  if (it == pParams.end())
67  {
68  outName = m_session->GetSessionName();
69  }
70  else
71  {
72  ASSERTL0(it->second.length() > 0, "Missing parameter 'OutputFile'.");
73  outName = it->second;
74  }
75  outName += ".eny";
76  m_out.open(outName.c_str());
77 
78  // OutputFrequency
79  it = pParams.find("OutputFrequency");
80  if (it == pParams.end())
81  {
83  }
84  else
85  {
86  LibUtilities::Equation equ(m_session, it->second);
87  m_outputFrequency = floor(equ.Evaluate());
88  }
89 }
90 
91 /**
92  * @brief Destructor.
93  */
95 {
96 
97 }
98 
99 /**
100  * @brief Initialize filter.
101  */
104  const NekDouble &time)
105 {
106  ASSERTL0(pFields[0]->GetExp(0)->GetNumBases() == 1,
107  "The Energy 1D filter is only valid in 1D.");
108 }
109 
110 /**
111  * @brief Update filter output with the current timestep's orthogonal
112  * coefficients.
113  */
116  const NekDouble &time)
117 {
118  // Only output every m_outputFrequency
119  if ((m_index++) % m_outputFrequency)
120  {
121  return;
122  }
123 
124  int nElmt = pFields[0]->GetExpSize();
125 
126  // Loop over all elements
127  m_out << "##" << endl;
128  m_out << "## Time = " << time << endl;
129  m_out << "##" << endl;
130 
131  for (int i = 0; i < nElmt; ++i)
132  {
133  // Figure out number of modes in this expansion.
134  LocalRegions::ExpansionSharedPtr exp = pFields[0]->GetExp(i);
135  int nModes = exp->GetBasis(0)->GetNumModes();
136 
137  // Set uo basis key for orthogonal basis
139  LibUtilities::BasisKey bkeyOrth(
140  btype, nModes, exp->GetBasis(0)->GetPointsKey());
141 
142  // Get basis key for existing expansion
144  exp->GetBasis(0)->GetBasisType(),
145  exp->GetBasis(0)->GetNumModes(),
146  exp->GetBasis(0)->GetPointsKey());
147 
148  // Find coeffs for this element in the list of all coefficients
149  Array<OneD, NekDouble> coeffs =
150  pFields[0]->GetCoeffs() + pFields[0]->GetCoeff_Offset(i);
151 
152  // Storage for orthogonal coefficients
153  Array<OneD, NekDouble> coeffsOrth(nModes);
154 
155  // Project from coeffs -> orthogonal coeffs
156  LibUtilities::InterpCoeff1D(bkey, coeffs, bkeyOrth, coeffsOrth);
157 
158  // Write coeffs to file
159  m_out << "# Element " << i << " (ID "
160  << exp->GetGeom()->GetGlobalID() << ")" << endl;
161  for (int j = 0; j < nModes; ++j)
162  {
163  m_out << coeffsOrth[j] << endl;
164  }
165  }
166  m_out << endl;
167 }
168 
171  const NekDouble &time)
172 {
173  m_out.close();
174 }
175 
177 {
178  return true;
179 }
180 }
181 }
virtual void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
SOLVER_UTILS_EXPORT FilterEnergy1D(const LibUtilities::SessionReaderSharedPtr &pSession, const ParamMap &pParams)
Set up filter with output file and frequency parameters.
void InterpCoeff1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
Definition: InterpCoeff.cpp:47
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:50
static std::string className
Name of the class.
virtual void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
Update filter output with the current timestep'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.
NekDouble Evaluate() const
Definition: Equation.h:102
Principle Orthogonal Functions .
Definition: BasisType.h:46
double NekDouble
std::map< std::string, std::string > ParamMap
Definition: Filter.h:67
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:84
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::map< std::string, std::string > &pParams)
Creates an instance of this class.
boost::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:68
FilterFactory & GetFilterFactory()
Definition: Filter.cpp:42
Describes the specification for a Basis.
Definition: Basis.h:50
unsigned int m_outputFrequency
Output frequency.