Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src/gsDynamicSolvers/gsDynamicBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -49,6 +50,9 @@ class gsDynamicBase

public:

/// @brief Callback that is evaluated before each timestep.
typedef std::function<bool(const T /* time */, const T /* dtime */,
const gsOptionList & /* solver options */)> StepCallback_t;
virtual ~gsDynamicBase() {};

/// Constructor
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand All @@ -239,6 +250,19 @@ class gsDynamicBase
virtual void setVelocities(const gsVector<T> & V) {this->setV(V);}
virtual void setAccelerations(const gsVector<T> & 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;};

Expand Down Expand Up @@ -335,6 +359,8 @@ class gsDynamicBase
Residual_t m_residual;
TResidual_t m_Tresidual;

StepCallback_t m_preStepCallback;

mutable typename gsSparseSolver<T>::uPtr m_solver; // Cholesky by default

protected:
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/gsStructuralAnalysisTools/gsStructuralAnalysisTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
Author(s): H.M. Verhelst (2019-..., TU Delft)
*/

#pragma once

#include <functional>
#include <gsCore/gsLinearAlgebra.h>

Expand Down
Loading