Nektar++
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:
[legend]

Public Member Functions

SOLVER_UTILS_EXPORT FilterEnergy1D (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
 Set up filter with output file and frequency parameters. More...
 
SOLVER_UTILS_EXPORT ~FilterEnergy1D () override
 Destructor. More...
 
- Public Member Functions inherited from Nektar::SolverUtils::Filter
SOLVER_UTILS_EXPORT Filter (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
 
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::weak_ptr< EquationSystem > &pEquation, 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

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

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
 
const std::weak_ptr< EquationSystemm_equ
 

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 50 of file FilterEnergy1D.h.

Constructor & Destructor Documentation

◆ FilterEnergy1D()

Nektar::SolverUtils::FilterEnergy1D::FilterEnergy1D ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::weak_ptr< EquationSystem > &  pEquation,
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 52 of file FilterEnergy1D.cpp.

55 : Filter(pSession, pEquation), m_index(0)
56{
57 ASSERTL0(pSession->GetComm()->GetSize() == 1,
58 "The 1D energy filter currently only works in serial.");
59
60 std::string outName;
61
62 // OutputFile
63 auto it = pParams.find("OutputFile");
64 if (it == pParams.end())
65 {
66 outName = m_session->GetSessionName();
67 }
68 else
69 {
70 ASSERTL0(it->second.length() > 0, "Missing parameter 'OutputFile'.");
71 outName = it->second;
72 }
73 outName += ".eny";
74 m_out.open(outName.c_str());
75
76 // OutputFrequency
77 it = pParams.find("OutputFrequency");
78 if (it == pParams.end())
79 {
81 }
82 else
83 {
84 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
85 m_outputFrequency = round(equ.Evaluate());
86 }
87}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
unsigned int m_outputFrequency
Output frequency.
unsigned int m_index
Current index counter.
std::ofstream m_out
Output file.
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:83
SOLVER_UTILS_EXPORT Filter(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
Definition: Filter.cpp:45

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

◆ ~FilterEnergy1D()

Nektar::SolverUtils::FilterEnergy1D::~FilterEnergy1D ( )
override

Destructor.

Definition at line 92 of file FilterEnergy1D.cpp.

93{
94}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 56 of file FilterEnergy1D.h.

60 {
62 pSession, pEquation, pParams);
63 return p;
64 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Filter > FilterSharedPtr
A shared pointer to a Driver object.
Definition: Filter.h:51

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and CellMLToNektar.cellml_metadata::p.

◆ v_Finalise()

void Nektar::SolverUtils::FilterEnergy1D::v_Finalise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pField,
const NekDouble time 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 165 of file FilterEnergy1D.cpp.

169{
170 m_out.close();
171}

References m_out.

◆ v_Initialise()

void Nektar::SolverUtils::FilterEnergy1D::v_Initialise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pField,
const NekDouble time 
)
overrideprotectedvirtual

Initialize filter.

Implements Nektar::SolverUtils::Filter.

Definition at line 99 of file FilterEnergy1D.cpp.

102{
103 ASSERTL0(pFields[0]->GetExp(0)->GetNumBases() == 1,
104 "The Energy 1D filter is only valid in 1D.");
105}

References ASSERTL0.

◆ v_IsTimeDependent()

bool Nektar::SolverUtils::FilterEnergy1D::v_IsTimeDependent ( )
overrideprotectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 173 of file FilterEnergy1D.cpp.

174{
175 return true;
176}

◆ v_Update()

void Nektar::SolverUtils::FilterEnergy1D::v_Update ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pField,
const NekDouble time 
)
overrideprotectedvirtual

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

Implements Nektar::SolverUtils::Filter.

Definition at line 111 of file FilterEnergy1D.cpp.

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(btype, nModes,
137 exp->GetBasis(0)->GetPointsKey());
138
139 // Get basis key for existing expansion
140 LibUtilities::BasisKey bkey(exp->GetBasis(0)->GetBasisType(),
141 exp->GetBasis(0)->GetNumModes(),
142 exp->GetBasis(0)->GetPointsKey());
143
144 // Find coeffs for this element in the list of all coefficients
145 Array<OneD, NekDouble> coeffs =
146 pFields[0]->GetCoeffs() + pFields[0]->GetCoeff_Offset(i);
147
148 // Storage for orthogonal coefficients
149 Array<OneD, NekDouble> coeffsOrth(nModes);
150
151 // Project from coeffs -> orthogonal coeffs
152 LibUtilities::InterpCoeff1D(bkey, coeffs, bkeyOrth, coeffsOrth);
153
154 // Write coeffs to file
155 m_out << "# Element " << i << " (ID " << exp->GetGeom()->GetGlobalID()
156 << ")" << endl;
157 for (int j = 0; j < nModes; ++j)
158 {
159 m_out << coeffsOrth[j] << endl;
160 }
161 }
162 m_out << endl;
163}
void InterpCoeff1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
Definition: InterpCoeff.cpp:42
@ eOrtho_A
Principle Orthogonal Functions .
Definition: BasisType.h:42
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:66

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

Friends And Related Function Documentation

◆ MemoryManager< FilterEnergy1D >

friend class MemoryManager< FilterEnergy1D >
friend

Definition at line 1 of file FilterEnergy1D.h.

Member Data Documentation

◆ className

std::string Nektar::SolverUtils::FilterEnergy1D::className
static
Initial value:
=
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const std::map< std::string, std::string > &pParams)
Creates an instance of this class.
FilterFactory & GetFilterFactory()
Definition: Filter.cpp:39

Name of the class.

Definition at line 67 of file FilterEnergy1D.h.

◆ m_index

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

Current index counter.

Definition at line 93 of file FilterEnergy1D.h.

Referenced by v_Update().

◆ m_out

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().

◆ m_outputFrequency

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

Output frequency.

Definition at line 91 of file FilterEnergy1D.h.

Referenced by FilterEnergy1D(), and v_Update().