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

This processing module calculates the gradient and adds it as an extra-field to the output file. More...

#include <ProcessGrad.h>

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

Public Member Functions

 ProcessGrad (FieldSharedPtr f)
 
 ~ProcessGrad () 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
 

Protected Member Functions

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
 
- 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 ()
 

Private Member Functions

void ParserOptions (std::set< int > &variables, std::set< int > &directions)
 
void ProcessCartesianFld (Array< OneD, Array< OneD, NekDouble > > &grad)
 
void ProcessMappingFld (Array< OneD, Array< OneD, NekDouble > > &grad)
 

Private Attributes

std::set< int > m_selectedVars
 
std::set< int > m_directions
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- 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 calculates the gradient and adds it as an extra-field to the output file.

Definition at line 47 of file ProcessGrad.h.

Constructor & Destructor Documentation

◆ ProcessGrad()

Nektar::FieldUtils::ProcessGrad::ProcessGrad ( FieldSharedPtr  f)

Definition at line 53 of file ProcessGrad.cpp.

53 : ProcessModule(f)
54{
55 m_config["vars"] = ConfigOption(false, "NotSet", "Select variables");
56 m_config["dirs"] = ConfigOption(false, "NotSet", "Select directions");
57}
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272

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

◆ ~ProcessGrad()

Nektar::FieldUtils::ProcessGrad::~ProcessGrad ( )
override

Definition at line 59 of file ProcessGrad.cpp.

60{
61}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 51 of file ProcessGrad.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().

◆ ParserOptions()

void Nektar::FieldUtils::ProcessGrad::ParserOptions ( std::set< int > &  variables,
std::set< int > &  directions 
)
private

Definition at line 63 of file ProcessGrad.cpp.

65{
66 if (m_config["vars"].as<string>().compare("NotSet"))
67 {
68 ParseUtils::GenerateVariableSet(m_config["vars"].as<string>(),
69 m_f->m_variables, variables);
70 }
71 else
72 {
73 for (int v = 0; v < m_f->m_variables.size(); ++v)
74 {
75 variables.insert(v);
76 }
77 }
78 vector<string> coords = {"x", "y", "z"};
79 int spacedim = m_f->m_numHomogeneousDir + m_f->m_graph->GetMeshDimension();
80 coords.resize(spacedim);
81 if (m_config["dirs"].as<string>().compare("NotSet"))
82 {
83 ParseUtils::GenerateVariableSet(m_config["dirs"].as<string>(), coords,
84 directions);
85 }
86 else
87 {
88 for (int d = 0; d < spacedim; ++d)
89 {
90 directions.insert(d);
91 }
92 }
93}
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
std::vector< double > d(NPUPPER *NPUPPER)

References Nektar::UnitTests::d(), Nektar::ParseUtils::GenerateVariableSet(), Nektar::FieldUtils::Module::m_config, and Nektar::FieldUtils::Module::m_f.

Referenced by v_Process().

◆ ProcessCartesianFld()

void Nektar::FieldUtils::ProcessGrad::ProcessCartesianFld ( Array< OneD, Array< OneD, NekDouble > > &  grad)
private

Definition at line 95 of file ProcessGrad.cpp.

96{
97 // Calculate Gradient
98 int n = 0;
99 for (int i : m_selectedVars)
100 {
101 for (int j : m_directions)
102 {
103 m_f->m_exp[i]->PhysDeriv(MultiRegions::DirCartesianMap[j],
104 m_f->m_exp[i]->GetPhys(), grad[n]);
105 ++n;
106 }
107 }
108}
std::set< int > m_selectedVars
Definition: ProcessGrad.h:83
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:87

References Nektar::MultiRegions::DirCartesianMap, m_directions, Nektar::FieldUtils::Module::m_f, and m_selectedVars.

Referenced by v_Process().

◆ ProcessMappingFld()

void Nektar::FieldUtils::ProcessGrad::ProcessMappingFld ( Array< OneD, Array< OneD, NekDouble > > &  grad)
private

Definition at line 110 of file ProcessGrad.cpp.

111{
112 int expdim = m_f->m_graph->GetMeshDimension();
113 int spacedim = m_f->m_numHomogeneousDir + expdim;
114 int nfields = m_f->m_variables.size();
115 bool hasvel = m_selectedVars.size() && (*m_selectedVars.begin() < spacedim);
116
117 int npoints = m_f->m_exp[0]->GetNpoints();
118
119 Array<OneD, Array<OneD, NekDouble>> tmp(spacedim);
120 for (int i = 0; i < spacedim; i++)
121 {
122 tmp[i] = Array<OneD, NekDouble>(npoints);
123 }
124
125 // Get mapping
127
128 // Get velocity and convert to Cartesian system,
129 // if it is still in transformed system
130 Array<OneD, Array<OneD, NekDouble>> vel(spacedim);
131 if (hasvel && m_f->m_fieldMetaDataMap.count("MappingCartesianVel"))
132 {
133 if (m_f->m_fieldMetaDataMap["MappingCartesianVel"] == "False")
134 {
135 // Initialize arrays and copy velocity
136 for (int i = 0; i < spacedim; ++i)
137 {
138 vel[i] = Array<OneD, NekDouble>(npoints);
139 if (m_f->m_exp[0]->GetWaveSpace())
140 {
141 m_f->m_exp[0]->HomogeneousBwdTrans(
142 npoints, m_f->m_exp[i]->GetPhys(), vel[i]);
143 }
144 else
145 {
146 Vmath::Vcopy(npoints, m_f->m_exp[i]->GetPhys(), 1, vel[i],
147 1);
148 }
149 }
150 // Convert velocity to cartesian system
151 mapping->ContravarToCartesian(vel, vel);
152 // Convert back to wavespace if necessary
153 if (m_f->m_exp[0]->GetWaveSpace())
154 {
155 for (int i = 0; i < spacedim; ++i)
156 {
157 m_f->m_exp[0]->HomogeneousFwdTrans(npoints, vel[i], vel[i]);
158 }
159 }
160 }
161 else
162 {
163 for (int i = 0; i < spacedim; ++i)
164 {
165 vel[i] = Array<OneD, NekDouble>(npoints);
166 Vmath::Vcopy(npoints, m_f->m_exp[i]->GetPhys(), 1, vel[i], 1);
167 }
168 }
169 }
170 else if (hasvel)
171 {
172 for (int i = 0; i < spacedim && i < nfields; ++i)
173 {
174 vel[i] = Array<OneD, NekDouble>(npoints);
175 Vmath::Vcopy(npoints, m_f->m_exp[i]->GetPhys(), 1, vel[i], 1);
176 }
177 }
178
179 // Calculate Gradient
180 int n = 0;
181 for (int i : m_selectedVars)
182 {
183 for (int j = 0; j < spacedim; ++j)
184 {
185 if (i < spacedim)
186 {
187 m_f->m_exp[i]->PhysDeriv(MultiRegions::DirCartesianMap[j],
188 vel[i], tmp[j]);
189 }
190 else
191 {
192 m_f->m_exp[i]->PhysDeriv(MultiRegions::DirCartesianMap[j],
193 m_f->m_exp[i]->GetPhys(), tmp[j]);
194 }
195 }
196 mapping->CovarToCartesian(tmp, tmp);
197 for (int j : m_directions)
198 {
199 Vmath::Vcopy(npoints, tmp[j], 1, grad[n], 1);
200 ++n;
201 }
202 }
203}
static GlobalMapping::MappingSharedPtr GetMapping(FieldSharedPtr f)
GLOBAL_MAPPING_EXPORT typedef std::shared_ptr< Mapping > MappingSharedPtr
A shared pointer to a Mapping object.
Definition: Mapping.h:51
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825

References Nektar::MultiRegions::DirCartesianMap, Nektar::FieldUtils::ProcessMapping::GetMapping(), m_directions, Nektar::FieldUtils::Module::m_f, m_selectedVars, Nektar::GlobalMapping::MappingSharedPtr, and Vmath::Vcopy().

Referenced by v_Process().

◆ v_GetModuleDescription()

std::string Nektar::FieldUtils::ProcessGrad::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 69 of file ProcessGrad.h.

70 {
71 return "Calculating gradients";
72 }

◆ v_GetModuleName()

std::string Nektar::FieldUtils::ProcessGrad::v_GetModuleName ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 64 of file ProcessGrad.h.

65 {
66 return "ProcessGrad";
67 }

◆ v_GetModulePriority()

ModulePriority Nektar::FieldUtils::ProcessGrad::v_GetModulePriority ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 74 of file ProcessGrad.h.

75 {
76 return eModifyExp;
77 }

References Nektar::FieldUtils::eModifyExp.

◆ v_Process()

void Nektar::FieldUtils::ProcessGrad::v_Process ( po::variables_map &  vm)
overrideprotectedvirtual

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 205 of file ProcessGrad.cpp.

206{
207 m_f->SetUpExp(vm);
209
210 int nfields = m_f->m_variables.size();
211 int addfields = m_selectedVars.size() * m_directions.size();
212 m_f->m_exp.resize(nfields + addfields);
213
214 vector<string> coords = {"x", "y", "z"};
215 for (int i : m_selectedVars)
216 {
217 for (int j : m_directions)
218 {
219 m_f->m_variables.push_back(m_f->m_variables[i] + "_" + coords[j]);
220 }
221 }
222
223 // Skip in case of empty partition
224 if (m_f->m_exp[0]->GetNumElmts() == 0)
225 {
226 return;
227 }
228
229 int npoints = m_f->m_exp[0]->GetNpoints();
230 Array<OneD, Array<OneD, NekDouble>> grad(addfields);
231 for (int i = 0; i < addfields; ++i)
232 {
233 grad[i] = Array<OneD, NekDouble>(npoints);
234 }
235
236 if (m_f->m_fieldMetaDataMap.count("MappingType"))
237 {
238 ProcessMappingFld(grad);
239 }
240 else
241 {
243 }
244
245 for (int i = 0; i < addfields; ++i)
246 {
247 m_f->m_exp[nfields + i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
248
249 Vmath::Vcopy(npoints, grad[i], 1, m_f->m_exp[nfields + i]->UpdatePhys(),
250 1);
251 m_f->m_exp[nfields + i]->FwdTransLocalElmt(
252 grad[i], m_f->m_exp[nfields + i]->UpdateCoeffs());
253 }
254}
void ProcessMappingFld(Array< OneD, Array< OneD, NekDouble > > &grad)
void ParserOptions(std::set< int > &variables, std::set< int > &directions)
Definition: ProcessGrad.cpp:63
void ProcessCartesianFld(Array< OneD, Array< OneD, NekDouble > > &grad)
Definition: ProcessGrad.cpp:95

References m_directions, Nektar::FieldUtils::Module::m_f, m_selectedVars, ParserOptions(), ProcessCartesianFld(), ProcessMappingFld(), and Vmath::Vcopy().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessGrad::className
static
Initial value:
"Computes gradient of fields.")
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Definition: ProcessGrad.h:51
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 ProcessGrad.h.

◆ m_directions

std::set<int> Nektar::FieldUtils::ProcessGrad::m_directions
private

Definition at line 84 of file ProcessGrad.h.

Referenced by ProcessCartesianFld(), ProcessMappingFld(), and v_Process().

◆ m_selectedVars

std::set<int> Nektar::FieldUtils::ProcessGrad::m_selectedVars
private

Definition at line 83 of file ProcessGrad.h.

Referenced by ProcessCartesianFld(), ProcessMappingFld(), and v_Process().