Skip to content

Commit

Permalink
[Constraints] Created VertexConstraint
Browse files Browse the repository at this point in the history
  • Loading branch information
arpastrana committed Sep 21, 2024
1 parent 848a2ac commit da310d2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/jax_fdm/constraints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .node import * # noqa F403
from .edge import * # noqa F403
from .network import * # noqa F403
from .vertex import * # noqa F403


__all__ = [name for name in dir() if not name.startswith('_')]
5 changes: 5 additions & 0 deletions src/jax_fdm/constraints/vertex/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .vertex import * # noqa F403
from .coordinates import * # noqa F403


__all__ = [name for name in dir() if not name.startswith('_')]
37 changes: 37 additions & 0 deletions src/jax_fdm/constraints/vertex/coordinates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from jax_fdm.constraints.vertex import VertexConstraint


class VertexXCoordinateConstraint(VertexConstraint):
"""
Constraint the X coordinate of a vertex between a lower and an upper bound.
"""
@staticmethod
def constraint(eqstate, index):
"""
Returns the X coordinate of a vertex from an equilibrium state.
"""
return eqstate.xyz[index, :1]


class VertexYCoordinateConstraint(VertexConstraint):
"""
Constraint the Y coordinate of a vertex between a lower and an upper bound.
"""
@staticmethod
def constraint(eqstate, index):
"""
Returns the Y coordinate of a vertex from an equilibrium state.
"""
return eqstate.xyz[index, 1:2]


class VertexZCoordinateConstraint(VertexConstraint):
"""
Constraint the Z coordinate of a vertex between a lower and an upper bound.
"""
@staticmethod
def constraint(eqstate, index):
"""
Returns the Z coordinate of a vertex from an equilibrium state.
"""
return eqstate.xyz[index, 2]
15 changes: 15 additions & 0 deletions src/jax_fdm/constraints/vertex/vertex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from jax_fdm.constraints import Constraint


class VertexConstraint(Constraint):
"""
Base class for all constraints that pertain to a vertex in a mesh.
"""
def index_from_model(self, model, structure):
"""
The index of the node in a structure.
"""
try:
return structure.vertex_index[self.key]
except TypeError:
return tuple([structure.vertex_index[k] for k in self.key])

0 comments on commit da310d2

Please sign in to comment.