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...
 
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
 

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, 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 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.
virtual std::string Nektar::Utilities::ProcessInnerProduct::GetModuleName ( )
inlinevirtual

Implements Nektar::Utilities::Module.

Definition at line 66 of file ProcessInnerProduct.h.

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

Definition at line 228 of file ProcessInnerProduct.cpp.

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

Referenced by Process().

232 {
233  int nphys = m_f->m_exp[0]->GetTotPoints();
234  NekDouble totiprod = 0.0;
235 
236  for (int j = 0; j < processFields.size(); ++j)
237  {
238  int fid = processFields[j];
239 
240  // load new field
241  for (int i = 0; i < fromField->m_data.size(); ++i)
242  {
243  m_f->m_exp[fid]->ExtractDataToCoeffs(
244  fromField->m_fielddef[i],
245  fromField->m_data[i],
246  fromField->m_fielddef[i]->m_fields[fid],
247  m_f->m_exp[fid]->UpdateCoeffs());
248  }
249 
250  m_f->m_exp[fid]->BwdTrans(m_f->m_exp[fid]->GetCoeffs(),
251  m_f->m_exp[fid]->UpdatePhys());
252 
253  Vmath::Vmul(nphys,
254  SaveFld[j],
255  1,
256  m_f->m_exp[fid]->GetPhys(),
257  1,
258  m_f->m_exp[fid]->UpdatePhys(),
259  1);
260 
261  NekDouble iprod =
262  m_f->m_exp[fid]->PhysIntegral(m_f->m_exp[fid]->UpdatePhys());
263 
264  // put in parallel summation
265  m_f->m_comm->AllReduce(iprod, Nektar::LibUtilities::ReduceSum);
266 
267  totiprod += iprod;
268  }
269  return totiprod;
270 }
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  if(m_f->m_comm->GetRank() == 0)
83  {
84  cout << "ProcessInnerProduct: Evaluating inner product..." << endl;
85  }
86  }
87 
88  ASSERTL0(m_f->m_exp.size() != 0, "input xml file needs to be specified");
89  ASSERTL0(m_f->m_data.size() != 0, "No input data has been defined");
90 
91  string fromfld = m_config["fromfld"].as<string>();
92  FieldSharedPtr fromField = boost::shared_ptr<Field>(new Field());
93 
94  ASSERTL0(m_config["fromfld"].as<string>() != "NotSet",
95  "The config parameter "
96  "fromfld needs to be defined");
97 
98  // Set up ElementGIDs in case of parallel processing
99  Array<OneD, int> ElementGIDs(m_f->m_exp[0]->GetExpSize());
100  for (int i = 0; i < m_f->m_exp[0]->GetExpSize(); ++i)
101  {
102  ElementGIDs[i] = m_f->m_exp[0]->GetExp(i)->GetGeom()->GetGlobalID();
103  }
104 
105  int nfields = m_f->m_fielddef[0]->m_fields.size();
106  int nphys = m_f->m_exp[0]->GetTotPoints();
107  NekDouble totiprod;
108  string fields = m_config["fields"].as<string>();
109  vector<unsigned int> processFields;
110  string multifldidsstr = m_config["multifldids"].as<string>();
111  vector<unsigned int> multiFldIds;
112  vector<string> fromfiles;
113  bool allfromflds = m_config["allfromflds"].m_beenSet;
114 
115  if (fields.compare("All") == 0)
116  {
117  for (int i = 0; i < nfields; ++i)
118  {
119  processFields.push_back(i);
120  }
121  }
122  else
123  {
124  ASSERTL0(ParseUtils::GenerateSeqVector(fields.c_str(), processFields),
125  "Failed to interpret field string in module innerproduct");
126  }
127 
128  if (multifldidsstr.compare("NotSet") == 0)
129  {
130  fromfiles.push_back(fromfld);
131  }
132  else
133  {
134  ASSERTL0(
135  ParseUtils::GenerateSeqVector(multifldidsstr.c_str(), multiFldIds),
136  "Failed to interpret multifldids string in module innerproduct");
137  int end = fromfld.find_first_of('.', 0);
138  string endstr = fromfld.substr(end, fromfld.size());
139  string bodystr = fromfld.substr(0, end);
140  for (int i = 0; i < multiFldIds.size(); ++i)
141  {
142  string infile = bodystr + "_" +
143  boost::lexical_cast<string>(multiFldIds[i]) +
144  endstr;
145  fromfiles.push_back(infile);
146  }
147  }
148 
149  Array<OneD, Array<OneD, NekDouble> > SaveFld(processFields.size());
150  for (int j = 0; j < processFields.size(); ++j)
151  {
152  int fid = processFields[j];
153  SaveFld[j] = Array<OneD, NekDouble>(nphys);
154  m_f->m_exp[fid]->BwdTrans(m_f->m_exp[fid]->GetCoeffs(), SaveFld[j]);
155  }
156 
157  if (allfromflds == false)
158  {
159 
160  for (int f = 0; f < fromfiles.size(); ++f)
161  {
162  m_f->m_fld->Import(fromfiles[f],
163  fromField->m_fielddef,
164  fromField->m_data,
166  ElementGIDs);
167 
168  totiprod = IProduct(processFields, fromField, SaveFld);
169 
170  if (m_f->m_comm->GetRank() == 0)
171  {
172  cout << "Inner Product WRT " << fromfiles[f] << " : "
173  << totiprod << endl;
174  }
175  }
176  }
177  else // evaluate all from fields, first by loading them all up and then
178  // calling IProduct
179  {
180 
181  // Load all from fields.
182  Array<OneD, FieldSharedPtr> allFromField(fromfiles.size());
183  for (int i = 0; i < fromfiles.size(); ++i)
184  {
185  allFromField[i] = boost::shared_ptr<Field>(new Field());
186  m_f->m_fld->Import(fromfiles[i],
187  allFromField[i]->m_fielddef,
188  allFromField[i]->m_data,
190  ElementGIDs);
191  }
192 
193  for (int g = 0; g < fromfiles.size(); ++g)
194  {
195  for (int j = 0; j < processFields.size(); ++j)
196  {
197  int fid = processFields[j];
198 
199  // load new field
200  for (int i = 0; i < allFromField[g]->m_data.size(); ++i)
201  {
202  m_f->m_exp[fid]->ExtractDataToCoeffs(
203  allFromField[g]->m_fielddef[i],
204  allFromField[g]->m_data[i],
205  allFromField[g]->m_fielddef[i]->m_fields[fid],
206  m_f->m_exp[fid]->UpdateCoeffs());
207  }
208 
209  m_f->m_exp[fid]->BwdTrans(m_f->m_exp[fid]->GetCoeffs(),
210  SaveFld[j]);
211  }
212 
213  // take inner product from this g field with all other above
214  for (int f = g; f < fromfiles.size(); ++f)
215  {
216  totiprod = IProduct(processFields, allFromField[f], SaveFld);
217 
218  if (m_f->m_comm->GetRank() == 0)
219  {
220  cout << "Inner Product of " << fromfiles[g] << " WRT "
221  << fromfiles[f] << " : " << totiprod << endl;
222  }
223  }
224  }
225  }
226 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
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.