Nektar++
Loading...
Searching...
No Matches
SteadyADR.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: SteadyADR.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: SteadyADR problem solve routines
32//
33///////////////////////////////////////////////////////////////////////////////
34
36
38#include <SolverCore/Core/SessionFunction.h>
39#include <SolverCore/GlobalLinSysOps/LinearSolvers/LinearSolverOp.hpp>
40#include <SolverCore/GlobalLinSysOps/LinearSystems/HelmSolve/HelmSolveOp.hpp>
41#include <SolverCore/GlobalLinSysOps/LinearSystems/LinearADRSolve/LinearADRSolveOp.hpp>
42#include <SolverCore/GlobalLinSysOps/LinearSystems/LinearSystemOp.hpp>
43#include <SolverCore/GlobalLinSysOps/LinearSystems/PoissonSolve/PoissonSolveOp.hpp>
44#include <SolverCore/PreconOps/PreconOp.hpp>
45
46namespace Nektar
47{
48using namespace MultiRegions;
49
50std::string SteadyADR::className1 =
53std::string SteadyADR::className2 =
56std::string SteadyADR::className3 =
59
62 : EquationSystem(pSession, pGraph), m_epsilon(1.0), m_lambda(0.0)
63{
65 "The SteadyADR is only implemented for "
66 "projectionType Galerkin");
67}
68
69/**
70 * @brief Initialisation object for the SteadyADR problem.
71 */
72void SteadyADR::v_InitObject(bool declareExpansionLists)
73{
74 // Call to the initialisation object of EquationSystem
75 EquationSystem::v_InitObject(declareExpansionLists);
76
77 /// Load parameters from session
79
80 /// Create Fields for solution m_phys, m_coeff and others
82
83 // Set advection velocity
85
86 // Set up diffusion Coeff.
88
89 // Create and initialise all operators
91}
92
93/**
94 * @brief Solves SteadyADR problem.
95 */
97{
98 // Evaluate forcing terms. The first forcing assigns into the workspace;
99 // subsequent forcings append.
100 for (unsigned int i = 0; i < m_forcing.size(); ++i)
101 {
102 m_forcing[i]->SetAppend(i > 0);
103 m_forcing[i]->Apply(m_fce, m_fce, m_time);
104 }
105
106 // Zero the forcing if there is none.
107 if (m_forcing.empty())
108 {
109 m_math.zero(m_fce);
110 }
111
112 // Apply method for solving the SteadyADR problem
113 m_linearSystemOp->Apply(m_fce, m_coeff[0]);
114 m_bwdTransOp->Apply(m_coeff[0], m_phys[0]);
115}
116
118{
120 AddSummaryItem(s, "Equations", "Advection-Diffusion-Reaction");
121
122 std::stringstream ss;
123 ss << R"(
124 _ _ _ _
125| \ | | | | | | _ _
126| \| | ___| | _| |_ __ _ _ __ _| |_ _| |_
127| . ` |/ _ \ |/ / __/ _` | '__|_ _|_ _|
128| |\ | __/ <| || (_| | | |_| |_|
129\_| \_/\___|_|\_\\__\__,_|_|
130 _ _ _
131 | | (_) | |
132 _ __ ___ __| | ___ ___ _ __ _ _ __ ___ __| |
133| '__/ _ \/ _` |/ _ \/ __| |/ _` | '_ \ / _ \/ _` |
134| | | __/ (_| | __/\__ \ | (_| | | | | __/ (_| |
135|_| \___|\__,_|\___||___/_|\__, |_| |_|\___|\__,_|
136 __/ |
137 |___/
138)";
139 AddSummaryItem(s, "Redesign disclaimer", ss.str());
140}
141
143{
144 // Load lambda parameter for SteadyADR and Helmholtz problems.
145 m_session->LoadParameter("lambda", m_lambda, 0.0);
146
147 // Get diffusion parameters.
148 const auto nDiffCoeff = m_coordim * (m_coordim + 1) / 2;
149 m_diffCoeff.resize(nDiffCoeff);
150
151 m_session->LoadParameter("epsilon", m_epsilon, 1.0);
152 if (m_coordim == 1)
153 {
154 m_session->LoadParameter("D00", m_diffCoeff[0], 1.0);
155 }
156 else if (m_coordim == 2)
157 {
158 m_session->LoadParameter("D00", m_diffCoeff[0], 1.0);
159 m_session->LoadParameter("D01", m_diffCoeff[1], 0.0);
160 m_session->LoadParameter("D11", m_diffCoeff[2], 1.0);
161 }
162 else if (m_coordim == 3)
164 m_session->LoadParameter("D00", m_diffCoeff[0], 1.0);
165 m_session->LoadParameter("D01", m_diffCoeff[1], 0.0);
166 m_session->LoadParameter("D11", m_diffCoeff[2], 1.0);
167 m_session->LoadParameter("D02", m_diffCoeff[3], 0.0);
168 m_session->LoadParameter("D12", m_diffCoeff[4], 0.0);
169 m_session->LoadParameter("D22", m_diffCoeff[5], 1.0);
170 }
171}
172
173/*
174 * Create and initialise Fields.
175 *
176 * m_fce is FieldState::Phys workspace for the forcing term
177 */
179{
180 // Initialise solution "m_phys" via EquationSystem routine
181 EquationSystem::v_InitialiseFields();
182
184 m_expansionLists[0]);
186 "m_fce", bAtr_phys, m_variables[0], m_npointsZ);
187}
188
189/*
190 * @brief Sets the Advection Veclocity
191 */
193{
194 if (m_session->GetSolverInfo("EQTYPE") == "SteadyADR")
195 {
196 // Read advection velocity from session.
197 if (m_session->DefinesFunction("AdvectionVelocity"))
198 {
199 auto bAtr_phys =
201 m_expansionLists[0]);
203 "advVel", bAtr_phys, m_coordim, m_npointsZ);
204
205 // Reads the Session File Velocity defined as function.
206 std::vector<std::string> vel = {"Vx", "Vy", "Vz"};
207 vel.resize(m_coordim);
208 SessionFunction advectionVelocity(m_session, m_expansionLists[0],
209 vel, "AdvectionVelocity");
210 advectionVelocity.Evaluate(m_advectionVel, m_time);
211 }
212 else
213 {
214 NEKERROR(ErrorUtil::efatal, "Function 'AdvectionVelocity' was "
215 "not defined in session file.")
216 }
217 }
218}
219
220/**
221 * @brief Set the diffusion Coeff.
222 * the diff. coeff., diffCoeff_{ij} := \epslion * D_{ij}
223 * where,
224 * \epslion is scalar part
225 * D_{ij} is a 2D tensor for enforcing anisotropy
226 * Note, it is assumed that, diffCoeff_{ij} = diffCoeff_{ji}
227 *
228 * Let, Vec be a Vector<double> storing a flatten \diffCoeff_{ij}, then
229 * Case 1: For 1D
230 * Vec[0] = D_{00}
231 * Case 2: For 2D
232 * Vec[0] = D_{00}
233 * Vec[1] = D_{01}
234 * Vec[2] = D_{11}
235 * Case 3: For 3D
236 * Vec[0] = D_{00}
237 * Vec[1] = D_{01}
238 * Vec[2] = D_{11}
239 * Vec[3] = D_{02}
240 * Vec[4] = D_{12}
241 * Vec[5] = D_{22}
242 */
244{
245 // Optional physical tensor, in the same D00,D01,D11,D02,D12,D22 order
246 // as the constant parameters. epsilon scales every tensor component.
247 if (m_session->DefinesFunction("DiffusionCoefficient"))
248 {
249 std::vector<std::string> names = {"D00", "D01", "D11",
250 "D02", "D12", "D22"};
251 names.resize(m_coordim * (m_coordim + 1) / 2);
252 auto bAtr_phys =
254 m_expansionLists[0]);
256 "DiffusionCoefficient", bAtr_phys, names.size(), m_npointsZ);
257 m_varDiffCoeffFunction = std::make_shared<SessionFunction>(
258 m_session, m_expansionLists[0], names, "DiffusionCoefficient");
261 }
262 else
263 {
264 if (m_coordim == 1)
265 {
266 // Multiply by Scalar Part
268 }
269 else if (m_coordim == 2)
270 {
271 // Multiply by Scalar Part
275 }
276 else if (m_coordim == 3)
278 // Multiply by Scalar Part
285 }
286 }
287}
288
289/*
290 * Create and initialise all operators for this solver
291 */
293{
295 BwdTransOp<double>::Create(m_expansionLists[0], m_variables[0]);
296
297 // Create LinearADRSolve, preconditioner, and linear system operators
298 m_preconOp = PreconOp<double>::Create(m_expansionLists[0],
299 m_session->GetVariables());
300 m_linearSolverOp = LinearSolverOp<double>::Create(
301 m_expansionLists[0], m_session->GetVariables());
302
303 if (m_session->GetSolverInfo("EQTYPE") == "SteadyADR")
304 {
305 auto linearADRSolveOp = LinearADRSolveOp<double>::Create(
306 m_expansionLists[0], m_session->GetVariables());
307 linearADRSolveOp->SetLinearSolver(m_linearSolverOp);
308 linearADRSolveOp->SetLambda(m_lambda);
310 {
311 linearADRSolveOp->SetVarDiffCoeff(m_varDiffCoeff);
312 }
313 else
314 {
315 linearADRSolveOp->SetDiffCoeff(m_diffCoeff);
316 }
317 linearADRSolveOp->SetAdvVel(m_advectionVel);
318 linearADRSolveOp->SetPrecon(m_preconOp);
319 linearADRSolveOp->UpdatePrecon();
320 m_linearSystemOp = linearADRSolveOp;
321 }
322 else if (m_session->GetSolverInfo("EQTYPE") == "Helmholtz")
323 {
324 auto helmSolveOp = HelmSolveOp<double>::Create(
325 m_expansionLists[0], m_session->GetVariables());
326 helmSolveOp->SetLambda(m_lambda);
327 helmSolveOp->SetLinearSolver(m_linearSolverOp);
329 {
330 helmSolveOp->SetVarDiffCoeff(m_varDiffCoeff);
331 }
332 else
333 {
334 helmSolveOp->SetDiffCoeff(m_diffCoeff);
335 }
336 helmSolveOp->SetPrecon(m_preconOp);
337 helmSolveOp->UpdatePrecon();
338 m_linearSystemOp = helmSolveOp;
339 }
340 else if (m_session->GetSolverInfo("EQTYPE") == "Poisson")
341 {
342 auto poissonSolveOp = PoissonSolveOp<double>::Create(
343 m_expansionLists[0], m_session->GetVariables());
344 poissonSolveOp->SetLinearSolver(m_linearSolverOp);
346 {
347 poissonSolveOp->SetVarDiffCoeff(m_varDiffCoeff);
348 }
349 else
350 {
351 poissonSolveOp->SetDiffCoeff(m_diffCoeff);
352 }
353 poissonSolveOp->SetPrecon(m_preconOp);
354 poissonSolveOp->UpdatePrecon();
355 m_linearSystemOp = poissonSolveOp;
356 }
357
358 // Load forcing terms, if defined in the session file.
359 m_forcing = Forcing::Load(m_session, m_expansionLists[0], m_variables[0]);
360}
361
362} // namespace Nektar
Public interface of the backward-transform (BwdTrans) element operator, which maps a field from coeff...
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
A Field represents expansion data to be operated on.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static std::shared_ptr< BwdTransOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a backward-transform operator through the operator and block-operator factories.
A base class for describing how to solve specific equations.
NekDouble m_time
Current time of simulation.
int m_npointsZ
number of points in Z direction (if homogeneous)
virtual SOLVER_UTILS_EXPORT void v_InitObject(bool DeclareFeld=true)
Initialisation object for EquationSystem.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
enum MultiRegions::ProjectionType m_projectionType
Type of projection; e.g continuous or discontinuous.
virtual SOLVER_UTILS_EXPORT void v_GenerateSummary(SummaryList &l)
Virtual function for generating summary information.
static SOLVER_UTILS_EXPORT std::vector< ForcingSharedPtr > Load(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields=0)
Definition Forcing.cpp:77
std::shared_ptr< LinearSolverOp< double > > m_linearSolverOp
Definition SteadyADR.h:96
std::vector< ForcingSharedPtr > m_forcing
Definition SteadyADR.h:98
static std::string className1
Name of class.
Definition SteadyADR.h:76
static std::string className3
Definition SteadyADR.h:78
LibUtilities::Field< double, FieldState::Phys > m_varDiffCoeff
Definition SteadyADR.h:86
static EquationSystemSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Creates an instance of this class.
Definition SteadyADR.h:65
void v_InitialiseOperators() override
void SetDiffusionCoeff()
Set the diffusion Coeff. the diff. coeff., diffCoeff_{ij} := \epslion * D_{ij} where,...
void v_GenerateSummary(SummaryList &s) override
Virtual function for generating summary information.
static std::string className2
Definition SteadyADR.h:77
SteadyADR(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Definition SteadyADR.cpp:60
SessionFunctionSharedPtr m_varDiffCoeffFunction
Definition SteadyADR.h:87
std::vector< double > m_diffCoeff
Definition SteadyADR.h:84
void LoadSessionParameters()
std::shared_ptr< BwdTransOp< double > > m_bwdTransOp
Definition SteadyADR.h:94
void v_InitObject(bool declareExpansionLists=true) override
Initialisation object for the SteadyADR problem.
Definition SteadyADR.cpp:72
LibUtilities::Field< double, FieldState::Phys > m_advectionVel
Definition SteadyADR.h:91
std::shared_ptr< PreconOp< double > > m_preconOp
Definition SteadyADR.h:97
LibUtilities::Field< double, FieldState::Phys > m_fce
Definition SteadyADR.h:90
std::shared_ptr< LinearSystemOp< double > > m_linearSystemOp
Definition SteadyADR.h:95
void v_InitialiseFields() override
void v_DoSolve() override
Solves SteadyADR problem.
Definition SteadyADR.cpp:96
std::shared_ptr< SessionReader > SessionReaderSharedPtr
template std::vector< BlockAttributes< FieldState::Phys > > GetBlockAttributes< double, FieldState::Phys >(const MultiRegions::ExpListSharedPtr explist, const std::vector< unsigned int > &interleave_widths)
std::vector< std::pair< std::string, std::string > > SummaryList
Definition Misc.h:46
EquationSystemFactory & GetEquationSystemFactory()
void AddSummaryItem(SummaryList &l, const std::string &name, const std::string &value)
Adds a summary item to the summary info list.
Definition Misc.cpp:46
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition MeshGraph.h:287