Commit 5228edb8 authored by Baptiste Durand's avatar Baptiste Durand

Pass unit tests for geometry (except unexpected behavior for round_corner)

Change name of boolean operations;
Correction name of plot functions;
parent b506dedd
...@@ -96,7 +96,7 @@ macro_s = geo.PlaneSurface(macro_ll) ...@@ -96,7 +96,7 @@ macro_s = geo.PlaneSurface(macro_ll)
logger.info('Start boolean operations on surfaces') logger.info('Start boolean operations on surfaces')
pattern_s = [geo.PlaneSurface(ll) for ll in pattern_ll] pattern_s = [geo.PlaneSurface(ll) for ll in pattern_ll]
rve_s = geo.AbstractSurface.bool_cut(macro_s, pattern_s) rve_s = geo.surface_bool_cut(macro_s, pattern_s)
rve_s = rve_s[0] rve_s = rve_s[0]
logger.info('Done boolean operations on surfaces') logger.info('Done boolean operations on surfaces')
rve_s_phy = geo.PhysicalGroup([rve_s], 2, "partition_plein") rve_s_phy = geo.PhysicalGroup([rve_s], 2, "partition_plein")
...@@ -153,4 +153,4 @@ geo.PhysicalGroup.set_group_mesh(1) ...@@ -153,4 +153,4 @@ geo.PhysicalGroup.set_group_mesh(1)
gmsh.model.mesh.generate(2) gmsh.model.mesh.generate(2)
gmsh.write("%s.msh"%name) gmsh.write("%s.msh"%name)
os.system("gmsh %s.msh &" %name) os.system("gmsh %s.msh &" %name)
gmsh.fltk.run() gmsh.fltk.run()
\ No newline at end of file
...@@ -19,35 +19,13 @@ import gmsh ...@@ -19,35 +19,13 @@ import gmsh
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from .curves import AbstractCurve, Arc, Line, bndry_logger
from .physical import PhysicalGroup
from .point import Point
from .surfaces import (
AbstractSurface,
LineLoop,
PlaneSurface,
surface_bool_cut,
surface_bool_intersect,
)
from .tools import (
angle_between,
bisector,
dual_base,
macro_line_fragments,
offset,
remove_duplicates,
round_corner,
unit_vect,
)
from .transformations import plane_reflection, point_reflection, rotation, translation
logger = logging.getLogger(__name__)
# nice shortcuts # nice shortcuts
model = gmsh.model model = gmsh.model
factory = model.occ factory = model.occ
logger = logging.getLogger(__name__)
warnings.simplefilter("always") warnings.simplefilter("always")
# ? Doc: https://docs.python.org/3.6/library/warnings.html # ? Doc: https://docs.python.org/3.6/library/warnings.html
...@@ -77,6 +55,29 @@ def set_gmsh_option(option, val): ...@@ -77,6 +55,29 @@ def set_gmsh_option(option, val):
logger.info(f"Gmsh option {option} set to {val} (previously : {preval}).") logger.info(f"Gmsh option {option} set to {val} (previously : {preval}).")
from .curves import AbstractCurve, Arc, Line, bndry_logger
from .physical import PhysicalGroup
from .point import Point
from .surfaces import (
AbstractSurface,
LineLoop,
PlaneSurface,
surface_bool_cut,
surface_bool_intersect,
)
from .tools import (
angle_between,
bisector,
dual_base,
macro_line_fragments,
offset,
remove_duplicates,
round_corner,
unit_vect,
)
from .transformations import plane_reflection, point_reflection, rotation, translation
def init_geo_tools(): def init_geo_tools():
""" """
The Gmsh Python API must be initialized before using any functions. The Gmsh Python API must be initialized before using any functions.
...@@ -112,7 +113,7 @@ __all__ = [ ...@@ -112,7 +113,7 @@ __all__ = [
"logger", "logger",
"set_gmsh_option", "set_gmsh_option",
"init_geo_tools", "init_geo_tools",
"reset" "reset",
# * points # * points
"Point", "Point",
# * curves # * curves
......
...@@ -49,7 +49,6 @@ class Curve(object): ...@@ -49,7 +49,6 @@ class Curve(object):
self.def_pts = def_pts_list self.def_pts = def_pts_list
self.tag = None self.tag = None
self.gmsh_constructor = gmsh_api_add_function self.gmsh_constructor = gmsh_api_add_function
Curve.all_instances.append(self)
def __eq__(self, other): def __eq__(self, other):
""" """
...@@ -160,9 +159,9 @@ class Arc(Curve): ...@@ -160,9 +159,9 @@ class Arc(Curve):
"""Représenter l'arc de cercle dans un plot matplotlib. """Représenter l'arc de cercle dans un plot matplotlib.
Disponible seulement en 2D pour l'instant.""" Disponible seulement en 2D pour l'instant."""
self.def_pts[0].plot(end_pts_color, pt_size) self.def_pts[0].plot2D(end_pts_color, pt_size)
self.def_pts[2].plot(end_pts_color, pt_size) self.def_pts[2].plot2D(end_pts_color, pt_size)
self.def_pts[1].plot(center_color, pt_size) self.def_pts[1].plot2D(center_color, pt_size)
circle = plt.Circle( circle = plt.Circle(
(self.def_pts[1].coord[0], self.def_pts[1].coord[1]), (self.def_pts[1].coord[0], self.def_pts[1].coord[1]),
self.radius, self.radius,
......
...@@ -101,7 +101,7 @@ class LineLoop(object): ...@@ -101,7 +101,7 @@ class LineLoop(object):
if not self.sides: if not self.sides:
self.vertices_2_sides() self.vertices_2_sides()
for elmt in self.sides: for elmt in self.sides:
elmt.plot(color) elmt.plot2D(color)
def add_gmsh(self): def add_gmsh(self):
if self.tag: if self.tag:
......
...@@ -11,7 +11,7 @@ Perform diverse operations on numpy arrays, points or curves. ...@@ -11,7 +11,7 @@ Perform diverse operations on numpy arrays, points or curves.
from . import np, plt, logger, math from . import np, plt, logger, math
from .point import Point from .point import Point
from .curves import Line, Arc from .curves import Line, Arc
from .transformations import translation
import copy import copy
...@@ -108,6 +108,7 @@ def round_corner(inp_pt, pt_amt, pt_avl, r, junction_raduis=False, plot=False): ...@@ -108,6 +108,7 @@ def round_corner(inp_pt, pt_amt, pt_avl, r, junction_raduis=False, plot=False):
Ces segments orientés relient les deux points en amont et aval de l'angle à l'arc. Ces segments orientés relient les deux points en amont et aval de l'angle à l'arc.
""" """
from .transformations import translation
# Direction en amont et en aval # Direction en amont et en aval
v_amt = unit_vect(pt_amt.coord - inp_pt.coord) v_amt = unit_vect(pt_amt.coord - inp_pt.coord)
v_avl = unit_vect(pt_avl.coord - inp_pt.coord) v_avl = unit_vect(pt_avl.coord - inp_pt.coord)
...@@ -149,15 +150,15 @@ def round_corner(inp_pt, pt_amt, pt_avl, r, junction_raduis=False, plot=False): ...@@ -149,15 +150,15 @@ def round_corner(inp_pt, pt_amt, pt_avl, r, junction_raduis=False, plot=False):
colors = ["black", "red", "blue"] colors = ["black", "red", "blue"]
x, y = list(), list() x, y = list(), list()
for pt, color in zip(pts, colors): for pt, color in zip(pts, colors):
pt.plot(color) pt.plot2D(color)
x.append(pt.coord[0]) x.append(pt.coord[0])
y.append(pt.coord[1]) y.append(pt.coord[1])
pt_racc_amt.plot("black") pt_racc_amt.plot2D("black")
pt_racc_avl.plot("black") pt_racc_avl.plot2D("black")
pt_ctr.plot("purple") pt_ctr.plot2D("purple")
racc_amt.plot("red") racc_amt.plot2D("red")
racc_avl.plot("blue") racc_avl.plot2D("blue")
ax.add_patch(round_arc.plot("purple")) ax.add_patch(round_arc.plot2D("purple"))
plt.axis("equal") plt.axis("equal")
plt.xlim(min(x), max(x)) plt.xlim(min(x), max(x))
plt.ylim(min(y), max(y)) plt.ylim(min(y), max(y))
......
...@@ -162,7 +162,7 @@ class Gmsh2DRVE(object): ...@@ -162,7 +162,7 @@ class Gmsh2DRVE(object):
logger.info("Start boolean operations on surfaces") logger.info("Start boolean operations on surfaces")
phy_surf = list() phy_surf = list()
pattern_s = [geo.PlaneSurface(ll) for ll in pattern_ll] pattern_s = [geo.PlaneSurface(ll) for ll in pattern_ll]
rve_s = geo.AbstractSurface.bool_cut(macro_s, pattern_s) rve_s = geo.surface_bool_cut(macro_s, pattern_s)
if len(rve_s) == 1: if len(rve_s) == 1:
logger.info( logger.info(
"The main material domain of the RVE is connected (topological property)." "The main material domain of the RVE is connected (topological property)."
...@@ -178,7 +178,7 @@ class Gmsh2DRVE(object): ...@@ -178,7 +178,7 @@ class Gmsh2DRVE(object):
rve_s_phy = geo.PhysicalGroup(rve_s, 2, "microstruct_domain") rve_s_phy = geo.PhysicalGroup(rve_s, 2, "microstruct_domain")
phy_surf.append(rve_s_phy) phy_surf.append(rve_s_phy)
if soft_mat: if soft_mat:
soft_s = geo.AbstractSurface.bool_cut(macro_s, rve_s) soft_s = geo.surface_bool_cut(macro_s, rve_s)
soft_s_phy = geo.PhysicalGroup(soft_s, 2, "soft_domain") soft_s_phy = geo.PhysicalGroup(soft_s, 2, "soft_domain")
phy_surf.append(soft_s_phy) phy_surf.append(soft_s_phy)
logger.info("Done boolean operations on surfaces") logger.info("Done boolean operations on surfaces")
......
This diff is collapsed.
...@@ -157,14 +157,14 @@ def test_mat_area(): ...@@ -157,14 +157,14 @@ def test_mat_area():
surface = geo.PlaneSurface(contour) surface = geo.PlaneSurface(contour)
cut_vertices = list() cut_vertices = list()
for local_coord in [(H, 0., 0.), (0., H, 0.), (-H, 0., 0.), (0., -H, 0.)]: for local_coord in [(H, 0., 0.), (0., H, 0.), (-H, 0., 0.), (0., -H, 0.)]:
vertex = geo.translation(contour.vertices[2], vertex = geo.translation(contour.vertices[2],
np.array(local_coord)) np.array(local_coord))
cut_vertices.append(vertex) cut_vertices.append(vertex)
cut_surface = geo.PlaneSurface(geo.LineLoop(cut_vertices,False)) cut_surface = geo.PlaneSurface(geo.LineLoop(cut_vertices,False))
for s in [surface, cut_surface]: for s in [surface, cut_surface]:
s.add_gmsh() s.add_gmsh()
factory.synchronize() factory.synchronize()
surface, = geo.AbstractSurface.bool_cut(surface, cut_surface) surface, = geo.surface_bool_cut(surface, cut_surface)
factory.synchronize() factory.synchronize()
for dim_tag in model.getEntities(2): for dim_tag in model.getEntities(2):
if not dim_tag[1] == surface.tag: if not dim_tag[1] == surface.tag:
...@@ -254,13 +254,13 @@ def test_get_domains_gmsh(plots=False): ...@@ -254,13 +254,13 @@ def test_get_domains_gmsh(plots=False):
for coord in [(H/2, -H/2, 0.), (H/2, H/2, 0.), (-H/2, H/2, 0.), (-H/2, -H/2, 0.)]: for coord in [(H/2, -H/2, 0.), (H/2, H/2, 0.), (-H/2, H/2, 0.), (-H/2, -H/2, 0.)]:
vertex = geo.translation(geo.Point((L_x/2, L_y/2)), coord) vertex = geo.translation(geo.Point((L_x/2, L_y/2)), coord)
inclusion_vertices.append(vertex) inclusion_vertices.append(vertex)
inclusion = geo.PlaneSurface(geo.LineLoop(inclusion_vertices,False)) inclusion = geo.PlaneSurface(geo.LineLoop(inclusion_vertices, False))
for s in [surface, inclusion]: for s in [surface, inclusion]:
s.add_gmsh() s.add_gmsh()
factory.synchronize() factory.synchronize()
stiff_s, = geo.AbstractSurface.bool_cut(surface, inclusion) stiff_s, = geo.surface_bool_cut(surface, inclusion)
factory.synchronize() factory.synchronize()
soft_s, = geo.AbstractSurface.bool_cut(surface, stiff_s) soft_s, = geo.surface_bool_cut(surface, stiff_s)
factory.synchronize() factory.synchronize()
domains = { domains = {
'stiff': geo.PhysicalGroup(stiff_s, 2), 'stiff': geo.PhysicalGroup(stiff_s, 2),
...@@ -297,7 +297,7 @@ def test_get_domains_gmsh(plots=False): ...@@ -297,7 +297,7 @@ def test_get_domains_gmsh(plots=False):
W = fe.FunctionSpace( W = fe.FunctionSpace(
test_part.mesh, test_part.mesh,
fe.VectorElement(elem_type, test_part.mesh.ufl_cell(), degree, dim=3), fe.VectorElement(elem_type, test_part.mesh.ufl_cell(), degree, dim=3),
) )
boundary_conditions = { boundary_conditions = {
boundaries['N'].tag: fe.Expression(("x[0]-1", "1"), degree=1), boundaries['N'].tag: fe.Expression(("x[0]-1", "1"), degree=1),
boundaries['S'].tag: fe.Expression(("x[0]-1", "-1"), degree=1), boundaries['S'].tag: fe.Expression(("x[0]-1", "-1"), degree=1),
...@@ -338,7 +338,7 @@ def test_get_domains_gmsh(plots=False): ...@@ -338,7 +338,7 @@ def test_get_domains_gmsh(plots=False):
plt.show() plt.show()
error = fe.errornorm(strain, fe.Expression(("1","1","0"),degree=0),degree_rise=3, mesh=test_part.mesh) 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) assert error == approx(0,abs=1e-12)
materials = { materials = {
domains['soft'].tag: mat.Material(E_1, nu, 'cp'), domains['soft'].tag: mat.Material(E_1, nu, 'cp'),
domains['stiff'].tag: mat.Material(E_2, nu, 'cp') domains['stiff'].tag: mat.Material(E_2, nu, 'cp')
...@@ -367,4 +367,4 @@ def test_get_domains_gmsh(plots=False): ...@@ -367,4 +367,4 @@ def test_get_domains_gmsh(plots=False):
energy = 0.5 * fe.assemble(fe.inner(stress, strain) * fe.dx(test_part.mesh)) energy = 0.5 * fe.assemble(fe.inner(stress, strain) * fe.dx(test_part.mesh))
energy_abaqus = 12.8788939 energy_abaqus = 12.8788939
assert energy == approx(energy_abaqus, rel=1e-3) assert energy == approx(energy_abaqus, rel=1e-3)
geo.reset() geo.reset()
\ 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