Nektar++
FilterMaxMinFields.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: FilterMaxMinFields.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: Maximun/minimum solution fields during time-stepping.
32//
33///////////////////////////////////////////////////////////////////////////////
34
37
38namespace Nektar::SolverUtils
39{
43
46 const std::weak_ptr<EquationSystem> &pEquation, const ParamMap &pParams)
47 : FilterFieldConvert(pSession, pEquation, pParams)
48{
49 // Load sampling frequency
50 auto it = pParams.find("SampleFrequency");
51 if (it == pParams.end())
52 {
54 }
55 else
56 {
57 LibUtilities::Equation equ(m_session->GetInterpreter(), it->second);
58 m_sampleFrequency = round(equ.Evaluate());
59 }
60
61 // Load flag for max or min
62 it = pParams.find("MaxOrMin");
63 std::string sOption = it->second.c_str();
64 if (boost::iequals(sOption, "maximum") || boost::iequals(sOption, "max"))
65 {
66 m_isMax = true;
67 }
68 else if (boost::iequals(sOption, "minimum") ||
69 boost::iequals(sOption, "min"))
70 {
71 m_isMax = false;
72 }
73 else
74 {
75 ASSERTL1(false, "MaxOrMin needs to be max or min.");
76 }
78
79 // Initialize other member vars
81}
82
84{
85}
86
89 const NekDouble &time)
90{
91 // Initialise output arrays
93
94 // Allocate storage
95 int nf;
96 m_curFieldsPhys.resize(m_variables.size());
97 m_outFieldsPhys.resize(m_variables.size());
98 for (int n = 0; n < m_variables.size(); ++n)
99 {
100 nf = (n < pFields.size()) ? n : 0;
101 m_curFieldsPhys[n] =
102 Array<OneD, NekDouble>(pFields[nf]->GetTotPoints(), 0.0);
103 m_outFieldsPhys[n] =
104 Array<OneD, NekDouble>(pFields[nf]->GetTotPoints(), 0.0);
105 }
106
107 // Check type of problem
108 std::string firstVarName = pFields[0]->GetSession()->GetVariable(0);
109 if (boost::iequals(firstVarName, "u"))
110 {
112 }
113 else if (boost::iequals(firstVarName, "rho"))
114 {
116 }
117 else
118 {
120 }
121
122 if (m_initialized)
123 {
124 for (int n = 0; n < m_variables.size(); ++n)
125 {
126 int nf = (n < pFields.size()) ? n : 0;
127 pFields[nf]->BwdTrans(m_outFields[n], m_outFieldsPhys[n]);
128 if (pFields[nf]->GetWaveSpace())
129 {
130 pFields[nf]->HomogeneousBwdTrans(pFields[nf]->GetTotPoints(),
132 m_outFieldsPhys[n]);
133 }
134 }
135 }
136}
137
138// For compressible flows, also compute max/min for extra variabless, which can
139// include (u, v, w, p, T. s, a, Mach, sensor, ArtificialVisc), but not sure
140// for variables (divVelSquare, curlVelSquare, Ducros) when Ducros sensor is
141// turned on. Now presume Ducros sensor is turned off.
142// For other cases, including incompressible flows, only compute max/min for
143// variables in pFields.
144//
145// curFieldsCoeffs is the coeffs at current time step, size=[*][m_ncoeffs]
146// m_curFieldsPhys is the phys value at current time step, size=[*][m_npoints]
147// m_outFields is the coeffs for output fld
148// m_outFieldsPhys is the phys value for output fld
149// PS. curFieldsCoeffs is not set to be a member variable since its size will
150// be increased by CompressibleFlowSystem::v_ExtraFldOutput to also include
151// coeffs for extra variables. fieldcoeffs is not used.
152
155 std::vector<Array<OneD, NekDouble>> &fieldcoeffs,
156 [[maybe_unused]] const NekDouble &time)
157{
158 for (int n = 0; n < m_variables.size(); ++n)
159 {
160 int nf = (n < pFields.size()) ? n : 0;
161 pFields[nf]->BwdTrans(fieldcoeffs[n], m_curFieldsPhys[n]);
162 if (pFields[nf]->GetWaveSpace())
163 {
164 pFields[nf]->HomogeneousBwdTrans(pFields[nf]->GetTotPoints(),
166 m_curFieldsPhys[n]);
167 }
168 }
169
170 // Get max/min for each field
171 if (!m_initialized)
172 {
173 for (int n = 0; n < m_variables.size(); ++n)
174 {
175 int length = m_outFieldsPhys[n].size();
176 Vmath::Vcopy(length, m_curFieldsPhys[n], 1, m_outFieldsPhys[n], 1);
177 }
178 m_initialized = true;
179 }
180 else
181 {
182 for (int n = 0; n < m_variables.size(); ++n)
183 {
184 int length = m_outFieldsPhys[n].size();
185 if (m_isMax)
186 {
187 // Compute max
188 for (int i = 0; i < length; ++i)
189 {
190 if (m_curFieldsPhys[n][i] > m_outFieldsPhys[n][i])
191 {
192 m_outFieldsPhys[n][i] = m_curFieldsPhys[n][i];
193 }
194 }
195 }
196 else
197 {
198 // Compute min
199 for (int i = 0; i < length; ++i)
200 {
201 if (m_curFieldsPhys[n][i] < m_outFieldsPhys[n][i])
202 {
203 m_outFieldsPhys[n][i] = m_curFieldsPhys[n][i];
204 }
205 }
206 }
207 }
208 }
209
210 // Forward transform and put into m_outFields
211 for (int n = 0; n < m_variables.size(); ++n)
212 {
213 int nf = (n < pFields.size()) ? n : 0;
214 pFields[nf]->FwdTransLocalElmt(m_outFieldsPhys[n], m_outFields[n]);
215 }
216}
217
220 &pFields,
221 [[maybe_unused]] const NekDouble &time)
222{
223 m_fieldMetaData["NumberOfFieldDumps"] = std::to_string(m_numSamples);
224}
225
227{
228 return 1.0;
229}
230
231} // namespace Nektar::SolverUtils
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
LibUtilities::FieldMetaDataMap m_fieldMetaData
std::vector< Array< OneD, NekDouble > > m_outFields
SOLVER_UTILS_EXPORT void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
LibUtilities::SessionReaderSharedPtr m_session
Definition: Filter.h:83
std::map< std::string, std::string > ParamMap
Definition: Filter.h:65
std::vector< Array< OneD, NekDouble > > m_curFieldsPhys
std::vector< Array< OneD, NekDouble > > m_outFieldsPhys
SOLVER_UTILS_EXPORT ~FilterMaxMinFields() override
void v_PrepareOutput(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
static FilterSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const std::map< std::string, std::string > &pParams)
Creates an instance of this class.
SOLVER_UTILS_EXPORT FilterMaxMinFields(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const ParamMap &pParams)
void v_Initialise(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, const NekDouble &time) override
static std::string className
Name of the class.
void v_ProcessSample(const Array< OneD, const MultiRegions::ExpListSharedPtr > &pFields, std::vector< Array< OneD, NekDouble > > &fieldcoeffs, const NekDouble &time) override
std::shared_ptr< SessionReader > SessionReaderSharedPtr
FilterFactory & GetFilterFactory()
Definition: Filter.cpp:39
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825