Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Attributes | Friends | List of all members
Nektar::SolverUtils::FilterEnergy1D Class Reference

Filter for one-dimensional energy spectrum. More...

#include <FilterEnergy1D.h>

Inheritance diagram for Nektar::SolverUtils::FilterEnergy1D:
Inheritance graph
[legend]
Collaboration diagram for Nektar::SolverUtils::FilterEnergy1D:
Collaboration graph
[legend]

Public Member Functions

SOLVER_UTILS_EXPORT FilterEnergy1D (const LibUtilities::SessionReaderSharedPtr &pSession, const ParamMap &pParams)
 Set up filter with output file and frequency parameters. More...
 
SOLVER_UTILS_EXPORT ~FilterEnergy1D ()
 Destructor. More...
 
- Public Member Functions inherited from Nektar::SolverUtils::Filter
SOLVER_UTILS_EXPORT Filter (const LibUtilities::SessionReaderSharedPtr &pSession)
 
virtual SOLVER_UTILS_EXPORT ~Filter ()
 
SOLVER_UTILS_EXPORT void Initialise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 
SOLVER_UTILS_EXPORT void Update (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 
SOLVER_UTILS_EXPORT void Finalise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time)
 
SOLVER_UTILS_EXPORT bool IsTimeDependent ()
 

Static Public Member Functions

static FilterSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession, const std::map< std::string, std::string > &pParams)
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className
 Name of the class. More...
 

Protected Member Functions

virtual void v_Initialise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
 Initialize filter. More...
 
virtual void v_Update (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
 Update filter output with the current timestep's orthogonal coefficients. More...
 
virtual void v_Finalise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
 
virtual bool v_IsTimeDependent ()
 

Private Attributes

std::ofstream m_out
 Output file. More...
 
unsigned int m_outputFrequency
 Output frequency. More...
 
unsigned int m_index
 Current index counter. More...
 

Friends

class MemoryManager< FilterEnergy1D >
 

Additional Inherited Members

- Public Types inherited from Nektar::SolverUtils::Filter
typedef std::map< std::string,
std::string > 
ParamMap
 
- Protected Attributes inherited from Nektar::SolverUtils::Filter
LibUtilities::SessionReaderSharedPtr m_session
 

Detailed Description

Filter for one-dimensional energy spectrum.

This filter transforms the coefficients of each element into an orthogonal basis and outputs these coefficients at each timestep. It can be used to, for example, detect high-order oscillations in the solution field.

Definition at line 53 of file FilterEnergy1D.h.

Constructor & Destructor Documentation

Nektar::SolverUtils::FilterEnergy1D::FilterEnergy1D ( const LibUtilities::SessionReaderSharedPtr pSession,
const ParamMap pParams 
)

Set up filter with output file and frequency parameters.

Parameters
pSessionCurrent session.
pParamsMap of parameters defined in XML file.

Definition at line 54 of file FilterEnergy1D.cpp.

References ASSERTL0, Nektar::LibUtilities::Equation::Evaluate(), m_out, m_outputFrequency, and Nektar::SolverUtils::Filter::m_session.

56  :
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 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
std::ofstream m_out
Output file.
unsigned int m_index
Current index counter.
SOLVER_UTILS_EXPORT Filter(const LibUtilities::SessionReaderSharedPtr &pSession)
Definition: Filter.cpp:52
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:84
unsigned int m_outputFrequency
Output frequency.
Nektar::SolverUtils::FilterEnergy1D::~FilterEnergy1D ( )

Destructor.

Definition at line 96 of file FilterEnergy1D.cpp.

97 {
98 
99 }

Member Function Documentation

static FilterSharedPtr Nektar::SolverUtils::FilterEnergy1D::create ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::map< std::string, std::string > &  pParams 
)
inlinestatic

Creates an instance of this class.

Definition at line 59 of file FilterEnergy1D.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

61  {
63  ::AllocateSharedPtr(pSession, pParams);
64  return p;
65  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
boost::shared_ptr< Filter > FilterSharedPtr
A shared pointer to a Driver object.
Definition: Filter.h:50
void Nektar::SolverUtils::FilterEnergy1D::v_Finalise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pField,
const NekDouble time 
)
protectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 171 of file FilterEnergy1D.cpp.

References m_out.

174 {
175  m_out.close();
176 }
std::ofstream m_out
Output file.
void Nektar::SolverUtils::FilterEnergy1D::v_Initialise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pField,
const NekDouble time 
)
protectedvirtual

Initialize filter.

Implements Nektar::SolverUtils::Filter.

Definition at line 104 of file FilterEnergy1D.cpp.

References ASSERTL0.

107 {
108  ASSERTL0(pFields[0]->GetExp(0)->GetNumBases() == 1,
109  "The Energy 1D filter is only valid in 1D.");
110 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
bool Nektar::SolverUtils::FilterEnergy1D::v_IsTimeDependent ( )
protectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 178 of file FilterEnergy1D.cpp.

179 {
180  return true;
181 }
void Nektar::SolverUtils::FilterEnergy1D::v_Update ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pField,
const NekDouble time 
)
protectedvirtual

Update filter output with the current timestep's orthogonal coefficients.

Implements Nektar::SolverUtils::Filter.

Definition at line 116 of file FilterEnergy1D.cpp.

References Nektar::LibUtilities::eOrtho_A, Nektar::LibUtilities::InterpCoeff1D(), m_index, m_out, and m_outputFrequency.

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
145  LibUtilities::BasisKey bkey(
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 }
void InterpCoeff1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
Definition: InterpCoeff.cpp:47
std::ofstream m_out
Output file.
unsigned int m_index
Current index counter.
Principle Orthogonal Functions .
Definition: BasisType.h:46
boost::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:68
unsigned int m_outputFrequency
Output frequency.

Friends And Related Function Documentation

friend class MemoryManager< FilterEnergy1D >
friend

Definition at line 56 of file FilterEnergy1D.h.

Member Data Documentation

std::string Nektar::SolverUtils::FilterEnergy1D::className
static
Initial value:
RegisterCreatorFunction("Energy1D", FilterEnergy1D::create)

Name of the class.

Definition at line 68 of file FilterEnergy1D.h.

unsigned int Nektar::SolverUtils::FilterEnergy1D::m_index
private

Current index counter.

Definition at line 93 of file FilterEnergy1D.h.

Referenced by v_Update().

std::ofstream Nektar::SolverUtils::FilterEnergy1D::m_out
private

Output file.

Definition at line 89 of file FilterEnergy1D.h.

Referenced by FilterEnergy1D(), v_Finalise(), and v_Update().

unsigned int Nektar::SolverUtils::FilterEnergy1D::m_outputFrequency
private

Output frequency.

Definition at line 91 of file FilterEnergy1D.h.

Referenced by FilterEnergy1D(), and v_Update().