Nektar++
UnsteadyReactionDiffusion.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File UnsteadyReactionDiffusion.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: Unsteady reaction-diffusion solve routines
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <iostream>
36 #include <iomanip>
37 
38 #include <boost/core/ignore_unused.hpp>
39 
42 
43 using namespace std;
44 
45 namespace Nektar
46 {
47 string UnsteadyReactionDiffusion::className = GetEquationSystemFactory().
48  RegisterCreatorFunction("UnsteadyReactionDiffusion",
49  UnsteadyReactionDiffusion::create);
50 
51 UnsteadyReactionDiffusion::UnsteadyReactionDiffusion(
54  : UnsteadySystem(pSession, pGraph)
55 {
56 }
57 
58 /**
59  * @brief Initialisation object for the unsteady reaction-diffusion problem.
60  */
62 {
64 
65  ASSERTL0(m_intScheme->GetIntegrationSchemeType() == LibUtilities::eIMEX,
66  "Reaction-diffusion requires an implicit-explicit timestepping"
67  " (e.g. IMEXOrder2)");
69  "Reaction-diffusion requires use of continuous Galerkin"
70  "projection.");
71 
72  // Load diffusion parameter
73  m_session->LoadParameter("epsilon", m_epsilon, 0.0);
74 
75  // Forcing terms
76  m_forcing = SolverUtils::Forcing::Load(m_session, shared_from_this(),
77  m_fields, m_fields.size());
78 
82 }
83 
84 /**
85  * @brief Unsteady diffusion problem destructor.
86  */
88 {
89 }
90 
91 /**
92  * @brief Compute the right-hand side for the unsteady reaction diffusion
93  * problem.
94  *
95  * @param inarray Given fields.
96  * @param outarray Calculated solution.
97  * @param time Time.
98  */
100  const Array<OneD, const Array<OneD, NekDouble> > &inarray,
101  Array<OneD, Array<OneD, NekDouble> > &outarray,
102  const NekDouble time)
103 {
104  // RHS should be set to zero.
105  for (int i = 0; i < outarray.size(); ++i)
106  {
107  Vmath::Zero(outarray[i].size(), &outarray[i][0], 1);
108  }
109 
110  // Add forcing terms for reaction.
111  for (auto &x : m_forcing)
112  {
113  // set up non-linear terms
114  x->Apply(m_fields, inarray, outarray, time);
115  }
116 }
117 
118 /**
119  * @brief Compute the projection for the unsteady diffusion problem.
120  *
121  * @param inarray Given fields.
122  * @param outarray Calculated solution.
123  * @param time Time.
124  */
126  const Array<OneD, const Array<OneD, NekDouble> > &inarray,
127  Array<OneD, Array<OneD, NekDouble> > &outarray,
128  const NekDouble time)
129 {
130  int i;
131  int nvariables = inarray.size();
132  SetBoundaryConditions(time);
133 
135 
136  for(i = 0; i < nvariables; ++i)
137  {
138  m_fields[i]->FwdTrans(inarray[i], coeffs);
139  m_fields[i]->BwdTrans_IterPerExp(coeffs, outarray[i]);
140  }
141 }
142 
143 /**
144  * @brief Implicit solution of the unsteady diffusion problem.
145  */
147  const Array<OneD, const Array<OneD, NekDouble> > &inarray,
148  Array<OneD, Array<OneD, NekDouble> > &outarray,
149  const NekDouble time,
150  const NekDouble lambda)
151 {
152  boost::ignore_unused(time);
153 
155 
156  int nvariables = inarray.size();
157  int npoints = m_fields[0]->GetNpoints();
158  factors[StdRegions::eFactorLambda] = 1.0 / lambda / m_epsilon;
159 
160  // We solve ( \nabla^2 - HHlambda ) Y[i] = rhs [i] inarray = input:
161  // \hat{rhs} -> output: \hat{Y} outarray = output: nabla^2 \hat{Y} where
162  // \hat = modal coeffs
163  for (int i = 0; i < nvariables; ++i)
164  {
165  // Multiply 1.0/timestep/lambda
166  Vmath::Smul(npoints, -factors[StdRegions::eFactorLambda],
167  inarray[i], 1, outarray[i], 1);
168 
169  // Solve a system of equations with Helmholtz solver
170  m_fields[i]->HelmSolve(
171  outarray[i], m_fields[i]->UpdateCoeffs(), factors);
172  m_fields[i]->BwdTrans(m_fields[i]->GetCoeffs(), outarray[i]);
173  m_fields[i]->SetPhysState(false);
174  }
175 }
176 
177 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
void DefineProjection(FuncPointerT func, ObjectPointerT obj)
void DefineOdeRhs(FuncPointerT func, ObjectPointerT obj)
void DefineImplicitSolve(FuncPointerT func, ObjectPointerT obj)
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
SOLVER_UTILS_EXPORT int GetNcoeffs()
enum MultiRegions::ProjectionType m_projectionType
Type of projection; e.g continuous or discontinuous.
SOLVER_UTILS_EXPORT void SetBoundaryConditions(NekDouble time)
Evaluates the boundary conditions at the given time.
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:128
Base class for unsteady solvers.
LibUtilities::TimeIntegrationSchemeOperators m_ode
The time integration scheme operators to use.
LibUtilities::TimeIntegrationSchemeSharedPtr m_intScheme
Wrapper to the time integration scheme.
virtual SOLVER_UTILS_EXPORT void v_InitObject()
Init object for UnsteadySystem class.
virtual void v_InitObject()
Initialisation object for the unsteady reaction-diffusion problem.
std::vector< SolverUtils::ForcingSharedPtr > m_forcing
Forcing terms.
void DoOdeRhs(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time)
Compute the right-hand side for the unsteady reaction diffusion problem.
void DoOdeProjection(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time)
Compute the projection for the unsteady diffusion problem.
void DoImplicitSolve(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, NekDouble time, NekDouble lambda)
Implicit solution of the unsteady diffusion problem.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
@ eIMEX
Implicit Explicit General Linear Method.
EquationSystemFactory & GetEquationSystemFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:314
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
double NekDouble
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.cpp:225
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:436