Nektar++
ContField.h
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: ContField.h
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: Field definition in tow-dimensions
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_LIBS_MULTIREGIONS_CONTFIELD2D_H
36#define NEKTAR_LIBS_MULTIREGIONS_CONTFIELD2D_H
37
47
49{
50
51/// This class is the abstraction of a global continuous two-
52/// dimensional spectral/hp element expansion which approximates the
53/// solution of a set of partial differential equations.
54class ContField : public DisContField
55{
56public:
57 /// The default constructor.
59
60 /// This constructor sets up global continuous field based on an
61 /// input mesh and boundary conditions.
65 const std::string &variable = "DefaultVar",
66 const bool DeclareCoeffPhysArrays = true,
67 const bool CheckIfSingularSystem = false,
70
71 /// Construct a global continuous field with solution type based on
72 /// another field but using a separate input mesh and boundary
73 /// conditions.
75 const ContField &In, const SpatialDomains::MeshGraphSharedPtr &graph2D,
76 const std::string &variable, const bool DeclareCoeffPhysArrays = true,
77 const bool CheckIfSingularSystem = false);
78
79 /// The copy constructor.
81 bool DeclareCoeffPhysArrays = true);
82
83 /// Copy constructor.
86 const ExpList &In);
87
88 /// The default destructor.
90
91 /// Assembles the global coefficients \f$\boldsymbol{\hat{u}}_g\f$
92 /// from the local coefficients \f$\boldsymbol{\hat{u}}_l\f$.
93 inline void Assemble();
94
95 /// Assembles the global coefficients \f$\boldsymbol{\hat{u}}_g\f$
96 /// from the local coefficients \f$\boldsymbol{\hat{u}}_l\f$.
97 inline void Assemble(const Array<OneD, const NekDouble> &inarray,
98 Array<OneD, NekDouble> &outarray) const;
99
100 /// Returns the map from local to global level.
101 inline const AssemblyMapCGSharedPtr &GetLocalToGlobalMap() const;
102
103 /// Solves the two-dimensional Laplace equation, subject to the
104 /// boundary conditions specified.
106 const Array<OneD, const NekDouble> &inarray,
107 Array<OneD, NekDouble> &outarray,
109 const Array<OneD, Array<OneD, NekDouble>> &variablecoeffs =
111 NekDouble time = 0.0);
112
113 /// Compute the eigenvalues of the linear advection operator.
115 const NekDouble ax, const NekDouble ay, Array<OneD, NekDouble> &Real,
118
119 inline int GetGlobalMatrixNnz(const GlobalMatrixKey &gkey);
120
121 /// Solves the linear system specified by the key \a key.
123 const GlobalLinSysKey &key, const Array<OneD, const NekDouble> &rhs,
126
128 {
129 // initialize if required
130 if (!m_GJPData)
131 {
134 }
135
136 return m_GJPData;
137 }
138
140 const GJPStabilisationSharedPtr &GJPData)
141 {
142 m_GJPData = GJPData;
143 }
144
145protected:
146 // private:
147 /// (A shared pointer to) the object which contains all the
148 /// required information for the transformation from local to
149 /// global degrees of freedom.
151
152 /// (A shared pointer to) a list which collects all the global
153 /// matrices being assembled, such that they should be constructed
154 /// only once.
156
157 /// A manager which collects all the global
158 /// linear systems being assembled, such that they should be
159 /// constructed only once.
162
163 /// Data for Gradient Jump Penalisation (GJP) stabilisaiton
165
166 /// Returns the global matrix specified by \a mkey.
168 GetGlobalMatrix(const GlobalMatrixKey &mkey);
169
170 /// Returns the linear system specified by the key \a mkey.
172 GetGlobalLinSys(const GlobalLinSysKey &mkey);
173
175 GenGlobalLinSys(const GlobalLinSysKey &mkey);
176
177 /// Impose the Dirichlet Boundary Conditions on outarray
179 Array<OneD, NekDouble> &outarray) override;
180
182 const Array<OneD, NekDouble> coeffs) override;
183
185 const int nreg, const Array<OneD, NekDouble> coeffs) override;
186
187 /// Gathers the global coefficients \f$\boldsymbol{\hat{u}}_g\f$
188 /// from the local coefficients \f$\boldsymbol{\hat{u}}_l\f$.
190 const Array<OneD, const NekDouble> &inarray,
191 Array<OneD, NekDouble> &outarray, bool useComm) override;
192
193 MULTI_REGIONS_EXPORT void v_LocalToGlobal(bool useComm) override;
194
195 /// Scatters from the global coefficients
196 /// \f$\boldsymbol{\hat{u}}_g\f$ to the local coefficients
197 /// \f$\boldsymbol{\hat{u}}_l\f$.
199 const Array<OneD, const NekDouble> &inarray,
200 Array<OneD, NekDouble> &outarray) override;
201
202 MULTI_REGIONS_EXPORT void v_GlobalToLocal(void) override;
203
204 /// Template method virtual forwarder for FwdTrans().
206 const Array<OneD, const NekDouble> &inarray,
207 Array<OneD, NekDouble> &outarray) override;
208
209 /// Template method virtual forwarded for SmoothField().
211 Array<OneD, NekDouble> &field) override;
212
213 /// Template method virtual forwarder for MultiplyByInvMassMatrix().
215 const Array<OneD, const NekDouble> &inarray,
216 Array<OneD, NekDouble> &outarray) override;
217
218 /// Solves the two-dimensional Helmholtz equation, subject to the
219 /// boundary conditions specified.
222 Array<OneD, NekDouble> &outarray,
224 const StdRegions::VarCoeffMap &varcoeff,
225 const MultiRegions::VarFactorsMap &varfactors,
226 const Array<OneD, const NekDouble> &dirForcing,
227 const bool PhysSpaceForcing) override;
228
229 // Solve the linear advection problem assuming that m_coeffs
230 // vector contains an intial estimate for solution
233 const Array<OneD, const NekDouble> &inarray,
234 Array<OneD, NekDouble> &outarray,
236 const StdRegions::VarCoeffMap &varcoeff,
237 const MultiRegions::VarFactorsMap &varfactors,
238 const Array<OneD, const NekDouble> &dirForcing,
239 const bool PhysSpaceForcing) override;
240
241 // Solve the linear advection problem assuming that m_coeff
242 // vector contains an intial estimate for solution
244 const Array<OneD, Array<OneD, NekDouble>> &velocity,
245 const Array<OneD, const NekDouble> &inarray,
246 Array<OneD, NekDouble> &outarray, const NekDouble lambda,
247 const Array<OneD, const NekDouble> &dirForcing =
248 NullNekDouble1DArray) override;
249
250 /// Returns the boundary conditions expansion.
252 v_GetBndCondExpansions() override;
253
254 /// Template method virtual forwarder for GetBndConditions().
257 v_GetBndConditions() override;
259
260 // Get manager pool count; intended for unit tests
261 MULTI_REGIONS_EXPORT int v_GetPoolCount(std::string) override;
262
263 // Remove GlobalLinSys, StaticCond Blocks and LocalMatrix Blocks
265 bool) override;
266};
267
268typedef std::shared_ptr<ContField> ContFieldSharedPtr;
269
270/**
271 * This operation is evaluated as:
272 * \f{tabbing}
273 * \hspace{1cm} \= Do \= $e=$ $1, N_{\mathrm{el}}$ \\
274 * > > Do \= $i=$ $0,N_m^e-1$ \\
275 * > > > $\boldsymbol{\hat{u}}_g[\mbox{map}[e][i]] =
276 * \boldsymbol{\hat{u}}_g[\mbox{map}[e][i]]+\mbox{sign}[e][i] \cdot
277 * \boldsymbol{\hat{u}}^{e}[i]$\\
278 * > > continue\\
279 * > continue
280 * \f}
281 * where \a map\f$[e][i]\f$ is the mapping array and \a
282 * sign\f$[e][i]\f$ is an array of similar dimensions ensuring the
283 * correct modal connectivity between the different elements (both
284 * these arrays are contained in the data member #m_locToGloMap). This
285 * operation is equivalent to the gather operation
286 * \f$\boldsymbol{\hat{u}}_g=\mathcal{A}^{T}\boldsymbol{\hat{u}}_l\f$,
287 * where \f$\mathcal{A}\f$ is the
288 * \f$N_{\mathrm{eof}}\times N_{\mathrm{dof}}\f$ permutation matrix.
289 *
290 * @note The array #m_coeffs should be filled with the local
291 * coefficients \f$\boldsymbol{\hat{u}}_l\f$ and that the
292 * resulting global coefficients \f$\boldsymbol{\hat{u}}_g\f$
293 * will be stored in #m_coeffs.
294 */
296{
297 m_locToGloMap->Assemble(m_coeffs, m_coeffs);
298}
299
300/**
301 * This operation is evaluated as:
302 * \f{tabbing}
303 * \hspace{1cm} \= Do \= $e=$ $1, N_{\mathrm{el}}$ \\
304 * > > Do \= $i=$ $0,N_m^e-1$ \\
305 * > > > $\boldsymbol{\hat{u}}_g[\mbox{map}[e][i]] =
306 * \boldsymbol{\hat{u}}_g[\mbox{map}[e][i]]+\mbox{sign}[e][i] \cdot
307 * \boldsymbol{\hat{u}}^{e}[i]$\\
308 * > > continue\\
309 * > continue
310 * \f}
311 * where \a map\f$[e][i]\f$ is the mapping array and \a
312 * sign\f$[e][i]\f$ is an array of similar dimensions ensuring the
313 * correct modal connectivity between the different elements (both
314 * these arrays are contained in the data member #m_locToGloMap). This
315 * operation is equivalent to the gather operation
316 * \f$\boldsymbol{\hat{u}}_g=\mathcal{A}^{T}\boldsymbol{\hat{u}}_l\f$,
317 * where \f$\mathcal{A}\f$ is the
318 * \f$N_{\mathrm{eof}}\times N_{\mathrm{dof}}\f$ permutation matrix.
319 *
320 * @param inarray An array of size \f$N_\mathrm{eof}\f$
321 * containing the local degrees of freedom
322 * \f$\boldsymbol{x}_l\f$.
323 * @param outarray The resulting global degrees of freedom
324 * \f$\boldsymbol{x}_g\f$ will be stored in this
325 * array of size \f$N_\mathrm{dof}\f$.
326 */
328 Array<OneD, NekDouble> &outarray) const
329{
330 m_locToGloMap->Assemble(inarray, outarray);
331}
332
334{
335 return m_locToGloMap;
336}
337
340{
341 return m_bndCondExpansions;
342}
343
346{
347 return m_bndConditions;
348}
349
351{
353 "To use method must have a AssemblyMap "
354 "attached to key");
355
356 auto matrixIter = m_globalMat->find(gkey);
357
358 if (matrixIter == m_globalMat->end())
359 {
360 return 0;
361 }
362 else
363 {
364 return matrixIter->second->GetNumNonZeroEntries();
365 }
366
367 return 0;
368}
369
370} // namespace Nektar::MultiRegions
371
372#endif // MULTIERGIONS_CONTFIELD2D_H
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
#define MULTI_REGIONS_EXPORT
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
This class is the abstraction of a global continuous two- dimensional spectral/hp element expansion w...
Definition: ContField.h:55
~ContField() override
The default destructor.
Definition: ContField.cpp:225
void v_FillBndCondFromField(const Array< OneD, NekDouble > coeffs) override
Definition: ContField.cpp:616
LibUtilities::NekManager< GlobalLinSysKey, GlobalLinSys > m_globalLinSysManager
A manager which collects all the global linear systems being assembled, such that they should be cons...
Definition: ContField.h:161
void LaplaceSolve(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray, const Array< OneD, Array< OneD, NekDouble > > &variablecoeffs=NullNekDoubleArrayOfArray, NekDouble time=0.0)
Solves the two-dimensional Laplace equation, subject to the boundary conditions specified.
Definition: ContField.cpp:336
GlobalLinSysSharedPtr GenGlobalLinSys(const GlobalLinSysKey &mkey)
Definition: ContField.cpp:548
GlobalLinSysKey v_HelmSolve(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdRegions::ConstFactorMap &factors, const StdRegions::VarCoeffMap &varcoeff, const MultiRegions::VarFactorsMap &varfactors, const Array< OneD, const NekDouble > &dirForcing, const bool PhysSpaceForcing) override
Solves the two-dimensional Helmholtz equation, subject to the boundary conditions specified.
Definition: ContField.cpp:772
const GJPStabilisationSharedPtr GetGJPForcing()
Definition: ContField.h:127
AssemblyMapCGSharedPtr m_locToGloMap
(A shared pointer to) the object which contains all the required information for the transformation f...
Definition: ContField.h:150
void v_FwdTrans(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Template method virtual forwarder for FwdTrans().
Definition: ContField.cpp:242
int v_GetPoolCount(std::string) override
Definition: ContField.cpp:1025
void v_SmoothField(Array< OneD, NekDouble > &field) override
Template method virtual forwarded for SmoothField().
Definition: ContField.cpp:259
const Array< OneD, const SpatialDomains ::BoundaryConditionShPtr > & v_GetBndConditions() override
Template method virtual forwarder for GetBndConditions().
Definition: ContField.h:345
void v_ClearGlobalLinSysManager(void) override
Definition: ContField.cpp:1017
void v_GlobalToLocal(void) override
Definition: ContField.cpp:713
const AssemblyMapCGSharedPtr & GetLocalToGlobalMap() const
Returns the map from local to global level.
Definition: ContField.h:333
void v_UnsetGlobalLinSys(GlobalLinSysKey, bool) override
Definition: ContField.cpp:1035
int GetGlobalMatrixNnz(const GlobalMatrixKey &gkey)
Definition: ContField.h:350
void v_LocalToGlobal(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, bool useComm) override
Gathers the global coefficients from the local coefficients .
Definition: ContField.cpp:739
void SetGJPForcing(const GJPStabilisationSharedPtr &GJPData)
Definition: ContField.h:139
GlobalMatrixMapShPtr m_globalMat
(A shared pointer to) a list which collects all the global matrices being assembled,...
Definition: ContField.h:155
void v_LinearAdvectionReactionSolve(const Array< OneD, Array< OneD, NekDouble > > &velocity, const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const NekDouble lambda, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray) override
Definition: ContField.cpp:992
GlobalLinSysSharedPtr GetGlobalLinSys(const GlobalLinSysKey &mkey)
Returns the linear system specified by the key mkey.
Definition: ContField.cpp:543
void v_ImposeDirichletConditions(Array< OneD, NekDouble > &outarray) override
Impose the Dirichlet Boundary Conditions on outarray.
Definition: ContField.cpp:556
const Array< OneD, const MultiRegions::ExpListSharedPtr > & v_GetBndCondExpansions() override
Returns the boundary conditions expansion.
Definition: ContField.h:339
void v_MultiplyByInvMassMatrix(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Template method virtual forwarder for MultiplyByInvMassMatrix().
Definition: ContField.cpp:277
GlobalMatrixSharedPtr GetGlobalMatrix(const GlobalMatrixKey &mkey)
Returns the global matrix specified by mkey.
Definition: ContField.cpp:513
ContField()
The default constructor.
Definition: ContField.cpp:87
void LinearAdvectionEigs(const NekDouble ax, const NekDouble ay, Array< OneD, NekDouble > &Real, Array< OneD, NekDouble > &Imag, Array< OneD, NekDouble > &Evecs=NullNekDouble1DArray)
Compute the eigenvalues of the linear advection operator.
Definition: ContField.cpp:414
GlobalLinSysKey v_LinearAdvectionDiffusionReactionSolve(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdRegions::ConstFactorMap &factors, const StdRegions::VarCoeffMap &varcoeff, const MultiRegions::VarFactorsMap &varfactors, const Array< OneD, const NekDouble > &dirForcing, const bool PhysSpaceForcing) override
Definition: ContField.cpp:883
void GlobalSolve(const GlobalLinSysKey &key, const Array< OneD, const NekDouble > &rhs, Array< OneD, NekDouble > &inout, const Array< OneD, const NekDouble > &dirForcing=NullNekDouble1DArray)
Solves the linear system specified by the key key.
Definition: ContField.cpp:486
void Assemble()
Assembles the global coefficients from the local coefficients .
Definition: ContField.h:295
GJPStabilisationSharedPtr m_GJPData
Data for Gradient Jump Penalisation (GJP) stabilisaiton.
Definition: ContField.h:164
This class is the abstractio n of a global discontinuous two- dimensional spectral/hp element expansi...
Definition: DisContField.h:56
Array< OneD, SpatialDomains::BoundaryConditionShPtr > m_bndConditions
An array which contains the information about the boundary condition structure definition on the diff...
Definition: DisContField.h:143
Array< OneD, MultiRegions::ExpListSharedPtr > m_bndCondExpansions
An object which contains the discretised boundary conditions.
Definition: DisContField.h:156
Base class for all multi-elemental spectral/hp expansions.
Definition: ExpList.h:99
Array< OneD, NekDouble > m_coeffs
Concatenation of all local expansion coefficients.
Definition: ExpList.h:1083
std::shared_ptr< ExpList > GetSharedThisPtr()
Returns a shared pointer to the current object.
Definition: ExpList.h:956
Describes a matrix with ordering defined by a local to global map.
bool LocToGloMapIsDefined() const
Returns true if a local to global map is defined.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< AssemblyMapCG > AssemblyMapCGSharedPtr
Definition: AssemblyMapCG.h:50
std::shared_ptr< GlobalLinSys > GlobalLinSysSharedPtr
Pointer to a GlobalLinSys object.
Definition: GlobalLinSys.h:51
std::shared_ptr< GlobalMatrix > GlobalMatrixSharedPtr
Shared pointer to a GlobalMatrix object.
Definition: GlobalMatrix.h:84
std::shared_ptr< GlobalMatrixMap > GlobalMatrixMapShPtr
Shared pointer to a global matrix map.
Definition: GlobalMatrix.h:88
std::map< StdRegions::ConstFactorType, Array< OneD, NekDouble > > VarFactorsMap
std::shared_ptr< GJPStabilisation > GJPStabilisationSharedPtr
std::shared_ptr< ContField > ContFieldSharedPtr
Definition: ContField.h:268
std::shared_ptr< BoundaryConditionBase > BoundaryConditionShPtr
Definition: Conditions.h:212
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
std::map< ConstFactorType, NekDouble > ConstFactorMap
Definition: StdRegions.hpp:430
std::map< StdRegions::VarCoeffType, VarCoeffEntry > VarCoeffMap
Definition: StdRegions.hpp:375
StdRegions::ConstFactorMap factors
static Array< OneD, Array< OneD, NekDouble > > NullNekDoubleArrayOfArray
static Array< OneD, NekDouble > NullNekDouble1DArray
double NekDouble