Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | 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:
Inheritance graph
[legend]
Collaboration diagram for Nektar::FieldUtils::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...
 
void PrintProgressbar (const int position, const int goal) const
 
virtual std::string GetModuleName ()
 
- 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)
 
FIELD_UTILS_EXPORT void RegisterConfig (string key, 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 bool GetRequireEquiSpaced (void)
 
FIELD_UTILS_EXPORT void SetRequireEquiSpaced (bool pVal)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

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 Attributes

FieldSharedPtr m_fromField
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 

Detailed Description

This processing module interpolates one field to another.

Definition at line 49 of file ProcessInterpField.h.

Constructor & Destructor Documentation

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

Definition at line 58 of file ProcessInterpField.cpp.

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

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

Definition at line 74 of file ProcessInterpField.cpp.

75 {
76 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 53 of file ProcessInterpField.h.

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

54  {
56  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
virtual std::string Nektar::FieldUtils::ProcessInterpField::GetModuleName ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 67 of file ProcessInterpField.h.

68  {
69  return "ProcessInterpField";
70  }
void Nektar::FieldUtils::ProcessInterpField::PrintProgressbar ( const int  position,
const int  goal 
) const

Definition at line 275 of file ProcessInterpField.cpp.

References Nektar::LibUtilities::PrintProgressbar().

Referenced by Process().

277 {
278  LibUtilities::PrintProgressbar(position, goal, "Interpolating");
279 }
int PrintProgressbar(const int position, const int goal, const string message, int lastprogress=-1)
Prints a progressbar.
Definition: Progressbar.hpp:69
void Nektar::FieldUtils::ProcessInterpField::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Implements Nektar::FieldUtils::Module.

Definition at line 78 of file ProcessInterpField.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::SessionReader::CreateInstance(), Nektar::ParseUtils::GenerateOrderedStringVector(), Nektar::FieldUtils::Interpolator::Interpolate(), Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, m_fromField, npts, Nektar::LibUtilities::NullFieldMetaDataMap, Nektar::NullNekDouble1DArray, PrintProgressbar(), Nektar::SpatialDomains::MeshGraph::Read(), Nektar::FieldUtils::Interpolator::SetProgressCallback(), Vmath::Vmax(), and Vmath::Vmin().

79 {
80  if (m_f->m_verbose)
81  {
82  if (m_f->m_comm->TreatAsRankZero())
83  {
84  cout << "ProcessInterpField: Interpolating field..." << endl;
85  }
86  }
87 
88  m_fromField = boost::shared_ptr<Field>(new Field());
89 
90  std::vector<std::string> files;
91 
92  // set up session file for from field
93  ParseUtils::GenerateOrderedStringVector(m_config["fromxml"].as<string>().c_str(), files);
94  m_fromField->m_session =
96 
97  // Set up range based on min and max of local parallel partition
100 
101  int coordim = m_f->m_exp[0]->GetCoordim(0);
102  int npts = m_f->m_exp[0]->GetTotPoints();
103  Array<OneD, Array<OneD, NekDouble> > coords(3);
104 
105  for (int i = 0; i < coordim; ++i)
106  {
107  coords[i] = Array<OneD, NekDouble>(npts);
108  }
109 
110  for (int i = coordim; i < 3; ++i)
111  {
112  coords[i] = NullNekDouble1DArray;
113  }
114 
115  m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
116 
117  rng->m_checkShape = false;
118  switch (coordim)
119  {
120  case 3:
121  rng->m_doZrange = true;
122  rng->m_zmin = Vmath::Vmin(npts, coords[2], 1);
123  rng->m_zmax = Vmath::Vmax(npts, coords[2], 1);
124  case 2:
125  rng->m_doYrange = true;
126  rng->m_ymin = Vmath::Vmin(npts, coords[1], 1);
127  rng->m_ymax = Vmath::Vmax(npts, coords[1], 1);
128  case 1:
129  rng->m_doXrange = true;
130  rng->m_xmin = Vmath::Vmin(npts, coords[0], 1);
131  rng->m_xmax = Vmath::Vmax(npts, coords[0], 1);
132  break;
133  default:
134  ASSERTL0(false, "too many values specfied in range");
135  }
136 
137  // setup rng parameters.
138  m_fromField->m_graph =
140 
141  // Read in local from field partitions
142  const SpatialDomains::ExpansionMap &expansions =
143  m_fromField->m_graph->GetExpansions();
144 
145  // check for case where no elements are specified on this
146  // parallel partition
147  if (!expansions.size())
148  {
149  return;
150  }
151 
152  Array<OneD, int> ElementGIDs(expansions.size());
153  SpatialDomains::ExpansionMap::const_iterator expIt;
154 
155  int i = 0;
156  for (expIt = expansions.begin(); expIt != expansions.end(); ++expIt)
157  {
158  ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
159  }
160 
161  string fromfld = m_config["fromfld"].as<string>();
162  m_f->FieldIOForFile(fromfld)->Import(
163  fromfld, m_fromField->m_fielddef, m_fromField->m_data,
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] =
176  m_fromField->SetUpFirstExpList(NumHomogeneousDir, true);
177 
178  m_f->m_exp.resize(nfields);
179 
180  // declare auxiliary fields.
181  for (i = 1; i < nfields; ++i)
182  {
183  m_f->m_exp[i] = m_f->AppendExpList(NumHomogeneousDir);
184  m_fromField->m_exp[i] = m_fromField->AppendExpList(NumHomogeneousDir);
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], m_fromField->m_data[i],
194  m_fromField->m_fielddef[0]->m_fields[j],
195  m_fromField->m_exp[j]->UpdateCoeffs());
196  }
197  m_fromField->m_exp[j]->BwdTrans(m_fromField->m_exp[j]->GetCoeffs(),
198  m_fromField->m_exp[j]->UpdatePhys());
199  }
200 
201  int nq1 = m_f->m_exp[0]->GetTotPoints();
202 
203  Array<OneD, NekDouble> x1(nq1);
204  Array<OneD, NekDouble> y1(nq1);
205  Array<OneD, NekDouble> z1(nq1);
206 
207  if (coordim == 2)
208  {
209  m_f->m_exp[0]->GetCoords(x1, y1);
210  }
211  else if (coordim == 3)
212  {
213  m_f->m_exp[0]->GetCoords(x1, y1, z1);
214  }
215 
216  NekDouble clamp_low = m_config["clamptolowervalue"].as<NekDouble>();
217  NekDouble clamp_up = m_config["clamptouppervalue"].as<NekDouble>();
218  NekDouble def_value = m_config["defaultvalue"].as<NekDouble>();
219 
220  for (int i = 0; i < nfields; i++)
221  {
222  for (int j = 0; j < nq1; ++j)
223  {
224  m_f->m_exp[i]->UpdatePhys()[j] = def_value;
225  }
226  }
227 
228  Interpolator interp;
229  if (m_f->m_comm->GetRank() == 0)
230  {
231  interp.SetProgressCallback(&ProcessInterpField::PrintProgressbar, this);
232  }
233  interp.Interpolate(m_fromField->m_exp, m_f->m_exp);
234  if (m_f->m_comm->GetRank() == 0)
235  {
236  cout << endl;
237  }
238 
239  for (int i = 0; i < nfields; ++i)
240  {
241  for (int j = 0; j < nq1; ++j)
242  {
243  if (m_f->m_exp[i]->GetPhys()[j] > clamp_up)
244  {
245  m_f->m_exp[i]->UpdatePhys()[j] = clamp_up;
246  }
247  else if (m_f->m_exp[i]->GetPhys()[j] < clamp_low)
248  {
249  m_f->m_exp[i]->UpdatePhys()[j] = clamp_low;
250  }
251  }
252  }
253 
254  // put field into field data for output
255  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
256  m_f->m_exp[0]->GetFieldDefinitions();
257  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
258 
259  for (int j = 0; j < nfields; ++j)
260  {
261  m_f->m_exp[j]->FwdTrans(m_f->m_exp[j]->GetPhys(),
262  m_f->m_exp[j]->UpdateCoeffs());
263  for (i = 0; i < FieldDef.size(); ++i)
264  {
265  FieldDef[i]->m_fields.push_back(
266  m_fromField->m_fielddef[0]->m_fields[j]);
267  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
268  }
269  }
270 
271  m_f->m_fielddef = FieldDef;
272  m_f->m_data = FieldData;
273 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
static bool GenerateOrderedStringVector(const char *const str, std::vector< std::string > &vec)
Definition: ParseUtils.hpp:143
static Array< OneD, NekDouble > NullNekDouble1DArray
static boost::shared_ptr< MeshGraph > Read(const LibUtilities::SessionReaderSharedPtr &pSession, DomainRangeShPtr &rng=NullDomainRangeShPtr)
Definition: MeshGraph.cpp:124
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:779
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:871
void PrintProgressbar(const int position, const int goal) const
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:55
std::map< int, ExpansionShPtr > ExpansionMap
Definition: MeshGraph.h:174
FieldSharedPtr m_f
Field object.

Member Data Documentation

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

Definition at line 57 of file ProcessInterpField.h.

FieldSharedPtr Nektar::FieldUtils::ProcessInterpField::m_fromField
private

Definition at line 73 of file ProcessInterpField.h.

Referenced by Process().