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

This processing module adds a new field from a string definition. More...

#include <ProcessFieldFromString.h>

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

Public Member Functions

 ProcessFieldFromString (FieldSharedPtr f)
 
 ~ProcessFieldFromString () 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
 
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 adds a new field from a string definition.

Definition at line 46 of file ProcessFieldFromString.h.

Constructor & Destructor Documentation

◆ ProcessFieldFromString()

Nektar::FieldUtils::ProcessFieldFromString::ProcessFieldFromString ( FieldSharedPtr  f)

Definition at line 55 of file ProcessFieldFromString.cpp.

56 : ProcessModule(f)
57{
58 m_config["fieldstr"] = ConfigOption(false, "NotSet", "Analytic expression");
59 m_config["fieldname"] = ConfigOption(
60 false, "newfield",
61 "name for modified new field, default is \"newfield\" (optional)");
62}
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272

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

◆ ~ProcessFieldFromString()

Nektar::FieldUtils::ProcessFieldFromString::~ProcessFieldFromString ( void  )
override

Definition at line 64 of file ProcessFieldFromString.cpp.

65{
66}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 50 of file ProcessFieldFromString.h.

51 {
53 }
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::ProcessFieldFromString::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 67 of file ProcessFieldFromString.h.

68 {
69 return "Calculating new field";
70 }

◆ v_GetModuleName()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 62 of file ProcessFieldFromString.h.

63 {
64 return "ProcessFieldFromString";
65 }

◆ v_GetModulePriority()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 72 of file ProcessFieldFromString.h.

73 {
74 return eModifyExp;
75 }

References Nektar::FieldUtils::eModifyExp.

◆ v_Process()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 68 of file ProcessFieldFromString.cpp.

69{
70 m_f->SetUpExp(vm);
71
72 // Check if required parameter fieldstr was provided
73 ASSERTL0(m_config["fieldstr"].m_beenSet, "fieldstr must be specified");
74
75 // Get number of fields (before adding new entry)
76 int nfields = m_f->m_variables.size();
77
78 // Set up new field name
79 string fieldName = m_config["fieldname"].as<string>();
80
81 int fieldID;
82 bool addField;
83 // check if field exists
84 auto it =
85 std::find(m_f->m_variables.begin(), m_f->m_variables.end(), fieldName);
86 if (it != m_f->m_variables.end())
87 {
88 addField = false;
89 fieldID = std::distance(m_f->m_variables.begin(), it);
90 }
91 else
92 {
93 // Create new expansion
94 addField = true;
95 fieldID = nfields;
96 m_f->m_variables.push_back(fieldName);
97 }
98
99 // Skip in case of empty partition
100 if (m_f->m_exp[0]->GetNumElmts() == 0)
101 {
102 return;
103 }
104
105 // Check if using strips
106 int nstrips;
107 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
108 ASSERTL0(nstrips == 1,
109 "Routine is currently only setup for non-strip files");
110
111 if (addField)
112 {
113 m_f->m_exp.resize(nfields + 1);
114 m_f->m_exp[nfields] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
115 }
116
117 // Variables for storing names and values for evaluating the function
118 string varstr;
119 vector<Array<OneD, const NekDouble>> interpfields;
120
121 // Add the coordinate values
122 varstr += "x y z";
123 int npoints = m_f->m_exp[0]->GetTotPoints();
124 Array<OneD, NekDouble> x(npoints, 0.0);
125 Array<OneD, NekDouble> y(npoints, 0.0);
126 Array<OneD, NekDouble> z(npoints, 0.0);
127 m_f->m_exp[0]->GetCoords(x, y, z);
128 interpfields.push_back(x);
129 interpfields.push_back(y);
130 interpfields.push_back(z);
131
132 // Add the field values
133 for (int i = 0; i < nfields; ++i)
134 {
135 varstr += " " + m_f->m_variables[i];
136 interpfields.push_back(m_f->m_exp[i]->GetPhys());
137 }
138
139 // Create new function
140 LibUtilities::Interpreter strEval;
141 int exprId = -1;
142 string fieldstr = m_config["fieldstr"].as<string>();
143 exprId = strEval.DefineFunction(varstr.c_str(), fieldstr);
144
145 // Evaluate function
146 strEval.Evaluate(exprId, interpfields, m_f->m_exp[fieldID]->UpdatePhys());
147 // Update coeffs
148 m_f->m_exp[fieldID]->FwdTransLocalElmt(m_f->m_exp[fieldID]->GetPhys(),
149 m_f->m_exp[fieldID]->UpdateCoeffs());
150}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:475
std::vector< double > z(NPUPPER)

References ASSERTL0, Nektar::LibUtilities::Interpreter::DefineFunction(), Nektar::LibUtilities::Interpreter::Evaluate(), Nektar::StdRegions::find(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, and Nektar::UnitTests::z().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessFieldFromString::className
static
Initial value:
=
ModuleKey(eProcessModule, "fieldfromstring"),
"Modify an existing or create a new field from the existing fields as "
"specified by a string using a required argument of the form "
"fieldstr=\"x + y + u\" ")
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 54 of file ProcessFieldFromString.h.