CEPS  24.01
Cardiac ElectroPhysiology Simulator
FluxAnodeCathodeProblem.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 
37 {
38  setProblemName("Flux Anode Cathode");
39 
41 }
42 
44 {
45 }
46 
47 void
49 {
51 
52  m_robinCoeffs = p->getString("robin coefficients", "");
53 }
54 
55 
56 void
58 {
59  // A single spatial unknown defined everywhere
60  addUnknown("u");
61 
62  if (requireNullMean())
63  {
64  // and a lagrangian unknown
65  addZeroDUnknown("lambda");
66  addUnknownInteraction("lambda", "u");
67  m_ignoreZeroDError = true; // Ignore the Lagrangian multiplier in error computation
68  }
69 }
70 
71 void
73 {
74 }
75 
76 void
78 {
79  std::stringstream ssa,ssc;
81  ssa << a << " ";
83  ssc << a << " ";
84 
85  m_boundaryConditions->add("anode NEUMANN 1.0 UNKNOWN 0 ATTRIBUTES " + ssa.str());
86  m_boundaryConditions->add("cathode NEUMANN -1.0 UNKNOWN 0 ATTRIBUTES " + ssc.str());
87 
88  for (auto definition : ceps::split(m_robinCoeffs, ","))
89  {
90  auto options = ceps::split(definition);
91  CEPS_ABORT_IF(options.size() != 2, "robin coefficient entry requires a scalar and an attribute");
92  m_boundaryConditions->add("boundary ROBIN 0.0 UNKNOWN 0 ATTRIBUTES " + options[1] + " ROBINCOEFF " + options[0]);
93  }
94 }
95 
96 void
98 {
99 }
100 
101 void
103 {
104 
105  if (ceps::isProfiling())
106  getProfiler()->start("whole","solving the whole PDE");
107 
109 
110  FluxAnodeCathodeSolver solver(this);
111 
112  solver.solve();
113 
114  if (hasAnalyticSolution())
115  m_errors = solver.getErrors();
116 
117  if (ceps::isProfiling())
118  getProfiler()->stop("whole");
119 }
120 
121 CepsBool
123 {
124  return m_robinCoeffs.empty();
125 }
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
CepsInt CepsAttribute
Used to define regions.
Definition: CepsTypes.hpp:215
CepsBool hasAnalyticSolution() const
Tells if there is an analytic or reference solution.
void setProblemName(const CepsString &name)
Set the name of the problem.
void addUnknown(const CepsString &label, CepsSet< CepsAttribute > attrs={}, CepsLocationFlag flag=CepsLocationFlag::Point, const CepsString &unit="")
Register a new unknown.
void addZeroDUnknown(CepsString label, const CepsString &unit="")
Register a new unknown, defined outside of geometry.
CepsBool m_ignoreZeroDError
Ignore 0D unknowns when computing errors.
void addUnknownInteraction(CepsString label1, CepsString label2, CepsSet< CepsAttribute > attrs={})
Register interaction between unknowns. Also sets the interaction within Unknown instances label1 and ...
InputParameters * m_parameters
Input file data.
BoundaryConditionManager * m_boundaryConditions
All BCs should be there.
void initializeEquation() override
Initializes equations (unknowns, bc, source term) and creates the spatial discretization This method ...
CepsArray2< CepsArray3< CepsReal > > m_errors
Will store Linf, L1 and L2 relative errors.
CepsArray2< CepsArray3< CepsReal > > getErrors() const
Gets the currently computed errors. First index selects absolute(0) orrelative(1) second index is L-i...
void add(const CepsString &params)
Add a boundary condition term from parameters.
Profiler * getProfiler() const
Access to profiler.
Definition: CepsObject.cpp:46
Poisson equation with Dirichlet 1 on anode, 0 on cathode. Neumann elsewhere. Functional tensorial con...
void setupWithParameters(InputParameters *p) override
Sets the diffusion tensor.
CepsBool requireNullMean() const
Tells if this problem requires a null mean constraint.
void defineAnalyticSolution() override
No analytic solution.
void run() override
Run does nothing. The tests call directly a LaplacianSolver solve method.
~FluxAnodeCathodeProblem() override
Destructor.
void defineSourceTerms() override
No source term.
void setupWithParameters(InputParameters *p) override
Sets the parameters.
FluxAnodeCathodeProblem(Geometry *g, InputParameters *p=nullptr)
Constructor from geometry and optional input file.
void defineUnknowns() override
Lists the unknowns of the problem (one here)
CepsString m_robinCoeffs
Robin coefficients.
void defineBoundaryConditions() override
Neumann -1/1 and 0 elsewhere.
Solver for a Poisson equation with Neumann BC (using 0 mean constraint)
void solve() override
Solve and postprocess.
Encapsulates all the geometrical data.
Definition: Geometry.hpp:50
ElectrodeBase * m_anode
Electrode object.
ElectrodeBase * m_cathode
Electrode object.
Reads and stores simulation configuration.
CepsString getString(const keyType &key) const
Reads a CepsString from configuration.
void stop(CepsString lbl)
Stops the measure of a labeled chronometer.
void start(CepsString lbl, CepsString dspl="")
Creates or continue a labeled chronometer.
CepsSet< CepsAttribute > & getAttributes()
Returns the attributes of the entity.
CepsVector< CepsString > split(const CepsString &s, const CepsString &delimiters=CepsString(" \t"))
Splits a string using mulitple delimiters in a single string.
Definition: CepsString.cpp:38
CepsBool isProfiling()
Check if we are currently profiling on the master proc (always false on slave procs).
Definition: CepsFlags.cpp:257