CEPS  24.01
Cardiac ElectroPhysiology Simulator
BoundaryCondition.tpp
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
29 /** @file BoundaryCondition.cpp Wrapper around Field, specialized with parameters for BCs*/
30 // #included from "pde/common/functions/BoundaryCondition.hpp"
31 
32 template <class _Result>
33 BoundaryCondition<_Result>::BoundaryCondition(
34  ScalarSAFunc* functor,
35  const CepsVector<DegreeOfFreedom*>* domain,
36  CepsUnknownIndex unknown
37 ) :
38  Field<_Result,DegreeOfFreedom>(functor,domain),
39  m_type (CepsBoundaryConditionFlag::Dirichlet),
40  m_alpha (nullptr),
41  m_beta (nullptr),
42  m_unknown(unknown)
43 {
44 }
45 
46 template <class _Result>
47 BoundaryCondition<_Result>::~BoundaryCondition()
48 {
49 }
50 
51 template <class _Result>
52 void
53 BoundaryCondition<_Result>::setBoundaryConditionType(CepsBoundaryConditionFlag type)
54 {
55  m_type = type;
56  return;
57 }
58 
59 template <class _Result>
60 CepsBoundaryConditionFlag
61 BoundaryCondition<_Result>::getBoundaryConditionType() const
62 {
63  return m_type;
64 }
65 
66 template <class _Result>
67 CepsUnknownIndex
68 BoundaryCondition<_Result>::getUnknownId() const
69 {
70  return m_unknown;
71 }
72 
73 
74 template <class _Result>
75 void
76 BoundaryCondition<_Result>::setAlpha(CoeffFunc alpha)
77 {
78  m_alpha = alpha;
79  return;
80 }
81 
82 template <class _Result>
83 typename BoundaryCondition<_Result>::CoeffFunc
84 BoundaryCondition<_Result>::getAlpha() const
85 {
86  return m_alpha;
87 }
88 
89 template <class _Result>
90 typename std::remove_pointer_t<
91  typename BoundaryCondition<_Result>::CoeffFunc
92  >::ReturnType
93 BoundaryCondition<_Result>::getAlpha(CepsStandardArgs args) const
94 {
95  if (this->hasOneOfAttributes(args.attr) or this->hasUniversalAttribute() or this->getNumberOfAttributes() == 0)
96  return m_alpha->eval(std::forward<CepsStandardArgs>(args));
97  return 1.;
98 }
99 
100 template <class _Result>
101 void
102 BoundaryCondition<_Result>::setBeta(CoeffFunc beta)
103 {
104  m_beta = beta;
105  return;
106 }
107 
108 template <class _Result>
109 typename BoundaryCondition<_Result>::CoeffFunc
110 BoundaryCondition<_Result>::getBeta() const
111 {
112  return m_beta;
113 }
114 
115 template <class _Result>
116 typename std::remove_pointer_t<
117  typename BoundaryCondition<_Result>::CoeffFunc
118  >::ReturnType
119 BoundaryCondition<_Result>::getBeta(CepsStandardArgs args) const
120 {
121  if (this->hasOneOfAttributes(args.attr) or this->hasUniversalAttribute() or this->getNumberOfAttributes() == 0)
122  return m_beta->eval(std::forward<CepsStandardArgs>(args));
123  return 0.;
124 }
125 
126 template <class _Result>
127 void
128 BoundaryCondition<_Result>::applyAsDirichlet(DMatPtr mat, DVecPtr sec, CepsReal t, CepsReal scalingFactor)
129 {
130 
131  if (ceps::isValidPtr(mat))
132  {
133  CepsVector<CepsIndex> indices = this->getSupportIndices();
134  mat->zeroRows(indices.size(),indices.data(),scalingFactor);
135  }
136  if (ceps::isValidPtr(sec))
137  {
138  setFieldValuesTo(*this,sec.get(),t);
139  }
140 
141  return;
142 }
143 
144 template <class _Result>
145 _Result
146 BoundaryCondition<_Result>::eval(CepsStandardArgs args)
147 {
148  if (this->hasOneOfAttributes(args.attr) or this->hasUniversalAttribute() or this->getNumberOfAttributes() == 0)
149  return this->m_scaleFactor * this->m_functor->eval(std::forward<CepsStandardArgs>(args));
150  return 0.;
151 }
152 
153 template <class _Result>
154 CepsEnum
155 BoundaryCondition<_Result>::getFlags() const
156 {
157  return this->m_functor->getFlags();
158 }
159 
160 // template <class _Result>
161 // std::ostream &
162 // operator<< (std::ostream &os, const BoundaryCondition<_Result> &that)
163 // {
164 // os << static_cast<Field<_Result>> (that);
165 // os << " -- type : ";
166 // switch (m_type)
167 // {
168 // case CepsBoundaryConditionFlag::Dirichlet: os << "Dirichlet\n"; break;
169 // case CepsBoundaryConditionFlag::Neumann: os << "Neumann\n"; break;
170 // case CepsBoundaryConditionFlag::Robin: os << "Robin\n"; break;
171 // }
172 // os << " -- alpha : " << m_alpha.get () << "\n";
173 // os << " -- beta : " << m_beta.get () << "\n";
174 
175 // return os;
176 // }