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

#include <FilterHilbertFFTPhase.h>

Inheritance diagram for Nektar::FilterHilbertFFTPhase:
[legend]

Public Member Functions

 FilterHilbertFFTPhase (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< SolverUtils::EquationSystem > &pEquation, const ParamMap &pParams)
 
 ~FilterHilbertFFTPhase () override
 
- 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 SolverUtils::FilterSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_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

void v_Initialise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
 
void v_Update (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
 
void v_Finalise (const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, 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

unsigned int m_index
 
unsigned int m_outputIndex
 
unsigned int vCounter
 
unsigned int m_outputFrequency
 
int m_window
 
unsigned int m_overlap
 
bool linear_trans = true
 
bool provided_mean = false
 
std::string m_outputFile
 
LibUtilities::FieldIOSharedPtr m_fld
 
unsigned int npoints
 
NekDouble m_TimeStep
 
double m_mean
 
Array< OneD, NekDoubleoldV
 
Array< OneD, NekDoubleoldV_zero_mean
 
Array< OneD, NekDoublefcoef
 
Array< OneD, NekDoubleh
 
Array< OneD, NekDoubleoverlap_phase
 
fftw_plan plan_forward
 
fftw_plan plan_backward
 

Friends

class MemoryManager< FilterHilbertFFTPhase >
 

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

Definition at line 45 of file FilterHilbertFFTPhase.h.

Constructor & Destructor Documentation

◆ FilterHilbertFFTPhase()

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

Definition at line 44 of file FilterHilbertFFTPhase.cpp.

48 : Filter(pSession, pEquation)
49{
50 if (pParams.find("OutputFile") == pParams.end())
51 {
52 m_outputFile = m_session->GetSessionName();
53 }
54 else
55 {
56 ASSERTL0(!(pParams.find("OutputFile")->second.empty()),
57 "Missing parameter 'OutputFile'.");
58 m_outputFile = pParams.find("OutputFile")->second;
59 }
60
61 ASSERTL0(pParams.find("OutputFrequency") != pParams.end(),
62 "Missing parameter 'OutputFrequency'."); // Sampling frequency =
63 // per number of timesteps
64 LibUtilities::Equation equ(m_session->GetInterpreter(),
65 pParams.find("OutputFrequency")->second);
66 m_outputFrequency = floor(equ.Evaluate());
67
68 ASSERTL0(pParams.find("WindowSize") != pParams.end(),
69 "Missing parameter 'WindowSize'.");
70 LibUtilities::Equation equ1(m_session->GetInterpreter(),
71 pParams.find("WindowSize")->second);
72 m_window = floor(equ1.Evaluate()); // No. of output steps taken in each FFT
73 ASSERTL0(m_window % 2 == 0, "'WindowSize' must be even.");
74
75 ASSERTL0(pParams.find("OverlapSize") != pParams.end(),
76 "Missing parameter 'OverlapSize'.");
77 LibUtilities::Equation equ2(m_session->GetInterpreter(),
78 pParams.find("OverlapSize")->second);
79 m_overlap = floor(equ2.Evaluate());
81 "'OverlapSize' must be smaller than 'WindowSize'.");
82
83 if (pParams.find("MeanV") != pParams.end())
84 {
85 provided_mean = true;
86 LibUtilities::Equation equ3(m_session->GetInterpreter(),
87 pParams.find("MeanV")->second);
88 m_mean = equ3.Evaluate();
89 }
90
91 if (pParams.find("LinearTransitionOverlap") != pParams.end())
92 {
94 (pParams.find("LinearTransitionOverlap")->second == "true");
95 }
96
97 m_outputIndex = 0;
98 m_index = 0;
99
101}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
LibUtilities::FieldIOSharedPtr m_fld
static std::shared_ptr< FieldIO > CreateDefault(const LibUtilities::SessionReaderSharedPtr session)
Returns an object for the default FieldIO method.
Definition: FieldIO.cpp:195
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::FieldIO::CreateDefault(), Nektar::LibUtilities::Equation::Evaluate(), linear_trans, m_fld, m_index, m_mean, m_outputFile, m_outputFrequency, m_outputIndex, m_overlap, Nektar::SolverUtils::Filter::m_session, m_window, and provided_mean.

◆ ~FilterHilbertFFTPhase()

Nektar::FilterHilbertFFTPhase::~FilterHilbertFFTPhase ( )
override

Definition at line 103 of file FilterHilbertFFTPhase.cpp.

104{
105}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 51 of file FilterHilbertFFTPhase.h.

55 {
58 pSession, pEquation, pParams);
59 return p;
60 }
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::FilterHilbertFFTPhase::v_Finalise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 293 of file FilterHilbertFFTPhase.cpp.

297{
298}

◆ v_Initialise()

void Nektar::FilterHilbertFFTPhase::v_Initialise ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 107 of file FilterHilbertFFTPhase.cpp.

110{
111 m_index = 0;
112 m_outputIndex = 0;
113 vCounter = 0;
114
115 m_TimeStep = pFields[0]->GetSession()->GetParameter("TimeStep");
116
117 npoints = pFields[0]->GetPhys().size();
118 oldV = Array<OneD, NekDouble>(npoints * m_window);
119 oldV_zero_mean = Array<OneD, NekDouble>(npoints * m_window);
120 fcoef = Array<OneD, NekDouble>(npoints * m_window);
121 h = Array<OneD, NekDouble>(npoints * m_window);
122 overlap_phase = Array<OneD, NekDouble>(npoints * m_overlap);
123 std::fill_n(&overlap_phase[0], npoints * m_overlap, 0.0);
124
125 // Initialise FFTW
126 fftw_r2r_kind *fwd_kind = new fftw_r2r_kind[npoints];
127 std::fill_n(fwd_kind, npoints, FFTW_R2HC);
128 plan_forward = fftw_plan_many_r2r(
130 &fcoef[0], &m_window, npoints, 1, &fwd_kind[0], FFTW_ESTIMATE);
131
132 fftw_r2r_kind *bwd_kind = new fftw_r2r_kind[npoints];
133 std::fill_n(bwd_kind, npoints, FFTW_HC2R);
134 plan_backward = fftw_plan_many_r2r(1, &m_window, npoints, &fcoef[0],
135 &m_window, npoints, 1, &h[0], &m_window,
136 npoints, 1, &bwd_kind[0], FFTW_ESTIMATE);
137
138 delete[] fwd_kind;
139 delete[] bwd_kind;
140 v_Update(pFields, 0.0);
141}
Array< OneD, NekDouble > overlap_phase
void v_Update(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
Array< OneD, NekDouble > oldV_zero_mean
Array< OneD, NekDouble > fcoef

References fcoef, h, m_index, m_outputIndex, m_overlap, m_TimeStep, m_window, npoints, oldV, oldV_zero_mean, overlap_phase, plan_backward, plan_forward, v_Update(), and vCounter.

◆ v_IsTimeDependent()

bool Nektar::FilterHilbertFFTPhase::v_IsTimeDependent ( )
overrideprotectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 300 of file FilterHilbertFFTPhase.cpp.

301{
302 return true;
303}

◆ v_Update()

void Nektar::FilterHilbertFFTPhase::v_Update ( const Array< OneD, const MultiRegions::ExpListSharedPtr > &  pFields,
const NekDouble time 
)
overrideprotectedvirtual

Implements Nektar::SolverUtils::Filter.

Definition at line 143 of file FilterHilbertFFTPhase.cpp.

146{
147 if (m_index++ % m_outputFrequency > 0)
148 {
149 return;
150 }
151
152 // Store old data
153 Array<OneD, NekDouble> currentV = pFields[0]->GetPhys();
154 memcpy(&oldV[vCounter * npoints], &currentV[0],
155 npoints * sizeof(NekDouble));
156 vCounter++;
157
158 // Do Hilbert Transform and output phase
159 if (vCounter == m_window)
160 {
161 // Zero mean
162 if (!provided_mean)
163 {
164 for (int j = 0; j < npoints; ++j)
165 {
166 m_mean = 0.0;
167 for (int i = 0; i < m_window; ++i)
168 {
169 m_mean += oldV[i * npoints + j];
170 }
171 m_mean = m_mean / (double)m_window; // time-average
172
173 for (int i = 0; i < m_window; ++i)
174 {
175 oldV_zero_mean[i * npoints + j] =
176 oldV[i * npoints + j] - m_mean;
177 }
178 }
179 }
180 else // minus mean directly
181 {
182 for (int i = 0; i < npoints * m_window; ++i)
183 {
184 oldV_zero_mean[i] = oldV[i] - m_mean;
185 }
186 }
187
188 // Do Hilbert Transform:
189 fftw_execute(plan_forward);
190 // Rearrange out: imag->real, -real->imag
191 double tmp_fcoef;
192 for (int i = 1; i < m_window / 2; ++i)
193 {
194 for (int j = 0; j < npoints; ++j)
195 {
196 tmp_fcoef = -fcoef[i * npoints + j] / m_window;
197 fcoef[i * npoints + j] =
198 fcoef[(m_window - i) * npoints + j] / m_window;
199 fcoef[(m_window - i) * npoints + j] = tmp_fcoef;
200 }
201 }
202 std::fill_n(&fcoef[0], npoints, 0.0);
203 std::fill_n(&fcoef[(m_window / 2) * npoints], npoints, 0.0);
204 fftw_execute(plan_backward);
205
206 // Output batch
207 Array<OneD, NekDouble> phase_coeff(pFields[0]->GetNcoeffs());
208 Array<OneD, NekDouble> phase(npoints);
209
210 for (int t = 0; t < m_window - m_overlap; ++t)
211 {
212 std::stringstream vOutputFilename;
213 vOutputFilename << m_outputFile << "_" << m_outputIndex << ".chk";
214
215 // Get FieldDefinitions and allocate Fielddata
216 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
217 pFields[0]->GetFieldDefinitions();
218 std::vector<std::vector<NekDouble>> FieldData(FieldDef.size());
219
220 // Calculate phase
221 if (t < m_overlap)
222 {
223 if (linear_trans)
224 {
225 for (int i = 0; i < npoints; ++i)
226 {
227 phase[i] = ((double)(m_overlap - t) / m_overlap) *
228 overlap_phase[t * npoints + i] +
229 ((double)t / m_overlap) *
230 atan2(h[t * npoints + i],
231 oldV_zero_mean[t * npoints + i]);
232 }
233 }
234 else // simple average
235 {
236 for (int i = 0; i < npoints; ++i)
237 {
238 phase[i] = 0.5 * overlap_phase[t * npoints + i] +
239 0.5 * atan2(h[t * npoints + i],
240 oldV_zero_mean[t * npoints + i]);
241 }
242 }
243 }
244 else
245 {
246 for (int i = 0; i < npoints; ++i)
247 {
248 phase[i] = atan2(h[t * npoints + i],
249 oldV_zero_mean[t * npoints + i]);
250 }
251 }
252
253 // Convert to coefficient space
254 pFields[0]->FwdTransLocalElmt(phase, phase_coeff);
255
256 // for each item in FieldDef
257 // push "phase" to FieldDef[i]->m_fields
258 // call AppendFieldData(FieldDef[i], FieldData[i], data)
259 for (int i = 0; i < FieldDef.size(); ++i)
260 {
261 FieldDef[i]->m_fields.push_back("phase");
262 pFields[0]->AppendFieldData(FieldDef[i], FieldData[i],
263 phase_coeff);
264 }
265
266 // Update time in field info if required
267 LibUtilities::FieldMetaDataMap fieldMetaDataMap;
268 fieldMetaDataMap["Time"] = boost::lexical_cast<std::string>(
270
271 m_fld->Write(vOutputFilename.str(), FieldDef, FieldData,
272 fieldMetaDataMap);
274 }
275
276 // Save phase for next iter
277 for (int t = m_window - m_overlap; t < m_window; ++t)
278 {
279 for (int i = 0; i < npoints; ++i)
280 {
281 overlap_phase[(t - m_window + m_overlap) * npoints + i] =
282 atan2(h[t * npoints + i], oldV_zero_mean[t * npoints + i]);
283 }
284 }
285
286 // Move overlap part to front
287 memcpy(&oldV[0], &oldV[(m_window - m_overlap) * npoints],
288 npoints * m_overlap * sizeof(NekDouble));
290 }
291}
std::map< std::string, std::string > FieldMetaDataMap
Definition: FieldIO.h:50
double NekDouble

References fcoef, h, linear_trans, m_fld, m_index, m_mean, m_outputFile, m_outputFrequency, m_outputIndex, m_overlap, m_TimeStep, m_window, npoints, oldV, oldV_zero_mean, overlap_phase, plan_backward, plan_forward, provided_mean, and vCounter.

Referenced by v_Initialise().

Friends And Related Function Documentation

◆ MemoryManager< FilterHilbertFFTPhase >

friend class MemoryManager< FilterHilbertFFTPhase >
friend

Definition at line 1 of file FilterHilbertFFTPhase.h.

Member Data Documentation

◆ className

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

Name of the class.

Definition at line 63 of file FilterHilbertFFTPhase.h.

◆ fcoef

Array<OneD, NekDouble> Nektar::FilterHilbertFFTPhase::fcoef
private

Definition at line 106 of file FilterHilbertFFTPhase.h.

Referenced by v_Initialise(), and v_Update().

◆ h

Array<OneD, NekDouble> Nektar::FilterHilbertFFTPhase::h
private

Definition at line 107 of file FilterHilbertFFTPhase.h.

Referenced by v_Initialise(), and v_Update().

◆ linear_trans

bool Nektar::FilterHilbertFFTPhase::linear_trans = true
private

Definition at line 93 of file FilterHilbertFFTPhase.h.

Referenced by FilterHilbertFFTPhase(), and v_Update().

◆ m_fld

LibUtilities::FieldIOSharedPtr Nektar::FilterHilbertFFTPhase::m_fld
private

Definition at line 96 of file FilterHilbertFFTPhase.h.

Referenced by FilterHilbertFFTPhase(), and v_Update().

◆ m_index

unsigned int Nektar::FilterHilbertFFTPhase::m_index
private

Definition at line 85 of file FilterHilbertFFTPhase.h.

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

◆ m_mean

double Nektar::FilterHilbertFFTPhase::m_mean
private

Definition at line 103 of file FilterHilbertFFTPhase.h.

Referenced by FilterHilbertFFTPhase(), and v_Update().

◆ m_outputFile

std::string Nektar::FilterHilbertFFTPhase::m_outputFile
private

Definition at line 95 of file FilterHilbertFFTPhase.h.

Referenced by FilterHilbertFFTPhase(), and v_Update().

◆ m_outputFrequency

unsigned int Nektar::FilterHilbertFFTPhase::m_outputFrequency
private

Definition at line 90 of file FilterHilbertFFTPhase.h.

Referenced by FilterHilbertFFTPhase(), and v_Update().

◆ m_outputIndex

unsigned int Nektar::FilterHilbertFFTPhase::m_outputIndex
private

Definition at line 86 of file FilterHilbertFFTPhase.h.

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

◆ m_overlap

unsigned int Nektar::FilterHilbertFFTPhase::m_overlap
private

Definition at line 92 of file FilterHilbertFFTPhase.h.

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

◆ m_TimeStep

NekDouble Nektar::FilterHilbertFFTPhase::m_TimeStep
private

Definition at line 100 of file FilterHilbertFFTPhase.h.

Referenced by v_Initialise(), and v_Update().

◆ m_window

int Nektar::FilterHilbertFFTPhase::m_window
private

Definition at line 91 of file FilterHilbertFFTPhase.h.

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

◆ npoints

unsigned int Nektar::FilterHilbertFFTPhase::npoints
private

Definition at line 99 of file FilterHilbertFFTPhase.h.

Referenced by v_Initialise(), and v_Update().

◆ oldV

Array<OneD, NekDouble> Nektar::FilterHilbertFFTPhase::oldV
private

Definition at line 104 of file FilterHilbertFFTPhase.h.

Referenced by v_Initialise(), and v_Update().

◆ oldV_zero_mean

Array<OneD, NekDouble> Nektar::FilterHilbertFFTPhase::oldV_zero_mean
private

Definition at line 105 of file FilterHilbertFFTPhase.h.

Referenced by v_Initialise(), and v_Update().

◆ overlap_phase

Array<OneD, NekDouble> Nektar::FilterHilbertFFTPhase::overlap_phase
private

Definition at line 108 of file FilterHilbertFFTPhase.h.

Referenced by v_Initialise(), and v_Update().

◆ plan_backward

fftw_plan Nektar::FilterHilbertFFTPhase::plan_backward
private

Definition at line 111 of file FilterHilbertFFTPhase.h.

Referenced by v_Initialise(), and v_Update().

◆ plan_forward

fftw_plan Nektar::FilterHilbertFFTPhase::plan_forward
private

Definition at line 110 of file FilterHilbertFFTPhase.h.

Referenced by v_Initialise(), and v_Update().

◆ provided_mean

bool Nektar::FilterHilbertFFTPhase::provided_mean = false
private

Definition at line 94 of file FilterHilbertFFTPhase.h.

Referenced by FilterHilbertFFTPhase(), and v_Update().

◆ vCounter

unsigned int Nektar::FilterHilbertFFTPhase::vCounter
private

Definition at line 87 of file FilterHilbertFFTPhase.h.

Referenced by v_Initialise(), and v_Update().