<commit_before>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4      *
*                (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS                    *
*                                                                             *
* 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.          *
*******************************************************************************
*                               SOFA :: Modules                               *
*                                                                             *
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/
#ifndef SOFA_COMPONENT_ODESOLVER_EULERIMPLICITSOLVER_H
#define SOFA_COMPONENT_ODESOLVER_EULERIMPLICITSOLVER_H

#include <sofa/core/behavior/OdeSolver.h>
#include <sofa/component/odesolver/OdeSolverImpl.h>


namespace sofa
{

namespace component
{

namespace odesolver
{

using namespace sofa::defaulttype;

/** Implicit time integrator using backward Euler scheme for first and second order. By default second.
 *
 *** 2nd Order ***
 *
 * This integration scheme is based on the following equations:
 *
 *   $x_{t+h} = x_t + h v_{t+h}$
 *   $v_{t+h} = v_t + h a_{t+h}$
 *
 * Applied to a mechanical system where $ M a_t + (B + r_M M + r_K K) v_t + K x_t = f_ext$, we need to solve the following system:
 *
 *   $ M a_{t+h} + (B + r_M M + r_K K) v_{t+h} + K x_{t+h} = f_ext $
 *   $ M a_{t+h} + (B + r_M M + r_K K) ( v_t + h a_{t+h} ) + K ( x_t + h v_t + h^2 a_{t+h} ) = f_ext $
 *   $ ( M + h (B + r_M M + r_K K) + h^2 K ) a_{t+h} = f_ext - (B + r_M M + r_K K) v_t - K ( x_t + h v_t ) $
 *   $ ( M + h (B + r_M M + r_K K) + h^2 K ) a_{t+h} = f_ext - K x_t - B v_t - (r_M M + r_K K + h K) v_t $
 *   $ ( M + h (B + r_M M + r_K K) + h^2 K ) a_{t+h} = f_t - (r_M M + r_K K + h K) v_t $
 *
 *
 *** 1st Order ***
 *<commit_msg>r8356/sofa-dev : More detail in the documentation of EulerImplicitSolver<commit_after>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4      *
*                (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS                    *
*                                                                             *
* 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.          *
*******************************************************************************
*                               SOFA :: Modules                               *
*                                                                             *
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/
#ifndef SOFA_COMPONENT_ODESOLVER_EULERIMPLICITSOLVER_H
#define SOFA_COMPONENT_ODESOLVER_EULERIMPLICITSOLVER_H

#include <sofa/core/behavior/OdeSolver.h>
#include <sofa/component/odesolver/OdeSolverImpl.h>


namespace sofa
{

namespace component
{

namespace odesolver
{

using namespace sofa::defaulttype;

/** Semi-implicit time integrator using backward Euler scheme for first and second degree ODEs. (default: second)
 *
 *** 2nd Order ***
 *
 * This is based on [<NAME> Witkin, Large Steps in Cloth Simulation, SIGGRAPH 1998]
 * The integration scheme is based on the following equations:
 *
 *   $x_{t+h} = x_t + h v_{t+h}$
 *   $v_{t+h} = v_t + h a_{t+h}$
 *
 *   The unknown is
 *   $v_{t+h} - v_t = dv$
 *
 *   Newton's law is
 *   $ M dv = h f(t+h) $
 *   $ M dv = h ( f(t) + K dx     + (B - r_M M + r_K K) dv )$
 *   $ M dv = h ( f(t) + K h dv   + (B - r_M M + r_K K) dv )$
 *
 *   $ M $ is the mass matrix.
 *   $ K = df/dx $ is the stiffness implemented (or not) by the force fields.
 *   $ B = df/dv $ is the damping implemented (or not) by the force fields.
 *   An additional, uniform Rayleigh damping  $- r_M M + r_K K$ is imposed by the solver.
 *
 * This corresponds to the following equation system:
 *
 *   $ ( (1+r_M) M - h B - h(h + r_K) K ) dv = h ( f(t) + h K dv - r_M M dv )$
 *
 * Moreover, the projective constraints filter out the forbidden motions.
 * This is equivalent with multiplying vectors with a projection matrix $P$.
 * Finally, the equation system set by this ode solver is:
 *
 *   $ P ( (1+r_M) M - h B - h(h + r_K) K ) P dv = P h ( f(t) + h K dv - r_M M dv )$
 *
 *** 1st Order ***
 *
{'fraction_non_alphanumeric': 0.15686564953340246, 'fraction_numerical': 0.009776329432676641, 'mean_word_length': 1.725878078320549, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3745624', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1813, 'n_words': 684}