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 
42 
47 #include <boost/math/special_functions/fpclassify.hpp>
48 namespace Nektar
49 {
50 namespace FieldUtils
51 {
52 
53 ModuleKey ProcessInterpPointDataToFld::className =
55  ModuleKey(eProcessModule, "interppointdatatofld"),
56  ProcessInterpPointDataToFld::create,
57  "Interpolates given discrete data using a finite difference "
58  "approximation to a fld file given a xml file");
59 
60 ProcessInterpPointDataToFld::ProcessInterpPointDataToFld(FieldSharedPtr f)
61  : ProcessModule(f)
62 {
63 
64  m_config["interpcoord"] =
65  ConfigOption(false, "-1", "coordinate id to use for interpolation");
66 }
67 
69 {
70 }
71 
72 void ProcessInterpPointDataToFld::Process(po::variables_map &vm)
73 {
74  if (m_f->m_verbose)
75  {
76  if (m_f->m_comm->TreatAsRankZero())
77  {
78  cout
79  << "ProcessInterpPointDataToFld: interpolating data to field..."
80  << endl;
81  }
82  }
83 
84  int i, j;
85 
86  // Check for command line point specification if no .pts file specified
88  "No input points found");
89 
90  int nFields = m_f->m_fieldPts->GetNFields();
91  ASSERTL0(nFields > 0, "No field values provided in input");
92 
93  // assume one field is already defined from input file.
94  m_f->m_exp.resize(nFields + 1);
95  for (i = 1; i < nFields; ++i)
96  {
97  m_f->m_exp[i] = m_f->AppendExpList(0);
98  }
99 
100  int totpoints = m_f->m_exp[0]->GetTotPoints();
101  Array<OneD, Array<OneD, NekDouble> > intFields(3 + nFields);
102  for (int i = 0; i < 3 + nFields; ++i)
103  {
104  intFields[i] = Array<OneD, NekDouble>(totpoints);
105  }
106  m_f->m_exp[0]->GetCoords(intFields[0], intFields[1], intFields[2]);
109 
110  int coord_id = m_config["interpcoord"].as<int>();
111  ASSERTL0(coord_id <= m_f->m_fieldPts->GetDim() - 1,
112  "interpcoord is bigger than the Pts files dimension");
113 
114  Interpolator interp(eNoMethod, coord_id);
115 
116  if (m_f->m_comm->GetRank() == 0)
117  {
118  interp.SetProgressCallback(
120  }
121  interp.Interpolate(m_f->m_fieldPts, outPts);
122  if (m_f->m_comm->GetRank() == 0)
123  {
124  cout << endl;
125  }
126 
127  for (i = 0; i < totpoints; ++i)
128  {
129  for (j = 0; j < nFields; ++j)
130  {
131  m_f->m_exp[j]->SetPhys(i, outPts->GetPointVal(j, i));
132  }
133  }
134 
135  // forward transform fields
136  for (i = 0; i < nFields; ++i)
137  {
138  m_f->m_exp[i]->FwdTrans_IterPerExp(m_f->m_exp[i]->GetPhys(),
139  m_f->m_exp[i]->UpdateCoeffs());
140  }
141 
142  // set up output fld file.
143  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
144  m_f->m_exp[0]->GetFieldDefinitions();
145  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
146 
147  for (j = 0; j < nFields; ++j)
148  {
149  for (i = 0; i < FieldDef.size(); ++i)
150  {
151  FieldDef[i]->m_fields.push_back(m_f->m_fieldPts->GetFieldName(j));
152 
153  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
154  }
155  }
156 
157  m_f->m_fielddef = FieldDef;
158  m_f->m_data = FieldData;
159 }
160 }
161 }
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:78
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:740
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