Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Attributes | List of all members
Nektar::SolverUtils::FilterEnergy Class Reference

#include <FilterEnergy.h>

Inheritance diagram for Nektar::SolverUtils::FilterEnergy:
[legend]

Public Member Functions

SOLVER_UTILS_EXPORT FilterEnergy (const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
 
SOLVER_UTILS_EXPORT ~FilterEnergy () override
 
- Public Member Functions inherited from Nektar::SolverUtils::Filter
SOLVER_UTILS_EXPORT Filter (const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_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 ()
 
SOLVER_UTILS_EXPORT std::string SetupOutput (const std::string ext, const ParamMap &pParams)
 
SOLVER_UTILS_EXPORT std::string SetupOutput (const std::string ext, const std::string inname)
 
SOLVER_UTILS_EXPORT void SetUpdateOnInitialise (bool flag)
 

Static Public Member Functions

static SolverUtils::FilterSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< SolverUtils::EquationSystem > &pEquation, const ParamMap &pParams)
 Creates an instance of this class. More...
 

Static Public Attributes

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

Protected Member Functions

SOLVER_UTILS_EXPORT void v_Initialise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time) override
 
SOLVER_UTILS_EXPORT void v_Update (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time) override
 
SOLVER_UTILS_EXPORT void v_Finalise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time) override
 
SOLVER_UTILS_EXPORT bool v_IsTimeDependent () override
 
- Protected Member Functions inherited from Nektar::SolverUtils::Filter
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
 
virtual SOLVER_UTILS_EXPORT std::string v_SetupOutput (const std::string ext, const ParamMap &pParams)
 
virtual SOLVER_UTILS_EXPORT std::string v_SetupOutput (const std::string ext, const std::string inname)
 

Private Attributes

unsigned int m_index
 
unsigned int m_outputFrequency
 
std::ofstream m_outFile
 
bool m_homogeneous
 
NekDouble m_homogeneousLength
 
NekDouble m_area
 
LibUtilities::CommSharedPtr m_comm
 
Array< OneD, unsigned int > m_planes
 

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
 
bool m_updateOnInitialise = true
 

Detailed Description

Definition at line 42 of file FilterEnergy.h.

Constructor & Destructor Documentation

◆ FilterEnergy()

Nektar::SolverUtils::FilterEnergy::FilterEnergy ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::shared_ptr< EquationSystem > &  pEquation,
const ParamMap pParams 
)

Definition at line 48 of file FilterEnergy.cpp.

51 : Filter(pSession, pEquation), m_index(-1), m_homogeneous(false), m_planes()
52{
53 std::string outName;
54 std::string ext = ".eny";
55 outName = Filter::SetupOutput(ext, pParams);
56
57 m_comm = pSession->GetComm();
58 if (m_comm->GetRank() == 0)
59 {
60 m_outFile.open(outName.c_str());
61 ASSERTL0(m_outFile.good(), "Unable to open: '" + outName + "'");
62 m_outFile.setf(ios::scientific, ios::floatfield);
63 m_outFile << "# Time Kinetic energy "
64 << "Enstrophy" << endl
65 << "# ---------------------------------------------"
66 << "--------------" << endl;
67 }
68 pSession->LoadParameter("LZ", m_homogeneousLength, 0.0);
69
70 // OutputFrequency
71 auto it = pParams.find("OutputFrequency");
72 ASSERTL0(it != pParams.end(), "Missing parameter 'OutputFrequency'.");
73 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
74 m_outputFrequency = round(equ.Evaluate());
75}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
LibUtilities::CommSharedPtr m_comm
Definition: FilterEnergy.h:85
Array< OneD, unsigned int > m_planes
Definition: FilterEnergy.h:86
SOLVER_UTILS_EXPORT std::string SetupOutput(const std::string ext, const ParamMap &pParams)
Definition: Filter.h:139
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:93
SOLVER_UTILS_EXPORT Filter(const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation)

References ASSERTL0, Nektar::LibUtilities::Equation::Evaluate(), m_comm, m_homogeneousLength, m_outFile, m_outputFrequency, Nektar::SolverUtils::Filter::m_session, and Nektar::SolverUtils::Filter::SetupOutput().

◆ ~FilterEnergy()

Nektar::SolverUtils::FilterEnergy::~FilterEnergy ( )
override

Definition at line 77 of file FilterEnergy.cpp.

78{
79}

Member Function Documentation

◆ create()

static SolverUtils::FilterSharedPtr Nektar::SolverUtils::FilterEnergy::create ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::shared_ptr< SolverUtils::EquationSystem > &  pEquation,
const ParamMap pParams 
)
inlinestatic

Creates an instance of this class.

Definition at line 46 of file FilterEnergy.h.

50 {
53 pParams);
54 return p;
55 }
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:52

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

◆ v_Finalise()

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

Implements Nektar::SolverUtils::Filter.

Definition at line 251 of file FilterEnergy.cpp.

255{
256 m_outFile.close();
257}

References m_outFile.

◆ v_Initialise()

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

Implements Nektar::SolverUtils::Filter.

Definition at line 81 of file FilterEnergy.cpp.

84{
85 m_index = -1;
87
88 ASSERTL0(pFields[0]->GetExpType() != MultiRegions::e1D,
89 "1D expansion not supported for energy filter");
90
91 ASSERTL0(pFields[0]->GetExpType() != MultiRegions::e2D,
92 "2D expansion not supported for energy filter");
93
94 ASSERTL0(pFields[0]->GetExpType() != MultiRegions::e3DH2D,
95 "Homogeneous 2D expansion not supported for energy filter");
96
97 if (pFields[0]->GetExpType() == MultiRegions::e3DH1D)
98 {
99 m_homogeneous = true;
100 }
101
102 // Calculate area/volume of domain.
103 if (m_homogeneous)
104 {
105 m_planes = pFields[0]->GetZIDs();
106 areaField = pFields[0]->GetPlane(0);
107 }
108 else
109 {
110 areaField = pFields[0];
111 }
112
113 Array<OneD, NekDouble> inarray(areaField->GetNpoints(), 1.0);
114 m_area = areaField->Integral(inarray);
115
116 if (m_homogeneous)
117 {
119 }
121 {
122 v_Update(pFields, time);
123 }
124}
SOLVER_UTILS_EXPORT void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time) override
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.

References ASSERTL0, Nektar::MultiRegions::e1D, Nektar::MultiRegions::e2D, Nektar::MultiRegions::e3DH1D, Nektar::MultiRegions::e3DH2D, m_area, m_homogeneous, m_homogeneousLength, m_index, m_planes, Nektar::SolverUtils::Filter::m_updateOnInitialise, and v_Update().

◆ v_IsTimeDependent()

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

Implements Nektar::SolverUtils::Filter.

Definition at line 259 of file FilterEnergy.cpp.

260{
261 return true;
262}

◆ v_Update()

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

Implements Nektar::SolverUtils::Filter.

Definition at line 126 of file FilterEnergy.cpp.

129{
130 int i, nPoints = pFields[0]->GetNpoints();
131
132 m_index++;
133
134 if (m_index % m_outputFrequency > 0)
135 {
136 return;
137 }
138
139 // Lock equation system pointer
140 auto equ = m_equ.lock();
141 ASSERTL0(equ, "Weak pointer expired");
142
143 auto fluidEqu = std::dynamic_pointer_cast<FluidInterface>(equ);
144 ASSERTL0(fluidEqu, "Energy filter is incompatible with this solver.");
145
146 // Store physical values in an array
147 Array<OneD, Array<OneD, NekDouble>> physfields(pFields.size());
148 for (i = 0; i < pFields.size(); ++i)
149 {
150 physfields[i] = pFields[i]->GetPhys();
151 }
152
153 // Calculate kinetic energy.
154 NekDouble Ek = 0.0;
155 Array<OneD, NekDouble> tmp(nPoints, 0.0);
156 Array<OneD, NekDouble> density;
157 Array<OneD, Array<OneD, NekDouble>> u(3);
158 for (i = 0; i < 3; ++i)
159 {
160 u[i] = Array<OneD, NekDouble>(nPoints);
161 }
162 fluidEqu->GetVelocity(physfields, u);
163
164 for (i = 0; i < 3; ++i)
165 {
166 if (m_homogeneous && pFields[i]->GetWaveSpace())
167 {
168 pFields[i]->HomogeneousBwdTrans(nPoints, u[i], u[i]);
169 }
170
171 Vmath::Vvtvp(nPoints, u[i], 1, u[i], 1, tmp, 1, tmp, 1);
172 }
173
174 if (!fluidEqu->HasConstantDensity())
175 {
176 density = Array<OneD, NekDouble>(nPoints);
177 fluidEqu->GetDensity(physfields, density);
178 Vmath::Vmul(nPoints, density, 1, tmp, 1, tmp, 1);
179 }
180
181 if (m_homogeneous)
182 {
183 Array<OneD, NekDouble> tmp2(nPoints, 0.0);
184 pFields[0]->HomogeneousFwdTrans(nPoints, tmp, tmp2);
185 Ek = pFields[0]->GetPlane(0)->Integral(tmp2) * m_homogeneousLength;
186 }
187 else
188 {
189 Ek = pFields[0]->Integral(tmp);
190 }
191
192 Ek /= 2.0 * m_area;
193
194 if (m_comm->GetRank() == 0)
195 {
196 m_outFile << setw(17) << setprecision(8) << time << setw(22)
197 << setprecision(11) << Ek;
198 }
199
200 bool waveSpace[3] = {pFields[0]->GetWaveSpace(), pFields[1]->GetWaveSpace(),
201 pFields[2]->GetWaveSpace()};
202
203 if (m_homogeneous)
204 {
205 for (i = 0; i < 3; ++i)
206 {
207 pFields[i]->SetWaveSpace(false);
208 }
209 }
210
211 // First calculate vorticity field.
212 Array<OneD, NekDouble> tmp2(nPoints), tmp3(nPoints);
213 Vmath::Zero(nPoints, tmp, 1);
214 for (i = 0; i < 3; ++i)
215 {
216 int f1 = (i + 2) % 3, c2 = f1;
217 int c1 = (i + 1) % 3, f2 = c1;
218 pFields[f1]->PhysDeriv(c1, u[f1], tmp2);
219 pFields[f2]->PhysDeriv(c2, u[f2], tmp3);
220 Vmath::Vsub(nPoints, tmp2, 1, tmp3, 1, tmp2, 1);
221 Vmath::Vvtvp(nPoints, tmp2, 1, tmp2, 1, tmp, 1, tmp, 1);
222 }
223
224 if (!fluidEqu->HasConstantDensity())
225 {
226 Vmath::Vmul(nPoints, density, 1, tmp, 1, tmp, 1);
227 }
228
229 if (m_homogeneous)
230 {
231 for (i = 0; i < 3; ++i)
232 {
233 pFields[i]->SetWaveSpace(waveSpace[i]);
234 }
235 pFields[0]->HomogeneousFwdTrans(nPoints, tmp, tmp);
236 Ek = pFields[0]->GetPlane(0)->Integral(tmp) * m_homogeneousLength;
237 }
238 else
239 {
240 Ek = pFields[0]->Integral(tmp);
241 }
242
243 Ek /= 2.0 * m_area;
244
245 if (m_comm->GetRank() == 0)
246 {
247 m_outFile << setw(22) << setprecision(11) << Ek << endl;
248 }
249}
const std::weak_ptr< EquationSystem > m_equ
Definition: Filter.h:94
double NekDouble
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.hpp:72
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.hpp:366
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.hpp:273
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.hpp:220

References ASSERTL0, m_area, m_comm, Nektar::SolverUtils::Filter::m_equ, m_homogeneous, m_homogeneousLength, m_index, m_outFile, m_outputFrequency, Vmath::Vmul(), Vmath::Vsub(), Vmath::Vvtvp(), and Vmath::Zero().

Referenced by v_Initialise().

Member Data Documentation

◆ className

std::string Nektar::SolverUtils::FilterEnergy::className
static
Initial value:
=
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static SolverUtils::FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< SolverUtils::EquationSystem > &pEquation, const ParamMap &pParams)
Creates an instance of this class.
Definition: FilterEnergy.h:46
FilterFactory & GetFilterFactory()

Name of the class.

Definition at line 58 of file FilterEnergy.h.

◆ m_area

NekDouble Nektar::SolverUtils::FilterEnergy::m_area
private

Definition at line 84 of file FilterEnergy.h.

Referenced by v_Initialise(), and v_Update().

◆ m_comm

LibUtilities::CommSharedPtr Nektar::SolverUtils::FilterEnergy::m_comm
private

Definition at line 85 of file FilterEnergy.h.

Referenced by FilterEnergy(), and v_Update().

◆ m_homogeneous

bool Nektar::SolverUtils::FilterEnergy::m_homogeneous
private

Definition at line 82 of file FilterEnergy.h.

Referenced by v_Initialise(), and v_Update().

◆ m_homogeneousLength

NekDouble Nektar::SolverUtils::FilterEnergy::m_homogeneousLength
private

Definition at line 83 of file FilterEnergy.h.

Referenced by FilterEnergy(), v_Initialise(), and v_Update().

◆ m_index

unsigned int Nektar::SolverUtils::FilterEnergy::m_index
private

Definition at line 79 of file FilterEnergy.h.

Referenced by v_Initialise(), and v_Update().

◆ m_outFile

std::ofstream Nektar::SolverUtils::FilterEnergy::m_outFile
private

Definition at line 81 of file FilterEnergy.h.

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

◆ m_outputFrequency

unsigned int Nektar::SolverUtils::FilterEnergy::m_outputFrequency
private

Definition at line 80 of file FilterEnergy.h.

Referenced by FilterEnergy(), and v_Update().

◆ m_planes

Array<OneD, unsigned int> Nektar::SolverUtils::FilterEnergy::m_planes
private

Definition at line 86 of file FilterEnergy.h.

Referenced by v_Initialise().