<commit_before>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 RC 1        *
*                (c) 2006-2011 INRIA, USTL, UJF, CNRS, MGH                    *
*                                                                             *
* 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 :: Framework                              *
*                                                                             *
* Authors: The SOFA Team (see Authors.txt)                                    *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/
#ifndef SOFA_CORE_BEHAVIOR_BASEMASS_H
#define SOFA_CORE_BEHAVIOR_BASEMASS_H

#include <sofa/core/core.h>
#include <sofa/core/MultiVecId.h>
#include <sofa/core/MechanicalParams.h>
#include <sofa/core/objectmodel/BaseObject.h>
#include <sofa/core/behavior/MultiMatrixAccessor.h>
#include <sofa/defaulttype/BaseMatrix.h>
#include <sofa/defaulttype/BaseVector.h>
#include <sofa/defaulttype/Vec.h>
namespace sofa
{

namespace core
{

namespace behavior
{

/**
 *  \brief Component responsible for mass-related computations (gravity, acceleration).
 *
 *  Mass can be defined either as a scalar, vector, or a full mass-matrix.
 *  It is responsible for converting forces to accelerations (for explicit integrators),
 *  or displacements to forces (for implicit integrators).
 *
 *  It is often also a ForceField, computing gravity-related forces.
 */
class BaseMass : public virtual objectmodel::BaseObject
{
public:
    SOFA_ABSTRACT_CLASS(BaseMass, objectmodel::BaseObject);
protected:
    BaseMass()
        : m_separateGravity (initData(&m_separateGravity , false, "separateGravity", "add separately gravity to velocity computation"))
    {
    }

    virtual ~BaseMass()
    {
    }
public:
    /// @name Vector operations
    /// @{

    /// f += factor M dx
    virtual void addMDx(const MechanicalParams* mparams /* PARAMS FIRST */, MultiVecDerivId fid, double factor) =0;

    /// dx = M^-1 f
    virtual void accFromF(const MechanicalParams* mparams /* PARAMS FIRST */, MultiVecDerivId aid) = 0;

    /// Perform  v += dt*g operation. Used if mass wants to added G separately from the other forces to v.
    /// \param mparams->dt() time step of for temporal discretization.
    virtual void addGravityToV(const MechanicalParams* mparams /* PARAMS FIRST */, MultiVecDerivId vid) = 0;

    /// vMv/2
    virtual double getKineticEnergy(const MechanicalParams* mparams = MechanicalParams::defaultInstance()) const = 0;
    /// Mgx
    virtual double getPotentialEnergy(const MechanicalParams* mparams = MechanicalParams::defaultInstance()) const = 0;

    /// (Mv,xMv+Iw) (linear and angular momenta against world origin)
    virtual defaulttype::Vec6d getMomentum(const MechanicalParams* mparams = MechanicalParams::defaultInstance()) const = 0;

    /// @}

    /// @name Matrix operations
    /// @{

    /// Add Mass contribution to global Matrix assembling
    ///
    /// This method must be implemented by the component.
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addMToMatrix(const MechanicalParams* mparams /* PARAMS FIRST */, const sofa::core::behavior::MultiMatrixAccessor* matrix) = 0;

    /// @}

    /// initialization to export kinetic and potential energy to gnuplot files format
    virtual void initGnuplot(const std::string path)=0;

    /// export kinetic and potential energy state at "time" to a gnuplot file
    virtual void exportGnuplot(const MechanicalParams* mparams /* PARAMS FIRST  = MechanicalParams::defaultInstance()*/, double time)=0;

    /// return the mass relative to the DOF #index
    virtual double getElementMass(unsigned int index) const =0;
    /// return the matrix relative to the DOF #index
    virtual void getElementMass(unsigned int index, defaulttype::BaseMatrix *m) const = 0;

    virtual bool isDiagonal() { return false; }

    /// Member specifying if the gravity is added separately to the DOFs velocities (in solve method),
    /// or if is added with the other forces(addForceMethod)
    Data<bool> m_separateGravity;

    /// @name ARPlugin Development
    /// @{

    /// Add RInvMass contribution to global Matrix assembling
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addRinvMToMatrix(const MechanicalParams* /*mparams*/ /* PARAMS FIRST */, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/)
    {std::cerr << "addRinvMToMatrix : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}

    /// Add RInvMass contribution to global Matrix assembling
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addRToMatrix(const MechanicalParams* /*mparams*/ /* PARAMS FIRST */, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/)
    {std::cerr << "addRToMatrix : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}

    /// Add InvMassS contribution to global Vector assembling
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addinvMsToVector(const core::MechanicalParams */*mparams*/ /* PARAMS FIRST */, sofa::defaulttype::BaseVector* /*vector*/ )
    {std::cerr << "addinvMsToMatrix : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}

    virtual void addinvMsAndinvMpToVector(const core::MechanicalParams */*mparams*/ /* PARAMS FIRST */, sofa::defaulttype::BaseVector* /*vector1*/, defaulttype::BaseVector* /*vector2*/ /*vector*/ )
    {std::cerr << "addinvMsAndinvMpToVector : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}

    /// Add S contribution to global Vector assembling
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addSToVector(const core::MechanicalParams */*mparams*/ /* PARAMS FIRST */, sofa::defaulttype::BaseVector* /*vector*/ )
    {std::cerr << "addSToMatrix : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}

    /// Add InvMass contribution to global Matrix assembling
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addinvMToMatrix(const MechanicalParams* /*mparams*/ /* PARAMS FIRST */, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/)
    {std::cerr << "addinvMToMatrix : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}
    /// @}

};

} // namespace behavior

} // namespace core

} // namespace sofa

#endif<commit_msg>r8996/sofa : Fix repeated warnings in BaseMass.h on Windows<commit_after>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, version 1.0 RC 1        *
*                (c) 2006-2011 INRIA, USTL, UJF, CNRS, MGH                    *
*                                                                             *
* 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 :: Framework                              *
*                                                                             *
* Authors: The SOFA Team (see Authors.txt)                                    *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/
#ifndef SOFA_CORE_BEHAVIOR_BASEMASS_H
#define SOFA_CORE_BEHAVIOR_BASEMASS_H

#include <sofa/core/core.h>
#include <sofa/core/MultiVecId.h>
#include <sofa/core/MechanicalParams.h>
#include <sofa/core/objectmodel/BaseObject.h>
#include <sofa/core/behavior/MultiMatrixAccessor.h>
#include <sofa/defaulttype/BaseMatrix.h>
#include <sofa/defaulttype/BaseVector.h>
#include <sofa/defaulttype/Vec.h>
namespace sofa
{

namespace core
{

namespace behavior
{

/**
 *  \brief Component responsible for mass-related computations (gravity, acceleration).
 *
 *  Mass can be defined either as a scalar, vector, or a full mass-matrix.
 *  It is responsible for converting forces to accelerations (for explicit integrators),
 *  or displacements to forces (for implicit integrators).
 *
 *  It is often also a ForceField, computing gravity-related forces.
 */
class BaseMass : public virtual objectmodel::BaseObject
{
public:
    SOFA_ABSTRACT_CLASS(BaseMass, objectmodel::BaseObject);
protected:
    BaseMass()
        : m_separateGravity (initData(&m_separateGravity , false, "separateGravity", "add separately gravity to velocity computation"))
    {
    }

    virtual ~BaseMass()
    {
    }
public:
    /// @name Vector operations
    /// @{

    /// f += factor M dx
    virtual void addMDx(const MechanicalParams* mparams /* PARAMS FIRST */, MultiVecDerivId fid, double factor) =0;

    /// dx = M^-1 f
    virtual void accFromF(const MechanicalParams* mparams /* PARAMS FIRST */, MultiVecDerivId aid) = 0;

    /// Perform  v += dt*g operation. Used if mass wants to added G separately from the other forces to v.
    /// \param mparams->dt() time step of for temporal discretization.
    virtual void addGravityToV(const MechanicalParams* mparams /* PARAMS FIRST */, MultiVecDerivId vid) = 0;

    /// vMv/2
    virtual double getKineticEnergy(const MechanicalParams* mparams = MechanicalParams::defaultInstance()) const = 0;
    /// Mgx
    virtual double getPotentialEnergy(const MechanicalParams* mparams = MechanicalParams::defaultInstance()) const = 0;

    /// (Mv,xMv+Iw) (linear and angular momenta against world origin)
    virtual defaulttype::Vec6d getMomentum(const MechanicalParams* mparams = MechanicalParams::defaultInstance()) const = 0;

    /// @}

    /// @name Matrix operations
    /// @{

    /// Add Mass contribution to global Matrix assembling
    ///
    /// This method must be implemented by the component.
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addMToMatrix(const MechanicalParams* mparams /* PARAMS FIRST */, const sofa::core::behavior::MultiMatrixAccessor* matrix) = 0;

    /// @}

    /// initialization to export kinetic and potential energy to gnuplot files format
    virtual void initGnuplot(const std::string path)=0;

    /// export kinetic and potential energy state at "time" to a gnuplot file
    virtual void exportGnuplot(const MechanicalParams* mparams /* PARAMS FIRST  = MechanicalParams::defaultInstance()*/, double time)=0;

    /// return the mass relative to the DOF #index
    virtual double getElementMass(unsigned int index) const =0;
    /// return the matrix relative to the DOF #index
    virtual void getElementMass(unsigned int index, defaulttype::BaseMatrix *m) const = 0;

    virtual bool isDiagonal() { return false; }

    /// Member specifying if the gravity is added separately to the DOFs velocities (in solve method),
    /// or if is added with the other forces(addForceMethod)
    Data<bool> m_separateGravity;

    /// @name ARPlugin Development
    /// @{

    /// Add RInvMass contribution to global Matrix assembling
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addRinvMToMatrix(const MechanicalParams* /*mparams*/ /* PARAMS FIRST */, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/)
    {std::cerr << "addRinvMToMatrix : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}

    /// Add RInvMass contribution to global Matrix assembling
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addRToMatrix(const MechanicalParams* /*mparams*/ /* PARAMS FIRST */, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/)
    {std::cerr << "addRToMatrix : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}

    /// Add InvMassS contribution to global Vector assembling
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addinvMsToVector(const core::MechanicalParams* /*mparams*/ /* PARAMS FIRST */, sofa::defaulttype::BaseVector* /*vector*/ )
    {std::cerr << "addinvMsToMatrix : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}

    virtual void addinvMsAndinvMpToVector(const core::MechanicalParams* /*mparams*/ /* PARAMS FIRST */, sofa::defaulttype::BaseVector* /*vector1*/, defaulttype::BaseVector* /*vector2*/ /*vector*/ )
    {std::cerr << "addinvMsAndinvMpToVector : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}

    /// Add S contribution to global Vector assembling
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addSToVector(const core::MechanicalParams* /*mparams*/ /* PARAMS FIRST */, sofa::defaulttype::BaseVector* /*vector*/ )
    {std::cerr << "addSToMatrix : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}

    /// Add InvMass contribution to global Matrix assembling
    /// \param matrix matrix to add the result to
    /// \param mparams->mFactor() coefficient for mass contributions (i.e. second-order derivatives term in the ODE)
    virtual void addinvMToMatrix(const MechanicalParams* /*mparams*/ /* PARAMS FIRST */, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/)
    {std::cerr << "addinvMToMatrix : Implemented in AdaptativeHamiltonianMass for ARPlugin"<<std::endl;}
    /// @}

};

} // namespace behavior

} // namespace core

} // namespace sofa

#endif
{'fraction_non_alphanumeric': 0.12531223980016654, 'fraction_numerical': 0.004995836802664446, 'mean_word_length': 2.769334229993275, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2351678', 'n_tokens_mistral': 4481, 'n_tokens_neox': 4126, 'n_words': 1494}