Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Load a file of interpolated vales at physical
33 // quadrature points and project to a fld file
34 //
35 ////////////////////////////////////////////////////////////////////////////////
36 #include <string>
37 #include <iostream>
38 
39 using namespace std;
40 
41 #include "ProcessPointDataToFld.h"
42 
45 #include <boost/math/special_functions/fpclassify.hpp>
46 namespace Nektar
47 {
48 namespace Utilities
49 {
50 
51 ModuleKey ProcessPointDataToFld::className =
53  ModuleKey(eProcessModule, "pointdatatofld"),
54  ProcessPointDataToFld::create,
55  "Given discrete data at quadrature points project them onto an expansion"
56  "basis and output fld file. Requires .pts .xml and .fld files.");
57 
58 
59 ProcessPointDataToFld::ProcessPointDataToFld(FieldSharedPtr f)
60  : ProcessModule(f)
61 {
62  m_requireEquiSpaced = true;
63 
64  m_config["setnantovalue"] = ConfigOption(false,"NotSet",
65  "reset any nan value to prescribed value");
66 
67  if((f->m_inputfiles.count("pts") == 0))
68  {
69  cout << endl << "A pts input file must be specified for the boundary extraction module" << endl;
70 
71  cout << "Usage: Fieldconvert -m pointdatatofld file.pts file.xml out.fld" << endl;
72  exit(3);
73  }
74 
75  if((f->m_inputfiles.count("xml") == 0)&&(f->m_inputfiles.count("xml.gz") == 0))
76  {
77  cout << endl << "An xml or xml.gz input file must be specified for the boundary extraction module" << endl;
78  cout << "Usage: Fieldconvert -m pointdatatofld file.pts file.xml out.fld" << endl;
79  exit(3);
80  }
81 
82 }
83 
85 {
86 }
87 
88 void ProcessPointDataToFld::Process(po::variables_map &vm)
89 {
90  int i,j;
91  bool setnantovalue = false;
92  NekDouble defvalue;
93 
94  if(!boost::iequals(m_config["setnantovalue"].as<string>(),"NotSet"))
95  {
96  setnantovalue = true;
97  defvalue = m_config["setnantovalue"].as<NekDouble>();
98  }
99 
100  // Check for command line point specification if no .pts file specified
101  ASSERTL0(m_f->m_fieldPts != LibUtilities::NullPtsField,
102  "No input points found");
103 
104  int nFields = m_f->m_fieldPts->GetNFields();
105  ASSERTL0(nFields > 0,
106  "No field values provided in input");
107 
108  int dim = m_f->m_fieldPts->GetDim();
109 
110  // assume one field is already defined from input file.
111  m_f->m_exp.resize(nFields);
112  for(i = 1; i < nFields; ++i)
113  {
114  m_f->m_exp[i] = m_f->AppendExpList(0);
115  }
116 
118  m_f->m_fieldPts->GetPts(pts);
119 
120  // set any nan values to default value if requested
121  if(setnantovalue)
122  {
123  for(int i = 0; i < pts[0].num_elements(); ++i)
124  {
125  for(int j = 0; j < nFields; ++j)
126  {
127  if ((boost::math::isnan)(pts[j+dim][i]))
128  {
129  pts[j+dim][i] = defvalue;
130  }
131  }
132  }
133  }
134 
135  if(m_f->m_fieldPts->m_ptsInfo.count(LibUtilities::eIsEquiSpacedData) != 0)
136  {
137  int totcoeffs = m_f->m_exp[0]->GetNcoeffs();
138 
139  ASSERTL0(pts[0].num_elements() != totcoeffs,"length of points in .pts file is different "
140  "to the number of coefficients in expansion ");
141 
142  for(int i = 0; i < nFields; ++i)
143  {
144  Array<OneD, NekDouble> coeffs = m_f->m_exp[i]->UpdateCoeffs(), tmp;
145  int cnt = 0;
146  for(int e = 0; e < m_f->m_exp[0]->GetNumElmts(); ++e)
147  {
148  int ncoeffs = m_f->m_exp[i]->GetExp(e)->GetNcoeffs();
149  int offset = m_f->m_exp[i]->GetCoeff_Offset(e);
150  Vmath::Vcopy(ncoeffs,&pts[i+dim][cnt],1,&coeffs[offset],1);
151 
152  m_f->m_exp[i]->GetExp(e)->EquiSpacedToCoeffs(coeffs+offset,tmp = coeffs+offset);
153  cnt += ncoeffs;
154  }
155  }
156  }
157  else
158  {
159  int totpoints = m_f->m_exp[0]->GetTotPoints();
161 
162  coords[0] = Array<OneD,NekDouble>(totpoints);
163  coords[1] = Array<OneD,NekDouble>(totpoints);
164  coords[2] = Array<OneD,NekDouble>(totpoints);
165 
166  m_f->m_exp[0]->GetCoords(coords[0],coords[1],coords[2]);
167 
168 
169  if(pts[0].num_elements() != totpoints)
170  {
171  WARNINGL0(false,"length of points in .pts file is different to the number of quadrature points in xml file");
172  totpoints = min(totpoints,(int)pts[0].num_elements());
173  }
174 
175  int mismatch = 0;
176  for(i = 0; i < totpoints; ++i)
177  {
178  for(j = 0; j < dim; ++j)
179  {
180  if(fabs(coords[j][i]-pts[j][i]) > 1e-4)
181  {
182  string outstring = "Coordinates do not match within 1e-4: "
183  + boost::lexical_cast<string>(coords[j][i])
184  + " versus "
185  + boost::lexical_cast<string>(pts[j][i])
186  + " diff " + boost::lexical_cast<string>(fabs(coords[j][i]-pts[j][i]));;
187  WARNINGL0(false,outstring);
188  mismatch +=1;
189  }
190  }
191 
192  for(j = 0;j < nFields; ++j)
193  {
194  m_f->m_exp[j]->SetPhys(i, pts[j+dim][i]);
195  }
196  }
197 
198  if(m_f->m_session->GetComm()->GetRank() == 0)
199  {
200  cout << endl;
201  }
202 
203  // forward transform fields
204  for(i = 0; i < nFields; ++i)
205  {
206  m_f->m_exp[i]->FwdTrans_IterPerExp(m_f->m_exp[i]->GetPhys(),
207  m_f->m_exp[i]->UpdateCoeffs());
208  }
209  }
210 
211  // set up output fld file.
212  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
213  = m_f->m_exp[0]->GetFieldDefinitions();
214  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
215 
216  for (j = 0; j < nFields; ++j)
217  {
218  for (i = 0; i < FieldDef.size(); ++i)
219  {
220  FieldDef[i]->m_fields.push_back(m_f->m_fieldPts->GetFieldName(j));
221 
222  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
223  }
224  }
225 
226  m_f->m_fielddef = FieldDef;
227  m_f->m_data = FieldData;
228 
229 }
230 
231 }
232 }
233 
234 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
pair< ModuleType, string > ModuleKey
virtual void Process()=0
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
FieldSharedPtr m_f
Field object.
#define WARNINGL0(condition, msg)
Definition: ErrorUtil.hpp:167
double NekDouble
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:695
Represents a command-line configuration option.
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:264
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1047
ModuleFactory & GetModuleFactory()
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215