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  m_f->SetUpExp(vm);
72 
73  ASSERTL0(m_f->m_numHomogeneousDir == 1,
74  "ProcessHomogeneousPlane only works for Homogeneous1D.");
75 
76  m_f->m_numHomogeneousDir = 0;
77 
78  // Skip in case of empty partition
79  if (m_f->m_exp[0]->GetNumElmts() == 0)
80  {
81  return;
82  }
83 
84  ASSERTL0(m_config["planeid"].m_beenSet,
85  "Missing parameter planeid for ProcessHomogeneousPlane");
86 
87  int planeid = m_config["planeid"].as<int>();
88  int nfields = m_f->m_variables.size();
89 
90  int nstrips;
91  m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
92 
93  // Look for correct plane (because of parallel case)
94  int plane = -1;
95  for (int i = 0; i < m_f->m_exp[0]->GetZIDs().size(); ++i)
96  {
97  if (m_f->m_exp[0]->GetZIDs()[i] == planeid)
98  {
99  plane = i;
100  }
101  }
102 
103  if (plane != -1)
104  {
105  for (int s = 0; s < nstrips; ++s)
106  {
107  for (int i = 0; i < nfields; ++i)
108  {
109  int n = s * nfields + i;
110  m_f->m_exp[n] = m_f->m_exp[n]->GetPlane(plane);
111 
112  if (m_config["wavespace"].as<bool>())
113  {
114  m_f->m_exp[n]->BwdTrans(m_f->m_exp[n]->GetCoeffs(),
115  m_f->m_exp[n]->UpdatePhys());
116  }
117  else
118  {
119  m_f->m_exp[n]->FwdTrans_IterPerExp(m_f->m_exp[n]->GetPhys(),
120  m_f->m_exp[n]->UpdateCoeffs());
121  }
122  }
123  }
124 
125  // Create new SessionReader with RowComm. This is done because when
126  // using a module requiring m_f->m_declareExpansionAsContField and
127  // outputting to vtu/dat, a new ContField with equispaced points
128  // is created. Since creating ContFields require communication, we have
129  // to change m_session->m_comm to prevent mpi from hanging
130  // (RowComm will only be used when creating the new expansion,
131  // since in other places we use m_f->m_comm)
132  std::vector<std::string> files;
133  for (int i = 0; i < m_f->m_inputfiles["xml"].size(); ++i)
134  {
135  files.push_back(m_f->m_inputfiles["xml"][i]);
136  }
137  for (int j = 0; j < m_f->m_inputfiles["xml.gz"].size(); ++j)
138  {
139  files.push_back(m_f->m_inputfiles["xml.gz"][j]);
140  }
141  vector<string> cmdArgs;
142  cmdArgs.push_back("FieldConvert");
143  if (m_f->m_verbose)
144  {
145  cmdArgs.push_back("--verbose");
146  }
147  int argc = cmdArgs.size();
148  const char **argv = new const char *[argc];
149  for (int i = 0; i < argc; ++i)
150  {
151  argv[i] = cmdArgs[i].c_str();
152  }
154  argc, (char **)argv, files, m_f->m_comm->GetRowComm());
155  m_f->m_session->InitSession();
156  }
157  else
158  {
159  // Create empty expansion
160  for (int s = 0; s < nstrips; ++s)
161  {
162  for (int i = 0; i < nfields; ++i)
163  {
164  int n = s * nfields + i;
165  m_f->m_exp[n] =
167  }
168  }
169  }
170 }
171 }
172 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
FieldSharedPtr m_f
Field object.
Definition: Module.h:230
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:233
virtual void Process(po::variables_map &vm)
Write mesh to output file.
Abstract base class for processing modules.
Definition: Module.h:265
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
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:989
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:290
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
Represents a command-line configuration option.
Definition: Module.h:134