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: GMSH converter.
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  ModuleKey InputFld::m_className[5] = {
52  ModuleKey(eInputModule, "fld"), InputFld::create,
53  "Reads Fld file."),
55  ModuleKey(eInputModule, "chk"), InputFld::create,
56  "Reads Fld file."),
58  ModuleKey(eInputModule, "rst"), InputFld::create,
59  "Reads Fld file."),
60  };
61 
62  /**
63  * @brief Set up InputFld object.
64  *
65  */
66  InputFld::InputFld(FieldSharedPtr f) : InputModule(f)
67  {
68  m_allowedFiles.insert("fld");
69  m_allowedFiles.insert("chk");
70  m_allowedFiles.insert("rst");
71  }
72 
74  {
75  }
76 
77  /**
78  *
79  */
80  void InputFld::Process(po::variables_map &vm)
81  {
82  if(m_f->m_verbose)
83  {
84  cout << "Processing input fld file" << endl;
85  }
86 
87  int i;
88  string fldending;
89  //Determine appropriate field input
90  if(m_f->m_inputfiles.count("fld") != 0)
91  {
92  fldending = "fld";
93  }
94  else if(m_f->m_inputfiles.count("chk") != 0)
95  {
96  fldending = "chk";
97  }
98  else if (m_f->m_inputfiles.count("rst") != 0)
99  {
100  fldending = "rst";
101  }
102  else
103  {
104  ASSERTL0(false,"no input file found");
105  }
106 
107  if(!m_f->m_fld)
108  {
109  if(m_f->m_session)
110  {
112  ::AllocateSharedPtr(m_f->m_session->GetComm());
113  }
114  else // serial communicator
115  {
119  }
120  }
121 
122 
123  if(m_f->m_graph) // all for restricted expansion defintion when loading field
124  {
125  // currently load all field (possibly could read data from expansion list
126  // but it is re-arranged in expansion)
127 
128  const SpatialDomains::ExpansionMap &expansions = m_f->m_graph->GetExpansions();
129 
130  // if Range has been speficied it is possible to have a
131  // partition which is empty so ccheck this and return if
132  // no elements present.
133  if(!expansions.size())
134  {
135  return;
136  }
137 
138  m_f->m_exp.resize(1);
139 
140  Array<OneD,int> ElementGIDs(expansions.size());
141  SpatialDomains::ExpansionMap::const_iterator expIt;
142 
143  i = 0;
144  for (expIt = expansions.begin(); expIt != expansions.end(); ++expIt)
145  {
146  ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
147  }
148 
149  m_f->m_fielddef.clear();
150  m_f->m_data.clear();
151 
152  m_f->m_fld->Import(m_f->m_inputfiles[fldending][0],m_f->m_fielddef,m_f->m_data,
154  ElementGIDs);
155  }
156  else // load all data.
157  {
158  m_f->m_fld->Import(m_f->m_inputfiles[fldending][0],m_f->m_fielddef,m_f->m_data);
159  }
160 
161 
162  // if m_exp defined presume we want to load all field into expansions
163  if(m_f->m_exp.size())
164  {
165  int nfields;
166  if(vm.count("useSessionVariables"))
167  {
168  nfields = m_f->m_session->GetVariables().size();
169  }
170  else
171  {
172  nfields = m_f->m_fielddef[0]->m_fields.size();
173  }
174  m_f->m_exp.resize(nfields);
175 
176  vector<string> vars = m_f->m_session->GetVariables();
177 
178  // declare other fields;
179  for (int i = 1; i < nfields; ++i)
180  {
181  if(i < vars.size())
182  {
183  m_f->m_exp[i] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir,
184  vars[i]);
185  }
186  else
187  {
188  if(vars.size())
189  {
190  m_f->m_exp[i] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir,vars[0]);
191  }
192  else
193  {
194  m_f->m_exp[i] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
195  }
196  }
197  }
198 
199  for (int j = 0; j < nfields; ++j)
200  {
201  for (int i = 0; i < m_f->m_data.size(); ++i)
202  {
203  m_f->m_exp[j]->ExtractDataToCoeffs(m_f->m_fielddef[i],
204  m_f->m_data[i],
205  m_f->m_fielddef[i]->m_fields[j],
206  m_f->m_exp[j]->UpdateCoeffs());
207  }
208  m_f->m_exp[j]->BwdTrans(m_f->m_exp[j]->GetCoeffs(),
209  m_f->m_exp[j]->UpdatePhys());
210  }
211 
212  // if range is defined reset up output field in case or
213  // reducing fld definition
214  if(vm.count("range"))
215  {
216  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
217  = m_f->m_exp[0]->GetFieldDefinitions();
218  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
219 
220  for (int j = 0; j < nfields; ++j)
221  {
222  for (i = 0; i < FieldDef.size(); ++i)
223  {
224  FieldDef[i]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[j]);
225  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
226  }
227  }
228  m_f->m_fielddef = FieldDef;
229  m_f->m_data = FieldData;
230  }
231  }
232  }
233  }
234 }