Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
Nektar::Utilities::ProcessInterpField Class Reference

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

#include <ProcessInterpField.h>

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

Public Member Functions

 ProcessInterpField (FieldSharedPtr f)
 
virtual ~ProcessInterpField ()
 
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 (std::string key, std::string value)
 
void PrintConfig ()
 
void SetDefaults ()
 
MeshSharedPtr GetMesh ()
 
virtual void ProcessVertices ()
 Extract element vertices. More...
 
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...
 
virtual void ClearElementLinks ()
 

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 InterpolateField (vector< MultiRegions::ExpListSharedPtr > &field0, vector< MultiRegions::ExpListSharedPtr > &field1, Array< OneD, NekDouble > x, Array< OneD, NekDouble > y, Array< OneD, NekDouble > z, NekDouble clamp_low, NekDouble clamp_up, NekDouble def_value)
 

Private Attributes

FieldSharedPtr m_fromField
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::Utilities::Module
 Module ()
 
void ReorderPrisms (PerMap &perFaces)
 Reorder node IDs so that prisms and tetrahedra are aligned correctly. More...
 
void PrismLines (int prism, PerMap &perFaces, std::set< int > &prismsDone, std::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...
 
std::map< std::string,
ConfigOption
m_config
 List of configuration values. More...
 

Detailed Description

This processing module interpolates one field to another.

Definition at line 49 of file ProcessInterpField.h.

Constructor & Destructor Documentation

Nektar::Utilities::ProcessInterpField::ProcessInterpField ( FieldSharedPtr  f)

Definition at line 57 of file ProcessInterpField.cpp.

References Nektar::Utilities::Module::m_config.

57  : ProcessModule(f)
58 {
59 
60  m_config["fromxml"] = ConfigOption(false, "NotSet",
61  "Xml file form which to interpolate field");
62  m_config["fromfld"] = ConfigOption(false, "NotSet",
63  "Fld file form which to interpolate field");
64 
65  m_config["clamptolowervalue"] = ConfigOption(false,"-10000000",
66  "Lower bound for interpolation value");
67  m_config["clamptouppervalue"] = ConfigOption(false,"10000000",
68  "Upper bound for interpolation value");
69  m_config["defaultvalue"] = ConfigOption(false,"0",
70  "Default value if point is outside domain");
71 }
map< string, ConfigOption > m_config
List of configuration values.
Nektar::Utilities::ProcessInterpField::~ProcessInterpField ( )
virtual

Definition at line 73 of file ProcessInterpField.cpp.

74 {
75 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 53 of file ProcessInterpField.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::ProcessInterpField::InterpolateField ( vector< MultiRegions::ExpListSharedPtr > &  field0,
vector< MultiRegions::ExpListSharedPtr > &  field1,
Array< OneD, NekDouble x,
Array< OneD, NekDouble y,
Array< OneD, NekDouble z,
NekDouble  clamp_low,
NekDouble  clamp_up,
NekDouble  def_value 
)
private

Definition at line 256 of file ProcessInterpField.cpp.

References ASSERTL0.

Referenced by Process().

265 {
266  int expdim = field0[0]->GetCoordim(0);
267 
268  Array<OneD, NekDouble> coords(expdim), Lcoords(expdim);
269  int nq1 = field1[0]->GetTotPoints();
270  int elmtid, offset;
271  int r, f;
272  static int intpts = 0;
273 
274  ASSERTL0(field0.size() == field1.size(),
275  "Input field dimension must be same as output dimension");
276 
277  for (r = 0; r < nq1; r++)
278  {
279  coords[0] = x[r];
280  coords[1] = y[r];
281  if (expdim == 3)
282  {
283  coords[2] = z[r];
284  }
285 
286  // Obtain nearest Element and LocalCoordinate to interpolate
287  elmtid = field0[0]->GetExpIndex(coords, Lcoords, 1e-3,true);
288 
289  if(elmtid >= 0)
290  {
291  offset = field0[0]->GetPhys_Offset(field0[0]->
292  GetOffset_Elmt_Id(elmtid));
293 
294  for (f = 0; f < field1.size(); ++f)
295  {
296  NekDouble value;
297  value = field0[f]->GetExp(elmtid)->
298  StdPhysEvaluate(Lcoords, field0[f]->GetPhys() +offset);
299 
300  if ((boost::math::isnan)(value))
301  {
302  ASSERTL0(false, "new value is not a number");
303  }
304  else
305  {
306  if(value > clamp_up)
307  {
308  value = clamp_up;
309  }
310  else if( value < clamp_low)
311  {
312  value = clamp_low;
313  }
314 
315  field1[f]->UpdatePhys()[r] = value;
316  }
317  }
318  }
319  else
320  {
321  for (f = 0; f < field1.size(); ++f)
322  {
323  field1[f]->UpdatePhys()[r] = def_value;
324  }
325  }
326 
327  if (intpts%1000 == 0)
328  {
329  cout <<"." << flush;
330  }
331  intpts ++;
332  }
333 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
double NekDouble
void Nektar::Utilities::ProcessInterpField::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Implements Nektar::Utilities::Module.

Definition at line 77 of file ProcessInterpField.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::SessionReader::CreateInstance(), InterpolateField(), Nektar::Utilities::Module::m_config, Nektar::Utilities::Module::m_f, m_fromField, npts, Nektar::LibUtilities::NullFieldMetaDataMap, Nektar::NullNekDouble1DArray, Nektar::SpatialDomains::MeshGraph::Read(), Vmath::Vmax(), and Vmath::Vmin().

78 {
79 
80  if(m_f->m_verbose)
81  {
82  cout << "Processing interpolation" << endl;
83  }
84 
85  m_fromField = boost::shared_ptr<Field>(new Field());
86 
87  std::vector<std::string> files;
88 
89  // set up session file for from field
90  files.push_back(m_config["fromxml"].as<string>());
92  CreateInstance(0, 0, files);
93 
94  // Set up range based on min and max of local parallel partition
97 
98  int coordim = m_f->m_exp[0]->GetCoordim(0);
99  int npts = m_f->m_exp[0]->GetTotPoints();
100  Array<OneD, Array<OneD, NekDouble> > coords(3);
101 
102 
103  for(int i = 0; i < coordim; ++i)
104  {
105  coords[i] = Array<OneD, NekDouble>(npts);
106  }
107 
108  for(int i = coordim; i < 3; ++i)
109  {
110  coords[i] = NullNekDouble1DArray;
111  }
112 
113  m_f->m_exp[0]->GetCoords(coords[0],coords[1],coords[2]);
114 
115  rng->m_checkShape = false;
116  switch(coordim)
117  {
118  case 3:
119  rng->m_doZrange = true;
120  rng->m_zmin = Vmath::Vmin(npts,coords[2],1);
121  rng->m_zmax = Vmath::Vmax(npts,coords[2],1);
122  case 2:
123  rng->m_doYrange = true;
124  rng->m_ymin = Vmath::Vmin(npts,coords[1],1);
125  rng->m_ymax = Vmath::Vmax(npts,coords[1],1);
126  case 1:
127  rng->m_doXrange = true;
128  rng->m_xmin = Vmath::Vmin(npts,coords[0],1);
129  rng->m_xmax = Vmath::Vmax(npts,coords[0],1);
130  break;
131  default:
132  ASSERTL0(false,"too many values specfied in range");
133  }
134 
135  // setup rng parameters.
136  m_fromField->m_graph =
138 
139  // Read in local from field partitions
140  const SpatialDomains::ExpansionMap &expansions =
141  m_fromField->m_graph->GetExpansions();
142 
143  // check for case where no elements are specified on this
144  // parallel partition
145  if(!expansions.size())
146  {
147  return;
148  }
149 
150  Array<OneD,int> ElementGIDs(expansions.size());
151  SpatialDomains::ExpansionMap::const_iterator expIt;
152 
153  int i = 0;
154  for (expIt = expansions.begin(); expIt != expansions.end();
155  ++expIt)
156  {
157  ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
158  }
159 
160  string fromfld = m_config["fromfld"].as<string>();
161  m_f->m_fld->Import(fromfld,m_fromField->m_fielddef,
162  m_fromField->m_data,
164  ElementGIDs);
165 
166  int NumHomogeneousDir = m_fromField->m_fielddef[0]->m_numHomogeneousDir;
167 
168  //----------------------------------------------
169  // Set up Expansion information to use mode order from field
170  m_fromField->m_graph->SetExpansions(m_fromField->m_fielddef);
171 
172  int nfields = m_fromField->m_fielddef[0]->m_fields.size();
173 
174  m_fromField->m_exp.resize(nfields);
175  m_fromField->m_exp[0] = m_fromField->SetUpFirstExpList(NumHomogeneousDir,true);
176 
177  m_f->m_exp.resize(nfields);
178 
179  // declare auxiliary fields.
180  for(i = 1; i < nfields; ++i)
181  {
182  m_f->m_exp[i] = m_f->AppendExpList(NumHomogeneousDir);
183  m_fromField->m_exp[i] = m_fromField->AppendExpList(NumHomogeneousDir);
184  }
185 
186 
187  // load field into expansion in fromfield.
188  for(int j = 0; j < nfields; ++j)
189  {
190  for (i = 0; i < m_fromField->m_fielddef.size(); i++)
191  {
192  m_fromField->m_exp[j]->ExtractDataToCoeffs(
193  m_fromField->m_fielddef[i],
194  m_fromField->m_data[i],
195  m_fromField->m_fielddef[0]->m_fields[j],
196  m_fromField->m_exp[j]->UpdateCoeffs());
197  }
198  m_fromField->m_exp[j]->BwdTrans(m_fromField->m_exp[j]->GetCoeffs(),
199  m_fromField->m_exp[j]->UpdatePhys());
200 
201  }
202 
203  int nq1 = m_f->m_exp[0]->GetTotPoints();
204 
205  Array<OneD, NekDouble> x1(nq1);
206  Array<OneD, NekDouble> y1(nq1);
207  Array<OneD, NekDouble> z1(nq1);
208 
209  if (coordim == 2)
210  {
211  m_f->m_exp[0]->GetCoords(x1, y1);
212  }
213  else if (coordim == 3)
214  {
215  m_f->m_exp[0]->GetCoords(x1, y1, z1);
216  }
217 
218  if(m_f->m_session->GetComm()->TreatAsRankZero())
219  {
220  cout << "Interpolating [" << flush;
221  }
222 
223  NekDouble clamp_low = m_config["clamptolowervalue"].as<NekDouble>();
224  NekDouble clamp_up = m_config["clamptouppervalue"].as<NekDouble>();
225  NekDouble def_value = m_config["defaultvalue"].as<NekDouble>();
226 
227  InterpolateField(m_fromField->m_exp, m_f->m_exp,
228  x1, y1, z1, clamp_low, clamp_up,def_value);
229 
230  if(m_f->m_session->GetComm()->TreatAsRankZero())
231  {
232  cout << "]" << endl;
233  }
234 
235 
236  // put field into field data for output
237  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
238  = m_f->m_exp[0]->GetFieldDefinitions();
239  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
240 
241  for (int j = 0; j < nfields; ++j)
242  {
243  m_f->m_exp[j]->FwdTrans(m_f->m_exp[j]->GetPhys(),
244  m_f->m_exp[j]->UpdateCoeffs());
245  for (i = 0; i < FieldDef.size(); ++i)
246  {
247  FieldDef[i]->m_fields.push_back(m_fromField->m_fielddef[0]->m_fields[j]);
248  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
249  }
250  }
251 
252  m_f->m_fielddef = FieldDef;
253  m_f->m_data = FieldData;
254 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
static Array< OneD, NekDouble > NullNekDouble1DArray
static boost::shared_ptr< MeshGraph > Read(const LibUtilities::SessionReaderSharedPtr &pSession, DomainRangeShPtr &rng=NullDomainRangeShPtr)
Definition: MeshGraph.cpp:121
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:765
void InterpolateField(vector< MultiRegions::ExpListSharedPtr > &field0, vector< MultiRegions::ExpListSharedPtr > &field1, Array< OneD, NekDouble > x, Array< OneD, NekDouble > y, Array< OneD, NekDouble > z, NekDouble clamp_low, NekDouble clamp_up, NekDouble def_value)
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:857
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:157
double NekDouble
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:54
std::map< int, ExpansionShPtr > ExpansionMap
Definition: MeshGraph.h:174

Member Data Documentation

ModuleKey Nektar::Utilities::ProcessInterpField::className
static
Initial value:
=
ModuleKey(eProcessModule, "interpfield"),
"Interpolates one field to another, requires fromxml, "
"fromfld to be defined")

Definition at line 56 of file ProcessInterpField.h.

FieldSharedPtr Nektar::Utilities::ProcessInterpField::m_fromField
private

Definition at line 65 of file ProcessInterpField.h.

Referenced by Process().