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[3] = {
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,j;
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],
153  m_f->m_fielddef,
154  m_f->m_data,
156  ElementGIDs);
157  }
158  else // load all data.
159  {
160  m_f->m_fld->Import(m_f->m_inputfiles[fldending][0],
161  m_f->m_fielddef,
162  m_f->m_data);
163  }
164 
165 
166  // if m_exp defined presume we want to load all field into expansions
167  if(m_f->m_exp.size())
168  {
169  int nfields;
170  if(vm.count("useSessionVariables"))
171  {
172  nfields = m_f->m_session->GetVariables().size();
173  }
174  else
175  {
176  nfields = m_f->m_fielddef[0]->m_fields.size();
177  }
178  m_f->m_exp.resize(nfields);
179 
180  vector<string> vars = m_f->m_session->GetVariables();
181 
182  // declare other fields;
183  for (i = 1; i < nfields; ++i)
184  {
185  if(i < vars.size())
186  {
187  m_f->m_exp[i] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir,
188  vars[i]);
189  }
190  else
191  {
192  if(vars.size())
193  {
194  m_f->m_exp[i] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir,vars[0]);
195  }
196  else
197  {
198  m_f->m_exp[i] = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
199  }
200  }
201  }
202 
203  for (j = 0; j < nfields; ++j)
204  {
205  for (i = 0; i < m_f->m_data.size(); ++i)
206  {
207  m_f->m_exp[j]->ExtractDataToCoeffs(m_f->m_fielddef[i],
208  m_f->m_data[i],
209  m_f->m_fielddef[i]->m_fields[j],
210  m_f->m_exp[j]->UpdateCoeffs());
211  }
212  m_f->m_exp[j]->BwdTrans(m_f->m_exp[j]->GetCoeffs(),
213  m_f->m_exp[j]->UpdatePhys());
214  }
215 
216  // if range is defined reset up output field in case or
217  // reducing fld definition
218  if(vm.count("range"))
219  {
220  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
221  = m_f->m_exp[0]->GetFieldDefinitions();
222  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
223 
224  for (j = 0; j < nfields; ++j)
225  {
226  for (i = 0; i < FieldDef.size(); ++i)
227  {
228  FieldDef[i]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[j]);
229  m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
230  }
231  }
232  m_f->m_fielddef = FieldDef;
233  m_f->m_data = FieldData;
234  }
235  }
236  }
237  }
238 }