Skip to content

Commit

Permalink
update strain
Browse files Browse the repository at this point in the history
  • Loading branch information
obouchaara committed Jun 12, 2024
1 parent 82574e8 commit 5686c51
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 54 deletions.
75 changes: 33 additions & 42 deletions notebooks/symbolic/strain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,13 @@
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"mechpy.core.symbolic.strain.SymbolicStrainTensor"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"e1, e2, e3, e4, e5, e6 = sp.symbols(\"epsilon_1 epsilon_2 epsilon_3 epsilon_4 epsilon_5 epsilon_6\")\n",
"data = sp.ImmutableDenseNDimArray([e1, e2, e3, e4, e5, e6])\n",
"display(data)\n",
"data = sp.NDimArray([e1, e2, e3, e4, e5, e6])\n",
"strain_tensor = SymbolicStrainTensor(data)\n",
"display(strain_tensor.__class__)"
"display(strain_tensor.data)\n"
]
},
{
Expand All @@ -90,8 +80,20 @@
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\epsilon_{1} & \\epsilon_{2} & \\epsilon_{3} & \\epsilon_{4} & \\epsilon_{5} & \\epsilon_{6}\\end{matrix}\\right]$"
],
"text/plain": [
"mechpy.core.symbolic.strain.SymbolicStrainTensor"
"[\\epsilon_1, \\epsilon_2, \\epsilon_3, \\epsilon_4, \\epsilon_5, \\epsilon_6]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'standard'"
]
},
"metadata": {},
Expand All @@ -112,10 +114,8 @@
],
"source": [
"strain_tensor = SymbolicStrainTensor.create()\n",
"display(strain_tensor.__class__)\n",
"# display(strain_tensor.data)\n",
"# display(strain_tensor.notation)\n",
"# display(strain_tensor.name)\n",
"display(strain_tensor.data)\n",
"display(strain_tensor.notation)\n",
"display(strain_tensor.to_general().data)"
]
},
Expand Down Expand Up @@ -146,19 +146,7 @@
{
"data": {
"text/plain": [
"2"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/latex": [
"$\\displaystyle \\epsilon$"
],
"text/plain": [
"\\epsilon"
"'voigt'"
]
},
"metadata": {},
Expand All @@ -178,12 +166,9 @@
}
],
"source": [
"strain_tensor = SymbolicStrainTensor.create(notation=2)\n",
"# display(strain_tensor)\n",
"strain_tensor = SymbolicStrainTensor.create(notation=\"voigt\")\n",
"display(strain_tensor.data)\n",
"display(strain_tensor.notation)\n",
"# display(strain_tensor.name)\n",
"display(sp.symbols(strain_tensor.name))\n",
"display(strain_tensor.to_general().data)"
]
},
Expand All @@ -202,10 +187,19 @@
{
"data": {
"text/latex": [
"$\\displaystyle \\epsilon^{1}$"
"$\\displaystyle \\left[\\begin{matrix}\\epsilon^{1}_{11} & \\epsilon^{1}_{22} & \\epsilon^{1}_{33} & 2 \\epsilon^{1}_{23} & 2 \\epsilon^{1}_{13} & 2 \\epsilon^{1}_{12}\\end{matrix}\\right]$"
],
"text/plain": [
"\\epsilon^1"
"[\\epsilon^1_11, \\epsilon^1_22, \\epsilon^1_33, 2*\\epsilon^1_23, 2*\\epsilon^1_13, 2*\\epsilon^1_12]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'voigt'"
]
},
"metadata": {},
Expand All @@ -225,12 +219,9 @@
}
],
"source": [
"strain_tensor = SymbolicStrainTensor.create(name=\"\\epsilon^1\", notation=2)\n",
"# display(strain_tensor)\n",
"# display(strain_tensor.data)\n",
"# display(strain_tensor.notation)\n",
"# display(strain_tensor.name)\n",
"display(sp.symbols(strain_tensor.name))\n",
"strain_tensor = SymbolicStrainTensor.create(name=\"\\epsilon^1\", notation=\"voigt\")\n",
"display(strain_tensor.data)\n",
"display(strain_tensor.notation)\n",
"display(strain_tensor.to_general().data)"
]
},
Expand Down
29 changes: 18 additions & 11 deletions src/mechpy/core/symbolic/strain.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,39 @@


class SymbolicStrainTensor(SS3X3T):
STRAIN_VOIGT_MAPPING = {0: 1, 1: 1, 2: 1, 3: 2, 4: 2, 5: 2}

def __init__(self, data, name=None, notation=1):
STRAIN_VOIGT_MAPPING = {
0: 1,
1: 1,
2: 1,
3: 2,
4: 2,
5: 2,
}

def __init__(self, data, name=None, notation=None):
super().__init__(data, name=name, notation=notation)

@classmethod
def create(cls, name="\epsilon", notation=1):
strain_tensor = super().create(name, notation)
if notation == 2:
def create(cls, name="\\epsilon", notation=None):
strain_tensor = super().create(name, notation=notation)
if strain_tensor.notation == "voigt":
data = strain_tensor.data
mapping = cls.STRAIN_VOIGT_MAPPING
new_components = [data[key] * value for key, value in mapping.items()]
strain_tensor = cls.from_list(new_components, notation=notation, name=name)
return strain_tensor

def to_general(self):
if self.notation == 1:
if self.notation == "standard":
if self.name:
return SymbolicStrainTensor.create(
name=self.name, notation=2
name=self.name,
notation="voigt",
).to_general()
raise ValueError("Should have a name")
elif self.notation == 2:
data = self.data
elif self.notation == "voigt":
mapping = self.STRAIN_VOIGT_MAPPING
new_components = [data[key] / value for key, value in mapping.items()]
new_components = [self.data[key] / value for key, value in mapping.items()]
return SS3X3T.from_list(new_components, self.notation).to_general()
raise ValueError()

Expand Down
44 changes: 43 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
SymbolicStressTensor,
)

from mechpy.core.symbolic.strain import (
SymbolicStrainTensor,
)


class TestSymbolicCoordSystem(unittest.TestCase):
def test_init(self):
Expand Down Expand Up @@ -1007,7 +1011,7 @@ def test_create(self):

stress_tensor = SymbolicStressTensor.create()
self.assertIsInstance(stress_tensor, SymbolicStressTensor)
stress_tensor = SymbolicStressTensor(data)
self.assertEqual(stress_tensor.data, data)

def test_to_general(self):
pass
Expand Down Expand Up @@ -1047,5 +1051,43 @@ def test_von_mises(self):
pass


class TestSymbolicStrainTensor(unittest.TestCase):
def test_init(self):
s_1, s_2, s_3, s_4, s_5, s_6 = sp.symbols(
"\\epsilon_1 \\epsilon_2 \\epsilon_3 \\epsilon_4 \\epsilon_5 \\epsilon_6"
)
data = sp.NDimArray([s_1, s_2, s_3, s_4, s_5, s_6])
strain_tensor = SymbolicStrainTensor(data)
self.assertEqual(strain_tensor.data, data)
self.assertEqual(strain_tensor.name, None)
self.assertEqual(strain_tensor.notation, "standard")
self.assertEqual(strain_tensor.tensor_params, {})

def test_create(self):
s_1, s_2, s_3, s_4, s_5, s_6 = sp.symbols(
"\\epsilon_1 \\epsilon_2 \\epsilon_3 \\epsilon_4 \\epsilon_5 \\epsilon_6"
)
data = sp.NDimArray([s_1, s_2, s_3, s_4, s_5, s_6])

strain_tensor = SymbolicStrainTensor.create()
self.assertIsInstance(strain_tensor, SymbolicStrainTensor)
self.assertEqual(strain_tensor.data, data)

def test_to_general(self):
pass

def test_normal_components(self):
pass

def test_shear_components(self):
pass

def test_principal_components(self):
pass

def test_volumetric_strain(self):
pass


if __name__ == "__main__":
unittest.main()

0 comments on commit 5686c51

Please sign in to comment.