DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
DirichletConditions.h
1
16
17
#pragma once
18
30
31
#if defined(DirichletConditions_RECURSES)
32
#error Recursive header files inclusion detected in DirichletConditions.h
33
#else
// defined(DirichletConditions_RECURSES)
35
#define DirichletConditions_RECURSES
36
37
#if !defined DirichletConditions_h
39
#define DirichletConditions_h
40
42
// Inclusions
43
#include <iostream>
44
#include <vector>
45
#include "DGtal/base/Common.h"
46
#include <DGtal/math/linalg/CDynamicMatrix.h>
47
#include <DGtal/math/linalg/CDynamicVector.h>
48
#include <DGtal/math/linalg/CLinearAlgebra.h>
50
51
namespace
DGtal
52
{
53
55
// template class DirichletConditions
96
template
<
typename
TLinearAlgebraBackend >
97
class
DirichletConditions
98
{
99
public
:
100
typedef
TLinearAlgebraBackend
LinearAlgebraBackend
;
101
102
typedef
typename
LinearAlgebraBackend::DenseVector::Index
Index
;
103
typedef
typename
LinearAlgebraBackend::DenseVector::Scalar
Scalar
;
104
typedef
typename
LinearAlgebraBackend::DenseVector
DenseVector
;
105
typedef
typename
LinearAlgebraBackend::IntegerVector
IntegerVector
;
106
typedef
typename
LinearAlgebraBackend::DenseMatrix
DenseMatrix
;
107
typedef
typename
LinearAlgebraBackend::SparseMatrix
SparseMatrix
;
108
typedef
typename
LinearAlgebraBackend::Triplet
Triplet
;
109
110
BOOST_CONCEPT_ASSERT
((
concepts::CDynamicVector<DenseVector>
));
111
BOOST_CONCEPT_ASSERT
((
concepts::CDynamicMatrix<DenseMatrix>
));
112
BOOST_CONCEPT_ASSERT
((
concepts::CDynamicMatrix<SparseMatrix>
));
113
BOOST_CONCEPT_ASSERT
((
concepts::CLinearAlgebra<DenseVector, SparseMatrix>
));
114
BOOST_CONCEPT_ASSERT
((
concepts::CLinearAlgebra<DenseVector, DenseMatrix>
));
115
129
static
130
SparseMatrix
dirichletOperator
(
const
SparseMatrix
&
A
,
131
const
IntegerVector
& p )
132
{
133
ASSERT(
A
.cols() ==
A
.rows() );
134
ASSERT( p.rows() ==
A
.rows() );
135
const
auto
n = p.rows();
136
std::vector< Index > relabeling( n );
137
Index
j = 0;
138
for
(
Index
i = 0; i < p.rows(); i++ )
139
relabeling[ i ] = ( p[ i ] == 0 ) ? j++ : n;
140
// Building matrix
141
SparseMatrix
Ap( j, j );
142
std::vector< Triplet > triplets;
143
for
(
int
k = 0; k <
A
.outerSize(); ++k )
144
for
(
typename
SparseMatrix::InnerIterator it(
A
, k ); it; ++it )
145
{
146
if
( ( relabeling[ it.row() ] != n ) && ( relabeling[ it.col() ] != n ) )
147
triplets.push_back( { relabeling[ it.row() ], relabeling[ it.col() ],
148
it.value() } );
149
}
150
Ap.setFromTriplets( triplets.cbegin(), triplets.cend() );
151
return
Ap;
152
}
153
169
static
170
DenseVector
dirichletVector
(
const
SparseMatrix
&
A
,
171
const
DenseVector
& b,
172
const
IntegerVector
& p,
173
const
DenseVector
& u )
174
{
175
ASSERT(
A
.cols() ==
A
.rows() );
176
ASSERT( p.rows() ==
A
.rows() );
177
const
auto
n = p.rows();
178
DenseVector
up = p.array().template cast<double>() * u.array();
179
DenseVector
tmp = b.array() - (
A
* up).array();
180
std::vector< Index > relabeling( n );
181
Index
j = 0;
182
for
(
Index
i = 0; i < p.rows(); i++ )
183
relabeling[ i ] = ( p[ i ] == 0 ) ? j++ : n;
184
DenseVector
bp( j );
185
for
(
Index
i = 0; i < p.rows(); i++ )
186
if
( p[ i ] == 0 ) bp[ relabeling[ i ] ] = tmp[ i ];
187
return
bp;
188
}
189
202
static
203
DenseVector
dirichletSolution
(
const
DenseVector
& xd,
204
const
IntegerVector
& p,
205
const
DenseVector
& u )
206
{
207
DenseVector
x( p.rows() );
208
Index
j = 0;
209
for
(
Index
i = 0; i < p.rows(); i++ )
210
x[ i ] = ( p[ i ] == 0 ) ? xd[ j++ ] : u[ i ];
211
return
x;
212
}
213
222
static
223
IntegerVector
nullBoundaryVector
(
const
DenseVector
& b )
224
{
225
return
IntegerVector::Zero( b.rows() );
226
}
227
};
228
229
}
// namespace DGtal
230
231
233
// Includes inline functions.
234
235
// //
237
238
#endif
// !defined DirichletConditions_h
239
240
#undef DirichletConditions_RECURSES
241
#endif
// else defined(DirichletConditions_RECURSES)
DGtal::DirichletConditions
Aim: A helper class to solve a system with Dirichlet boundary conditions.
Definition
DirichletConditions.h:98
DGtal::DirichletConditions::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDynamicMatrix< SparseMatrix >))
DGtal::DirichletConditions< LinAlgBackend >::DenseMatrix
LinearAlgebraBackend::DenseMatrix DenseMatrix
Definition
DirichletConditions.h:106
DGtal::DirichletConditions< LinAlgBackend >::Triplet
LinearAlgebraBackend::Triplet Triplet
Definition
DirichletConditions.h:108
DGtal::DirichletConditions< LinAlgBackend >::IntegerVector
LinearAlgebraBackend::IntegerVector IntegerVector
Definition
DirichletConditions.h:105
DGtal::DirichletConditions::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDynamicVector< DenseVector >))
DGtal::DirichletConditions::dirichletVector
static DenseVector dirichletVector(const SparseMatrix &A, const DenseVector &b, const IntegerVector &p, const DenseVector &u)
Definition
DirichletConditions.h:170
DGtal::DirichletConditions::dirichletOperator
static SparseMatrix dirichletOperator(const SparseMatrix &A, const IntegerVector &p)
Definition
DirichletConditions.h:130
DGtal::DirichletConditions::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDynamicMatrix< DenseMatrix >))
DGtal::DirichletConditions::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CLinearAlgebra< DenseVector, SparseMatrix >))
DGtal::DirichletConditions< LinAlgBackend >::Index
LinearAlgebraBackend::DenseVector::Index Index
Definition
DirichletConditions.h:102
DGtal::DirichletConditions< LinAlgBackend >::LinearAlgebraBackend
LinAlgBackend LinearAlgebraBackend
Definition
DirichletConditions.h:100
DGtal::DirichletConditions::nullBoundaryVector
static IntegerVector nullBoundaryVector(const DenseVector &b)
Definition
DirichletConditions.h:223
DGtal::DirichletConditions< LinAlgBackend >::Scalar
LinearAlgebraBackend::DenseVector::Scalar Scalar
Definition
DirichletConditions.h:103
DGtal::DirichletConditions::dirichletSolution
static DenseVector dirichletSolution(const DenseVector &xd, const IntegerVector &p, const DenseVector &u)
Definition
DirichletConditions.h:203
DGtal::DirichletConditions::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CLinearAlgebra< DenseVector, DenseMatrix >))
DGtal::DirichletConditions< LinAlgBackend >::SparseMatrix
LinearAlgebraBackend::SparseMatrix SparseMatrix
Definition
DirichletConditions.h:107
DGtal::DirichletConditions< LinAlgBackend >::DenseVector
LinearAlgebraBackend::DenseVector DenseVector
Definition
DirichletConditions.h:104
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
A
Definition
testCountedConstPtrOrConstPtr.cpp:43
DGtal::concepts::CDynamicMatrix
Aim: Represent any dynamic sized matrix having sparse or dense representation.
Definition
CDynamicMatrix.h:89
DGtal::concepts::CDynamicVector
Aim: Represent any dynamic sized column vector having sparse or dense representation.
Definition
CDynamicVector.h:89
DGtal::concepts::CLinearAlgebra
Aim: Check right multiplication between matrix and vector and internal matrix multiplication....
Definition
CLinearAlgebra.h:94
src
DGtal
math
linalg
DirichletConditions.h
Generated on
for DGtal by
1.18.0