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