CEPS  24.01
Cardiac ElectroPhysiology Simulator
AbstractDiscretization.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
30 #pragma once
31 
32 #include "common/CepsCommon.hpp"
33 #include "geometry/Geometry.hpp"
37 
38 
39 class AbstractPdeProblem;
40 
51  CepsMap<
55 
61 {
62  public:
65 
68 
72 
74  ~AbstractDiscretization() override;
75 
78  getProblem() const;
79 
82  getDofsFactory() const;
83 
86  getDistributedDofs() const;
87 
89  const DegreeOfFreedomTree&
90  getDegreeOfFreedomTree() const;
91 
95 
99 
103 
105  Geometry*
106  getGeometry() const;
107 
110  virtual void
112 
113  // ------------------------------------------------------
114  // Methods related to degrees of freedom management
115 
117  DVecPtr
118  newDofVector() const;
119 
121  DHVecPtr
122  newDofHaloVector() const;
123 
125  DMatPtr
126  newDofMatrix() const;
127 
130  getDof(CepsGlobalIndex globalDofId);
131 
133  const DegreeOfFreedom*
134  getDof(CepsGlobalIndex globalDofId) const;
135 
138  CepsBool
139  isDofSpatial(CepsGlobalIndex globalDofId) const;
140 
142  virtual CepsIndex
143  getDofSpatialId(const DegreeOfFreedom* dof) const = 0;
144 
147  getOwnedDofs() const;
148 
151  getHaloDofs() const;
152 
161  virtual void
163  const CepsUnknownIndex& uId,
164  DVecPtr vec,
165  CepsVector<CepsIndex>& indices,
166  CepsVector<CepsReal>& values,
167  CepsBool sendToMaster = false,
168  CepsBool returnGeomIndices = false
169 
170  ) = 0;
171 
173  void
176  DHVecPtr v,
177  CepsReal t=0.
178  ) const;
179 
181  void
182  findClosestDof(const CepsReal3D& x, Unknown* u, CepsDofGlobalIndex& dofId, CepsProcId& owner);
183 
185  CepsReal
186  getZeroDValue(Unknown* u, DHVecPtr sol);
187 
188  // ========== METRICS ================================================================
189 
191  virtual CepsReal
193  DHVecPtr u,
194  DHVecPtr v,
195  CepsBool boundary = false,
196  const CepsSet<CepsAttribute>& attrs = {},
197  const CepsVector<Unknown*>& unknowns = {}
198  ) = 0;
199 
201  CepsReal
202  l1Norm(
203  DHVecPtr v,
204  CepsBool boundary = false,
205  const CepsSet<CepsAttribute>& attrs = {},
206  const CepsVector<Unknown*>& unknowns = {}
207  );
208 
210  CepsReal
211  l2Norm(
212  DHVecPtr v,
213  CepsBool boundary = false,
214  const CepsSet<CepsAttribute>& attrs = {},
215  const CepsVector<Unknown*>& unknowns = {}
216  );
217 
219  virtual CepsReal
221  DHVecPtr v,
222  CepsBool boundary = false,
223  const CepsSet<CepsAttribute>& attrs = {},
224  const CepsVector<Unknown*>& unknowns = {}
225  ) = 0;
226 
227 
228  protected:
229 
232 
234  void
235  buildDofs();
236 
238  virtual void
240 
242  void
244 
246  void
248 
251  virtual void
253 
255  virtual void
257 
259  void
261 
271  void
273  const CepsUnknownIndex& uId,
274  DVecPtr vec,
275  CepsVector<CepsIndex>& indices,
276  CepsVector<CepsReal>& values,
277  CepsBool sendToMaster,
278  CepsBool returnGeomIndices,
279  std::function<CepsBool(DegreeOfFreedom*)>& selector
280  );
281 
282 
283 
288 
289  // Dofs
290 
301 
304 
309 
310 };
CepsArray< CepsMap< CepsGlobalIndex, CepsVector< DegreeOfFreedom * > >, CepsLocationFlagSize > DegreeOfFreedomTree
Data structure that classifies all the degrees of freedom.
CepsLocationFlag
DataLocation: an enum that will be used by various elements of the code (pde, readers,...
Definition: CepsEnums.hpp:108
constexpr CepsUInt CepsLocationFlagSize
Size of enum CepsLocationFlag.
Definition: CepsEnums.hpp:114
CepsIndex CepsUnknownIndex
For unknowns.
Definition: CepsTypes.hpp:217
std::array< _Type, _N > CepsArray
C++ arrays.
Definition: CepsTypes.hpp:159
std::map< _Key, _Tp, _Compare, _Alloc > CepsMap
C++ map.
Definition: CepsTypes.hpp:196
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
CepsGlobalIndex CepsDofGlobalIndex
Indices of degrees of freedom.
Definition: CepsTypes.hpp:226
CepsIndex CepsGlobalIndex
Many uses. Has to be signed for PETSc.
Definition: CepsTypes.hpp:218
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
CepsUInt CepsProcId
For CPU indices.
Definition: CepsTypes.hpp:123
CepsArray3< CepsReal > CepsReal3D
Three real scalars, used like this for compatibility in polynomials.
Definition: CepsTypes.hpp:178
CepsInt CepsIndex
Index rowid etc.
Definition: CepsTypes.hpp:111
std::shared_ptr< DistributedHaloVector > DHVecPtr
Typedef for pointer on Distributed Halo CepsVector.
std::shared_ptr< DistributedMatrix > DMatPtr
Short typedef for pointer on dist matrix.
std::shared_ptr< DistributedVector > DVecPtr
Short typedef for pointer on distributed vector.
Abstract Class for all numerical method (FE, FD, FV etc)
DHVecPtr newDofHaloVector() const
Get a new vector from the factory, with halo data.
const DegreeOfFreedomTree & getDegreeOfFreedomTree() const
The sorted degrees of freedom.
void extractValuesForUnknownInternal(const CepsUnknownIndex &uId, DVecPtr vec, CepsVector< CepsIndex > &indices, CepsVector< CepsReal > &values, CepsBool sendToMaster, CepsBool returnGeomIndices, std::function< CepsBool(DegreeOfFreedom *)> &selector)
Slicing method that extracts the data corresponding to a specific unknown.
virtual void extractValuesForUnknown(const CepsUnknownIndex &uId, DVecPtr vec, CepsVector< CepsIndex > &indices, CepsVector< CepsReal > &values, CepsBool sendToMaster=false, CepsBool returnGeomIndices=false)=0
Slicing method that extracts the data corresponding to a specific unknown.
DistributedInfos< DegreeOfFreedom * > * getDistributedDofs() const
Get the stored Degree Of Freedom repartition.
AbstractPdeProblem * m_problem
[not owned] Pointer on the pde problem
const CepsMap< CepsUnknownIndex, CepsVector< DegreeOfFreedom * > > & getDegreesOfFreedomForUnknown()
Dofs sorted by unknown.
AbstractPdeProblem * getProblem() const
Return link to pde problem.
DistributedFactory * m_dofsFactory
[owned] The factory that builds vectors and matrices
CepsBool isDofSpatial(CepsGlobalIndex globalDofId) const
Check if the Unknow is a spatial one (typically CepsLocationFlag != ZeroD)
virtual CepsReal dotProduct(DHVecPtr u, DHVecPtr v, CepsBool boundary=false, const CepsSet< CepsAttribute > &attrs={}, const CepsVector< Unknown * > &unknowns={})=0
Returns the dot product of two vectors of degrees of freedom.
void createDofsForZeroDUnknowns()
Adds one dof for each zeroD unknown, must be called after all other dofs are distributed.
void evaluateFunctionOnDofs(ceps::Function< CepsReal(CepsStandardArgs)> *func, DHVecPtr v, CepsReal t=0.) const
Fills vector v with values of function func at owned and halo dofs and time t.
CepsMap< CepsDofGlobalIndex, CepsSet< CepsDofGlobalIndex > > m_extraAdjacencyToRecv
A map to correct the missing adjacency that can occur in rare occasions in 3D.
~AbstractDiscretization() override
Destructor.
CepsBool m_dofsBuilt
Tells if the class has setup all the dofs.
AbstractDiscretization()=delete
Deleted default constructor.
CepsReal l1Norm(DHVecPtr v, CepsBool boundary=false, const CepsSet< CepsAttribute > &attrs={}, const CepsVector< Unknown * > &unknowns={})
L1-norm of a given vector.
CepsReal getZeroDValue(Unknown *u, DHVecPtr sol)
Get the value of a 0D unknown into a solution vector.
AbstractDiscretization(const AbstractDiscretization &that)=delete
Deleted Copy constructor (objects are too big, and not really useful)
virtual void setZeroDUnknownsDofsInteractions()
Updates neighboring lists with interaction with 0D unknowns.
Geometry * getGeometry() const
Get the stored Geometry.
CepsMap< CepsUnknownIndex, CepsVector< DegreeOfFreedom * > > m_dofsForUnknown
Reverse mapping of dofs, with unknown index as key.
DVecPtr newDofVector() const
Get a new vector from the factory.
void buildDofsDistributedInfo()
Builds the degrees of freedom distribution from the dofs tree.
DistributedInfos< DegreeOfFreedom * > * m_distributedDofs
[owned] Pointer on the dofs structure
void findClosestDof(const CepsReal3D &x, Unknown *u, CepsDofGlobalIndex &dofId, CepsProcId &owner)
Set dofId to that if the closest to position x, also sets owner.
DistributedFactory * getDofsFactory() const
Get the stored DistributedFactory.
Geometry * m_geometry
[not owned] Pointer on the geometry
CepsReal l2Norm(DHVecPtr v, CepsBool boundary=false, const CepsSet< CepsAttribute > &attrs={}, const CepsVector< Unknown * > &unknowns={})
L2-norm of a given vector. Computation of dotproduct depends on the discretization.
DMatPtr newDofMatrix() const
Get a new matrix from the factory.
CepsLocationFlag m_spatialUnknownsLocation
Where unknowns are located. Must be set in child classes.
CepsVector< CepsMap< CepsDofGlobalIndex, CepsSet< CepsDofGlobalIndex > > > m_extraAdjacencyToSend
A map to correct the missing adjacency that can occur in rare occasions in 3D.
void setupDofsFactory()
Prepare the factory that will generate vectors of dofs.
AbstractDiscretization & operator=(const AbstractDiscretization &)=delete
Deleted assignment operator.
CepsVector< DegreeOfFreedom * > getHaloDofs() const
Get the degrees of freedom owned by other processes.
virtual CepsIndex getDofSpatialId(const DegreeOfFreedom *dof) const =0
Return the spatial id (CellId or NodeId) for this row number.
DegreeOfFreedomTree m_dofsTree
[owned] Pointer on the distributed degree of freedom tree
virtual void setSpatialUnknownsDofsInteractions()=0
Build dofs neighboring list for spatial unknowns. Different in FE (same element dofs) and VF,...
virtual CepsReal h1Norm(DHVecPtr v, CepsBool boundary=false, const CepsSet< CepsAttribute > &attrs={}, const CepsVector< Unknown * > &unknowns={})=0
H1-norm of a given vector. Computation depends on the discretization.
virtual void buildDofsTree()=0
Builds the degrees of freedom tree from the PDE data.
CepsVector< DegreeOfFreedom * > getOwnedDofs() const
Get the degrees of freedom owned by process.
void buildDofs()
Builds the degrees of freedom data structures from the PDE data.
virtual void registerSpatialUnkown(Unknown *u)
Changes the location of unknown u to be adapted to the discrectization for example CepsLocationFlag::...
DegreeOfFreedom * getDof(CepsGlobalIndex globalDofId)
Get the dof with given globalID, nullptr if not found.
Base class for creating PDEs to solve.
Base class for other (big) CEPS classes. All classes can get a pointer to this base class and also co...
Definition: CepsObject.hpp:40
A degree of freedom for any kind of problem The dof can be associated to a geometrical element or not...
Encapsulates all the geometrical data.
Definition: Geometry.hpp:50
A class used to defined an unknown of a PDE problem The unknown can be defined on a specific region,...
Definition: Unknown.hpp:45
Structure used to pass arguments to SAFunc (see pde directory) The flags of the SAFunc allows extract...
Definition: CepsTypes.hpp:239
function caller : abstract base, only contains an variadic operator()