def rve_from_gmsh2drve(gmsh_2d_rve, materials, plots=True): """ Generate an instance of Fenics2DRVE from a instance of the Gmsh2DRVE class. """ msh_conversion(gmsh_2d_rve.mesh_abs_path, format_=".xml") mesh_path = gmsh_2d_rve.mesh_abs_path.with_suffix(".xml") gen_vect = gmsh_2d_rve.gen_vect kwargs = dict() try: kwargs["bottom_left_corner"] = gmsh_2d_rve.bottom_left_corner except AttributeError: pass fenics_rve = Fenics2DRVE.rve_from_file(mesh_path, gen_vect, materials, plots, **kwargs) return fenics_rve
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")
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
process_gmsh_log(gmsh.logger.get()) gmsh.logger.stop() # * Step 2 : Generating the RVE mesh lc_ratio = 1 / 5.0 d_min_max = (2 * r, a) lc_min_max = (lc_ratio * r, lc_ratio * a) rve_geo.main_mesh_refinement(d_min_max, lc_min_max, False) gmsh.logger.start() rve_geo.mesh_generate() process_gmsh_log(gmsh.logger.get()) gmsh.logger.stop() gmsh.model.mesh.renumberNodes() gmsh.model.mesh.renumberElements() gmsh.write(str(rve_geo.mesh_abs_path)) rve_path = msh_conversion(rve_geo.mesh_abs_path, ".xdmf") # * Step 3 : Build the mesh of the part from the mesh of the RVE gmsh.logger.start() part_geo = mesh_generate_2D.Gmsh2DPartFromRVE(rve_geo, (10, 1)) process_gmsh_log(gmsh.logger.get()) gmsh.logger.stop() part_path = msh_conversion(part_geo.mesh_abs_path, ".xdmf") # * Step 4 : Defining the material properties E, nu = 1.0, 0.3 E_nu_tuples = [(E, nu)] material = materials.Material(E, nu, "cp") # * Step 5 : Calculation of the full-scale solution # * Step 5.1 : Create a part object
def rve_from_file(mesh_path, generating_vectors, materials, plots=True, **kwargs): """Generate an instance of Fenics2DRVE from a .xml, .msh or .xdmf file that contains the mesh. Parameters ---------- mesh_path : string or Path Relative or absolute path to the mesh file (format Dolfin XML, XDMF or MSH version 2) generating_vectors : 2D-array dimensions of the RVE materials : dictionnary [description] #TODO : à compléter plots : bool, optional If True (default) the physical regions and the facet regions are plotted at the end of the import. Returns ------- Fenics2DRVE instance """ if not isinstance(mesh_path, Path): mesh_path = Path(mesh_path) name = mesh_path.stem if mesh_path.suffix == ".xml": mesh = fe.Mesh(str(mesh_path)) elif mesh_path.suffix == ".xdmf": mesh = fe.Mesh() with fe.XDMFFile(str(mesh_path)) as file_in: file_in.read(mesh) else: msh_conversion(mesh_path, format_=".xml") mesh_path = mesh_path.with_suffix(".xml") mesh = fe.Mesh(str(mesh_path)) logger.info("Import of the mesh : DONE") # TODO : import des subdomains subdomains, facets = fetools.import_subdomain_data_xml(mesh, mesh_path) logger.info("Import of the subdomain data and facet-region data: DONE") if "name" not in kwargs: kwargs["name"] = name fenics_rve = Fenics2DRVE(mesh, generating_vectors, materials, subdomains, facets, **kwargs) if plots: fenics_rve.plot_mesh() if subdomains is not None: fenics_rve.plot_subdomains() if facets is not None: fenics_rve.plot_facet_regions() plt.show() return fenics_rve
def part_from_file( mesh_path, materials, global_dimensions=None, subdomains_import=False, plots=False, **kwargs, ): """Generate an instance of FenicsPart from a .xml or .msh file that contains the mesh. Parameters ---------- mesh_path : string or Path Relative or absolute path to the mesh file (format Dolfin XML, XDMF or MSH version 2) global_dimensions : 2D-array shape : 2×2 if 2D problem dimensions of the RVE materials : dict or Material [description] #TODO : à compléter subdomains_import : bool Import subdomains data ? plots : bool, optional If True (default) the physical regions and the facet regions are plotted at the end of the import. Returns ------- FenicsPart instance """ mesh_path = Path(mesh_path) name = mesh_path.stem suffix = mesh_path.suffix if suffix not in fetools.SUPPORTED_MESH_SUFFIX: mesh_file_paths = msh_conversion(mesh_path, format_=".xml", subdomains=subdomains_import) try: mesh_path = mesh_file_paths[0] except (IndexError, TypeError) as error: mesh_path = mesh_file_paths logger.warning(error) suffix = mesh_path.suffix # Each supported mesh format -> one if structure subdomains, facets = None, None if suffix == ".xml": mesh = fe.Mesh(str(mesh_path)) if subdomains_import: subdomains, facets = fetools.import_subdomain_data_xml( mesh, mesh_path) elif suffix == ".xdmf": mesh = fetools.xdmf_mesh(mesh_path) if subdomains_import: subdomains, facets = fetools.import_subdomain_data_xdmf( mesh, mesh_path) msg = f"Import of a mesh from {mesh_path} file, with subdomains data" else: msg = f"Import of a mesh from {mesh_path} file, without subdomains data" logger.info(msg) else: raise ValueError( f"expected a mesh path with a suffix `.xml` or `.xdmf`.") logger.info(f"Import of the mesh : DONE") if "name" not in kwargs: kwargs["name"] = name part = FenicsPart(mesh, materials, subdomains, global_dimensions, facets, **kwargs) if plots: part.plot_mesh() if subdomains is not None: part.plot_subdomains() if facets is not None: part.plot_facet_regions() plt.show() return part
logger.info("Generating the mesh") lc_ratio = 1 / 3.0 d_min_max = (2 * r, a) lc_min_max = (lc_ratio * r, lc_ratio * a) rve_geo.main_mesh_refinement(d_min_max, lc_min_max, False) rve_geo.soft_mesh_refinement(d_min_max, lc_min_max, False) rve_geo.mesh_generate() logger.info("Saving mesh with MSH 4 format") gmsh.model.mesh.renumberNodes() gmsh.model.mesh.renumberElements() gmsh.write(str(rve_geo.mesh_abs_path)) logger.info("Mesh conversion MSH -> XDMF") mesh_path, *_ = toolbox_gmsh.msh_conversion(rve_geo.mesh_abs_path, ".xdmf", subdomains=True) logger.info("Import of mesh and partitions as MeshFunction instances") mesh, subdomains, facet_regions = toolbox_FEniCS.xdmf_mesh(mesh_path, True) plt.figure() fe.plot(mesh, title="Mesh only") plt.figure() subdo_plt = fe.plot(subdomains, title="Subdomains") plt.colorbar(subdo_plt) nb_val, facets_val = toolbox_FEniCS.get_MeshFunction_val(facet_regions) facets_val = facets_val[facets_val != 18446744073709551615] facets_val = facets_val[facets_val != 0] print(facets_val)
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}")