Page MenuHomec4science

driver.hpp
No OneTemporary

File Metadata

Created
Sat, Nov 2, 11:45

driver.hpp

#ifndef SPECMICP_DFPMSOLVER_DRIVER_HPP
#define SPECMICP_DFPMSOLVER_DRIVER_HPP
#include "common.hpp"
namespace specmicp {
namespace dfpmsolver {
//! \brief Base class for a driver
//!
//! Options should be a subclass of DriverOptions
//! Performance should be a subclass of DriverPerformance
//!
template <class Program, class Options, class Performance>
class Driver
{
public:
Driver(Program& the_program):
m_program(the_program),
m_options(),
m_scaling_is_initialized(false)
{
}
Driver(Program& the_program,
Options some_options):
m_program(the_program),
m_options(some_options),
m_scaling_is_initialized(false)
{
}
// basic program management
// ------------------------
//! Return the program
Program& program() {return m_program;}
//! Return the number of equations
index_t get_neq() {return m_program.get_neq();}
// common process
// --------------
//! \brief rescale the update if needed
//!
//! Return the step length
scalar_t is_step_too_long(Vector& update);
// options
// -------
//! \brief Return a read/write reference to the options
Options& get_options() {return m_options;}
//! \brief Return a read-only reference to the options
const Options& get_options() const {return m_options;}
// performance
// -----------
//! \brief Return a const reference to the performance
const Performance& get_perfs() const {return m_performance;}
// Scaling
// -------
void initialize_scaling() {
if (not m_scaling_is_initialized)
{
m_scaling.resize(get_neq());
m_scaling.setOnes();
}
}
void set_scaling(const Vector& scale) {
specmicp_assert(scale.rows() == get_neq());
m_scaling = scale;
m_scaling_is_initialized = true;
}
const Vector& scaling() const {return m_scaling;}
scalar_t scaling(index_t id_eq) const {return m_scaling(id_eq);}
protected:
//! \brief Read/write access to the performance
Performance& get_perfs() {return m_performance;}
private:
Program& m_program; //!< The program
Performance m_performance; //!< The performance
Options m_options; //!< The options
Vector m_scaling; //!< Scaling factor
bool m_scaling_is_initialized;
};
} // end namespace dfpmsolver
} // end namespace specmicp
// implementation
// ==============
#include "driver.inl"
#endif // SPECMICP_DFPMSOLVER_DRIVER_HPP

Event Timeline