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>
37using namespace std;
38
39#include <boost/core/ignore_unused.hpp>
40
42
44
45namespace Nektar
46{
47namespace FieldUtils
48{
49
53 "Extracts a plane from a 3DH1D expansion, requires planeid to be "
54 "defined.");
55
57 : ProcessModule(f)
58{
59 m_config["planeid"] = ConfigOption(false, "NotSet", "plane id to extract");
60 m_config["wavespace"] =
61 ConfigOption(true, "0", "Extract plane in Fourier space");
62}
63
65{
66}
67
68void ProcessHomogeneousPlane::v_Process(po::variables_map &vm)
69{
70 m_f->SetUpExp(vm);
71
72 ASSERTL0(m_f->m_numHomogeneousDir == 1,
73 "ProcessHomogeneousPlane only works for Homogeneous1D.");
74
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().size(); ++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]->FwdTransLocalElmt(
119 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} // namespace FieldUtils
172} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:263
virtual void v_Process(po::variables_map &vm) override
Write mesh to output file.
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
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
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:991
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
Represents a command-line configuration option.
Definition: Module.h:131