31 #if defined(DirichletConditions_RECURSES)
32 #error Recursive header files inclusion detected in DirichletConditions.h
35 #define DirichletConditions_RECURSES
37 #if !defined DirichletConditions_h
39 #define DirichletConditions_h
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>
96 template <
typename TLinearAlgebraBackend >
103 typedef typename LinearAlgebraBackend::DenseVector::Scalar
Scalar;
108 typedef typename LinearAlgebraBackend::Triplet
Triplet;
133 ASSERT( A.cols() == A.rows() );
134 ASSERT( p.rows() == A.rows() );
135 const auto n = p.rows();
136 std::vector< Index > relabeling( n );
138 for (
Index i = 0; i < p.rows(); i++ )
139 relabeling[ i ] = ( p[ i ] == 0 ) ? j++ : n;
142 std::vector< Triplet > triplets;
143 for (
int k = 0; k < A.outerSize(); ++k )
144 for (
typename SparseMatrix::InnerIterator it( A, k ); it; ++it )
146 if ( ( relabeling[ it.row() ] != n ) && ( relabeling[ it.col() ] != n ) )
147 triplets.push_back( { relabeling[ it.row() ], relabeling[ it.col() ],
150 Ap.setFromTriplets( triplets.cbegin(), triplets.cend() );
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();
180 std::vector< Index > relabeling( n );
182 for (
Index i = 0; i < p.rows(); i++ )
183 relabeling[ i ] = ( p[ i ] == 0 ) ? j++ : n;
185 for (
Index i = 0; i < p.rows(); i++ )
186 if ( p[ i ] == 0 ) bp[ relabeling[ i ] ] = tmp[ i ];
209 for (
Index i = 0; i < p.rows(); i++ )
210 x[ i ] = ( p[ i ] == 0 ) ? xd[ j++ ] : u[ i ];
225 return IntegerVector::Zero( b.rows() );
240 #undef DirichletConditions_RECURSES
Aim: A helper class to solve a system with Dirichlet boundary conditions.
BOOST_CONCEPT_ASSERT((concepts::CDynamicMatrix< SparseMatrix >))
LinearAlgebraBackend::DenseMatrix DenseMatrix
LinearAlgebraBackend::Triplet Triplet
LinearAlgebraBackend::IntegerVector IntegerVector
BOOST_CONCEPT_ASSERT((concepts::CDynamicVector< DenseVector >))
static DenseVector dirichletVector(const SparseMatrix &A, const DenseVector &b, const IntegerVector &p, const DenseVector &u)
static SparseMatrix dirichletOperator(const SparseMatrix &A, const IntegerVector &p)
BOOST_CONCEPT_ASSERT((concepts::CDynamicMatrix< DenseMatrix >))
BOOST_CONCEPT_ASSERT((concepts::CLinearAlgebra< DenseVector, SparseMatrix >))
LinearAlgebraBackend::DenseVector::Index Index
TLinearAlgebraBackend LinearAlgebraBackend
static IntegerVector nullBoundaryVector(const DenseVector &b)
LinearAlgebraBackend::DenseVector::Scalar Scalar
static DenseVector dirichletSolution(const DenseVector &xd, const IntegerVector &p, const DenseVector &u)
BOOST_CONCEPT_ASSERT((concepts::CLinearAlgebra< DenseVector, DenseMatrix >))
LinearAlgebraBackend::SparseMatrix SparseMatrix
LinearAlgebraBackend::DenseVector DenseVector
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Represent any dynamic sized matrix having sparse or dense representation.
Aim: Represent any dynamic sized column vector having sparse or dense representation.
Aim: Check right multiplication between matrix and vector and internal matrix multiplication....
EigenLinearAlgebraBackend::SparseMatrix SparseMatrix
EigenLinearAlgebraBackend::DenseMatrix DenseMatrix