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