Nektar++
ProcessMRF.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessMRF.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: Add transformed coordinates to field
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36#include <string>
37using namespace std;
38
39#include "ProcessMRF.h"
42
43namespace Nektar::FieldUtils
44{
47 "Add transformed coordinates to output file.");
48
50{
51 m_config["vectors"] = ConfigOption(false, "NotSet", "Select variables");
52}
53
55{
56}
57
58void ProcessMRF::v_Process(po::variables_map &vm)
59{
60 m_f->SetUpExp(vm);
62
63 // Skip in case of empty partition
64 if (m_f->m_exp[0]->GetNumElmts() == 0)
65 {
66 return;
67 }
68
69 // Determine dimensions
70 m_spacedim = m_f->m_graph->GetMeshDimension() + m_f->m_numHomogeneousDir;
71
72 // transform coordinates
73 int nfields = m_f->m_variables.size();
74 int addfields = m_spacedim;
75 int npoints = m_f->m_exp[0]->GetNpoints();
76 string fieldNames[3] = {"xCoord", "yCoord", "zCoord"};
77 for (int i = 0; i < addfields; ++i)
78 {
79 m_f->m_variables.push_back(fieldNames[i]);
80 }
81 m_f->m_exp.resize(nfields + addfields);
82 vector<Array<OneD, NekDouble>> coords(m_spacedim);
83 for (int i = 0; i < m_spacedim; ++i)
84 {
85 coords[i] = Array<OneD, NekDouble>(npoints);
86 }
87 if (m_spacedim == 1)
88 {
89 m_f->m_exp[0]->GetCoords(coords[0]);
90 }
91 else if (m_spacedim == 2)
92 {
93 m_f->m_exp[0]->GetCoords(coords[0], coords[1]);
94 }
95 else
96 {
97 m_f->m_exp[0]->GetCoords(coords[0], coords[1], coords[2]);
98 }
99 for (int i = 0; i < m_spacedim; ++i)
100 {
101 Vmath::Sadd(npoints, -m_pivot[i], coords[i], 1, coords[i], 1);
102 }
103 TransformVector(coords);
104 for (int i = 0; i < m_spacedim; ++i)
105 {
106 Vmath::Sadd(npoints, m_pivot[i] + m_origin[i], coords[i], 1, coords[i],
107 1);
108 }
109 // Add new information to m_f
110 for (int i = 0; i < addfields; ++i)
111 {
112 m_f->m_exp[nfields + i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
113 Vmath::Vcopy(npoints, coords[i], 1,
114 m_f->m_exp[nfields + i]->UpdatePhys(), 1);
115 m_f->m_exp[nfields + i]->FwdTransLocalElmt(
116 coords[i], m_f->m_exp[nfields + i]->UpdateCoeffs());
117 }
118
119 // tranform vectors
120 vector<Array<OneD, NekDouble>> data(m_spacedim);
121 vector<int> vars;
122 if (m_config["vectors"].as<string>().compare("NotSet"))
123 {
124 ParseUtils::GenerateVariableVector(m_config["vectors"].as<string>(),
125 m_f->m_variables, vars);
126 }
127 ASSERTL0(vars.size() % m_spacedim == 0,
128 "The number of vector variables is not divisible by the space "
129 "dimension.");
130 for (int i = 0; i < vars.size() / m_spacedim; ++i)
131 {
132 for (int d = 0; d < m_spacedim; ++d)
133 {
134 data[d] = m_f->m_exp[vars[m_spacedim * i + d]]->UpdatePhys();
135 }
136 TransformVector(data);
137 for (int d = 0; d < m_spacedim; ++d)
138 {
139 int nv = vars[m_spacedim * i + d];
140 m_f->m_exp[nv]->FwdTransLocalElmt(data[d],
141 m_f->m_exp[nv]->UpdateCoeffs());
142 }
143 }
144}
145
147{
148 vector<string> strOrigin = {"X", "Y", "Z"};
149 vector<string> strTheta = {"Theta_x", "Theta_y", "Theta_z"};
150 vector<string> strPivot = {"X0", "Y0", "Z0"};
151 m_origin.resize(3, 0.);
152 m_pivot.resize(3, 0.);
153 for (size_t i = 0; i < strOrigin.size(); ++i)
154 {
155 if (m_f->m_fieldMetaDataMap.count(strOrigin[i]))
156 {
157 m_origin[i] = stod(m_f->m_fieldMetaDataMap[strOrigin[i]]);
158 }
159 }
160 for (size_t i = 0; i < strTheta.size(); ++i)
161 {
162 if (m_f->m_fieldMetaDataMap.count(strTheta[i]))
163 {
164 if (m_theta.size() < 3)
165 {
166 m_theta.resize(3, 0.);
167 }
168 m_theta[i] = stod(m_f->m_fieldMetaDataMap[strTheta[i]]);
169 }
170 }
171 for (size_t i = 0; i < strPivot.size(); ++i)
172 {
173 if (m_f->m_fieldMetaDataMap.count(strPivot[i]))
174 {
175 m_pivot[i] = stod(m_f->m_fieldMetaDataMap[strPivot[i]]);
176 }
177 }
178}
179
181{
182 if (m_theta.size() < 3)
183 {
184 return;
185 }
186 if (data.size() < m_spacedim)
187 {
189 "data size is small than the space dimension.");
190 }
191
192 int npoint = data[0].size();
193 int dim = 2;
194 NekDouble sz = sin(m_theta[2]), cz = cos(m_theta[2]);
196 for (int i = 0; i < dim; ++i)
197 {
198 tmp[i] = Array<OneD, NekDouble>(npoint);
199 Vmath::Vcopy(npoint, data[i], 1, tmp[i], 1);
200 }
201 Vmath::Svtsvtp(npoint, cz, tmp[0], 1, -sz, tmp[1], 1, data[0], 1);
202 Vmath::Svtsvtp(npoint, sz, tmp[0], 1, cz, tmp[1], 1, data[1], 1);
203}
204} // namespace Nektar::FieldUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
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 TransformVector(std::vector< Array< OneD, NekDouble > > &data)
Definition: ProcessMRF.cpp:180
std::vector< NekDouble > m_theta
Definition: ProcessMRF.h:85
std::vector< NekDouble > m_origin
Definition: ProcessMRF.h:84
static ModuleKey className
Definition: ProcessMRF.h:56
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Definition: ProcessMRF.h:52
ProcessMRF(FieldSharedPtr f)
Definition: ProcessMRF.cpp:49
void v_Process(po::variables_map &vm) override
Write mesh to output file.
Definition: ProcessMRF.cpp:58
std::vector< NekDouble > m_pivot
Definition: ProcessMRF.h:86
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.
static bool GenerateVariableVector(const std::string &str, const std::vector< std::string > &variables, std::vector< int > &out)
Definition: ParseUtils.cpp:185
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:1026
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
std::vector< double > d(NPUPPER *NPUPPER)
double NekDouble
void Svtsvtp(int n, const T alpha, const T *x, int incx, const T beta, const T *y, int incy, T *z, int incz)
Svtsvtp (scalar times vector plus scalar times vector):
Definition: Vmath.hpp:473
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition: Vmath.hpp:194
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825
STL namespace.
Represents a command-line configuration option.
Definition: Module.h:129