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)
 
virtual ~ProcessPowerSpectrum ()
 
virtual void v_Process (po::variables_map &vm) override
 Write mesh to output file. More...
 
virtual std::string v_GetModuleName () override
 
virtual std::string v_GetModuleDescription () override
 
virtual 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 ()
 
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 ()
 
- 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 49 of file ProcessPowerSpectrum.h.

Constructor & Destructor Documentation

◆ ProcessPowerSpectrum()

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

Definition at line 55 of file ProcessPowerSpectrum.cpp.

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

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

◆ ~ProcessPowerSpectrum()

Nektar::FieldUtils::ProcessPowerSpectrum::~ProcessPowerSpectrum ( )
virtual

Definition at line 63 of file ProcessPowerSpectrum.cpp.

64{
65}

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 53 of file ProcessPowerSpectrum.h.

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

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

◆ v_GetModuleDescription()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 70 of file ProcessPowerSpectrum.h.

71 {
72 return "Output power spectrum at given regions";
73 }

◆ v_GetModuleName()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 65 of file ProcessPowerSpectrum.h.

66 {
67 return "ProcessPowerSpectrum";
68 }

◆ v_GetModulePriority()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 75 of file ProcessPowerSpectrum.h.

76 {
77 return eModifyExp;
78 }

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 67 of file ProcessPowerSpectrum.cpp.

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

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.
Definition: NekFactory.hpp:198
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49

Definition at line 57 of file ProcessPowerSpectrum.h.