Nektar++
ProcessHalfModeToFourier.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessHalfModeToFourier.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: Take a FourierHalfMode expansion and correct so it can be
32// understood as a two mode Fourier Expansion
33//
34////////////////////////////////////////////////////////////////////////////////
35
36#include <iostream>
37#include <string>
38using namespace std;
39
42
44
45namespace Nektar::FieldUtils
46{
47
50 ModuleKey(eProcessModule, "halfmodetofourier"),
52 "modify a FourierHalfMode into a Fourier expansion so it can be "
53 "processed as a 3D field.");
54
56 : ProcessModule(f)
57{
59 m_config["realmodetoimag"] =
60 ConfigOption(false, "NotSet", "Take fields as sin mode");
61}
62
64{
65}
66
67void ProcessHalfModeToFourier::v_Process([[maybe_unused]] po::variables_map &vm)
68{
69 set<int> sinmode;
70 if (m_config["realmodetoimag"].as<string>().compare("NotSet"))
71 {
72 ParseUtils::GenerateVariableSet(m_config["realmodetoimag"].as<string>(),
73 m_f->m_variables, sinmode);
74 }
75 // modify field definition
76 for (int i = 0; i < m_f->m_data.size(); ++i)
77 {
78 ASSERTL0((m_f->m_fielddef[i]->m_basis[2] ==
80 m_f->m_fielddef[i]->m_basis[2] ==
82 "This module is only for fourier Half modes");
83
84 // change HomogeneousID
85 m_f->m_fielddef[i]->m_homogeneousZIDs.resize(2);
86 m_f->m_fielddef[i]->m_homogeneousZIDs[0] = 2;
87 m_f->m_fielddef[i]->m_homogeneousZIDs[1] = 3;
88 // change expansion
89 int nelemts = m_f->m_fielddef[i]->m_elementIDs.size();
90 if (m_f->m_fielddef[i]->m_uniOrder)
91 {
92 m_f->m_fielddef[i]->m_numModes[2] = 4;
93 }
94 else
95 {
96 for (int e = 0; e < nelemts; ++e)
97 {
98 m_f->m_fielddef[i]->m_numModes[3 * e + 2] = 4;
99 }
100 }
101
102 // Set third expansion to Fourier
103 m_f->m_fielddef[i]->m_basis[2] = LibUtilities::eFourier;
104
105 // copy data
106 int ndata = m_f->m_data[i].size();
107 vector<NekDouble> data = m_f->m_data[i];
108 m_f->m_data[i].resize(2 * ndata);
109 int offset = 0, count = 0;
110 for (size_t n = 0; n < m_f->m_fielddef[i]->m_fields.size(); ++n)
111 {
113 m_f->m_fielddef[i]->m_shapeType,
114 m_f->m_fielddef[i]->m_numModes[0],
115 m_f->m_fielddef[i]->m_numModes[1]);
116 for (int e = 0; e < nelemts; ++e)
117 {
118 if (!m_f->m_fielddef[i]->m_uniOrder)
119 {
120
122 m_f->m_fielddef[i]->m_shapeType,
123 m_f->m_fielddef[i]->m_numModes[3 * e],
124 m_f->m_fielddef[i]->m_numModes[3 * e + 1]);
125 }
126 if (sinmode.count(n))
127 {
128 for (int l = 0; l < datalen; ++l)
129 {
130 m_f->m_data[i][count++] = 0.;
131 }
132 for (int l = 0; l < datalen; ++l)
133 {
134 m_f->m_data[i][count++] = -data[offset + l];
135 }
136 }
137 else
138 {
139 for (int l = 0; l < datalen; ++l)
140 {
141 m_f->m_data[i][count++] = data[offset + l];
142 }
143 for (int l = 0; l < datalen; ++l)
144 {
145 m_f->m_data[i][count++] = 0.;
146 }
147 }
148 offset += datalen;
149 }
150 }
151 }
152}
153} // 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 bool GenerateVariableSet(const std::string &str, const std::vector< std::string > &variables, std::set< int > &out)
Generate a set of variable locations.
Definition: ParseUtils.cpp:168
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
int GetNumberOfCoefficients(ShapeType shape, std::vector< unsigned int > &modes, int offset=0)
Definition: ShapeType.hpp:305
@ eFourierHalfModeIm
Fourier Modified expansions with just the imaginary part of the first mode .
Definition: BasisType.h:68
@ eFourierHalfModeRe
Fourier Modified expansions with just the real part of the first mode .
Definition: BasisType.h:66
@ eFourier
Fourier Expansion .
Definition: BasisType.h:55
Represents a command-line configuration option.
Definition: Module.h:129