Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | 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:
[legend]

Public Member Functions

 ProcessInnerProduct (FieldSharedPtr f)
 
 ~ProcessInnerProduct () override
 
- 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)
 
virtual ~Module ()=default
 
void Process (po::variables_map &vm)
 
std::string GetModuleName ()
 
std::string GetModuleDescription ()
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
std::vector< ModuleKeyGetModulePrerequisites ()
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::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 void AddFile (std::string fileType, std::string fileName)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static std::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey className
 

Protected Member Functions

void v_Process (po::variables_map &vm) override
 Write mesh to output file. More...
 
std::string v_GetModuleName () override
 
std::string v_GetModuleDescription () override
 
ModulePriority v_GetModulePriority () override
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
virtual void v_Process (po::variables_map &vm)
 
virtual std::string v_GetModuleName ()
 
virtual std::string v_GetModuleDescription ()
 
virtual ModulePriority v_GetModulePriority ()
 
virtual std::vector< ModuleKeyv_GetModulePrerequisites ()
 

Private Member Functions

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

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 
std::set< std::string > m_allowedFiles
 List of allowed file formats. More...
 

Detailed Description

This processing module computes the inner product between two fields.

Definition at line 47 of file ProcessInnerProduct.h.

Constructor & Destructor Documentation

◆ ProcessInnerProduct()

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

Definition at line 52 of file ProcessInnerProduct.cpp.

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

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

◆ ~ProcessInnerProduct()

Nektar::FieldUtils::ProcessInnerProduct::~ProcessInnerProduct ( )
override

Definition at line 68 of file ProcessInnerProduct.cpp.

69{
70}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 51 of file ProcessInnerProduct.h.

52 {
54 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

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

◆ IProduct()

NekDouble Nektar::FieldUtils::ProcessInnerProduct::IProduct ( std::vector< unsigned int > &  processFields,
FieldSharedPtr fromField,
Array< OneD, const Array< OneD, NekDouble > > &  SaveFld 
)
private

Definition at line 215 of file ProcessInnerProduct.cpp.

218{
219 int nphys = m_f->m_exp[0]->GetTotPoints();
220 NekDouble totiprod = 0.0;
221
222 for (int j = 0; j < processFields.size(); ++j)
223 {
224 int fid = processFields[j];
225
226 Array<OneD, NekDouble> coeffs(m_f->m_exp[fid]->GetNcoeffs());
227 Array<OneD, NekDouble> phys(m_f->m_exp[fid]->GetTotPoints());
228
229 // load new field
230 for (int i = 0; i < fromField->m_data.size(); ++i)
231 {
232 m_f->m_exp[fid]->ExtractDataToCoeffs(fromField->m_fielddef[i],
233 fromField->m_data[i],
234 m_f->m_variables[fid], coeffs);
235 }
236
237 m_f->m_exp[fid]->BwdTrans(coeffs, phys);
238
239 Vmath::Vmul(nphys, SaveFld[j], 1, phys, 1, phys, 1);
240
241 NekDouble iprod = m_f->m_exp[fid]->Integral(phys);
242
243 totiprod += iprod;
244 }
245 return totiprod;
246}
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
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.hpp:72

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

Referenced by v_Process().

◆ v_GetModuleDescription()

std::string Nektar::FieldUtils::ProcessInnerProduct::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 69 of file ProcessInnerProduct.h.

70 {
71 return "Evaluating inner product";
72 }

◆ v_GetModuleName()

std::string Nektar::FieldUtils::ProcessInnerProduct::v_GetModuleName ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 64 of file ProcessInnerProduct.h.

65 {
66 return "ProcessInnerProduct";
67 }

◆ v_GetModulePriority()

ModulePriority Nektar::FieldUtils::ProcessInnerProduct::v_GetModulePriority ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 74 of file ProcessInnerProduct.h.

75 {
76 return eModifyExp;
77 }

References Nektar::FieldUtils::eModifyExp.

◆ v_Process()

void Nektar::FieldUtils::ProcessInnerProduct::v_Process ( po::variables_map &  vm)
overrideprotectedvirtual

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 72 of file ProcessInnerProduct.cpp.

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

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

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessInnerProduct::className
static
Initial value:
=
"take inner product between two fields and return value.")
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47

Definition at line 55 of file ProcessInnerProduct.h.