Nektar++
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 // 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: Interpolate, using finite different approximation,
32 // given data 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/geometry.hpp>
41 #include <boost/math/special_functions/fpclassify.hpp>
42 
48 
50 
51 namespace bg = boost::geometry;
52 namespace bgi = boost::geometry::index;
53 
54 namespace Nektar
55 {
56 namespace FieldUtils
57 {
58 
59 ModuleKey ProcessInterpPointDataToFld::className =
61  ModuleKey(eProcessModule, "interppointdatatofld"),
62  ProcessInterpPointDataToFld::create,
63  "Interpolates given discrete data using a finite difference "
64  "approximation to a fld file given a xml file");
65 
66 ProcessInterpPointDataToFld::ProcessInterpPointDataToFld(FieldSharedPtr f)
67  : ProcessModule(f)
68 {
69  m_config["frompts"] = ConfigOption(
70  false, "NotSet", "Pts file from which to interpolate field");
71 
72  m_config["interpcoord"] =
73  ConfigOption(false, "-1", "coordinate id to use for interpolation");
74 }
75 
77 {
78 }
79 
80 void ProcessInterpPointDataToFld::Process(po::variables_map &vm)
81 {
82  boost::ignore_unused(vm);
83 
84  int i, j;
86  // Load pts file
87  ASSERTL0( m_config["frompts"].as<string>().compare("NotSet") != 0,
88  "ProcessInterpPointDataToFld requires frompts parameter");
89  string inFile = m_config["frompts"].as<string>().c_str();
90 
91  if (boost::filesystem::path(inFile).extension() == ".pts")
92  {
95 
96  ptsIO->Import(inFile, fieldPts);
97  }
98  else if (boost::filesystem::path(inFile).extension() == ".csv")
99  {
102 
103  csvIO->Import(inFile, fieldPts);
104  }
105  else
106  {
107  ASSERTL0(false, "unknown frompts file type");
108  }
109 
110  int nFields = fieldPts->GetNFields();
111  ASSERTL0(nFields > 0, "No field values provided in input");
112 
113  // Define new expansions.
114  ASSERTL0(m_f->m_numHomogeneousDir == 0,
115  "ProcessInterpPointDataToFld does not support homogeneous expansion");
116 
117  m_f->m_exp.resize(nFields);
118  for (i = 1; i < nFields; ++i)
119  {
120  m_f->m_exp[i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
121  }
122 
123  int totpoints = m_f->m_exp[0]->GetTotPoints();
124  Array<OneD, Array<OneD, NekDouble> > intFields(3 + nFields);
125  for (int i = 0; i < 3 + nFields; ++i)
126  {
127  intFields[i] = Array<OneD, NekDouble>(totpoints);
128  }
129  m_f->m_exp[0]->GetCoords(intFields[0], intFields[1], intFields[2]);
132 
133  int coord_id = m_config["interpcoord"].as<int>();
134  cout << coord_id << endl;
135  cout << outPts->GetDim() << endl;
136  ASSERTL0(coord_id <= static_cast<int>(outPts->GetDim()) - 1,
137  "interpcoord is bigger than the Pts files dimension");
138 
139  Interpolator interp(LibUtilities::eNoMethod, coord_id);
140 
141  if (m_f->m_verbose && m_f->m_comm->TreatAsRankZero())
142  {
143  interp.SetProgressCallback(
145  }
146  interp.Interpolate(fieldPts, outPts);
147  if (m_f->m_verbose && m_f->m_comm->TreatAsRankZero())
148  {
149  cout << endl;
150  }
151 
152  for (i = 0; i < totpoints; ++i)
153  {
154  for (j = 0; j < nFields; ++j)
155  {
156  m_f->m_exp[j]->SetPhys(i, outPts->GetPointVal(3 + j, i));
157  }
158  }
159 
160  // forward transform fields
161  for (i = 0; i < nFields; ++i)
162  {
163  m_f->m_exp[i]->FwdTrans_IterPerExp(m_f->m_exp[i]->GetPhys(),
164  m_f->m_exp[i]->UpdateCoeffs());
165  }
166 
167  // save field names
168  for (int j = 0; j < fieldPts->GetNFields(); ++j)
169  {
170  m_f->m_variables.push_back(fieldPts->GetFieldName(j));
171  }
172 }
173 }
174 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
A class that contains algorithms for interpolation between pts fields, expansions and different meshe...
std::map< std::string, ConfigOption > m_config
List of configuration values.
void SetProgressCallback(FuncPointerT func, ObjectPointerT obj)
sets a callback funtion which gets called every time the interpolation progresses ...
Represents a command-line configuration option.
STL namespace.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
std::shared_ptr< PtsIO > PtsIOSharedPtr
Definition: PtsIO.h:96
std::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:179
std::pair< ModuleType, std::string > ModuleKey
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
FIELD_UTILS_EXPORT void Interpolate(const std::vector< MultiRegions::ExpListSharedPtr > expInField, std::vector< MultiRegions::ExpListSharedPtr > &expOutField, NekDouble def_value=0.0)
Interpolate from an expansion to an expansion.
void PrintProgressbar(const int position, const int goal) const
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
virtual void Process(po::variables_map &vm)
Write mesh to output file.
Abstract base class for processing modules.
std::shared_ptr< CsvIO > CsvIOSharedPtr
Definition: CsvIO.h:81
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.