Get IDs of objects created with Extrude and BooleanDifference + set mesh res at such points
Hi,
I mean to get information on objects that are generated automatically by Gmsh as a result of several operations. I also want to set mesh resolution at points of those objects.
In principle, I am interested in Extrude
and BooleanDifference
.
In the example below I create a cylinder with a transverse cylindrical hole:
- Create cylinder 1 with an
Extrude
operation - Create transverse cylinder 2 with an
Extrude
operation - Subtract cylinder 2 from 1 with a
BooleanDifference
operation
As for Extrude
, I want to programmatically get the IDs of all entities created by either of the Extrude
operations in the example. So far, from example t3.geo
I learned how to interpret the return value of Extrude
(e.g., array extrusion_body
in my example). Element 0 is the ID of the extruded “top” surface, element 1 is the ID of the volume, and the remaining elements are the IDs of the Nc side surfaces of the extruded volume.
I.e., extrusion_body[] = [ID top surface, ID volume, ID side surface 1, ..., ID side surface Nc]
.
What I am missing is:
- How to programmatically get the total number Ne of elements in
extrusion_body
(a functionlen
or similar?). Note that I can work around this by knowing the number Nc of curves in the to-be-extruded “bottom” surface, since Ne = Nc+2. - How to programmatically get the association (ID to-extrude curve <-> ID side surface) between IDs of each of the Nc curves in the
Curve Loop
that originated the “bottom” surface and IDs of the Nc extruded side surfaces. By inspection, I learned that operationExtrude
does not preserve the ordering. E.g., if I extrude aSurface
based on aCurve Loop(cl_edge_f) = { l_edge_ruf, l_edge_rdf, l_edge_cdf, l_edge_cuf }
then side surface IDs as elementsextrusion_body[2 ... 5]
in the return value ofExtrude
do not necessarily correspond in order to IDs of the originating lines{ l_edge_ruf, l_edge_rdf, l_edge_cdf, l_edge_cuf }
. - How to programmatically get the IDs of extruded lines and points that are parents of the side and top surfaces. I found no information at all about this.
This is essential to properly set mesh resolution at those points.
I guess with those IDs, I could set mesh resolution with Characteristic Length
(e.g., t2.geo
).
As for BooleanDifference
, and in particular with Delete
, I found no way of getting any of the IDs of the generated objects.
Thanks!
My example:
//newp: point
//newc: curve
//news: surface
//newv: volume
//newcl: curve loop
//newsl: surface loop
//newreg: region. That is, newreg returns the maximum of newp, newl, news, newv, newll, newsl and all physical group tags4.
//================== Geometrical data ======================
/// sample body
// diameter = 1 inch
diam = 1.0 * 0.0254;
radius = 0.5 * diam;
// length
length = 0.05;
hlengthh = length / 2.0;
/// hole
hdiamr = 0.5;
hdiam = hdiamr * diam;
hradius = hdiam / 2.0;
hytop = hdiam;
hybot = -hdiam;
//===================== Resolution =========================
res_outer = diam / 5;
res_outer_hole = diam / 10;
//res_inner_hole = diam / 20;
//======================== Mesh ============================
// location are represented by initials, e.g. left/up/center -> luc.
//
// ^ y (up-center-down)
// |
// |
// |
// |
// |
// -----------> x (left-center-right)
// /
// /
// /
// /
// v z (front-center-back)
SetFactory("OpenCASCADE");
//==== First we draw one of the end faces. Due to symmetry, we replaced the
//==== original full face by a half face.
//== Outer surface, end face - Points
/// Front
//// Center
p_ccf = newp;
Point(p_ccf) = { 0.0, 0.0, hlengthh, res_outer };
//// Left
//p_lcf = newp;
//Point(p_lcf) = { -radius, 0.0, hlengthh, res_outer };
//// Right
p_rcf = newp;
Point(p_rcf) = { radius, 0.0, hlengthh, res_outer };
//// Up
p_cuf = newp;
Point(p_cuf) = { 0.0, radius, hlengthh, res_outer };
//// Down
p_cdf = newp;
Point(p_cdf) = { 0.0, -radius, hlengthh, res_outer };
//== Outer surface, end face - Edges (Lines)
//// Right Up
l_edge_ruf = newl;
Circle(l_edge_ruf) = { p_rcf, p_ccf, p_cuf };
//// Right Down
l_edge_rdf = newl;
Circle(l_edge_rdf) = { p_cdf, p_ccf, p_rcf };
//// Center Up
l_edge_cuf = newl;
Line(l_edge_cuf) = { p_ccf, p_cuf };
//// Center Down
l_edge_cdf = newl;
Line(l_edge_cdf) = { p_cdf, p_ccf };
//// Compound
cl_edge_f = newc;
Curve Loop(cl_edge_f) = { l_edge_ruf, l_edge_rdf, l_edge_cdf, l_edge_cuf };
//== Outer surface, end face - Surface
s_face_f = news;
Plane Surface(s_face_f) = { cl_edge_f };
//==== Then we extrude the end face to obtain a volume.
extrusion_body[] = Extrude { 0.0, 0.0, -length } { Surface{s_face_f}; };
//Printf("%d", len(extrusion_body) );
Printf("%f %f %f %f %f %f", extrusion_body[0], extrusion_body[1], extrusion_body[2], extrusion_body[3], extrusion_body[4], extrusion_body[5] );
// From t3.geo
// In this last extrusion command we retrieved the volume number programatically
// by using the return value (a list) of the Extrude command. This list contains
// the "top" of the extruded surface (in out[0]), the newly created volume (in
// out[1]) and the ids of the lateral surfaces (in out[2], out[3], ...)
s_face_b = extrusion_body[0];
v_body = extrusion_body[1];
s_side_ru = extrusion_body[2];
s_side_cu = extrusion_body[3];
s_side_cd = extrusion_body[4];
s_side_rd = extrusion_body[5];
//==== Then we draw one of the end faces of the hole.
//== Hole, end face - Points
/// Right Face
//// Center
p_hole_rcc = newp;
Point(p_hole_rcc) = { radius, 0.0, 0.0, res_outer_hole };
//// Front
p_hole_rcf = newp;
Point(p_hole_rcf) = { radius, 0.0, hradius, res_outer_hole };
//// Back
p_hole_rcb = newp;
Point(p_hole_rcb) = { radius, 0.0, -hradius, res_outer_hole };
//// Up
p_hole_ruc = newp;
Point(p_hole_ruc) = { radius, hradius, 0.0, res_outer_hole };
//// Down
p_hole_rdc = newp;
Point(p_hole_rdc) = { radius, -hradius, 0.0, res_outer_hole };
//== Hole, end face - Edges (Lines)
//// Back Up
l_edge_hole_rub = newl;
Circle(l_edge_hole_rub) = { p_hole_rcb, p_hole_rcc, p_hole_ruc };
//// Front Up
l_edge_hole_ruf = newl;
Circle(l_edge_hole_ruf) = { p_hole_ruc, p_hole_rcc, p_hole_rcf };
//// Front Down
l_edge_hole_rdf = newl;
Circle(l_edge_hole_rdf) = { p_hole_rcf, p_hole_rcc, p_hole_rdc };
//// Back Down
l_edge_hole_rdb = newl;
Circle(l_edge_hole_rdb) = { p_hole_rdc, p_hole_rcc, p_hole_rcb };
//// Compound
cl_edge_hole_r = newcl;
Curve Loop(cl_edge_hole_r) = { l_edge_hole_rub, l_edge_hole_ruf, l_edge_hole_rdf, l_edge_hole_rdb };
//== Hole, end face - Surface
s_hole_r = news;
Plane Surface(s_hole_r) = { cl_edge_hole_r };
//==== Then we extrude the end face to obtain a volume.
extrusion_hole[] = Extrude { -diam, 0.0, 0.0 } { Surface{s_hole_r}; };
Printf("%f %f %f %f %f %f", extrusion_hole[0], extrusion_hole[1], extrusion_hole[2], extrusion_hole[3], extrusion_hole[4], extrusion_hole[5] );
s_hole_l = extrusion_hole[0];
v_hole = extrusion_hole[1];
s_side_hole_ub = extrusion_hole[2];
s_side_hole_uf = extrusion_hole[3];
s_side_hole_df = extrusion_hole[4];
s_side_hole_db = extrusion_hole[5];
//==== Then we subtract the hole volume from the sample volume.
// Subtract the hole
BooleanDifference{ Volume{v_body}; Delete; }{ Volume{v_hole}; Delete; }