1 #ifndef DUNE_FEM_ISTLSOLVERS_HH 2 #define DUNE_FEM_ISTLSOLVERS_HH 13 #include <dune/istl/preconditioners.hh> 14 #include <dune/istl/solvers.hh> 15 #include <dune/istl/superlu.hh> 34 template<
class OperatorImp,
class DiscreteFunction,
class SolverCaller >
35 struct DefaultSolverCaller
38 static std::pair< int, double >
39 call (
const OperatorImp &op,
40 const DiscreteFunction &arg, DiscreteFunction &dest,
41 double reduction,
double absLimit,
int maxIter,
bool verbose,
44 typedef typename OperatorImp :: MatrixAdapterType MatrixAdapterType;
45 MatrixAdapterType matrix = op.systemMatrix().matrixAdapter();
47 typedef typename DiscreteFunction :: DofStorageType BlockVectorType;
50 int verb = (verbose && (dest.space().gridPart().comm().rank() == 0)) ? 2 : 0;
54 const double residuum = matrix.residuum( arg.blockVector(), dest.blockVector() );
55 reduction = (residuum > 0) ? absLimit/ residuum : 1e-3;
57 if( verbose && (dest.space().gridPart().comm().rank() == 0) )
58 std::cout << SolverCaller::name() <<
": reduction: " << reduction <<
", residuum: " << residuum <<
", absolut limit: " << absLimit << std::endl;
61 typename SolverCaller :: SolverType solver( matrix, matrix.scp(), matrix.preconditionAdapter(), reduction, maxIter, verb );
64 BlockVectorType rhs( arg.blockVector() );
66 InverseOperatorResult returnInfo;
69 solver.apply( dest.blockVector(), rhs, returnInfo );
71 return std::pair< int, double > ( returnInfo.iterations, matrix.averageCommTime() );
81 template<
class DF,
class Op,
class SolverCaller >
83 :
public Operator< DF, DF >
86 typedef DF DiscreteFunctionType;
87 typedef DiscreteFunctionType DestinationType;
88 typedef Op OperatorType;
89 typedef SolverCaller SolverCallerType;
101 ISTLInverseOp (
const OperatorType &op,
102 double reduction,
double absLimit,
int maxIter,
bool verbose,
105 reduction_( reduction ),
106 absLimit_( absLimit ),
110 averageCommTime_( 0.0 ),
111 parameter_( parameter )
121 ISTLInverseOp (
const OperatorType &op,
122 double reduction,
double absLimit,
int maxIter,
125 reduction_( reduction ),
126 absLimit_ ( absLimit ),
128 verbose_( parameter.getValue< bool >(
"fem.solver.verbose", false ) ),
130 averageCommTime_( 0.0 ),
131 parameter_( parameter )
134 ISTLInverseOp (
const OperatorType &op,
135 double reduction,
double absLimit,
138 reduction_( reduction ),
139 absLimit_ ( absLimit ),
140 maxIter_(
std::numeric_limits< int >::
max() ),
141 verbose_( parameter.getValue< bool >(
"fem.solver.verbose", false ) ),
143 averageCommTime_( 0.0 ),
144 parameter_( parameter )
147 void prepare (
const DiscreteFunctionType& Arg, DiscreteFunctionType& Dest)
const 150 void finalize ()
const 153 void printTexInfo(std::ostream& out)
const 155 out <<
"Solver:"<< SolverCallerType::name() <<
", eps = " << reduction_ ;
163 void apply(
const DiscreteFunctionType& arg, DiscreteFunctionType& dest )
const 165 std::pair< int, double > info
166 = SolverCallerType::call( op_, arg, dest, reduction_, absLimit_, maxIter_, verbose_, parameter_ );
168 iterations_ = info.first;
169 averageCommTime_ = info.second;
173 int iterations()
const 179 double averageCommTime()
const 181 return averageCommTime_;
188 void operator() (
const DiscreteFunctionType& arg, DiscreteFunctionType& dest )
const 194 const OperatorType &op_;
199 mutable int iterations_;
200 mutable double averageCommTime_;
208 template<
class OperatorImp,
class DiscreteFunction >
209 struct LoopSolverCaller
210 :
public DefaultSolverCaller< OperatorImp, DiscreteFunction, LoopSolverCaller< OperatorImp, DiscreteFunction > >
212 typedef LoopSolver< typename DiscreteFunction :: DofStorageType > SolverType;
214 static inline std::string name ()
216 std::string name =
"ISTL LoopSolver";
227 template<
class DF,
class Op >
229 :
public ISTLInverseOp< DF, Op, LoopSolverCaller< Op, DF > >
231 typedef ISTLInverseOp< DF, Op, LoopSolverCaller< Op, DF > > BaseType;
234 template<
class ... Args >
235 ISTLLoopOp ( Args && ... args ) : BaseType(
std::forward< Args >( args ) ... ) {}
242 template<
class OperatorImp,
class DiscreteFunction >
243 struct MINResSolverCaller
244 :
public DefaultSolverCaller< OperatorImp, DiscreteFunction, MINResSolverCaller< OperatorImp, DiscreteFunction > >
246 typedef MINRESSolver< typename DiscreteFunction :: DofStorageType > SolverType;
248 static inline std::string name ()
250 std::string name =
"ISTL MINRESSolver";
261 template<
class DF,
class Op >
263 :
public ISTLInverseOp< DF, Op, MINResSolverCaller< Op, DF > >
265 typedef ISTLInverseOp< DF, Op, MINResSolverCaller< Op, DF > > BaseType;
267 template<
class ... Args >
268 ISTLMINResOp ( Args && ... args ) : BaseType(
std::forward< Args >( args ) ... ) {}
275 template<
class OperatorImp,
class DiscreteFunction >
276 struct BiCGSTABSolverCaller
277 :
public DefaultSolverCaller< OperatorImp, DiscreteFunction, BiCGSTABSolverCaller< OperatorImp, DiscreteFunction > >
279 typedef BiCGSTABSolver< typename DiscreteFunction :: DofStorageType > SolverType;
281 static inline std::string name ()
283 std::string name =
"ISTL BiCGSTABSolver";
294 template<
class DF,
class Op >
295 struct ISTLBICGSTABOp
296 :
public ISTLInverseOp< DF, Op, BiCGSTABSolverCaller< Op, DF > >
298 typedef ISTLInverseOp< DF, Op, BiCGSTABSolverCaller< Op, DF > > BaseType;
300 template<
class ... Args >
301 ISTLBICGSTABOp ( Args && ... args ) : BaseType(
std::forward< Args >( args ) ... ) {}
308 template<
class OperatorImp,
class DiscreteFunction >
309 struct GMResSolverCaller
312 static std::pair< int, double >
313 call (
const OperatorImp &op,
314 const DiscreteFunction &arg, DiscreteFunction &dest,
315 double reduction,
double absLimit,
int maxIter,
bool verbose,
318 int restart = parameter.getValue<
int >(
"istl.gmres.restart", 5 );
319 typedef typename OperatorImp :: MatrixAdapterType MatrixAdapterType;
320 MatrixAdapterType matrix = op.systemMatrix().matrixAdapter();
322 typedef typename DiscreteFunction :: DofStorageType BlockVectorType;
325 int verb = (verbose && (dest.space().gridPart().comm().rank() == 0)) ? 2 : 0;
329 const double residuum = matrix.residuum( arg.blockVector(), dest.blockVector() );
330 reduction = (residuum > 0) ? absLimit/ residuum : 1e-3;
332 if( verbose && (dest.space().gridPart().comm().rank() == 0) )
333 std::cout <<
"ISTL GMRes-Solver: reduction: " << reduction <<
", residuum: " << residuum <<
", absolut limit: " << absLimit << std::endl;
336 RestartedGMResSolver< BlockVectorType >
337 solver( matrix, matrix.scp(), matrix.preconditionAdapter(), reduction, restart, maxIter, verb );
340 BlockVectorType rhs( arg.blockVector() );
342 InverseOperatorResult returnInfo;
345 solver.apply( dest.blockVector(), rhs, returnInfo );
347 return std::pair< int, double > ( returnInfo.iterations, matrix.averageCommTime() );
350 static std::string name ()
352 std::string name =
"ISTL GMRes-Solver";
364 template<
class DF,
class Op >
366 :
public ISTLInverseOp< DF, Op, GMResSolverCaller< Op, DF > >
368 typedef ISTLInverseOp< DF, Op, GMResSolverCaller< Op, DF > > BaseType;
370 template<
class ... Args >
371 ISTLGMResOp ( Args && ... args ) : BaseType(
std::forward< Args >( args ) ... ) {}
378 template<
class OperatorImp,
class DiscreteFunction >
379 struct CGSolverCaller
380 :
public DefaultSolverCaller< OperatorImp, DiscreteFunction, CGSolverCaller< OperatorImp, DiscreteFunction > >
382 typedef CGSolver< typename DiscreteFunction :: DofStorageType > SolverType;
384 static inline std::string name ()
386 std::string name =
"ISTL CGSolver";
397 template<
class DF,
class Op >
399 :
public ISTLInverseOp< DF, Op, CGSolverCaller< Op, DF > >
401 typedef ISTLInverseOp< DF, Op, CGSolverCaller< Op, DF > > BaseType;
403 template<
class ... Args >
404 ISTLCGOp ( Args && ... args ) : BaseType(
std::forward< Args >( args ) ... ) {}
411 template<
class OperatorImp,
class DiscreteFunction >
412 struct SuperLUSolverCaller
415 static std::pair< int, double >
416 call (
const OperatorImp &op,
417 const DiscreteFunction &arg, DiscreteFunction &dest,
418 double reduction,
double absLimit,
int maxIter,
bool verbose )
420 typedef typename OperatorImp :: MatrixAdapterType MatrixAdapterType;
421 MatrixAdapterType matrix = op.systemMatrix().matrixAdapter();
423 InverseOperatorResult returnInfo;
426 typedef typename MatrixAdapterType :: MatrixType MatrixType;
427 typedef typename MatrixType :: BaseType ISTLMatrixType;
428 SuperLU< ISTLMatrixType > solver( matrix.getmat(), verbose );
430 solver.apply( dest.blockVector(), arg.blockVector(), returnInfo );
432 DUNE_THROW(NotImplemented,
"SuperLU solver not found in configure, please re-configure");
436 std::pair< int, double > p( returnInfo.iterations, matrix.averageCommTime() );
440 static std::string name ()
442 std::string name =
"ISTL SuperLU";
458 template<
class DF,
class Op >
460 :
public ISTLInverseOp< DF, Op, SuperLUSolverCaller< Op, DF > >
462 typedef ISTLInverseOp< DF, Op, SuperLUSolverCaller< Op, DF > > BaseType;
464 template<
class ... Args >
465 ISTLSuperLU ( Args && ... args ) : BaseType(
std::forward< Args >( args ) ... ) {}
475 #endif // #if HAVE_DUNE_ISTL 477 #endif // #ifndef DUNE_FEM_ISTLSOLVERS_HH
BasicParameterReader< std::function< const std::string *(const std::string &, const std::string *) > > ParameterReader
Definition: reader.hh:264
static constexpr T max(T a)
Definition: utility.hh:65
static double max(const Double &v, const double p)
Definition: double.hh:387
Definition: coordinate.hh:4
static ParameterContainer & container()
Definition: io/parameter.hh:190