Nektar++
InputFld.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: InputFld.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: Reads a Nektar++ FLD file.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "InputFld.h"
41 
42 
43 static std::string npts = LibUtilities::SessionReader::RegisterCmdLineArgument(
44  "NumberOfPoints","n","Define number of points to dump output");
45 
46 namespace Nektar
47 {
48 namespace Utilities
49 {
50 
51 ModuleKey InputFld::m_className[3] = {
53  ModuleKey(eInputModule, "fld"), InputFld::create,
54  "Reads Fld file."),
56  ModuleKey(eInputModule, "chk"), InputFld::create,
57  "Reads Fld file."),
59  ModuleKey(eInputModule, "rst"), InputFld::create,
60  "Reads Fld file."),
61 };
62 
63 
64 /**
65  * @brief Set up InputFld object.
66  *
67  */
68 InputFld::InputFld(FieldSharedPtr f) : InputModule(f)
69 {
70  m_allowedFiles.insert("fld");
71  m_allowedFiles.insert("chk");
72  m_allowedFiles.insert("rst");
73 }
74 
75 
76 /**
77  *
78  */
80 {
81 }
82 
83 
84 /**
85  *
86  */
87 void InputFld::Process(po::variables_map &vm)
88 {
89  if(m_f->m_verbose)
90  {
91  cout << "Processing input fld file" << endl;
92  }
93 
94  int i,j;
95  string fldending;
96  //Determine appropriate field input
97  if(m_f->m_inputfiles.count("fld") != 0)
98  {
99  fldending = "fld";
100  }
101  else if(m_f->m_inputfiles.count("chk") != 0)
102  {
103  fldending = "chk";
104  }
105  else if (m_f->m_inputfiles.count("rst") != 0)
106  {
107  fldending = "rst";
108  }
109  else
110  {
111  ASSERTL0(false,"no input file found");
112  }
113 
114  if(!m_f->m_fld)
115  {
116  if(m_f->m_session)
117  {
119  ::AllocateSharedPtr(m_f->m_session->GetComm());
120  }
121  else // serial communicator
122  {
126  }
127  }
128 
129 
130  if(m_f->m_graph) // all for restricted expansion defintion when loading field
131  {
132  // currently load all field (possibly could read data from expansion list
133  // but it is re-arranged in expansion)
134 
135  const SpatialDomains::ExpansionMap &expansions = m_f->m_graph->GetExpansions();
136 
137  // if Range has been speficied it is possible to have a
138  // partition which is empty so ccheck this and return if
139  // no elements present.
140  if(!expansions.size())
141  {
142  return;
143  }
144 
145  m_f->m_exp.resize(1);
146 
147  Array<OneD,int> ElementGIDs(expansions.size());
148  SpatialDomains::ExpansionMap::const_iterator expIt;
149 
150  i = 0;
151  for (expIt = expansions.begin(); expIt != expansions.end(); ++expIt)
152  {
153  ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
154  }
155 
156  m_f->m_fielddef.clear();
157  m_f->m_data.clear();
158 
159  m_f->m_fld->Import(m_f->m_inputfiles[fldending][0],
160  m_f->m_fielddef,
161  m_f->m_data,
162  m_f->m_fieldMetaDataMap,
163  ElementGIDs);
164  }
165  else // load all data.
166  {
167  m_f->m_fld->Import(m_f->m_inputfiles[fldending][0],
168  m_f->m_fielddef,
169  m_f->m_data,
170  m_f->m_fieldMetaDataMap);
171  }
172 
173 
174  // if m_exp defined presume we want to load all field into expansions
175  if(m_f->m_exp.size())
176  {
177  int nfields,nstrips;
178 
179  m_f->m_session->LoadParameter("Strip_Z",nstrips,1);
180 
181  if(vm.count("useSessionVariables"))
182  {
183  nfields = m_f->m_session->GetVariables().size();
184  }
185  else
186  {
187  nfields = m_f->m_fielddef[0]->m_fields.size();
188  }
189 
190 
191  m_f->m_exp.resize(nfields*nstrips);
192 
193  vector<string> vars = m_f->m_session->GetVariables();
194 
195  // declare other fields;
196  for (int s = 0; s < nstrips; ++s) //homogeneous strip varient
197  {
198  for (i = 0; i < nfields; ++i)
199  {
200  if(i < vars.size())
201  {
202  m_f->m_exp[s*nfields+i] = m_f->AppendExpList(
203  m_f->m_fielddef[0]->m_numHomogeneousDir,
204  vars[i]);
205  }
206  else
207  {
208  if(vars.size())
209  {
210  m_f->m_exp[s*nfields+i] =
211  m_f->AppendExpList(
212  m_f->m_fielddef[0]->m_numHomogeneousDir,
213  vars[0]);
214  }
215  else
216  {
217  m_f->m_exp[s*nfields+i] =
218  m_f->AppendExpList(
219  m_f->m_fielddef[0]->m_numHomogeneousDir);
220  }
221  }
222  }
223  }
224 
225  for(int s = 0; s < nstrips; ++s) //homogeneous strip varient
226  {
227  for (j = 0; j < nfields; ++j)
228  {
229  for (i = 0; i < m_f->m_data.size()/nstrips; ++i)
230  {
231  m_f->m_exp[s*nfields+j]->
232  ExtractDataToCoeffs(m_f->m_fielddef[i*nstrips+s],
233  m_f->m_data[i*nstrips+s],
234  m_f->m_fielddef[i*nstrips+s]
235  ->m_fields[j],
236  m_f->m_exp[s*nfields+j]->UpdateCoeffs());
237  }
238  m_f->m_exp[s*nfields+j]->BwdTrans(m_f->m_exp[s*nfields+j]->GetCoeffs(),
239  m_f->m_exp[s*nfields+j]->UpdatePhys());
240  }
241  }
242 
243  // if range is defined reset up output field in case or
244  // reducing fld definition
245  if(vm.count("range"))
246  {
247  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
248  = m_f->m_exp[0]->GetFieldDefinitions();
249  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
250 
251  for (j = 0; j < nfields; ++j)
252  {
253  for (i = 0; i < FieldDef.size(); ++i)
254  {
255  FieldDef[i]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[j]);
256  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
257  }
258  }
259  m_f->m_fielddef = FieldDef;
260  m_f->m_data = FieldData;
261  }
262  }
263 }
264 
265 }
266 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:135
pair< ModuleType, string > ModuleKey
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:162
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
virtual void Process()=0
STL namespace.
CommFactory & GetCommFactory()
Definition: Comm.cpp:64
FieldSharedPtr m_f
Field object.
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
static std::string npts
Definition: InputFld.cpp:43
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:677
std::map< int, ExpansionShPtr > ExpansionMap
Definition: MeshGraph.h:171
ModuleFactory & GetModuleFactory()
Abstract base class for input modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215