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

This processing module computes the inner product between two fields. More...

#include <ProcessInnerProduct.h>

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

Public Member Functions

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

Private Member Functions

NekDouble IProduct (vector< unsigned int > &processFields, FieldSharedPtr &fromField, Array< OneD, const Array< OneD, NekDouble > > &SaveFld)
 

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 computes the inner product between two fields.

Definition at line 50 of file ProcessInnerProduct.h.

Constructor & Destructor Documentation

Nektar::FieldUtils::ProcessInnerProduct::ProcessInnerProduct ( FieldSharedPtr  f)

Definition at line 56 of file ProcessInnerProduct.cpp.

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

56  : ProcessModule(f)
57 {
58  m_config["fromfld"] = ConfigOption(
59  false, "NotSet", "Fld file form which to interpolate field");
60  m_config["fields"] =
61  ConfigOption(false, "All", "field id's to be used in inner product");
62  m_config["multifldids"] = ConfigOption(
63  false, "NotSet", "Take inner product of multiple field fields with "
64  "ids given in string. i.e. file_0.chk file_1.chk ...");
65  m_config["allfromflds"] =
66  ConfigOption(true, "NotSet", "Take inner product between all fromflds, "
67  "requires multifldids to be set");
68 }
map< string, ConfigOption > m_config
List of configuration values.
Nektar::FieldUtils::ProcessInnerProduct::~ProcessInnerProduct ( )
virtual

Definition at line 70 of file ProcessInnerProduct.cpp.

71 {
72 }

Member Function Documentation

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

Creates an instance of this class.

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

Implements Nektar::FieldUtils::Module.

Definition at line 66 of file ProcessInnerProduct.h.

67  {
68  return "ProcessInnerProduct";
69  }
NekDouble Nektar::FieldUtils::ProcessInnerProduct::IProduct ( vector< unsigned int > &  processFields,
FieldSharedPtr fromField,
Array< OneD, const Array< OneD, NekDouble > > &  SaveFld 
)
private

Definition at line 222 of file ProcessInnerProduct.cpp.

References Nektar::FieldUtils::Module::m_f, Nektar::LibUtilities::ReduceSum, and Vmath::Vmul().

Referenced by Process().

226 {
227  int nphys = m_f->m_exp[0]->GetTotPoints();
228  NekDouble totiprod = 0.0;
229 
230  for (int j = 0; j < processFields.size(); ++j)
231  {
232  int fid = processFields[j];
233 
234  // load new field
235  for (int i = 0; i < fromField->m_data.size(); ++i)
236  {
237  m_f->m_exp[fid]->ExtractDataToCoeffs(
238  fromField->m_fielddef[i], fromField->m_data[i],
239  fromField->m_fielddef[i]->m_fields[fid],
240  m_f->m_exp[fid]->UpdateCoeffs());
241  }
242 
243  m_f->m_exp[fid]->BwdTrans(m_f->m_exp[fid]->GetCoeffs(),
244  m_f->m_exp[fid]->UpdatePhys());
245 
246  Vmath::Vmul(nphys, SaveFld[j], 1, m_f->m_exp[fid]->GetPhys(), 1,
247  m_f->m_exp[fid]->UpdatePhys(), 1);
248 
249  NekDouble iprod =
250  m_f->m_exp[fid]->PhysIntegral(m_f->m_exp[fid]->UpdatePhys());
251 
252  // put in parallel summation
253  m_f->m_comm->AllReduce(iprod, Nektar::LibUtilities::ReduceSum);
254 
255  totiprod += iprod;
256  }
257  return totiprod;
258 }
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.cpp:183
FieldSharedPtr m_f
Field object.
void Nektar::FieldUtils::ProcessInnerProduct::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Implements Nektar::FieldUtils::Module.

Definition at line 74 of file ProcessInnerProduct.cpp.

References ASSERTL0, Nektar::ParseUtils::GenerateSeqVector(), IProduct(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, and Nektar::LibUtilities::NullFieldMetaDataMap.

75 {
76  if (m_f->m_verbose)
77  {
78  if (m_f->m_comm->TreatAsRankZero())
79  {
80  cout << "ProcessInnerProduct: Evaluating inner product..." << endl;
81  }
82  }
83 
84  ASSERTL0(m_f->m_exp.size() != 0, "input xml file needs to be specified");
85  ASSERTL0(m_f->m_data.size() != 0, "No input data has been defined");
86 
87  string fromfld = m_config["fromfld"].as<string>();
88  FieldSharedPtr fromField = boost::shared_ptr<Field>(new Field());
89 
90  ASSERTL0(m_config["fromfld"].as<string>() != "NotSet",
91  "The config parameter "
92  "fromfld needs to be defined");
93 
94  // Set up ElementGIDs in case of parallel processing
95  Array<OneD, int> ElementGIDs(m_f->m_exp[0]->GetExpSize());
96  for (int i = 0; i < m_f->m_exp[0]->GetExpSize(); ++i)
97  {
98  ElementGIDs[i] = m_f->m_exp[0]->GetExp(i)->GetGeom()->GetGlobalID();
99  }
100 
101  int nfields = m_f->m_fielddef[0]->m_fields.size();
102  int nphys = m_f->m_exp[0]->GetTotPoints();
103  NekDouble totiprod;
104  string fields = m_config["fields"].as<string>();
105  vector<unsigned int> processFields;
106  string multifldidsstr = m_config["multifldids"].as<string>();
107  vector<unsigned int> multiFldIds;
108  vector<string> fromfiles;
109  bool allfromflds = m_config["allfromflds"].m_beenSet;
110 
111  if (fields.compare("All") == 0)
112  {
113  for (int i = 0; i < nfields; ++i)
114  {
115  processFields.push_back(i);
116  }
117  }
118  else
119  {
120  ASSERTL0(ParseUtils::GenerateSeqVector(fields.c_str(), processFields),
121  "Failed to interpret field string in module innerproduct");
122  }
123 
124  if (multifldidsstr.compare("NotSet") == 0)
125  {
126  fromfiles.push_back(fromfld);
127  }
128  else
129  {
130  ASSERTL0(
131  ParseUtils::GenerateSeqVector(multifldidsstr.c_str(), multiFldIds),
132  "Failed to interpret multifldids string in module innerproduct");
133  int end = fromfld.find_first_of('.', 0);
134  string endstr = fromfld.substr(end, fromfld.size());
135  string bodystr = fromfld.substr(0, end);
136  for (int i = 0; i < multiFldIds.size(); ++i)
137  {
138  string infile = bodystr + "_" +
139  boost::lexical_cast<string>(multiFldIds[i]) +
140  endstr;
141  fromfiles.push_back(infile);
142  }
143  }
144 
145  Array<OneD, Array<OneD, NekDouble> > SaveFld(processFields.size());
146  for (int j = 0; j < processFields.size(); ++j)
147  {
148  int fid = processFields[j];
149  SaveFld[j] = Array<OneD, NekDouble>(nphys);
150  m_f->m_exp[fid]->BwdTrans(m_f->m_exp[fid]->GetCoeffs(), SaveFld[j]);
151  }
152 
153  if (allfromflds == false)
154  {
155 
156  for (int f = 0; f < fromfiles.size(); ++f)
157  {
158  m_f->FieldIOForFile(fromfiles[f])->Import(
159  fromfiles[f], fromField->m_fielddef, fromField->m_data,
161 
162  totiprod = IProduct(processFields, fromField, SaveFld);
163 
164  if (m_f->m_comm->GetRank() == 0)
165  {
166  cout << "Inner Product WRT " << fromfiles[f] << " : "
167  << totiprod << endl;
168  }
169  }
170  }
171  else // evaluate all from fields, first by loading them all up and then
172  // calling IProduct
173  {
174 
175  // Load all from fields.
176  Array<OneD, FieldSharedPtr> allFromField(fromfiles.size());
177  for (int i = 0; i < fromfiles.size(); ++i)
178  {
179  allFromField[i] = boost::shared_ptr<Field>(new Field());
180 
181  m_f->FieldIOForFile(fromfiles[i])->Import(
182  fromfiles[i], allFromField[i]->m_fielddef,
183  allFromField[i]->m_data, LibUtilities::NullFieldMetaDataMap,
184  ElementGIDs);
185  }
186 
187  for (int g = 0; g < fromfiles.size(); ++g)
188  {
189  for (int j = 0; j < processFields.size(); ++j)
190  {
191  int fid = processFields[j];
192 
193  // load new field
194  for (int i = 0; i < allFromField[g]->m_data.size(); ++i)
195  {
196  m_f->m_exp[fid]->ExtractDataToCoeffs(
197  allFromField[g]->m_fielddef[i],
198  allFromField[g]->m_data[i],
199  allFromField[g]->m_fielddef[i]->m_fields[fid],
200  m_f->m_exp[fid]->UpdateCoeffs());
201  }
202 
203  m_f->m_exp[fid]->BwdTrans(m_f->m_exp[fid]->GetCoeffs(),
204  SaveFld[j]);
205  }
206 
207  // take inner product from this g field with all other above
208  for (int f = g; f < fromfiles.size(); ++f)
209  {
210  totiprod = IProduct(processFields, allFromField[f], SaveFld);
211 
212  if (m_f->m_comm->GetRank() == 0)
213  {
214  cout << "Inner Product of " << fromfiles[g] << " WRT "
215  << fromfiles[f] << " : " << totiprod << endl;
216  }
217  }
218  }
219  }
220 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
static bool GenerateSeqVector(const char *const str, std::vector< unsigned int > &vec)
Definition: ParseUtils.hpp:79
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:767
double NekDouble
NekDouble IProduct(vector< unsigned int > &processFields, FieldSharedPtr &fromField, Array< OneD, const Array< OneD, NekDouble > > &SaveFld)
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:55
FieldSharedPtr m_f
Field object.

Member Data Documentation

ModuleKey Nektar::FieldUtils::ProcessInnerProduct::className
static
Initial value:
=
ModuleKey(eProcessModule, "innerproduct"),
"take inner product between two fields and return value.")

Definition at line 58 of file ProcessInnerProduct.h.