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

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

#include <ProcessInnerProduct.h>

Inheritance diagram for Nektar::Utilities::ProcessInnerProduct:
Inheritance graph
[legend]
Collaboration diagram for Nektar::Utilities::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...
 
- 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 (string key, 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
 

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::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, set< int > &prismsDone, 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...
 

Detailed Description

This processing module computes the inner product between two fields.

Definition at line 50 of file ProcessInnerProduct.h.

Constructor & Destructor Documentation

Nektar::Utilities::ProcessInnerProduct::ProcessInnerProduct ( FieldSharedPtr  f)

Definition at line 56 of file ProcessInnerProduct.cpp.

References Nektar::Utilities::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"] =
63  ConfigOption(false,
64  "NotSet",
65  "Take inner product of multiple field fields with "
66  "ids given in string. i.e. file_0.chk file_1.chk ...");
67  m_config["allfromflds"] =
68  ConfigOption(true,
69  "NotSet",
70  "Take inner product between all fromflds, "
71  "requires multifldids to be set");
72 }
map< string, ConfigOption > m_config
List of configuration values.
Nektar::Utilities::ProcessInnerProduct::~ProcessInnerProduct ( )
virtual

Definition at line 74 of file ProcessInnerProduct.cpp.

75 {
76 }

Member Function Documentation

static boost::shared_ptr<Module> Nektar::Utilities::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.
NekDouble Nektar::Utilities::ProcessInnerProduct::IProduct ( vector< unsigned int > &  processFields,
FieldSharedPtr fromField,
Array< OneD, const Array< OneD, NekDouble > > &  SaveFld 
)
private

Definition at line 225 of file ProcessInnerProduct.cpp.

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

Referenced by Process().

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

Write mesh to output file.

Implements Nektar::Utilities::Module.

Definition at line 78 of file ProcessInnerProduct.cpp.

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

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

Member Data Documentation

ModuleKey Nektar::Utilities::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.