Commit 71ce46ee authored by Baptiste Durand's avatar Baptiste Durand

Reduce calls to gmsh.fltk in tests + black + minor fixes

parent 91066980
......@@ -153,7 +153,7 @@ msh.set_periodicity_pairs(micro_bndry[1], micro_bndry[3])
logger.info("Periodicity constraint : Done")
logger.info("Cleaning model")
factory.remove([(1, l.tag) for l in macro_ll.sides])
factory.remove([(1, s.tag) for s in macro_ll.sides])
factory.synchronize()
factory.removeAllDuplicates()
factory.synchronize()
......@@ -164,4 +164,3 @@ 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)
gmsh.fltk.run()
......@@ -451,7 +451,6 @@ def Gmsh2DPartFromRVE(cell: Gmsh2DRVE, nb_cells, part_name=None):
tag = cell.phy_surf[i].tag + 1000
name = cell.phy_surf[i].name
phy_surfaces.append(geo.PhysicalGroup(all_surfaces, 2, name, tag))
# gmsh.fltk.run()
for gp in cell.phy_surf:
gp.remove_gmsh()
factory.synchronize()
......
......@@ -88,7 +88,7 @@ def conversion_to_xdmf(i_path, o_path, cell_reg, facet_reg, dim, subdomains=Fals
raise NotImplementedError("3D meshes are not supported yet.")
# * INFO :
else:
ValueError
raise ValueError
meshio.write(o_path, geo_only)
......
......@@ -191,7 +191,7 @@ def test_reconstruction_with_constraint():
def test_select_solver():
"The solver Mumps is selected."
"""The solver Mumps is selected."""
logger = logging.getLogger("test_reconstruction")
nb_x = nb_y = 20
L_x = 2
......
......@@ -434,46 +434,21 @@ def test_ll_modif():
gmsh.model.add(name)
t = math.tan(math.pi / 6)
vertcs_lists = []
vertcs_lists.append(
[
geo.Point(np.array(c), 0.05)
for c in [
(0, 0),
(2, 0),
(2 - SR2, 0 + SR2),
(2, 2),
(2 - 1, 2 + t),
(0, 2),
]
]
) # angles : pi/4, pi/2 and 2*pi/3
vertcs_lists.append(
[
geo.Point(np.array(c), 0.05)
for c in [
(3, 0),
(5, 0),
(5 - SR2, 0 + SR2),
(5, 2),
(5 - 1, 2 + t),
(3, 2),
]
]
)
vertcs_lists.append(
[
geo.Point(np.array(c), 0.05)
for c in [
(6, 0),
(8, 0),
(8 - SR2, 0 + SR2),
(8, 2),
(8 - 1, 2 + t),
(6, 2),
]
]
)
vertcs_lists = [None, None, None]
vertcs_lists[0] = [
geo.Point(np.array(c), 0.05)
for c in [(0, 0), (2, 0), (2 - SR2, 0 + SR2), (2, 2), (2 - 1, 2 + t), (0, 2),]
] # angles : pi/4, pi/2 and 2*pi/3
vertcs_lists[1] = [
geo.Point(np.array(c), 0.05)
for c in [(3, 0), (5, 0), (5 - SR2, 0 + SR2), (5, 2), (5 - 1, 2 + t), (3, 2),]
]
vertcs_lists[2] = [
geo.Point(np.array(c), 0.05)
for c in [(6, 0), (8, 0), (8 - SR2, 0 + SR2), (8, 2), (8 - 1, 2 + t), (6, 2),]
]
vertcs_lists = [v_list_1, v_list_2, v_list_3]
lls = [geo.LineLoop(vl, explicit=False) for vl in vertcs_lists]
plt.figure()
......@@ -566,8 +541,8 @@ def test_gather_line():
gp_l = geo.PhysicalGroup(l_list, 1, n)
gp_l.add_gmsh()
gps.append(gp_l)
for l in l_list:
l.plot2D(col)
for ln in l_list:
ln.plot2D(col)
factory.synchronize()
gmsh.option.setNumber("Mesh.SaveAll", 1)
......@@ -862,11 +837,6 @@ if __name__ == "__main__":
# test_mesh_only_phy_groups()
# * Bloc de fin
gmsh.fltk.run()
# gmsh.fltk.run()
plt.show()
# * Il faut fermer toutes les fenêtres avant de passer à la GUI gmsh. (pertinent en mode non interactive) #noqa
# gmsh.fltk.run()
# ! A revoir, ça génère des "kernel died" dans Spyder, pas idéal
# # gmsh.fltk.initialize()
# gmsh.finalize()
# plt.show()
......@@ -19,15 +19,14 @@ from ho_homog import geometry, homog2d, materials, mesh_generate, part
logger = logging.getLogger("Test_homog2d")
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(
'%(asctime)s :: %(levelname)s :: %(name)s :: %(message)s',
"%H:%M:%S")
"%(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.addHandler(stream_handler)
np.set_printoptions(suppress=False, floatmode='fixed', precision=8,
linewidth=150)
np.set_printoptions(suppress=False, floatmode="fixed", precision=8, linewidth=150)
def test_homog_EGG_pantograph_1x1(generate_mesh=False):
......@@ -35,15 +34,16 @@ def test_homog_EGG_pantograph_1x1(generate_mesh=False):
start = time.time()
if generate_mesh:
geometry.init_geo_tools()
geometry.set_gmsh_option('Mesh.MshFileVersion', 4.1)
geometry.set_gmsh_option("Mesh.MshFileVersion", 4.1)
a = 1
b, k = a, a/3
r = 0.02
panto_test = mesh_generate_2D.Gmsh2DRVE.pantograph(
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.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()
......@@ -51,8 +51,8 @@ def test_homog_EGG_pantograph_1x1(generate_mesh=False):
mesh = meshio.read("panto_rve_1x1.msh")
mesh.points = mesh.points[:, :2]
geo_only = meshio.Mesh(
points=mesh.points,
cells={"triangle": mesh.cells["triangle"]})
points=mesh.points, cells={"triangle": mesh.cells["triangle"]}
)
meshio.write("panto_rve_1x1.xdmf", geo_only)
geometry.reset()
......@@ -63,12 +63,15 @@ def test_homog_EGG_pantograph_1x1(generate_mesh=False):
"panto_rve_1x1.xdmf", gen_vect, material)
hom_model = homog2d.Fenics2DHomogenization(rve)
*localzt_dicts, constit_tensors = hom_model.homogenizationScheme('EGG')
*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]])
[
[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(
[
......@@ -81,10 +84,13 @@ def test_homog_EGG_pantograph_1x1(generate_mesh=False):
]
)
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)
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}")
......@@ -109,14 +115,15 @@ def test_homogeneous_pantograph(generate_mesh=False, save_results=False):
start = time.time()
if generate_mesh:
geometry.init_geo_tools()
geometry.set_gmsh_option('Mesh.MshFileVersion', 4.1)
geometry.set_gmsh_option("Mesh.MshFileVersion", 4.1)
a = 1
b, k, r = a, a/3, 0.1*a
geo_model = mesh_generate_2D.Gmsh2DRVE.pantograph(
a, b, k, r, soft_mat=True, name='homogeneous_panto')
b, k, r = a, a / 3, 0.1 * a
geo_model = mesh_generate.pantograph.pantograph_RVE(
a, b, k, r, soft_mat=True, name="homogeneous_panto"
)
lc_ratio = 1
lc_min_max = (lc_ratio*r, lc_ratio)
d_min_max = (2*r, a)
lc_min_max = (lc_ratio * r, lc_ratio)
d_min_max = (2 * r, a)
geo_model.main_mesh_refinement(d_min_max, lc_min_max, False)
geo_model.soft_mesh_refinement(d_min_max, lc_min_max, False)
geo_model.mesh_generate()
......@@ -126,8 +133,8 @@ def test_homogeneous_pantograph(generate_mesh=False, save_results=False):
mesh = meshio.read("homogeneous_panto.msh")
mesh.points = mesh.points[:, :2]
geo_only = meshio.Mesh(
points=mesh.points,
cells={"triangle": mesh.cells["triangle"]})
points=mesh.points, cells={"triangle": mesh.cells["triangle"]}
)
meshio.write("homogeneous_panto.xdmf", geo_only)
geometry.reset()
......@@ -137,30 +144,36 @@ def test_homogeneous_pantograph(generate_mesh=False, save_results=False):
rve = part.Fenics2DRVE.file_2_Fenics_2DRVE(
"homogeneous_panto.xdmf", gen_vect, material)
hom_model = homog2d.Fenics2DHomogenization(rve)
*localzt_dicts, constit_tensors = hom_model.homogenizationScheme('EGG')
*localzt_dicts, constit_tensors = hom_model.homogenizationScheme("EGG")
Chom_ref = np.array(
[[1.09890110, 0.329670330, 0],
[0.329670330, 1.09890110, 0],
[0, 0, 0.769230769]])
[
[1.09890110, 0.329670330, 0],
[0.329670330, 1.09890110, 0],
[0, 0, 0.769230769],
]
)
D_ref = np.zeros((6, 6))
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)
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
)
print(Chom)
if save_results:
with fe.XDMFFile("homogeneous_panto_results.xdmf") as ofile:
ofile.parameters["flush_output"] = False
ofile.parameters["functions_share_mesh"] = True
for i, E_ in enumerate(('E11', 'E22', 'E12')):
loc_eps = fe.project(localzt_dicts[2]['E'][i], hom_model.W)
for i, E_ in enumerate(("E11", "E22", "E12")):
loc_eps = fe.project(localzt_dicts[2]["E"][i], hom_model.W)
loc_eps.rename(E_, E_)
ofile.write(loc_eps, 0.)
ofile.write(loc_eps, 0.0)
assert Chom == approx(Chom_ref)
assert D == approx(D_ref)
logger.debug("End test_homogeneous_pantograph")
logger.debug(f"Duration : {time.time() - start}")
test_homog_EGG_pantograph_1x1(False)
# test_homog_EGG_pantograph_1x1(False)
# test_homogeneous_pantograph(False, True)
This diff is collapsed.
......@@ -13,10 +13,7 @@ geo.init_geo_tools()
def test_rve_2_part():
fltk = gmsh.fltk
geo.set_gmsh_option("Mesh.MshFileVersion", 4.1)
fltk.initialize()
fltk.update()
a = 1
b, k = a, a / 3
r = a / 1e2
......
......@@ -15,13 +15,10 @@ mesh_gen = ho_homog.mesh_generate
geo.init_geo_tools()
geo.set_gmsh_option("Mesh.MshFileVersion", 4.1)
fltk = gmsh.fltk
def test_E11only_offset_RVE():
logger = logging.getLogger("test_E11only_offset_RVE")
fltk.initialize()
fltk.update()
a = 1
r = a / 2e2
thickness = a / 1e2
......@@ -34,7 +31,3 @@ def test_E11only_offset_RVE():
gmsh.model.mesh.renumberNodes()
gmsh.model.mesh.renumberElements()
gmsh.write(str(panto_rve.mesh_abs_path))
test_E11only_offset_RVE()
fltk.run()
\ No newline at end of file
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