Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Nektar::Utilities::ProcessCombineAvg Class Reference

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

#include <ProcessCombineAvg.h>

Inheritance diagram for Nektar::Utilities::ProcessCombineAvg:
Inheritance graph
[legend]
Collaboration diagram for Nektar::Utilities::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::Utilities::ProcessModule
 ProcessModule ()
 
 ProcessModule (FieldSharedPtr p_f)
 
 ProcessModule (MeshSharedPtr p_m)
 
- Public Member Functions inherited from Nektar::Utilities::Module
 Module (FieldSharedPtr p_f)
 
void RegisterConfig (string key, string value)
 Register a configuration option with a module. More...
 
void PrintConfig ()
 Print out all configuration options for a module. More...
 
void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
bool GetRequireEquiSpaced (void)
 
void SetRequireEquiSpaced (bool pVal)
 
void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 
 Module (MeshSharedPtr p_m)
 
virtual void Process ()=0
 
void RegisterConfig (std::string key, std::string value)
 
void PrintConfig ()
 
void SetDefaults ()
 
MeshSharedPtr GetMesh ()
 
virtual void ProcessVertices ()
 Extract element vertices. More...
 
virtual void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual void ProcessElements ()
 Generate element IDs. More...
 
virtual void ProcessComposites ()
 Generate composites. More...
 
virtual void ClearElementLinks ()
 

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::Utilities::Module
 Module ()
 
void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
void PrismLines (int prism, PerMap &perFaces, std::set< int > &prismsDone, std::vector< ElementSharedPtr > &line)
 
- Protected Attributes inherited from Nektar::Utilities::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 
MeshSharedPtr m_mesh
 Mesh object. More...
 
std::map< std::string,
ConfigOption
m_config
 List of configuration values. More...
 

Detailed Description

This processing module combines two fld files containing average fields.

Definition at line 50 of file ProcessCombineAvg.h.

Constructor & Destructor Documentation

Nektar::Utilities::ProcessCombineAvg::ProcessCombineAvg ( FieldSharedPtr  f)

Definition at line 55 of file ProcessCombineAvg.cpp.

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

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

Definition at line 65 of file ProcessCombineAvg.cpp.

66 {
67 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 54 of file ProcessCombineAvg.h.

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

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

Implements Nektar::Utilities::Module.

Definition at line 66 of file ProcessCombineAvg.h.

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

Write mesh to output file.

Implements Nektar::Utilities::Module.

Definition at line 69 of file ProcessCombineAvg.cpp.

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

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

Member Data Documentation

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

Definition at line 58 of file ProcessCombineAvg.h.