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