1#ifndef DUNE_FEM_AUTOMATICDIFFERENCEOPERATOR_HH
2#define DUNE_FEM_AUTOMATICDIFFERENCEOPERATOR_HH
6#include <dune/fem/io/parameter.hh>
7#include <dune/fem/operator/common/differentiableoperator.hh>
18 template<
class DomainFunction,
class RangeFunction,
class LinearOperator >
19 class AutomaticDifferenceOperator;
26 template<
class DomainFunction,
class RangeFunction = DomainFunction >
27 class AutomaticDifferenceLinearOperator
30 typedef AutomaticDifferenceLinearOperator< DomainFunction, RangeFunction > ThisType;
33 friend class AutomaticDifferenceOperator< DomainFunction, RangeFunction, ThisType >;
42 typedef typename Dune::FieldTraits< RangeFieldType >::real_type RealType;
44 typedef typename RangeFunctionType::DiscreteFunctionSpaceType RangeSpaceType;
45 typedef typename DomainFunctionType::DiscreteFunctionSpaceType DomainSpaceType;
47 AutomaticDifferenceLinearOperator (
const std::string &name,
const DomainSpaceType &dSpace,
const RangeSpaceType &rSpace )
51 b_(
"AutomaticDifferenceOperator::b_", dSpace ),
52 op_u_(
"AutomaticDifferenceOperator::op_u_", rSpace ),
56 virtual void operator() (
const DomainFunctionType &arg, RangeFunctionType &dest )
const;
59 void set (
const DomainFunctionType &u,
const OperatorType &op,
const RealType &eps );
60 const std::string name_;
61 const OperatorType *op_;
62 const DomainFunctionType *u_;
64 mutable DomainFunctionType b_;
65 RangeFunctionType op_u_;
68 RangeFieldType norm_u_;
82 template<
class DomainFunction,
class RangeFunction = DomainFunction,
83 class LinearOperator = AutomaticDifferenceLinearOperator< DomainFunction, RangeFunction > >
94 typedef typename Dune::FieldTraits< RangeFieldType >::real_type RealType;
98 typedef typename RangeFunctionType::DiscreteFunctionSpaceType RangeSpaceType;
99 typedef typename DomainFunctionType::DiscreteFunctionSpaceType DomainSpaceType;
102 : eps_( parameter.getValue< RangeFieldType >(
"fem.differenceoperator.eps", RangeFieldType( 0 ) ) )
111 jOp.set( u, *
this, eps_ );
123 template<
class DomainFunction,
class RangeFunction >
124 inline void AutomaticDifferenceLinearOperator< DomainFunction, RangeFunction >
125 ::operator() (
const DomainFunctionType &arg, RangeFunctionType &dest )
const
136 if( eps <= RealType( 0. ) )
138 const RealType machine_eps = std::numeric_limits< RealType >::epsilon();
139 const RealType norm_p_sq = arg.normSquaredDofs( );
140 if( norm_p_sq > machine_eps )
141 eps = std::sqrt( (RealType( 1 ) + norm_u_) * machine_eps / norm_p_sq );
143 eps = std::sqrt( machine_eps );
150 dest *= RealType( 1 ) / eps;
154 template<
class DomainFunction,
class RangeFunction >
155 inline void AutomaticDifferenceLinearOperator< DomainFunction, RangeFunction >
156 ::set (
const DomainFunctionType &u,
const OperatorType &op,
const RealType &eps )
160 (*op_)( *u_, op_u_ );
163 if( eps_ <= RealType( 0 ) )
164 norm_u_ = std::sqrt( u_->scalarProductDofs( *u_ ) );
operator providing a Jacobian through automatic differentiation
Definition: automaticdifferenceoperator.hh:86
abstract differentiable operator
Definition: differentiableoperator.hh:29
BaseType::RangeFunctionType RangeFunctionType
type of discrete function in the operator's range
Definition: differentiableoperator.hh:40
BaseType::DomainFunctionType DomainFunctionType
type of discrete function in the operator's domain
Definition: differentiableoperator.hh:38
DomainFunctionType::RangeFieldType DomainFieldType
field type of the operator's domain
Definition: differentiableoperator.hh:43
RangeFunctionType::RangeFieldType RangeFieldType
field type of the operator's range
Definition: differentiableoperator.hh:45
Dune namespace.
Definition: alignedallocator.hh:13
abstract affine-linear operator
Definition: operator.hh:90
abstract operator
Definition: operator.hh:34
DomainFunction DomainFunctionType
type of discrete function in the operator's domain
Definition: operator.hh:36
RangeFunction::RangeFieldType RangeFieldType
field type of the operator's range
Definition: operator.hh:43
DomainFunction::RangeFieldType DomainFieldType
field type of the operator's domain
Definition: operator.hh:41
RangeFunction RangeFunctionType
type of discrete function in the operator's range
Definition: operator.hh:38