Commit 5baa7eed authored by Baptiste Durand's avatar Baptiste Durand

Split of the mesh_generate file

parent ea814ebe
......@@ -11,17 +11,16 @@ The Gmsh2DRVE class has been specially designed for the generation of meshes tha
import copy
import logging
import math
from itertools import chain, product
from pathlib import Path, PurePath
import gmsh
import numpy as np
from more_itertools import flatten, one, padded
from itertools import product, chain
import ho_homog.geometry as geo
import ho_homog.mesh_tools as msh
# TODO : placer un asarray dans la def de __init__ pour Point
# nice shortcuts
model = gmsh.model
factory = model.occ
......@@ -54,9 +53,6 @@ def duplicate_pattern(cell_ll, nb_cells, gen_vect):
gen_vect_3D[: gen_vect.shape[0], : gen_vect.shape[1]] = gen_vect
else:
gen_vect_3D = gen_vect
# moins générique : gen_vect_3D = np.pad(a,((0, 1), (0, 1)),'constant',constant_values=0)
# source : https://stackoverflow.com/questions/35751306/python-how-to-pad-numpy-array-with-zeros
for k in range(len(nb_cells)):
if nb_cells[k] > 1:
new_contours = list()
......@@ -96,8 +92,6 @@ def offset_pattern(cell_ll, offset, cell_vect):
class Gmsh2DRVE(object):
# ? Et si il y a pas seulement du mou et du vide mais plus de 2 matériaux constitutifs ? Imaginer une autre sous-classe semblable qui permet de définir plusieurs sous-domaines à partir d'une liste d'ensembles de LineLoop (chaque ensemble correspondant à un type d'inclusions ?)
def __init__(
self, pattern_ll, cell_vect, nb_cells, offset, attractors, soft_mat, name
):
......@@ -319,96 +313,6 @@ class Gmsh2DRVE(object):
gmsh.write(str(mesh_path))
self.mesh_abs_path = mesh_path
@staticmethod
def pantograph(
a, b, k, junction_r, nb_cells=(1, 1), offset=(0.0, 0.0), soft_mat=False, name=""
):
"""
Create an instance of Gmsh2DRVE that represents a RVE of the pantograph microstructure.
The geometry that is specific to this microstructure is defined in this staticmethod. Then, the generic operations will be performed with the Gmsh2DRVE methods.
Parameters
----------
a,b and k : floats
main lengths of the microstruture
junction_r : float
radius of the junctions inside the pantograph microstructure
nb_cells : tuple or 1D array
nb of cells in each direction of repetition
offset : tuple or 1D array
Relative position inside a cell of the point that will coincide with the origin of the global domain
Returns
-------
Instance of the Gmsh2DRVE class.
"""
name = name if name else "pantograph"
offset = np.asarray(offset)
nb_cells = np.asarray(nb_cells)
logger.info("Start defining the pantograph geometry")
Lx = 4 * a
Ly = 6 * a + 2 * b
cell_vect = np.array(((Lx, 0.0), (0.0, Ly)))
e1 = np.array((a, 0.0, 0.0))
e2 = np.array((0.0, a, 0.0))
p = np.array((k, 0.0, 0.0))
b_ = b / a * e2
E1 = geo.Point(e1)
E2 = geo.Point(e2)
E1m = geo.Point(-1 * e1)
E2m = geo.Point(-1 * e2)
L = geo.Point(2 * (e1 + e2))
Lm = geo.Point(2 * (e1 - e2))
M = geo.Point(e1 + 1.5 * e2 + b_ / 2)
I = geo.Point(2 * (e1 + 1.5 * e2 + b_ / 2))
contours = list()
contours.append([E1, E2, E1m, E2m])
contours.append([E1, Lm, geo.Point(3 * e1), L])
contours.append(
[
E2,
L,
geo.translation(L, 0.5 * b_ - p),
geo.translation(L, b_),
geo.translation(E2, b_),
geo.translation(E2, 0.5 * b_ + p),
]
)
pattern_ll = [geo.LineLoop(pt_list, explicit=False) for pt_list in contours]
pattern_ll += [geo.point_reflection(ll, M) for ll in pattern_ll]
sym_ll = [geo.plane_reflection(ll, I, e1) for ll in pattern_ll]
for ll in sym_ll:
ll.reverse()
pattern_ll += sym_ll
sym_ll = [geo.plane_reflection(ll, I, e2) for ll in pattern_ll]
for ll in sym_ll:
ll.reverse()
pattern_ll += sym_ll
pattern_ll = geo.remove_duplicates(pattern_ll)
logger.info("Done removing of the line-loops duplicates")
for ll in pattern_ll:
ll.round_corner_incircle(junction_r)
logger.info("Done rounding all corners of pattern line-loops")
constr_pts = [pt for ll in pattern_ll for pt in ll.vertices]
fine_pts = [
pt
for pt in constr_pts
if (pt.coord[0] % 1 < p[0] / 2.0 or pt.coord[0] % 1 > 1.0 - p[0] / 2.0)
]
fine_pts = geo.remove_duplicates(fine_pts)
return Gmsh2DRVE(
pattern_ll, cell_vect, nb_cells, offset, fine_pts, soft_mat, name
)
@staticmethod
def auxetic_square(
L, a, t, nb_cells=(1, 1), offset=(0.0, 0.0), soft_mat=False, name=""
......@@ -497,103 +401,6 @@ class Gmsh2DRVE(object):
pattern_ll, gen_vect, nb_cells, offset, fine_pts, soft_mat, name
)
@staticmethod
def beam_pantograph(
a,
b,
w,
junction_r=0.0,
nb_cells=(1, 1),
offset=(0.0, 0.0),
soft_mat=False,
name="",
):
"""
Create an instance of Gmsh2DRVE that represents a RVE of the beam pantograph microstructure.
The geometry that is specific to this microstructure is defined in this staticmethod. Then, the generic operations will be performed with the Gmsh2DRVE methods.
Parameters
----------
a, b : floats
main lengths of the microstruture
w : float
width of the constitutive beams
junction_r : float, optional
Radius of the corners/fillets that are created between concurrent borders of beams.
The default is 0., which implies that the angles will not be rounded.
nb_cells : tuple or 1D array, optional
nb of cells in each direction of repetition (the default is (1, 1).)
offset : tuple, optional
If (0., 0.) or False : No shift of the microstructure.
Else : The microstructure is shift with respect to the macroscopic domain.
offset is the relative position inside a cell of the point that will coincide with the origin of the global domain.
soft_mat : bool, optional
If True : the remaining surface inside the RVE is associated with a second material domain and a mesh is genereted to represent it.
Else, this space remains empty.
name : str, optional
The name of the RVE. It is use for the gmsh model and the mesh files.
If name is '' (default) or False, the name of the RVE is 'beam_pantograph'.
Returns
-------
Instance of the Gmsh2DRVE class.
"""
name = name if name else "beam_pantograph"
offset = np.asarray(offset)
nb_cells = np.asarray(nb_cells)
logger.info("Start defining the beam pantograph geometry")
Lx = 4 * a
Ly = 6 * a + 2 * b
cell_vect = np.array(((Lx, 0.0), (0.0, Ly)))
e1 = np.array((a, 0.0, 0.0))
e2 = np.array((0.0, a, 0.0))
b_ = b / a * e2
E1 = geo.Point(e1)
E2 = geo.Point(e2)
E1m = geo.Point(-1 * e1)
E2m = geo.Point(-1 * e2)
L = geo.Point(2 * (e1 + e2))
Lm = geo.Point(2 * (e1 - e2))
M = geo.Point(e1 + 1.5 * e2 + b_ / 2)
I = geo.Point(2 * (e1 + 1.5 * e2 + b_ / 2))
contours = [
[E1, E2, E1m, E2m],
[E1, Lm, geo.Point(3 * e1), L],
[E1, L, E2],
[E2, L, geo.translation(L, b_), geo.translation(E2, b_)],
]
pattern_ll = [geo.LineLoop(pt_list, explicit=False) for pt_list in contours]
pattern_ll += [geo.point_reflection(ll, M) for ll in pattern_ll]
sym_ll = [geo.plane_reflection(ll, I, e1) for ll in pattern_ll]
for ll in sym_ll:
ll.reverse()
pattern_ll += sym_ll
sym_ll = [geo.plane_reflection(ll, I, e2) for ll in pattern_ll]
for ll in sym_ll:
ll.reverse()
pattern_ll += sym_ll
pattern_ll = geo.remove_duplicates(pattern_ll)
constr_pts = [copy.deepcopy(pt) for ll in pattern_ll for pt in ll.vertices]
for ll in pattern_ll:
ll.offset(w)
if junction_r:
for ll in pattern_ll:
ll.round_corner_incircle(junction_r)
fine_pts = geo.remove_duplicates(constr_pts)
return Gmsh2DRVE(
pattern_ll, cell_vect, nb_cells, offset, fine_pts, soft_mat, name
)
class Gmsh2DPart(object):
def __init__(self, gen_vect, nb_cells, phy_surf, mesh_path: PurePath):
......
"""
Created on 17/01/2019
@author: Baptiste Durand, baptiste.durand@enpc.fr
"""
import copy
import gmsh
import numpy as np
import ho_homog.geometry as geo
from . import Gmsh2DRVE, logger
model = gmsh.model
factory = model.occ
def pantograph_RVE(
a, b, k, junction_r, nb_cells=(1, 1), offset=(0.0, 0.0), soft_mat=False, name=""
):
"""
Create an instance of Gmsh2DRVE that represents a RVE of the pantograph microstructure.
The geometry that is specific to this microstructure is defined in this staticmethod. Then, the generic operations will be performed with the Gmsh2DRVE methods.
Parameters
----------
a,b and k : floats
main lengths of the microstruture
junction_r : float
radius of the junctions inside the pantograph microstructure
nb_cells : tuple or 1D array
nb of cells in each direction of repetition
offset : tuple or 1D array
Relative position inside a cell of the point that will coincide with the origin of the global domain
Returns
-------
Instance of the Gmsh2DRVE class.
"""
name = name if name else "pantograph"
offset = np.asarray(offset)
nb_cells = np.asarray(nb_cells)
logger.info("Start defining the pantograph geometry")
Lx = 4 * a
Ly = 6 * a + 2 * b
cell_vect = np.array(((Lx, 0.0), (0.0, Ly)))
e1 = np.array((a, 0.0, 0.0))
e2 = np.array((0.0, a, 0.0))
p = np.array((k, 0.0, 0.0))
b_ = b / a * e2
E1 = geo.Point(e1)
E2 = geo.Point(e2)
E1m = geo.Point(-1 * e1)
E2m = geo.Point(-1 * e2)
L = geo.Point(2 * (e1 + e2))
Lm = geo.Point(2 * (e1 - e2))
M = geo.Point(e1 + 1.5 * e2 + b_ / 2)
I = geo.Point(2 * (e1 + 1.5 * e2 + b_ / 2))
contours = list()
contours.append([E1, E2, E1m, E2m])
contours.append([E1, Lm, geo.Point(3 * e1), L])
contours.append(
[
E2,
L,
geo.translation(L, 0.5 * b_ - p),
geo.translation(L, b_),
geo.translation(E2, b_),
geo.translation(E2, 0.5 * b_ + p),
]
)
pattern_ll = [geo.LineLoop(pt_list, explicit=False) for pt_list in contours]
pattern_ll += [geo.point_reflection(ll, M) for ll in pattern_ll]
sym_ll = [geo.plane_reflection(ll, I, e1) for ll in pattern_ll]
for ll in sym_ll:
ll.reverse()
pattern_ll += sym_ll
sym_ll = [geo.plane_reflection(ll, I, e2) for ll in pattern_ll]
for ll in sym_ll:
ll.reverse()
pattern_ll += sym_ll
pattern_ll = geo.remove_duplicates(pattern_ll)
logger.info("Done removing of the line-loops duplicates")
for ll in pattern_ll:
ll.round_corner_incircle(junction_r)
logger.info("Done rounding all corners of pattern line-loops")
constr_pts = [pt for ll in pattern_ll for pt in iter((ll.vertices))]
fine_pts = [
pt
for pt in constr_pts
if pt.coord[0] % 1 < p[0] / 2.0 or pt.coord[0] % 1 > 1.0 - p[0] / 2.0
]
fine_pts = geo.remove_duplicates(fine_pts)
return Gmsh2DRVE(pattern_ll, cell_vect, nb_cells, offset, fine_pts, soft_mat, name)
def pantograph_offset_RVE(
a,
b,
k,
thickness,
fillet_r=0.0,
nb_cells=(1, 1),
offset=(0.0, 0.0),
soft_mat=False,
name="",
):
"""
Generate a RVE object for the pantograph microstructure.
Junctions are obtained by creating offset curves from the microstructure contour.
Parameters
----------
a,b and k : floats
main lengths of the microstruture
thickness : float
distance of translation prescribed for the vertices of the contour
fillet_r : float
radius of the fillets for the contour
nb_cells : tuple or 1D array
nb of cells in each direction of repetition
offset : tuple or 1D array
Relative position inside a cell of the point that will coincide with the origin of the global domain
Returns
-------
Instance of the Gmsh2DRVE class.
"""
name = name if name else "pantograph"
offset = np.asarray(offset)
nb_cells = np.asarray(nb_cells)
logger.info("Start defining the pantograph geometry")
Lx = 4 * a
Ly = 6 * a + 2 * b
cell_vect = np.array(((Lx, 0.0), (0.0, Ly)))
e1 = np.array((a, 0.0, 0.0))
e2 = np.array((0.0, a, 0.0))
p = np.array((k, 0.0, 0.0))
b_ = b / a * e2
E1 = geo.Point(e1)
E2 = geo.Point(e2)
E1m = geo.Point(-1 * e1)
E2m = geo.Point(-1 * e2)
L = geo.Point(2 * (e1 + e2))
Lm = geo.Point(2 * (e1 - e2))
M = geo.Point(e1 + 1.5 * e2 + b_ / 2)
I = geo.Point(2 * (e1 + 1.5 * e2 + b_ / 2))
contours = list()
contours.append([E1, E2, E1m, E2m])
contours.append([E1, Lm, geo.Point(3 * e1), L])
contours.append(
[
E2,
L,
geo.translation(L, 0.5 * b_ - p),
geo.translation(L, b_),
geo.translation(E2, b_),
geo.translation(E2, 0.5 * b_ + p),
]
)
pattern_ll = [geo.LineLoop(pt_list, explicit=False) for pt_list in contours]
pattern_ll += [geo.point_reflection(ll, M) for ll in pattern_ll]
sym_ll = [geo.plane_reflection(ll, I, e1) for ll in pattern_ll]
for ll in sym_ll:
ll.reverse()
pattern_ll += sym_ll
sym_ll = [geo.plane_reflection(ll, I, e2) for ll in pattern_ll]
for ll in sym_ll:
ll.reverse()
pattern_ll += sym_ll
pattern_ll = geo.remove_duplicates(pattern_ll)
logger.info("Done removing of the line-loops duplicates")
constr_pts = [copy.deepcopy(pt) for ll in pattern_ll for pt in iter((ll.vertices))]
for ll in pattern_ll:
ll.offset(thickness)
if fillet_r:
for ll in pattern_ll:
ll.round_corner_explicit(fillet_r)
logger.info("Done rounding all corners of pattern line-loops")
fine_pts = [
pt
for pt in constr_pts
if pt.coord[0] % 1 < p[0] / 2.0 or pt.coord[0] % 1 > 1.0 - p[0] / 2.0
]
fine_pts = geo.remove_duplicates(fine_pts)
return Gmsh2DRVE(pattern_ll, cell_vect, nb_cells, offset, fine_pts, soft_mat, name)
def beam_pantograph_RVE(
a, b, w, junction_r=0.0, nb_cells=(1, 1), offset=(0.0, 0.0), soft_mat=False, name=""
):
"""
Create an instance of Gmsh2DRVE that represents a RVE of the beam pantograph microstructure.
The geometry that is specific to this microstructure is defined in this staticmethod. Then, the generic operations will be performed with the Gmsh2DRVE methods.
Parameters
----------
a, b : floats
main lengths of the microstruture
w : float
width of the constitutive beams
junction_r : float, optional
Radius of the corners/fillets that are created between concurrent borders of beams.
The default is 0., which implies that the angles will not be rounded.
nb_cells : tuple or 1D array, optional
nb of cells in each direction of repetition (the default is (1, 1).)
offset : tuple, optional
If (0., 0.) or False : No shift of the microstructure.
Else : The microstructure is shift with respect to the macroscopic domain.
offset is the relative position inside a cell of the point that will coincide with the origin of the global domain.
soft_mat : bool, optional
If True : the remaining surface inside the RVE is associated with a second material domain and a mesh is genereted to represent it.
Else, this space remains empty.
name : str, optional
The name of the RVE. It is use for the gmsh model and the mesh files.
If name is '' (default) or False, the name of the RVE is 'beam_pantograph'.
Returns
-------
Instance of the Gmsh2DRVE class.
"""
name = name if name else "beam_pantograph"
offset = np.asarray(offset)
nb_cells = np.asarray(nb_cells)
logger.info("Start defining the beam pantograph geometry")
Lx = 4 * a
Ly = 6 * a + 2 * b
cell_vect = np.array(((Lx, 0.0), (0.0, Ly)))
e1 = np.array((a, 0.0, 0.0))
e2 = np.array((0.0, a, 0.0))
b_ = b / a * e2
E1 = geo.Point(e1)
E2 = geo.Point(e2)
E1m = geo.Point(-1 * e1)
E2m = geo.Point(-1 * e2)
L = geo.Point(2 * (e1 + e2))
Lm = geo.Point(2 * (e1 - e2))
M = geo.Point(e1 + 1.5 * e2 + b_ / 2)
I = geo.Point(2 * (e1 + 1.5 * e2 + b_ / 2))
contours = [
[E1, E2, E1m, E2m],
[E1, Lm, geo.Point(3 * e1), L],
[E1, L, E2],
[E2, L, geo.translation(L, b_), geo.translation(E2, b_)],
]
pattern_ll = [geo.LineLoop(pt_list, explicit=False) for pt_list in contours]
pattern_ll += [geo.point_reflection(ll, M) for ll in pattern_ll]
sym_ll = [geo.plane_reflection(ll, I, e1) for ll in pattern_ll]
for ll in sym_ll:
ll.reverse()
pattern_ll += sym_ll
sym_ll = [geo.plane_reflection(ll, I, e2) for ll in pattern_ll]
for ll in sym_ll:
ll.reverse()
pattern_ll += sym_ll
pattern_ll = geo.remove_duplicates(pattern_ll)
constr_pts = [copy.deepcopy(pt) for ll in pattern_ll for pt in iter((ll.vertices))]
for ll in pattern_ll:
ll.offset(w)
if junction_r:
for ll in pattern_ll:
ll.round_corner_incircle(junction_r)
fine_pts = geo.remove_duplicates(constr_pts)
return Gmsh2DRVE(pattern_ll, cell_vect, nb_cells, offset, fine_pts, soft_mat, name)
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