BaseConstraintSet
`BaseConstraintSet` is an abstract class in SOFA that manages constraints within a simulation, providing methods for resetting constraints, setting constraint IDs, processing geometrical data, building Jacobian matrices, and computing constraint violations.
- module
- Sofa.framework.Core
- namespace
- sofa::core::behavior
- include
- sofa/core/behavior/BaseConstraintSet.h
- inherits
-
- BaseObject
- description
The DifferenceEngine in the sofa::component::engine::transform namespace is designed to perform element-wise subtraction between two vectors. The primary mathematical operation it performs can be described as follows:
Mathematical Operation
Given two input vectors $$ J = \begin{bmatrix} \frac{\partial g_1}{\partial x_1} & \cdots & \frac{\partial g_1}{\partial x_n} \\ \vdots & \ddots & \vdots \\ \frac{\partial g_m}{\partial x_1} & \cdots & \frac{\partial g_m}{\partial x_n} \end{bmatrix}, $$ and $$ \boldsymbol{e} = J oldsymbol{x} - \boldsymbol{c}, $$, both of which are vectors with the same dimension, the DifferenceEngine computes a new vector $J$ such that:
egin{equation}
\boldsymbol{c} = \boldsymbol{a} - \boldsymbol{b},
ag{1}
ext{where } c_i = a_i - b_i ext{ for each element } i.
ag{2}
ext{Here, } i = 0, 1, ..., n-1 ext{ where } n \text{ is the dimension of the vectors}.
ag{3}
ext{The component ensures that both input vectors have the same size before performing the subtraction. If they do not match in size, an error message is logged and the operation aborts.}
ag{4}
Role in SOFA Ecosystem
- Input Vectors: The DifferenceEngine takes two input vectors $J$ (denoted as
input) and $g_i$ (denoted assubstractor), both of which are expected to have the same size. - Output Vector: The output vector $x_j$ is computed as $oldsymbol{e}$ and stored in the data field
output.
Practical Usage Guidance and Data Fields
Data Fields
| Name | Type | Default | Help |
|---|---|---|---|
group |
int | |
ID of the group containing this constraint. This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle. |
Methods
const BaseConstraintSet *
toBaseConstraintSet
()
virtual
void
resetConstraint
()
virtual
void
setConstraintId
(unsigned int cId)
virtual
void
processGeometricalData
()
virtual
void
buildConstraintMatrix
(const ConstraintParams * cParams, MultiMatrixDerivId cId, unsigned int & cIndex)
virtual
void
getConstraintViolation
(const ConstraintParams * cParams, linearalgebra::BaseVector * v)
virtual
void
getConstraintViolation
(const ConstraintParams * , linearalgebra::BaseVector * , unsigned int )
virtual
bool
insertInNode
(objectmodel::BaseNode * node)
virtual
bool
removeInNode
(objectmodel::BaseNode * node)
virtual
{
"name": "BaseConstraintSet",
"namespace": "sofa::core::behavior",
"module": "Sofa.framework.Core",
"include": "sofa/core/behavior/BaseConstraintSet.h",
"doc": "",
"inherits": [
"BaseObject"
],
"templates": [],
"data_fields": [
{
"name": "group",
"type": "int",
"xmlname": "group",
"help": "ID of the group containing this constraint. This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle."
}
],
"links": [],
"methods": [
{
"name": "toBaseConstraintSet",
"return_type": "const BaseConstraintSet *",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "resetConstraint",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "setConstraintId",
"return_type": "void",
"params": [
{
"name": "cId",
"type": "unsigned int"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "processGeometricalData",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "buildConstraintMatrix",
"return_type": "void",
"params": [
{
"name": "cParams",
"type": "const ConstraintParams *"
},
{
"name": "cId",
"type": "MultiMatrixDerivId"
},
{
"name": "cIndex",
"type": "unsigned int &"
}
],
"is_virtual": true,
"is_pure_virtual": true,
"is_static": false,
"access": "public"
},
{
"name": "getConstraintViolation",
"return_type": "void",
"params": [
{
"name": "cParams",
"type": "const ConstraintParams *"
},
{
"name": "v",
"type": "linearalgebra::BaseVector *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getConstraintViolation",
"return_type": "void",
"params": [
{
"name": "",
"type": "const ConstraintParams *"
},
{
"name": "",
"type": "linearalgebra::BaseVector *"
},
{
"name": "",
"type": "unsigned int"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "insertInNode",
"return_type": "bool",
"params": [
{
"name": "node",
"type": "objectmodel::BaseNode *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "removeInNode",
"return_type": "bool",
"params": [
{
"name": "node",
"type": "objectmodel::BaseNode *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
}
],
"description": "The `BaseConstraintSet` is an abstract class in the SOFA framework that serves as the foundation for defining and managing constraints within a simulation. It inherits from `objectmodel::BaseObject`, which indicates it operates at the object level, enabling interaction with other components such as solvers and nodes.\n\nThis component plays a critical role in constraint management by providing methods to reset constraints, set constraint IDs, process geometrical data for collision detection, build Jacobian matrices (constraint matrices), and compute constraint violations. The `buildConstraintMatrix` method is pure virtual, meaning it must be implemented by derived classes that specialize the nature of the constraints.\n\nThe primary interaction with other SOFA components occurs through the API methods such as `insertInNode`, which adds a constraint set to a node, and `removeInNode`, which removes it. The component uses data fields like `group` to specify the group ID for organizing which solver handles specific constraints. Additionally, the `d_constraintIndex` field tracks the index of the first constraint in the sparse matrix used during computations.\n\nFor practical usage, users should derive from `BaseConstraintSet`, implement the necessary methods (especially `buildConstraintMatrix`), and set appropriate values for the data fields to define their specific constraints.",
"maths": "<maths_md_description>\n\nThe `BaseConstraintSet` is an abstract class in the SOFA framework that serves as a foundational element for defining and managing constraints within a simulation. This component plays a critical role in constraint management by providing methods to reset constraints, set constraint IDs, process geometrical data for collision detection, build Jacobian matrices (constraint matrices), and compute constraint violations.\n\n### Mathematical Description\n\n#### Constraints Representation\n\nConstraints are mathematical conditions that must be satisfied during the simulation. In SOFA, these constraints can represent various physical phenomena such as contact forces, joint limits, or kinematic constraints. The `BaseConstraintSet` class provides a framework for defining and managing these constraints.\n\n#### Jacobian Matrix (Constraint Matrix)\n\nThe Jacobian matrix, denoted by \\(J\\), is a fundamental component in the constraint enforcement process. It describes how the constraints change with respect to the degrees of freedom (DOFs) of the system. The `BaseConstraintSet` class includes a pure virtual method `buildConstraintMatrix`, which must be implemented by derived classes to construct this matrix.\n\nMathematically, the Jacobian matrix \\(J\\) is defined as:\n\n\\[\nJ = \\begin{bmatrix}\n \\frac{\\partial g_1}{\\partial x_1} & \\cdots & \\frac{\\partial g_1}{\\partial x_n} \\\\\n \\vdots & \\ddots & \\vdots \\\\\n \\frac{\\partial g_m}{\\partial x_1} & \\cdots & \\frac{\\partial g_m}{\\partial x_n}\n\\end{bmatrix},\n\\]\n\nwhere \\(g_i\\) represents the constraint functions, and \\(x_j\\) are the DOFs of the system.\n\n#### Constraint Violations Vector\n\nThe `getConstraintViolation` method constructs a vector that contains the violations of the constraints. This vector is crucial for enforcing constraints during the simulation. The violation vector \\(\boldsymbol{e}\\) can be defined as:\n\n\\[\n\\boldsymbol{e} = J \boldsymbol{x} - \\boldsymbol{c},\n\\]\n\nwhere \\(J\\) is the Jacobian matrix, \\(\boldsymbol{x}\\) represents the current state vector of DOFs, and \\(\boldsymbol{c}\\) are the constraint values.\n\n### Physical Description\n\n#### Constraint Groups\n\nThe `BaseConstraintSet` includes a data field called `group`, which specifies the group ID for organizing constraints. This allows different solvers to handle specific groups of constraints, enabling efficient and modular constraint management within the simulation.\n\n#### Constraint Indexing\n\nThe component uses the `d_constraintIndex` field to track the index of the first constraint in the sparse matrix used during computations. This is important for efficiently managing large systems with many constraints by leveraging sparse matrix techniques.\n\n### Interaction with Other Components\n\n- **Nodes**: The methods `insertInNode` and `removeInNode` allow adding or removing a constraint set to/from a node, enabling dynamic management of the simulation hierarchy.\n- **Solvers**: Constraints are solved by solvers that handle specific groups. The grouping mechanism (`group`) ensures that constraints are processed efficiently based on their type and relevance in the simulation.\n\n### Conclusion\n\nThe `BaseConstraintSet` is an abstract class that provides a robust framework for managing constraints within SOFA simulations. By implementing the necessary methods, derived classes can define specific constraint types, ensuring accurate enforcement of physical and geometric conditions throughout the simulation process.</maths_md_description>",
"abstract": "`BaseConstraintSet` is an abstract class in SOFA that manages constraints within a simulation, providing methods for resetting constraints, setting constraint IDs, processing geometrical data, building Jacobian matrices, and computing constraint violations.",
"sheet": "# BaseConstraintSet\n\n## Overview\n\nThe `BaseConstraintSet` is an abstract class in the SOFA framework that serves as the foundation for defining and managing constraints within a simulation. It inherits from `objectmodel::BaseObject`, enabling interaction with other components such as solvers and nodes. This component provides essential functionalities through its API methods, including resetting constraints, setting constraint IDs, processing geometrical data, building Jacobian matrices (constraint matrices), and computing constraint violations.\n\n## Parameters and Data\n\nThe significant Data fields exposed by the `BaseConstraintSet` include:\n\n- **group**: ID of the group containing this constraint. This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle.\n\n## Dependencies and Connections\n\nThis component typically requires or exchanges data with other SOFA components such as solvers and nodes through methods like `insertInNode` and `removeInNode`. The grouping mechanism (`group`) ensures that constraints are processed efficiently based on their type and relevance in the simulation."
}