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

This processing module combines two fld files containing average fields. More...

#include <ProcessCombineAvg.h>

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

Public Member Functions

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

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 combines two fld files containing average fields.

Definition at line 48 of file ProcessCombineAvg.h.

Constructor & Destructor Documentation

◆ ProcessCombineAvg()

Nektar::FieldUtils::ProcessCombineAvg::ProcessCombineAvg ( FieldSharedPtr  f)

Definition at line 52 of file ProcessCombineAvg.cpp.

52 : ProcessModule(f)
53{
54 m_config["fromfld"] =
55 ConfigOption(false, "NotSet", "Fld file form which to add field");
56}
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272

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

◆ ~ProcessCombineAvg()

Nektar::FieldUtils::ProcessCombineAvg::~ProcessCombineAvg ( )
override

Definition at line 58 of file ProcessCombineAvg.cpp.

59{
60}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 52 of file ProcessCombineAvg.h.

53 {
55 }
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::ProcessCombineAvg::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 70 of file ProcessCombineAvg.h.

71 {
72 return "Combining new fld into input avg fld";
73 }

◆ v_GetModuleName()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 65 of file ProcessCombineAvg.h.

66 {
67 return "ProcessCombineAvg";
68 }

◆ v_GetModulePriority()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 75 of file ProcessCombineAvg.h.

76 {
77 return eModifyExp;
78 }

References Nektar::FieldUtils::eModifyExp.

◆ v_Process()

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

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 62 of file ProcessCombineAvg.cpp.

63{
64 m_f->SetUpExp(vm);
65
66 // Skip in case of empty partition
67 if (m_f->m_exp[0]->GetNumElmts() == 0)
68 {
69 return;
70 }
71
72 ASSERTL0(m_config["fromfld"].as<string>().compare("NotSet") != 0,
73 "Need to specify fromfld=file.fld ");
74
75 int nfields = m_f->m_variables.size();
76 int nq = m_f->m_exp[0]->GetTotPoints();
77 int expdim = m_f->m_graph->GetMeshDimension();
78 int spacedim = expdim;
79 if ((m_f->m_numHomogeneousDir) == 1 || (m_f->m_numHomogeneousDir) == 2)
80 {
81 spacedim += m_f->m_numHomogeneousDir;
82 }
83
84 // Allocate storage for new field and correction (for Reynolds stress)
85 Array<OneD, Array<OneD, NekDouble>> fromPhys(nfields);
86 Array<OneD, Array<OneD, NekDouble>> correction(nfields);
87 for (int j = 0; j < nfields; ++j)
88 {
89 fromPhys[j] = Array<OneD, NekDouble>(nq, 0.0);
90 correction[j] = Array<OneD, NekDouble>(nq, 0.0);
91 }
92
93 string fromfld = m_config["fromfld"].as<string>();
94 FieldSharedPtr fromField = std::shared_ptr<Field>(new Field());
95 LibUtilities::FieldMetaDataMap fromFieldMetaDataMap;
96
97 // Set up ElementGIDs in case of parallel processing
98 Array<OneD, int> ElementGIDs(m_f->m_exp[0]->GetExpSize());
99 for (int i = 0; i < m_f->m_exp[0]->GetExpSize(); ++i)
100 {
101 ElementGIDs[i] = m_f->m_exp[0]->GetExp(i)->GetGeom()->GetGlobalID();
102 }
103 // Import fromfld file
104 m_f->FieldIOForFile(fromfld)->Import(fromfld, fromField->m_fielddef,
105 fromField->m_data,
106 fromFieldMetaDataMap, ElementGIDs);
107 ASSERTL0(fromField->m_fielddef[0]->m_fields.size() == nfields,
108 "Mismatch in number of fields");
109 // Extract data to fromPhys
110 for (int j = 0; j < nfields; ++j)
111 {
112 ASSERTL0(fromField->m_fielddef[0]->m_fields[j] == m_f->m_variables[j],
113 "Field names do not match.");
114
115 // load new field (overwrite m_f->m_exp coeffs for now)
116 for (int i = 0; i < fromField->m_data.size(); ++i)
117 {
118 m_f->m_exp[j]->ExtractDataToCoeffs(
119 fromField->m_fielddef[i], fromField->m_data[i],
120 m_f->m_variables[j], m_f->m_exp[j]->UpdateCoeffs());
121 }
122 m_f->m_exp[j]->BwdTrans(m_f->m_exp[j]->GetCoeffs(), fromPhys[j]);
123 }
124
125 // Load number of samples in each file
126 ASSERTL0(m_f->m_fieldMetaDataMap.count("NumberOfFieldDumps") != 0,
127 "Missing NumberOfFieldDumps metadata.");
128 ASSERTL0(fromFieldMetaDataMap.count("NumberOfFieldDumps") != 0,
129 "Missing NumberOfFieldDumps metadata.");
130 string s_num;
131 s_num = m_f->m_fieldMetaDataMap["NumberOfFieldDumps"];
132 int na = atoi(s_num.c_str());
133 s_num = fromFieldMetaDataMap["NumberOfFieldDumps"];
134 int nb = atoi(s_num.c_str());
135
136 // Look for Reynolds stresses
137 int stress = -1;
138 for (int j = 0; j < nfields; ++j)
139 {
140 if (m_f->m_variables[j] == "uu")
141 {
142 stress = j;
143 break;
144 }
145 }
146
147 // Calculate correction for Reynolds stresses
148 if (stress != -1)
149 {
150 Array<OneD, NekDouble> tmp(nq, 0.0);
151 int n = stress;
152 // Follow same numbering as FilterReynoldsStresses
153 for (int i = 0; i < spacedim; ++i)
154 {
155 for (int j = i; j < spacedim; ++j, ++n)
156 {
157 // correction is zero for averages and
158 // = (\bar{x_a}-\bar{x_b})*(\bar{y_a}-\bar{y_b})*na*nb/N
159 // for Reynolds stresses
160 NekDouble fac = ((NekDouble)(na * nb)) / ((NekDouble)(na + nb));
161 Vmath::Vsub(nq, m_f->m_exp[i]->GetPhys(), 1, fromPhys[i], 1,
162 correction[n], 1);
163 Vmath::Vsub(nq, m_f->m_exp[j]->GetPhys(), 1, fromPhys[j], 1,
164 tmp, 1);
165 Vmath::Vmul(nq, correction[n], 1, tmp, 1, correction[n], 1);
166 Vmath::Smul(nq, fac, correction[n], 1, correction[n], 1);
167 }
168 }
169 }
170 // Combine fields
171 for (int j = 0; j < nfields; ++j)
172 {
173 // The new value is: (x_a*na + x_b*nb + correction)/N
174 Vmath::Smul(nq, 1.0 * na, m_f->m_exp[j]->GetPhys(), 1,
175 m_f->m_exp[j]->UpdatePhys(), 1);
176 Vmath::Svtvp(nq, 1.0 * nb, fromPhys[j], 1, m_f->m_exp[j]->GetPhys(), 1,
177 m_f->m_exp[j]->UpdatePhys(), 1);
178 Vmath::Vadd(nq, m_f->m_exp[j]->GetPhys(), 1, correction[j], 1,
179 m_f->m_exp[j]->UpdatePhys(), 1);
180 Vmath::Smul(nq, 1.0 / (na + nb), m_f->m_exp[j]->GetPhys(), 1,
181 m_f->m_exp[j]->UpdatePhys(), 1);
182 m_f->m_exp[j]->FwdTransLocalElmt(m_f->m_exp[j]->GetPhys(),
183 m_f->m_exp[j]->UpdateCoeffs());
184 }
185
186 // Update metadata
187 m_f->m_fieldMetaDataMap["NumberOfFieldDumps"] = std::to_string(na + nb);
188 NekDouble t0 = -1;
189 NekDouble finTime = -1;
190 if (m_f->m_fieldMetaDataMap.count("InitialTime"))
191 {
192 string s_t = m_f->m_fieldMetaDataMap["InitialTime"];
193 NekDouble t = atof(s_t.c_str());
194
195 t0 = t;
196 }
197 if (fromFieldMetaDataMap.count("InitialTime"))
198 {
199 string s_t = fromFieldMetaDataMap["InitialTime"];
200 NekDouble t = atof(s_t.c_str());
201
202 if (t0 == -1)
203 {
204 t0 = t;
205 }
206 else
207 {
208 t0 = std::min(t0, t);
209 }
210 }
211 if (m_f->m_fieldMetaDataMap.count("FinalTime"))
212 {
213 string s_t = m_f->m_fieldMetaDataMap["FinalTime"];
214 NekDouble t = atof(s_t.c_str());
215
216 finTime = std::max(t0, t);
217 }
218 if (fromFieldMetaDataMap.count("FinalTime"))
219 {
220 string s_t = fromFieldMetaDataMap["FinalTime"];
221 NekDouble t = atof(s_t.c_str());
222
223 finTime = std::max(t0, t);
224 }
225 if (t0 != -1)
226 {
227 m_f->m_fieldMetaDataMap["InitialTime"] =
228 boost::lexical_cast<std::string>(t0);
229 }
230 if (finTime != -1)
231 {
232 m_f->m_fieldMetaDataMap["FinalTime"] =
233 boost::lexical_cast<std::string>(finTime);
234 }
235}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:990
std::map< std::string, std::string > FieldMetaDataMap
Definition: FieldIO.h:50
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 Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Svtvp (scalar times vector plus vector): z = alpha*x + y.
Definition: Vmath.hpp:396
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.hpp:180
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 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.hpp:220

References ASSERTL0, Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, Vmath::Smul(), Vmath::Svtvp(), Vmath::Vadd(), Vmath::Vmul(), and Vmath::Vsub().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessCombineAvg::className
static
Initial value:
=
"combine two fields containing averages (and possibly Reynolds "
"stresses). Must specify fromfld.")
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:197
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47

Definition at line 56 of file ProcessCombineAvg.h.