CEPS  24.01
Cardiac ElectroPhysiology Simulator
FluxAnodeCathodeSolver.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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
34 
36  : LaplacianSolver(problem)
37 {
39 }
40 
42 {
43 }
44 
45 void
47 {
50 
51  auto bcFE = m_fe->getBoundaryFiniteElements();
52  CepsReal anodeMeas = getDomainMeasure(bcFE,pb->getAnodeAttributes ());
53  CepsReal cathodeMeas = getDomainMeasure(bcFE,pb->getCathodeAttributes());
54 
55 
56  bcManager->getNeumannBCs()->at("ANODE" )->setScaleFactor(1./anodeMeas );
57  bcManager->getNeumannBCs()->at("CATHODE")->setScaleFactor(1./cathodeMeas);
58 }
59 
60 void
62 {
64 
65  FEMassIntegrator integrator(m_fe);
66  CepsReal uMean = integrator.integrate(m_solution, m_fe->getMassMatrix()); // integrate 1.M.u
67  CEPS_SAYS(" Solution vector with mean " << uMean);
68 }
69 
72 {
73  return ceps::runtimeCast<FluxAnodeCathodeProblem*>(m_problem);
74 }
75 
76 void
78 {
79  if (getFluxAnodeCathodeProblem()->requireNullMean())
80  {
82 
83  LhsAssembler* opAsb = ceps::getNew<LhsAssembler>(m_fe);
84 
85  // Set diffusion coefficient for the single unknown and for the lagrangian
86  opAsb->setKForUnknown(m_problem->getUnknown(0),getFluxAnodeCathodeProblem()->getDiffusionTensor());
87  opAsb->addLagrangian(m_problem->getUnknown(1));
88 
89  m_opAsb = opAsb;
90  }
91  else
92  {
93  FEDivKGradAssembler* opAsb = ceps::getNew<FEDivKGradAssembler>(m_fe);
94 
95  // Set diffusion coefficient for the single unknown and for the lagrangian
96  opAsb->setKForUnknown(m_problem->getUnknown(0),getFluxAnodeCathodeProblem()->getDiffusionTensor());
97  m_opAsb = opAsb;
98  }
99 
100  m_opAsb->setMatrix(m_lhs.get());
101 
102  m_bcAsb = ceps::getNew<FEDivKGradBCAssembler>(m_fe);
103  m_bcAsb->setMatrix(m_lhs.get());
104  m_bcAsb->setVector(m_rhs.get());
105 }
106 
#define CEPS_SAYS(message)
Writes a message in the debug log and in the terminal (stdio).
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
CepsReal getDomainMeasure(const CepsVector< FEBase * > &cells, const CepsSet< CepsAttribute > &attributes, CepsBool onlyOfThisProc)
Compute the measure of a set of a cells.
void setMatrix(DistributedMatrix *mat)
The matrix to assemble.
void setVector(DistributedVector *vec)
The vector to assemble.
InputParameters * getParameters() const
Text parameters.
Unknown * getUnknown(const CepsString &label) const
Get an unknown by its name.
BoundaryConditionManager * getBoundaryConditionManager() const
Get boundary condition manager.
DMatPtr m_lhs
Left hand side of the system.
DVecPtr m_rhs
Right hand side of the system.
AbstractAssembler * m_bcAsb
Assembler for Robin and Neumann BCs.
AbstractAssembler * m_opAsb
Assembler for the operator matrix.
AbstractPdeProblem * m_problem
Link to PDE to solve.
void solve() override
Solves the whole PDE in time.
DHVecPtr m_solution
The actual vector with the solution.
Boundary condition to manage Dirichlet, Neumann and Robin conditions.
Manager * getNeumannBCs() const
Get the manager for Neumann conditions of dim.
Assembles the stiffness matrix for a given k-simplexes geometry.
void setKForUnknown(Unknown *u, CepsMathScalar k)
Register the diffusion coefficient (x,t,...) for given unknown.
Computes the integral of a quantity on the whole domain or subdomains, using a FE matrix.
CepsReal integrate(DHVecPtr u, DMatPtr mat=nullptr)
Returns the value of the integral by computing ones dot Mu.
A class that adds a 0 mean constraint to an already existing assembler.
FiniteElements * m_fe
Geometry and reference FE.
CepsVector< FEBase * > & getBoundaryFiniteElements()
Get vector containing all finite elements of the maximum valid dim.
DMatPtr getMassMatrix() const
Pointer on mass matrix.
Poisson equation with Neumann 1 on anode, -1 on cathode. Neumann 0 elsewhere. Functional tensorial co...
FluxAnodeCathodeProblem * getFluxAnodeCathodeProblem() const
Returns a pointer to the linked problem with appropriate type.
FluxAnodeCathodeSolver(FluxAnodeCathodeProblem *problem)
Constructor.
void setupWithParameters(InputParameters *params) override
Set attributes from input file. Parameters are passed as arguments in case one wants to use other par...
~FluxAnodeCathodeSolver() override
Destructor.
void initializeAssemblers() override
Creates the LHS assembler.
void solve() override
Solve and postprocess.
CepsSet< CepsAttribute > & getAnodeAttributes() const
Anode attributes.
CepsSet< CepsAttribute > & getCathodeAttributes() const
Cathode attributes.
Reads and stores simulation configuration.
Solve laplacian equation with backward Euler, constant time step, using Finite Elements.