Exemple #1
0
def test_rve_2_part():
    geo.set_gmsh_option("Mesh.MshFileVersion", 4.1)
    a = 1
    b, k = a, a / 3
    r = a / 1e2
    panto_rve = mg.pantograph.pantograph_RVE(a, b, k, r, name="couple_panto")
    lc_ratio = 1 / 2
    lc_min_max = (lc_ratio * r, lc_ratio * a)
    d_min_max = (5 * r, a)
    panto_rve.main_mesh_refinement(d_min_max, lc_min_max, False)
    panto_rve.mesh_generate()
    gmsh.model.mesh.renumberNodes()
    gmsh.model.mesh.renumberElements()
    gmsh.write(str(panto_rve.mesh_abs_path))
    panto_part = mg.Gmsh2DPartFromRVE(panto_rve, (2, 3))
    msh_conversion(panto_rve.mesh_abs_path, ".xdmf")
    msh_conversion(panto_part.mesh_abs_path, ".xdmf")
Exemple #2
0
def test_pantograph_offset():
    geo.set_gmsh_option("Mesh.MshFileVersion", 4.1)
    a = 1
    b, k = a, a / 3
    t = 0.02
    panto_test = mg.pantograph.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)
    panto_test.mesh_generate()
    gmsh.model.mesh.renumberNodes()
    gmsh.model.mesh.renumberElements()
    gmsh.write("panto_rve_offset.msh")
Exemple #3
0
def _mesh_homogeneous_cell(cell_vect, mesh_path):
    """Generate a  simple mesh for a homogeneous cell.
    cell_vect: np.array 2x2  colonnes = vecteurs periodicité
    """
    name = mesh_path.stem
    geometry.init_geo_tools()
    geometry.set_gmsh_option("Mesh.MshFileVersion", 4.1)
    # Mesh.Algorithm = 6; Frontal - Delaunay for 2D meshes
    geometry.set_gmsh_option("Mesh.Algorithm", 6)
    geometry.set_gmsh_option("Mesh.MeshSizeMin", 0.05)
    geometry.set_gmsh_option("Mesh.MeshSizeMax", 0.05)

    rve = Gmsh2DRVE([], cell_vect, (1, 1), np.zeros(2), [], False, name)
    rve.mesh_generate()
    gmsh.model.mesh.renumberNodes()
    gmsh.model.mesh.renumberElements()
    gmsh.write(str(mesh_path))
    mesh_path = msh_conversion(mesh_path, ".xdmf")
    geometry.reset()
    return mesh_path
Exemple #4
0
logger.info("Start defining a periodicity constraint for the mesh")
macro_bndry = macro_ll.sides
rve_s.get_boundary(recursive=True)
micro_bndry = [
    geo.macro_line_fragments(rve_s.boundary, M_ln) for M_ln in macro_bndry
]
dirct = [(M_ln.def_pts[-1].coord - M_ln.def_pts[0].coord)
         for M_ln in macro_bndry]
logger.debug("value and type of dirct items : " + repr([(i, type(i))
                                                        for i in dirct]))
for i, crvs in enumerate(micro_bndry):
    msh.order_curves(crvs, dirct[i % 2], orientation=True)
logger.debug("length of micro_bndry list : " + str(len(micro_bndry)))

msh.set_periodicity_pairs(micro_bndry[0], micro_bndry[2])
msh.set_periodicity_pairs(micro_bndry[1], micro_bndry[3])
logger.info("Periodicity constraint : Done")

logger.info("Cleaning model")
factory.remove([(1, s.tag) for s in macro_ll.sides])
factory.synchronize()
factory.removeAllDuplicates()
factory.synchronize()

geo.set_gmsh_option("Mesh.CharacteristicLengthExtendFromBoundary", 0)
geo.set_gmsh_option("Mesh.SaveAll", 0)
geo.PhysicalGroup.set_group_mesh(1)
gmsh.model.mesh.generate(2)
gmsh.write(str(mesh_file))
run(f"gmsh {str(mesh_file)} &", shell=True, check=True)
Exemple #5
0
def test_get_domains_gmsh(plots=False):
    """ Get subdomains and partition of the boundary from a .msh file. """
    name = "test_domains"
    local_dir = Path(__file__).parent
    mesh_file = local_dir.joinpath(name + ".msh")
    gmsh.model.add(name)
    L_x, L_y = 2.0, 2.0
    H = 1.0
    vertices = [(0.0, 0.0), (0.0, L_y), (L_x, L_y), (L_x, 0.0)]
    contour = geo.LineLoop([geo.Point(np.array(c)) for c in vertices], False)
    surface = geo.PlaneSurface(contour)
    inclusion_vertices = list()
    for coord in [
        (H / 2, -H / 2, 0.0),
        (H / 2, H / 2, 0.0),
        (-H / 2, H / 2, 0.0),
        (-H / 2, -H / 2, 0.0),
    ]:
        vertex = geo.translation(geo.Point((L_x / 2, L_y / 2)), coord)
        inclusion_vertices.append(vertex)
    inclusion = geo.PlaneSurface(geo.LineLoop(inclusion_vertices, False))
    for s in [surface, inclusion]:
        s.add_gmsh()
    factory.synchronize()
    (stiff_s, ) = geo.surface_bool_cut(surface, inclusion)
    factory.synchronize()
    (soft_s, ) = geo.surface_bool_cut(surface, stiff_s)
    factory.synchronize()
    domains = {
        "stiff": geo.PhysicalGroup(stiff_s, 2),
        "soft": geo.PhysicalGroup(soft_s, 2),
    }
    boundaries = {
        "S": geo.PhysicalGroup(surface.ext_contour.sides[0], 1),
        "W": geo.PhysicalGroup(surface.ext_contour.sides[1], 1),
        "N": geo.PhysicalGroup(surface.ext_contour.sides[2], 1),
        "E": geo.PhysicalGroup(surface.ext_contour.sides[3], 1),
    }
    for group in domains.values():
        group.add_gmsh()
    for group in boundaries.values():
        group.add_gmsh()
    charact_field = mesh_tools.MathEvalField("0.05")
    mesh_tools.set_background_mesh(charact_field)
    geo.set_gmsh_option("Mesh.SaveAll", 0)
    model.mesh.generate(1)
    model.mesh.generate(2)
    gmsh.model.mesh.removeDuplicateNodes()
    gmsh.write(str(mesh_file))
    E_1, E_2, nu = 1, 3, 0.3
    materials = {
        domains["soft"].tag: mat.Material(E_1, nu, "cp"),
        domains["stiff"].tag: mat.Material(E_1, nu, "cp"),
    }
    test_part = part.FenicsPart.part_from_file(mesh_file,
                                               materials,
                                               subdomains_import=True)
    assert test_part.mat_area == approx(L_x * L_y)
    elem_type = "CG"
    degree = 2
    V = fe.VectorFunctionSpace(test_part.mesh, elem_type, degree)
    W = fe.FunctionSpace(
        test_part.mesh,
        fe.VectorElement(elem_type, test_part.mesh.ufl_cell(), degree, dim=3),
    )
    boundary_conditions = {
        boundaries["N"].tag: fe.Expression(("x[0]-1", "1"), degree=1),
        boundaries["S"].tag: fe.Expression(("x[0]-1", "-1"), degree=1),
        boundaries["E"].tag: fe.Expression(("1", "x[1]-1"), degree=1),
        boundaries["W"].tag: fe.Expression(("-1", "x[1]-1"), degree=1),
    }
    bcs = list()
    for tag, val in boundary_conditions.items():
        bcs.append(fe.DirichletBC(V, val, test_part.facet_regions, tag))
    ds = fe.Measure("ds",
                    domain=test_part.mesh,
                    subdomain_data=test_part.facet_regions)
    v = fe.TestFunctions(V)
    u = fe.TrialFunctions(V)
    F = (fe.inner(mat.sigma(test_part.elasticity_tensor, mat.epsilon(u)),
                  mat.epsilon(v)) * fe.dx)
    a, L = fe.lhs(F), fe.rhs(F)
    u_sol = fe.Function(V)
    fe.solve(a == L, u_sol, bcs)
    strain = fe.project(mat.epsilon(u_sol), W)
    if plots:
        import matplotlib.pyplot as plt

        plt.figure()
        plot = fe.plot(u_sol)
        plt.colorbar(plot)
        plt.figure()
        plot = fe.plot(strain[0])
        plt.colorbar(plot)
        plt.figure()
        plot = fe.plot(strain[1])
        plt.colorbar(plot)
        plt.figure()
        plot = fe.plot(strain[2])
        plt.colorbar(plot)
        plt.show()
    error = fe.errornorm(
        strain,
        fe.Expression(("1", "1", "0"), degree=0),
        degree_rise=3,
        mesh=test_part.mesh,
    )
    assert error == approx(0, abs=1e-12)

    materials = {
        domains["soft"].tag: mat.Material(E_1, nu, "cp"),
        domains["stiff"].tag: mat.Material(E_2, nu, "cp"),
    }
    test_part = part.FenicsPart.part_from_file(mesh_file,
                                               materials,
                                               subdomains_import=True)
    V = fe.VectorFunctionSpace(test_part.mesh, elem_type, degree)
    W = fe.FunctionSpace(
        test_part.mesh,
        fe.VectorElement(elem_type, test_part.mesh.ufl_cell(), degree, dim=3),
    )
    bcs = list()
    for tag, val in boundary_conditions.items():
        bcs.append(fe.DirichletBC(V, val, test_part.facet_regions, tag))
    v = fe.TestFunctions(V)
    u = fe.TrialFunctions(V)
    F = (fe.inner(mat.sigma(test_part.elasticity_tensor, mat.epsilon(u)),
                  mat.epsilon(v)) * fe.dx)
    a, L = fe.lhs(F), fe.rhs(F)
    u_sol = fe.Function(V)
    fe.solve(a == L, u_sol, bcs)
    strain = mat.epsilon(u_sol)
    stress = mat.sigma(test_part.elasticity_tensor, strain)
    energy = 0.5 * fe.assemble(
        fe.inner(stress, strain) * fe.dx(test_part.mesh))
    energy_abaqus = 12.8788939
    assert energy == approx(energy_abaqus, rel=1e-3)
    geo.reset()
Exemple #6
0
def test_mat_area():
    """FenicsPart method global_aera, for 2D parts created from a gmsh mesh and from a FEniCS mesh"""
    L_x, L_y = 4.0, 5.0
    H = 1.0
    size = 0.5
    rectangle = mshr.Rectangle(fe.Point(0.0, 0), fe.Point(L_x, L_y))
    hole = mshr.Rectangle(
        fe.Point(L_x / 2 - H / 2, L_y / 2 - H / 2),
        fe.Point(L_x / 2 + H / 2, L_y / 2 + H / 2),
    )
    domain = rectangle - hole
    domain.set_subdomain(1, rectangle)
    mesh = mshr.generate_mesh(domain, size)
    dimensions = np.array(((L_x, 0.0), (0.0, L_y)))
    material = {"0": mat.Material(1.0, 0.3, "cp")}
    rect_part = part.FenicsPart(
        mesh,
        materials=material,
        subdomains=None,
        global_dimensions=dimensions,
        facet_regions=None,
    )
    assert rect_part.mat_area == (L_x * L_y - H**2)

    name = "test_mat_area"
    local_dir = Path(__file__).parent
    mesh_file = local_dir.joinpath(name + ".msh")
    gmsh.model.add(name)
    vertices = [(0.0, 0.0), (0.0, L_y), (L_x, L_y), (L_x, 0.0)]
    contour = geo.LineLoop([geo.Point(np.array(c)) for c in vertices], False)
    surface = geo.PlaneSurface(contour)
    cut_vertices = list()
    for local_coord in [(H, 0.0, 0.0), (0.0, H, 0.0), (-H, 0.0, 0.0),
                        (0.0, -H, 0.0)]:
        vertex = geo.translation(contour.vertices[2], np.array(local_coord))
        cut_vertices.append(vertex)
    cut_surface = geo.PlaneSurface(geo.LineLoop(cut_vertices, False))
    for s in [surface, cut_surface]:
        s.add_gmsh()
    factory.synchronize()
    (surface, ) = geo.surface_bool_cut(surface, cut_surface)
    factory.synchronize()
    for dim_tag in model.getEntities(2):
        if not dim_tag[1] == surface.tag:
            model.removeEntities([dim_tag], True)
    charact_field = mesh_tools.MathEvalField("0.1")
    mesh_tools.set_background_mesh(charact_field)
    geo.set_gmsh_option("Mesh.SaveAll", 1)
    model.mesh.generate(2)
    gmsh.write(str(mesh_file))
    cmd = f"dolfin-convert {mesh_file} {mesh_file.with_suffix('.xml')}"
    run(cmd, shell=True, check=True)
    mesh = fe.Mesh(str(mesh_file.with_suffix(".xml")))
    dimensions = np.array(((L_x, 0.0), (0.0, L_y)))
    material = {"0": mat.Material(1.0, 0.3, "cp")}
    rect_part = part.FenicsPart(
        mesh,
        materials=material,
        subdomains=None,
        global_dimensions=dimensions,
        facet_regions=None,
    )
    assert rect_part.mat_area == approx(L_x * L_y - H * H / 2)
    geo.reset()
Exemple #7
0
from ho_homog import part

model = gmsh.model
factory = model.occ
logger = logging.getLogger(
    __name__)  # http://sametmax.com/ecrire-des-logs-en-python/
logger.setLevel(logging.INFO)

if __name__ == "__main__":
    logger_root = logging.getLogger()
    logger_root.setLevel(logging.INFO)
    logging.basicConfig(format="%(asctime)s :: %(levelname)s :: %(message)s",
                        level=logging.INFO)

geo.init_geo_tools()
geo.set_gmsh_option("General.Verbosity", 3)


# ? Test du constructeur gmsh_2_Fenics_2DRVE
def test_rve_from_gmsh2drve():
    a = 1
    b, k = a, a / 3
    panto_test = mg.pantograph.pantograph_RVE(a,
                                              b,
                                              k,
                                              0.1,
                                              nb_cells=(2, 3),
                                              soft_mat=False,
                                              name="panto_test")
    panto_test.main_mesh_refinement((0.1, 0.5), (0.03, 0.3), False)
Exemple #8
0
    "%(asctime)s :: %(levelname)s :: %(name)s :: %(message)s", "%H:%M:%S")
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
stream_handler.setFormatter(formatter)
logger_root.addHandler(stream_handler)

gmsh_logger = logging.getLogger("gmsh")
gmsh_logger.setLevel(logging.INFO)

logging.getLogger("UFL").setLevel(logging.DEBUG)
logging.getLogger("FFC").setLevel(logging.DEBUG)
fe.set_log_level(20)

# * Step 1 : Modeling the geometry of the RVE
geometry.init_geo_tools()
geometry.set_gmsh_option("Mesh.Algorithm", 6)
geometry.set_gmsh_option("Mesh.MshFileVersion", 4.1)
gmsh.option.setNumber("Geometry.Tolerance", 1e-15)
gmsh.option.setNumber("Mesh.CharacteristicLengthExtendFromBoundary", 0)
gmsh.option.setNumber("Mesh.CharacteristicLengthMax", 0.1)
gmsh.option.setNumber("Mesh.LcIntegrationPrecision", 1e-9)
gmsh.option.setNumber("Geometry.MatchMeshTolerance", 1e-12)

a = 1
b, k = a, a / 3
r = a / 1e3
gmsh.logger.start()
rve_geo = mesh_generate_2D.Gmsh2DRVE.pantograph(a, b, k, r, name="panto_rve")
process_gmsh_log(gmsh.logger.get())
gmsh.logger.stop()
Exemple #9
0
def test_mesh_only_phy_groups():
    """
    Test of the set_group_mesh classmethod.
    A mesh must be generated only entities that belong to physical groups.
    """

    name = "test_mesh_only_phy_groups"
    gmsh.model.add(name)
    geo.set_gmsh_option("Mesh.SaveAll", 1)

    coords = [
        (0.0, 0.05),
        (0.05, 0.0),
        (1.8, 0.0),
        (2.0, 0.2),
        (2.0, 1.95),
        (1.95, 2.0),
        (0.2, 2.0),
        (0.0, 1.8),
    ]
    pts = [geo.Point(np.array(c), 0.03) for c in coords]
    lines = [
        geo.Line(pts[2 * i - 1], pts[2 * i]) for i in range(len(pts) // 2)
    ]
    centers = [
        geo.Point(np.array(c), 0.03)
        for c in [(0.05, 0.05), (1.8, 0.2), (1.95, 1.95), (0.2, 1.8)]
    ]
    arcs = [
        geo.Arc(pts[2 * i], centers[i], pts[2 * i + 1])
        for i in range(len(pts) // 2)
    ]
    elmts_1D = [item for pair in zip(lines, arcs) for item in pair]
    ll_1 = geo.LineLoop(elmts_1D, explicit=True)
    coords = [(1.0, 1.0), (3.0, 1.0), (3.0, 3.0), (1.0, 3.0)]
    vertc = [geo.Point(np.array(c), 0.01) for c in coords]
    ll_2 = geo.LineLoop(vertc, explicit=False)
    surf_1 = geo.PlaneSurface(ll_1)
    surf_2 = geo.PlaneSurface(ll_2)

    rect_vtcs = [
        geo.Point(np.array(c), 0.05) for c in [(4, 2), (4, 4), (6, 4), (6, 2)]
    ]
    hole_vtcs = [
        geo.Point(np.array(c), 0.02)
        for c in [(5 - 0.1, 3), (5, 3 - 0.5), (5 + 0.1, 3), (5, 3 + 0.5)]
    ]
    rect_ll = geo.LineLoop(rect_vtcs, explicit=False)
    hole_ll = geo.LineLoop(hole_vtcs, explicit=False)
    surf_with_hole = geo.PlaneSurface(rect_ll, [hole_ll])

    all_surf = [surf_1, surf_2, surf_with_hole]
    for s in all_surf:
        s.add_gmsh()
    factory.synchronize()
    surf_group = geo.PhysicalGroup([surf_1, surf_with_hole], 2, "surf_group")
    line_group = geo.PhysicalGroup(ll_2.sides + ll_1.sides, 1, "line_group")
    surf_group.add_gmsh()
    line_group.add_gmsh()
    surf_group.set_color([22, 160, 133, 255])
    line_group.set_color([234, 97, 83, 255])
    geo.PhysicalGroup.set_group_mesh(True)
    factory.synchronize()  # * Important before meshing
    data = model.getPhysicalGroups()
    logger.info(
        f"All physical groups in '{name}' model : \n"
        f"{data} \n"
        f"Names : {[model.getPhysicalName(*dimtag) for dimtag in data]}")
    gmsh.model.mesh.generate(2)
    gmsh.write("%s.brep" % name)
    gmsh.write("%s.msh" % name)
    os.system("gmsh %s.brep &" % name)
    os.system("gmsh %s.msh &" % name)
Exemple #10
0
def test_physical_group():
    """
    Test of the PhysicalGroup class.
    Group membership in the gmsh model : OK
    Colors in the gmsh GUI opened with gmsh.fltk.run() : OK
    Information about Physical group membership are exported in the msh file : OK

    """
    name = "test_PhysicalGroup"
    gmsh.model.add(name)
    geo.set_gmsh_option("Mesh.SaveAll", 0)
    # gmsh.option.setNumber('Mesh.MeshOnlyVisible',1)

    coords = [
        (0.0, 0.05),
        (0.05, 0.0),
        (1.8, 0.0),
        (2.0, 0.2),
        (2.0, 1.95),
        (1.95, 2.0),
        (0.2, 2.0),
        (0.0, 1.8),
    ]
    pts = [geo.Point(np.array(c), 0.03) for c in coords]
    lines = [
        geo.Line(pts[2 * i - 1], pts[2 * i]) for i in range(len(pts) // 2)
    ]
    centers = [
        geo.Point(np.array(c), 0.03)
        for c in [(0.05, 0.05), (1.8, 0.2), (1.95, 1.95), (0.2, 1.8)]
    ]
    arcs = [
        geo.Arc(pts[2 * i], centers[i], pts[2 * i + 1])
        for i in range(len(pts) // 2)
    ]
    elmts_1D = [item for pair in zip(lines, arcs) for item in pair]
    ll_1 = geo.LineLoop(elmts_1D, explicit=True)
    coords = [(1.0, 1.0), (3.0, 1.0), (3.0, 3.0), (1.0, 3.0)]
    vertc = [geo.Point(np.array(c), 0.01) for c in coords]
    ll_2 = geo.LineLoop(vertc, explicit=False)

    surf_1 = geo.PlaneSurface(ll_1)
    surf_2 = geo.PlaneSurface(ll_2)

    rect_vtcs = [
        geo.Point(np.array(c), 0.05) for c in [(4, 2), (4, 4), (6, 4), (6, 2)]
    ]
    hole_vtcs = [
        geo.Point(np.array(c), 0.02)
        for c in [(5 - 0.1, 3), (5, 3 - 0.5), (5 + 0.1, 3), (5, 3 + 0.5)]
    ]
    rect_ll = geo.LineLoop(rect_vtcs, explicit=False)
    hole_ll = geo.LineLoop(hole_vtcs, explicit=False)
    surf_with_hole = geo.PlaneSurface(rect_ll, [hole_ll])

    all_surf = [surf_1, surf_2, surf_with_hole]
    logger.info(
        f"In model {name}, PlaneSurface instances added to the gmsh model.")
    for s in all_surf:
        s.add_gmsh()
    logger.info(f"Python objects, surfaces tag : {[s.tag for s in all_surf]}")
    logger.info(
        f"Entities in model {name} before synchronize() call : {model.getEntities()}"
    )
    factory.synchronize()
    logger.info(
        f"After synchronize() call : \n Points : {model.getEntities(0)} \n Curves : {model.getEntities(1)} \n Surfaces : {model.getEntities(2)}"
    )
    surf_group = geo.PhysicalGroup([surf_1, surf_with_hole], 2, "surf_group")
    surf_group.add_gmsh()
    factory.synchronize()
    logger.info(
        "Operations : synchronize() -> def surf_group -> adding surf_group to the model -> synchronize()"
    )
    logger.info(
        f"Physical groups in model after : {model.getPhysicalGroups()}")

    # * OK, Here is no need of a second sync or a second physical group added in the model.

    factory.synchronize()
    logger.info(
        f"Physical groups in model after a second synchronize() : {model.getPhysicalGroups()}"
    )
    # surf_group.add_to_group(surf_2) #* Raise an AttributeError, OK
    line_group = geo.PhysicalGroup(ll_2.sides, 1, "line_group")
    line_group.add_to_group(ll_1.sides)
    line_group.add_gmsh()
    factory.synchronize()
    logger.info(
        "Ops : def line_group -> adding line_group to the model -> synchronize()"
    )
    logger.info(
        f"Physical groups in model after that : {model.getPhysicalGroups()}")
    pts_group = geo.PhysicalGroup(
        [pt for crv in ll_2.sides for pt in crv.def_pts], 0, "pts_group")
    pts_group.add_gmsh()
    factory.synchronize()
    logger.info(
        "Ops : def pts_group -> adding pts_group to the model -> synchronize()"
    )
    logger.info(
        f"Physical groups in model after that : {model.getPhysicalGroups()}")
    surf_group.set_color([22, 160, 133, 255])
    line_group.set_color([234, 97, 83, 255])
    factory.synchronize()  # * Important before meshing
    data = model.getPhysicalGroups()
    logger.info(
        f"All physical groups in '{name}' model : {data} Names : {[model.getPhysicalName(*dimtag) for dimtag in data]}"
    )
    prev_val = gmsh.option.getNumber("General.Verbosity")
    geo.set_gmsh_option("General.Verbosity", 3)
    gmsh.model.mesh.generate(2)
    geo.set_gmsh_option("General.Verbosity", prev_val)
    gmsh.write("%s.brep" % name)
    gmsh.write("%s.msh" % name)
    os.system("gmsh %s.brep &" % name)
    os.system("gmsh %s.msh &" % name)
pckg_logger.setLevel(logging.INFO)
geometry.bndry_logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    "%(asctime)s :: %(levelname)s :: %(name)s :: %(message)s", "%H:%M:%S")
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO)
stream_handler.setFormatter(formatter)
logger_root.addHandler(stream_handler)

logging.getLogger("UFL").setLevel(logging.DEBUG)
logging.getLogger("FFC").setLevel(logging.DEBUG)
fe.set_log_level(20)

# * Step 1 : Modeling the geometry of the part and the RVE
geometry.init_geo_tools()
geometry.set_gmsh_option("Mesh.MaxNumThreads2D", 4)
geometry.set_gmsh_option("Mesh.MaxNumThreads1D", 4)
geometry.set_gmsh_option("Mesh.Algorithm", 5)
a = 1
b, k = a, a / 3
r = 0.01
gmsh.logger.start()
part_geo = mesh_generate_2D.Gmsh2DRVE.pantograph(a,
                                                 b,
                                                 k,
                                                 r,
                                                 nb_cells=(20, 1),
                                                 soft_mat=False,
                                                 name="panto_part")
# ! Utiliser autre chose que Gmsh2DRVE
toolbox_gmsh.process_gmsh_log(gmsh.logger.get())
# coding: utf-8

import gmsh
import ho_homog.geometry as geo
import ho_homog.mesh_generate as mg

geo.init_geo_tools()
geo.set_gmsh_option("Mesh.MshFileVersion", 4.1)


def test_kagome():
    """ Generate a mesh that corresponds to one unit cell of 'kagome' microstructure.
    Two cases : alpha = 0.5, fully open, alpha = 0.1 triangles almost close"""
    a = 1
    junction_thinness = 1e-2
    for alpha in [0.1, 0.5]:
        rve = mg.kagome.kagome_RVE(0.5,
                                   junction_thinness,
                                   a=a,
                                   name=f"kagome_{alpha:.2f}")
        lc_ratio = 1 / 2
        lc_min_max = (lc_ratio * junction_thinness * a, lc_ratio * a)
        d_min_max = (2 * junction_thinness * a, a)
        rve.main_mesh_refinement(d_min_max, lc_min_max, False)
        rve.mesh_generate()
        gmsh.model.mesh.renumberNodes()
        gmsh.model.mesh.renumberElements()
        gmsh.write(str(rve.mesh_abs_path))
Exemple #13
0
def test_homog_EGG_pantograph_1x1(generate_mesh=False):
    logger.debug("Start test_homog_EGG_pantograph_1x1")
    start = time.time()
    if generate_mesh:
        geometry.init_geo_tools()
        geometry.set_gmsh_option("Mesh.MshFileVersion", 4.1)
        a = 1
        b, k = a, a / 3
        r = 0.02
        panto_test = mesh_generate.pantograph.pantograph_RVE(
            a, b, k, r, nb_cells=(1, 1), soft_mat=False, name="panto_rve_1x1")
        lc_ratio = 1 / 6
        lc_min_max = (lc_ratio * r * a, lc_ratio * a)
        panto_test.main_mesh_refinement((2 * r * a, a), lc_min_max, False)
        panto_test.mesh_generate()
        gmsh.model.mesh.renumberNodes()
        gmsh.model.mesh.renumberElements()
        gmsh.write("panto_rve_1x1.msh")
        mesh_path = msh_conversion("panto_rve_1x1.msh", ".xdmf")

    E, nu = 1.0, 0.3
    mesh_path = "panto_rve_1x1.xdmf"
    material = materials.Material(E, nu, "cp")
    gen_vect = np.array([[4.0, 0.0], [0.0, 8.0]])
    rve = part.Fenics2DRVE.rve_from_file(mesh_path, gen_vect, material)
    hom_model = homog2d.Fenics2DHomogenization(rve)
    *localzt_dicts, constit_tensors = hom_model.homogenizationScheme("EGG")

    Chom_ref = np.array([
        [2.58608139e-04, 3.45496903e-04, 5.16572422e-12],
        [3.45496903e-04, 3.81860676e-02, 6.48384646e-11],
        [5.16572422e-12, 6.48384646e-11, 3.27924466e-04],
    ])

    D_ref = np.array([
        [
            3.7266e-02, 2.2039e-02, 4.6218e-10, 1.5420e-10, 1.2646e-09,
            -1.3939e-03
        ],
        [
            2.2039e-02, -4.3185e-03, -3.4719e-11, 2.7544e-10, 7.0720e-10,
            1.2415e-02
        ],
        [
            4.6218e-10, -3.4719e-11, 1.3071e-01, 1.5918e-02, -9.9492e-03,
            -2.9101e-10
        ],
        [
            1.5420e-10, 2.7544e-10, 1.5918e-02, 1.5802e-01, 1.2891e-01,
            1.5962e-09
        ],
        [
            1.2646e-09, 7.0720e-10, -9.9492e-03, 1.2891e-01, 1.1628e-01,
            1.3358e-09
        ],
        [
            -1.3939e-03, 1.2415e-02, -2.9101e-10, 1.5962e-09, 1.3358e-09,
            6.3893e-05
        ],
    ])

    Chom = constit_tensors["E"]["E"]
    G = constit_tensors["E"]["EGGbis"]
    D = (constit_tensors["EG"]["EG"] - np.vstack(
        (G[:, :6], G[:, 6:])) - np.vstack((G[:, :6], G[:, 6:])).T)
    logger.debug(f"Chom : \n {Chom}")
    logger.debug(f"D : \n {D}")
    logger.debug(f"Duration : {time.time() - start}")
    assert Chom == approx(Chom_ref, rel=1e-3, abs=1e-10)
    assert D == approx(D_ref, rel=1e-3, abs=1e-8)
    logger.debug("End test_homog_EGG_pantograph_1x1")
    logger.debug(f"Duration : {time.time() - start}")