Page MenuHomec4science

reduced_system_solver.hpp
No OneTemporary

File Metadata

Created
Thu, Sep 5, 01:40

reduced_system_solver.hpp

/*-------------------------------------------------------
- Module : specmicp
- File : reduced_system_solver.hpp
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget <fabieng@princeton.edu>, Princeton University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Princeton University nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------*/
#ifndef SPECMICP_SPECMICP_REDUCEDSYSTEMSOLVER_HPP
#define SPECMICP_SPECMICP_REDUCEDSYSTEMSOLVER_HPP
#include "database.hpp"
#include "reduced_system.hpp"
#include "reduced_system_solver_structs.hpp"
//! \file reduced_system_solver.hpp Solve a reduced system
namespace specmicp {
// forward declaration
class EquilibriumState;
//! \brief Solver a reduced system
//!
//! Take care of possibly non-existing component in the system
class ReducedSystemSolver
{
public:
//! Default constructor - you need to use another method to initialize it correctly
ReducedSystemSolver() {}
ReducedSystemSolver(RawDatabasePtr data,
const Vector& totconc,
const SimulationBox& simulbox,
ReducedSystemSolverOptions options=ReducedSystemSolverOptions()
);
ReducedSystemSolver(RawDatabasePtr data,
const Vector& totconc,
ReducedSystemSolverOptions options=ReducedSystemSolverOptions()
);
ReducedSystemSolver(RawDatabasePtr data,
const Vector& totconc,
const EquilibriumState& previous_solution,
ReducedSystemSolverOptions options=ReducedSystemSolverOptions()
);
ReducedSystemSolver(RawDatabasePtr data,
const Vector& totconc,
const SimulationBox& simulbox,
const EquilibriumState& previous_solution,
ReducedSystemSolverOptions options=ReducedSystemSolverOptions()
);
//! \brief solve the problem using initial guess x
//!
//! \param[in,out] x in -> initial guess, out -> solution
//! \param init if true, the algorithm guess a starting point
micpsolver::MiCPPerformance solve(Vector& x, bool init=false);
//! \brief Return the system used for the computation
std::shared_ptr<ReducedSystem> get_system() {return m_system;}
//! \brief Return the solution in a manageable form
EquilibriumState get_solution(const Eigen::VectorXd& x);
//! \brief Return a const reference to the options
const ReducedSystemSolverOptions& get_options() const {return m_options;}
//! \brief Return a reference to the options
ReducedSystemSolverOptions& get_options() {return m_options;}
private:
//! \brief set up the true variable vector
void set_true_variable_vector(const Vector& x);
//! \brief set up the true solution vector
//!
//! add zero components
void set_return_vector(Vector& x);
//! \brief solve the problem
micpsolver::MiCPPerformance solve();
ReducedSystemSolverOptions m_options; //! The options
RawDatabasePtr m_data; //! The raw database
std::shared_ptr<ReducedSystem> m_system; //! The system to solve
Vector m_var; //! Copy of the solution vector
};
//! \brief Solve a reduced system, function provided for convenience
inline micpsolver::MiCPPerformance solve_reduced_system(std::shared_ptr<database::DataContainer> data,
Vector& totconc,
Vector& x)
{
return ReducedSystemSolver(data, totconc).solve(x);
}
} // end namespace specmicp
#endif // SPECMICP_SPECMICP_REDUCEDSYSTEMSOLVER_HPP

Event Timeline