Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
Nektar::Utilities::ProcessInterpPoints Class Reference

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

#include <ProcessInterpPoints.h>

Inheritance diagram for Nektar::Utilities::ProcessInterpPoints:
Inheritance graph
[legend]
Collaboration diagram for Nektar::Utilities::ProcessInterpPoints:
Collaboration graph
[legend]

Public Member Functions

 ProcessInterpPoints (FieldSharedPtr f)
 
virtual ~ProcessInterpPoints ()
 
virtual void Process (po::variables_map &vm)
 Write mesh to output file. More...
 
- Public Member Functions inherited from Nektar::Utilities::ProcessModule
 ProcessModule ()
 
 ProcessModule (FieldSharedPtr p_f)
 
 ProcessModule (MeshSharedPtr p_m)
 
- Public Member Functions inherited from Nektar::Utilities::Module
 Module (FieldSharedPtr p_f)
 
void RegisterConfig (string key, string value)
 Register a configuration option with a module. More...
 
void PrintConfig ()
 Print out all configuration options for a module. More...
 
void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
bool GetRequireEquiSpaced (void)
 
void SetRequireEquiSpaced (bool pVal)
 
void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 
 Module (MeshSharedPtr p_m)
 
virtual void Process ()=0
 
void RegisterConfig (string key, string value)
 
void PrintConfig ()
 
void SetDefaults ()
 
MeshSharedPtr GetMesh ()
 
virtual void ProcessVertices ()
 Extract element vertices. More...
 

Static Public Member Functions

static boost::shared_ptr< Modulecreate (FieldSharedPtr f)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey className
 

Private Member Functions

void InterpolateFieldToPts (vector< MultiRegions::ExpListSharedPtr > &field0, Array< OneD, Array< OneD, NekDouble > > &pts, NekDouble clamp_low, NekDouble clamp_up, NekDouble def_value)
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::Utilities::Module
 Module ()
 
virtual void ProcessEdges (bool ReprocessEdges=true)
 Extract element edges. More...
 
virtual void ProcessFaces (bool ReprocessFaces=true)
 Extract element faces. More...
 
virtual void ProcessElements ()
 Generate element IDs. More...
 
virtual void ProcessComposites ()
 Generate composites. More...
 
void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
void PrismLines (int prism, PerMap &perFaces, set< int > &prismsDone, vector< ElementSharedPtr > &line)
 
- Protected Attributes inherited from Nektar::Utilities::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 
MeshSharedPtr m_mesh
 Mesh object. More...
 

Detailed Description

This processing module interpolates one field to another.

Definition at line 49 of file ProcessInterpPoints.h.

Constructor & Destructor Documentation

Nektar::Utilities::ProcessInterpPoints::ProcessInterpPoints ( FieldSharedPtr  f)

Definition at line 58 of file ProcessInterpPoints.cpp.

References ASSERTL0, and Nektar::Utilities::Module::m_config.

58  : ProcessModule(f)
59 {
60 
61  m_config["fromxml"] =
62  ConfigOption(false, "NotSet",
63  "Xml file from which to interpolate field");
64 
65  ASSERTL0(m_config["fromxml"].as<string>().compare("NotSet") != 0,
66  "Need to specify fromxml=file.xml");
67 
68  m_config["fromfld"] =
69  ConfigOption(false,"NotSet",
70  "Fld file from which to interpolate field");
71 
72  ASSERTL0(m_config["fromfld"].as<string>().compare("NotSet") != 0,
73  "Need to specify fromfld=file.fld ");
74 
75  m_config["clamptolowervalue"] =
76  ConfigOption(false, "-10000000",
77  "Lower bound for interpolation value");
78  m_config["clamptouppervalue"] =
79  ConfigOption(false, "10000000",
80  "Upper bound for interpolation value");
81  m_config["defaultvalue"] =
82  ConfigOption(false, "0",
83  "Default value if point is outside domain");
84  m_config["line"] =
85  ConfigOption(false, "NotSet",
86  "Specify a line of N points using "
87  "line=N,x0,y0,z0,z1,y1,z1");
88 
89  m_config["plane"] =
90  ConfigOption(false, "NotSet",
91  "Specify a plane of N1 x N1 points using "
92  "plane=N1,N2,x0,y0,z0,z1,y1,z1,x2,y2,z2,x3,"
93  "y3,z3");
94 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
map< string, ConfigOption > m_config
List of configuration values.
Nektar::Utilities::ProcessInterpPoints::~ProcessInterpPoints ( )
virtual

Definition at line 96 of file ProcessInterpPoints.cpp.

97 {
98 }

Member Function Documentation

static boost::shared_ptr<Module> Nektar::Utilities::ProcessInterpPoints::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 53 of file ProcessInterpPoints.h.

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

53  {
55  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void Nektar::Utilities::ProcessInterpPoints::InterpolateFieldToPts ( vector< MultiRegions::ExpListSharedPtr > &  field0,
Array< OneD, Array< OneD, NekDouble > > &  pts,
NekDouble  clamp_low,
NekDouble  clamp_up,
NekDouble  def_value 
)
private

Definition at line 333 of file ProcessInterpPoints.cpp.

References ASSERTL0, and Nektar::Utilities::Module::m_f.

Referenced by Process().

339 {
340  int expdim = field0[0]->GetCoordim(0);
341 
342  Array<OneD, NekDouble> coords(expdim), Lcoords(expdim);
343  int nq1 = pts[0].num_elements();
344  int elmtid, offset;
345  int r, f;
346  int intpts = 0;
347 
348  // resize data field
349  m_f->m_data.resize(field0.size());
350 
351  for (f = 0; f < field0.size(); ++f)
352  {
353  m_f->m_data[f].resize(nq1);
354  }
355 
356  for (r = 0; r < nq1; r++)
357  {
358  coords[0] = pts[0][r];
359  coords[1] = pts[1][r];
360  if (expdim == 3)
361  {
362  coords[2] = pts[2][r];
363  }
364 
365  // Obtain Element and LocalCoordinate to interpolate
366  elmtid = field0[0]->GetExpIndex(coords, Lcoords, 1e-3);
367 
368  if(elmtid >= 0)
369  {
370  offset = field0[0]->GetPhys_Offset(field0[0]->
371  GetOffset_Elmt_Id(elmtid));
372 
373  for (f = 0; f < field0.size(); ++f)
374  {
375  NekDouble value;
376  value = field0[f]->GetExp(elmtid)->
377  StdPhysEvaluate(Lcoords, field0[f]->GetPhys() +offset);
378 
379  if ((boost::math::isnan)(value))
380  {
381  ASSERTL0(false, "new value is not a number");
382  }
383  else
384  {
385  value = (value > clamp_up)? clamp_up :
386  ((value < clamp_low)? clamp_low :
387  value);
388 
389  m_f->m_data[f][r] = value;
390  }
391  }
392  }
393  else
394  {
395  for (f = 0; f < field0.size(); ++f)
396  {
397  m_f->m_data[f][r] = def_value;
398  }
399  }
400 
401  if (intpts%1000 == 0)
402  {
403  cout <<"." << flush;
404  }
405  intpts ++;
406  }
407 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
FieldSharedPtr m_f
Field object.
double NekDouble
void Nektar::Utilities::ProcessInterpPoints::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Implements Nektar::Utilities::Module.

Definition at line 100 of file ProcessInterpPoints.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::SessionReader::CreateInstance(), Nektar::LibUtilities::ePtsLine, Nektar::LibUtilities::ePtsPlane, Nektar::ParseUtils::GenerateUnOrderedVector(), InterpolateFieldToPts(), Nektar::Utilities::Module::m_config, Nektar::Utilities::Module::m_f, npts, Nektar::LibUtilities::NullFieldMetaDataMap, Nektar::LibUtilities::NullPtsField, Nektar::SpatialDomains::MeshGraph::Read(), Vmath::Vmax(), and Vmath::Vmin().

101 {
102 
103  if(m_f->m_verbose)
104  {
105  cout << "Processing point interpolation" << endl;
106  }
107 
108 
109  // Check for command line point specification if no .pts file specified
110  if(m_f->m_fieldPts == LibUtilities::NullPtsField)
111  {
112  if(m_config["line"].as<string>().compare("NotSet") != 0)
113  {
114  string help = m_config["line"].as<string>();
115  vector<NekDouble> values;
117  m_config["line"].as<string>().c_str(),values),
118  "Failed to interpret line string");
119 
120  ASSERTL0(values.size() > 3,
121  "line string should contain 2Dim+1 values "
122  "N,x0,y0,z0,x1,y1,z1");
123 
124  int dim = (values.size()-1)/2;
125  int npts = values[0];
127 
128  for(int i = 0; i < dim; ++i)
129  {
130  pts[i] = Array<OneD,NekDouble>(npts);
131  }
132 
133  for(int i = 0; i < npts; ++i)
134  {
135  pts[0][i] = values[1]
136  + i/((NekDouble)(npts-1))*(values[dim+1] - values[1]);
137  if(dim > 1)
138  {
139  pts[1][i] = values[2]
140  + i/((NekDouble)(npts-1))*(values[dim+2] - values[2]);
141 
142  if(dim > 2)
143  {
144  pts[2][i] = values[3]
145  + i/((NekDouble)(npts-1))*(values[dim+3] - values[3]);
146  }
147  }
148  }
149 
150  vector<int> ppe;
151  ppe.push_back(npts);
153  m_f->m_fieldPts->SetPointsPerEdge(ppe);
154  m_f->m_fieldPts->SetPtsType(LibUtilities::ePtsLine);
155 
156  }
157  else if(m_config["plane"].as<string>().compare("NotSet") != 0)
158  {
159  string help = m_config["plane"].as<string>();
160  vector<NekDouble> values;
162  m_config["plane"].as<string>().c_str(),values),
163  "Failed to interpret plane string");
164 
165  ASSERTL0(values.size() > 3,
166  "line string should contain 2Dim+1 values "
167  "N,x0,y0,z0,x1,y1,z1");
168 
169 
170  int dim = (values.size()-1)/4;
171 
172  int npts1 = values[0];
173  int npts2 = values[1];
174 
176 
177  for(int i = 0; i < dim; ++i)
178  {
179  pts[i] = Array<OneD,NekDouble>(npts1*npts2);
180  }
181 
182  for(int j = 0; j < npts2; ++j)
183  {
184  for(int i = 0; i < npts1; ++i)
185  {
186  pts[0][i+j*npts1] =
187  (values[2] + i/((NekDouble)(npts1-1))*(values[dim+2] - values[2]))*(1.0-j/((NekDouble)(npts2-1))) +
188  (values[3*dim+2] + i/((NekDouble)(npts1-1))*(values[2*dim+2] - values[3*dim+2]))*(j/((NekDouble)(npts2-1)));
189  if(dim > 1)
190  {
191  pts[1][i+j*npts1] =
192  (values[3] + i/((NekDouble)(npts1-1))*(values[dim+3] - values[3]))*(1.0-j/((NekDouble)(npts2-1))) +
193  (values[3*dim+3] + i/((NekDouble)(npts1-1))*(values[2*dim+3] - values[3*dim+3]))*(j/((NekDouble)(npts2-1)));
194 
195  if(dim > 2)
196  {
197  pts[2][i+j*npts1] =
198  (values[4] + i/((NekDouble)(npts1-1))*(values[dim+4] - values[4]))*(1.0-j/((NekDouble)(npts2-1))) +
199  (values[3*dim+4] + i/((NekDouble)(npts1-1))*(values[2*dim+4] - values[3*dim+4]))*(j/((NekDouble)(npts2-1)));
200  }
201  }
202  }
203  }
204 
205  vector<int> ppe;
206  ppe.push_back(npts1);
207  ppe.push_back(npts2);
209  m_f->m_fieldPts->SetPointsPerEdge(ppe);
210  m_f->m_fieldPts->SetPtsType(LibUtilities::ePtsPlane);
211 
212  }
213  }
214 
215 
216  FieldSharedPtr fromField = boost::shared_ptr<Field>(new Field());
217 
218  std::vector<std::string> files;
219  // set up session file for from field
220  files.push_back(m_config["fromxml"].as<string>());
221  fromField->m_session = LibUtilities::SessionReader::
222  CreateInstance(0, 0, files);
223 
224  // Set up range based on min and max of local parallel partition
226 
227  int coordim = m_f->m_fieldPts->GetDim();
228  int npts = m_f->m_fieldPts->GetNpoints();
230  m_f->m_fieldPts->GetPts(pts);
231 
232  rng->m_checkShape = false;
233  switch(coordim)
234  {
235  case 3:
236  rng->m_doZrange = true;
237  rng->m_zmin = Vmath::Vmin(npts, pts[2],1);
238  rng->m_zmax = Vmath::Vmax(npts, pts[2],1);
239  case 2:
240  rng->m_doYrange = true;
241  rng->m_ymin = Vmath::Vmin(npts, pts[1],1);
242  rng->m_ymax = Vmath::Vmax(npts, pts[1],1);
243  case 1:
244  rng->m_doXrange = true;
245  rng->m_xmin = Vmath::Vmin(npts, pts[0],1);
246  rng->m_xmax = Vmath::Vmax(npts, pts[0],1);
247  break;
248  default:
249  ASSERTL0(false,"too many values specfied in range");
250  }
251 
252  // setup rng parameters.
253  fromField->m_graph = SpatialDomains::MeshGraph::Read(fromField->m_session,rng);
254 
255  // Read in local from field partitions
256  const SpatialDomains::ExpansionMap &expansions = fromField->m_graph->GetExpansions();
257 
258  fromField->m_fld = MemoryManager<LibUtilities::FieldIO>
259  ::AllocateSharedPtr(fromField->m_session->GetComm());
260 
261  Array<OneD,int> ElementGIDs(expansions.size());
262  SpatialDomains::ExpansionMap::const_iterator expIt;
263 
264  int i = 0;
265  for (expIt = expansions.begin(); expIt != expansions.end();
266  ++expIt)
267  {
268  ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
269  }
270 
271  string fromfld = m_config["fromfld"].as<string>();
272  fromField->m_fld->Import(fromfld,fromField->m_fielddef,
273  fromField->m_data,
275  ElementGIDs);
276 
277  int NumHomogeneousDir = fromField->m_fielddef[0]->m_numHomogeneousDir;
278 
279  //----------------------------------------------
280  // Set up Expansion information to use mode order from field
281  fromField->m_graph->SetExpansions(fromField->m_fielddef);
282 
283  int nfields = fromField->m_fielddef[0]->m_fields.size();
284 
285  fromField->m_exp.resize(nfields);
286  fromField->m_exp[0] = fromField->SetUpFirstExpList(NumHomogeneousDir,true);
287 
288  m_f->m_exp.resize(nfields);
289 
290  // declare auxiliary fields.
291  for(i = 1; i < nfields; ++i)
292  {
293  fromField->m_exp[i] = fromField->AppendExpList(NumHomogeneousDir);
294  }
295 
296  // load field into expansion in fromfield.
297  for(int j = 0; j < nfields; ++j)
298  {
299  for (i = 0; i < fromField->m_fielddef.size(); i++)
300  {
301  fromField->m_exp[j]->ExtractDataToCoeffs(
302  fromField->m_fielddef[i],
303  fromField->m_data[i],
304  fromField->m_fielddef[0]->m_fields[j],
305  fromField->m_exp[j]->UpdateCoeffs());
306  }
307  fromField->m_exp[j]->BwdTrans(fromField->m_exp[j]->GetCoeffs(),
308  fromField->m_exp[j]->UpdatePhys());
309 
310  Array< OneD, NekDouble > newPts(m_f->m_fieldPts->GetNpoints());
311  m_f->m_fieldPts->AddField(newPts, fromField->m_fielddef[0]->m_fields[j]);
312  }
313 
314  if(fromField->m_session->GetComm()->GetRank() == 0)
315  {
316  cout << "Interpolating [" << flush;
317  }
318 
319  NekDouble clamp_low = m_config["clamptolowervalue"].as<NekDouble>();
320  NekDouble clamp_up = m_config["clamptouppervalue"].as<NekDouble>();
321  NekDouble def_value = m_config["defaultvalue"].as<NekDouble>();
322 
323  InterpolateFieldToPts(fromField->m_exp, pts,
324  clamp_low, clamp_up, def_value);
325 
326  if(fromField->m_session->GetComm()->GetRank() == 0)
327  {
328  cout << "]" << endl;
329  }
330 
331 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
static boost::shared_ptr< MeshGraph > Read(const LibUtilities::SessionReaderSharedPtr &pSession, DomainRangeShPtr &rng=NullDomainRangeShPtr)
Definition: MeshGraph.cpp:119
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
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.cpp:756
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.cpp:848
map< string, ConfigOption > m_config
List of configuration values.
FieldSharedPtr m_f
Field object.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
static std::string npts
Definition: InputFld.cpp:43
boost::shared_ptr< DomainRange > DomainRangeShPtr
Definition: MeshGraph.h:154
double NekDouble
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:677
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:249
static bool GenerateUnOrderedVector(const char *const str, std::vector< NekDouble > &vec)
Definition: ParseUtils.hpp:127
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:66
std::map< int, ExpansionShPtr > ExpansionMap
Definition: MeshGraph.h:171
void InterpolateFieldToPts(vector< MultiRegions::ExpListSharedPtr > &field0, Array< OneD, Array< OneD, NekDouble > > &pts, NekDouble clamp_low, NekDouble clamp_up, NekDouble def_value)

Member Data Documentation

ModuleKey Nektar::Utilities::ProcessInterpPoints::className
static
Initial value:
=
ModuleKey(eProcessModule, "interppoints"),
"Interpolates a set of points to another, requires fromfld and "
"fromxml to be defined, a line or plane of points can be "
"defined")

Definition at line 56 of file ProcessInterpPoints.h.