Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | 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:
Inheritance graph
[legend]
Collaboration diagram for Nektar::FieldUtils::ProcessCombineAvg:
Collaboration graph
[legend]

Public Member Functions

 ProcessCombineAvg (FieldSharedPtr f)
 
virtual ~ProcessCombineAvg ()
 
virtual void Process (po::variables_map &vm)
 Write mesh to output file. More...
 
virtual std::string GetModuleName ()
 
- 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)
 
FIELD_UTILS_EXPORT void RegisterConfig (string key, 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 bool GetRequireEquiSpaced (void)
 
FIELD_UTILS_EXPORT void SetRequireEquiSpaced (bool pVal)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

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

Static Public Attributes

static ModuleKey className
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 

Detailed Description

This processing module combines two fld files containing average fields.

Definition at line 51 of file ProcessCombineAvg.h.

Constructor & Destructor Documentation

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

Definition at line 57 of file ProcessCombineAvg.cpp.

References ASSERTL0, and Nektar::FieldUtils::Module::m_config.

57  : ProcessModule(f)
58 {
59  m_config["fromfld"] =
60  ConfigOption(false, "NotSet", "Fld file form which to add field");
61 
62  ASSERTL0(m_config["fromfld"].as<string>().compare("NotSet") != 0,
63  "Need to specify fromfld=file.fld ");
64 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
Nektar::FieldUtils::ProcessCombineAvg::~ProcessCombineAvg ( )
virtual

Definition at line 66 of file ProcessCombineAvg.cpp.

67 {
68 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 55 of file ProcessCombineAvg.h.

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

56  {
58  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
virtual std::string Nektar::FieldUtils::ProcessCombineAvg::GetModuleName ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 67 of file ProcessCombineAvg.h.

68  {
69  return "ProcessCombineAvg";
70  }
void Nektar::FieldUtils::ProcessCombineAvg::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Implements Nektar::FieldUtils::Module.

Definition at line 70 of file ProcessCombineAvg.cpp.

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

71 {
72  if (m_f->m_verbose)
73  {
74  if (m_f->m_comm->TreatAsRankZero())
75  {
76  cout << "ProcessCombineAvg: Combining new fld into input avg fld..."
77  << endl;
78  }
79  }
80 
81  ASSERTL0(m_f->m_exp.size() != 0, "No input expansion defined");
82 
83  int nfields = m_f->m_fielddef[0]->m_fields.size();
84  int nq = m_f->m_exp[0]->GetTotPoints();
85  int expdim = m_f->m_graph->GetMeshDimension();
86  int spacedim = expdim;
87  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) == 1 ||
88  (m_f->m_fielddef[0]->m_numHomogeneousDir) == 2)
89  {
90  spacedim += m_f->m_fielddef[0]->m_numHomogeneousDir;
91  }
92 
93  // Allocate storage for new field and correction (for Reynolds stress)
94  Array<OneD, Array<OneD, NekDouble> > fromPhys(nfields);
95  Array<OneD, Array<OneD, NekDouble> > correction(nfields);
96  for (int j = 0; j < nfields; ++j)
97  {
98  fromPhys[j] = Array<OneD, NekDouble>(nq, 0.0);
99  correction[j] = Array<OneD, NekDouble>(nq, 0.0);
100  }
101 
102  string fromfld = m_config["fromfld"].as<string>();
103  FieldSharedPtr fromField = boost::shared_ptr<Field>(new Field());
104  LibUtilities::FieldMetaDataMap fromFieldMetaDataMap;
105 
106  // Set up ElementGIDs in case of parallel processing
107  Array<OneD, int> ElementGIDs(m_f->m_exp[0]->GetExpSize());
108  for (int i = 0; i < m_f->m_exp[0]->GetExpSize(); ++i)
109  {
110  ElementGIDs[i] = m_f->m_exp[0]->GetExp(i)->GetGeom()->GetGlobalID();
111  }
112  // Import fromfld file
113  m_f->FieldIOForFile(fromfld)->Import(
114  fromfld, fromField->m_fielddef, fromField->m_data, fromFieldMetaDataMap,
115  ElementGIDs);
116  ASSERTL0(fromField->m_fielddef[0]->m_fields.size() == nfields,
117  "Mismatch in number of fields");
118  // Extract data to fromPhys
119  for (int j = 0; j < nfields; ++j)
120  {
121  ASSERTL0(fromField->m_fielddef[0]->m_fields[j] ==
122  m_f->m_fielddef[0]->m_fields[j],
123  "Field names do not match.");
124 
125  // load new field (overwrite m_f->m_exp coeffs for now)
126  for (int i = 0; i < fromField->m_data.size(); ++i)
127  {
128  m_f->m_exp[j]->ExtractDataToCoeffs(
129  fromField->m_fielddef[i], fromField->m_data[i],
130  fromField->m_fielddef[i]->m_fields[j],
131  m_f->m_exp[j]->UpdateCoeffs());
132  }
133  m_f->m_exp[j]->BwdTrans(m_f->m_exp[j]->GetCoeffs(), fromPhys[j]);
134  }
135 
136  // Load number of samples in each file
137  ASSERTL0(m_f->m_fieldMetaDataMap.count("NumberOfFieldDumps") != 0,
138  "Missing NumberOfFieldDumps metadata.");
139  ASSERTL0(fromFieldMetaDataMap.count("NumberOfFieldDumps") != 0,
140  "Missing NumberOfFieldDumps metadata.");
141  string s_num;
142  s_num = m_f->m_fieldMetaDataMap["NumberOfFieldDumps"];
143  int na = atoi(s_num.c_str());
144  s_num = fromFieldMetaDataMap["NumberOfFieldDumps"];
145  int nb = atoi(s_num.c_str());
146 
147  // Look for Reynolds stresses
148  int stress = -1;
149  for (int j = 0; j < nfields; ++j)
150  {
151  if (m_f->m_fielddef[0]->m_fields[j] == "uu")
152  {
153  stress = j;
154  break;
155  }
156  }
157 
158  // Calculate correction for Reynolds stresses
159  if (stress != -1)
160  {
161  Array<OneD, NekDouble> tmp(nq, 0.0);
162  int n = stress;
163  // Follow same numbering as FilterReynoldsStresses
164  for (int i = 0; i < spacedim; ++i)
165  {
166  for (int j = i; j < spacedim; ++j, ++n)
167  {
168  // correction is zero for averages and
169  // = (\bar{x_a}-\bar{x_b})*(\bar{y_a}-\bar{y_b})*na*nb/N
170  // for Reynolds stresses
171  NekDouble fac = ((NekDouble)(na * nb)) / ((NekDouble)(na + nb));
172  Vmath::Vsub(nq, m_f->m_exp[i]->GetPhys(), 1, fromPhys[i], 1,
173  correction[n], 1);
174  Vmath::Vsub(nq, m_f->m_exp[j]->GetPhys(), 1, fromPhys[j], 1,
175  tmp, 1);
176  Vmath::Vmul(nq, correction[n], 1, tmp, 1, correction[n], 1);
177  Vmath::Smul(nq, fac, correction[n], 1, correction[n], 1);
178  }
179  }
180  }
181  // Combine fields
182  for (int j = 0; j < nfields; ++j)
183  {
184  // The new value is: (x_a*na + x_b*nb + correction)/N
185  Vmath::Smul(nq, 1.0 * na, m_f->m_exp[j]->GetPhys(), 1,
186  m_f->m_exp[j]->UpdatePhys(), 1);
187  Vmath::Svtvp(nq, 1.0 * nb, fromPhys[j], 1, m_f->m_exp[j]->GetPhys(), 1,
188  m_f->m_exp[j]->UpdatePhys(), 1);
189  Vmath::Vadd(nq, m_f->m_exp[j]->GetPhys(), 1, correction[j], 1,
190  m_f->m_exp[j]->UpdatePhys(), 1);
191  Vmath::Smul(nq, 1.0 / (na + nb), m_f->m_exp[j]->GetPhys(), 1,
192  m_f->m_exp[j]->UpdatePhys(), 1);
193 
194  m_f->m_exp[j]->FwdTrans_IterPerExp(m_f->m_exp[j]->GetPhys(),
195  m_f->m_exp[j]->UpdateCoeffs());
196  }
197 
198  // Update metadata
199  m_f->m_fieldMetaDataMap["NumberOfFieldDumps"] =
200  boost::lexical_cast<std::string>(na + nb);
201  NekDouble t0 = -1;
202  NekDouble finTime = -1;
203  if (m_f->m_fieldMetaDataMap.count("InitialTime"))
204  {
205  string s_t = m_f->m_fieldMetaDataMap["InitialTime"];
206  NekDouble t = atof(s_t.c_str());
207 
208  t0 = t;
209  }
210  if (fromFieldMetaDataMap.count("InitialTime"))
211  {
212  string s_t = fromFieldMetaDataMap["InitialTime"];
213  NekDouble t = atof(s_t.c_str());
214 
215  if (t0 == -1)
216  {
217  t0 = t;
218  }
219  else
220  {
221  t0 = std::min(t0, t);
222  }
223  }
224  if (m_f->m_fieldMetaDataMap.count("FinalTime"))
225  {
226  string s_t = m_f->m_fieldMetaDataMap["FinalTime"];
227  NekDouble t = atof(s_t.c_str());
228 
229  finTime = std::max(t0, t);
230  }
231  if (fromFieldMetaDataMap.count("FinalTime"))
232  {
233  string s_t = fromFieldMetaDataMap["FinalTime"];
234  NekDouble t = atof(s_t.c_str());
235 
236  finTime = std::max(t0, t);
237  }
238  if (t0 != -1)
239  {
240  m_f->m_fieldMetaDataMap["InitialTime"] =
241  boost::lexical_cast<std::string>(t0);
242  }
243  if (finTime != -1)
244  {
245  m_f->m_fieldMetaDataMap["FinalTime"] =
246  boost::lexical_cast<std::string>(finTime);
247  }
248 
249  // Update field def and data
250  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
251  m_f->m_exp[0]->GetFieldDefinitions();
252  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
253  for (int i = 0; i < nfields; ++i)
254  {
255  for (int j = 0; j < FieldDef.size(); ++j)
256  {
257  FieldDef[j]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[i]);
258  m_f->m_exp[i]->AppendFieldData(FieldDef[j], FieldData[j]);
259  }
260  }
261 
262  m_f->m_fielddef = FieldDef;
263  m_f->m_data = FieldData;
264 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
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.cpp:485
std::map< std::string, std::string > FieldMetaDataMap
Definition: FieldIO.h:54
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*y.
Definition: Vmath.cpp:213
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:740
double NekDouble
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.cpp:343
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.cpp:299
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:183
FieldSharedPtr m_f
Field object.

Member Data Documentation

ModuleKey Nektar::FieldUtils::ProcessCombineAvg::className
static
Initial value:
=
ModuleKey(eProcessModule, "combineAvg"),
"combine two fields containing averages (and possibly Reynolds "
"stresses). Must specify fromfld.")

Definition at line 59 of file ProcessCombineAvg.h.