Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProcessHomogeneousStretch.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessHomogeneousStretch.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: Stretch homogeneous direction by an integer factor.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <iostream>
37 #include <string>
38 using namespace std;
39 
41 
44 
45 namespace Nektar
46 {
47 namespace FieldUtils
48 {
49 
50 ModuleKey ProcessHomogeneousStretch::className =
52  ModuleKey(eProcessModule, "homstretch"),
53  ProcessHomogeneousStretch::create,
54  "Stretches homogeneous direction of a 3DH1D expansion, requires factor "
55  "to be "
56  "defined. The number of modes in the final expansion can be defined "
57  "using"
58  " --output-points-hom-z.");
59 
60 ProcessHomogeneousStretch::ProcessHomogeneousStretch(FieldSharedPtr f)
61  : ProcessModule(f)
62 {
63  m_config["factor"] = ConfigOption(false, "NotSet", "stretch factor");
64 }
65 
67 {
68 }
69 
70 void ProcessHomogeneousStretch::Process(po::variables_map &vm)
71 {
72  if (m_f->m_verbose)
73  {
74  if (m_f->m_comm->GetRank() == 0)
75  {
76  cout << "ProcessHomogeneousStretch: Stretching expansion..."
77  << endl;
78  }
79  }
80 
81  if ((m_f->m_fielddef[0]->m_numHomogeneousDir) != 1)
82  {
83  ASSERTL0(false,
84  "ProcessHomogeneousStretch only works for Homogeneous1D.");
85  }
86 
87  ASSERTL0(m_config["factor"].m_beenSet,
88  "Missing parameter factor for ProcessHomogeneousStretch");
89 
90  int factor = m_config["factor"].as<int>();
91  int nfields = m_f->m_fielddef[0]->m_fields.size();
92  int nplanes = m_f->m_exp[0]->GetHomogeneousBasis()->GetZ().num_elements();
93 
94  ASSERTL0(factor > 1, "Parameter factor must be greater than 1.");
95 
96  int nstrips;
97  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
98 
99  for (int s = 0; s < nstrips; ++s)
100  {
101  for (int i = 0; i < nfields; ++i)
102  {
103  int n = s * nfields + i;
104  int ncoeffs = m_f->m_exp[n]->GetPlane(0)->GetNcoeffs();
105  // Loop planes backwards so we can copy in place
106  for (int p = nplanes - 1; p > 1; --p)
107  {
108  int newP = 2 * factor * (p / 2) + p % 2;
109  if (newP < nplanes)
110  {
111  Vmath::Vcopy(
112  ncoeffs, m_f->m_exp[n]->GetPlane(p)->GetCoeffs(), 1,
113  m_f->m_exp[n]->GetPlane(newP)->UpdateCoeffs(), 1);
114  }
115  Vmath::Zero(ncoeffs, m_f->m_exp[n]->GetPlane(p)->UpdateCoeffs(),
116  1);
117  }
118 
119  m_f->m_exp[n]->BwdTrans(m_f->m_exp[n]->GetCoeffs(),
120  m_f->m_exp[n]->UpdatePhys());
121  }
122  }
123  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
124  m_f->m_exp[0]->GetFieldDefinitions();
125  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
126 
127  for (int s = 0; s < nstrips; ++s)
128  {
129  for (int j = 0; j < nfields; ++j)
130  {
131  for (int i = 0; i < FieldDef.size() / nstrips; ++i)
132  {
133  int n = s * FieldDef.size() / nstrips + i;
134 
135  FieldDef[n]->m_fields.push_back(
136  m_f->m_fielddef[0]->m_fields[j]);
137  m_f->m_exp[s * nfields + j]->AppendFieldData(FieldDef[n],
138  FieldData[n]);
139  }
140  }
141  }
142  for (int i = 0; i < FieldDef.size(); ++i)
143  {
144  FieldDef[i]->m_homogeneousLengths[0] =
145  factor * m_f->m_fielddef[i]->m_homogeneousLengths[0];
146  }
147  m_f->m_fielddef = FieldDef;
148  m_f->m_data = FieldData;
149 }
150 }
151 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
Represents a command-line configuration option.
STL namespace.
pair< ModuleType, string > ModuleKey
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:740
virtual void Process(po::variables_map &vm)
Write mesh to output file.
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:373
Abstract base class for processing modules.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1061
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215