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

This processing module scales the input fld file. More...

#include <ProcessAddFld.h>

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

Public Member Functions

 ProcessAddFld (FieldSharedPtr f)
 
 ~ProcessAddFld () 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
 
std::vector< ModuleKeyv_GetModulePrerequisites () 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 Attributes

ModulePriority m_priority
 

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 scales the input fld file.

Definition at line 47 of file ProcessAddFld.h.

Constructor & Destructor Documentation

◆ ProcessAddFld()

Nektar::FieldUtils::ProcessAddFld::ProcessAddFld ( FieldSharedPtr  f)

Definition at line 51 of file ProcessAddFld.cpp.

51 : ProcessModule(f)
52{
53 m_config["scale"] = ConfigOption(false, "1.0", "scale factor");
54
55 m_config["fromfld"] =
56 ConfigOption(false, "NotSet", "Fld file form which to add field");
57
58 if (f->m_inputfiles.count("xml"))
59 {
61 }
62 else
63 {
65 }
66}
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272

References Nektar::FieldUtils::eModifyExp, Nektar::FieldUtils::eModifyFieldData, Nektar::FieldUtils::Module::m_config, and m_priority.

◆ ~ProcessAddFld()

Nektar::FieldUtils::ProcessAddFld::~ProcessAddFld ( )
override

Definition at line 68 of file ProcessAddFld.cpp.

69{
70}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 51 of file ProcessAddFld.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::ProcessAddFld::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 69 of file ProcessAddFld.h.

70 {
71 return "Adding new fld to input fld";
72 }

◆ v_GetModuleName()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 64 of file ProcessAddFld.h.

65 {
66 return "ProcessAddFld";
67 }

◆ v_GetModulePrerequisites()

std::vector< ModuleKey > Nektar::FieldUtils::ProcessAddFld::v_GetModulePrerequisites ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 79 of file ProcessAddFld.h.

80 {
81 return {{eProcessModule, "createExp"}};
82 }

References Nektar::FieldUtils::eProcessModule.

◆ v_GetModulePriority()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 74 of file ProcessAddFld.h.

75 {
76 return m_priority;
77 }

References m_priority.

◆ v_Process()

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

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 72 of file ProcessAddFld.cpp.

73{
74 string scalestr = m_config["scale"].as<string>();
75 NekDouble scale = std::stod(scalestr);
76
77 ASSERTL0(m_config["fromfld"].as<string>().compare("NotSet") != 0,
78 "Need to specify fromfld=file.fld ");
79 string fromfld = m_config["fromfld"].as<string>();
80
81 vector<LibUtilities::FieldDefinitionsSharedPtr> fromFieldDef;
82 vector<vector<double>> fromFieldData;
83
84 if (m_f->m_graph)
85 {
86 const SpatialDomains::ExpansionInfoMap &expansions =
87 m_f->m_graph->GetExpansionInfo();
88
89 // if Range has been speficied it is possible to have a
90 // partition which is empty so check this and return if
91 // no elements present.
92
93 if (!expansions.size())
94 {
95 return;
96 }
97
98 Array<OneD, int> ElementGIDs(expansions.size());
99
100 int i = 0;
101 for (auto &expIt : expansions)
102 {
103 ElementGIDs[i++] = expIt.second->m_geomShPtr->GetGlobalID();
104 }
105 m_f->FieldIOForFile(fromfld)->Import(
106 fromfld, fromFieldDef, fromFieldData,
108 }
109 else
110 {
111 m_f->FieldIOForFile(fromfld)->Import(
112 fromfld, fromFieldDef, fromFieldData,
114 }
115
116 bool samelength = true;
117 if (fromFieldData.size() != m_f->m_data.size())
118 {
119 samelength = false;
120 }
121
122 // scale input field
123 for (int i = 0; i < fromFieldData.size(); ++i)
124 {
125 int datalen = fromFieldData[i].size();
126
127 Vmath::Smul(datalen, scale, &(fromFieldData[i][0]), 1,
128 &(fromFieldData[i][0]), 1);
129
130 if (samelength)
131 {
132 if (datalen != m_f->m_data[i].size())
133 {
134 samelength = false;
135 }
136 }
137 }
138
140 {
141 ASSERTL0(samelength == true,
142 "Input fields have partitions of different length and so xml "
143 "file needs to be specified");
144 for (int i = 0; i < m_f->m_data.size(); ++i)
145 {
146 int datalen = m_f->m_data[i].size();
147
148 Vmath::Vadd(datalen, &(m_f->m_data[i][0]), 1,
149 &(fromFieldData[i][0]), 1, &(m_f->m_data[i][0]), 1);
150 }
151 }
152 else
153 {
154 // Skip in case of empty partition
155 if (m_f->m_exp[0]->GetNumElmts() == 0)
156 {
157 return;
158 }
159
160 int nfields = m_f->m_variables.size();
161 int ncoeffs = m_f->m_exp[0]->GetNcoeffs();
162 Array<OneD, NekDouble> SaveFld(ncoeffs);
163
164 for (int j = 0; j < nfields; ++j)
165 {
166 Vmath::Vcopy(ncoeffs, m_f->m_exp[j]->GetCoeffs(), 1, SaveFld, 1);
167
168 // Check if new field has this variable
169 auto it =
170 find(fromFieldDef[0]->m_fields.begin(),
171 fromFieldDef[0]->m_fields.end(), m_f->m_variables[j]);
172
173 ASSERTL0(it != fromFieldDef[0]->m_fields.end(),
174 "Could not find field " + m_f->m_variables[j] +
175 " in from field");
176
177 // load new field
178 for (int i = 0; i < fromFieldData.size(); ++i)
179 {
180 m_f->m_exp[j]->ExtractDataToCoeffs(
181 fromFieldDef[i], fromFieldData[i], m_f->m_variables[j],
182 m_f->m_exp[j]->UpdateCoeffs());
183 }
184
185 Vmath::Vadd(ncoeffs, m_f->m_exp[j]->GetCoeffs(), 1, SaveFld, 1,
186 m_f->m_exp[j]->UpdateCoeffs(), 1);
187 m_f->m_exp[j]->BwdTrans(m_f->m_exp[j]->GetCoeffs(),
188 m_f->m_exp[j]->UpdatePhys());
189 }
190 }
191}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:51
std::map< int, ExpansionInfoShPtr > ExpansionInfoMap
Definition: MeshGraph.h:141
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:475
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
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825

References ASSERTL0, Nektar::FieldUtils::eModifyFieldData, Nektar::StdRegions::find(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, m_priority, Nektar::LibUtilities::NullFieldMetaDataMap, Vmath::Smul(), Vmath::Vadd(), and Vmath::Vcopy().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessAddFld::className
static
Initial value:
"add two fields together with optional scaling. Must specify fromfld and "
"scaling is optionally specified with input option scale.")
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Definition: ProcessAddFld.h:51
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 ProcessAddFld.h.

◆ m_priority

ModulePriority Nektar::FieldUtils::ProcessAddFld::m_priority
private

Definition at line 85 of file ProcessAddFld.h.

Referenced by ProcessAddFld(), v_GetModulePriority(), and v_Process().