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)
logger.info('Start boolean operations on surfaces')
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]
logger.info('Done boolean operations on surfaces')
rve_s_phy = geo.PhysicalGroup([rve_s], 2, "partition_plein")
......@@ -153,4 +153,4 @@ geo.PhysicalGroup.set_group_mesh(1)
gmsh.model.mesh.generate(2)
gmsh.write("%s.msh"%name)
os.system("gmsh %s.msh &" %name)
gmsh.fltk.run()
\ No newline at end of file
gmsh.fltk.run()
......@@ -19,35 +19,13 @@ import gmsh
import matplotlib.pyplot as plt
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
model = gmsh.model
factory = model.occ
logger = logging.getLogger(__name__)
warnings.simplefilter("always")
# ? Doc: https://docs.python.org/3.6/library/warnings.html
......@@ -77,6 +55,29 @@ def set_gmsh_option(option, val):
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():
"""
The Gmsh Python API must be initialized before using any functions.
......@@ -112,7 +113,7 @@ __all__ = [
"logger",
"set_gmsh_option",
"init_geo_tools",
"reset"
"reset",
# * points
"Point",
# * curves
......
......@@ -49,7 +49,6 @@ class Curve(object):
self.def_pts = def_pts_list
self.tag = None
self.gmsh_constructor = gmsh_api_add_function
Curve.all_instances.append(self)
def __eq__(self, other):
"""
......@@ -160,9 +159,9 @@ class Arc(Curve):
"""Représenter l'arc de cercle dans un plot matplotlib.
Disponible seulement en 2D pour l'instant."""
self.def_pts[0].plot(end_pts_color, pt_size)
self.def_pts[2].plot(end_pts_color, pt_size)
self.def_pts[1].plot(center_color, pt_size)
self.def_pts[0].plot2D(end_pts_color, pt_size)
self.def_pts[2].plot2D(end_pts_color, pt_size)
self.def_pts[1].plot2D(center_color, pt_size)
circle = plt.Circle(
(self.def_pts[1].coord[0], self.def_pts[1].coord[1]),
self.radius,
......
......@@ -101,7 +101,7 @@ class LineLoop(object):
if not self.sides:
self.vertices_2_sides()
for elmt in self.sides:
elmt.plot(color)
elmt.plot2D(color)
def add_gmsh(self):
if self.tag:
......
......@@ -11,7 +11,7 @@ Perform diverse operations on numpy arrays, points or curves.
from . import np, plt, logger, math
from .point import Point
from .curves import Line, Arc
from .transformations import translation
import copy
......@@ -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.
"""
from .transformations import translation
# Direction en amont et en aval
v_amt = unit_vect(pt_amt.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):
colors = ["black", "red", "blue"]
x, y = list(), list()
for pt, color in zip(pts, colors):
pt.plot(color)
pt.plot2D(color)
x.append(pt.coord[0])
y.append(pt.coord[1])
pt_racc_amt.plot("black")
pt_racc_avl.plot("black")
pt_ctr.plot("purple")
racc_amt.plot("red")
racc_avl.plot("blue")
ax.add_patch(round_arc.plot("purple"))
pt_racc_amt.plot2D("black")
pt_racc_avl.plot2D("black")
pt_ctr.plot2D("purple")
racc_amt.plot2D("red")
racc_avl.plot2D("blue")
ax.add_patch(round_arc.plot2D("purple"))
plt.axis("equal")
plt.xlim(min(x), max(x))
plt.ylim(min(y), max(y))
......
......@@ -162,7 +162,7 @@ class Gmsh2DRVE(object):
logger.info("Start boolean operations on surfaces")
phy_surf = list()
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:
logger.info(
"The main material domain of the RVE is connected (topological property)."
......@@ -178,7 +178,7 @@ class Gmsh2DRVE(object):
rve_s_phy = geo.PhysicalGroup(rve_s, 2, "microstruct_domain")
phy_surf.append(rve_s_phy)
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")
phy_surf.append(soft_s_phy)
logger.info("Done boolean operations on surfaces")
......
This diff is collapsed.
......@@ -157,14 +157,14 @@ def test_mat_area():
surface = geo.PlaneSurface(contour)
cut_vertices = list()
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))
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.AbstractSurface.bool_cut(surface, cut_surface)
surface, = geo.surface_bool_cut(surface, cut_surface)
factory.synchronize()
for dim_tag in model.getEntities(2):
if not dim_tag[1] == surface.tag:
......@@ -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.)]:
vertex = geo.translation(geo.Point((L_x/2, L_y/2)), coord)
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]:
s.add_gmsh()
factory.synchronize()
stiff_s, = geo.AbstractSurface.bool_cut(surface, inclusion)
stiff_s, = geo.surface_bool_cut(surface, inclusion)
factory.synchronize()
soft_s, = geo.AbstractSurface.bool_cut(surface, stiff_s)
soft_s, = geo.surface_bool_cut(surface, stiff_s)
factory.synchronize()
domains = {
'stiff': geo.PhysicalGroup(stiff_s, 2),
......@@ -297,7 +297,7 @@ def test_get_domains_gmsh(plots=False):
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),
......@@ -338,7 +338,7 @@ def test_get_domains_gmsh(plots=False):
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')
......@@ -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_abaqus = 12.8788939
assert energy == approx(energy_abaqus, rel=1e-3)
geo.reset()
\ No newline at end of file
geo.reset()
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