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

#include <FilterEnergyBase.h>

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

Public Member Functions

SOLVER_UTILS_EXPORT FilterEnergyBase (const LibUtilities::SessionReaderSharedPtr &pSession, const ParamMap &pParams, const bool pConstDensity=true)
 
SOLVER_UTILS_EXPORT ~FilterEnergyBase ()
 
- 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 ()
 

Protected Member Functions

virtual SOLVER_UTILS_EXPORT void v_Initialise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
 
virtual SOLVER_UTILS_EXPORT void v_Update (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
 
virtual SOLVER_UTILS_EXPORT void v_Finalise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
 
virtual SOLVER_UTILS_EXPORT bool v_IsTimeDependent ()
 
virtual SOLVER_UTILS_EXPORT void v_GetVelocity (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const int i, Array< OneD, NekDouble > &velocity)
 
virtual SOLVER_UTILS_EXPORT
Array< OneD, NekDouble
v_GetDensity (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFld)
 

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
 
bool m_constDensity
 

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

Definition at line 45 of file FilterEnergyBase.h.

Constructor & Destructor Documentation

Nektar::SolverUtils::FilterEnergyBase::FilterEnergyBase ( const LibUtilities::SessionReaderSharedPtr pSession,
const ParamMap pParams,
const bool  pConstDensity = true 
)

Definition at line 44 of file FilterEnergyBase.cpp.

References ASSERTL0, m_comm, m_homogeneousLength, m_outFile, m_outputFrequency, and Nektar::SolverUtils::Filter::m_session.

48  : Filter (pSession),
49  m_index (-1),
50  m_homogeneous (false),
51  m_planes (),
52  m_constDensity(pConstDensity)
53 {
54  ParamMap::const_iterator it;
55  std::string outName;
56 
57  // OutputFile
58  it = pParams.find("OutputFile");
59  if (it == pParams.end())
60  {
61  outName = m_session->GetSessionName();
62  }
63  else
64  {
65  ASSERTL0(it->second.length() > 0, "Missing parameter 'OutputFile'.");
66  outName = it->second;
67  }
68  outName += ".eny";
69 
70  m_comm = pSession->GetComm();
71  if (m_comm->GetRank() == 0)
72  {
73  m_outFile.open(outName.c_str());
74  ASSERTL0(m_outFile.good(), "Unable to open: '" + outName + "'");
75  m_outFile.setf(ios::scientific, ios::floatfield);
76  m_outFile << "# Time Kinetic energy "
77  << "Enstrophy"
78  << endl
79  << "# ---------------------------------------------"
80  << "--------------"
81  << endl;
82  }
83  pSession->LoadParameter("LZ", m_homogeneousLength, 0.0);
84 
85  // OutputFrequency
86  it = pParams.find("OutputFrequency");
87  ASSERTL0(it != pParams.end(), "Missing parameter 'OutputFrequency'.");
88  LibUtilities::Equation equ(m_session, it->second);
89  m_outputFrequency = floor(equ.Evaluate());
90 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
Array< OneD, unsigned int > m_planes
LibUtilities::CommSharedPtr m_comm
SOLVER_UTILS_EXPORT Filter(const LibUtilities::SessionReaderSharedPtr &pSession)
Definition: Filter.cpp:52
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:84
Nektar::SolverUtils::FilterEnergyBase::~FilterEnergyBase ( )

Definition at line 92 of file FilterEnergyBase.cpp.

93 {
94 
95 }

Member Function Documentation

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

Implements Nektar::SolverUtils::Filter.

Definition at line 245 of file FilterEnergyBase.cpp.

References m_outFile.

248 {
249  m_outFile.close();
250 }
Array< OneD, NekDouble > Nektar::SolverUtils::FilterEnergyBase::v_GetDensity ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFld)
protectedvirtual

Reimplemented in Nektar::FilterEnergy.

Definition at line 265 of file FilterEnergyBase.cpp.

References ASSERTL0.

Referenced by v_Update().

267 {
268  ASSERTL0(false, "Needs to implemented by subclass");
269  return Array<OneD, NekDouble>();
270 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
void Nektar::SolverUtils::FilterEnergyBase::v_GetVelocity ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pField,
const int  i,
Array< OneD, NekDouble > &  velocity 
)
protectedvirtual

Reimplemented in Nektar::FilterEnergy, and Nektar::FilterEnergy.

Definition at line 257 of file FilterEnergyBase.cpp.

References ASSERTL0.

Referenced by v_Update().

261 {
262  ASSERTL0(false, "Needs to implemented by subclass");
263 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
void Nektar::SolverUtils::FilterEnergyBase::v_Initialise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pField,
const NekDouble time 
)
protectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 97 of file FilterEnergyBase.cpp.

References ASSERTL0, Nektar::MultiRegions::e3DH1D, Nektar::MultiRegions::e3DH2D, m_area, m_homogeneous, m_homogeneousLength, m_index, m_planes, and v_Update().

100 {
101  m_index = -1;
103 
104  ASSERTL0(pFields[0]->GetExpType() != MultiRegions::e3DH2D,
105  "Homogeneous 2D expansion not supported"
106  "for energy filter");
107 
108  if (pFields[0]->GetExpType() == MultiRegions::e3DH1D)
109  {
110  m_homogeneous = true;
111  }
112 
113  // Calculate area/volume of domain.
114  if (m_homogeneous)
115  {
116  m_planes = pFields[0]->GetZIDs();
117  areaField = pFields[0]->GetPlane(0);
118  }
119  else
120  {
121  areaField = pFields[0];
122  }
123 
124  Array<OneD, NekDouble> inarray(areaField->GetNpoints(), 1.0);
125  m_area = areaField->Integral(inarray);
126 
127  if (m_homogeneous)
128  {
130  }
131 
132  // Output values at initial time.
133  v_Update(pFields, time);
134 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
Array< OneD, unsigned int > m_planes
virtual SOLVER_UTILS_EXPORT void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const NekDouble &time)
boost::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
bool Nektar::SolverUtils::FilterEnergyBase::v_IsTimeDependent ( )
protectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 252 of file FilterEnergyBase.cpp.

253 {
254  return true;
255 }
void Nektar::SolverUtils::FilterEnergyBase::v_Update ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pField,
const NekDouble time 
)
protectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 136 of file FilterEnergyBase.cpp.

References m_area, m_comm, m_constDensity, m_homogeneous, m_index, m_outFile, m_outputFrequency, v_GetDensity(), v_GetVelocity(), Vmath::Vmul(), Vmath::Vsub(), Vmath::Vvtvp(), and Vmath::Zero().

Referenced by v_Initialise().

139 {
140  int i, nPoints = pFields[0]->GetNpoints();
141 
142  m_index++;
143 
144  if (m_index % m_outputFrequency > 0)
145  {
146  return;
147  }
148 
149  // Calculate kinetic energy.
150  NekDouble Ek = 0.0;
151  Array<OneD, NekDouble> tmp(nPoints, 0.0);
153  for (i = 0; i < 3; ++i)
154  {
155  u[i] = Array<OneD, NekDouble>(nPoints);
156 
157  v_GetVelocity(pFields, i, u[i]);
158 
159  if (m_homogeneous && pFields[i]->GetWaveSpace())
160  {
161  pFields[i]->HomogeneousBwdTrans(u[i], u[i]);
162  }
163 
164  Vmath::Vvtvp(nPoints, u[i], 1, u[i], 1, tmp, 1, tmp, 1);
165  }
166 
167  if (!m_constDensity)
168  {
169  Vmath::Vmul(nPoints, v_GetDensity(pFields), 1, tmp, 1, tmp, 1);
170  }
171 
172  if (m_homogeneous)
173  {
174  Array<OneD, NekDouble> tmp2(nPoints, 0.0);
175  pFields[0]->HomogeneousFwdTrans(tmp, tmp2);
176  Ek = pFields[0]->GetPlane(0)->Integral(tmp2) * 2.0 * M_PI;
177  }
178  else
179  {
180  Ek = pFields[0]->Integral(tmp);
181  }
182 
183  Ek /= 2.0 * m_area;
184 
185  if (m_comm->GetRank() == 0)
186  {
187  m_outFile << setw(17) << setprecision(8) << time
188  << setw(22) << setprecision(11) << Ek;
189  }
190 
191  bool waveSpace[3] = {
192  pFields[0]->GetWaveSpace(),
193  pFields[1]->GetWaveSpace(),
194  pFields[2]->GetWaveSpace()
195  };
196 
197  if (m_homogeneous)
198  {
199  for (i = 0; i < 3; ++i)
200  {
201  pFields[i]->SetWaveSpace(false);
202  }
203  }
204 
205  // First calculate vorticity field.
206  Array<OneD, NekDouble> tmp2(nPoints), tmp3(nPoints);
207  Vmath::Zero(nPoints, tmp, 1);
208  for (i = 0; i < 3; ++i)
209  {
210  int f1 = (i+2) % 3, c2 = f1;
211  int c1 = (i+1) % 3, f2 = c1;
212  pFields[f1]->PhysDeriv(c1, u[f1], tmp2);
213  pFields[f2]->PhysDeriv(c2, u[f2], tmp3);
214  Vmath::Vsub (nPoints, tmp2, 1, tmp3, 1, tmp2, 1);
215  Vmath::Vvtvp(nPoints, tmp2, 1, tmp2, 1, tmp, 1, tmp, 1);
216  }
217 
218  if (!m_constDensity)
219  {
220  Vmath::Vmul(nPoints, v_GetDensity(pFields), 1, tmp, 1, tmp, 1);
221  }
222 
223  if (m_homogeneous)
224  {
225  for (i = 0; i < 3; ++i)
226  {
227  pFields[i]->SetWaveSpace(waveSpace[i]);
228  }
229  pFields[0]->HomogeneousFwdTrans(tmp, tmp);
230  Ek = pFields[0]->GetPlane(0)->Integral(tmp) * 2 * M_PI;
231  }
232  else
233  {
234  Ek = pFields[0]->Integral(tmp);
235  }
236 
237  Ek /= 2.0*m_area;
238 
239  if (m_comm->GetRank() == 0)
240  {
241  m_outFile << setw(22) << setprecision(11) << Ek << endl;
242  }
243 }
virtual SOLVER_UTILS_EXPORT Array< OneD, NekDouble > v_GetDensity(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFld)
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.cpp:428
LibUtilities::CommSharedPtr m_comm
double NekDouble
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.cpp:329
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:359
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.cpp:169
virtual SOLVER_UTILS_EXPORT void v_GetVelocity(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pField, const int i, Array< OneD, NekDouble > &velocity)

Member Data Documentation

NekDouble Nektar::SolverUtils::FilterEnergyBase::m_area
private

Definition at line 79 of file FilterEnergyBase.h.

Referenced by v_Initialise(), and v_Update().

LibUtilities::CommSharedPtr Nektar::SolverUtils::FilterEnergyBase::m_comm
private

Definition at line 80 of file FilterEnergyBase.h.

Referenced by FilterEnergyBase(), and v_Update().

bool Nektar::SolverUtils::FilterEnergyBase::m_constDensity
private

Definition at line 82 of file FilterEnergyBase.h.

Referenced by v_Update().

bool Nektar::SolverUtils::FilterEnergyBase::m_homogeneous
private

Definition at line 77 of file FilterEnergyBase.h.

Referenced by v_Initialise(), and v_Update().

NekDouble Nektar::SolverUtils::FilterEnergyBase::m_homogeneousLength
private

Definition at line 78 of file FilterEnergyBase.h.

Referenced by FilterEnergyBase(), and v_Initialise().

unsigned int Nektar::SolverUtils::FilterEnergyBase::m_index
private

Definition at line 74 of file FilterEnergyBase.h.

Referenced by v_Initialise(), and v_Update().

std::ofstream Nektar::SolverUtils::FilterEnergyBase::m_outFile
private

Definition at line 76 of file FilterEnergyBase.h.

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

unsigned int Nektar::SolverUtils::FilterEnergyBase::m_outputFrequency
private

Definition at line 75 of file FilterEnergyBase.h.

Referenced by FilterEnergyBase(), and v_Update().

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

Definition at line 81 of file FilterEnergyBase.h.

Referenced by v_Initialise().