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::ProcessAddFld Class Reference

This processing module scales the input fld file. More...

#include <ProcessAddFld.h>

Inheritance diagram for Nektar::FieldUtils::ProcessAddFld:
Inheritance graph
[legend]
Collaboration diagram for Nektar::FieldUtils::ProcessAddFld:
Collaboration graph
[legend]

Public Member Functions

 ProcessAddFld (FieldSharedPtr f)
 
virtual ~ProcessAddFld ()
 
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 scales the input fld file.

Definition at line 50 of file ProcessAddFld.h.

Constructor & Destructor Documentation

Nektar::FieldUtils::ProcessAddFld::ProcessAddFld ( FieldSharedPtr  f)

Definition at line 56 of file ProcessAddFld.cpp.

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

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

Definition at line 67 of file ProcessAddFld.cpp.

68 {
69 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 54 of file ProcessAddFld.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::FieldUtils::ProcessAddFld::GetModuleName ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 66 of file ProcessAddFld.h.

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

Write mesh to output file.

Implements Nektar::FieldUtils::Module.

Definition at line 71 of file ProcessAddFld.cpp.

References ASSERTL0, Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, Nektar::LibUtilities::NullFieldMetaDataMap, Vmath::Smul(), Vmath::Vadd(), and Vmath::Vcopy().

72 {
73  if (m_f->m_verbose)
74  {
75  if (m_f->m_comm->TreatAsRankZero())
76  {
77  cout << "ProcessAddFld: Adding new fld to input fld..." << endl;
78  }
79  }
80 
81  ASSERTL0(m_f->m_data.size() != 0, "No input data defined");
82 
83  string scalestr = m_config["scale"].as<string>();
84  NekDouble scale = boost::lexical_cast<NekDouble>(scalestr);
85 
86  string fromfld = m_config["fromfld"].as<string>();
87  FieldSharedPtr fromField = boost::shared_ptr<Field>(new Field());
88 
89  if (m_f->m_exp.size())
90  {
91  // Set up ElementGIDs in case of parallel processing
92  Array<OneD, int> ElementGIDs(m_f->m_exp[0]->GetExpSize());
93  for (int i = 0; i < m_f->m_exp[0]->GetExpSize(); ++i)
94  {
95  ElementGIDs[i] = m_f->m_exp[0]->GetExp(i)->GetGeom()->GetGlobalID();
96  }
97  m_f->FieldIOForFile(fromfld)->Import(
98  fromfld, fromField->m_fielddef, fromField->m_data,
100  }
101  else
102  {
103  m_f->FieldIOForFile(fromfld)->Import(
104  fromfld, fromField->m_fielddef, fromField->m_data,
106  }
107 
108  bool samelength = true;
109  if (fromField->m_data.size() != m_f->m_data.size())
110  {
111  samelength = false;
112  }
113 
114  // scale input field
115  for (int i = 0; i < fromField->m_data.size(); ++i)
116  {
117  int datalen = fromField->m_data[i].size();
118 
119  Vmath::Smul(datalen, scale, &(fromField->m_data[i][0]), 1,
120  &(fromField->m_data[i][0]), 1);
121 
122  if (samelength)
123  {
124  if (datalen != m_f->m_data[i].size())
125  {
126  samelength = false;
127  }
128  }
129  }
130 
131  if (samelength == true)
132  {
133  for (int i = 0; i < m_f->m_data.size(); ++i)
134  {
135  int datalen = m_f->m_data[i].size();
136 
137  Vmath::Vadd(datalen, &(m_f->m_data[i][0]), 1,
138  &(fromField->m_data[i][0]), 1, &(m_f->m_data[i][0]), 1);
139  }
140  }
141  else
142  {
143  ASSERTL0(m_f->m_exp.size() != 0,
144  "Input fields have partitions of different length and so xml "
145  "file needs to be specified");
146 
147  int nfields = m_f->m_fielddef[0]->m_fields.size();
148  int ncoeffs = m_f->m_exp[0]->GetNcoeffs();
149  Array<OneD, NekDouble> SaveFld(ncoeffs);
150 
151  for (int j = 0; j < nfields; ++j)
152  {
153  Vmath::Vcopy(ncoeffs, m_f->m_exp[j]->GetCoeffs(), 1, SaveFld, 1);
154 
155  // since expansion is set up according to m_f search for same
156  // variable in new field
157  int nfield;
158  for (nfield = 0; nfield < fromField->m_fielddef[0]->m_fields.size();
159  ++nfield)
160  {
161  if (fromField->m_fielddef[0]->m_fields[nfield] ==
162  m_f->m_fielddef[0]->m_fields[j])
163  {
164  break;
165  }
166  }
167 
168  ASSERTL0(nfield != fromField->m_fielddef[0]->m_fields.size(),
169  "Could not find field " + m_f->m_fielddef[0]->m_fields[j] +
170  " in from field");
171 
172  // load new field
173  for (int i = 0; i < fromField->m_data.size(); ++i)
174  {
175  m_f->m_exp[j]->ExtractDataToCoeffs(
176  fromField->m_fielddef[i], fromField->m_data[i],
177  fromField->m_fielddef[i]->m_fields[nfield],
178  m_f->m_exp[j]->UpdateCoeffs());
179  }
180 
181  Vmath::Vadd(ncoeffs, m_f->m_exp[j]->GetCoeffs(), 1, SaveFld, 1,
182  m_f->m_exp[j]->UpdateCoeffs(), 1);
183  }
184 
185  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
186  m_f->m_exp[0]->GetFieldDefinitions();
187  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
188 
189  for (int i = 0; i < nfields; ++i)
190  {
191  for (int j = 0; j < FieldDef.size(); ++j)
192  {
193  FieldDef[j]->m_fields.push_back(
194  m_f->m_fielddef[0]->m_fields[i]);
195  m_f->m_exp[i]->AppendFieldData(FieldDef[j], FieldData[j]);
196  }
197  }
198 
199  m_f->m_fielddef = FieldDef;
200  m_f->m_data = FieldData;
201  }
202 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
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:767
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:55
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
FieldSharedPtr m_f
Field object.

Member Data Documentation

ModuleKey Nektar::FieldUtils::ProcessAddFld::className
static
Initial value:
"add two fields together with optional scaling. Must specify fromfld and "
"scaling is optionally specified with input option scale.")

Definition at line 58 of file ProcessAddFld.h.