From 4b5e387da444eceb1463ee36ead6d3b53e879eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Thu, 26 Dec 2013 10:51:55 +0100 Subject: [PATCH] extend debug facilities with state writing and add externalisation to make it compile with a decent amout of memory --- src/Mod/Assembly/App/CMakeLists.txt | 17 +- src/Mod/Assembly/App/Constraint.h | 2 +- src/Mod/Assembly/App/ConstraintGroup.h | 2 +- src/Mod/Assembly/App/ItemAssembly.cpp | 13 +- src/Mod/Assembly/App/ItemAssembly.h | 3 +- src/Mod/Assembly/App/ItemPart.h | 2 +- src/Mod/Assembly/App/{ => Solver}/Solver.h | 15 ++ .../Assembly/App/Solver/solver_3d_ext1.cpp | 30 ++++ .../Assembly/App/Solver/solver_3d_ext2.cpp | 25 +++ .../Assembly/App/Solver/solver_3d_ext3.cpp | 25 +++ .../Assembly/App/Solver/solver_state_ext1.cpp | 44 +++++ .../Assembly/App/Solver/solver_state_ext2.cpp | 40 +++++ src/Mod/Assembly/App/opendcm/core.hpp | 3 + .../Assembly/App/opendcm/core/equations.hpp | 8 +- .../App/opendcm/core/imp/equations_imp.hpp | 6 - .../App/opendcm/core/imp/kernel_imp.hpp | 1 - .../App/opendcm/core/imp/system_imp.hpp | 83 --------- src/Mod/Assembly/App/opendcm/core/system.hpp | 88 ++++++++++ .../App/opendcm/core/transformation.hpp | 4 +- .../App/opendcm/module3d/alignment.hpp | 2 +- .../App/opendcm/module3d/coincident.hpp | 2 +- .../App/opendcm/module3d/distance.hpp | 1 + .../App/opendcm/module3d/imp/state_imp.hpp | 104 ++++++++---- .../App/opendcm/moduleState/defines.hpp | 2 +- .../moduleState/edge_vertex_generator_imp.hpp | 58 ------- .../moduleState/edge_vertex_parser_imp.hpp | 56 ------ .../App/opendcm/moduleState/generator_imp.hpp | 73 -------- .../moduleState/imp/object_parser_imp.hpp | 14 +- .../moduleState/object_generator_imp.hpp | 59 ------- .../opendcm/moduleState/object_parser_imp.hpp | 78 --------- .../App/opendcm/moduleState/parser_imp.hpp | 74 -------- .../moduleState/property_generator_imp.hpp | 43 ----- .../moduleState/property_parser_imp.hpp | 81 --------- .../App/opendcm/moduleState/traits_impl.hpp | 160 ------------------ src/Mod/Assembly/App/opendcm/modulestate.hpp | 16 +- .../Assembly/Gui/TaskAssemblyConstraints.h | 2 +- 36 files changed, 396 insertions(+), 840 deletions(-) rename src/Mod/Assembly/App/{ => Solver}/Solver.h (96%) create mode 100644 src/Mod/Assembly/App/Solver/solver_3d_ext1.cpp create mode 100644 src/Mod/Assembly/App/Solver/solver_3d_ext2.cpp create mode 100644 src/Mod/Assembly/App/Solver/solver_3d_ext3.cpp create mode 100644 src/Mod/Assembly/App/Solver/solver_state_ext1.cpp create mode 100644 src/Mod/Assembly/App/Solver/solver_state_ext2.cpp delete mode 100644 src/Mod/Assembly/App/opendcm/moduleState/edge_vertex_generator_imp.hpp delete mode 100644 src/Mod/Assembly/App/opendcm/moduleState/edge_vertex_parser_imp.hpp delete mode 100644 src/Mod/Assembly/App/opendcm/moduleState/generator_imp.hpp delete mode 100644 src/Mod/Assembly/App/opendcm/moduleState/object_generator_imp.hpp delete mode 100644 src/Mod/Assembly/App/opendcm/moduleState/object_parser_imp.hpp delete mode 100644 src/Mod/Assembly/App/opendcm/moduleState/parser_imp.hpp delete mode 100644 src/Mod/Assembly/App/opendcm/moduleState/property_generator_imp.hpp delete mode 100644 src/Mod/Assembly/App/opendcm/moduleState/property_parser_imp.hpp delete mode 100644 src/Mod/Assembly/App/opendcm/moduleState/traits_impl.hpp diff --git a/src/Mod/Assembly/App/CMakeLists.txt b/src/Mod/Assembly/App/CMakeLists.txt index bcbd962e4..8d8613830 100644 --- a/src/Mod/Assembly/App/CMakeLists.txt +++ b/src/Mod/Assembly/App/CMakeLists.txt @@ -58,6 +58,15 @@ SET(Module_SRCS ) SOURCE_GROUP("Module" FILES ${Module_SRCS}) + +set(Solver_SRC Solver/solver_3d_ext1.cpp + Solver/solver_3d_ext2.cpp + Solver/solver_3d_ext3.cpp + Solver/solver_state_ext1.cpp + Solver/solver_state_ext2.cpp +) +SOURCE_GROUP("Solver" FILES ${Solver_SRC}) + SET(Python_SRCS ItemPy.xml ItemPyImp.cpp @@ -76,15 +85,9 @@ SET(Assembly_SRCS ${Features_SRCS} ${Python_SRCS} ${Module_SRCS} + ${Solver_SRC} ) -#set(log_LIB boost_log -# rt -# ${Boost_SYSTEM_LIBRARY} -# ${Boost_FILESYSTEM_LIBRARY} -# ${Boost_THREAD_LIBRARY} -#) - add_library(Assembly SHARED ${Assembly_SRCS}) target_link_libraries(Assembly ${Assembly_LIBS} ${log_LIB}) diff --git a/src/Mod/Assembly/App/Constraint.h b/src/Mod/Assembly/App/Constraint.h index 4ab7b736a..1c128d464 100644 --- a/src/Mod/Assembly/App/Constraint.h +++ b/src/Mod/Assembly/App/Constraint.h @@ -30,7 +30,7 @@ #include -#include "Solver.h" +#include "Solver/Solver.h" #include "ItemAssembly.h" diff --git a/src/Mod/Assembly/App/ConstraintGroup.h b/src/Mod/Assembly/App/ConstraintGroup.h index efd6c734d..82bf95ac3 100644 --- a/src/Mod/Assembly/App/ConstraintGroup.h +++ b/src/Mod/Assembly/App/ConstraintGroup.h @@ -30,7 +30,7 @@ #include #include "Constraint.h" -#include "Solver.h" +#include "Solver/Solver.h" namespace Assembly { diff --git a/src/Mod/Assembly/App/ItemAssembly.cpp b/src/Mod/Assembly/App/ItemAssembly.cpp index fa39a2728..5cefa44a9 100644 --- a/src/Mod/Assembly/App/ItemAssembly.cpp +++ b/src/Mod/Assembly/App/ItemAssembly.cpp @@ -52,6 +52,7 @@ ItemAssembly::ItemAssembly() { #ifdef ASSEMBLY_DEBUG_FACILITIES ADD_PROPERTY(ApplyAtFailure,(false)); ADD_PROPERTY(Precision,(1e-6)); + ADD_PROPERTY(SaveState,(false)); #endif } @@ -79,6 +80,14 @@ App::DocumentObjectExecReturn* ItemAssembly::execute(void) { m_solver->setOption(dcm::IgnoreResults); m_solver->setOption(Precision.getValue()); + + if(SaveState.getValue()) { + + ofstream myfile; + myfile.open("solverstate.txt"); + m_solver->saveState(myfile); + myfile.close(); + }; #endif initConstraints(boost::shared_ptr()); @@ -259,8 +268,8 @@ void ItemAssembly::initSolver(boost::shared_ptr parent, Base::Placement& PL_downstream *= this->Placement.getValue(); } } - - //we always need to store the downstream placement as we may be a subassembly in a + + //we always need to store the downstream placement as we may be a subassembly in a //non-rigid subassembly m_downstream_placement = PL_downstream; diff --git a/src/Mod/Assembly/App/ItemAssembly.h b/src/Mod/Assembly/App/ItemAssembly.h index 86dc5c308..fcea7a64e 100644 --- a/src/Mod/Assembly/App/ItemAssembly.h +++ b/src/Mod/Assembly/App/ItemAssembly.h @@ -27,7 +27,7 @@ #include #include "Item.h" -#include "Solver.h" +#include "Solver/Solver.h" namespace Assembly { @@ -87,6 +87,7 @@ public: #ifdef ASSEMBLY_DEBUG_FACILITIES App::PropertyBool ApplyAtFailure; App::PropertyFloat Precision; + App::PropertyBool SaveState; #endif private: diff --git a/src/Mod/Assembly/App/ItemPart.h b/src/Mod/Assembly/App/ItemPart.h index ac6a3e030..dd129e690 100644 --- a/src/Mod/Assembly/App/ItemPart.h +++ b/src/Mod/Assembly/App/ItemPart.h @@ -26,7 +26,7 @@ #include #include "Item.h" -#include "Solver.h" +#include "Solver/Solver.h" namespace Assembly diff --git a/src/Mod/Assembly/App/Solver.h b/src/Mod/Assembly/App/Solver/Solver.h similarity index 96% rename from src/Mod/Assembly/App/Solver.h rename to src/Mod/Assembly/App/Solver/Solver.h index b330d7142..304d663c8 100644 --- a/src/Mod/Assembly/App/Solver.h +++ b/src/Mod/Assembly/App/Solver/Solver.h @@ -23,10 +23,20 @@ #ifndef SOLVER_H #define SOLVER_H +#define DCM_EXTERNAL_CORE +#define DCM_EXTERNAL_3D +#define DCM_EXTERNAL_STATE + +#include "PreCompiled.h" + #include "opendcm/core.hpp" #include "opendcm/module3d.hpp" #include "opendcm/modulepart.hpp" +#ifdef ASSEMBLY_DEBUG_FACILITIES +#include "opendcm/modulestate.hpp" +#endif + #include #include @@ -320,7 +330,12 @@ struct geometry_traits { typedef dcm::Kernel Kernel; typedef dcm::Module3D< mpl::vector4< gp_Pnt, gp_Lin, gp_Pln, gp_Cylinder>, std::string > Module3D; typedef dcm::ModulePart< mpl::vector1< Base::Placement >, std::string > ModulePart; + +#ifdef ASSEMBLY_DEBUG_FACILITIES +typedef dcm::System Solver; +#elif typedef dcm::System Solver; +#endif typedef ModulePart::type::Part Part3D; typedef Module3D::type::Geometry3D Geometry3D; diff --git a/src/Mod/Assembly/App/Solver/solver_3d_ext1.cpp b/src/Mod/Assembly/App/Solver/solver_3d_ext1.cpp new file mode 100644 index 000000000..abc4ca496 --- /dev/null +++ b/src/Mod/Assembly/App/Solver/solver_3d_ext1.cpp @@ -0,0 +1,30 @@ +/* + openDCM, dimensional constraint manager + Copyright (C) 2013 Stefan Troeger + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "Solver.h" + +#ifdef DCM_EXTERNAL_CORE +#include DCM_EXTERNAL_CORE_INCLUDE_01 +DCM_EXTERNAL_CORE_01( Solver ) +#endif + +#ifdef DCM_EXTERNAL_3D +#include DCM_EXTERNAL_3D_INCLUDE_01 +DCM_EXTERNAL_3D_01( Solver ) +#endif diff --git a/src/Mod/Assembly/App/Solver/solver_3d_ext2.cpp b/src/Mod/Assembly/App/Solver/solver_3d_ext2.cpp new file mode 100644 index 000000000..1267d1e78 --- /dev/null +++ b/src/Mod/Assembly/App/Solver/solver_3d_ext2.cpp @@ -0,0 +1,25 @@ +/* + openDCM, dimensional constraint manager + Copyright (C) 2013 Stefan Troeger + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "Solver.h" + +#ifdef DCM_EXTERNAL_3D +#include DCM_EXTERNAL_3D_INCLUDE_02 +DCM_EXTERNAL_3D_02(Solver) +#endif diff --git a/src/Mod/Assembly/App/Solver/solver_3d_ext3.cpp b/src/Mod/Assembly/App/Solver/solver_3d_ext3.cpp new file mode 100644 index 000000000..80f73acc7 --- /dev/null +++ b/src/Mod/Assembly/App/Solver/solver_3d_ext3.cpp @@ -0,0 +1,25 @@ +/* + openDCM, dimensional constraint manager + Copyright (C) 2013 Stefan Troeger + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "Solver.h" + +#ifdef DCM_EXTERNAL_3D +#include DCM_EXTERNAL_3D_INCLUDE_03 +DCM_EXTERNAL_3D_03(Solver) +#endif \ No newline at end of file diff --git a/src/Mod/Assembly/App/Solver/solver_state_ext1.cpp b/src/Mod/Assembly/App/Solver/solver_state_ext1.cpp new file mode 100644 index 000000000..e1f6d0e86 --- /dev/null +++ b/src/Mod/Assembly/App/Solver/solver_state_ext1.cpp @@ -0,0 +1,44 @@ +/* + openDCM, dimensional constraint manager + Copyright (C) 2013 Stefan Troeger + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "Solver.h" + +#ifdef DCM_EXTERNAL_STATE +#include DCM_EXTERNAL_STATE_INCLUDE_001 +DCM_EXTERNAL_STATE_001( Solver ) +#endif + +#ifdef DCM_EXTERNAL_STATE +#include DCM_EXTERNAL_STATE_INCLUDE_002 +DCM_EXTERNAL_STATE_002( Solver ) +#endif + +#ifdef DCM_EXTERNAL_STATE +#include DCM_EXTERNAL_STATE_INCLUDE_003 +DCM_EXTERNAL_STATE_003( Solver ) + +#include DCM_EXTERNAL_STATE_INCLUDE_009 +DCM_EXTERNAL_STATE_009( Solver ) +#endif + +#ifdef DCM_EXTERNAL_STATE +#include DCM_EXTERNAL_STATE_INCLUDE_004 +DCM_EXTERNAL_STATE_004( Solver ) +#endif + diff --git a/src/Mod/Assembly/App/Solver/solver_state_ext2.cpp b/src/Mod/Assembly/App/Solver/solver_state_ext2.cpp new file mode 100644 index 000000000..fec3b13c6 --- /dev/null +++ b/src/Mod/Assembly/App/Solver/solver_state_ext2.cpp @@ -0,0 +1,40 @@ +/* + openDCM, dimensional constraint manager + Copyright (C) 2013 Stefan Troeger + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along + with this library; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "Solver.h" + +#ifdef DCM_EXTERNAL_STATE +#include DCM_EXTERNAL_STATE_INCLUDE_005 +DCM_EXTERNAL_STATE_005( Solver ) +#endif + +#ifdef DCM_EXTERNAL_STATE +#include DCM_EXTERNAL_STATE_INCLUDE_006 +DCM_EXTERNAL_STATE_006( Solver ) +#endif + +#ifdef DCM_EXTERNAL_STATE +#include DCM_EXTERNAL_STATE_INCLUDE_007 +DCM_EXTERNAL_STATE_007( Solver ) +#endif + +#ifdef DCM_EXTERNAL_STATE +#include DCM_EXTERNAL_STATE_INCLUDE_008 +DCM_EXTERNAL_STATE_008( Solver ) +#endif \ No newline at end of file diff --git a/src/Mod/Assembly/App/opendcm/core.hpp b/src/Mod/Assembly/App/opendcm/core.hpp index 8808cf6f7..a36f981e4 100644 --- a/src/Mod/Assembly/App/opendcm/core.hpp +++ b/src/Mod/Assembly/App/opendcm/core.hpp @@ -49,6 +49,9 @@ #define DCM_EXTERNAL_CORE_INCLUDE_01 "opendcm/core/imp/system_imp.hpp" #define DCM_EXTERNAL_CORE_01( Sys )\ template class dcm::System; \ + template struct dcm::Equation, 1>; \ + template struct dcm::Equation; \ + template struct dcm::Equation, 3, dcm::rotation>; #endif //external diff --git a/src/Mod/Assembly/App/opendcm/core/equations.hpp b/src/Mod/Assembly/App/opendcm/core/equations.hpp index 28b56ac9c..795834e10 100644 --- a/src/Mod/Assembly/App/opendcm/core/equations.hpp +++ b/src/Mod/Assembly/App/opendcm/core/equations.hpp @@ -96,7 +96,7 @@ struct seq_has_option { typedef typename mpl::not_::type, mpl::end > >::type type; }; -template +template struct constraint_sequence : public seq { template @@ -118,12 +118,12 @@ struct constraint_sequence : public seq { //we also allow to set values directly into the equation, as this makes it more compftable for multi constraints //as align. Note that this only works if all option types of all equations in this sequence are distinguishable template - typename boost::enable_if::type, constraint_sequence&>::type + typename boost::enable_if::type, Derived&>::type operator=(const T& val) { fusion::filter_view > view(*this); fusion::front(view) = val; - return *this; + return *((Derived*)this); }; }; @@ -193,7 +193,7 @@ struct Equation : public EQ { */ //set default option values, neeeded for repedability and to prevent unexpected behaviour - virtual void setDefault() = 0; + virtual void setDefault() {}; }; template diff --git a/src/Mod/Assembly/App/opendcm/core/imp/equations_imp.hpp b/src/Mod/Assembly/App/opendcm/core/imp/equations_imp.hpp index 56b2c2cd0..ca7e8a143 100644 --- a/src/Mod/Assembly/App/opendcm/core/imp/equations_imp.hpp +++ b/src/Mod/Assembly/App/opendcm/core/imp/equations_imp.hpp @@ -182,12 +182,6 @@ Equation::operator &(T& val) { }; */ -template -void Equation::setDefault() { - fusion::at_key(values) = std::make_pair(false, 0.); - fusion::at_key(values) = std::make_pair(false, bidirectional); -}; - //convinience stream functions for debugging template struct print_pair { diff --git a/src/Mod/Assembly/App/opendcm/core/imp/kernel_imp.hpp b/src/Mod/Assembly/App/opendcm/core/imp/kernel_imp.hpp index cd2ae8d5a..d166a30b7 100644 --- a/src/Mod/Assembly/App/opendcm/core/imp/kernel_imp.hpp +++ b/src/Mod/Assembly/App/opendcm/core/imp/kernel_imp.hpp @@ -21,7 +21,6 @@ #define DCM_KERNEL_IMP_H #include "../kernel.hpp" -#include #include #include diff --git a/src/Mod/Assembly/App/opendcm/core/imp/system_imp.hpp b/src/Mod/Assembly/App/opendcm/core/imp/system_imp.hpp index 005e11bce..5dbd53efb 100644 --- a/src/Mod/Assembly/App/opendcm/core/imp/system_imp.hpp +++ b/src/Mod/Assembly/App/opendcm/core/imp/system_imp.hpp @@ -88,50 +88,6 @@ void System::clear() { fusion::for_each(*m_storage, clearer()); }; -template< typename KernelType, typename T1, typename T2, typename T3 > -template -typename std::vector< boost::shared_ptr >::iterator System::begin() { - - typedef typename mpl::find::type iterator; - typedef typename mpl::distance::type, iterator>::type distance; - BOOST_MPL_ASSERT((mpl::not_::type > >)); - return fusion::at(*m_storage).begin(); -}; - -template< typename KernelType, typename T1, typename T2, typename T3 > -template -typename std::vector< boost::shared_ptr >::iterator System::end() { - - typedef typename mpl::find::type iterator; - typedef typename mpl::distance::type, iterator>::type distance; - BOOST_MPL_ASSERT((mpl::not_::type > >)); - return fusion::at(*m_storage).end(); -}; - -template< typename KernelType, typename T1, typename T2, typename T3 > -template -std::vector< boost::shared_ptr >& System::objectVector() { - - typedef typename mpl::find::type iterator; - typedef typename mpl::distance::type, iterator>::type distance; - BOOST_MPL_ASSERT((mpl::not_::type > >)); - return fusion::at(*m_storage); -}; - -template< typename KernelType, typename T1, typename T2, typename T3 > -template -void System::push_back(boost::shared_ptr ptr) { - objectVector().push_back(ptr); -}; - -template< typename KernelType, typename T1, typename T2, typename T3 > -template -void System::erase(boost::shared_ptr ptr) { - - std::vector< boost::shared_ptr >& vec = objectVector(); - vec.erase(std::remove(vec.begin(), vec.end(), ptr), vec.end()); -}; - template< typename KernelType, typename T1, typename T2, typename T3 > SolverInfo System::solve() { clock_t start = clock(); @@ -180,45 +136,6 @@ typename std::vector > >::itera return m_subsystems.end(); }; -template< typename KernelType, typename T1, typename T2, typename T3 > -template -typename boost::enable_if< boost::is_same< typename mpl::find::type, - typename mpl::end::type >, typename Option::type& >::type -System::getOption() { - return m_options->template getProperty