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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Reads a Nektar++ FLD file.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <string>
37 using namespace std;
38 
39 #include <boost/core/ignore_unused.hpp>
40 
41 #include "InputFld.h"
42 using namespace Nektar;
43 
44 namespace Nektar
45 {
46 namespace FieldUtils
47 {
48 
49 ModuleKey InputFld::m_className[4] = {
51  ModuleKey(eInputModule, "fld"),
52  InputFld::create, "Reads Fld file."),
54  ModuleKey(eInputModule, "chk"),
55  InputFld::create, "Reads checkpoint file."),
57  ModuleKey(eInputModule, "rst"),
58  InputFld::create, "Reads restart file."),
60  ModuleKey(eInputModule, "bse"),
61  InputFld::create, "Reads stability base-flow file.")
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  m_allowedFiles.insert("bse");
74 }
75 
76 /**
77  *
78  */
80 {
81 }
82 
83 /**
84  *
85  */
86 void InputFld::Process(po::variables_map &vm)
87 {
88  boost::ignore_unused(vm);
89 
90  int i;
91  string fileName = m_config["infile"].as<string>();
92 
94  m_f->FieldIOForFile(fileName);
95 
96  int oldSize = m_f->m_fielddef.size();
97  if(m_f->m_graph)
98  {
99  // Determine IDs of elements in the domain
100  vector<int> IDs;
101  auto domain = m_f->m_graph->GetDomain();
102  for(int d = 0; d < domain.size(); ++d)
103  {
104  for (auto &compIter : domain[d])
105  {
106  for (auto &x : compIter.second->m_geomVec)
107  {
108  IDs.push_back(x->GetGlobalID());
109  }
110  }
111  }
112 
113  if (!IDs.size())
114  {
115  return;
116  }
117 
118  // Move to an array to match FieldIO interface
119  Array<OneD, int> ElementGIDs(IDs.size(), IDs.data());
120 
121  fld->Import(
122  fileName, m_f->m_fielddef, m_f->m_data,
123  m_f->m_fieldMetaDataMap, ElementGIDs);
124  }
125  else // load all data.
126  {
127  fld->Import(
128  fileName, m_f->m_fielddef, m_f->m_data,
129  m_f->m_fieldMetaDataMap);
130  }
131 
132  // save field names
133  for(i = 0; i < m_f->m_fielddef[oldSize]->m_fields.size(); ++i)
134  {
135  // check for multiple fld files
136  auto it = find (m_f->m_variables.begin(),
137  m_f->m_variables.end(),
138  m_f->m_fielddef[oldSize]->m_fields[i]);
139 
140  if(it == m_f->m_variables.end())
141  {
142  m_f->m_variables.push_back(m_f->m_fielddef[oldSize]->m_fields[i]);
143  }
144  }
145 }
146 }
147 }
std::map< std::string, ConfigOption > m_config
List of configuration values.
STL namespace.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
Abstract base class for input modules.
std::pair< ModuleType, std::string > ModuleKey
std::set< std::string > m_allowedFiles
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:358
virtual void Process(po::variables_map &vm)
Definition: InputFld.cpp:86
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
std::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:306
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.