diff --git a/src/gsDynamicSolvers/gsDynamicBase.h b/src/gsDynamicSolvers/gsDynamicBase.h index 9f0d818..00630a2 100644 --- a/src/gsDynamicSolvers/gsDynamicBase.h +++ b/src/gsDynamicSolvers/gsDynamicBase.h @@ -24,7 +24,8 @@ namespace gismo { /** - @brief Performs the arc length method to solve a nonlinear system of equations. + @brief Base class for solution strategies of nonlinear second-order dynamic + systems. \tparam T coefficient type @@ -49,6 +50,9 @@ class gsDynamicBase public: + /// @brief Callback that is evaluated before each timestep. + typedef std::function StepCallback_t; virtual ~gsDynamicBase() {}; /// Constructor @@ -190,11 +194,18 @@ class gsDynamicBase // Returns the current time step virtual T getTimeStep() const {return m_options.getReal("DT"); } - /// Perform one arc-length step + /// Perform one time step virtual gsStatus step(T dt) { + if (m_preStepCallback && !m_preStepCallback(m_time,dt,m_options)) + { + m_status = gsStatus::OtherError; + return m_status; + } + gsStatus status = this->_step(m_time,dt,m_U,m_V,m_A); m_time += dt; + m_status = status; return status; } @@ -215,7 +226,7 @@ class gsDynamicBase } // Output - /// True if the Arc Length method converged + /// True if the method converged virtual bool converged() const {return m_status==gsStatus::Success;} /// Returns the number of Newton iterations performed @@ -239,6 +250,19 @@ class gsDynamicBase virtual void setVelocities(const gsVector & V) {this->setV(V);} virtual void setAccelerations(const gsVector & A) {this->setA(A);} + /// @brief Set a function that is executed when non-const step() is called before + /// the actual step is performed. + virtual void setPreStepCallback(const StepCallback_t & callback) + { + m_preStepCallback = callback; + } + + /// @brief Clear the pre-step callback. + virtual void clearPreStepCallback() + { + m_preStepCallback = StepCallback_t(); + } + /// Access the options virtual gsOptionList & options() {return m_options;}; @@ -335,6 +359,8 @@ class gsDynamicBase Residual_t m_residual; TResidual_t m_Tresidual; + StepCallback_t m_preStepCallback; + mutable typename gsSparseSolver::uPtr m_solver; // Cholesky by default protected: @@ -347,7 +373,7 @@ class gsDynamicBase /// Number of iterations performed mutable index_t m_numIterations; - // /// Maximum number of Arc Length iterations allowed + // /// Maximum number of iterations allowed // index_t m_maxIterations; // /// Number of desired iterations diff --git a/src/gsStructuralAnalysisTools/gsStructuralAnalysisTypes.h b/src/gsStructuralAnalysisTools/gsStructuralAnalysisTypes.h index e58e8c1..86a5552 100644 --- a/src/gsStructuralAnalysisTools/gsStructuralAnalysisTypes.h +++ b/src/gsStructuralAnalysisTools/gsStructuralAnalysisTypes.h @@ -11,6 +11,8 @@ Author(s): H.M. Verhelst (2019-..., TU Delft) */ +#pragma once + #include #include