Nektar++
ProcessHomogeneousPlane.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessHomogeneousPlane.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: Extract a single plane of a 3DH1D field.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <string>
37 using namespace std;
38 
39 #include <boost/core/ignore_unused.hpp>
40 
42 
44 
45 namespace Nektar
46 {
47 namespace FieldUtils
48 {
49 
50 ModuleKey ProcessHomogeneousPlane::className =
52  ModuleKey(eProcessModule, "homplane"),
53  ProcessHomogeneousPlane::create,
54  "Extracts a plane from a 3DH1D expansion, requires planeid to be "
55  "defined.");
56 
57 ProcessHomogeneousPlane::ProcessHomogeneousPlane(FieldSharedPtr f)
58  : ProcessModule(f)
59 {
60  m_config["planeid"] = ConfigOption(false, "NotSet", "plane id to extract");
61  m_config["wavespace"] =
62  ConfigOption(true, "0", "Extract plane in Fourier space");
63 }
64 
66 {
67 }
68 
69 void ProcessHomogeneousPlane::Process(po::variables_map &vm)
70 {
71  boost::ignore_unused(vm);
72 
73  ASSERTL0(m_f->m_numHomogeneousDir == 1,
74  "ProcessHomogeneousPlane only works for Homogeneous1D.");
75  m_f->m_numHomogeneousDir = 0;
76 
77  // Skip in case of empty partition
78  if (m_f->m_exp[0]->GetNumElmts() == 0)
79  {
80  return;
81  }
82 
83  ASSERTL0(m_config["planeid"].m_beenSet,
84  "Missing parameter planeid for ProcessHomogeneousPlane");
85 
86  int planeid = m_config["planeid"].as<int>();
87  int nfields = m_f->m_variables.size();
88 
89  int nstrips;
90  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
91 
92  // Look for correct plane (because of parallel case)
93  int plane = -1;
94  for (int i = 0; i < m_f->m_exp[0]->GetZIDs().num_elements(); ++i)
95  {
96  if (m_f->m_exp[0]->GetZIDs()[i] == planeid)
97  {
98  plane = i;
99  }
100  }
101 
102  if (plane != -1)
103  {
104  for (int s = 0; s < nstrips; ++s)
105  {
106  for (int i = 0; i < nfields; ++i)
107  {
108  int n = s * nfields + i;
109  m_f->m_exp[n] = m_f->m_exp[n]->GetPlane(plane);
110 
111  if (m_config["wavespace"].as<bool>())
112  {
113  m_f->m_exp[n]->BwdTrans(m_f->m_exp[n]->GetCoeffs(),
114  m_f->m_exp[n]->UpdatePhys());
115  }
116  else
117  {
118  m_f->m_exp[n]->FwdTrans_IterPerExp(m_f->m_exp[n]->GetPhys(),
119  m_f->m_exp[n]->UpdateCoeffs());
120  }
121  }
122  }
123 
124  // Create new SessionReader with RowComm. This is done because when
125  // using a module requiring m_f->m_declareExpansionAsContField and
126  // outputting to vtu/dat, a new ContField with equispaced points
127  // is created. Since creating ContFields require communication, we have
128  // to change m_session->m_comm to prevent mpi from hanging
129  // (RowComm will only be used when creating the new expansion,
130  // since in other places we use m_f->m_comm)
131  std::vector<std::string> files;
132  for (int i = 0; i < m_f->m_inputfiles["xml"].size(); ++i)
133  {
134  files.push_back(m_f->m_inputfiles["xml"][i]);
135  }
136  for (int j = 0; j < m_f->m_inputfiles["xml.gz"].size(); ++j)
137  {
138  files.push_back(m_f->m_inputfiles["xml.gz"][j]);
139  }
140  vector<string> cmdArgs;
141  cmdArgs.push_back("FieldConvert");
142  if (m_f->m_verbose)
143  {
144  cmdArgs.push_back("--verbose");
145  }
146  int argc = cmdArgs.size();
147  const char **argv = new const char *[argc];
148  for (int i = 0; i < argc; ++i)
149  {
150  argv[i] = cmdArgs[i].c_str();
151  }
153  argc, (char **)argv, files, m_f->m_comm->GetRowComm());
154  m_f->m_session->InitSession();
155  }
156  else
157  {
158  // Create empty expansion
159  for (int s = 0; s < nstrips; ++s)
160  {
161  for (int i = 0; i < nfields; ++i)
162  {
163  int n = s * nfields + i;
164  m_f->m_exp[n] =
166  }
167  }
168  }
169 }
170 }
171 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
virtual void Process(po::variables_map &vm)
Write mesh to output file.
std::map< std::string, ConfigOption > m_config
List of configuration values.
Represents a command-line configuration option.
STL namespace.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
std::pair< ModuleType, std::string > ModuleKey
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
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.