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