Skip to content

Commit

Permalink
Solvers: move AdditionalData outside of class
Browse files Browse the repository at this point in the history
  • Loading branch information
sebproell committed Mar 4, 2023
1 parent 43c3932 commit 7d22245
Show file tree
Hide file tree
Showing 11 changed files with 383 additions and 311 deletions.
93 changes: 51 additions & 42 deletions include/deal.II/lac/eigen.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,53 @@

DEAL_II_NAMESPACE_OPEN

/**
* Standardized data struct to pipe additional data to EigenPower.
*/
struct EigenPowerAdditionalData
{
/**
* Shift parameter. This parameter allows to shift the spectrum to compute
* a different eigenvalue.
*/
double shift;
/**
* Constructor. Set the shift parameter.
*/
EigenPowerAdditionalData(const double shift = 0.)
: shift(shift)
{}
};

/**
* Standardized data struct to pipe additional data to EigenInverse.
*/
struct EigenInverseAdditionalData
{
/**
* Damping of the updated shift value.
*/
double relaxation;

/**
* Start step of adaptive shift parameter.
*/
unsigned int start_adaption;
/**
* Flag for the stopping criterion.
*/
bool use_residual;
/**
* Constructor.
*/
EigenInverseAdditionalData(double relaxation = 1.,
unsigned int start_adaption = 6,
bool use_residual = true)
: relaxation(relaxation)
, start_adaption(start_adaption)
, use_residual(use_residual)
{}
};

/**
* @addtogroup Solvers
Expand Down Expand Up @@ -62,22 +109,9 @@ class EigenPower : private SolverBase<VectorType>
using size_type = types::global_dof_index;

/**
* Standardized data struct to pipe additional data to the solver.
* An alias for the solver-specific additional data.
*/
struct AdditionalData
{
/**
* Shift parameter. This parameter allows to shift the spectrum to compute
* a different eigenvalue.
*/
double shift;
/**
* Constructor. Set the shift parameter.
*/
AdditionalData(const double shift = 0.)
: shift(shift)
{}
};
using AdditionalData = EigenPowerAdditionalData;

/**
* Constructor.
Expand Down Expand Up @@ -135,34 +169,9 @@ class EigenInverse : private SolverBase<VectorType>
using size_type = types::global_dof_index;

/**
* Standardized data struct to pipe additional data to the solver.
* An alias for the solver-specific additional data.
*/
struct AdditionalData
{
/**
* Damping of the updated shift value.
*/
double relaxation;

/**
* Start step of adaptive shift parameter.
*/
unsigned int start_adaption;
/**
* Flag for the stopping criterion.
*/
bool use_residual;
/**
* Constructor.
*/
AdditionalData(double relaxation = 1.,
unsigned int start_adaption = 6,
bool use_residual = true)
: relaxation(relaxation)
, start_adaption(start_adaption)
, use_residual(use_residual)
{}
};
using AdditionalData = EigenInverseAdditionalData;

/**
* Constructor.
Expand Down
2 changes: 1 addition & 1 deletion include/deal.II/lac/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class Vector;
* Several solvers need additional data, like the damping parameter @p omega
* of the @p SolverRichardson class or the maximum number of temporary vectors
* of @p SolverGMRES. To have a standardized way of constructing solvers,
* each solver class has a <tt>struct AdditionalData</tt> as a member, and
* each solver class has a typedef <tt>AdditionalData</tt> as a member, and
* constructors of all solver classes take such an argument. Some solvers need
* no additional data, or may not at the current time. For these solvers the
* struct @p AdditionalData is empty and calling the constructor may be done
Expand Down
75 changes: 42 additions & 33 deletions include/deal.II/lac/solver_bicgstab.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,51 @@

DEAL_II_NAMESPACE_OPEN

/**
* Standardized data struct to pipe additional data to SolverBicgstab.
*
* There are two possibilities to compute the residual: one is an estimate
* using the computed value @p tau. The other is exact computation using
* another matrix vector multiplication. This increases the costs of the
* algorithm, so it is should be set to false whenever the problem allows
* it.
*
* Bicgstab is susceptible to breakdowns, so we need a parameter telling us,
* which numbers are considered zero.
*/
template <typename VectorType>
struct SolverBicgstabAdditionalData
{
/**
* Constructor.
*
* The default is to perform an exact residual computation and breakdown
* parameter is the minimum finite value representable by the value_type of
* VectorType.
*/
explicit SolverBicgstabAdditionalData(
const bool exact_residual = true,
const double breakdown =
std::numeric_limits<typename VectorType::value_type>::min())
: exact_residual(exact_residual)
, breakdown(breakdown)
{}
/**
* Flag for exact computation of residual.
*/
bool exact_residual;
/**
* Breakdown threshold.
*/
double breakdown;
};

/**
* @addtogroup Solvers
* @{
*/


/**
* Bicgstab algorithm by van der Vorst.
*
Expand Down Expand Up @@ -80,40 +120,9 @@ class SolverBicgstab : public SolverBase<VectorType>
{
public:
/**
* There are two possibilities to compute the residual: one is an estimate
* using the computed value @p tau. The other is exact computation using
* another matrix vector multiplication. This increases the costs of the
* algorithm, so it is should be set to false whenever the problem allows
* it.
*
* Bicgstab is susceptible to breakdowns, so we need a parameter telling us,
* which numbers are considered zero.
* An alias for the solver-specific additional data.
*/
struct AdditionalData
{
/**
* Constructor.
*
* The default is to perform an exact residual computation and breakdown
* parameter is the minimum finite value representable by the value_type of
* VectorType.
*/
explicit AdditionalData(
const bool exact_residual = true,
const double breakdown =
std::numeric_limits<typename VectorType::value_type>::min())
: exact_residual(exact_residual)
, breakdown(breakdown)
{}
/**
* Flag for exact computation of residual.
*/
bool exact_residual;
/**
* Breakdown threshold.
*/
double breakdown;
};
using AdditionalData = SolverBicgstabAdditionalData<VectorType>;

/**
* Constructor.
Expand Down
31 changes: 21 additions & 10 deletions include/deal.II/lac/solver_cg.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ namespace LinearAlgebra
} // namespace LinearAlgebra
#endif

/**
* Standardized data struct to pipe additional data to a SolverCG.
* Here, it does not store anything but just exists for consistency
* with the other solver classes.
*/
struct SolverCGAdditionalData
{};

/**
* Standardized data struct to pipe additional data to a SolverFlexibleCG.
* Here, it does not store anything but just exists for consistency
* with the other solver classes.
*/
struct SolverFlexibleCGAdditionalData
{};



/** @addtogroup Solvers */
/** @{ */
Expand Down Expand Up @@ -183,12 +200,9 @@ class SolverCG : public SolverBase<VectorType>
using size_type = types::global_dof_index;

/**
* Standardized data struct to pipe additional data to the solver.
* Here, it does not store anything but just exists for consistency
* with the other solver classes.
* An alias for the solver-specific additional data.
*/
struct AdditionalData
{};
using AdditionalData = SolverCGAdditionalData;

/**
* Constructor.
Expand Down Expand Up @@ -360,12 +374,9 @@ class SolverFlexibleCG : public SolverCG<VectorType>
using size_type = types::global_dof_index;

/**
* Standardized data struct to pipe additional data to the solver.
* Here, it does not store anything but just exists for consistency
* with the other solver classes.
* An alias for the solver-specific additional data.
*/
struct AdditionalData
{};
using AdditionalData = SolverCGAdditionalData;

/**
* Constructor.
Expand Down
61 changes: 32 additions & 29 deletions include/deal.II/lac/solver_fire.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@

DEAL_II_NAMESPACE_OPEN

/**
* Standardized data struct to pipe additional data to SolverFIRE.
*/
struct SolverFIREAdditionalData
{
/**
* Constructor. By default, set the initial time step for the (forward)
* Euler integration step to 0.1, the maximum time step to 1 and the
* maximum change allowed in any variable (per iteration) to 1.
*/
explicit SolverFIREAdditionalData(const double initial_timestep = 0.1,
const double maximum_timestep = 1,
const double maximum_linfty_norm = 1);

/**
* Initial time step for the (forward) Euler integration step.
*/
const double initial_timestep;

/**
* Maximum time step for the (forward) Euler integration step.
*/
const double maximum_timestep;

/**
* Maximum change allowed in any variable of the objective function.
*/
const double maximum_linfty_norm;
};

/**
* @addtogroup Solvers
Expand Down Expand Up @@ -92,34 +121,9 @@ class SolverFIRE : public SolverBase<VectorType>
{
public:
/**
* Standardized data struct to pipe additional data to the solver.
* An alias for the solver-specific additional data.
*/
struct AdditionalData
{
/**
* Constructor. By default, set the initial time step for the (forward)
* Euler integration step to 0.1, the maximum time step to 1 and the
* maximum change allowed in any variable (per iteration) to 1.
*/
explicit AdditionalData(const double initial_timestep = 0.1,
const double maximum_timestep = 1,
const double maximum_linfty_norm = 1);

/**
* Initial time step for the (forward) Euler integration step.
*/
const double initial_timestep;

/**
* Maximum time step for the (forward) Euler integration step.
*/
const double maximum_timestep;

/**
* Maximum change allowed in any variable of the objective function.
*/
const double maximum_linfty_norm;
};
using AdditionalData = SolverFIREAdditionalData;

/**
* Constructor.
Expand Down Expand Up @@ -187,8 +191,7 @@ class SolverFIRE : public SolverBase<VectorType>

#ifndef DOXYGEN

template <typename VectorType>
SolverFIRE<VectorType>::AdditionalData::AdditionalData(
SolverFIREAdditionalData::SolverFIREAdditionalData(
const double initial_timestep,
const double maximum_timestep,
const double maximum_linfty_norm)
Expand Down

0 comments on commit 7d22245

Please sign in to comment.