Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProcessNumModes.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessNumModes.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: Writes the number of modes in each direction.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "ProcessNumModes.h"
41 
44 #include <StdRegions/StdQuadExp.h>
45 
46 namespace Nektar
47 {
48 namespace Utilities
49 {
50 
51 ModuleKey ProcessNumModes::className =
53  ModuleKey(eProcessModule, "nummodes"), ProcessNumModes::create,
54  "Computes number of modes in each direction for each element.");
55 
56 ProcessNumModes::ProcessNumModes(FieldSharedPtr f) : ProcessModule(f)
57 {
58 }
59 
61 {
62 }
63 
64 void ProcessNumModes::Process(po::variables_map &vm)
65 {
66  if (m_f->m_verbose)
67  {
68  if(m_f->m_comm->TreatAsRankZero())
69  {
70  cout << "ProcessNumModes: Calculating number of modes..." << endl;
71  }
72  }
73 
74  int i, j, s;
75  int expdim = m_f->m_graph->GetMeshDimension();
76  int nfields = m_f->m_fielddef[0]->m_fields.size();
77  int addfields = expdim;
78  int npoints = m_f->m_exp[0]->GetNpoints();
79  Array<OneD, Array<OneD, NekDouble> > outfield(addfields);
80 
81  int nstrips;
82 
83  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
84 
85  m_f->m_exp.resize(nfields * nstrips);
86 
87  for (i = 0; i < addfields; ++i)
88  {
89  outfield[i] = Array<OneD, NekDouble>(npoints);
90  }
91 
92  vector<MultiRegions::ExpListSharedPtr> Exp(nstrips * addfields);
93 
94  int nExp, nq, offset;
95  nExp = m_f->m_exp[0]->GetExpSize();
96 
97  for (int n = 0; n < nExp; n++)
98  {
99  offset = m_f->m_exp[0]->GetPhys_Offset(n);
100  nq = m_f->m_exp[0]->GetExp(n)->GetTotPoints();
101 
102  for (i = 0; i < expdim; i++)
103  {
104  int P = m_f->m_exp[0]->GetExp(n)->GetBasis(i)->GetNumModes();
105  Array<OneD, NekDouble> result = outfield[i] + offset;
106  Vmath::Fill(nq, 1.0 * P, result, 1);
107  }
108  }
109 
110  for (s = 0; s < nstrips; ++s)
111  {
112  for (i = 0; i < addfields; ++i)
113  {
114  int n = s * addfields + i;
115  Exp[n] =
116  m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir);
117  Exp[n]->UpdatePhys() = outfield[i];
118  Exp[n]->FwdTrans_IterPerExp(outfield[i], Exp[n]->UpdateCoeffs());
119  }
120  }
121 
123  for (s = 0; s < nstrips; ++s)
124  {
125  for (i = 0; i < addfields; ++i)
126  {
127  it = m_f->m_exp.begin() + s * (nfields + addfields) + nfields + i;
128  m_f->m_exp.insert(it, Exp[s * addfields + i]);
129  }
130  }
131 
132  vector<string> outname;
133  outname.push_back("P1");
134  if (addfields >= 2)
135  {
136  outname.push_back("P2");
137  }
138 
139  if (addfields == 3)
140  {
141  outname.push_back("P3");
142  }
143 
144  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
145  m_f->m_exp[0]->GetFieldDefinitions();
146  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
147 
148  // homogeneous strip variant
149  for (s = 0; s < nstrips; ++s)
150  {
151  for (j = 0; j < nfields + addfields; ++j)
152  {
153  for (i = 0; i < FieldDef.size() / nstrips; ++i)
154  {
155  int n = s * FieldDef.size() / nstrips + i;
156 
157  if (j >= nfields)
158  {
159  FieldDef[n]->m_fields.push_back(outname[j - nfields]);
160  }
161  else
162  {
163  FieldDef[n]->m_fields.push_back(
164  m_f->m_fielddef[0]->m_fields[j]);
165  }
166 
167  m_f->m_exp[s * (nfields + addfields) + j]->AppendFieldData(
168  FieldDef[n], FieldData[n]);
169  }
170  }
171  }
172 
173  m_f->m_fielddef = FieldDef;
174  m_f->m_data = FieldData;
175 }
176 }
177 }
pair< ModuleType, string > ModuleKey
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:46
virtual void Process()=0
STL namespace.
FieldSharedPtr m_f
Field object.
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:698
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
ModuleFactory & GetModuleFactory()
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215