CEPS  24.01
Cardiac ElectroPhysiology Simulator
FEDivKGradAssembler.cpp
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
31 
33  FEAssembler(),
34  m_cstScalars({}),
35  m_fctScalars({}),
36  m_cstTensors({}),
37  m_fctTensors({}),
38  m_isTimeDependant(false)
39 {
40 }
41 
43  FiniteElements* fe,
44  CepsBool isBoundary,
45  const CepsSet<CepsAttribute>& attributes,
46  const CepsVector<Unknown*>& unknowns
47 ):
48  FEAssembler(fe,isBoundary,attributes,unknowns),
49  m_cstScalars({}),
50  m_fctScalars({}),
51  m_cstTensors({}),
52  m_fctTensors({}),
53  m_isTimeDependant(false)
54 {
55 }
56 
58 {
59 }
60 
61 void
63 {
64  m_cstScalars[u->getIdentifier()] = k;
65 }
66 
67 void
69 {
70  m_fctScalars[u->getIdentifier()] = k;
71 
73  m_isTimeDependant = true;
74 }
75 
76 void
78 {
79  m_cstTensors[u->getIdentifier()] = k;
80 }
81 
82 void
84 {
85  m_fctTensors[u->getIdentifier()] = k;
86 
88  m_isTimeDependant = true;
89 }
90 
93 {
94  return m_isTimeDependant;
95 
96 }
97 
100  const CepsVector<Unknown*>& us,
101  FEBase* elem,
102  CepsReal3D x,
103  CepsReal t
104 ) const
105 {
107  res.reserve(us.size());
108  for (Unknown* u: us)
109  {
110  if (u->isOnLocation(CepsLocationFlag::ZeroD))
111  {
112  res.push_back({});
113  continue;
114  }
115 
116  // Loop through all 4 kinds of diffusion coefficients
117 
118  CepsUnknownIndex uId = u->getIdentifier();
119  // Constant tensors, not much to do
120  if (m_cstTensors.contains(uId))
121  res.push_back(m_cstTensors.at(uId));
122  // Constant scalars, multipliy by identity matrix
123  else if (m_cstScalars.contains(uId))
124  {
125  CepsMathDynamic2D id = Eigen::MatrixXd::Identity(3,3);
126  res.push_back(m_cstScalars.at(uId)*id);
127  }
128  else // Functions, we need to build the arguments
129  {
130  CepsStandardArgs args;
131  args.x = x;
132  args.t = t;
133  args.cellId = elem->getGeomObject()->getGlobalIndex();
134  args.attr = elem->getGeomObject()->getAttributes();
135 
136  if (m_fctTensors.contains(uId))
137  res.push_back(m_fctTensors.at(u->getIdentifier())->operator()(args));
138  // Scalar function: multiply by identity matrix
139  else if (m_fctScalars.contains(uId))
140  {
141  CepsMathDynamic2D id = Eigen::MatrixXd::Identity(3,3);
142  res.push_back(m_fctScalars.at(u->getIdentifier())->operator()(args)*id);
143  }
144  else
145  {
146  CEPS_ABORT(
147  "Tensor for unknown " << std::quoted(u->getName()) << " was not set." << std::endl <<
148  " Use setKForUnknown(...) before assembly."
149  );
150  }
151  }
152 
153  }
154 
155  return res;
156 }
157 
158 void
160  FEBase* elem,
161  CepsReal3D xQ,
162  CepsReal t,
163  const CepsMathDynamic1D& phi,
164  const CepsMathDynamic2D& gradPhi
165 )
166 {
167  // Add Gradphi*GradphiT for each spatial unknown
168  auto us = extractUnknownsFrom(m_problem->getUnknowns(), elem);
169  auto tensors = getDiffusionTensorsForUnknowns(us,elem,xQ,t);
170 
172 
173  for (CepsUInt i=0; i<us.size(); i++)
174  if (us[i]->isSpatial())
175  m_bMat[i][i] += gradPhi.transpose() * tensors[i] * gradPhi;
176 
177  return;
178 }
@ ZeroD
Data is defined once.
@ Time
Depends on time.
#define CEPS_ABORT(message)
Stops the execution with a message. If testing is enabled, only throws a runtime_error.
Eigen::Matrix< CepsScalar, Eigen::Dynamic, 1 > CepsMathDynamic1D
Dynamic 1D array, eigen format.
Definition: CepsTypes.hpp:139
CepsIndex CepsUnknownIndex
For unknowns.
Definition: CepsTypes.hpp:217
CepsScalar CepsMathScalar
Real numbers.
Definition: CepsTypes.hpp:133
std::set< _Type, _Compare, _Alloc > CepsSet
C++ set.
Definition: CepsTypes.hpp:209
Eigen::Matrix< CepsScalar, 3, 3 > CepsMathTensor
Tensor, eigen format.
Definition: CepsTypes.hpp:137
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
CepsArray3< CepsReal > CepsReal3D
Three real scalars, used like this for compatibility in polynomials.
Definition: CepsTypes.hpp:178
Eigen::Matrix< CepsScalar, Eigen::Dynamic, Eigen::Dynamic > CepsMathDynamic2D
Dynamic 2D array, eigen format.
Definition: CepsTypes.hpp:140
AbstractPdeProblem * m_problem
Direct link to problem, you may write getXXXProblem methods in derived classes that return the right ...
const CepsVector< Unknown * > & getUnknowns() const
List of unknowns of the pb.
A base class made for Finite Element assembler.
Definition: FEAssembler.hpp:42
virtual void setupBlocksOnElementForUnknowns(FEBase *elem, const CepsVector< Unknown * > &unknowns)
Get all the dofs on an element related to the given unknowns. This routine MUST be called before addB...
CepsVector< Unknown * > extractUnknownsFrom(const CepsVector< Unknown * > &us, FEBase *elem) const
From a vector of unknowns, get the ones defined on that element.
CepsVector< CepsVector< CepsMathDynamic2D > > m_bMat
Block submatrices. The first two vectors account for unknowns: if assembly on element if for unknowns...
Abstract class for finite elements.
Definition: FEBase.hpp:65
void computeBlocksOnElementAtQuadPoint(FEBase *element, CepsReal3D xQ, CepsReal t, const CepsMathDynamic1D &phi, const CepsMathDynamic2D &gradPhi) override
The function that is called to get the coefficients of the submatrix on a given finite element....
CepsMap< CepsUnknownIndex, CepsMathTensor > m_cstTensors
Diffusion coefficient.
CepsMap< CepsUnknownIndex, CepsMathScalar > m_cstScalars
Diffusion coefficient.
CepsBool m_isTimeDependant
Enforce time dependencie.
CepsBool isChangingBetweenTimes(CepsReal t1, CepsReal t2) const override
Tells if this assembler changes between the two times.
CepsMap< CepsUnknownIndex, SAFunc< CepsMathScalar > * > m_fctScalars
Diffusion coefficient.
virtual ~FEDivKGradAssembler()
Destructor.
CepsMap< CepsUnknownIndex, SAFunc< CepsMathTensor > * > m_fctTensors
Diffusion coefficient.
FEDivKGradAssembler()
Default constructor (for virtual inheritance)
CepsVector< CepsMathTensor > getDiffusionTensorsForUnknowns(const CepsVector< Unknown * > &us, FEBase *elem, CepsReal3D x, CepsReal t) const
Returns tensors with the correct k tensor type. To be defined in child classes.
void setKForUnknown(Unknown *u, CepsMathScalar k)
Register the diffusion coefficient (x,t,...) for given unknown.
Holds all finite elements corresponding to each geometrical element.
A SAFunc is a ceps::Function that uses CepsStandardArgs as argument of call operator (),...
Definition: SAFunc.hpp:100
CepsBool hasOption(CepsFunctionFlag flag)
Tells if option is activated.
A class used to defined an unknown of a PDE problem The unknown can be defined on a specific region,...
Definition: Unknown.hpp:45
CepsUnknownIndex getIdentifier() const
Get the identifier of the unknown.
Definition: Unknown.cpp:82
CepsSet< CepsAttribute > & getAttributes()
Returns the attributes of the entity.
_GeomObject * getGeomObject() const
Get the geom object.
const CepsGlobalIndex & getGlobalIndex() const
Get the index
Structure used to pass arguments to SAFunc (see pde directory) The flags of the SAFunc allows extract...
Definition: CepsTypes.hpp:239
CepsSet< CepsAttribute > attr
attributes
Definition: CepsTypes.hpp:243
CepsCellGlobalIndex cellId
cell index
Definition: CepsTypes.hpp:245
CepsReal3D x
space
Definition: CepsTypes.hpp:241
CepsReal t
time
Definition: CepsTypes.hpp:240