39#include <boost/core/ignore_unused.hpp>
54 "take inner product between two fields and return value.");
59 false,
"NotSet",
"Fld file form which to interpolate field");
61 ConfigOption(
false,
"All",
"field id's to be used in inner product");
64 "Take inner product of multiple field fields with "
65 "ids given in string. i.e. file_0.chk file_1.chk ...");
68 "Take inner product between all fromflds, "
69 "requires multifldids to be set");
81 if (
m_f->m_exp[0]->GetNumElmts() == 0)
86 string fromfld =
m_config[
"fromfld"].as<
string>();
90 "The config parameter "
91 "fromfld needs to be defined");
95 for (
int i = 0; i <
m_f->m_exp[0]->GetExpSize(); ++i)
97 ElementGIDs[i] =
m_f->m_exp[0]->GetExp(i)->GetGeom()->GetGlobalID();
100 int nfields =
m_f->m_variables.size();
101 int nphys =
m_f->m_exp[0]->GetTotPoints();
103 string fields =
m_config[
"fields"].as<
string>();
104 vector<unsigned int> processFields;
105 string multifldidsstr =
m_config[
"multifldids"].as<
string>();
106 vector<unsigned int> multiFldIds;
107 vector<string> fromfiles;
108 bool allfromflds =
m_config[
"allfromflds"].as<
bool>();
110 if (fields.compare(
"All") == 0)
112 for (
int i = 0; i < nfields; ++i)
114 processFields.push_back(i);
120 "Failed to interpret field string in module innerproduct");
123 if (multifldidsstr.compare(
"NotSet") == 0)
125 fromfiles.push_back(fromfld);
131 "Failed to interpret multifldids string in module innerproduct");
132 int end = fromfld.find_first_of(
'.', 0);
133 string endstr = fromfld.substr(end, fromfld.size());
134 string bodystr = fromfld.substr(0, end);
135 for (
int i = 0; i < multiFldIds.size(); ++i)
137 string infile = bodystr +
"_" +
138 boost::lexical_cast<string>(multiFldIds[i]) +
140 fromfiles.push_back(infile);
145 for (
int j = 0; j < processFields.size(); ++j)
147 int fid = processFields[j];
149 m_f->m_exp[fid]->BwdTrans(
m_f->m_exp[fid]->GetCoeffs(), SaveFld[j]);
152 if (allfromflds ==
false)
155 for (
int f = 0; f < fromfiles.size(); ++f)
157 m_f->FieldIOForFile(fromfiles[f])
158 ->Import(fromfiles[f], fromField->m_fielddef, fromField->m_data,
161 totiprod =
IProduct(processFields, fromField, SaveFld);
163 if (
m_f->m_comm->GetSpaceComm()->GetRank() == 0)
165 cout <<
"Inner Product WRT " << fromfiles[f] <<
" : "
176 for (
int i = 0; i < fromfiles.size(); ++i)
178 allFromField[i] = std::shared_ptr<Field>(
new Field());
180 m_f->FieldIOForFile(fromfiles[i])
181 ->Import(fromfiles[i], allFromField[i]->m_fielddef,
182 allFromField[i]->m_data,
186 for (
int g = 0; g < fromfiles.size(); ++g)
188 for (
int j = 0; j < processFields.size(); ++j)
190 int fid = processFields[j];
193 for (
int i = 0; i < allFromField[g]->m_data.size(); ++i)
195 m_f->m_exp[fid]->ExtractDataToCoeffs(
196 allFromField[g]->m_fielddef[i],
197 allFromField[g]->m_data[i],
m_f->m_variables[fid],
201 m_f->m_exp[fid]->BwdTrans(coeffs, SaveFld[j]);
205 for (
int f = g; f < fromfiles.size(); ++f)
207 totiprod =
IProduct(processFields, allFromField[f], SaveFld);
209 if (
m_f->m_comm->GetSpaceComm()->GetRank() == 0)
211 cout <<
"Inner Product of " << fromfiles[g] <<
" WRT "
212 << fromfiles[f] <<
" : " << totiprod << endl;
223 int nphys =
m_f->m_exp[0]->GetTotPoints();
226 for (
int j = 0; j < processFields.size(); ++j)
228 int fid = processFields[j];
234 for (
int i = 0; i < fromField->m_data.size(); ++i)
236 m_f->m_exp[fid]->ExtractDataToCoeffs(fromField->m_fielddef[i],
237 fromField->m_data[i],
238 m_f->m_variables[fid], coeffs);
241 m_f->m_exp[fid]->BwdTrans(coeffs, phys);
243 Vmath::Vmul(nphys, SaveFld[j], 1, phys, 1, phys, 1);
#define ASSERTL0(condition, msg)
FieldSharedPtr m_f
Field object.
std::map< std::string, ConfigOption > m_config
List of configuration values.
ProcessInnerProduct(FieldSharedPtr f)
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
virtual ~ProcessInnerProduct()
static ModuleKey className
NekDouble IProduct(std::vector< unsigned int > &processFields, FieldSharedPtr &fromField, Array< OneD, const Array< OneD, NekDouble > > &SaveFld)
virtual void v_Process(po::variables_map &vm) override
Write mesh to output file.
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
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.
std::shared_ptr< Field > FieldSharedPtr
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()
static FieldMetaDataMap NullFieldMetaDataMap
The above copyright notice and this permission notice shall be included.
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.
Represents a command-line configuration option.