Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 using namespace Nektar;
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[4] = {
53  ModuleKey(eInputModule, "fld"), InputFld::create,
54  "Reads Fld file."),
56  ModuleKey(eInputModule, "chk"), InputFld::create,
57  "Reads checkpoint file."),
59  ModuleKey(eInputModule, "rst"), InputFld::create,
60  "Reads restart file."),
62  ModuleKey(eInputModule, "bse"), InputFld::create,
63  "Reads stability base-flow file.")
64 };
65 
66 
67 /**
68  * @brief Set up InputFld object.
69  *
70  */
71 InputFld::InputFld(FieldSharedPtr f) : InputModule(f)
72 {
73  m_allowedFiles.insert("fld");
74  m_allowedFiles.insert("chk");
75  m_allowedFiles.insert("rst");
76  m_allowedFiles.insert("bse");
77 }
78 
79 
80 /**
81  *
82  */
84 {
85 }
86 
87 
88 /**
89  *
90  */
91 void InputFld::Process(po::variables_map &vm)
92 {
93 
94  if(m_f->m_verbose)
95  {
96  if(m_f->m_comm->TreatAsRankZero())
97  {
98  cout << "Processing input fld file" << endl;
99  }
100  }
101 
102  int i,j;
103  string fldending;
104  //Determine appropriate field input
105  if(m_f->m_inputfiles.count("fld") != 0)
106  {
107  fldending = "fld";
108  }
109  else if(m_f->m_inputfiles.count("chk") != 0)
110  {
111  fldending = "chk";
112  }
113  else if (m_f->m_inputfiles.count("rst") != 0)
114  {
115  fldending = "rst";
116  }
117  else if (m_f->m_inputfiles.count("bse") != 0)
118  {
119  fldending = "bse";
120  }
121  else
122  {
123  ASSERTL0(false,"no input file found");
124  }
125 
126  if(!m_f->m_fld)
127  {
128  if(m_f->m_session)
129  {
131  ::AllocateSharedPtr(m_f->m_session->GetComm());
132  }
133  else // serial communicator
134  {
138  }
139  }
140 
141 
142  if(m_f->m_graph)
143  {
144  if (m_f->m_data.size() == 0)
145  {
146  // currently load all field (possibly could read data from
147  // expansion list but it is re-arranged in expansion)
148 
149  const SpatialDomains::ExpansionMap &expansions =
150  m_f->m_graph->GetExpansions();
151 
152  // if Range has been speficied it is possible to have a
153  // partition which is empty so check this and return if
154  // no elements present.
155 
156  if(!expansions.size())
157  {
158  return;
159  }
160 
161  m_f->m_exp.resize(1);
162 
163  Array<OneD,int> ElementGIDs(expansions.size());
164  SpatialDomains::ExpansionMap::const_iterator expIt;
165 
166  i = 0;
167  for (expIt = expansions.begin(); expIt != expansions.end(); ++expIt)
168  {
169  ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
170  }
171 
172  m_f->m_fielddef.clear();
173  m_f->m_data.clear();
174 
175  m_f->m_fld->Import(m_f->m_inputfiles[fldending][0],
176  m_f->m_fielddef,
177  m_f->m_data,
178  m_f->m_fieldMetaDataMap,
179  ElementGIDs);
180  }
181  }
182  else // load all data.
183  {
184  m_f->m_fld->Import(m_f->m_inputfiles[fldending][0],
185  m_f->m_fielddef,
186  m_f->m_data,
187  m_f->m_fieldMetaDataMap);
188  }
189 
190 
191  // if m_exp defined presume we want to load all field into expansions
192  if(m_f->m_exp.size())
193  {
194  int nfields,nstrips;
195 
196  m_f->m_session->LoadParameter("Strip_Z",nstrips,1);
197 
198  if(vm.count("useSessionVariables"))
199  {
200  nfields = m_f->m_session->GetVariables().size();
201  }
202  else
203  {
204  nfields = m_f->m_fielddef[0]->m_fields.size();
205  }
206 
207 
208  m_f->m_exp.resize(nfields*nstrips);
209 
210  vector<string> vars = m_f->m_session->GetVariables();
211 
212 
213  // declare other fields;
214  for (int s = 0; s < nstrips; ++s) //homogeneous strip varient
215  {
216  for (i = 0; i < nfields; ++i)
217  {
218  if(i < vars.size())
219  {
220  // check to see if field already defined
221  if(!m_f->m_exp[s*nfields+i])
222  {
223  m_f->m_exp[s*nfields+i] = m_f->AppendExpList(
224  m_f->m_fielddef[0]->m_numHomogeneousDir,
225  vars[i]);
226  }
227  }
228  else
229  {
230  if(vars.size())
231  {
232  m_f->m_exp[s*nfields+i] =
233  m_f->AppendExpList(
234  m_f->m_fielddef[0]->m_numHomogeneousDir,
235  vars[0]);
236  }
237  else
238  {
239  m_f->m_exp[s*nfields+i] =
240  m_f->AppendExpList(
241  m_f->m_fielddef[0]->m_numHomogeneousDir);
242  }
243  }
244  }
245  }
246 
247  // Extract data to coeffs and bwd transform
248  for(int s = 0; s < nstrips; ++s) //homogeneous strip varient
249  {
250  for (j = 0; j < nfields; ++j)
251  {
252  for (i = 0; i < m_f->m_data.size()/nstrips; ++i)
253  {
254  m_f->m_exp[s*nfields+j]->
255  ExtractDataToCoeffs(m_f->m_fielddef[i*nstrips+s],
256  m_f->m_data[i*nstrips+s],
257  m_f->m_fielddef[i*nstrips+s]
258  ->m_fields[j],
259  m_f->m_exp[s*nfields+j]->UpdateCoeffs());
260  }
261  m_f->m_exp[s*nfields+j]->BwdTrans(m_f->m_exp[s*nfields+j]->GetCoeffs(),
262  m_f->m_exp[s*nfields+j]->UpdatePhys());
263  }
264  }
265 
266  // reset output field in case Import loaded elements that are not
267  // in the expansion (because of range option of partitioning)
268  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
269  = m_f->m_exp[0]->GetFieldDefinitions();
270  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
271 
272  for (j = 0; j < nfields; ++j)
273  {
274  for (i = 0; i < FieldDef.size(); ++i)
275  {
276  FieldDef[i]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[j]);
277  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
278  }
279  }
280  m_f->m_fielddef = FieldDef;
281  m_f->m_data = FieldData;
282  }
283 }
284 
285 }
286 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
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:698
std::map< int, ExpansionShPtr > ExpansionMap
Definition: MeshGraph.h:174
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