Skip to content

Move force-related methods from State to MechanicalState #6197

Description

@ChristianDuriez

Problem

The methods addToTotalForces() and removeFromTotalForces() are currently defined in the base State class (lines 116-118 in Sofa/framework/Core/src/sofa/core/State.h). However, these methods are mechanics-specific and should not be in the generic State class.

Rationale

  • Concept of forces is mechanics-specific: The notion of "force" is inherently tied to mechanical simulations and has no meaning in other physics domains.
  • Limits State reusability: Having these methods in the base State class prevents State from being reused for other physics simulations such as:
    • Electrical simulations (where "force" is not applicable)
    • Thermal simulations (heat flow, not forces)
    • Other non-mechanical physics

Suggested Solution

Move the following methods from State to MechanicalState:

  • void addToTotalForces(core::ConstVecDerivId forceId) override;
  • void removeFromTotalForces(core::ConstVecDerivId forceId) override;

Also move related members:

  • AccumulationVecId<TDataTypes, V_DERIV, V_READ> accumulatedForces;
  • const AccumulationVecId<TDataTypes, V_DERIV, V_READ>& readTotalForces() const;

This would make the base State class truly generic and extensible for any physics domain, while keeping mechanical-specific functionality in MechanicalState.

Impact

This is a refactoring that would improve the architecture's extensibility for non-mechanical physics simulations while maintaining backward compatibility through MechanicalState.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions