Commit 1e596ab8 authored by David Bommes's avatar David Bommes

added FEM stuff

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@269 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent ccc15dd5
......@@ -209,6 +209,15 @@ else ()
set (COMISO_EIGEN3_CONFIG_FILE_SETTINGS "#define COMISO_EIGEN3_AVAILABLE 0" )
endif ()
find_package (DCO)
if (DCO_FOUND )
set (COMISO_DCO_CONFIG_FILE_SETTINGS "#define COMISO_DCO_AVAILABLE 1" )
list( APPEND COMISO_INCLUDE_DIRECTORIES ${DCO_INCLUDE_DIR} )
else ()
message (STATUS "DCO not found!")
set (COMISO_DCO_CONFIG_FILE_SETTINGS "#define COMISO_DCO_AVAILABLE 0" )
endif ()
find_package (Taucs)
if (TAUCS_FOUND )
set (COMISO_TAUCS_CONFIG_FILE_SETTINGS "#define COMISO_TAUCS_AVAILABLE 1" )
......@@ -403,16 +412,23 @@ endif()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/small_adolc/CMakeLists.txt" )
add_subdirectory (Examples/small_adolc)
endif()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/small_dco/CMakeLists.txt" )
add_subdirectory (Examples/small_dco)
endif()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/vector1_adolc/CMakeLists.txt" )
add_subdirectory (Examples/vector1_adolc)
endif()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/vector2_adolc/CMakeLists.txt" )
add_subdirectory (Examples/vector2_adolc)
endif()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/small_linear_problem/CMakeLists.txt" )
add_subdirectory (Examples/small_linear_problem)
endif()
add_subdirectory (Examples/small_linear_problem)
endif()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/crossfield3d/CMakeLists.txt" )
add_subdirectory (Examples/crossfield3d)
endif()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/crossfield3d/CMakeLists.txt" )
add_subdirectory (Examples/crossfield3d_dco)
endif()
if( EXISTS "${CMAKE_SOURCE_DIR}/Examples/small_finite_element/CMakeLists.txt" )
add_subdirectory (Examples/small_finite_element)
endif()
......@@ -20,5 +20,6 @@
@COMISO_ARPACK_CONFIG_FILE_SETTINGS@
@COMISO_CPLEX_CONFIG_FILE_SETTINGS@
@COMISO_EIGEN3_CONFIG_FILE_SETTINGS@
@COMISO_DCO_CONFIG_FILE_SETTINGS@
include (CoMISoExample)
acg_add_executable (small_finite_element ${sources} ${headers} )
# enable rpath linking
set_target_properties(small_finite_element PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1)
target_link_libraries (small_finite_element
CoMISo
${COMISO_LINK_LIBRARIES}
)
/*===========================================================================*\
* *
* CoMISo *
* Copyright (C) 2008-2009 by Computer Graphics Group, RWTH Aachen *
* www.rwth-graphics.de *
* *
*---------------------------------------------------------------------------*
* This file is part of CoMISo. *
* *
* CoMISo is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* CoMISo is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with CoMISo. If not, see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
#include <CoMISo/Config/config.hh>
#include <CoMISo/Utils/StopWatch.hh>
#include <vector>
#include <CoMISo/NSolver/FiniteElementProblem.hh>
#include <CoMISo/NSolver/NPDerivativeChecker.hh>
#include <CoMISo/NSolver/IPOPTSolver.hh>
// create a simple finite element (x-y)^2
class SimpleElement
{
public:
// define dimensions
const static int NV = 2;
const static int NC = 0;
typedef Eigen::Matrix<size_t,NV,1> VecI;
typedef Eigen::Matrix<double,NV,1> VecV;
typedef Eigen::Matrix<double,NC,1> VecC;
typedef Eigen::Triplet<double> Triplet;
inline double eval_f (const VecV& _x, const VecC& _c) const
{
return std::pow(_x[0]-_x[1],2);
}
inline void eval_gradient(const VecV& _x, const VecC& _c, VecV& _g) const
{
_g[0] = 2.0*(_x[0]-_x[1]);
_g[1] = -_g[0];
}
inline void eval_hessian (const VecV& _x, const VecC& _c, std::vector<Triplet>& _triplets) const
{
_triplets.clear();
_triplets.push_back(Triplet(0,0,2));
_triplets.push_back(Triplet(1,1,2));
_triplets.push_back(Triplet(0,1,-2));
_triplets.push_back(Triplet(1,0,-2));
}
};
// create a simple finite element (x-c)^2
class SimpleElement2
{
public:
// define dimensions
const static int NV = 1;
const static int NC = 1;
typedef Eigen::Matrix<size_t,NV,1> VecI;
typedef Eigen::Matrix<double,NV,1> VecV;
typedef Eigen::Matrix<double,NC,1> VecC;
typedef Eigen::Triplet<double> Triplet;
inline double eval_f(const VecV& _x, const VecC& _c) const
{
return std::pow(_x[0]-_c[0],2);
}
inline void eval_gradient(const VecV& _x, const VecC& _c, VecV& _g) const
{
_g[0] = 2.0*(_x[0]-_c[0]);
}
inline void eval_hessian (const VecV& _x, const VecC& _c, std::vector<Triplet>& _triplets) const
{
_triplets.clear();
_triplets.push_back(Triplet(0,0,2));
}
};
//------------------------------------------------------------------------------------------------------
// Example main
int main(void)
{
std::cout << "---------- 1) Get an instance of a FiniteElementProblem..." << std::endl;
// first create sets of different finite elements
COMISO::FiniteElementSet<SimpleElement> fe_set;
fe_set.instances().add_element(SimpleElement::VecI(0,1), SimpleElement::VecC());
fe_set.instances().add_element(SimpleElement::VecI(1,2), SimpleElement::VecC());
// second set for boundary conditions
COMISO::FiniteElementSet<SimpleElement2> fe_set2;
SimpleElement2::VecI vi;
SimpleElement2::VecV v;
vi[0] = 0;
v [0] = 0;
fe_set2.instances().add_element(vi, v);
vi[0] = 2;
v [0] = 2;
fe_set2.instances().add_element(vi, v);
// then create finite element problem and add sets
COMISO::FiniteElementProblem fe_problem(3);
fe_problem.add_set(&fe_set );
fe_problem.add_set(&fe_set2);
std::cout << "---------- 2) (optional for debugging) Check derivatives of problem..." << std::endl;
COMISO::NPDerivativeChecker npd;
npd.check_all(&fe_problem);
// check if IPOPT solver available in current configuration
#if( COMISO_IPOPT_AVAILABLE)
std::cout << "---------- 3) Get IPOPT solver... " << std::endl;
COMISO::IPOPTSolver ipsol;
std::cout << "---------- 4) Solve..." << std::endl;
// there are no constraints -> provide an empty vector
std::vector<COMISO::NConstraintInterface*> constraints;
ipsol.solve(&fe_problem, constraints);
#endif
// print result
for(unsigned int i=0; i<fe_problem.x().size(); ++i)
std::cerr << "x[" << i << "] = " << fe_problem.x()[i] << std::endl;
return 0;
}
......@@ -76,6 +76,11 @@ if(EIGEN3_FOUND)
list( APPEND COMISO_INCLUDE_DIRECTORIES ${EIGEN3_INCLUDE_DIR})
endif()
#FIND_PACKAGE( DCO)
if(DCO_FOUND)
list( APPEND COMISO_INCLUDE_DIRECTORIES ${DCO_INCLUDE_DIR})
endif()
if (CGAL_FOUND)
list( APPEND COMISO_INCLUDE_DIRECTORIES ${CGAL_INCLUDE_DIR} )
list( APPEND COMISO_LINK_DIRECTORIES ${CGAL_LIBRARY_DIR} )
......
......@@ -12,10 +12,12 @@ IF (COMISO_INCLUDE_DIR)
SET(COMISO_FIND_QUIETLY TRUE)
ENDIF (COMISO_INCLUDE_DIR)
# Find CoMISo config file
FIND_PATH( COMISO_INCLUDE_DIR CoMISo/Config/config.hh
PATHS "${CMAKE_SOURCE_DIR}/../" "${CMAKE_SOURCE_DIR}/libs/" )
PATHS "${CMAKE_SOURCE_DIR}"
"${CMAKE_SOURCE_DIR}/libs/"
"${CMAKE_SOURCE_DIR}/../" )
if ( COMISO_INCLUDE_DIR )
......@@ -207,6 +209,20 @@ if ( COMISO_INCLUDE_DIR )
endif()
STRING(REGEX MATCH "\#define COMISO_DCO_AVAILABLE 1" COMISO_DCO_BUILD_TIME_AVAILABLE ${CURRENT_COMISO_CONFIG} )
if ( COMISO_DCO_BUILD_TIME_AVAILABLE )
find_package(DCO)
if ( NOT DCO_FOUND )
message(ERROR "COMISO configured with DCO but DCO not available")
endif()
list (APPEND COMISO_OPT_DEPS “DCO”)
endif()
add_definitions (-DCOMISODLL -DUSECOMISO )
endif(COMISO_INCLUDE_DIR)
......
# - Try to find DCO
# Once done this will define
# DCO_FOUND - System has DCO
# DCO_INCLUDE_DIRS - The DCO include directories
if (DCO_INCLUDE_DIR)
# in cache already
set(DCO_FOUND TRUE)
set(DCO_INCLUDE_DIRS "${DCO_INCLUDE_DIR}" )
else (DCO_INCLUDE_DIR)
find_path( DCO_INCLUDE_DIR
NAMES dco.hpp
PATHS $ENV{DCO_DIR}
/usr/include/dco
/usr/local/include
/usr/local/include/dco/
/opt/local/include/dco/
)
set(DCO_INCLUDE_DIRS "${DCO_INCLUDE_DIR}" )
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set DCO_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(DCO DEFAULT_MSG
DCO_INCLUDE_DIR)
mark_as_advanced(DCO_INCLUDE_DIR)
endif(DCO_INCLUDE_DIR)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment