MechanicalPickParticlesVisitor
Find mechanical particles hit by the given ray. A mechanical particle is defined as a 2D or 3D, position or rigid DOF which is linked to the free mechanical DOFs by mechanical mappings
Identifies mechanical particles intersecting a specified ray in SOFA simulations, facilitating user interaction and visualization.
- module
- Sofa.framework.Simulation.Core
- namespace
- sofa::simulation::mechanicalvisitor
- include
- sofa/simulation/mechanicalvisitor/MechanicalPickParticlesVisitor.h
- inherits
-
- BaseMechanicalVisitor
- description
Governing Equations and Operators:
- Constraint Violation: The
PairInteractionConstraintcomputes constraint violations which represent how much the current state of the system violates the defined constraints. This is done via abstract methods that must be implemented by derived classes. Mathematically, if we denote $\mathbf{p}_i = (x_i, y_i, z_i)$ as a constraint equation where $i$ represents the DOFs, then the violation vector $oldsymbol{o} = (o_x, o_y, o_z)$ can be written as:
- Jacobian Matrix: The Jacobian matrix $oldsymbol{d} = (d_x, d_y, d_z)$, which captures how constraints change with respect to changes in DOFs, is computed by derived classes implementing the
buildConstraintMatrixmethod. This matrix has entries:
method. These multipliers represent the forces required to enforce constraints and ensure mechanical equilibrium.
- Lagrange Multipliers: The Lagrange multipliers $oldsymbol{p}_i$ are stored using the
method. These multipliers represent the forces required to enforce constraints and ensure mechanical equilibrium.
Constitutive or Kinematic Laws:
This component does not directly specify any constitutive or kinematic laws but serves as a framework for enforcing interaction constraints between pairs of bodies. The actual computation of constraint violations and Jacobian matrices must be defined by derived classes based on specific physical interactions such as contacts, attachments, or multi-resolution coupling.
Role in the Global FEM Pipeline:
-
**Assembly Phase**: The `PairInteractionConstraint` contributes to the assembly phase by computing and storing contributions from constraints. This involves computing constraint violations <!--MATH8--> and Jacobian matrices <!--MATH9-->.
- Constraint Violations: These are assembled into a global vector of constraints.
- Jacobian Matrices: These are used to form the global tangent stiffness matrix.
-
**Time Integration**: Constraints affect time integration by modifying the dynamic equations. The Lagrange multipliers ensure that the constraints are satisfied at each timestep.
Numerical Methods and Discretization Choices:
The
-
**Variational Principles**: The constraint equations and their enforcement through Lagrange multipliers fit naturally into the variational framework of FEM. Constraints are enforced by augmenting the system’s Lagrangian with penalty terms involving Lagrange multipliers.
<!--MATH2-->
-
**Lagrangian Mechanics**: The constraints can be viewed as modifications to the generalized coordinates, leading to a modified set of equations of motion that include constraint forces.
In summary, `PairInteractionConstraint` serves as an abstract interface for defining and enforcing interaction constraints between pairs of bodies within the FEM simulation framework. It does not specify concrete physics but instead provides a mechanism for derived classes to implement specific interactions.
Methods
Result
fwdMechanicalState
(simulation::Node * , sofa::core::behavior::BaseMechanicalState * mm)
virtual
Result
fwdMechanicalMapping
(simulation::Node * , sofa::core::BaseMapping * map)
virtual
Result
fwdMappedMechanicalState
(simulation::Node * , sofa::core::behavior::BaseMechanicalState * mm)
virtual
void
getClosestParticle
(sofa::core::behavior::BaseMechanicalState *& mstate, int & indexCollisionElement, type::Vec3 & point, SReal & rayLength)
{
"name": "MechanicalPickParticlesVisitor",
"namespace": "sofa::simulation::mechanicalvisitor",
"module": "Sofa.framework.Simulation.Core",
"include": "sofa/simulation/mechanicalvisitor/MechanicalPickParticlesVisitor.h",
"doc": "Find mechanical particles hit by the given ray.\n A mechanical particle is defined as a 2D or 3D, position or rigid DOF\n which is linked to the free mechanical DOFs by mechanical mappings",
"inherits": [
"BaseMechanicalVisitor"
],
"templates": [],
"data_fields": [],
"links": [],
"methods": [
{
"name": "fwdMechanicalState",
"return_type": "Result",
"params": [
{
"name": "",
"type": "simulation::Node *"
},
{
"name": "mm",
"type": "sofa::core::behavior::BaseMechanicalState *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "fwdMechanicalMapping",
"return_type": "Result",
"params": [
{
"name": "",
"type": "simulation::Node *"
},
{
"name": "map",
"type": "sofa::core::BaseMapping *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "fwdMappedMechanicalState",
"return_type": "Result",
"params": [
{
"name": "",
"type": "simulation::Node *"
},
{
"name": "mm",
"type": "sofa::core::behavior::BaseMechanicalState *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getClosestParticle",
"return_type": "void",
"params": [
{
"name": "mstate",
"type": "sofa::core::behavior::BaseMechanicalState *&"
},
{
"name": "indexCollisionElement",
"type": "int &"
},
{
"name": "point",
"type": "type::Vec3 &"
},
{
"name": "rayLength",
"type": "SReal &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
}
],
"description": "The `MechanicalPickParticlesVisitor` is a visitor component in the SOFA framework designed to find mechanical particles that are hit by a given ray. It operates within the simulation's scene graph, interacting with various mechanical states and mappings to identify pickable particles based on their positions relative to the specified ray.\n\nThis component inherits from `BaseMechanicalVisitor`, which provides a foundational structure for traversing the mechanical elements of a SOFA simulation. Its primary methods include:\n- `fwdMechanicalState`: Handles the forward traversal of mechanical states, checking if picking is enabled and whether the model is static or simulated.\n- `fwdMappedMechanicalState`: Similar to `fwdMechanicalState`, but specifically deals with mapped mechanical states.\n- `fwdMechanicalMapping`: Manages the traversal through mappings between mechanical states.\n- `getClosestParticle`: Returns the closest pickable particle along the ray, sorting particles by their distance from the ray and selecting the nearest one.\n\n`MechanicalPickParticlesVisitor` relies on its internal state to store information about the ray (origin and direction) and the radius of the picking area. It also maintains a list of identified particles in `particles`, which is used to determine the closest particle hit by the ray.",
"maths": "The `MechanicalPickParticlesVisitor` is a visitor component in the SOFA framework designed to identify mechanical particles that are hit by a given ray. It operates within the simulation's scene graph, interacting with various mechanical states and mappings to determine which particles intersect with the specified ray.\n\n### Governing Equations or Operators:\n- **Mechanical State Interaction:** The visitor interacts with `BaseMechanicalState` objects to obtain particle positions. For a given set of mechanical particles, their positions are denoted by vectors \\(\\mathbf{p}_i = (x_i, y_i, z_i)\\), where \\(i\\) indexes the particles.\n- **Ray Definition:** The ray is defined by its origin \\(\boldsymbol{o} = (o_x, o_y, o_z)\\) and direction vector \\(\boldsymbol{d} = (d_x, d_y, d_z)\\). Any point on the ray can be parameterized as:\n \n \n \\[ \\mathbf{r}(t) = \\boldsymbol{o} + t \\cdot \\boldsymbol{d}, \\quad t \\in [0, \\infty) \\]\n\n### Constitutive or Kinematic Laws Involved:\n- **Distance Calculation:** The distance from a particle position \\(\boldsymbol{p}_i\\) to the ray is computed using the formula for the perpendicular distance between a point and a line in 3D. This involves finding the minimum distance along the direction vector of the ray.\n\n### Role in the Global FEM Pipeline:\n- **Traversal:** The visitor traverses the mechanical states and mappings within the SOFA scene graph to identify pickable particles. It checks if picking is enabled for each `BaseMechanicalState` and ensures that static objects (not simulated) are excluded from consideration.\n- **Identification:** Once the mechanical state interactions have been processed, the visitor identifies all particles that lie along or near the ray based on their positions relative to the specified ray origin and direction. These particles are stored in an internal list sorted by distance to the ray.\n\n### Numerical Methods or Discretization Choices:\n- **Picking Area Radius:** The visitor uses a picking area radius \\(r_0\\) and a tolerance value \\(\text{dRadius}\\). Particles within this tolerance range from the closest point on the ray are considered for selection. The threshold distance is defined as:\n \n \\[ d_{max} = d + r_0 \\times 10^{-10}, \\]\n where \\(d\\) is the shortest distance to the ray.\n- **Sorting and Selection:** Particles are sorted by their distances from the ray, and the closest one within the tolerance range is selected as the final pickable particle. The distance along the ray direction for each candidate point is computed as:\n \n \\[ t = (\\mathbf{p}_i - \\boldsymbol{o}) \\cdot \\boldsymbol{d}, \\]\n where \\(t\\) represents the parametric position of the intersection along the ray.\n\n### Integration into Variational / Lagrangian Mechanics Framework:\n- **Mechanical State Context:** The visitor operates on mechanical states, which are part of the broader variational mechanics framework. Each `BaseMechanicalState` contains information about particle positions and may be linked through mappings to other mechanical states representing different levels of detail or constraints.\n\n### Summary:\nThe `MechanicalPickParticlesVisitor` is primarily concerned with identifying particles that intersect a given ray within the SOFA simulation environment. It does not directly contribute to governing equations like mass matrices, stiffness matrices, internal forces, or residuals but plays an important role in user interaction and visualization by providing a method for selecting mechanical elements based on their spatial relationships.",
"abstract": "Identifies mechanical particles intersecting a specified ray in SOFA simulations, facilitating user interaction and visualization.",
"sheet": "# MechanicalPickParticlesVisitor\n\n**Overview:**\nMechanicalPickParticlesVisitor is a visitor component that identifies mechanical particles hit by a given ray. It operates within the simulation's scene graph to determine which particles are closest to the ray based on their positions relative to the specified ray origin and direction.\n\nThe component interacts with `BaseMechanicalState` objects to obtain particle positions and uses methods such as `fwdMechanicalState`, `fwdMappedMechanicalState`, and `fwdMechanicalMapping` for traversal. It also includes a method, `getClosestParticle`, which returns the closest pickable particle along the ray.\n\n**Dependencies and Connections:**\nThe component typically requires interaction with mechanical states (`BaseMechanicalState`) and mappings (`BaseMapping`). It fits into the scene graph by traversing these components to identify particles that intersect with a given ray.\n\n**Practical Notes:**\nPicking operations are sensitive to numerical precision, particularly in determining the closest particle. The picking area radius and tolerance values must be carefully configured to ensure accurate selection of particles."
}