BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
discrete_sparse_boundary_operator.hpp
1 // Copyright (C) 2011-2012 by the BEM++ Authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef bempp_discrete_sparse_boundary_operator_hpp
22 #define bempp_discrete_sparse_boundary_operator_hpp
23 
24 #include "../common/common.hpp"
25 #include "bempp/common/config_ahmed.hpp"
26 #include "bempp/common/config_trilinos.hpp"
27 
28 #include "discrete_boundary_operator.hpp"
29 
30 #include "ahmed_aux_fwd.hpp"
31 #include "symmetry.hpp"
32 #include "transposition_mode.hpp"
33 
34 #include "../common/shared_ptr.hpp"
35 #include "../common/boost_shared_array_fwd.hpp"
36 #include "../fiber/scalar_traits.hpp"
37 
38 #ifdef WITH_TRILINOS
39 #include <Teuchos_RCP.hpp>
40 #include <Thyra_SpmdVectorSpaceBase_decl.hpp>
42 class Epetra_CrsMatrix;
44 #endif
45 
46 namespace Bempp
47 {
49 class IndexPermutation;
55 template <typename ValueType>
57  public DiscreteBoundaryOperator<ValueType>
58 {
59  typedef typename Fiber::ScalarTraits<ValueType>::RealType CoordinateType;
61  typedef bbxbemblcluster<AhmedDofType, AhmedDofType> AhmedBemBlcluster;
62  typedef mblock<typename AhmedTypeTraits<ValueType>::Type> AhmedMblock;
63 
64 #ifdef WITH_TRILINOS
65 public:
78  const shared_ptr<const Epetra_CrsMatrix>& mat,
79  int symmetry = NO_SYMMETRY,
81  const shared_ptr<AhmedBemBlcluster>& blockCluster =
82  shared_ptr<AhmedBemBlcluster>(),
83  const shared_ptr<IndexPermutation>& domainPermutation =
84  shared_ptr<IndexPermutation>(),
85  const shared_ptr<IndexPermutation>& rangePermutation =
86  shared_ptr<IndexPermutation>());
87 #else
88  // This class cannot be used without Trilinos
89 private:
91 public:
92 #endif
93 
94  virtual void dump() const;
95 
96  virtual arma::Mat<ValueType> asMatrix() const;
97 
98  virtual unsigned int rowCount() const;
99  virtual unsigned int columnCount() const;
100 
101  virtual void addBlock(const std::vector<int>& rows,
102  const std::vector<int>& cols,
103  const ValueType alpha,
104  arma::Mat<ValueType>& block) const;
105 
106 #ifdef WITH_AHMED
107  virtual shared_ptr<const DiscreteBoundaryOperator<ValueType> >
108  asDiscreteAcaBoundaryOperator(double eps=-1, int maximumRank=-1,
109  bool interleave=false) const;
110 #endif
111 
117  static shared_ptr<const DiscreteSparseBoundaryOperator<ValueType> > castToSparse(
118  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >&
119  discreteOperator);
120 
121 #ifdef WITH_TRILINOS
122 
128  shared_ptr<const Epetra_CrsMatrix> epetraMatrix() const;
129 #endif
130 
137 
139  inline int symmetryMode() const{
140  return m_symmetry;
141  }
142 
143 #ifdef WITH_TRILINOS
144 public:
145  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<ValueType> > domain() const;
146  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<ValueType> > range() const;
147 
148 protected:
149  virtual bool opSupportedImpl(Thyra::EOpTransp M_trans) const;
150 #endif
151 
152 private:
154  virtual void applyBuiltInImpl(const TranspositionMode trans,
155  const arma::Col<ValueType>& x_in,
156  arma::Col<ValueType>& y_inout,
157  const ValueType alpha,
158  const ValueType beta) const;
159  bool isTransposed() const;
160 
161  // void constructAhmedMatrix(
162  // int* rowOffsets, int* colIndices, double* values,
163  // std::vector<unsigned int>& domain_o2p,
164  // std::vector<unsigned int>& range_p2o,
165  // double eps,
166  // AhmedBemBlcluster* blockCluster,
167  // boost::shared_array<AhmedMblock*>& mblocks,
168  // int& maximumRank) const;
171 private:
173 #ifdef WITH_TRILINOS
174  shared_ptr<const Epetra_CrsMatrix> m_mat;
175  int m_symmetry;
176  TranspositionMode m_trans;
177  shared_ptr<AhmedBemBlcluster> m_blockCluster;
178  // o2p
179  shared_ptr<IndexPermutation> m_domainPermutation, m_rangePermutation;
180  Teuchos::RCP<const Thyra::SpmdVectorSpaceBase<ValueType> > m_domainSpace;
181  Teuchos::RCP<const Thyra::SpmdVectorSpaceBase<ValueType> > m_rangeSpace;
182 #endif
183 
184 };
185 
186 } // namespace Bempp
187 
188 #endif
Traits of scalar types.
Definition: scalar_traits.hpp:40
Discrete boundary operator stored as a sparse matrix.
Definition: discrete_sparse_boundary_operator.hpp:56
virtual arma::Mat< ValueType > asMatrix() const
Matrix representation of the operator.
Definition: discrete_sparse_boundary_operator.cpp:233
virtual unsigned int columnCount() const
Number of columns of the operator.
Definition: discrete_sparse_boundary_operator.cpp:272
virtual unsigned int rowCount() const
Number of rows of the operator.
Definition: discrete_sparse_boundary_operator.cpp:266
TranspositionMode transpositionMode() const
Return the active sparse matrix transformation.
Definition: discrete_sparse_boundary_operator.cpp:408
shared_ptr< const Epetra_CrsMatrix > epetraMatrix() const
Return a shared pointer to the sparse matrix stored within this operator.
Definition: discrete_sparse_boundary_operator.cpp:401
DiscreteSparseBoundaryOperator(const shared_ptr< const Epetra_CrsMatrix > &mat, int symmetry=NO_SYMMETRY, TranspositionMode trans=NO_TRANSPOSE, const shared_ptr< AhmedBemBlcluster > &blockCluster=shared_ptr< AhmedBemBlcluster >(), const shared_ptr< IndexPermutation > &domainPermutation=shared_ptr< IndexPermutation >(), const shared_ptr< IndexPermutation > &rangePermutation=shared_ptr< IndexPermutation >())
Constructor.
Definition: discrete_sparse_boundary_operator.cpp:205
TranspositionMode
Enumeration determining how a discrete boundary operator is transformed before being applied...
Definition: transposition_mode.hpp:37
static shared_ptr< const DiscreteSparseBoundaryOperator< ValueType > > castToSparse(const shared_ptr< const DiscreteBoundaryOperator< ValueType > > &discreteOperator)
Downcast a shared pointer to a DiscreteBoundaryOperator object to a shared pointer to a DiscreteSpars...
Definition: discrete_sparse_boundary_operator.cpp:387
Discrete boundary operator.
Definition: assembled_potential_operator.hpp:33
virtual void addBlock(const std::vector< int > &rows, const std::vector< int > &cols, const ValueType alpha, arma::Mat< ValueType > &block) const
Add a subblock of this operator to a matrix.
Definition: discrete_sparse_boundary_operator.cpp:278
An Ahmed-compatible degree-of-freedom type.
Definition: ahmed_aux.hpp:89
Use the non-transposed operator.
Definition: transposition_mode.hpp:41
int symmetryMode() const
Return the symmetry type of the sparse matrix.
Definition: discrete_sparse_boundary_operator.hpp:139
virtual shared_ptr< const DiscreteBoundaryOperator< ValueType > > asDiscreteAcaBoundaryOperator(double eps=-1, int maximumRank=-1, bool interleave=false) const
Return a representation that can be cast to a DiscreteAcaBoundaryOperator.
Definition: discrete_sparse_boundary_operator.cpp:331
virtual void dump() const
Write a textual representation of the operator to standard output.
Definition: discrete_sparse_boundary_operator.cpp:223