39 #include <boost/core/ignore_unused.hpp> 51 ModuleKey ProcessInnerProduct::className =
54 ProcessInnerProduct::create,
55 "take inner product between two fields and return value.");
60 false,
"NotSet",
"Fld file form which to interpolate field");
62 ConfigOption(
false,
"All",
"field id's to be used in inner product");
64 false,
"NotSet",
"Take inner product of multiple field fields with " 65 "ids given in string. i.e. file_0.chk file_1.chk ...");
67 ConfigOption(
true,
"0",
"Take inner product between all fromflds, " 68 "requires multifldids to be set");
77 boost::ignore_unused(vm);
80 if (
m_f->m_exp[0]->GetNumElmts() == 0)
85 string fromfld =
m_config[
"fromfld"].as<
string>();
89 "The config parameter " 90 "fromfld needs to be defined");
94 for (
int i = 0; i <
m_f->m_exp[0]->GetExpSize(); ++i)
96 ElementGIDs[i] =
m_f->m_exp[0]->GetExp(i)->GetGeom()->GetGlobalID();
99 int nfields =
m_f->m_variables.size();
100 int nphys =
m_f->m_exp[0]->GetTotPoints();
102 string fields =
m_config[
"fields"].as<
string>();
103 vector<unsigned int> processFields;
104 string multifldidsstr =
m_config[
"multifldids"].as<
string>();
105 vector<unsigned int> multiFldIds;
106 vector<string> fromfiles;
107 bool allfromflds =
m_config[
"allfromflds"].as<
bool>();
109 if (fields.compare(
"All") == 0)
111 for (
int i = 0; i < nfields; ++i)
113 processFields.push_back(i);
119 "Failed to interpret field string in module innerproduct");
122 if (multifldidsstr.compare(
"NotSet") == 0)
124 fromfiles.push_back(fromfld);
130 "Failed to interpret multifldids string in module innerproduct");
131 int end = fromfld.find_first_of(
'.', 0);
132 string endstr = fromfld.substr(end, fromfld.size());
133 string bodystr = fromfld.substr(0, end);
134 for (
int i = 0; i < multiFldIds.size(); ++i)
136 string infile = bodystr +
"_" +
137 boost::lexical_cast<
string>(multiFldIds[i]) +
139 fromfiles.push_back(infile);
144 for (
int j = 0; j < processFields.size(); ++j)
146 int fid = processFields[j];
148 m_f->m_exp[fid]->BwdTrans(
m_f->m_exp[fid]->GetCoeffs(), SaveFld[j]);
151 if (allfromflds ==
false)
154 for (
int f = 0; f < fromfiles.size(); ++f)
156 m_f->FieldIOForFile(fromfiles[f])->Import(
157 fromfiles[f], fromField->m_fielddef, fromField->m_data,
160 totiprod =
IProduct(processFields, fromField, SaveFld);
162 if (
m_f->m_comm->GetRank() == 0)
164 cout <<
"Inner Product WRT " << fromfiles[f] <<
" : " 175 for (
int i = 0; i < fromfiles.size(); ++i)
177 allFromField[i] = std::shared_ptr<Field>(
new Field());
179 m_f->FieldIOForFile(fromfiles[i])->Import(
180 fromfiles[i], allFromField[i]->m_fielddef,
185 for (
int g = 0; g < fromfiles.size(); ++g)
187 for (
int j = 0; j < processFields.size(); ++j)
189 int fid = processFields[j];
192 for (
int i = 0; i < allFromField[g]->m_data.size(); ++i)
194 m_f->m_exp[fid]->ExtractDataToCoeffs(
195 allFromField[g]->m_fielddef[i],
196 allFromField[g]->m_data[i],
197 m_f->m_variables[fid],
198 m_f->m_exp[fid]->UpdateCoeffs());
201 m_f->m_exp[fid]->BwdTrans(
m_f->m_exp[fid]->GetCoeffs(),
206 for (
int f = g; f < fromfiles.size(); ++f)
208 totiprod =
IProduct(processFields, allFromField[f], SaveFld);
210 if (
m_f->m_comm->GetRank() == 0)
212 cout <<
"Inner Product of " << fromfiles[g] <<
" WRT " 213 << fromfiles[f] <<
" : " << totiprod << endl;
221 vector<unsigned int> &processFields,
225 int nphys =
m_f->m_exp[0]->GetTotPoints();
228 for (
int j = 0; j < processFields.size(); ++j)
230 int fid = processFields[j];
233 for (
int i = 0; i < fromField->m_data.size(); ++i)
235 m_f->m_exp[fid]->ExtractDataToCoeffs(
236 fromField->m_fielddef[i], fromField->m_data[i],
237 m_f->m_variables[fid],
238 m_f->m_exp[fid]->UpdateCoeffs());
241 m_f->m_exp[fid]->BwdTrans(
m_f->m_exp[fid]->GetCoeffs(),
242 m_f->m_exp[fid]->UpdatePhys());
245 m_f->m_exp[fid]->UpdatePhys(), 1);
248 m_f->m_exp[fid]->PhysIntegral(
m_f->m_exp[fid]->UpdatePhys());
#define ASSERTL0(condition, msg)
std::map< std::string, ConfigOption > m_config
List of configuration values.
virtual void Process(po::variables_map &vm)
Write mesh to output file.
Represents a command-line configuration option.
virtual ~ProcessInnerProduct()
std::shared_ptr< Field > FieldSharedPtr
std::pair< ModuleType, std::string > ModuleKey
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
NekDouble IProduct(vector< unsigned int > &processFields, FieldSharedPtr &fromField, Array< OneD, const Array< OneD, NekDouble > > &SaveFld)
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Abstract base class for processing modules.
static FieldMetaDataMap NullFieldMetaDataMap
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.
ModuleFactory & GetModuleFactory()
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. ...
FieldSharedPtr m_f
Field object.