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

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

#include <ProcessPointDataToFld.h>

Inheritance diagram for Nektar::FieldUtils::ProcessPointDataToFld:
Inheritance graph
[legend]
Collaboration diagram for Nektar::FieldUtils::ProcessPointDataToFld:
Collaboration graph
[legend]

Public Member Functions

 ProcessPointDataToFld (FieldSharedPtr f)
 
virtual ~ProcessPointDataToFld ()
 
virtual void Process (po::variables_map &vm)
 Write mesh to output file. More...
 
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
 

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 51 of file ProcessPointDataToFld.h.

Constructor & Destructor Documentation

Nektar::FieldUtils::ProcessPointDataToFld::ProcessPointDataToFld ( FieldSharedPtr  f)

Definition at line 59 of file ProcessPointDataToFld.cpp.

References Nektar::FieldUtils::Module::m_config, and Nektar::FieldUtils::Module::m_requireEquiSpaced.

60  : ProcessModule(f)
61 {
62  m_requireEquiSpaced = true;
63 
64  m_config["setnantovalue"] = ConfigOption(
65  false, "NotSet", "reset any nan value to prescribed value");
66 
67  if ((f->m_inputfiles.count("pts") == 0))
68  {
69  cout << endl
70  << "A pts input file must be specified for the boundary "
71  "extraction module"
72  << endl;
73 
74  cout
75  << "Usage: Fieldconvert -m pointdatatofld file.pts file.xml out.fld"
76  << endl;
77  exit(3);
78  }
79 
80  if ((f->m_inputfiles.count("xml") == 0) &&
81  (f->m_inputfiles.count("xml.gz") == 0))
82  {
83  cout << endl
84  << "An xml or xml.gz input file must be specified for the "
85  "boundary extraction module"
86  << endl;
87  cout
88  << "Usage: Fieldconvert -m pointdatatofld file.pts file.xml out.fld"
89  << endl;
90  exit(3);
91  }
92 }
map< string, ConfigOption > m_config
List of configuration values.
Nektar::FieldUtils::ProcessPointDataToFld::~ProcessPointDataToFld ( )
virtual

Definition at line 94 of file ProcessPointDataToFld.cpp.

95 {
96 }

Member Function Documentation

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

Creates an instance of this class.

Definition at line 55 of file ProcessPointDataToFld.h.

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

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

Implements Nektar::FieldUtils::Module.

Definition at line 67 of file ProcessPointDataToFld.h.

68  {
69  return "ProcessPointDataToFld";
70  }
void Nektar::FieldUtils::ProcessPointDataToFld::Process ( po::variables_map &  vm)
virtual

Write mesh to output file.

Implements Nektar::FieldUtils::Module.

Definition at line 98 of file ProcessPointDataToFld.cpp.

References ASSERTL0, Nektar::LibUtilities::eIsEquiSpacedData, Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, Nektar::LibUtilities::NullPtsField, Vmath::Vcopy(), and WARNINGL0.

99 {
100  if (m_f->m_verbose)
101  {
102  if (m_f->m_comm->TreatAsRankZero())
103  {
104  cout << "ProcessPointDataToFld: projecting data to expansion..."
105  << endl;
106  }
107  }
108 
109  int i, j;
110  bool setnantovalue = false;
111  NekDouble defvalue=0.0;
112 
113  if (!boost::iequals(m_config["setnantovalue"].as<string>(), "NotSet"))
114  {
115  setnantovalue = true;
116  defvalue = m_config["setnantovalue"].as<NekDouble>();
117  }
118 
119  // Check for command line point specification if no .pts file specified
120  ASSERTL0(m_f->m_fieldPts != LibUtilities::NullPtsField,
121  "No input points found");
122 
123  int nFields = m_f->m_fieldPts->GetNFields();
124  ASSERTL0(nFields > 0, "No field values provided in input");
125 
126  int dim = m_f->m_fieldPts->GetDim();
127 
128  // assume one field is already defined from input file.
129  m_f->m_exp.resize(nFields);
130  for (i = 1; i < nFields; ++i)
131  {
132  m_f->m_exp[i] = m_f->AppendExpList(0);
133  }
134 
135  Array<OneD, Array<OneD, NekDouble> > pts;
136  m_f->m_fieldPts->GetPts(pts);
137 
138  // set any nan values to default value if requested
139  if (setnantovalue)
140  {
141  for (int i = 0; i < pts[0].num_elements(); ++i)
142  {
143  for (int j = 0; j < nFields; ++j)
144  {
145  if ((boost::math::isnan)(pts[j + dim][i]))
146  {
147  pts[j + dim][i] = defvalue;
148  }
149  }
150  }
151  }
152 
153  if (m_f->m_fieldPts->m_ptsInfo.count(LibUtilities::eIsEquiSpacedData) != 0)
154  {
155  int totcoeffs = m_f->m_exp[0]->GetNcoeffs();
156 
157  ASSERTL0(pts[0].num_elements() != totcoeffs,
158  "length of points in .pts file is different "
159  "to the number of coefficients in expansion ");
160 
161  for (int i = 0; i < nFields; ++i)
162  {
163  Array<OneD, NekDouble> coeffs = m_f->m_exp[i]->UpdateCoeffs(), tmp;
164  int cnt = 0;
165  for (int e = 0; e < m_f->m_exp[0]->GetNumElmts(); ++e)
166  {
167  int ncoeffs = m_f->m_exp[i]->GetExp(e)->GetNcoeffs();
168  int offset = m_f->m_exp[i]->GetCoeff_Offset(e);
169  Vmath::Vcopy(ncoeffs, &pts[i + dim][cnt], 1, &coeffs[offset],
170  1);
171 
172  m_f->m_exp[i]->GetExp(e)->EquiSpacedToCoeffs(
173  coeffs + offset, tmp = coeffs + offset);
174  cnt += ncoeffs;
175  }
176  }
177  }
178  else
179  {
180  int totpoints = m_f->m_exp[0]->GetTotPoints();
181  Array<OneD, Array<OneD, NekDouble> > coords(3);
182 
183  coords[0] = Array<OneD, NekDouble>(totpoints);
184  coords[1] = Array<OneD, NekDouble>(totpoints);
185  coords[2] = Array<OneD, NekDouble>(totpoints);
186 
187  m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
188 
189  if (pts[0].num_elements() != totpoints)
190  {
191  WARNINGL0(false, "length of points in .pts file is different to "
192  "the number of quadrature points in xml file");
193  totpoints = min(totpoints, (int)pts[0].num_elements());
194  }
195 
196  int mismatch = 0;
197  for (i = 0; i < totpoints; ++i)
198  {
199  for (j = 0; j < dim; ++j)
200  {
201  if (fabs(coords[j][i] - pts[j][i]) > 1e-4)
202  {
203  string outstring =
204  "Coordinates do not match within 1e-4: " +
205  boost::lexical_cast<string>(coords[j][i]) + " versus " +
206  boost::lexical_cast<string>(pts[j][i]) + " diff " +
207  boost::lexical_cast<string>(
208  fabs(coords[j][i] - pts[j][i]));
209  ;
210  WARNINGL0(false, outstring);
211  mismatch += 1;
212  }
213  }
214 
215  for (j = 0; j < nFields; ++j)
216  {
217  m_f->m_exp[j]->SetPhys(i, pts[j + dim][i]);
218  }
219  }
220 
221  if (m_f->m_session->GetComm()->GetRank() == 0)
222  {
223  cout << endl;
224  }
225 
226  // forward transform fields
227  for (i = 0; i < nFields; ++i)
228  {
229  m_f->m_exp[i]->FwdTrans_IterPerExp(m_f->m_exp[i]->GetPhys(),
230  m_f->m_exp[i]->UpdateCoeffs());
231  }
232  }
233 
234  // set up output fld file.
235  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
236  m_f->m_exp[0]->GetFieldDefinitions();
237  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
238 
239  for (j = 0; j < nFields; ++j)
240  {
241  for (i = 0; i < FieldDef.size(); ++i)
242  {
243  FieldDef[i]->m_fields.push_back(m_f->m_fieldPts->GetFieldName(j));
244 
245  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
246  }
247  }
248 
249  m_f->m_fielddef = FieldDef;
250  m_f->m_data = FieldData;
251 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
#define WARNINGL0(condition, msg)
Definition: ErrorUtil.hpp:204
double NekDouble
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:179
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
FieldSharedPtr m_f
Field object.

Member Data Documentation

ModuleKey Nektar::FieldUtils::ProcessPointDataToFld::className
static
Initial value:
=
ModuleKey(eProcessModule, "pointdatatofld"),
"Given discrete data at quadrature points project them onto an "
"expansion"
"basis and output fld file. Requires .pts .xml and .fld files.")

Definition at line 59 of file ProcessPointDataToFld.h.