Nektar++
ProcessPointDataToFld.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessPointDataToFld.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Load a file of interpolated vales at physical
32 // quadrature points and project to a fld file
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 #include <iostream>
36 #include <string>
37 using namespace std;
38 
39 #include <boost/core/ignore_unused.hpp>
40 #include <boost/math/special_functions/fpclassify.hpp>
41 
43 
44 #include "ProcessPointDataToFld.h"
45 
46 namespace Nektar
47 {
48 namespace FieldUtils
49 {
50 
51 ModuleKey ProcessPointDataToFld::className =
53  ModuleKey(eProcessModule, "pointdatatofld"),
54  ProcessPointDataToFld::create,
55  "Given discrete data at quadrature points project them onto an "
56  "expansion"
57  "basis and output fld file. Requires frompts and .xml and .fld files.");
58 
59 ProcessPointDataToFld::ProcessPointDataToFld(FieldSharedPtr f)
60  : ProcessModule(f)
61 {
62  m_config["setnantovalue"] = ConfigOption(
63  false, "NotSet", "reset any nan value to prescribed value");
64 
65  m_config["frompts"] = ConfigOption(
66  false, "NotSet", "Pts file from which to interpolate field");
67 }
68 
70 {
71 }
72 
73 void ProcessPointDataToFld::v_Process(po::variables_map &vm)
74 {
75  m_f->SetUpExp(vm);
76 
77  int i, j;
78  bool setnantovalue = false;
79  NekDouble defvalue = 0.0;
80 
81  if (!boost::iequals(m_config["setnantovalue"].as<string>(), "NotSet"))
82  {
83  setnantovalue = true;
84  defvalue = m_config["setnantovalue"].as<NekDouble>();
85  }
86 
87  // Check for command line point specification if no .pts file specified
88  // Load pts file
90  ASSERTL0(m_config["frompts"].as<string>().compare("NotSet") != 0,
91  "ProcessInterpPointDataToFld requires frompts parameter");
92  string inFile = m_config["frompts"].as<string>().c_str();
97  ptsIO->Import(inFile, fieldPts);
98 
99  int nFields = fieldPts->GetNFields();
100  ASSERTL0(nFields > 0, "No field values provided in input");
101 
102  int dim = fieldPts->GetDim();
103 
104  // assume one field is already defined from input file.
105  ASSERTL0(
106  m_f->m_numHomogeneousDir == 0,
107  "ProcessInterpPointDataToFld does not support homogeneous expansion");
108 
109  m_f->m_exp.resize(nFields);
110  for (i = 1; i < nFields; ++i)
111  {
112  m_f->m_exp[i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
113  }
114 
116  fieldPts->GetPts(pts);
117 
118  // set any nan values to default value if requested
119  if (setnantovalue)
120  {
121  for (int i = 0; i < pts[0].size(); ++i)
122  {
123  for (int j = 0; j < nFields; ++j)
124  {
125  if ((boost::math::isnan)(pts[j + dim][i]))
126  {
127  pts[j + dim][i] = defvalue;
128  }
129  }
130  }
131  }
132 
133  if (fieldPts->m_ptsInfo.count(LibUtilities::eIsEquiSpacedData) != 0)
134  {
135  int totcoeffs = m_f->m_exp[0]->GetNcoeffs();
136 
137  ASSERTL0(pts[0].size() != totcoeffs,
138  "length of points in .pts file is different "
139  "to the number of coefficients in expansion ");
140 
141  for (int i = 0; i < nFields; ++i)
142  {
143  Array<OneD, NekDouble> coeffs = m_f->m_exp[i]->UpdateCoeffs(), tmp;
144  int cnt = 0;
145  for (int e = 0; e < m_f->m_exp[0]->GetNumElmts(); ++e)
146  {
147  int ncoeffs = m_f->m_exp[i]->GetExp(e)->GetNcoeffs();
148  int offset = m_f->m_exp[i]->GetCoeff_Offset(e);
149  Vmath::Vcopy(ncoeffs, &pts[i + dim][cnt], 1, &coeffs[offset],
150  1);
151 
152  m_f->m_exp[i]->GetExp(e)->EquiSpacedToCoeffs(
153  coeffs + offset, tmp = coeffs + offset);
154  cnt += ncoeffs;
155  }
156  m_f->m_exp[i]->BwdTrans(m_f->m_exp[i]->GetCoeffs(),
157  m_f->m_exp[i]->UpdatePhys());
158  }
159  }
160  else
161  {
162  int totpoints = m_f->m_exp[0]->GetTotPoints();
164 
165  coords[0] = Array<OneD, NekDouble>(totpoints);
166  coords[1] = Array<OneD, NekDouble>(totpoints);
167  coords[2] = Array<OneD, NekDouble>(totpoints);
168 
169  m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
170 
171  if (pts[0].size() != totpoints)
172  {
173  WARNINGL0(false, "length of points in .pts file is different to "
174  "the number of quadrature points in xml file");
175  totpoints = min(totpoints, (int)pts[0].size());
176  }
177 
178  for (j = 0; j < dim; ++j)
179  {
180  for (i = 0; i < totpoints; ++i)
181  {
182  if (fabs(coords[j][i] - pts[j][i]) > 1e-4)
183  {
184  string outstring =
185  "Coordinates do not match within 1e-4: " +
186  boost::lexical_cast<string>(coords[j][i]) + " versus " +
187  boost::lexical_cast<string>(pts[j][i]) + " diff " +
188  boost::lexical_cast<string>(
189  fabs(coords[j][i] - pts[j][i]));
190  ;
191  WARNINGL0(false, outstring);
192  }
193  }
194  }
195 
196  for (j = 0; j < nFields; ++j)
197  {
198  Array<OneD, NekDouble> phys = m_f->m_exp[j]->UpdatePhys();
199 
200  for (i = 0; i < totpoints; ++i)
201  {
202  phys[i] = pts[j + dim][i];
203  }
204 
205  // forward transform fields
206  m_f->m_exp[j]->FwdTransLocalElmt(phys,
207  m_f->m_exp[j]->UpdateCoeffs());
208  }
209  }
210 
211  // save field names
212  for (int j = 0; j < fieldPts->GetNFields(); ++j)
213  {
214  m_f->m_variables.push_back(fieldPts->GetFieldName(j));
215  }
216 }
217 } // namespace FieldUtils
218 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define WARNINGL0(condition, msg)
Definition: ErrorUtil.hpp:222
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:263
Abstract base class for processing modules.
Definition: Module.h:292
virtual void v_Process(po::variables_map &vm) override
Write mesh to output file.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:991
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
std::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:190
std::shared_ptr< PtsIO > PtsIOSharedPtr
Definition: PtsIO.h:96
CommFactory & GetCommFactory()
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255
Represents a command-line configuration option.
Definition: Module.h:131