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
40
42
43namespace Nektar::FieldUtils
44{
45
49 "Extracts a plane from a 3DH1D expansion, requires planeid to be "
50 "defined.");
51
53 : ProcessModule(f)
54{
55 m_config["planeid"] = ConfigOption(false, "NotSet", "plane id to extract");
56 m_config["wavespace"] =
57 ConfigOption(true, "0", "Extract plane in Fourier space");
58}
59
61{
62}
63
64void ProcessHomogeneousPlane::v_Process(po::variables_map &vm)
65{
66 m_f->SetUpExp(vm);
67
68 ASSERTL0(m_f->m_numHomogeneousDir == 1,
69 "ProcessHomogeneousPlane only works for Homogeneous1D.");
70
71 m_f->m_numHomogeneousDir = 0;
72
73 // Skip in case of empty partition
74 if (m_f->m_exp[0]->GetNumElmts() == 0)
75 {
76 return;
77 }
78
79 ASSERTL0(m_config["planeid"].m_beenSet,
80 "Missing parameter planeid for ProcessHomogeneousPlane");
81
82 int planeid = m_config["planeid"].as<int>();
83 int nfields = m_f->m_variables.size();
84
85 int nstrips;
86 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
87
88 // Look for correct plane (because of parallel case)
89 int plane = -1;
90 for (int i = 0; i < m_f->m_exp[0]->GetZIDs().size(); ++i)
91 {
92 if (m_f->m_exp[0]->GetZIDs()[i] == planeid)
93 {
94 plane = i;
95 }
96 }
97
98 if (plane != -1)
99 {
100 for (int s = 0; s < nstrips; ++s)
101 {
102 for (int i = 0; i < nfields; ++i)
103 {
104 int n = s * nfields + i;
105 m_f->m_exp[n] = m_f->m_exp[n]->GetPlane(plane);
106
107 if (m_config["wavespace"].as<bool>())
108 {
109 m_f->m_exp[n]->BwdTrans(m_f->m_exp[n]->GetCoeffs(),
110 m_f->m_exp[n]->UpdatePhys());
111 }
112 else
113 {
114 m_f->m_exp[n]->FwdTransLocalElmt(
115 m_f->m_exp[n]->GetPhys(),
116 m_f->m_exp[n]->UpdateCoeffs());
117 }
118 }
119 }
120
121 // Create new SessionReader with RowComm. This is done because when
122 // using a module requiring m_f->m_declareExpansionAsContField and
123 // outputting to vtu/dat, a new ContField with equispaced points
124 // is created. Since creating ContFields require communication, we have
125 // to change m_session->m_comm to prevent mpi from hanging
126 // (RowComm will only be used when creating the new expansion,
127 // since in other places we use m_f->m_comm)
128 std::vector<std::string> files;
129 for (int i = 0; i < m_f->m_inputfiles["xml"].size(); ++i)
130 {
131 files.push_back(m_f->m_inputfiles["xml"][i]);
132 }
133 for (int j = 0; j < m_f->m_inputfiles["xml.gz"].size(); ++j)
134 {
135 files.push_back(m_f->m_inputfiles["xml.gz"][j]);
136 }
137 vector<string> cmdArgs;
138 cmdArgs.push_back("FieldConvert");
139 if (m_f->m_verbose)
140 {
141 cmdArgs.push_back("--verbose");
142 }
143 int argc = cmdArgs.size();
144 const char **argv = new const char *[argc];
145 for (int i = 0; i < argc; ++i)
146 {
147 argv[i] = cmdArgs[i].c_str();
148 }
150 argc, (char **)argv, files, m_f->m_comm->GetRowComm());
151 m_f->m_session->InitSession();
152 }
153 else
154 {
155 // Create empty expansion
156 for (int s = 0; s < nstrips; ++s)
157 {
158 for (int i = 0; i < nfields; ++i)
159 {
160 int n = s * nfields + i;
161 m_f->m_exp[n] =
163 }
164 }
165 }
166}
167} // namespace Nektar::FieldUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272
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:301
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
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:990
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
Represents a command-line configuration option.
Definition: Module.h:129