33# SPDX-FileContributor: Alexandre Benedicto, Martin Lemay
44import numpy as np
55import numpy .typing as npt
6- from typing_extensions import Self
6+ from typing_extensions import Self , Any
77
88from geos .geomechanics .processing .geomechanicsCalculatorFunctions import (
99 computeStressPrincipalComponentsFromStressVector , )
1010
1111__doc__ = """
1212MohrCircle module define the Mohr's circle parameters.
1313
14- Inputs are a 6 component stress vector, a circle id, and the mechanical
15- convention used for compression.
14+ Inputs are a 6 component stress vector, and a circle id.
1615The class computes principal components from stress vector during initialization.
1716Accessors get access to these 3 principal components as well as circle center
1817and radius.
2322
2423 from processing.MohrCircle import MohrCircle
2524
26- # create the object
27- stressVector : npt.NDArray[np.float64]
28- circleId : str
29- mohrCircle : MohrCircle = MohrCircle(circleId)
25+ # Create the object
26+ stressVector: npt.NDArray[np.float64]
27+ circleId: str
28+ mohrCircle: MohrCircle = MohrCircle(circleId)
3029
31- # either directly set principal components (p3 <= p2 <= p1)
30+ # Either directly set principal components (p3 <= p2 <= p1)
3231 mohrCircle.SetPrincipalComponents(p3, p2, p1)
33- # or compute them from stress vector
32+ # Or compute them from stress vector
3433 mohrCircle.computePrincipalComponents(stressVector)
3534
36- # access to members
37- id : str = mohrCircle.getCircleId()
38- p1, p2, p3 : float = mohrCircle.getPrincipalComponents()
39- radius : float = mohrCircle.getCircleRadius()
40- center : float = mohrCircle.getCircleCenter()
35+ # Access to members
36+ id: str = mohrCircle.getCircleId()
37+ p1, p2, p3: float = mohrCircle.getPrincipalComponents()
38+ radius: float = mohrCircle.getCircleRadius()
39+ center: float = mohrCircle.getCircleCenter()
4140"""
4241
4342
@@ -49,60 +48,86 @@ def __init__( self: Self, circleId: str ) -> None:
4948 Args:
5049 circleId (str): Mohr's circle id.
5150 """
52- self .m_circleId : str = circleId
51+ self .circleId : str = circleId
5352
54- self .m_p1 : float = 0.0
55- self .m_p2 : float = 0.0
56- self .m_p3 : float = 0.0
53+ self .p1 : float = 0.0
54+ self .p2 : float = 0.0
55+ self .p3 : float = 0.0
5756
5857 def __str__ ( self : Self ) -> str :
5958 """Overload of __str__ method."""
60- return self .m_circleId
59+ return self .circleId
6160
6261 def __repr__ ( self : Self ) -> str :
6362 """Overload of __repr__ method."""
64- return self .m_circleId
63+ return self .circleId
64+
65+ def __eq__ ( self : Self , other : Any ) -> bool :
66+ """Overload of __eq__ method."""
67+ if not isinstance ( other , MohrCircle ):
68+ return NotImplemented
69+ return self .circleId == other .circleId
70+
71+ def __hash__ ( self : Self ) -> int :
72+ """Overload of hash method."""
73+ return hash ( self .circleId )
6574
6675 def setCircleId ( self : Self , circleId : str ) -> None :
6776 """Set circle Id variable.
6877
6978 Args:
70- circleId (str): circle Id.
79+ circleId (str): Circle Id.
7180 """
72- self .m_circleId = circleId
81+ self .circleId = circleId
7382
7483 def getCircleId ( self : Self ) -> str :
7584 """Access the Id of the Mohr circle.
7685
7786 Returns:
7887 str: Id of the Mohr circle
7988 """
80- return self .m_circleId
89+ return self .circleId
8190
8291 def getCircleRadius ( self : Self ) -> float :
83- """Compute and return Mohr's circle radius from principal components."""
84- return ( self .m_p1 - self .m_p3 ) / 2.0
92+ """Compute and return Mohr's circle radius from principal components.
93+
94+ Returns:
95+ float: Mohr circle radius.
96+ """
97+ return ( self .p1 - self .p3 ) / 2.0
8598
8699 def getCircleCenter ( self : Self ) -> float :
87- """Compute and return Mohr's circle center from principal components."""
88- return ( self .m_p1 + self .m_p3 ) / 2.0
100+ """Compute and return Mohr's circle center from principal components.
101+
102+ Returns:
103+ float: Mohr circle center.
104+ """
105+ return ( self .p1 + self .p3 ) / 2.0
89106
90107 def getPrincipalComponents ( self : Self ) -> tuple [ float , float , float ]:
91- """Get Moh's circle principal components."""
92- return ( self .m_p3 , self .m_p2 , self .m_p1 )
108+ """Get Moh's circle principal components.
109+
110+ Returns:
111+ tuple[float, float, float]: Mohr circle principal components.
112+ """
113+ return ( self .p3 , self .p2 , self .p1 )
93114
94115 def setPrincipalComponents ( self : Self , p3 : float , p2 : float , p1 : float ) -> None :
95116 """Set principal components.
96117
97118 Args:
98- p3 (float): first component. Must be the lowest.
99- p2 (float): second component.
100- p1 (float): third component. Must be the greatest.
119+ p3 (float): First component. Must be the lowest.
120+ p2 (float): Second component.
121+ p1 (float): Third component. Must be the greatest.
122+
123+ Raises:
124+ ValueError: Expected p3 <= p2 <= p1.
101125 """
102- assert ( p3 <= p2 ) and ( p2 <= p1 ), "Component order is wrong."
103- self .m_p3 = p3
104- self .m_p2 = p2
105- self .m_p1 = p1
126+ if ( p3 <= p2 ) and ( p2 <= p1 ):
127+ raise ValueError ( "Component order is wrong. Expected p3 <= p2 <= p1." )
128+ self .p3 = p3
129+ self .p2 = p2
130+ self .p1 = p1
106131
107132 def computePrincipalComponents ( self : Self , stressVector : npt .NDArray [ np .float64 ] ) -> None :
108133 """Calculate principal components.
@@ -111,5 +136,5 @@ def computePrincipalComponents( self: Self, stressVector: npt.NDArray[ np.float6
111136 stressVector (npt.NDArray[np.float64]): 6 components stress vector
112137 Stress vector must follow GEOS convention (XX, YY, ZZ, YZ, XZ, XY)
113138 """
114- # get stress principal components
115- self .m_p3 , self .m_p2 , self .m_p1 = ( computeStressPrincipalComponentsFromStressVector ( stressVector ) )
139+ # Get stress principal components
140+ self .p3 , self .p2 , self .p1 = ( computeStressPrincipalComponentsFromStressVector ( stressVector ) )
0 commit comments