BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
discrete_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 
23 #ifndef bempp_discrete_boundary_operator_hpp
24 #define bempp_discrete_boundary_operator_hpp
25 
26 #include "../common/common.hpp"
27 #include "../common/shared_ptr.hpp"
28 
29 #include "transposition_mode.hpp"
30 #include "boost/enable_shared_from_this.hpp"
31 
32 #include "../common/armadillo_fwd.hpp"
33 
34 #ifdef WITH_TRILINOS
35 #include <Thyra_LinearOpDefaultBase_decl.hpp>
36 #endif
37 
38 #include <boost/mpl/set.hpp>
39 #include <boost/mpl/has_key.hpp>
40 #include <boost/utility/enable_if.hpp>
41 
42 namespace Bempp
43 {
44 
75 template <typename ValueType>
76 class DiscreteBoundaryOperator :
77  public boost::enable_shared_from_this<DiscreteBoundaryOperator<ValueType> >
78 #ifdef WITH_TRILINOS
79  , public Thyra::LinearOpDefaultBase<ValueType>
80 #endif
81 {
82 public:
85 
86 #ifdef WITH_TRILINOS
87 #ifndef DOXYGEN
88  // import the apply() member function from base class
89  // before we overload it
90  using Thyra::LinearOpDefaultBase<ValueType>::apply;
91 #else // DOXYGEN
92 
115  void apply(const Thyra::EOpTransp M_trans,
116  const Thyra::MultiVectorBase<ValueType>& x_in,
117  const Thyra::Ptr<Thyra::MultiVectorBase<ValueType> >& y_inout,
118  const ValueType alpha,
119  const ValueType beta) const;
120 #endif // DOXYGEN
121 #endif // WITH_TRILINOS
122 
147  void apply(const TranspositionMode trans,
148  const arma::Mat<ValueType>& x_in,
149  arma::Mat<ValueType>& y_inout,
150  const ValueType alpha,
151  const ValueType beta) const;
152 
180  virtual shared_ptr<const DiscreteBoundaryOperator>
181  asDiscreteAcaBoundaryOperator(double eps=-1, int maximumRank=-1,
182  bool interleave=false) const;
183 
188  virtual void dump() const;
189 
193  virtual arma::Mat<ValueType> asMatrix() const;
194 
196  virtual unsigned int rowCount() const = 0;
197 
199  virtual unsigned int columnCount() const = 0;
200 
220  virtual void addBlock(const std::vector<int>& rows,
221  const std::vector<int>& cols,
222  const ValueType alpha,
223  arma::Mat<ValueType>& block) const = 0;
224 
225 #ifdef WITH_TRILINOS
226 protected:
227  virtual void applyImpl(
228  const Thyra::EOpTransp M_trans,
229  const Thyra::MultiVectorBase<ValueType> &X_in,
230  const Teuchos::Ptr<Thyra::MultiVectorBase<ValueType> > &Y_inout,
231  const ValueType alpha,
232  const ValueType beta) const;
233 #endif
234 
235 private:
236  virtual void applyBuiltInImpl(const TranspositionMode trans,
237  const arma::Col<ValueType>& x_in,
238  arma::Col<ValueType>& y_inout,
239  const ValueType alpha,
240  const ValueType beta) const = 0;
241 };
242 
245 template <typename ValueType>
246 shared_ptr<const DiscreteBoundaryOperator<ValueType> > operator+(
247  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op);
248 
254 template <typename ValueType>
255 shared_ptr<const DiscreteBoundaryOperator<ValueType> > operator-(
256  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op);
257 
263 template <typename ValueType>
264 shared_ptr<DiscreteBoundaryOperator<ValueType> > operator+(
265  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op1,
266  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op2);
267 
273 template <typename ValueType>
274 shared_ptr<DiscreteBoundaryOperator<ValueType> > operator-(
275  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op1,
276  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op2);
277 
283 template <typename ValueType, typename ScalarType>
284 typename boost::enable_if<
285  typename boost::mpl::has_key<
286  boost::mpl::set<float, double, std::complex<float>, std::complex<double> >,
287  ScalarType>,
288  shared_ptr<DiscreteBoundaryOperator<ValueType> > >::type
289 operator*(
290  ScalarType scalar,
291  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op);
292 
298 template <typename ValueType, typename ScalarType>
299 typename boost::enable_if<
300  typename boost::mpl::has_key<
301  boost::mpl::set<float, double, std::complex<float>, std::complex<double> >,
302  ScalarType>,
303  shared_ptr<DiscreteBoundaryOperator<ValueType> > >::type
304 operator*(
305  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op,
306  ScalarType scalar);
307 
313 template <typename ValueType>
314 shared_ptr<DiscreteBoundaryOperator<ValueType> > operator*(
315  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op1,
316  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op2);
317 
323 template <typename ValueType>
324 shared_ptr<DiscreteBoundaryOperator<ValueType> > mul(
325  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op1,
326  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op2);
327 
333 template <typename ValueType, typename ScalarType>
334 shared_ptr<DiscreteBoundaryOperator<ValueType> > operator/(
335  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op,
336  ScalarType scalar);
337 
343 template <typename ValueType>
344 shared_ptr<DiscreteBoundaryOperator<ValueType> > transpose(
345  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op);
346 
352 template <typename ValueType>
353 shared_ptr<DiscreteBoundaryOperator<ValueType> > conjugate(
354  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op);
355 
361 template <typename ValueType>
362 shared_ptr<DiscreteBoundaryOperator<ValueType> > conjugateTranspose(
363  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op);
364 
371 template <typename ValueType>
372 shared_ptr<DiscreteBoundaryOperator<ValueType> > transpose(
373  TranspositionMode trans,
374  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op);
375 
384 template <typename RealType>
385 shared_ptr<DiscreteBoundaryOperator<std::complex<RealType> > > complexify(
386  const shared_ptr<const DiscreteBoundaryOperator<RealType> >& op);
387 
388 template <typename ValueType>
389 shared_ptr<DiscreteBoundaryOperator<ValueType> > sum(
390  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op1,
391  const shared_ptr<const DiscreteBoundaryOperator<ValueType> >& op2);
392 
393 } // namespace Bempp
394 
395 #endif
virtual void addBlock(const std::vector< int > &rows, const std::vector< int > &cols, const ValueType alpha, arma::Mat< ValueType > &block) const =0
Add a subblock of this operator to a matrix.
void apply(const Thyra::EOpTransp M_trans, const Thyra::MultiVectorBase< ValueType > &x_in, const Thyra::Ptr< Thyra::MultiVectorBase< ValueType > > &y_inout, const ValueType alpha, const ValueType beta) const
Apply the linear operator to a multivector.
TranspositionMode
Enumeration determining how a discrete boundary operator is transformed before being applied...
Definition: transposition_mode.hpp:37
virtual unsigned int rowCount() const =0
Number of rows of the operator.
virtual ~DiscreteBoundaryOperator()
Destructor.
Definition: discrete_boundary_operator.hpp:84
virtual arma::Mat< ValueType > asMatrix() const
Matrix representation of the operator.
Definition: discrete_boundary_operator.cpp:40
virtual shared_ptr< const DiscreteBoundaryOperator > asDiscreteAcaBoundaryOperator(double eps=-1, int maximumRank=-1, bool interleave=false) const
Return a representation that can be cast to a DiscreteAcaBoundaryOperator.
Definition: discrete_boundary_operator.cpp:92
virtual void dump() const
Write a textual representation of the operator to standard output.
Definition: discrete_boundary_operator.cpp:110
virtual unsigned int columnCount() const =0
Number of columns of the operator.