pantograph.py 12.4 KB
Newer Older
1
# coding: utf-8
2 3 4 5
"""
Created on 17/01/2019
@author: Baptiste Durand, baptiste.durand@enpc.fr
"""
6

7 8 9
import copy
import gmsh
import numpy as np
10

11 12
import ho_homog.geometry as geo

13
from . import Gmsh2DRVE, logger
14

15
# nice shortcuts
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
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")

95
    constr_pts = [pt for ll in pattern_ll for pt in ll.vertices]
96 97 98
    fine_pts = [
        pt
        for pt in constr_pts
99
        if (pt.coord[0] % 1 < p[0] / 2.0 or pt.coord[0] % 1 > 1.0 - p[0] / 2.0)
100 101 102 103 104 105
    ]
    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(
106 107 108 109 110 111 112 113 114
    a,
    b,
    k,
    thickness,
    fillet_r=0.0,
    nb_cells=(1, 1),
    offset=(0.0, 0.0),
    soft_mat=False,
    name="",
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
):
    """
    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.
    """
137

138
    name = name if name else "pantograph"
139

140 141
    offset = np.asarray(offset)
    nb_cells = np.asarray(nb_cells)
142

143
    logger.info("Start defining the pantograph geometry")
144

145 146 147
    Lx = 4 * a
    Ly = 6 * a + 2 * b
    cell_vect = np.array(((Lx, 0.0), (0.0, Ly)))
148

149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    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")
186 187 188

    constr_pts = [copy.deepcopy(pt) for ll in pattern_ll for pt in ll.vertices]

189 190 191 192 193 194 195
    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")
196

197 198 199
    fine_pts = [
        pt
        for pt in constr_pts
200
        if (pt.coord[0] % 1 < p[0] / 2.0 or pt.coord[0] % 1 > 1.0 - p[0] / 2.0)
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
    ]
    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.
        """
239

240 241 242
    name = name if name else "beam_pantograph"
    offset = np.asarray(offset)
    nb_cells = np.asarray(nb_cells)
243

244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    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)
276
    constr_pts = [copy.deepcopy(pt) for ll in pattern_ll for pt in ll.vertices]
277 278 279 280 281 282 283 284
    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)
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323


def pantograph_E11only_RVE(
    a,
    thickness,
    fillet_r=0.0,
    nb_cells=(1, 1),
    offset=(0.0, 0.0),
    soft_mat=False,
    name="",
):
    """
    Generate a RVE object for the simplified pantograph microstructure.
    Only one floppy mode : E11
    Junctions are obtained by creating offset curves from the microstructure contour.
    + fillets -> avoid stress concentration

    Parameters
    ----------
    a: floats
        main dimension 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
324
    Ly = 4 * a + 2 * thickness
325 326 327 328 329 330 331 332 333 334 335 336 337
    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))

    pt_O = geo.Point((0.0, 0.0, 0.0))
    L = geo.Point(2 * (e1 + e2))

    square = [
        geo.translation(L, e1),
        geo.translation(L, e2),
        geo.translation(L, -1 * e1),
        geo.translation(L, -1 * e2),
    ]
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
    rhombus_v = [
        pt_O,
        geo.Point(e1 + 2 * e2),
        geo.Point(4 * e2),
        geo.Point(-e1 + 2 * e2),
    ]
    cut_shape_h = [
        pt_O,
        geo.Point(0.25 * (-2 * e1 + e2)),
        geo.Point(0.25 * (-4 * e1 + e2)),
        geo.Point(0.25 * (-4 * e1 - e2)),
        # geo.Point(-2 * e1 - e2),
        # geo.Point(6 * e1 - e2),
        geo.Point(4 * e1 + 0.25 * (4 * e1 - e2)),
        geo.Point(4 * e1 + 0.25 * (4 * e1 + e2)),
        geo.Point(4 * e1 + 0.25 * (2 * e1 + e2)),
        # geo.Point(6 * e1 + e2),
        geo.Point(4 * e1),
        geo.Point(e2 + 2 * e1),
    ]
358 359
    square = geo.LineLoop(square, explicit=False)
    rhombus_v = geo.LineLoop(rhombus_v, explicit=False)
360 361 362 363 364 365
    cut_shape_h = geo.LineLoop(cut_shape_h, explicit=False)
    pattern = [square, rhombus_v, cut_shape_h]
    sym_rhombus = [
        geo.plane_reflection(rhombus_v, L, e1),
        geo.plane_reflection(cut_shape_h, L, e2),
    ]
366 367 368 369
    for ll in sym_rhombus:
        ll.reverse()
    pattern += sym_rhombus
    pattern = geo.remove_duplicates(pattern)
Baptiste Durand's avatar
Baptiste Durand committed
370
    translated_pattern = list()
371
    for ll in pattern:
Baptiste Durand's avatar
Baptiste Durand committed
372
        translated_pattern.append(geo.translation(ll, np.array((0.0, thickness, 0.0))))
373
    logger.info("Done removing of the line-loops duplicates")
Baptiste Durand's avatar
Baptiste Durand committed
374
    pattern = translated_pattern
375 376 377
    constr_pts = [copy.deepcopy(pt) for ll in pattern for pt in iter((ll.vertices))]
    for ll in pattern:
        ll.offset(thickness)
378

379 380 381 382 383 384
    if fillet_r:
        for ll in pattern:
            ll.round_corner_explicit(fillet_r)
    logger.info("Done rounding all corners of pattern line-loops")
    fine_pts = geo.remove_duplicates(constr_pts)
    return Gmsh2DRVE(pattern, cell_vect, nb_cells, offset, fine_pts, soft_mat, name)