Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 <string>
37 #include <iostream>
38 
39 using namespace std;
40 
42 
45 #include <boost/math/special_functions/fpclassify.hpp>
46 namespace Nektar
47 {
48 namespace Utilities
49 {
50 
51 ModuleKey ProcessInterpPointDataToFld::className =
53  ModuleKey(eProcessModule, "interppointdatatofld"),
54  ProcessInterpPointDataToFld::create,
55  "Interpolates given discrete data using a finite difference "
56  "approximation to a fld file given a xml file");
57 
58 
59 ProcessInterpPointDataToFld::ProcessInterpPointDataToFld(FieldSharedPtr f)
60  : ProcessModule(f)
61 {
62 
63  m_config["interpcoord"] = ConfigOption(false, "-1",
64  "coordinate id to use for interpolation");
65 
66 }
67 
69 {
70 }
71 
72 void ProcessInterpPointDataToFld::Process(po::variables_map &vm)
73 {
74  int i,j;
75 
76  // Check for command line point specification if no .pts file specified
78  "No input points found");
79 
80  int nFields = m_f->m_fieldPts->GetNFields();
81  ASSERTL0(nFields > 0,
82  "No field values provided in input");
83 
84  // assume one field is already defined from input file.
85  m_f->m_exp.resize(nFields+1);
86  for(i = 1; i < nFields; ++i)
87  {
88  m_f->m_exp[i] = m_f->AppendExpList(0);
89  }
90 
91  int totpoints = m_f->m_exp[0]->GetTotPoints();
93 
94  coords[0] = Array<OneD,NekDouble>(totpoints);
95  coords[1] = Array<OneD,NekDouble>(totpoints);
96  coords[2] = Array<OneD,NekDouble>(totpoints);
97 
98  m_f->m_exp[0]->GetCoords(coords[0],coords[1],coords[2]);
99 
100  int coord_id = m_config["interpcoord"].as<int>();
101  ASSERTL0(coord_id <= m_f->m_fieldPts->GetDim() - 1,
102  "interpcoord is bigger than the Pts files dimension");
103 
104  // interpolate points and transform
105  Array<OneD, Array<OneD, NekDouble> > intFields(nFields);
106  if (m_f->m_session->GetComm()->GetRank() == 0)
107  {
108  m_f->m_fieldPts->setProgressCallback(
110  cout << "Interpolating: ";
111  }
112  m_f->m_fieldPts->Interpolate(coords, intFields, coord_id);
113 
114  for(i = 0; i < totpoints; ++i)
115  {
116  for(j = 0; j < nFields; ++j)
117  {
118  m_f->m_exp[j]->SetPhys(i, intFields[j][i]);
119  }
120  }
121 
122  if(m_f->m_session->GetComm()->GetRank() == 0)
123  {
124  cout << endl;
125  }
126 
127  // forward transform fields
128  for(i = 0; i < nFields; ++i)
129  {
130  m_f->m_exp[i]->FwdTrans_IterPerExp(m_f->m_exp[i]->GetPhys(),
131  m_f->m_exp[i]->UpdateCoeffs());
132  }
133 
134 
135  // set up output fld file.
136  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
137  = m_f->m_exp[0]->GetFieldDefinitions();
138  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
139 
140  for (j = 0; j < nFields; ++j)
141  {
142  for (i = 0; i < FieldDef.size(); ++i)
143  {
144  FieldDef[i]->m_fields.push_back(m_f->m_fieldPts->GetFieldName(j));
145 
146  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
147  }
148  }
149 
150  m_f->m_fielddef = FieldDef;
151  m_f->m_data = FieldData;
152 
153 }
154 
155 }
156 }
157 
158 
#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.
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:695
Represents a command-line configuration option.
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:264
void PrintProgressbar(const int position, const int goal) const
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