Peter,

To make sure you have the correct trimmed surface I think the easiest is simply 
construct your "subvolume" by starting from the solid. Here's a modified 
version of example that uses that approach.

Christophe

import gmsh
import sys
import numpy as np

# set up parameters (eventually will read from file).
th_l = 10.0
th_u = 40.0

phioff = 160.0
phi = 20.0

infrac = 0.0
outfrac = 0.7
thickness = 1.0

radius = 1.0

# create rectangular coords of point from r, theta, phi.
def polars(rad,th,phi):
    x = rad*np.cos(np.radians(th))*np.cos(np.radians(phi))
    y = rad*np.cos(np.radians(th))*np.sin(np.radians(phi))
    z = rad*np.sin(np.radians(th))
    return x,y,z

# start of main code
gmsh.initialize(sys.argv)
gmsh.option.setNumber("General.Terminal", 1)
gmsh.model.add("sphere_cut")

sph1 = gmsh.model.occ.addSphere(0,0,0, radius, -1, 0, np.pi/2, 2*np.pi)
sph2 = gmsh.model.occ.addSphere(0,0,0, radius+thickness, -1, 0, np.pi/2, 2*np.pi)
sph3 = gmsh.model.occ.addSphere(0,0,0, radius+outfrac*thickness, -1, 0, np.pi/2, 2*np.pi)

outf, _ = gmsh.model.occ.cut([(3,sph3)], [(3,sph1)], -1, True, False)

origin = gmsh.model.occ.addPoint(0.,0.,0.,0,-1)
x,y,z = polars(radius+thickness,th_l,phioff-phi)
pll = gmsh.model.occ.addPoint(x,y,z,0,-1)
x,y,z = polars(radius+thickness,th_u,phioff-phi)
pul = gmsh.model.occ.addPoint(x,y,z,0,-1)
x,y,z = polars(radius+thickness,th_u,phioff+phi)
pur = gmsh.model.occ.addPoint(x,y,z,0,-1)
x,y,z = polars(radius+thickness,th_l,phioff+phi)
plr = gmsh.model.occ.addPoint(x,y,z,0,-1)

c12 = gmsh.model.occ.addLine(pll,pul,-1)
c22 = gmsh.model.occ.addLine(pul,pur,-1)
c32 = gmsh.model.occ.addLine(pur,plr,-1)
c42 = gmsh.model.occ.addLine(plr,pll,-1)
c1 = gmsh.model.occ.addLine(origin,pul,-1)
c2 = gmsh.model.occ.addLine(origin,pur,-1)
c3 = gmsh.model.occ.addLine(origin,plr,-1)
c4 = gmsh.model.occ.addLine(origin,pll,-1)
cl = gmsh.model.occ.addCurveLoop([c12,c22,c32,c42],-1)
cl1 = gmsh.model.occ.addCurveLoop([c12,c1,c4],-1)
cl2 = gmsh.model.occ.addCurveLoop([c22,c2,c1],-1)
cl3 = gmsh.model.occ.addCurveLoop([c32,c3,c2],-1)
cl4 = gmsh.model.occ.addCurveLoop([c42,c4,c3],-1)
s1 = gmsh.model.occ.addPlaneSurface([cl],-1)
s2 = gmsh.model.occ.addPlaneSurface([cl1],-1)
s3 = gmsh.model.occ.addPlaneSurface([cl2],-1)
s4 = gmsh.model.occ.addPlaneSurface([cl3],-1)
s5 = gmsh.model.occ.addPlaneSurface([cl4],-1)
sl = gmsh.model.occ.addSurfaceLoop([s1,s2,s3,s4,s5],-1)
v = gmsh.model.occ.addVolume([sl],-1)

stuff, _ = gmsh.model.occ.intersect([outf], [(3,v)])

gmsh.model.occ.fragment([(3,sph1),(3,sph2)], [stuff])

gmsh.model.occ.synchronize()
gmsh.fltk.run()
gmsh.finalize()

> On 30 Apr 2019, at 07:59, Peter Johnston <[email protected]> wrote:
> 
> Dear Max,
> 
> Thanks for your thoughts. However, I am not sure how this helps as the 
> spheres are no longer concentric.
> 
> I have made another example script, this time in python, that shows the issue 
> that I keep coming up against. If you run the script, you will see that 
> surfaces 10 and 13 have the same set of bounding curves: 6, 7, 8 and 9, but 
> one is a bspline surface and the other is a spherical surface. Perhaps I 
> simply need to delete one of these?
> 
> Regards,
> 
> Peter.
> 
> ---------------------------------------------------------------------
> 
> Associate Professor Peter Johnston (FAustMS, FIMA)
> School of Environment and Science
> Griffith University | Nathan | QLD 4111 | Technology (N44) Room 3.19
> T +61 7 373 57748| F +61 7 373 57656 Email [email protected]
> On 29 Apr 2019, 6:41 AM +1000, Max Orok <[email protected]>, wrote:
>> Hello Peter,
>> 
>> I took a bit of a different approach and hopefully it is similar to what 
>> you'd like to do.
>> This short script makes a "sphere patch" by subtracting one sphere from 
>> another.
>> 
>> SetFactory("OpenCASCADE");
>> 
>> // arbitrary angle selections here
>> Sphere(1) = {0, 0, 0, 0.5, -Pi/9, Pi/9, Pi/4};
>> Sphere(2) = {-.25, 0, 0, 0.5, -Pi/9, Pi/9, Pi/4}; // shift sphere 2
>> 
>> // use sphere 2 to cut sphere 1
>> BooleanDifference{ Volume{1}; Delete; }{ Volume{2}; Delete; }
>> 
>> <image.png>
>> <image.png>
>> 
>> I hope this is helpful! If I missed the point please let me know.
>> 
>> Sincerely,
>> Max
>> 
>> On Wed, Apr 24, 2019 at 7:22 PM Peter Johnston <[email protected]> 
>> wrote:
>> Thanks Max and Christophe,
>> 
>> I have attached a simple sample .geo file. For some reason it creates even 
>> more volumes than the more complicated script I was working on. However, it 
>> still displays similar problems.
>> 
>> If you have any further questions, please let me know.
>> 
>> Thanks again,
>> 
>> Peter.
>> 
>> ---------------------------------------------------------------------
>> 
>> Associate Professor Peter Johnston (FAustMS, FIMA)
>> School of Environment and Science
>> Griffith University | Nathan | QLD 4111 | Technology (N44) Room 3.19
>> T +61 7 373 57748| F +61 7 373 57656 Email [email protected]
>> On 25 Apr 2019, 1:36 AM +1000, Max Orok <[email protected]>, wrote:
>>> Hi Peter,
>>> 
>>> Scripts are always helpful! It is nice to be able to see the steps as you 
>>> go along.
>>> 
>>> Max
>>> 
>>> On Wed, Apr 24, 2019 at 8:36 AM Peter Johnston <[email protected]> 
>>> wrote:
>>> Hello,
>>> 
>>> I appear to have a problem for which I cannot figure out a solution.
>>> 
>>> I have an annular hemispherical volume created between to hemispheres 
>>> centred on the origin. I would like to divide the volume into two parts in 
>>> a special way using Boolean operations. To define a sub-volume of the 
>>> initial volume by defining four points on the surface of the inner sphere, 
>>> create a “quadrilateral” on the inner surface by joining the four points in 
>>> order using circles through the origin. (I think that these should be parts 
>>> of great circles on the inner surface?). Then I create a line loop and a 
>>> surface, and finally extrude the surface away from the origin to create a 
>>> volume. Perhaps a .geo script would help here?
>>> 
>>> When I perform BooleanDifferences and BooleanIntersections I end up with 
>>> three volumes instead of two. The reason I get the third volume is that the 
>>> surface patch that I create does not fit exactly onto the original 
>>> spherical surface. Is there any way that I can force the patch to be part 
>>> of the spherical surface?
>>> 
>>> A consequence of the extra volume is that I cannot create a sensible mesh.
>>> 
>>> Any ideas would be greatly appreciated.
>>> 
>>> Thanks very much,
>>> 
>>> Peter.
>>> 
>>> PS, I could send a simple script file if that would help.
>>> 
>>> ---------------------------------------------------------------------
>>> 
>>> Associate Professor Peter Johnston (FAustMS, FIMA)
>>> School of Environment and Science
>>> Griffith University | Nathan | QLD 4111 | Technology (N44) Room 3.19
>>> T +61 7 373 57748| F +61 7 373 57656 Email [email protected]
>>> _______________________________________________
>>> gmsh mailing list
>>> [email protected]
>>> http://onelab.info/mailman/listinfo/gmsh
>>> 
>>> 
>>> --
>>> Max Orok
>>> Contractor
>>> www.mevex.com
>>> 
>>> 
>> 
>> 
>> --
>> Max Orok
>> Contractor
>> www.mevex.com
>> 
>> 
> <sample.py>_______________________________________________
> gmsh mailing list
> [email protected]
> http://onelab.info/mailman/listinfo/gmsh

— 
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science 
http://www.montefiore.ulg.ac.be/~geuzaine



_______________________________________________
gmsh mailing list
[email protected]
http://onelab.info/mailman/listinfo/gmsh

Reply via email to