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

This processing module interpolates one field to another. More...

#include <ProcessInterpField.h>

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

Public Member Functions

 ProcessInterpField (FieldSharedPtr f)
 
 ~ProcessInterpField () 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...
 
void PrintProgressbar (const int position, const int goal) const
 
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 interpolates one field to another.

Definition at line 46 of file ProcessInterpField.h.

Constructor & Destructor Documentation

◆ ProcessInterpField()

Nektar::FieldUtils::ProcessInterpField::ProcessInterpField ( FieldSharedPtr  f)

Definition at line 60 of file ProcessInterpField.cpp.

60 : ProcessModule(f)
61{
62
63 m_config["fromxml"] = ConfigOption(
64 false, "NotSet", "Xml file from which to interpolate field");
65 m_config["fromfld"] = ConfigOption(
66 false, "NotSet", "Fld file from which to interpolate field");
67
68 m_config["clamptolowervalue"] =
69 ConfigOption(false, "-10000000", "Lower bound for interpolation value");
70 m_config["clamptouppervalue"] =
71 ConfigOption(false, "10000000", "Upper bound for interpolation value");
72 m_config["defaultvalue"] =
73 ConfigOption(false, "0", "Default value if point is outside domain");
74 m_config["realmodetoimag"] =
75 ConfigOption(false, "NotSet", "Take fields as sin mode");
76 m_config["distTolerance"] =
77 ConfigOption(false, "1e-5", "The maximum acceptable distance.");
78}
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272

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

◆ ~ProcessInterpField()

Nektar::FieldUtils::ProcessInterpField::~ProcessInterpField ( )
override

Definition at line 80 of file ProcessInterpField.cpp.

81{
82}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

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

◆ PrintProgressbar()

void Nektar::FieldUtils::ProcessInterpField::PrintProgressbar ( const int  position,
const int  goal 
) const
protected

Definition at line 278 of file ProcessInterpField.cpp.

280{
281 LibUtilities::PrintProgressbar(position, goal, "Interpolating");
282}
int PrintProgressbar(const int position, const int goal, const std::string message, int lastprogress=-1)
Prints a progressbar.
Definition: Progressbar.hpp:65

References Nektar::LibUtilities::PrintProgressbar().

Referenced by v_Process().

◆ v_GetModuleDescription()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 70 of file ProcessInterpField.h.

71 {
72 return "Interpolating field";
73 }

◆ v_GetModuleName()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 65 of file ProcessInterpField.h.

66 {
67 return "ProcessInterpField";
68 }

◆ v_GetModulePriority()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 75 of file ProcessInterpField.h.

76 {
77 return eFillExp;
78 }

References Nektar::FieldUtils::eFillExp.

◆ v_Process()

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

Write mesh to output file.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 84 of file ProcessInterpField.cpp.

85{
86 m_f->SetUpExp(vm);
87
88 FieldSharedPtr fromField = std::shared_ptr<Field>(new Field());
89
90 std::vector<std::string> files;
91
92 // set up session file for from field
93 char *argv[] = {const_cast<char *>("FieldConvert"), nullptr};
94 ParseUtils::GenerateVector(m_config["fromxml"].as<string>(), files);
96 1, argv, files,
97 LibUtilities::GetCommFactory().CreateInstance("Serial", 0, 0));
98
99 // Set up range based on min and max of local parallel partition
102
103 int numHomoDir = m_f->m_numHomogeneousDir;
104 int coordim = m_f->m_exp[0]->GetCoordim(0) + numHomoDir;
105 int npts = m_f->m_exp[0]->GetTotPoints();
106 Array<OneD, Array<OneD, NekDouble>> coords(3);
107
108 for (int i = 0; i < coordim; ++i)
109 {
110 coords[i] = Array<OneD, NekDouble>(npts);
111 }
112
113 for (int i = coordim; i < 3; ++i)
114 {
115 coords[i] = NullNekDouble1DArray;
116 }
117
118 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
119
120 rng->m_checkShape = false;
121 switch (coordim)
122 {
123 case 3:
124 rng->m_doZrange = true;
125 rng->m_zmin = Vmath::Vmin(npts, coords[2], 1);
126 rng->m_zmax = Vmath::Vmax(npts, coords[2], 1);
127 /* Falls through. */
128 case 2:
129 rng->m_doYrange = true;
130 rng->m_ymin = Vmath::Vmin(npts, coords[1], 1);
131 rng->m_ymax = Vmath::Vmax(npts, coords[1], 1);
132 /* Falls through. */
133 case 1:
134 rng->m_doXrange = true;
135 rng->m_xmin = Vmath::Vmin(npts, coords[0], 1);
136 rng->m_xmax = Vmath::Vmax(npts, coords[0], 1);
137 break;
138 default:
139 NEKERROR(ErrorUtil::efatal, "coordim should be <= 3");
140 }
141
142 // setup rng parameters.
143 fromField->m_graph =
144 SpatialDomains::MeshGraphIO::Read(fromField->m_session, rng);
145
146 // Read in local from field partitions
147 const SpatialDomains::ExpansionInfoMap &expansions =
148 fromField->m_graph->GetExpansionInfo();
149
150 // check for case where no elements are specified on this
151 // parallel partition
152 if (!expansions.size())
153 {
154 return;
155 }
156
157 Array<OneD, int> ElementGIDs(expansions.size());
158
159 int i = 0;
160 for (auto &expIt : expansions)
161 {
162 ElementGIDs[i++] = expIt.second->m_geomShPtr->GetGlobalID();
163 }
164
165 string fromfld = m_config["fromfld"].as<string>();
166 m_f->FieldIOForFile(fromfld)->Import(
167 fromfld, fromField->m_fielddef, fromField->m_data,
169
170 int fromNumHomoDir = fromField->m_fielddef[0]->m_numHomogeneousDir;
171 for (i = 0; i < fromField->m_fielddef.size(); ++i)
172 {
173 int d1 = fromField->m_fielddef[i]->m_basis.size();
174 d1 -= 1;
175 if (d1 >= 0 && (fromField->m_fielddef[i]->m_basis[d1] ==
177 fromField->m_fielddef[i]->m_basis[d1] ==
179 {
180 fromField->m_fielddef[i]->m_homogeneousZIDs[0] += 2;
181 fromField->m_fielddef[i]->m_numModes[d1] = 4;
182 fromField->m_fielddef[i]->m_basis[d1] = LibUtilities::eFourier;
183 }
184 }
185
186 //----------------------------------------------
187 // Set up Expansion information to use mode order from field
188 fromField->m_graph->SetExpansionInfo(fromField->m_fielddef);
189
190 int nfields = fromField->m_fielddef[0]->m_fields.size();
191
192 fromField->m_exp.resize(nfields);
193 fromField->m_exp[0] = fromField->SetUpFirstExpList(fromNumHomoDir, true);
194
195 m_f->m_exp.resize(nfields);
196
197 // declare auxiliary fields.
198 for (i = 1; i < nfields; ++i)
199 {
200 m_f->m_exp[i] = m_f->AppendExpList(numHomoDir);
201 fromField->m_exp[i] = fromField->AppendExpList(fromNumHomoDir);
202 }
203
204 // load field into expansion in fromfield.
205 set<int> sinmode;
206 if (m_config["realmodetoimag"].as<string>().compare("NotSet"))
207 {
208 ParseUtils::GenerateVariableSet(m_config["realmodetoimag"].as<string>(),
209 m_f->m_variables, sinmode);
210 }
211 for (int j = 0; j < nfields; ++j)
212 {
213 for (i = 0; i < fromField->m_fielddef.size(); i++)
214 {
215 fromField->m_exp[j]->ExtractDataToCoeffs(
216 fromField->m_fielddef[i], fromField->m_data[i],
217 fromField->m_fielddef[0]->m_fields[j],
218 fromField->m_exp[j]->UpdateCoeffs());
219 }
220 if (fromNumHomoDir == 1)
221 {
222 fromField->m_exp[j]->SetWaveSpace(true);
223 if (sinmode.count(j))
224 {
225 int Ncoeff = fromField->m_exp[j]->GetPlane(2)->GetNcoeffs();
227 Ncoeff, -1., fromField->m_exp[j]->GetPlane(2)->GetCoeffs(),
228 1, fromField->m_exp[j]->GetPlane(3)->UpdateCoeffs(), 1);
229 Vmath::Zero(Ncoeff,
230 fromField->m_exp[j]->GetPlane(2)->UpdateCoeffs(),
231 1);
232 }
233 }
234 fromField->m_exp[j]->BwdTrans(fromField->m_exp[j]->GetCoeffs(),
235 fromField->m_exp[j]->UpdatePhys());
236 }
237
238 int nq1 = m_f->m_exp[0]->GetTotPoints();
239
240 NekDouble clamp_low = m_config["clamptolowervalue"].as<NekDouble>();
241 NekDouble clamp_up = m_config["clamptouppervalue"].as<NekDouble>();
242 NekDouble def_value = m_config["defaultvalue"].as<NekDouble>();
243 NekDouble tolerance = m_config["distTolerance"].as<NekDouble>();
244
245 Interpolator<std::vector<MultiRegions::ExpListSharedPtr>> interp;
246 if (m_f->m_verbose && m_f->m_comm->TreatAsRankZero())
247 {
248 interp.SetProgressCallback(&ProcessInterpField::PrintProgressbar, this);
249 }
250
251 interp.Interpolate(fromField->m_exp, m_f->m_exp, def_value, tolerance);
252
253 if (m_f->m_verbose && m_f->m_comm->TreatAsRankZero())
254 {
255 cout << endl;
256 }
257
258 for (int i = 0; i < nfields; ++i)
259 {
260 for (int j = 0; j < nq1; ++j)
261 {
262 if (m_f->m_exp[i]->GetPhys()[j] > clamp_up)
263 {
264 m_f->m_exp[i]->UpdatePhys()[j] = clamp_up;
265 }
266 else if (m_f->m_exp[i]->GetPhys()[j] < clamp_low)
267 {
268 m_f->m_exp[i]->UpdatePhys()[j] = clamp_low;
269 }
270 }
271 m_f->m_exp[i]->FwdTransLocalElmt(m_f->m_exp[i]->GetPhys(),
272 m_f->m_exp[i]->UpdateCoeffs());
273 }
274 // save field names
275 m_f->m_variables = fromField->m_fielddef[0]->m_fields;
276}
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
void PrintProgressbar(const int position, const int goal) const
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
static bool GenerateVariableSet(const std::string &str, const std::vector< std::string > &variables, std::set< int > &out)
Generate a set of variable locations.
Definition: ParseUtils.cpp:168
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 MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
Definition: MeshGraphIO.cpp:53
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:1026
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:51
std::shared_ptr< DomainRange > DomainRangeShPtr
Definition: DomainRange.h:64
CommFactory & GetCommFactory()
@ eFourierHalfModeIm
Fourier Modified expansions with just the imaginary part of the first mode .
Definition: BasisType.h:68
@ eFourierHalfModeRe
Fourier Modified expansions with just the real part of the first mode .
Definition: BasisType.h:66
@ eFourier
Fourier Expansion .
Definition: BasisType.h:55
std::map< int, ExpansionInfoShPtr > ExpansionInfoMap
Definition: MeshGraph.h:141
static Array< OneD, NekDouble > NullNekDouble1DArray
double NekDouble
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
Definition: Vmath.hpp:725
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 Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.hpp:273
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
Definition: Vmath.hpp:644

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::LibUtilities::SessionReader::CreateInstance(), Nektar::ErrorUtil::efatal, Nektar::LibUtilities::eFourier, Nektar::LibUtilities::eFourierHalfModeIm, Nektar::LibUtilities::eFourierHalfModeRe, Nektar::ParseUtils::GenerateVariableSet(), Nektar::ParseUtils::GenerateVector(), Nektar::LibUtilities::GetCommFactory(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, NEKERROR, Nektar::LibUtilities::NullFieldMetaDataMap, Nektar::NullNekDouble1DArray, PrintProgressbar(), Nektar::SpatialDomains::MeshGraphIO::Read(), Nektar::LibUtilities::Interpolator::SetProgressCallback(), Vmath::Smul(), Vmath::Vmax(), Vmath::Vmin(), and Vmath::Zero().

Member Data Documentation

◆ className

ModuleKey Nektar::FieldUtils::ProcessInterpField::className
static
Initial value:
=
"Interpolates one field to another, requires fromxml, "
"fromfld to be defined")
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 ProcessInterpField.h.