Commit 53d274f3 authored by Baptiste Durand's avatar Baptiste Durand

black formatting

parent 6a598503
......@@ -18,42 +18,43 @@ PLANE_IDX = np.array([0, 1, 5])
class Material(object):
def __init__(self, E, nu, cas_elast='cp'):
def __init__(self, E, nu, cas_elast="cp"):
""" Définir un nouveau comportement élastique, exclusivement isotrope pour le moment.
cas_elast : Choisir entre 'cp' contraintes planes, 'dp' déformations planes ou '3D'.
"""
self.E = E
self.nu = nu
self.G = self.E / (2.*(1 + self.nu))
self.G = self.E / (2.0 * (1 + self.nu))
self.cas_elast = cas_elast
self.S_3D = np.array((
(1./self.E, -self.nu/self.E, -self.nu/self.E, 0., 0., 0.),
(-self.nu/self.E, 1./self.E, -self.nu/self.E, 0., 0., 0.),
(-self.nu/self.E, -self.nu/self.E, 1./self.E, 0., 0., 0.),
(0., 0., 0., 1./(2.*self.G), 0., 0.),
(0., 0., 0., 0., 1./(2.*self.G), 0.),
(0., 0., 0., 0., 0., 1./(2.*self.G))
))
self.S_3D = np.array(
(
(1.0 / self.E, -self.nu / self.E, -self.nu / self.E, 0.0, 0.0, 0.0),
(-self.nu / self.E, 1.0 / self.E, -self.nu / self.E, 0.0, 0.0, 0.0),
(-self.nu / self.E, -self.nu / self.E, 1.0 / self.E, 0.0, 0.0, 0.0),
(0.0, 0.0, 0.0, 1.0 / (2.0 * self.G), 0.0, 0.0),
(0.0, 0.0, 0.0, 0.0, 1.0 / (2.0 * self.G), 0.0),
(0.0, 0.0, 0.0, 0.0, 0.0, 1.0 / (2.0 * self.G)),
)
)
self.C_3D = np.linalg.inv(self.S_3D)
self.set_elast[cas_elast](self)
def set_cp(self):
self.S = self.S_3D[PLANE_IDX[:, None], PLANE_IDX]
self.C = np.linalg.inv(self.S)
self.cas_elast = 'cp'
self.cas_elast = "cp"
def set_dp(self):
self.C = self.C_3D[PLANE_IDX[:, None], PLANE_IDX]
self.S = np.linalg.inv(self.C)
self.cas_elast = 'dp'
self.cas_elast = "dp"
def set_3D(self):
self.S = self.S_3D
self.C = self.C_3D
self.cas_elast = '3D'
self.cas_elast = "3D"
# Dictionnaire des méthodes set
set_elast = {"cp": set_cp, "dp": set_dp, "3D": set_3D}
......@@ -70,14 +71,15 @@ class Material(object):
class StiffnessComponent(fe.UserExpression):
""" FEniCS Expression that represent one component of the stiffness tensor on a mesh that contain several subdomains."""
def __init__(self, cell_function, mat_dict, i, j, **kwargs):
self.cell_function = cell_function
self.mat_dict = mat_dict
self.i = i
self.j = j
super().__init__(degree=kwargs["degree"])
#? Info : https://docs.python.org/fr/3/library/functions.html#super,
#? and http://folk.uio.no/kent-and/hpl-fem-book/doc/pub/book/pdf/fem-book-4print-2up.pdf
# ? Info : https://docs.python.org/fr/3/library/functions.html#super,
# ? and http://folk.uio.no/kent-and/hpl-fem-book/doc/pub/book/pdf/fem-book-4print-2up.pdf
def eval_cell(self, values, x, cell):
subdomain_id = self.cell_function[cell.index]
......@@ -106,7 +108,7 @@ def mat_per_subdomains(cell_function, mat_dict, topo_dim):
"""
C = []
nb_val = int(topo_dim * (topo_dim + 1)/2)
nb_val = int(topo_dim * (topo_dim + 1) / 2)
for i in range(nb_val):
Cj = []
for j in range(nb_val):
......@@ -117,7 +119,9 @@ def mat_per_subdomains(cell_function, mat_dict, topo_dim):
def epsilon(u):
return fe.as_vector((u[0].dx(0), u[1].dx(1), (u[0].dx(1) + u[1].dx(0))/math.sqrt(2)))
return fe.as_vector(
(u[0].dx(0), u[1].dx(1), (u[0].dx(1) + u[1].dx(0)) / math.sqrt(2))
)
def sigma(C, eps):
......@@ -128,14 +132,18 @@ def strain_cross_energy(sig, eps, mesh, area):
"""
Calcul de l'energie croisée des champs de contrainte sig et de deformation eps.
"""
# TODO : Redondant. Voir si cela est nécessaire.
return fe.assemble(fe.inner(sig, eps) * fe.dx(mesh)) / area
return fe.assemble(fe.inner(sig, eps) * fe.dx(mesh))/area
def cross_energy(sig, eps, mesh):
"""
Calcul de l'energie croisée des champs de contrainte sig et de deformation eps.
"""
return fe.assemble(fe.inner(sig, eps) * fe.dx(mesh))
# def energy_norm()
# return fe.assemble(fe.inner(sig, eps) * fe.dx(mesh))/area
......
......@@ -35,19 +35,17 @@ def test_rve_2_part():
def test_pantograph_offset():
geo.set_gmsh_option('Mesh.MshFileVersion', 4.1)
geo.set_gmsh_option("Mesh.MshFileVersion", 4.1)
a = 1
b, k = a, a/3
b, k = a, a / 3
t = 0.02
panto_test = mesh2D.pantograph_offset_RVE(
a, b, k, t, nb_cells=(1, 1), soft_mat=False, name='panto_rve_1x1')
lc_ratio = 1/6
lc_min_max = (lc_ratio*t*a, lc_ratio*a)
panto_test.main_mesh_refinement((2*t*a, a), lc_min_max, False)
a, b, k, t, nb_cells=(1, 1), soft_mat=False, name="panto_rve_1x1"
)
lc_ratio = 1 / 6
lc_min_max = (lc_ratio * t * a, lc_ratio * a)
panto_test.main_mesh_refinement((2 * t * a, a), lc_min_max, False)
panto_test.mesh_generate()
gmsh.model.mesh.renumberNodes()
gmsh.model.mesh.renumberElements()
gmsh.write("panto_rve_offset.msh")
test_pantograph_offset()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment