Nektar++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProcessCreateExp.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessCreateExp.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: Dummy module to create m_exp.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <string>
37 using namespace std;
38 
39 #include "ProcessCreateExp.h"
40 
43 
44 namespace Nektar
45 {
46 namespace FieldUtils
47 {
48 
49 ModuleKey ProcessCreateExp::className =
51  ModuleKey(eProcessModule, "createExp"),
52  ProcessCreateExp::create,
53  "dummy module used to create m_exp.");
54 
55 ProcessCreateExp::ProcessCreateExp(FieldSharedPtr f) : ProcessModule(f)
56 {
57 }
58 
60 {
61 }
62 
63 void ProcessCreateExp::Process(po::variables_map &vm)
64 {
65  if(m_f->m_graph)
66  {
67  LibUtilities::Timer timerpart;
68  if (m_f->m_verbose)
69  {
70  if (m_f->m_comm->TreatAsRankZero())
71  {
72  timerpart.Start();
73  }
74  }
75  // check to see if fld file defined so can use in
76  // expansion defintion if required
77  bool fldfilegiven = (m_f->m_fielddef.size() != 0);
78  bool expFromFld = fldfilegiven && !vm.count("useSessionExpansion");
79 
80  // load fielddef header if fld file is defined. This gives
81  // precedence to Homogeneous definition in fld file
82  m_f->m_numHomogeneousDir = 0;
83  if (expFromFld)
84  {
85  m_f->m_numHomogeneousDir = m_f->m_fielddef[0]->m_numHomogeneousDir;
86 
87  // Set up Expansion information to use mode order from field
88  m_f->m_graph->SetExpansionInfo(m_f->m_fielddef);
89  }
90  else
91  {
92  if (m_f->m_session->DefinesSolverInfo("HOMOGENEOUS"))
93  {
94  std::string HomoStr =
95  m_f->m_session->GetSolverInfo("HOMOGENEOUS");
96 
97  if ((HomoStr == "HOMOGENEOUS1D") ||
98  (HomoStr == "Homogeneous1D") ||
99  (HomoStr == "1D") || (HomoStr == "Homo1D"))
100  {
101  m_f->m_numHomogeneousDir = 1;
102  }
103  if ((HomoStr == "HOMOGENEOUS2D") ||
104  (HomoStr == "Homogeneous2D") ||
105  (HomoStr == "2D") || (HomoStr == "Homo2D"))
106  {
107  m_f->m_numHomogeneousDir = 2;
108  }
109  }
110  }
111 
112  m_f->m_exp.resize(1);
113  // Check if there are any elements to process
114  vector<int> IDs;
115  auto domain = m_f->m_graph->GetDomain();
116  for(int d = 0; d < domain.size(); ++d)
117  {
118  for (auto &compIter : domain[d])
119  {
120  for (auto &x : compIter.second->m_geomVec)
121  {
122  IDs.push_back(x->GetGlobalID());
123  }
124  }
125  }
126  // if Range has been specified it is possible to have a
127  // partition which is empty so check this and return with empty
128  // expansion if no elements present.
129  if (!IDs.size())
130  {
133  return;
134  }
135 
136  // Adjust number of quadrature points
137  if (vm.count("output-points"))
138  {
139  int nPointsNew = vm["output-points"].as<int>();
140  m_f->m_graph->SetExpansionInfoToPointOrder(nPointsNew);
141  }
142 
143  if (m_f->m_verbose)
144  {
145  if (m_f->m_comm->TreatAsRankZero())
146  {
147  timerpart.Stop();
148  NekDouble cpuTime = timerpart.TimePerTest(1);
149 
150  stringstream ss;
151  ss << cpuTime << "s";
152  cout << "\t ProcessCreateExp setexpansion CPU Time: "
153  << setw(8) << left
154  << ss.str() << endl;
155  timerpart.Start();
156  }
157  }
158  // Override number of planes with value from cmd line
159  if (m_f->m_numHomogeneousDir == 1 && vm.count("output-points-hom-z"))
160  {
161  int expdim = m_f->m_graph->GetMeshDimension();
162  m_f->m_fielddef[0]->m_numModes[expdim] =
163  vm["output-points-hom-z"].as<int>();
164  }
165  m_f->m_exp[0] = m_f->SetUpFirstExpList(m_f->m_numHomogeneousDir,
166  expFromFld);
167  if (m_f->m_verbose)
168  {
169  if (m_f->m_comm->TreatAsRankZero())
170  {
171  timerpart.Stop();
172  NekDouble cpuTime = timerpart.TimePerTest(1);
173 
174  stringstream ss1;
175 
176  ss1 << cpuTime << "s";
177  cout << "\t ProcessCreateExp set first exp CPU Time: "
178  << setw(8) << left
179  << ss1.str() << endl;
180  }
181  }
182 
183  if (fldfilegiven)
184  {
185  LoadFieldData(vm.count("useSessionVariables"));
186  }
187  }
188 
189 }
190 
191 void ProcessCreateExp::LoadFieldData(bool useSessionVariables)
192 {
193  int i, j;
194  int nfields, nstrips;
195  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
196  vector<string> vars = m_f->m_session->GetVariables();
197 
198  //if (vm.count("useSessionVariables"))
199  if (useSessionVariables)
200  {
201  m_f->m_variables = vars;
202  }
203  nfields = m_f->m_variables.size();
204 
205  m_f->m_exp.resize(nfields * nstrips);
206  // declare other fields;
207  for (int s = 0; s < nstrips; ++s) // homogeneous strip varient
208  {
209  for (i = 0; i < nfields; ++i)
210  {
211  if (i < vars.size())
212  {
213  // check to see if field already defined
214  if (!m_f->m_exp[s * nfields + i])
215  {
216  m_f->m_exp[s * nfields + i] = m_f->AppendExpList(
217  m_f->m_numHomogeneousDir, vars[i]);
218  }
219  }
220  else
221  {
222  if (vars.size())
223  {
224  m_f->m_exp[s * nfields + i] = m_f->AppendExpList(
225  m_f->m_numHomogeneousDir, vars[0]);
226  }
227  else
228  {
229  m_f->m_exp[s * nfields + i] = m_f->AppendExpList(
230  m_f->m_numHomogeneousDir);
231  }
232  }
233  }
234  }
235 
236  // Extract data to coeffs and bwd transform
237  for (int s = 0; s < nstrips; ++s) // homogeneous strip varient
238  {
239  for (j = 0; j < nfields; ++j)
240  {
241  for (i = 0; i < m_f->m_data.size() / nstrips; ++i)
242  {
243  int n = i * nstrips + s;
244  // In case of multiple flds, we might not have a
245  // variable in this m_data[n] -> skip in this case
246  auto it = find (m_f->m_fielddef[n]->m_fields.begin(),
247  m_f->m_fielddef[n]->m_fields.end(),
248  m_f->m_variables[j]);
249  if(it !=m_f->m_fielddef[n]->m_fields.end())
250  {
251  m_f->m_exp[s * nfields + j]->ExtractDataToCoeffs(
252  m_f->m_fielddef[n],
253  m_f->m_data[n],
254  m_f->m_variables[j],
255  m_f->m_exp[s * nfields + j]->UpdateCoeffs());
256  }
257  }
258  m_f->m_exp[s * nfields + j]->BwdTrans(
259  m_f->m_exp[s * nfields + j]->GetCoeffs(),
260  m_f->m_exp[s * nfields + j]->UpdatePhys());
261  }
262  }
263  // Clear fielddef and data (they should not be used after running this
264  // module)
265  m_f->m_fielddef = vector<LibUtilities::FieldDefinitionsSharedPtr>();
266  m_f->m_data = vector<std::vector<NekDouble> >();
267 }
268 
269 
270 }
271 }
FieldSharedPtr m_f
Field object.
Definition: Module.h:230
virtual void Process(po::variables_map &vm)
Write mesh to output file.
void LoadFieldData(bool useSessionVariables=false)
Abstract base class for processing modules.
Definition: Module.h:265
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
NekDouble TimePerTest(unsigned int n)
Returns amount of seconds per iteration in a test with n iterations.
Definition: Timer.cpp:62
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:989
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:290
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:362
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble