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)
 
virtual ~ProcessFieldFromString ()
 
- 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 ()
 
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

virtual void v_Process (po::variables_map &vm) override
 
virtual std::string v_GetModuleName () override
 
virtual std::string v_GetModuleDescription () override
 
virtual 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 ()
 

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 48 of file ProcessFieldFromString.h.

Constructor & Destructor Documentation

◆ ProcessFieldFromString()

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

Definition at line 59 of file ProcessFieldFromString.cpp.

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

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

◆ ~ProcessFieldFromString()

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

Definition at line 68 of file ProcessFieldFromString.cpp.

69{
70}

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 52 of file ProcessFieldFromString.h.

53 {
55 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ v_GetModuleDescription()

virtual std::string Nektar::FieldUtils::ProcessFieldFromString::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 69 of file ProcessFieldFromString.h.

70 {
71 return "Calculating new field";
72 }

◆ v_GetModuleName()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 64 of file ProcessFieldFromString.h.

65 {
66 return "ProcessFieldFromString";
67 }

◆ v_GetModulePriority()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 74 of file ProcessFieldFromString.h.

75 {
76 return eModifyExp;
77 }

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 72 of file ProcessFieldFromString.cpp.

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

Definition at line 56 of file ProcessFieldFromString.h.