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  if(m_f->m_verbose)
75  {
76  if(m_f->m_comm->TreatAsRankZero())
77  {
78  cout << "ProcessInterpPointDataToFld: interpolating data to field..."
79  << endl;
80  }
81  }
82 
83  int i,j;
84 
85  // Check for command line point specification if no .pts file specified
87  "No input points found");
88 
89  int nFields = m_f->m_fieldPts->GetNFields();
90  ASSERTL0(nFields > 0,
91  "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();
102 
103  coords[0] = Array<OneD,NekDouble>(totpoints);
104  coords[1] = Array<OneD,NekDouble>(totpoints);
105  coords[2] = Array<OneD,NekDouble>(totpoints);
106 
107  m_f->m_exp[0]->GetCoords(coords[0],coords[1],coords[2]);
108 
109  int coord_id = m_config["interpcoord"].as<int>();
110  ASSERTL0(coord_id <= m_f->m_fieldPts->GetDim() - 1,
111  "interpcoord is bigger than the Pts files dimension");
112 
113  // interpolate points and transform
114  Array<OneD, Array<OneD, NekDouble> > intFields(nFields);
115  if (m_f->m_session->GetComm()->GetRank() == 0)
116  {
117  m_f->m_fieldPts->setProgressCallback(
119  cout << "Interpolating: ";
120  }
121  m_f->m_fieldPts->Interpolate(coords, intFields, coord_id);
122 
123  for(i = 0; i < totpoints; ++i)
124  {
125  for(j = 0; j < nFields; ++j)
126  {
127  m_f->m_exp[j]->SetPhys(i, intFields[j][i]);
128  }
129  }
130 
131  if(m_f->m_session->GetComm()->GetRank() == 0)
132  {
133  cout << endl;
134  }
135 
136  // forward transform fields
137  for(i = 0; i < nFields; ++i)
138  {
139  m_f->m_exp[i]->FwdTrans_IterPerExp(m_f->m_exp[i]->GetPhys(),
140  m_f->m_exp[i]->UpdateCoeffs());
141  }
142 
143 
144  // set up output fld file.
145  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
146  = m_f->m_exp[0]->GetFieldDefinitions();
147  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
148 
149  for (j = 0; j < nFields; ++j)
150  {
151  for (i = 0; i < FieldDef.size(); ++i)
152  {
153  FieldDef[i]->m_fields.push_back(m_f->m_fieldPts->GetFieldName(j));
154 
155  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
156  }
157  }
158 
159  m_f->m_fielddef = FieldDef;
160  m_f->m_data = FieldData;
161 }
162 
163 }
164 }
165 
166 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
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:698
Represents a command-line configuration option.
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:263
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