BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
discrete_aca_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 #include "bempp/common/config_trilinos.hpp"
22 #include "bempp/common/config_ahmed.hpp"
23 
24 #ifdef WITH_AHMED
25 
26 #ifndef bempp_discrete_aca_boundary_operator_hpp
27 #define bempp_discrete_aca_boundary_operator_hpp
28 
29 #include "../common/common.hpp"
30 
31 #include "discrete_boundary_operator.hpp"
32 #include "ahmed_aux_fwd.hpp"
33 #include "assembly_options.hpp" // actually only ParallelizationOptions are needed
34 #include "index_permutation.hpp"
35 #include "symmetry.hpp"
36 #include "../fiber/scalar_traits.hpp"
37 
38 #include <iostream>
39 #include "../common/boost_shared_array_fwd.hpp"
40 
41 #ifdef WITH_TRILINOS
42 #include <Teuchos_RCP.hpp>
43 #include <Thyra_SpmdVectorSpaceBase_decl.hpp>
44 #endif
45 
46 namespace Bempp
47 {
48 
49 void dumpblcluster(const blcluster* bl, const std::string& indent);
50 
51 // Forward declarations
52 
54 template <typename ValueType> class AcaApproximateLuInverse;
55 template <typename ValueType> class DiscreteAcaBoundaryOperator;
58 // Global functions
59 
75 template <typename ValueType>
76 shared_ptr<const DiscreteBoundaryOperator<ValueType> > acaOperatorSum(
77  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op1,
78  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op2,
79  double eps, int maximumRank);
80 
94 template <typename ValueType>
95 shared_ptr<const DiscreteBoundaryOperator<ValueType> > scaledAcaOperator(
96  const ValueType& multiplier,
97  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op);
98 
112 template <typename ValueType>
113 shared_ptr<const DiscreteBoundaryOperator<ValueType> > scaledAcaOperator(
114  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op,
115  const ValueType& multiplier);
116 
117 //template <typename ValueType>
118 //shared_ptr<DiscreteAcaBoundaryOperator<ValueType> > acaOperatorComposition(
119 // ValueType multiplier,
120 // const shared_ptr<const DiscreteAcaBoundaryOperator<ValueType> >& op1,
121 // const shared_ptr<const DiscreteAcaBoundaryOperator<ValueType> >& op2,
122 // double eps, int maximumRank);
123 
133 template <typename ValueType>
134 shared_ptr<const DiscreteBoundaryOperator<ValueType> > acaOperatorApproximateLuInverse(
135  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op,
136  double delta);
137 
138 // class DiscreteAcaBoundaryOperator
139 
143 template <typename ValueType>
145  public DiscreteBoundaryOperator<ValueType>
146 {
147  friend class AcaApproximateLuInverse<ValueType>;
148  friend shared_ptr<const DiscreteBoundaryOperator<ValueType> > acaOperatorSum<>(
149  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op1,
150  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op2,
151  double eps, int maximumRank);
152 
153  friend shared_ptr<const DiscreteBoundaryOperator<ValueType> > scaledAcaOperator<>(
154  const ValueType& multiplier,
155  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op);
156 
157  friend shared_ptr<const DiscreteBoundaryOperator<ValueType> > scaledAcaOperator<>(
158  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op,
159  const ValueType& multiplier);
160 
161 public:
162  typedef typename Fiber::ScalarTraits<ValueType>::RealType CoordinateType;
164  typedef bbxbemblcluster<AhmedDofType, AhmedDofType> AhmedBemBlcluster;
165  typedef mblock<typename AhmedTypeTraits<ValueType>::Type> AhmedMblock;
166  typedef boost::shared_array<AhmedMblock*> AhmedMblockArray;
167  // Unfortunately currently shared_array<T> cannot be converted to
168  // shared_array<const T>. So we can't write
169  // typedef boost::shared_array<const AhmedMblock*> AhmedConstMblockArray;
170  // and need to use this instead:
171  typedef boost::shared_array<AhmedMblock*> AhmedConstMblockArray;
172 
209  unsigned int rowCount, unsigned int columnCount,
210  double epsUsedInAssembly,
211  int maximumRankUsedInAssembly,
212  int symmetry,
213  const shared_ptr<const AhmedBemBlcluster>& blockCluster_,
214  const AhmedMblockArray& blocks_,
215  const IndexPermutation& domainPermutation_,
216  const IndexPermutation& rangePermutation_,
217  const ParallelizationOptions& parallelizationOptions_,
218  const std::vector<AhmedConstMblockArray>& sharedBlocks_ =
219  std::vector<AhmedConstMblockArray>());
220 
257  unsigned int rowCount, unsigned int columnCount,
258  int maximumRankUsedInAssembly,
259  int symmetry,
260  std::auto_ptr<const AhmedBemBlcluster> blockCluster_,
261  AhmedMblockArray blocks_,
262  const IndexPermutation& domainPermutation_,
263  const IndexPermutation& rangePermutation_,
264  const ParallelizationOptions& parallelizationOptions_,
265  const std::vector<AhmedConstMblockArray>& sharedBlocks_ =
266  std::vector<AhmedConstMblockArray>()) BEMPP_DEPRECATED;
267 
306  unsigned int rowCount, unsigned int columnCount,
307  int maximumRankUsedInAssembly,
308  int symmetry,
309  const shared_ptr<const AhmedBemBlcluster>& blockCluster_,
310  const AhmedMblockArray& blocks_,
311  const IndexPermutation& domainPermutation_,
312  const IndexPermutation& rangePermutation_,
313  const ParallelizationOptions& parallelizationOptions_,
314  const std::vector<AhmedConstMblockArray>& sharedBlocks_ =
315  std::vector<AhmedConstMblockArray>());
316 
317  virtual arma::Mat<ValueType> asMatrix() const;
318 
319  virtual unsigned int rowCount() const;
320  virtual unsigned int columnCount() const;
321 
322  virtual void addBlock(const std::vector<int>& rows,
323  const std::vector<int>& cols,
324  const ValueType alpha,
325  arma::Mat<ValueType>& block) const;
326 
327  virtual shared_ptr<const DiscreteBoundaryOperator<ValueType> >
329  bool interleave=false) const;
330 
335  void makeAllMblocksDense();
336 
343  const DiscreteBoundaryOperator<ValueType>& discreteOperator);
344 
350  static shared_ptr<const DiscreteAcaBoundaryOperator<ValueType> > castToAca(
351  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >&
352  discreteOperator);
353 
356  int maximumRank() const;
357 
360  double eps() const;
361 
363  int actualMaximumRank() const;
364 
366  int symmetry() const;
367 
369  shared_ptr<const AhmedBemBlcluster> blockCluster() const;
370 
377  AhmedMblockArray blocks() const;
378 
380  size_t blockCount() const;
381 
383  const IndexPermutation& domainPermutation() const;
384 
386  const IndexPermutation& rangePermutation() const;
387 
391 
394  std::vector<AhmedConstMblockArray> sharedBlocks() const;
395 
396 #ifdef WITH_TRILINOS
397 public:
398  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<ValueType> > domain() const;
399  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<ValueType> > range() const;
400 
401 protected:
402  virtual bool opSupportedImpl(Thyra::EOpTransp M_trans) const;
403 #endif
404 
405 private:
406  virtual void applyBuiltInImpl(const TranspositionMode trans,
407  const arma::Col<ValueType>& x_in,
408  arma::Col<ValueType>& y_inout,
409  const ValueType alpha,
410  const ValueType beta) const;
411 
412 private:
414 #ifdef WITH_TRILINOS
415  Teuchos::RCP<const Thyra::SpmdVectorSpaceBase<ValueType> > m_domainSpace;
416  Teuchos::RCP<const Thyra::SpmdVectorSpaceBase<ValueType> > m_rangeSpace;
417 #else
418  unsigned int m_rowCount;
419  unsigned int m_columnCount;
420 #endif
421  double m_eps;
422  int m_maximumRank; // used by the approximate-LU preconditioner
423  int m_symmetry;
424 
425  shared_ptr<const AhmedBemBlcluster> m_blockCluster;
426  AhmedMblockArray m_blocks;
427 
428  IndexPermutation m_domainPermutation;
429  IndexPermutation m_rangePermutation;
430  ParallelizationOptions m_parallelizationOptions;
431  std::vector<AhmedConstMblockArray> m_sharedBlocks;
433 };
434 
435 } // namespace Bempp
436 
437 #endif // WITH_AHMED
438 
439 #endif
Traits of scalar types.
Definition: scalar_traits.hpp:40
void makeAllMblocksDense()
Uncompress all blocks of the H-matrix and store them as dense matrices.
Definition: discrete_aca_boundary_operator.cpp:583
int actualMaximumRank() const
Return the actual maximum rank of low-rank mblocks.
Definition: discrete_aca_boundary_operator.cpp:606
Permutation of indices.
Definition: index_permutation.hpp:39
Parallel operation settings.
Definition: parallelization_options.hpp:32
Approximate LU decomposition of a H-matrix.
Definition: aca_approximate_lu_inverse.hpp:52
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_aca_boundary_operator.cpp:390
size_t blockCount() const
Return the number of mblocks making up this operator.
Definition: discrete_aca_boundary_operator.cpp:636
#define BEMPP_DEPRECATED
Macro used to mark deprecated functions or classes.
Definition: deprecated.hpp:41
const IndexPermutation & rangePermutation() const
Return the range index permutation.
Definition: discrete_aca_boundary_operator.cpp:650
TranspositionMode
Enumeration determining how a discrete boundary operator is transformed before being applied...
Definition: transposition_mode.hpp:37
Discrete linear operator stored as a H-matrix.
Definition: discrete_aca_boundary_operator.hpp:144
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_aca_boundary_operator.cpp:401
Discrete boundary operator.
Definition: assembled_potential_operator.hpp:33
An Ahmed-compatible degree-of-freedom type.
Definition: ahmed_aux.hpp:89
int maximumRank() const
Return the upper bound for the rank of low-rank mblocks specified during H-matrix construction...
Definition: discrete_aca_boundary_operator.cpp:599
virtual unsigned int columnCount() const
Number of columns of the operator.
Definition: discrete_aca_boundary_operator.cpp:378
std::vector< AhmedConstMblockArray > sharedBlocks() const
Return the vector of mblock arrays that this operator implicitly depends on.
Definition: discrete_aca_boundary_operator.cpp:664
const IndexPermutation & domainPermutation() const
Return the domain index permutation.
Definition: discrete_aca_boundary_operator.cpp:643
shared_ptr< const AhmedBemBlcluster > blockCluster() const
Return the block cluster.
Definition: discrete_aca_boundary_operator.cpp:622
virtual arma::Mat< ValueType > asMatrix() const
Matrix representation of the operator.
Definition: discrete_aca_boundary_operator.cpp:322
DiscreteAcaBoundaryOperator(unsigned int rowCount, unsigned int columnCount, double epsUsedInAssembly, int maximumRankUsedInAssembly, int symmetry, const shared_ptr< const AhmedBemBlcluster > &blockCluster_, const AhmedMblockArray &blocks_, const IndexPermutation &domainPermutation_, const IndexPermutation &rangePermutation_, const ParallelizationOptions &parallelizationOptions_, const std::vector< AhmedConstMblockArray > &sharedBlocks_=std::vector< AhmedConstMblockArray >())
Constructor.
Definition: discrete_aca_boundary_operator.cpp:225
double eps() const
Return the value of the epsilon parameter specified during H-matrix construction. ...
Definition: discrete_aca_boundary_operator.cpp:592
int symmetry() const
Return a flag describing the symmetry of this operator.
Definition: discrete_aca_boundary_operator.cpp:615
virtual unsigned int rowCount() const
Number of rows of the operator.
Definition: discrete_aca_boundary_operator.cpp:366
const ParallelizationOptions & parallelizationOptions() const
Return the parallelization options used in the matrix-vector multiply.
Definition: discrete_aca_boundary_operator.cpp:657
static const DiscreteAcaBoundaryOperator< ValueType > & castToAca(const DiscreteBoundaryOperator< ValueType > &discreteOperator)
Downcast a reference to a DiscreteBoundaryOperator object to DiscreteAcaBoundaryOperator.
Definition: discrete_aca_boundary_operator.cpp:409
AhmedMblockArray blocks() const
Return the mblocks making up the H-matrix represented by this operator.
Definition: discrete_aca_boundary_operator.cpp:629