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 std::map<std::string, std::string> &pParams) :
55  Filter(pSession),
56  m_index(0)
57  {
58  std::string outName;
59  if (pParams.find("OutputFile") == pParams.end())
60  {
61  outName = m_session->GetSessionName();
62  }
63  else
64  {
65  ASSERTL0(!(pParams.find("OutputFile")->second.empty()),
66  "Missing parameter 'OutputFile'.");
67  outName = pParams.find("OutputFile")->second;
68  }
69 
70  if (pParams.find("OutputFrequency") == pParams.end())
71  {
73  }
74  else
75  {
77  atoi(pParams.find("OutputFrequency")->second.c_str());
78  }
79 
80  outName += ".eny";
81 
82  ASSERTL0(pSession->GetComm()->GetSize() == 1,
83  "The 1D energy filter currently only works in serial.");
84 
85  m_out.open(outName.c_str());
86  }
87 
88  /**
89  * @brief Destructor.
90  */
92  {
93 
94  }
95 
96  /**
97  * @brief Initialize filter.
98  */
101  const NekDouble &time)
102  {
103  ASSERTL0(pFields[0]->GetExp(0)->GetNumBases() == 1,
104  "The Energy 1D filter is only valid in 1D.");
105  }
106 
107  /**
108  * @brief Update filter output with the current timestep's orthogonal
109  * coefficients.
110  */
113  const NekDouble &time)
114  {
115  // Only output every m_outputFrequency
116  if ((m_index++) % m_outputFrequency)
117  {
118  return;
119  }
120 
121  int nElmt = pFields[0]->GetExpSize();
122 
123  // Loop over all elements
124  m_out << "##" << endl;
125  m_out << "## Time = " << time << endl;
126  m_out << "##" << endl;
127 
128  for (int i = 0; i < nElmt; ++i)
129  {
130  // Figure out number of modes in this expansion.
131  LocalRegions::ExpansionSharedPtr exp = pFields[0]->GetExp(i);
132  int nModes = exp->GetBasis(0)->GetNumModes();
133 
134  // Set uo basis key for orthogonal basis
136  LibUtilities::BasisKey bkeyOrth(
137  btype, nModes, exp->GetBasis(0)->GetPointsKey());
138 
139  // Get basis key for existing expansion
141  exp->GetBasis(0)->GetBasisType(),
142  exp->GetBasis(0)->GetNumModes(),
143  exp->GetBasis(0)->GetPointsKey());
144 
145  // Find coeffs for this element in the list of all coefficients
146  Array<OneD, NekDouble> coeffs =
147  pFields[0]->GetCoeffs() + pFields[0]->GetCoeff_Offset(i);
148 
149  // Storage for orthogonal coefficients
150  Array<OneD, NekDouble> coeffsOrth(nModes);
151 
152  // Project from coeffs -> orthogonal coeffs
153  LibUtilities::InterpCoeff1D(bkey, coeffs, bkeyOrth, coeffsOrth);
154 
155  // Write coeffs to file
156  m_out << "# Element " << i << " (ID "
157  << exp->GetGeom()->GetGlobalID() << ")" << endl;
158  for (int j = 0; j < nModes; ++j)
159  {
160  m_out << coeffsOrth[j] << endl;
161  }
162  }
163  m_out << endl;
164  }
165 
168  const NekDouble &time)
169  {
170  m_out.close();
171  }
172 
174  {
175  return true;
176  }
177  }
178 }
virtual void v_Finalise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:135
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.
SOLVER_UTILS_EXPORT FilterEnergy1D(const LibUtilities::SessionReaderSharedPtr &pSession, const std::map< std::string, std::string > &pParams)
Set up filter with output file and frequency parameters.
virtual void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
Initialize filter.
Principle Orthogonal Functions .
Definition: BasisType.h:46
double NekDouble
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:76
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.