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