Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Nektar::FieldUtils::ProcessPowerSpectrum Class Reference

This processing module outputs power spectrum at given regions for a 3DH1D fields. More...

#include <ProcessPowerSpectrum.h>

Inheritance diagram for Nektar::FieldUtils::ProcessPowerSpectrum:
[legend]

Public Member Functions

 ProcessPowerSpectrum (FieldSharedPtr f)
 
 ~ProcessPowerSpectrum () override
 
void v_Process (po::variables_map &vm) override
 Write mesh to output file. More...
 
std::string v_GetModuleName () override
 
std::string v_GetModuleDescription () override
 
ModulePriority v_GetModulePriority () override
 
- Public Member Functions inherited from Nektar::FieldUtils::ProcessModule
 ProcessModule ()
 
 ProcessModule (FieldSharedPtr p_f)
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
virtual ~Module ()=default
 
void Process (po::variables_map &vm)
 
std::string GetModuleName ()
 
std::string GetModuleDescription ()
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
std::vector< ModuleKeyGetModulePrerequisites ()
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::string value="")
 Register a configuration option with a module. More...
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
FIELD_UTILS_EXPORT void AddFile (std::string fileType, std::string fileName)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static std::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey className
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
virtual void v_Process (po::variables_map &vm)
 
virtual std::string v_GetModuleName ()
 
virtual std::string v_GetModuleDescription ()
 
virtual ModulePriority v_GetModulePriority ()
 
virtual std::vector< ModuleKeyv_GetModulePrerequisites ()
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 
std::set< std::string > m_allowedFiles
 List of allowed file formats. More...
 

Detailed Description

This processing module outputs power spectrum at given regions for a 3DH1D fields.

Definition at line 47 of file ProcessPowerSpectrum.h.

Constructor & Destructor Documentation

◆ ProcessPowerSpectrum()

Nektar::FieldUtils::ProcessPowerSpectrum::ProcessPowerSpectrum ( FieldSharedPtr  f)

Definition at line 52 of file ProcessPowerSpectrum.cpp.

52 : ProcessModule(f)
53{
54 m_config["box"] =
55 ConfigOption(false, "NotSet",
56 "Specify a rectangular box by box=xmin,xmax,ymin,ymax");
57 m_config["vars"] = ConfigOption(false, "NotSet", "signal variable");
58}
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272

References Nektar::FieldUtils::Module::m_config.

◆ ~ProcessPowerSpectrum()

Nektar::FieldUtils::ProcessPowerSpectrum::~ProcessPowerSpectrum ( )
override

Definition at line 60 of file ProcessPowerSpectrum.cpp.

61{
62}

Member Function Documentation

◆ create()

static std::shared_ptr< Module > Nektar::FieldUtils::ProcessPowerSpectrum::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 51 of file ProcessPowerSpectrum.h.

52 {
54 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

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

◆ v_GetModuleDescription()

std::string Nektar::FieldUtils::ProcessPowerSpectrum::v_GetModuleDescription ( )
inlineoverridevirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 68 of file ProcessPowerSpectrum.h.

69 {
70 return "Output power spectrum at given regions";
71 }

◆ v_GetModuleName()

std::string Nektar::FieldUtils::ProcessPowerSpectrum::v_GetModuleName ( )
inlineoverridevirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 63 of file ProcessPowerSpectrum.h.

64 {
65 return "ProcessPowerSpectrum";
66 }

◆ v_GetModulePriority()

ModulePriority Nektar::FieldUtils::ProcessPowerSpectrum::v_GetModulePriority ( )
inlineoverridevirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 73 of file ProcessPowerSpectrum.h.

74 {
75 return eModifyExp;
76 }

References Nektar::FieldUtils::eModifyExp.

◆ v_Process()

void Nektar::FieldUtils::ProcessPowerSpectrum::v_Process ( po::variables_map &  vm)
overridevirtual

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 64 of file ProcessPowerSpectrum.cpp.

65{
66 m_f->SetUpExp(vm);
67
68 ASSERTL0(m_f->m_numHomogeneousDir == 1,
69 "ProcessPowerSpectrum only works for Homogeneous1D fields.");
70 // Skip in case of empty partition
71 if (m_f->m_exp[0]->GetNumElmts() == 0)
72 {
73 return;
74 }
75
76 std::set<int> variables;
77 if (m_config["vars"].as<string>().compare("NotSet") != 0)
78 {
79 ParseUtils::GenerateVariableSet(m_config["vars"].as<string>(),
80 m_f->m_variables, variables);
81 }
82 ASSERTL0(variables.size() >= 1,
83 "At least one variable should be selected.");
84 if (variables.empty())
85 {
86 return;
87 }
88 std::vector<NekDouble> box;
89 if (m_config["box"].as<string>().compare("NotSet") != 0)
90 {
91 ASSERTL0(ParseUtils::GenerateVector(m_config["box"].as<string>(), box),
92 "Failed to interpret box string");
94 box.size() >= 4,
95 "box string should contain at least 4 values xmin,xmax,ymin,ymax");
96 }
97 box.resize(4, 0.);
98 if (m_f->m_comm->GetSpaceComm()->GetRank() == 0)
99 {
100
101 cout << "Processing frequency spectra of variables (";
102 for (auto nsignal : variables)
103 {
104 cout << m_f->m_variables[nsignal] << ", ";
105 }
106 cout << ") in box [" << box[0] << ", " << box[1] << "]X[" << box[2]
107 << ", " << box[3] << "].\n";
108 }
109
110 for (auto nsignal : variables)
111 {
112 m_f->m_exp[nsignal]->SetWaveSpace(true);
113 m_f->m_exp[nsignal]->BwdTrans(m_f->m_exp[nsignal]->GetCoeffs(),
114 m_f->m_exp[nsignal]->UpdatePhys());
115 }
116
117 int nplanes = m_f->m_exp[0]->GetZIDs().size();
118 NekDouble lz = m_f->m_exp[0]->GetHomoLen();
119 MultiRegions::ExpListSharedPtr plane0 = m_f->m_exp[0]->GetPlane(0);
120 int ntot = plane0->GetNpoints();
121 Array<OneD, NekDouble> masks(ntot, 0.);
122 for (size_t i = 0; i < plane0->GetExpSize(); ++i)
123 {
124 LocalRegions::ExpansionSharedPtr exp = plane0->GetExp(i);
125 SpatialDomains::GeometrySharedPtr geom = exp->GetGeom();
126 int nv = geom->GetNumVerts();
127 NekDouble gc[3] = {0., 0., 0.};
128 NekDouble gct[3] = {0., 0., 0.};
129 for (size_t j = 0; j < nv; ++j)
130 {
131 SpatialDomains::PointGeomSharedPtr vertex = geom->GetVertex(j);
132 vertex->GetCoords(gct[0], gct[1], gct[2]);
133 gc[0] += gct[0] / NekDouble(nv);
134 gc[1] += gct[1] / NekDouble(nv);
135 }
136 if (box[0] <= gc[0] && gc[0] <= box[1] && box[2] <= gc[1] &&
137 gc[1] <= box[3])
138 {
139 Vmath::Fill(exp->GetTotPoints(), 1.,
140 &masks[plane0->GetPhys_Offset(i)], 1);
141 }
142 }
143 NekDouble area = m_f->m_exp[0]->GetPlane(0)->Integral(masks);
144 m_f->m_comm->GetSpaceComm()->AllReduce(area, LibUtilities::ReduceMax);
145 if (area <= NekConstants::kNekZeroTol)
146 {
147 area = 1.;
148 }
149
150 Array<OneD, NekDouble> value(nplanes / 2, 0.);
151 for (size_t m = 0; m < value.size(); ++m)
152 {
153 for (auto nsignal : variables)
154 {
155 Array<OneD, NekDouble> wavecoef(ntot, 0.);
156 Vmath::Vvtvp(ntot, m_f->m_exp[nsignal]->GetPlane(2 * m)->GetPhys(),
157 1, m_f->m_exp[nsignal]->GetPlane(2 * m)->GetPhys(), 1,
158 wavecoef, 1, wavecoef, 1);
159 Vmath::Vvtvp(ntot,
160 m_f->m_exp[nsignal]->GetPlane(2 * m + 1)->GetPhys(), 1,
161 m_f->m_exp[nsignal]->GetPlane(2 * m + 1)->GetPhys(), 1,
162 wavecoef, 1, wavecoef, 1);
163 Vmath::Vmul(ntot, wavecoef, 1, masks, 1, wavecoef, 1);
164 if (m > 0)
165 {
166 Vmath::Smul(ntot, 0.25, wavecoef, 1, wavecoef, 1);
167 }
168 value[m] += m_f->m_exp[0]->GetPlane(2 * m)->Integral(wavecoef);
169 }
170 }
171 m_f->m_comm->GetSpaceComm()->AllReduce(value, LibUtilities::ReduceMax);
172 if (m_f->m_comm->GetSpaceComm()->GetRank() == 0)
173 {
174 NekDouble energy = 0.;
175 ofstream powersp("spectra.dat");
176 powersp << "variables = lambda beta energy" << endl;
177 for (size_t m = 1; m < value.size(); ++m)
178 {
179 powersp << (lz / m) << " " << (2. * M_PI * m / lz) << " "
180 << value[m] << endl;
181 energy += value[m] * value[m];
182 }
183 powersp.close();
184 if (vm.count("error"))
185 {
186 cout << "L 2 error (variable E) : " << energy << endl;
187 }
188 }
189
190 int nfields = m_f->m_variables.size();
191 m_f->m_exp.resize(nfields + 1);
192 m_f->m_variables.push_back("regions");
193 m_f->m_exp[nfields] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
194 for (size_t m = 0; m < nplanes; ++m)
195 {
196 Vmath::Vcopy(ntot, masks, 1,
197 m_f->m_exp[nfields]->GetPlane(m)->UpdatePhys(), 1);
198 }
199 m_f->m_exp[nfields]->FwdTrans(m_f->m_exp[nfields]->GetPhys(),
200 m_f->m_exp[nfields]->UpdateCoeffs());
201}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
static bool GenerateVariableSet(const std::string &str, const std::vector< std::string > &variables, std::set< int > &out)
Generate a set of variable locations.
Definition: ParseUtils.cpp:168
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Definition: ParseUtils.cpp:130
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:66
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
static const NekDouble kNekZeroTol
std::shared_ptr< PointGeom > PointGeomSharedPtr
Definition: Geometry.h:57
std::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:51
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 Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.hpp:100
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.hpp:54
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825

References ASSERTL0, Vmath::Fill(), Nektar::ParseUtils::GenerateVariableSet(), Nektar::ParseUtils::GenerateVector(), Nektar::NekConstants::kNekZeroTol, Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, Nektar::LibUtilities::ReduceMax, Vmath::Smul(), Vmath::Vcopy(), Vmath::Vmul(), and Vmath::Vvtvp().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessPowerSpectrum::className
static
Initial value:
=
ModuleKey(eProcessModule, "powerspectrum"),
"Output power spectrum at given regions from a 3DH1D expansion.")
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47

Definition at line 55 of file ProcessPowerSpectrum.h.