Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Nektar::FieldUtils::ProcessAverageFld Class Reference

This processing module averages the input fld files. More...

#include <ProcessAverageFld.h>

Inheritance diagram for Nektar::FieldUtils::ProcessAverageFld:
[legend]

Public Member Functions

 ProcessAverageFld (FieldSharedPtr f)
 
 ~ProcessAverageFld () 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 ()
 

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 averages the input fld files.

Definition at line 47 of file ProcessAverageFld.h.

Constructor & Destructor Documentation

◆ ProcessAverageFld()

Nektar::FieldUtils::ProcessAverageFld::ProcessAverageFld ( FieldSharedPtr  f)

Definition at line 53 of file ProcessAverageFld.cpp.

53 : ProcessModule(f)
54{
55 m_config["inputfld"] =
56 ConfigOption(false, "NotSet", "Fld file form which to average");
57 m_config["range"] = ConfigOption(false, "NotSet", "range of file numbers");
58}
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272

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

◆ ~ProcessAverageFld()

Nektar::FieldUtils::ProcessAverageFld::~ProcessAverageFld ( )
override

Definition at line 60 of file ProcessAverageFld.cpp.

61{
62}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 51 of file ProcessAverageFld.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().

◆ v_GetModuleDescription()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 69 of file ProcessAverageFld.h.

70 {
71 return "Averaging input flds";
72 }

◆ v_GetModuleName()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 64 of file ProcessAverageFld.h.

65 {
66 return "ProcessAverageFld";
67 }

◆ v_GetModulePriority()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 74 of file ProcessAverageFld.h.

75 {
76 return eFillExp;
77 }

References Nektar::FieldUtils::eFillExp.

◆ v_Process()

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

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 64 of file ProcessAverageFld.cpp.

65{
66 m_f->SetUpExp(vm);
67 ASSERTL0(m_config["inputfld"].as<string>().compare("NotSet") != 0,
68 "Need to specify inputfld=file_%.fld ");
69 ASSERTL0(m_config["range"].as<string>().compare("NotSet") != 0,
70 "Need to specify range=ns,dn,ne[include]");
71
72 std::string infilename = m_config["inputfld"].as<string>();
73 std::vector<int> range;
74 ASSERTL0(ParseUtils::GenerateVector(m_config["range"].as<string>(), range),
75 "Failed to interpret range string");
77 range.size() == 3,
78 "range string should contain 3 values nstart, deltan, nend[include].");
79
80 vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef;
81 vector<vector<double>> FieldData;
82 NekDouble scale = 0.;
83 for (int i = range[0]; i <= range[2]; i += range[1])
84 {
85 boost::format filenameformat(infilename);
86 filenameformat % i;
87 string inputfldname = filenameformat.str();
88 vector<LibUtilities::FieldDefinitionsSharedPtr> tempFieldDef;
89 vector<vector<double>> tempFieldData;
90
91 if (m_f->m_graph)
92 {
93 const SpatialDomains::ExpansionInfoMap &expansions =
94 m_f->m_graph->GetExpansionInfo();
95
96 // if Range has been speficied it is possible to have a
97 // partition which is empty so check this and return if
98 // no elements present.
99
100 if (!expansions.size())
101 {
102 return;
103 }
104
105 Array<OneD, int> ElementGIDs(expansions.size());
106
107 int i = 0;
108 for (auto &expIt : expansions)
109 {
110 ElementGIDs[i++] = expIt.second->m_geomShPtr->GetGlobalID();
111 }
112 m_f->FieldIOForFile(inputfldname)
113 ->Import(inputfldname, tempFieldDef, tempFieldData,
115 }
116 else
117 {
118 m_f->FieldIOForFile(inputfldname)
119 ->Import(inputfldname, tempFieldDef, tempFieldData,
121 }
122
123 if (FieldDef.size() == 0)
124 {
125 FieldDef = tempFieldDef;
126 }
127
128 if (FieldData.size() < tempFieldData.size())
129 {
130 FieldData.resize(tempFieldData.size());
131 }
132
133 for (size_t i = 0; i < tempFieldData.size(); ++i)
134 {
135 if (FieldData[i].size() < tempFieldData[i].size())
136 {
137 FieldData[i].resize(tempFieldData[i].size(), 0.);
138 }
139 Vmath::Vadd(FieldData[i].size(), tempFieldData[i].data(), 1,
140 FieldData[i].data(), 1, FieldData[i].data(), 1);
141 }
142 if (m_f->m_comm->GetSpaceComm()->GetRank() == 0 && vm.count("verbose"))
143 {
144 std::cout << "File " << inputfldname << " processed." << std::endl;
145 }
146 scale += 1.;
147 }
148 if (scale < 0.5)
149 {
150 return; // no input file
151 }
152 scale = 1. / scale;
153
154 // Filling expansion
155 int numHomoDir = m_f->m_numHomogeneousDir;
156 int nfields = FieldDef[0]->m_fields.size();
157 m_f->m_exp.resize(nfields);
158 for (int i = 1; i < nfields; ++i)
159 {
160 m_f->m_exp[i] = m_f->AppendExpList(numHomoDir);
161 }
162 m_f->m_variables = FieldDef[0]->m_fields;
163
164 for (int j = 0; j < nfields; ++j)
165 {
166 // load new field
167 for (int i = 0; i < FieldDef.size(); ++i)
168 {
169 m_f->m_exp[j]->ExtractDataToCoeffs(FieldDef[i], FieldData[i],
170 m_f->m_variables[j],
171 m_f->m_exp[j]->UpdateCoeffs());
172 }
173 Vmath::Smul(m_f->m_exp[j]->GetNcoeffs(), scale,
174 m_f->m_exp[j]->UpdateCoeffs(), 1,
175 m_f->m_exp[j]->UpdateCoeffs(), 1);
176 m_f->m_exp[j]->BwdTrans(m_f->m_exp[j]->GetCoeffs(),
177 m_f->m_exp[j]->UpdatePhys());
178 }
179}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
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 FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:51
std::map< int, ExpansionInfoShPtr > ExpansionInfoMap
Definition: MeshGraph.h:141
double NekDouble
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.hpp:180
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.hpp:100

References ASSERTL0, CellMLToNektar.pycml::format, Nektar::ParseUtils::GenerateVector(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, Nektar::LibUtilities::NullFieldMetaDataMap, Vmath::Smul(), and Vmath::Vadd().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessAverageFld::className
static
Initial value:
=
"averaging of several field files. Must specify inputfld and range of "
"file numbers.")
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.
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47

Definition at line 55 of file ProcessAverageFld.h.