Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProcessInterpPointDataToFld.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessInterpPointDataToFld.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: Interpolate, using finite different approximation,
33 // given data to a fld file
34 //
35 ////////////////////////////////////////////////////////////////////////////////
36 #include <iostream>
37 #include <string>
38 
39 using namespace std;
40 
41 #include <boost/geometry.hpp>
43 
48 #include <boost/math/special_functions/fpclassify.hpp>
49 
50 namespace bg = boost::geometry;
51 namespace bgi = boost::geometry::index;
52 
53 namespace Nektar
54 {
55 namespace FieldUtils
56 {
57 
58 ModuleKey ProcessInterpPointDataToFld::className =
60  ModuleKey(eProcessModule, "interppointdatatofld"),
61  ProcessInterpPointDataToFld::create,
62  "Interpolates given discrete data using a finite difference "
63  "approximation to a fld file given a xml file");
64 
65 ProcessInterpPointDataToFld::ProcessInterpPointDataToFld(FieldSharedPtr f)
66  : ProcessModule(f)
67 {
68 
69  m_config["interpcoord"] =
70  ConfigOption(false, "-1", "coordinate id to use for interpolation");
71 }
72 
74 {
75 }
76 
77 void ProcessInterpPointDataToFld::Process(po::variables_map &vm)
78 {
79  if (m_f->m_verbose)
80  {
81  if (m_f->m_comm->TreatAsRankZero())
82  {
83  cout
84  << "ProcessInterpPointDataToFld: interpolating data to field..."
85  << endl;
86  }
87  }
88 
89  int i, j;
90 
91  // Check for command line point specification if no .pts file specified
93  "No input points found");
94 
95  int nFields = m_f->m_fieldPts->GetNFields();
96  ASSERTL0(nFields > 0, "No field values provided in input");
97 
98  // assume one field is already defined from input file.
99  m_f->m_exp.resize(nFields);
100  for (i = 1; i < nFields; ++i)
101  {
102  m_f->m_exp[i] = m_f->AppendExpList(0);
103  }
104 
105  int totpoints = m_f->m_exp[0]->GetTotPoints();
106  Array<OneD, Array<OneD, NekDouble> > intFields(3 + nFields);
107  for (int i = 0; i < 3 + nFields; ++i)
108  {
109  intFields[i] = Array<OneD, NekDouble>(totpoints);
110  }
111  m_f->m_exp[0]->GetCoords(intFields[0], intFields[1], intFields[2]);
114 
115  int coord_id = m_config["interpcoord"].as<int>();
116  ASSERTL0(coord_id <= m_f->m_fieldPts->GetDim() - 1,
117  "interpcoord is bigger than the Pts files dimension");
118 
119  Interpolator interp(eNoMethod, coord_id);
120 
121  if (m_f->m_comm->GetRank() == 0)
122  {
123  interp.SetProgressCallback(
125  }
126  interp.Interpolate(m_f->m_fieldPts, outPts);
127  if (m_f->m_comm->GetRank() == 0)
128  {
129  cout << endl;
130  }
131 
132  for (i = 0; i < totpoints; ++i)
133  {
134  for (j = 0; j < nFields; ++j)
135  {
136  m_f->m_exp[j]->SetPhys(i, outPts->GetPointVal(3 + j, i));
137  }
138  }
139 
140  // forward transform fields
141  for (i = 0; i < nFields; ++i)
142  {
143  m_f->m_exp[i]->FwdTrans_IterPerExp(m_f->m_exp[i]->GetPhys(),
144  m_f->m_exp[i]->UpdateCoeffs());
145  }
146 
147  // set up output fld file.
148  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
149  m_f->m_exp[0]->GetFieldDefinitions();
150  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
151 
152  for (j = 0; j < nFields; ++j)
153  {
154  for (i = 0; i < FieldDef.size(); ++i)
155  {
156  FieldDef[i]->m_fields.push_back(m_f->m_fieldPts->GetFieldName(j));
157 
158  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
159  }
160  }
161 
162  m_f->m_fielddef = FieldDef;
163  m_f->m_data = FieldData;
164 }
165 }
166 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
A class that contains algorithms for interpolation between pts fields, expansions and different meshe...
Definition: Interpolator.h:75
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
Represents a command-line configuration option.
STL namespace.
pair< ModuleType, string > ModuleKey
boost::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:178
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:767
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:179
void PrintProgressbar(const int position, const int goal) const
virtual void Process(po::variables_map &vm)
Write mesh to output file.
Abstract base class for processing modules.
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215