Commit 3975e131 authored by David Bommes's avatar David Bommes
Browse files

added NonLinearSolvers and adapted cmake build system

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@54 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent b9a37aa9
...@@ -39,8 +39,43 @@ endif () ...@@ -39,8 +39,43 @@ endif ()
#added by CAT #added by CAT
find_package (SUITESPARSE) find_package (SUITESPARSE)
if (NOT SUITESPARSE_FOUND ) if (SUITESPARSE_FOUND )
message (FATAL_ERROR "SUITESPARSE not found!") set (COMISO_SUITESPARSE_CONFIG_FILE_SETTINGS "#define COMISO_SUITESPARSE_AVAILABLE 1" )
else ()
message (STATUS "SUITESPARSE not found!")
set (COMISO_SUITESPARSE_CONFIG_FILE_SETTINGS "#define COMISO_SUITESPARSE_AVAILABLE 0" )
endif ()
find_package (MPI)
if (MPI_FOUND )
set (COMISO_MPI_CONFIG_FILE_SETTINGS "#define COMISO_MPI_AVAILABLE 1" )
else ()
message (STATUS "MPI not found!")
set (COMISO_MPI_CONFIG_FILE_SETTINGS "#define COMISO_MPI_AVAILABLE 0" )
endif ()
find_package (PETSC)
if (PETSC_FOUND )
set (COMISO_PETSC_CONFIG_FILE_SETTINGS "#define COMISO_PETSC_AVAILABLE 1" )
else ()
message (STATUS "PETSC not found!")
set (COMISO_PETSC_CONFIG_FILE_SETTINGS "#define COMISO_PETSC_AVAILABLE 0" )
endif ()
find_package (TAO)
if (TAO_FOUND )
set (COMISO_TAO_CONFIG_FILE_SETTINGS "#define COMISO_TAO_AVAILABLE 1" )
else ()
message (STATUS "PETSC not found!")
set (COMISO_TAO_CONFIG_FILE_SETTINGS "#define COMISO_TAO_AVAILABLE 0" )
endif ()
find_package (IPOPT)
if (IPOPT_FOUND )
set (COMISO_IPOPT_CONFIG_FILE_SETTINGS "#define COMISO_IPOPT_AVAILABLE 1" )
else ()
message (STATUS "IPOPT not found!")
set (COMISO_IPOPT_CONFIG_FILE_SETTINGS "#define COMISO_IPOPT_AVAILABLE 0" )
endif () endif ()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/factored_solver/CMakeLists.txt" ) if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/factored_solver/CMakeLists.txt" )
...@@ -60,8 +95,6 @@ if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/small_factored_example/CMakeLists.txt" ...@@ -60,8 +95,6 @@ if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/small_factored_example/CMakeLists.txt"
add_subdirectory (Examples/small_factored_example) add_subdirectory (Examples/small_factored_example)
endif() endif()
include_directories ( include_directories (
.. ..
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
...@@ -69,6 +102,10 @@ include_directories ( ...@@ -69,6 +102,10 @@ include_directories (
${Boost_INCLUDE_DIR} ${Boost_INCLUDE_DIR}
${GMM_INCLUDE_DIR} ${GMM_INCLUDE_DIR}
${SUITESPARSE_INCLUDE_DIRS} ${SUITESPARSE_INCLUDE_DIRS}
${MPI_INCLUDE_PATH}
${PETSC_INCLUDE_DIRS}
${TAO_INCLUDE_DIRS}
${IPOPT_INCLUDE_DIR}
) )
# generate dllexport macros on windows # generate dllexport macros on windows
...@@ -79,12 +116,17 @@ endif () ...@@ -79,12 +116,17 @@ endif ()
link_directories ( link_directories (
${SUITESPARSE_LIBRARY_DIRS} ${SUITESPARSE_LIBRARY_DIRS}
# ${MPI_LIBRARY_DIR}
${PETSC_LIBRARY_DIR}
${TAO_LIBRARY_DIR}
${IPOPT_LIBRARY_DIR}
) )
# source code directories # source code directories
set (directories set (directories
. .
Solver Solver
NSolver
Config Config
Utils Utils
QtWidgets QtWidgets
...@@ -142,26 +184,17 @@ else(NOT APPLE) ...@@ -142,26 +184,17 @@ else(NOT APPLE)
${QT_LIBRARIES} ${QT_LIBRARIES}
${SUITESPARSE_LIBRARIES} ${SUITESPARSE_LIBRARIES}
${BLAS_LIBRARIES} ${BLAS_LIBRARIES}
${PETSC_LIBRARIES}
${TAO_LIBRARIES}
${MPI_LIBRARIES}
${IPOPT_LIBRARIES}
) )
endif(NOT APPLE) endif(NOT APPLE)
# display results # display results
acg_print_configure_header (COMISO "CoMISo") acg_print_configure_header (COMISO "CoMISo")
# write config file
if ( SUITESPARSE_FOUND )
set (COMISO_SUITESPARSE_COFIG_FILE_SETTINGS "#define COMISO_ENABLE_SUITESPARSE" )
else ()
set (COMISO_SUITESPARSE_COFIG_FILE_SETTINGS "#define COMISO_DISABLE_SUITESPARSE" )
endif ()
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/Config/config.hh.in" configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/Config/config.hh.in"
"${CMAKE_CURRENT_SOURCE_DIR}/Config/config.hh" @ONLY IMMEDIATE) "${CMAKE_CURRENT_SOURCE_DIR}/Config/config.hh" @ONLY IMMEDIATE)
// Build time dependencies for CoMiso // Build time dependencies for CoMiso
@COMISO_SUITESPARSE_COFIG_FILE_SETTINGS@ @COMISO_SUITESPARSE_CONFIG_FILE_SETTINGS@
@COMISO_MPI_CONFIG_FILE_SETTINGS@
@COMISO_PETSC_CONFIG_FILE_SETTINGS@
@COMISO_TAO_CONFIG_FILE_SETTINGS@
@COMISO_IPOPT_CONFIG_FILE_SETTINGS@
include (ACGCommon) include (ACGCommon)
find_package(CoMISo) find_package(CoMISo)
find_package(SUITESPARSE)
find_package(MPI)
include_directories ( include_directories (
.. ..
...@@ -7,9 +10,13 @@ include_directories ( ...@@ -7,9 +10,13 @@ include_directories (
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${COMISO_INCLUDE_DIR} ${COMISO_INCLUDE_DIR}
${SUITESPARSE_INCLUDE_DIRS}
) )
link_directories ( link_directories (
${SUITESPARSE_LIBRARY_DIRS}
${TAO_LIBRARY_DIR}
${PETSC_LIBRARY_DIR}
) )
# source code directories # source code directories
...@@ -33,8 +40,15 @@ else () ...@@ -33,8 +40,15 @@ else ()
acg_add_executable (factored_solver ${sources} ${headers} ) acg_add_executable (factored_solver ${sources} ${headers} )
endif () endif ()
# enable rpath linking
set_target_properties(factored_solver PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1)
target_link_libraries (factored_solver target_link_libraries (factored_solver
CoMISo CoMISo
${SUITESPARSE_LIBRARIES}
${MPI_LIBRARY}
${PETSC_LIBRARY}
${TAO_LIBRARY}
) )
if (APPLE) if (APPLE)
......
include (ACGCommon) include (ACGCommon)
find_package(CoMISo) find_package(CoMISo)
find_package(SUITESPARSE)
find_package(MPI)
include_directories ( include_directories (
.. ..
...@@ -7,11 +9,13 @@ include_directories ( ...@@ -7,11 +9,13 @@ include_directories (
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${COMISO_INCLUDE_DIR} ${COMISO_INCLUDE_DIR}
${SUITESPARSE_INCLUDE_DIRS}
) )
link_directories ( link_directories (
# ${CMAKE_CURRENT_BINARY_DIR}/Build/lib/CoMISo ${SUITESPARSE_LIBRARY_DIRS}
#/data/home1/zimmer/projects/ConstrainedSolver/package/CoMISo/build/Build/lib/CoMISo ${TAO_LIBRARY_DIR}
${PETSC_LIBRARY_DIR}
) )
# source code directories # source code directories
...@@ -35,8 +39,15 @@ else () ...@@ -35,8 +39,15 @@ else ()
acg_add_executable (quadratic_solver ${sources} ${headers} ) acg_add_executable (quadratic_solver ${sources} ${headers} )
endif () endif ()
# enable rpath linking
set_target_properties(quadratic_solver PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1)
target_link_libraries (quadratic_solver target_link_libraries (quadratic_solver
CoMISo CoMISo
${SUITESPARSE_LIBRARIES}
${MPI_LIBRARY}
${PETSC_LIBRARY}
${TAO_LIBRARY}
) )
if (APPLE) if (APPLE)
...@@ -49,4 +60,3 @@ if (APPLE) ...@@ -49,4 +60,3 @@ if (APPLE)
MACOSX_BUNDLE_INFO_STRING "CoMISo quadratic_solver" MACOSX_BUNDLE_INFO_STRING "CoMISo quadratic_solver"
) )
endif () endif ()
include (ACGCommon) include (ACGCommon)
find_package(CoMISo) find_package(CoMISo)
find_package(SUITESPARSE)
find_package(MPI)
include_directories ( include_directories (
.. ..
...@@ -7,9 +9,13 @@ include_directories ( ...@@ -7,9 +9,13 @@ include_directories (
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${COMISO_INCLUDE_DIR} ${COMISO_INCLUDE_DIR}
${SUITESPARSE_INCLUDE_DIRS}
) )
link_directories ( link_directories (
${SUITESPARSE_LIBRARY_DIRS}
${TAO_LIBRARY_DIR}
${PETSC_LIBRARY_DIR}
) )
# source code directories # source code directories
...@@ -33,8 +39,15 @@ else () ...@@ -33,8 +39,15 @@ else ()
acg_add_executable (small_factored_solver ${sources} ${headers} ) acg_add_executable (small_factored_solver ${sources} ${headers} )
endif () endif ()
# enable rpath linking
set_target_properties(small_factored_solver PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1)
target_link_libraries (small_factored_solver target_link_libraries (small_factored_solver
CoMISo CoMISo
${SUITESPARSE_LIBRARIES}
${MPI_LIBRARY}
${PETSC_LIBRARY}
${TAO_LIBRARY}
) )
if (APPLE) if (APPLE)
...@@ -48,3 +61,4 @@ if (APPLE) ...@@ -48,3 +61,4 @@ if (APPLE)
) )
endif () endif ()
include (ACGCommon) include (ACGCommon)
find_package(CoMISo) find_package(CoMISo)
find_package(SUITESPARSE)
find_package(MPI)
include_directories ( include_directories (
.. ..
...@@ -7,9 +9,13 @@ include_directories ( ...@@ -7,9 +9,13 @@ include_directories (
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${COMISO_INCLUDE_DIR} ${COMISO_INCLUDE_DIR}
${SUITESPARSE_INCLUDE_DIRS}
) )
link_directories ( link_directories (
${SUITESPARSE_LIBRARY_DIRS}
${TAO_LIBRARY_DIR}
${PETSC_LIBRARY_DIR}
) )
# source code directories # source code directories
...@@ -33,8 +39,15 @@ else () ...@@ -33,8 +39,15 @@ else ()
acg_add_executable (small_quadratic_solver ${sources} ${headers} ) acg_add_executable (small_quadratic_solver ${sources} ${headers} )
endif () endif ()
# enable rpath linking
set_target_properties(small_quadratic_solver PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1)
target_link_libraries (small_quadratic_solver target_link_libraries (small_quadratic_solver
CoMISo CoMISo
${SUITESPARSE_LIBRARIES}
${MPI_LIBRARY}
${PETSC_LIBRARY}
${TAO_LIBRARY}
) )
if (APPLE) if (APPLE)
...@@ -48,3 +61,4 @@ if (APPLE) ...@@ -48,3 +61,4 @@ if (APPLE)
) )
endif () endif ()
//=============================================================================
//
// CLASS LinearConstraintHandlerElimination - IMPLEMENTATION TEMPLATES
//
//=============================================================================
//== INCLUDES =================================================================
#include "LinearConstraintHandlerElimination.hh"
//== NAMESPACES ===============================================================
namespace ACG {
//== IMPLEMENTATION ==========================================================
void
LinearConstraintHandlerElimination::
initialize_identity(int _n)
{
n_ = _n;
n_red_ = _n;
m_ = 0;
b_.resize(n_);
gmm::resize(C_, n_, n_);
gmm::resize(Ct_, n_, n_);
gmm::clear(C_);
gmm::clear(Ct_);
for(int i=0; i<n_; ++i)
{
b_[i] = 0.0;
Ct_(i,i) = 1.0;
C_(i,i) = 1.0;
}
}
//-----------------------------------------------------------------------------
void
LinearConstraintHandlerElimination::
initialize( const std::vector<double>& _c)
{
if( _c.size() )
initialize( (double*) &(_c[0]));
}
//-----------------------------------------------------------------------------
void
LinearConstraintHandlerElimination::
initialize( double* _c)
{
// TODO
}
//-----------------------------------------------------------------------------
void
LinearConstraintHandlerElimination::
transform_x( const std::vector<double>& _x, std::vector<double>& _xC)
{
_xC.resize(n_red_);
if( _x.size() && _xC.size())
transform_x((double*)&(_x[0]), &(_xC[0]));
}
//-----------------------------------------------------------------------------
void
LinearConstraintHandlerElimination::
transform_x( double* _x, double* _xC)
{
// directly exploit orthogonality of QR-factorization
// _xC = Ct_*(_x-b_)
Vtemp_.resize(n_);
gmm::add(VectorPT(_x,n_), gmm::scaled(b_,-1.0), Vtemp_);
gmm::mult(Ct_,Vtemp_, VectorPT(_xC,n_red_));
// // set up least squares problem
// // Ct (_x - b_) = CtC _xC
//
// Vtemp_.resize(n_);
// Vtemp2_.resize(n_red_);
// gmm::add(VectorPT(_x,n_), gmm::scaled(b_,-1.0), Vtemp_);
// gmm::mult(Ct_,Vtemp_, Vtemp2_);
//
// // solve least squares problem
// if( n_red_)
// chol_CtC_.solve(_xC, (double*)(&(Vtemp2_[0])));
}
//-----------------------------------------------------------------------------
void
LinearConstraintHandlerElimination::
inv_transform_x( const std::vector<double>& _xC, std::vector<double>& _x)
{
_x.resize(n_);
if( _x.size())
inv_transform_x( (double*)&(_xC[0]), &(_x[0]));
}
//-----------------------------------------------------------------------------
void
LinearConstraintHandlerElimination::
inv_transform_x( double* _xC, double* _x)
{
gmm::copy(b_, VectorPT(_x, n_));
gmm::mult_add(C_, VectorPT(_xC, n_red_), VectorPT(_x, n_));
}
//-----------------------------------------------------------------------------
void
LinearConstraintHandlerElimination::
transform_gradient( const std::vector<double>& _g, std::vector<double>& _gC)
{
_gC.resize(n_red_);
if( _g.size() && _gC.size())
transform_gradient( (double*)&(_g[0]), &(_gC[0]));
}
//-----------------------------------------------------------------------------
void
LinearConstraintHandlerElimination::
transform_gradient( double* _g, double* _gC)
{
gmm::mult( Ct_, VectorPT(_g, n_), VectorPT(_gC, n_red_));
}
//-----------------------------------------------------------------------------
void
LinearConstraintHandlerElimination::
transform_hessian( const RMatrix& _H, RMatrix& _HC)
{
// resize and clear matrix
gmm::resize(_HC, n_red_, n_red_);
gmm::clear(_HC);
gmm::resize(Mtemp_, n_, n_red_);
gmm::mult(_H,C_, Mtemp_);
gmm::mult(Ct_, Mtemp_, _HC);
}
//-----------------------------------------------------------------------------
//=============================================================================
} // namespace ACG
//=============================================================================
//=============================================================================
//
// CLASS LinearConstraintHandlerElimination
//
//=============================================================================
#ifndef ACG_LINEARCONSTRAINTHANDLERELIMINATION_HH
#define ACG_LINEARCONSTRAINTHANDLERELIMINATION_HH
//== INCLUDES =================================================================
#include <iostream>
#include <gmm/gmm.h>
//== FORWARDDECLARATIONS ======================================================
//== NAMESPACES ===============================================================
namespace ACG {
//== CLASS DEFINITION =========================================================
/** \class LinearConstraintHandler LinearConstraintHandler.hh <ACG/.../LinearConstraintHandler.hh>
Brief Description.
A more elaborate description follows.
*/
class LinearConstraintHandlerElimination
{
public:
typedef gmm::col_matrix< gmm::wsvector< double> > CMatrix;
typedef gmm::row_matrix< gmm::wsvector< double> > RMatrix;
// use c-arrays as vectors for gmm
typedef gmm::array1D_reference<double*> VectorPT;