Ejemplo n.º 1
0
    def intersect(self):
        if not self.found_intersection:
            self._geo_int = None
            return None

        geo_out = cad_geometry()

        list_t = asarray(self.list_t); list_t.sort()
        list_s = asarray(self.list_s); list_s.sort()

        axis = 0

        geo = cad_geometry()
        geo.append(self.wall)
        for i,t in enumerate(list_t):
            geo.split(i,t,axis)
        for i_nrb in range(0, geo.npatchs):
            geo_out.append(geo[i_nrb])

        geo = cad_geometry()
        geo.append(self.flux)
        for i,s in enumerate(list_s):
            geo.split(i,s,axis)

        for i_nrb in range(0, geo.npatchs):
            geo_out.append(geo[i_nrb])

        self._geo_int = geo_out
        return geo_out
Ejemplo n.º 2
0
    def open(self, filename):
        from caid.cad_geometry import cad_geometry
        from caid.io import XML
        io = XML()

        from xml.dom.minidom import parse
        doc = parse(filename)
        rootElt = doc.documentElement

        # read attributs
        # get camera attributs
        #    eye = strtoArray(rootElt.getAttribute("eye"))
        #    self.viewer.lookAt.SetEye(eye)

        # geometry
        geoElt = rootElt.getElementsByTagName("geometry")[0]
        geo = cad_geometry()
        io.xmltogeo(geo, doc, geoElt)

        # ... values
        valuesElt = rootElt.getElementsByTagName("values")[0]
        values = cad_geometry()
        io.xmltogeo(values, doc, valuesElt)

        self.set_geometry(geo)
        self.set_values(values)
Ejemplo n.º 3
0
    def open(self, filename):
        from caid.cad_geometry import cad_geometry
        from caid.io import XML
        io = XML()

        from xml.dom.minidom import parse
        doc = parse(filename)
        rootElt = doc.documentElement

        # read attributs
        # get camera attributs
    #    eye = strtoArray(rootElt.getAttribute("eye"))
    #    self.viewer.lookAt.SetEye(eye)

        # geometry
        geoElt = rootElt.getElementsByTagName("geometry")[0]
        geo = cad_geometry()
        io.xmltogeo(geo, doc, geoElt)

        # ... values
        valuesElt = rootElt.getElementsByTagName("values")[0]
        values = cad_geometry()
        io.xmltogeo(values, doc, valuesElt)

        self.set_geometry(geo)
        self.set_values(values)
Ejemplo n.º 4
0
    def cutCurve(self):
        wk = self.workGroup
        try:
            list_patchs = []
            for item in wk.inspector.tree.selectionsItems:
                patch = wk.inspector.tree.GetItemData(item)
                if patch.dim > 1:
                    print("cut curves algorithm only works with curves")
                    return
                list_patchs.append(patch)
            if len(list_patchs) > 1:
                print(("cut curves algorithm needs 1 curve, but "\
                        , len(list_patchs), " curves were given"))
                return

            from caid.utils.intersect import intersect_crv
            c0 = list_patchs[0]
            geo0 = cad_geometry()
            geo0.append(c0)

            freq = wk.viewer.cutCurveFreq
            list_P = wk.viewer.CutCurvePoints[::freq]
            x, y, z = list(zip(*list_P))
            x = np.asarray(x)
            y = np.asarray(y)
            z = np.asarray(z)
            from scipy import interpolate
            smooth = 0.
            degree = 3
            tck, u = interpolate.splprep([x, y], s=smooth, k=degree)
            knots = tck[0]
            Px = tck[1][0]
            Py = tck[1][1]
            C = np.zeros((len(Px), 3))
            C[:, 0] = array(Px)
            C[:, 1] = array(Py)
            c1 = cad_nurbs([knots], C)
            geo1 = cad_geometry()
            geo1.append(c1)

            list_P, list_t, list_s, ierr = intersect_crv(c0, c1)

            list_t = np.asarray(list_t)
            list_t.sort()
            axis = 0
            for i, t in enumerate(list_t):
                geo0.split(i, t, axis)

            wk.add_geometry(geometry(geo0))
            wk.Refresh()
        except:
            self.statusbar.SetStatusText(
                'Cannot use cut Curve. Check that a patch is selected on the inspector'
            )
Ejemplo n.º 5
0
    def cutCurve(self):
        wk = self.workGroup
        try:
            list_patchs = []
            for item in wk.inspector.tree.selectionsItems:
                patch = wk.inspector.tree.GetPyData(item)
                if patch.dim > 1:
                    print("cut curves algorithm only works with curves")
                    return
                list_patchs.append(patch)
            if len(list_patchs) > 1:
                print(("cut curves algorithm needs 1 curve, but ", len(list_patchs), " curves were given"))
                return

            from caid.utils.intersect import intersect_crv

            c0 = list_patchs[0]
            geo0 = cad_geometry()
            geo0.append(c0)

            freq = wk.viewer.cutCurveFreq
            list_P = wk.viewer.CutCurvePoints[::freq]
            x, y, z = list(zip(*list_P))
            x = np.asarray(x)
            y = np.asarray(y)
            z = np.asarray(z)
            from scipy import interpolate

            smooth = 0.0
            degree = 3
            tck, u = interpolate.splprep([x, y], s=smooth, k=degree)
            knots = tck[0]
            Px = tck[1][0]
            Py = tck[1][1]
            C = np.zeros((len(Px), 3))
            C[:, 0] = array(Px)
            C[:, 1] = array(Py)
            c1 = cad_nurbs([knots], C)
            geo1 = cad_geometry()
            geo1.append(c1)

            list_P, list_t, list_s, ierr = intersect_crv(c0, c1)

            list_t = np.asarray(list_t)
            list_t.sort()
            axis = 0
            for i, t in enumerate(list_t):
                geo0.split(i, t, axis)

            wk.add_geometry(geometry(geo0))
            wk.Refresh()
        except:
            self.statusbar.SetStatusText("Cannot use cut Curve. Check that a patch is selected on the inspector")
Ejemplo n.º 6
0
    def test3():
        from . import fem as fem
        from caid.cad_geometry import line, circle, bilinear
        import caid.cad_geometry as cg

        fe = fem.fem()

        geo1 = cg.cad_geometry(geo=line())
        geo2 = cg.cad_geometry(geo=circle())
        geo3 = cg.cad_geometry(geo=bilinear())

        PDE1 = pigasus(fem=fe, geometry=geo1)
        PDE2 = pigasus(fem=fe, geometry=geo2)
        PDE3 = pigasus(fem=fe, geometry=geo3)
Ejemplo n.º 7
0
    def createBilinear(self):
        wk = self.workGroup
        list_P = wk.viewer.MarkerPoints
        if len(list_P) != 4:
            print("You have to specify 4 markers.")
            return

        A = list_P[0]
        B = list_P[1]
        C = list_P[2]
        D = list_P[3]

        points = np.zeros((2, 2, 3))

        points[0, 0, :] = A[:3]
        points[1, 0, :] = B[:3]
        points[0, 1, :] = C[:3]
        points[1, 1, :] = D[:3]

        #        weights[0,0] = A[3]
        #        weights[1,0] = B[3]
        #        weights[0,1] = C[3]
        #        weights[1,1] = D[3]

        from caid.cad_geometry import bilinear
        nrb = bilinear(points=points)[0]

        wk.viewer.CleanMarkerPoints()
        geo = cad_geometry()
        geo.append(nrb)
        wk.add_geometry(geometry(geo))
        wk.Refresh()
Ejemplo n.º 8
0
    def construct(self, xyzk, uvk=None, exportGeometry=True):
        cxyz = self.fit(xyzk, uvk=uvk)

        U = self.PDE.unknown

        geo_ini = self.geometry
        if exportGeometry:
            geo_f = cad_geometry()
        else:
            list_nrb = []

        for patch_id in range(0, self.geometry.npatchs):
            nrb = self.geometry[patch_id]

            C = np.zeros(list(nrb.shape) + [3])
            for i, cx in enumerate(cxyz):
                U.set(cx)
                C[..., i] = U.tomatrix(patch_id).reshape(nrb.shape)

            if exportGeometry:
                srf = cad_nurbs(nrb.knots, C, weights=nrb.weights)
                srf.orientation = nrb.orientation
                srf.rational = nrb.rational
                geo_f.append(srf)
            else:
                srf = cad_nurbs(nrb.knots, C, weights=nrb.weights)
                list_nrb.append(srf)

        if exportGeometry:
            geo_f.set_internal_faces(geo_ini.internal_faces)
            geo_f.set_external_faces(geo_ini.external_faces)
            geo_f.set_connectivity(geo_ini.connectivity)
            return geo_f
        else:
            return list_nrb
Ejemplo n.º 9
0
def refine(geo, n=None, p=None):
    if n is None:
        n = np.zeros(geo.dim, dtype=np.int)
    if p is None:
        p = np.zeros(geo.dim, dtype=np.int)
    n = np.asarray(n)
    p = np.asarray(p)
    geo_t = cg.cad_geometry()

    nrb = geo[0]
    geo_t.append(nrb)
    # ... refinement
    list_t = None
    if n.sum() > 0:
        list_t = []
        for axis in range(0,nrb.dim):
            ub = nrb.knots[axis][0]
            ue = nrb.knots[axis][-1]
            t = []
            if n[axis] > 0:
                t = np.linspace(ub,ue,n[axis]+2)[1:-1]
            list_t.append(t)

    list_p = None
    if p.sum() > 0:
        list_p = []
        for axis in range(0,nrb.dim):
            list_p.append(np.max(p[axis] - nrb.degree[axis], 0))

    geo_t.refine(list_t=list_t, list_p=list_p)
    return geo_t
Ejemplo n.º 10
0
    def transferSolution(self, geo_H, U_H, geo_h, U_h):
        patch_id = 0
        nrb_H = geo_H[patch_id]
        nrb_h = geo_h[patch_id]

        # degrees of the input surface
        px_in = nrb_H.degree[0]
        py_in = nrb_H.degree[1]

        # degrees of the output surface
        px = nrb_h.degree[0]
        py = nrb_h.degree[1]

        C = np.zeros_like(nrb_H.points)
        shape = list(nrb_H.shape)
        C = np.zeros(shape+[3])
        _C = U_H.tomatrix(patch_id)
        C[...,0] = _C
        srf = cad_nurbs(nrb_H.knots, C, weights= nrb_H.weights)

        geo_f = cad_geometry()
        geo_f.append(srf)

        list_t = []
        for axis in range(0, nrb_H.dim):
            tx = [t for t in nrb_h.knots[axis] if t not in nrb_H.knots[axis]]
            list_t.append(tx)

        geo_f.refine(list_t = list_t, list_p=[px-px_in, py-py_in])
        uh = geo_f[0].points[...,0]
        U_h.frommatrix(patch_id, uh)
Ejemplo n.º 11
0
def refine(geo, n=None, p=None):
    if n is None:
        n = np.zeros(geo.dim, dtype=np.int)
    if p is None:
        p = np.zeros(geo.dim, dtype=np.int)
    n = np.asarray(n)
    p = np.asarray(p)
    geo_t = cg.cad_geometry()

    nrb = geo[0]
    geo_t.append(nrb)
    # ... refinement
    list_t = None
    if n.sum() > 0:
        list_t = []
        for axis in range(0, nrb.dim):
            ub = nrb.knots[axis][0]
            ue = nrb.knots[axis][-1]
            t = []
            if n[axis] > 0:
                t = np.linspace(ub, ue, n[axis] + 2)[1:-1]
            list_t.append(t)

    list_p = None
    if p.sum() > 0:
        list_p = []
        for axis in range(0, nrb.dim):
            list_p.append(np.max(p[axis] - nrb.degree[axis], 0))

    geo_t.refine(list_t=list_t, list_p=list_p)
    return geo_t
Ejemplo n.º 12
0
    def createBilinear(self):
        wk = self.workGroup
        list_P = wk.viewer.MarkerPoints
        if len(list_P) != 4 :
            print("You have to specify 4 markers.")
            return

        A = list_P[0]
        B = list_P[1]
        C = list_P[2]
        D = list_P[3]

        points = np.zeros((2,2,3))

        points[0,0,:] = A[:3]
        points[1,0,:] = B[:3]
        points[0,1,:] = C[:3]
        points[1,1,:] = D[:3]

#        weights[0,0] = A[3]
#        weights[1,0] = B[3]
#        weights[0,1] = C[3]
#        weights[1,1] = D[3]

        from caid.cad_geometry import bilinear
        nrb = bilinear(points=points)[0]

        wk.viewer.CleanMarkerPoints()
        geo = cad_geometry()
        geo.append(nrb)
        wk.add_geometry(geometry(geo))
        wk.Refresh()
Ejemplo n.º 13
0
    def genGeometry(self):
        from caid.op_nurbs import opNURBS, grad
        from caid.cad_geometry import cad_geometry, cad_grad_nurbs, cad_nurbs

        geo = self.geo_h
        PDE = self.PDE_h
        if PDE.Dirichlet:
            U = PDE.unknown_dirichlet
        else:
            U = PDE.unknown
        geo_f = cad_geometry()
        for patch_id in range(0, geo.npatchs):
            met = geo[patch_id]

            _C = U.tomatrix(patch_id)
            C = np.zeros_like(met.points)
            C[..., :2] = met.points[..., :2]
            C[..., 2] = _C
            srf = cad_nurbs(met.knots, C, weights=met.weights)
            gsrf = grad(srf)
            grad_nrb = cad_grad_nurbs(gsrf)
            print("name ", grad_nrb.__class__.__name__)
            geo_f.append(grad_nrb)
            geo_f[-1].set_orientation(met.orientation)
            geo_f[-1].set_rational(met.rational)

        geo_f.set_internal_faces(geo.internal_faces)
        geo_f.set_external_faces(geo.external_faces)
        geo_f.set_connectivity(geo.connectivity)

        return geo_f
Ejemplo n.º 14
0
    def construct(self, xyzk, uk=None):
        cxyz = self.fit(xyzk, uk=uk)

        U = self.PDE.unknown

        geo_ini = self.geometry

        geo_f = cad_geometry()
        for patch_id in range(0, self.geometry.npatchs):
            nrb = self.geometry[patch_id]

            C = np.zeros(list(nrb.shape) + [3])
            for i, cx in enumerate(cxyz):
                U.set(cx)
                C[..., i] = U.tomatrix(patch_id).reshape(nrb.shape)

            srf = cad_nurbs(nrb.knots, C, weights=nrb.weights)
            srf.orientation = nrb.orientation
            srf.rational = nrb.rational
            geo_f.append(srf)

        geo_f._internal_faces = geo_ini._internal_faces
        geo_f._external_faces = geo_ini._external_faces
        geo_f._connectivity = geo_ini._connectivity

        return geo_f
Ejemplo n.º 15
0
    def open(self, filename=None):
        if filename is not None:
            self.filename = filename
        else:
            from global_vars import CAIDWorkGroupwildcard
            # Create an open file dialog
            dialog = wx.FileDialog(None\
                                   , style = wx.OPEN\
                                   , wildcard=CAIDWorkGroupwildcard)
            # Show the dialog and get user input
            if dialog.ShowModal() == wx.ID_OK:
                self.filename = dialog.GetPath()
            # The user did not select anything
            else:
                print('Nothing was selected.')
            # Destroy the dialog
            dialog.Destroy()

        from caid.cad_geometry import cad_geometry
        from caid.io import XML
        from geometry import geometry
        io = XML()

        from xml.dom.minidom import parse
        doc = parse(self.filename)
        rootElt = doc.documentElement

        # read attributs
        # get camera attributs
        eye = strtoArray(rootElt.getAttribute("eye"))
        self.viewer.lookAt.SetEye(eye)
        center = strtoArray(rootElt.getAttribute("center"))
        self.viewer.lookAt.SetCenter(center)
        up = strtoArray(rootElt.getAttribute("up"))
        self.viewer.lookAt.SetUp(up)
        # get colors attributs

        # ...
        try:
            self.viewer.theme.load(rootElt=rootElt)
        except:
            print("Theme can not be loaded. Dark theme will be used.")
            self.viewer.theme.set_theme("dark")
        # ...

        for geoElt in rootElt.getElementsByTagName("geometry"):
            geo = cad_geometry()
            io.xmltogeo(geo, doc, geoElt)
            _geo = geometry(geo)
            _geo.load_attributs()
            self.add_geometry(_geo)

        self.Refresh()

        # sets the temporary file for auto-save
        tmp = self.filename.split('/')[-1]
        basedir = self.filename.split(tmp)[0]
        self.tmp_filename = basedir+"~"+tmp
Ejemplo n.º 16
0
    def open(self, filename=None):
        if filename is not None:
            self.filename = filename
        else:
            from global_vars import CAIDWorkGroupwildcard
            # Create an open file dialog
            dialog = wx.FileDialog(None\
                                   , style = wx.OPEN\
                                   , wildcard=CAIDWorkGroupwildcard)
            # Show the dialog and get user input
            if dialog.ShowModal() == wx.ID_OK:
                self.filename = dialog.GetPath()
            # The user did not select anything
            else:
                print('Nothing was selected.')
            # Destroy the dialog
            dialog.Destroy()

        from caid.cad_geometry import cad_geometry
        from caid.io import XML
        from geometry import geometry
        io = XML()

        from xml.dom.minidom import parse
        doc = parse(self.filename)
        rootElt = doc.documentElement

        # read attributs
        # get camera attributs
        eye = strtoArray(rootElt.getAttribute("eye"))
        self.viewer.lookAt.SetEye(eye)
        center = strtoArray(rootElt.getAttribute("center"))
        self.viewer.lookAt.SetCenter(center)
        up = strtoArray(rootElt.getAttribute("up"))
        self.viewer.lookAt.SetUp(up)
        # get colors attributs

        # ...
        try:
            self.viewer.theme.load(rootElt=rootElt)
        except:
            print("Theme can not be loaded. Dark theme will be used.")
            self.viewer.theme.set_theme("dark")
        # ...

        for geoElt in rootElt.getElementsByTagName("geometry"):
            geo = cad_geometry()
            io.xmltogeo(geo, doc, geoElt)
            _geo = geometry(geo)
            _geo.load_attributs()
            self.add_geometry(_geo)

        self.Refresh()

        # sets the temporary file for auto-save
        tmp = self.filename.split('/')[-1]
        basedir = self.filename.split(tmp)[0]
        self.tmp_filename = basedir + "~" + tmp
Ejemplo n.º 17
0
 def geometry_1D(nx, px):
     # ...
     nrb = line(p0=(0, 0), p1=(1, 0))
     geo = cg.cad_geometry(geo=nrb)
     geo.refine(id=0, list_p=[px - 1])
     tx = np.linspace(0., 1., nx + 2)[1:-1]
     geo.refine(id=0, list_t=[tx])
     # ...
     return geo
Ejemplo n.º 18
0
def get_geometry(domain):
    """ Reads a geometry from a file.
    Args:
      domain(str) : type of domain to open."""
    if (domain == 0):
        ls_domain = "domains/2squares_inv.xml"
        import caid.cad_geometry as cg
        geo = cg.cad_geometry(ls_domain)
    elif (domain == 1):
        ls_domain = "domains/disk_100100.xml"
        import caid.cad_geometry as cg
        geo = cg.cad_geometry(ls_domain)
        # from caid.cad_geometry import circle
        # geo = circle()
    elif (domain == 2):
        ls_domain = "domains/disk_5mp_n64x64_p3x3.xml"
        import caid.cad_geometry as cg
        geo = cg.cad_geometry(ls_domain)
    elif (domain == 3):
        ls_domain = "domains/pinched_disk_5mp_eps09.xml"
        import caid.cad_geometry as cg
        geo = cg.cad_geometry(ls_domain)
    elif (domain == 4):
        ls_domain = "domains/4squares.xml"
        import caid.cad_geometry as cg
        geo = cg.cad_geometry(ls_domain)
    elif (domain == 5):
        ls_domain = "domains/annulus.xml"
        import caid.cad_geometry as cg
        geo = cg.cad_geometry(ls_domain)
    elif (domain == 6):
        ls_domain = "domains/2squares_C0.xml"
        import caid.cad_geometry as cg
        geo = cg.cad_geometry(ls_domain)
    elif (domain == 7):
        ls_domain = "domains/1square.xml"
        import caid.cad_geometry as cg
        geo = cg.cad_geometry(ls_domain)
    elif (domain == 8):
        ls_domain = "domains/quart_annulus_1mp.xml"
        import caid.cad_geometry as cg
        geo = cg.cad_geometry(ls_domain)
    else:
        raise SystemExit("ERROR in globals_variables:" \
                         + " no domain associated to that number")
    return geo
Ejemplo n.º 19
0
    def geometry_2D(nx, ny, px, py):
        # ...
        #    points = np.asarray([[[0.,0.],[0.,1.]],[[1.,0.],[1.,1.]]])
        points = np.asarray([[[0., 0.], [0., 1.]], [[2., 0.], [1., 1.]]])
        nrb = bilinear(points)
        geo = cg.cad_geometry(geo=nrb)
        geo.refine(id=0, list_p=[px - 1, py - 1])
        tx = np.linspace(0., 1., nx + 2)[1:-1]
        ty = np.linspace(0., 1., ny + 2)[1:-1]
        geo.refine(id=0, list_t=[tx, ty])
        # ...

        return geo
Ejemplo n.º 20
0
 def __init__(self, nrb):
     geometry = cad_geometry()
     geometry.append(nrb)
     geo_ref, list_lmatrices = geometry.bezier_extract()
     nrb_ref = geo_ref[0]
     list_lmatrices = list_lmatrices[0]
     npatchs = len(list_lmatrices)
     shape = list(list_lmatrices[0].shape)
     print(npatchs)
     print(shape)
     shape = [npatchs] + [3 + 1 + 1] + shape
     self._array = np.zeros(shape)
     for patch_id in range(0, npatchs):
         self._array[patch_id, 3, ...] = list_lmatrices[patch_id]
Ejemplo n.º 21
0
 def __init__(self, nrb):
     geometry = cad_geometry()
     geometry.append(nrb)
     geo_ref, list_lmatrices = geometry.bezier_extract()
     nrb_ref = geo_ref[0]
     list_lmatrices = list_lmatrices[0]
     npatchs = len(list_lmatrices)
     shape = list(list_lmatrices[0].shape)
     print(npatchs)
     print(shape)
     shape = [npatchs] + [3 + 1 + 1] + shape
     self._array = np.zeros(shape)
     for patch_id in range(0, npatchs):
         self._array[patch_id, 3, ...] = list_lmatrices[patch_id]
Ejemplo n.º 22
0
 def export(self, filename):
     from caid.cad_geometry import cad_geometry, cad_nurbs
     from caid.field import field as iga_field
     U = self
     geo   = U.space.geometry
     geo_c = cad_geometry()
     for i in range(0, geo.npatchs):
         nrb = geo[i]
         C = zeros_like(nrb.points)
         _C = U.tomatrix(i)
         shape = list(nrb.shape)
         C = zeros(shape+[3])
         C[...,0] = _C
         srf = cad_nurbs(nrb.knots, C, weights= nrb.weights)
         geo_c.append(srf)
     F = iga_field(geo, geo_c)
     F.save(filename)
Ejemplo n.º 23
0
def points_to_geo_interp(x, y, z=None, p=3):
    if z is None:
        z = np.zeros_like(x)

	tck, u = splprep([x,y], s=0, k=p)
    #-----------------------------------
    geo = cad_geometry()
    knots = [tck[0]]
    Px = tck[1][0]
    Py = tck[1][1]
    P = np.zeros((len(Px),3))
    P[:,0] = Px
    P[:,1] = Py

    nrb = cad_nurbs(knots, P)
    geo.append(nrb)
    #-----------------------------------

    return geo
Ejemplo n.º 24
0
    def load(self, filename):
        geo = cad_geometry(filename)
        self._geo_int = geo
        self._nt      = int(geo.get_attribut("n_intersection"))
        self._list_P = []
        for j in range(0, self.n_intersect):
            P_str = geo.get_attribut('intersection_P'+str(j))
            P = [float(x) for x in P_str.split(',')]

            t = geo.get_attribut('intersection_t'+str(j))
            s = geo.get_attribut('intersection_s'+str(j))

            P = asarray(P)
            t = float(t)
            s = float(s)

            self._list_P.append(P)
            self._list_t.append(t)
            self._list_s.append(s)
Ejemplo n.º 25
0
def create_wall(R_wall, Z_wall):
    zz = np.zeros_like(R_wall)
    list_P = list(zip(R_wall, Z_wall, zz))
    list_crv = []
    for P,Q in zip(list_P[:-1], list_P[1:]):
        points = np.zeros((2,2))
        points[0,0] = P[0] ; points[0,1] = P[1]
        points[1,0] = Q[0] ; points[1,1] = Q[1]
        crv = linear(points = points)[0]
        list_crv.append(crv)

    nrb = list_crv[0]
    axis = 0
    for crv in list_crv[1:]:
        nrb = join(nrb, crv, axis)
        nrb = cad_nurbs(nrb.knots, nrb.points, weights=nrb.weights)

    geo = cad_geometry()
    geo.append(nrb)
    return geo
Ejemplo n.º 26
0
    def createLines(self):
        wk = self.workGroup
        list_P = wk.viewer.MarkerPoints
        list_crv = []
        for P,Q in zip(list_P[:-1], list_P[1:]):
            points = np.zeros((2,2))
            points[0,0] = P[0] ; points[0,1] = P[1]
            points[1,0] = Q[0] ; points[1,1] = Q[1]
            crv = linear(points = points)[0]
            list_crv.append(crv)
        nrb = list_crv[0]
        axis = 0
        for crv in list_crv[1:]:
            nrb = join(nrb, crv, axis)

        wk.viewer.CleanMarkerPoints()
        geo = cad_geometry()
        geo.append(nrb)
        wk.add_geometry(geometry(geo))
        wk.Refresh()
Ejemplo n.º 27
0
    def createLines(self):
        wk = self.workGroup
        list_P = wk.viewer.MarkerPoints
        list_crv = []
        for P, Q in zip(list_P[:-1], list_P[1:]):
            points = np.zeros((2, 2))
            points[0, 0] = P[0]
            points[0, 1] = P[1]
            points[1, 0] = Q[0]
            points[1, 1] = Q[1]
            crv = linear(points=points)[0]
            list_crv.append(crv)
        nrb = list_crv[0]
        axis = 0
        for crv in list_crv[1:]:
            nrb = join(nrb, crv, axis)

        wk.viewer.CleanMarkerPoints()
        geo = cad_geometry()
        geo.append(nrb)
        wk.add_geometry(geometry(geo))
        wk.Refresh()
Ejemplo n.º 28
0
    def createArc(self):
        wk = self.workGroup
        list_P = wk.viewer.MarkerPoints
        if len(list_P) != 3:
            print("You have to specify 3 markers.")
            return

        dlg = edtTxtDialog(None, title="Edit Angle")
        dlg.ShowModal()
        ls_text = dlg.getValue()
        try:
            lr_degree = float(ls_text)
        except:
            lr_degree = 0.0

        theta = lr_degree * pi / 180

        dlg.Destroy()

        A0 = list_P[0]
        A1 = list_P[1]
        A2 = list_P[2]

        knots = [0., 0., 0., 1., 1., 1.]
        C = np.zeros((3, 3))
        C[0, :] = A0[:3]
        C[1, :] = A1[:3]
        C[2, :] = A2[:3]
        weights = [1., cos(theta), 1.]

        nrb = cad_nurbs([knots], C, weights=weights)

        wk.viewer.CleanMarkerPoints()
        geo = cad_geometry()
        geo.append(nrb)
        wk.add_geometry(geometry(geo))
        wk.Refresh()
Ejemplo n.º 29
0
    def createArc(self):
        wk = self.workGroup
        list_P = wk.viewer.MarkerPoints
        if len(list_P) != 3 :
            print("You have to specify 3 markers.")
            return

        dlg = edtTxtDialog(None, title="Edit Angle")
        dlg.ShowModal()
        ls_text = dlg.getValue()
        try:
            lr_degree = float(ls_text)
        except:
            lr_degree = 0.0

        theta = lr_degree * pi / 180

        dlg.Destroy()

        A0 = list_P[0]
        A1 = list_P[1]
        A2 = list_P[2]

        knots       = [0.,0.,0.,1.,1.,1.]
        C           = np.zeros((3,3))
        C[0,:]      = A0[:3]
        C[1,:]      = A1[:3]
        C[2,:]      = A2[:3]
        weights     = [1.,cos(theta),1.]

        nrb = cad_nurbs([knots], C, weights=weights)

        wk.viewer.CleanMarkerPoints()
        geo = cad_geometry()
        geo.append(nrb)
        wk.add_geometry(geometry(geo))
        wk.Refresh()
Ejemplo n.º 30
0
         [ 1.,-2., 0.],
         [ 1., 0., 0.],
         [ 1., 1., 0.],
         [ 0., 1., 0.],
         [-1., 1., 0.],
         [-1., 0., 0.],
         [-1.,-2., 0.],
         [ 0.,-2., 0.],]

    crv = cad_nurbs([T], C)
    return crv
# ...

# ... create a 3D curve
crv0 = make_curve()
geo = cad_geometry()
geo.append(crv0)
geo.plotMesh(MeshResolution=20)
plt.savefig("polar_extrude_ex1_original.png")
plt.clf()
# ...

# ... polar extrude
geo_1 = geo.polarExtrude()
U = np.linspace(0., 1., 9)[1:-1]
V = np.linspace(0., 1., 17)[1:-1]
V = [v for v in V if v not in crv0.knots[0]]
geo_1.refine(list_t=[U, V])
geo_1.plotMesh()
plt.savefig("polar_extrude_ex1_geo1.png")
plt.clf()
Ejemplo n.º 31
0
    def OnClick(self, event):
        # inspector = self.parent
        wk = self.parent.WorkGroup

        ID = event.GetId()
        if ID == self.BCK_ID:
            self.parent.ShowAction(self.parent.geometryActions)
        if ID == self.EMP_ID:
            geo = cad_geometry()
            wk.add_geometry(geometry(geo))
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... create object")
                macro_script.append("_geo = cad_geometry()")
                macro_script.append("wk.add_geometry(geometry(_geo))")
                macro_script.append("# ...")
        if ID == self.LIN_ID:
            from caid.cad_geometry import line as domain
            geo = domain()
            wk.add_geometry(geometry(geo))
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... create object")
                macro_script.append("_geo = line()")
                macro_script.append("wk.add_geometry(geometry(_geo))")
                macro_script.append("# ...")
        if ID == self.LNR_ID:
            self.parent.objectActionsCreateLinear.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateLinear)
        if ID == self.ARC_ID:
            self.parent.objectActionsCreateArc.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateArc)
        if ID == self.CRV_ID:
            self.parent.objectActionsCurve.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCurve)
        if ID == self.SQR_ID:
            from caid.cad_geometry import square as domain
            geo = domain()
            wk.add_geometry(geometry(geo))
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... create object")
                macro_script.append("_geo = square()")
                macro_script.append("wk.add_geometry(geometry(_geo))")
                macro_script.append("# ...")
        if ID == self.BIL_ID:
            self.parent.objectActionsCreateBilinear.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateBilinear)
        if ID == self.CRC_ID:
            self.parent.objectActionsCreateCircle.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateCircle)
        if ID == self.QCR_ID:
            self.parent.objectActionsCreateQuartCircle.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateQuartCircle)
        if ID == self.ANL_ID:
            self.parent.objectActionsCreateAnnulus.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateAnnulus)
        if ID == self.CR5_ID:
            self.parent.objectActionsCreateCircle_5mp.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateCircle_5mp)
        if ID == self.TRL_ID:
            self.parent.objectActionsCreateTriangle.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateTriangle)
Ejemplo n.º 32
0
if __name__ == "__main__":
    from pigasus.gallery.basicPDE import *
    from caid.cad_geometry import cad_geometry
    from scipy.io import mmwrite
    from scipy.sparse import csr_matrix

    #-----------------------------------
    t = 0.5
    #    nx = 2 ; px = 1
    nx = N - (p - 1)
    px = p
    nlevel = 1
    #-----------------------------------

    geo = cad_geometry("iter_inner.xml")
    nrb = geo[0]

    #-----------------------------------
    #    # ...
    #    def a_ext(s):
    #        S = nrb(s)
    #        return S[:,0]
    #    # ...
    #    # ...
    #    def b_ext(s):
    #        S = nrb(s)
    #        return S[:,1]
    #    # ...
    #    # ...
    #    def ads_ext(s):
Ejemplo n.º 33
0
    def OnClick(self, event):
        ID = event.GetId()
        if ID == self.NEW_ID:
            self.parent.ShowAction(self.parent.geometryActionsNew)
        if ID == self.ADD_ID:
            self.parent.ShowAction(self.parent.geometryActionsAdd)
        if ID == self.DEL_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            geoItem = wk.inspector.currentGeometryItem
            geo_id = wk.list_geo.index(geo)
            wk.remove_geometry(geoItem, geo)

            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... delete geometry")
                macro_script.append("geo_id = "+str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("geoItem = geo.treeItem")
                macro_script.append("wk.remove_geometry(geoItem, geo)")
                macro_script.append("# ...")

        if ID == self.DUP_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo_new = wk.inspector.currentGeometry.copy()
            geo_newItem = wk.add_geometry(geo_new)
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... copy geometry")
                geo_id = wk.list_geo.index(geo)
                macro_script.append("geo_id = "+str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("_geo = geo.copy()")
                macro_script.append("wk.add_geometry(geometry(_geo))")
                macro_script.append("# ...")

        if ID == self.PLJ_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            import matplotlib.pyplot as plt
            try:
                MeshResolution = geo.list_patchInfo[0].steps[0]
            except:
                MeshResolution = 10
            geo.plotJacobians(MeshResolution=MeshResolution)
            plt.colorbar()
            plt.show()
        if ID == self.PLM_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            import matplotlib.pyplot as plt
            MeshResolution = geo.list_patchInfo[0].steps[0]
            geo.plotMesh(MeshResolution=MeshResolution)
            plt.show()
        if ID == self.EXP_ID:
            from global_vars import CAIDwildcard
            # Create a save file dialog
            dialog = wx.FileDialog ( None, style = wx.SAVE | wx.OVERWRITE_PROMPT
                                   , wildcard=CAIDwildcard)
            # Show the dialog and get user input
            if dialog.ShowModal() == wx.ID_OK:
                ls_file = dialog.GetPath()
                wk = self.parent.WorkGroup
                geo = wk.inspector.currentGeometry
                geo.save(ls_file)

                # macro recording
                if wk.macroRecording:
                    macro_script = wk.macro_script
                    macro_script.new_line()
                    macro_script.append("# ... export geometry")
                    geo_id = wk.list_geo.index(geo)
                    macro_script.append("geo_id = "+str(geo_id))
                    macro_script.append("geo = geometries[geo_id]")
                    macro_script.append("filename = \""+ls_file+"\"")
                    macro_script.append("geo.save(filename)")
                    macro_script.append("# ...")

            # Destroy the dialog
            dialog.Destroy()
        if ID == self.EDT_ID:
            from Editor import Editor
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            edt = Editor(wk.parent, -1, 'Editor')
            filename = edt.DoOpenGeometryAsFile(geo)
            # wait until the editor is closed
            createNewGeo = False
            while edt:
                if edt.modify:
                    createNewGeo = True
                wx.MilliSleep(10)
                wx.GetApp().Yield()
            if createNewGeo:
                newgeo = cad_geometry(filename)
                geo_new = geometry(newgeo)
                geo_newItem = wk.add_geometry(geo_new)
            try:
                os.remove(filename)
            except:
                pass
        if ID == self.TRS_ID:
            self.parent.objectActionsTranslate.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsTranslate)
        if ID == self.ROT_ID:
            self.parent.objectActionsRotate.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsRotate)
        if ID == self.SCL_ID:
            self.parent.objectActionsScale.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsScale)
        if ID == self.REF_ID:
            self.parent.ShowAction(self.parent.geometryActionsRefine)
        if ID == self.PEX_ID:
            self.parent.objectActionsPolarExtrude.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsPolarExtrude)
        if ID == self.EXD_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            geoItem = wk.inspector.currentGeometryItem
            list_geo = geo.expand()
            for _geo in list_geo:
                geo_new = geometry(_geo)
                geo_newItem = wk.add_geometry(geo_new)
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... expand geometry")
                geo_id = wk.list_geo.index(geo)
                macro_script.append("geo_id = "+str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("list_geo = geo.expand()")
                macro_script.append("for _geo in list_geo:")
                macro_script.append("\twk.add_geometry(geometry(_geo))")
                macro_script.append("# ...")

        if ID == self.IMP_ID:
            # Create an open file dialog
            dialog = wx.FileDialog(None, style = wx.OPEN)
            # Show the dialog and get user input
            if dialog.ShowModal() == wx.ID_OK:
                filename = dialog.GetPath()
                # TODO update recent files
#                self.UpdateRecentFiles(filename)
                geo = cad_geometry(filename)
                wk = self.parent.WorkGroup
                wk.add_geometry(geometry(geo))
                # macro recording
                if wk.macroRecording:
                    macro_script = wk.macro_script
                    macro_script.new_line()
                    macro_script.append("# ... import geometry")
                    macro_script.append("filename = \""+filename+"\"")
                    macro_script.append("_geo = cad_geometry(filename)")
                    macro_script.append("wk.add_geometry(geometry(_geo))")
                    macro_script.append("# ...")
            # Destroy the dialog
            dialog.Destroy()
        if ID == self.REI_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            geoItem = wk.inspector.currentGeometryItem
            geo.initialize_info()
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... initialize info geometry")
                geo_id = wk.list_geo.index(geo)
                macro_script.append("geo_id = "+str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("geo.initialize_info()")
                macro_script.append("wk.Refresh(inspector=True)")
                macro_script.append("# ...")
            wk.Refresh(inspector=True)
        if ID == self.UPI_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            geoItem = wk.inspector.currentGeometryItem
            geo.update()
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... update geometry")
                geo_id = wk.list_geo.index(geo)
                macro_script.append("geo_id = "+str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("geo.update()")
                macro_script.append("wk.Refresh(inspector=True)")
                macro_script.append("# ...")
            wk.Refresh(inspector=True)
        if ID == self.T5P_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            item = wk.inspector.tree.GetSelection()
            geo_bnd = wk.inspector.tree.GetPyData(item)
            face = geo_bnd.face
            faceItem = wk.inspector.tree.GetItemParent(item)
            patchItem = wk.inspector.tree.GetItemParent(faceItem)
            geoItem = wk.inspector.tree.GetItemParent(patchItem)
            geo = wk.inspector.tree.GetPyData(geoItem)
            _geo = cad_geometry()
            _geo.append(geo[0])
            geo_new = geometry(_geo.to5patchs(face))
            geo_newItem = wk.add_geometry(geo_new)
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... to-5-patchs geometry")
                geo_id = wk.list_geo.index(geo)
                macro_script.append("geo_id = "+str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("_geo = cad_geometry()")
                macro_script.append("_geo.append(geo[0])")
                macro_script.append("face = "+str(face))
                macro_script.append("_geo = _geo.to5patchs(face)")
                macro_script.append("wk.add_geometry(geometry(_geo))")
                macro_script.append("wk.Refresh()")
                macro_script.append("# ...")
            wk.Refresh()
Ejemplo n.º 34
0
nx = int(sys.argv[1])
ny = int(sys.argv[2])

px = int(sys.argv[3])
py = int(sys.argv[4])

mx = int(sys.argv[5])
my = int(sys.argv[6])

file_in = sys.argv[7]
file_out = sys.argv[8]

if (mx > px) or (my > py):
    raise ("the multiplicity must be less than the final degree")

geo = cg.cad_geometry(file_in)

for i in range(0, geo.npatchs):
    list_p = geo[i].degree
    geo.refine(id=i, list_p=[px - list_p[0], py - list_p[1]])
    ux = np.linspace(0., 1., nx + 2)[1:-1]
    uy = np.linspace(0., 1., ny + 2)[1:-1]
    tx = []
    for x in ux:
        for j in range(0, mx):
            tx.append(x)
    ty = []
    for y in uy:
        for j in range(0, my):
            ty.append(y)
Ejemplo n.º 35
0
    def OnClick(self, event):
        ID = event.GetId()
        if ID == self.BCK_ID:
            self.parent.ShowAction(self.parent.geometryActions)
        if ID == self.GO_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            geoItem = wk.inspector.currentGeometryItem
            _geo = cad_geometry()
            for nrb in geo:
                geo_t = cad_geometry()
                geo_t.append(nrb)

                # ... refinement
                list_t = None
                if self.n.sum() > 0:
                    list_t = []
                    for axis in range(0,nrb.dim):
                        ub = nrb.knots[axis][0]
                        ue = nrb.knots[axis][-1]
                        t = []
                        if self.n[axis] > 0:
                            t = np.linspace(ub,ue,self.n[axis]+2)[1:-1]
                        list_t.append(t)

                list_p = None
                if self.p.sum() > 0:
                    list_p = []
                    for axis in range(0,nrb.dim):
                        list_p.append(np.max(self.p[axis] - nrb.degree[axis], 0))

                list_m = None
                if self.m.sum() > 0:
                    list_m = []
                    for axis in range(0,nrb.dim):
                        list_m.append(self.m[axis])

                geo_t.refine(list_t=list_t, list_p=list_p, list_m=list_m)
                _geo.append(geo_t[0])

                # macro recording
                if wk.macroRecording:
                    macro_script = wk.macro_script
                    macro_script.new_line()
                    macro_script.append("# ... refine geometry")
                    macro_script.append("_geo = cad_geometry()")

                    geo_id = wk.list_geo.index(geo)
                    macro_script.append("geo_id = "+str(geo_id))
                    macro_script.append("geo = geometries[geo_id]")
                    macro_script.append("for nrb in geo:")
                    macro_script.append("\tgeo_t = cad_geometry()")
                    macro_script.append("\tgeo_t.append(nrb)")

                    str_list_t = [list(ts) for ts in list_t]
                    macro_script.append("\tlist_t = "+ str(str_list_t))
                    macro_script.append("\tlist_p = "+ str(list_p))
                    macro_script.append("\tlist_m = "+ str(list_m))
                    macro_script.append("\tgeo_t.refine(list_t=list_t, list_p=list_p, list_m=list_m)")
                    macro_script.append("\t_geo.append(geo_t[0])")
                    macro_script.append("wk.add_geometry(geometry(_geo))")
                    macro_script.append("# ...")
            # ...

            _geo.set_internal_faces(geo.internal_faces)
            _geo.set_external_faces(geo.external_faces)
            _geo.set_connectivity(geo.connectivity)

            geo_new = geometry(_geo)
            geo_newItem = wk.add_geometry(geo_new)
Ejemplo n.º 36
0
    def __init__(self, nrb, check=False, verbose=False):

        self._matrices = []
        self._lmatrices = []
        self._nrb  = nrb
        self._nrb_ref = None

        from caid.cad_geometry import cad_geometry
        # ...
        spl = splineRefMat(1)
        geo = cad_geometry()
        geo.append(nrb)

        if verbose:
            print("== shape before ", nrb.shape)
            print(nrb.knots)

        list_t = []
        for axis in range(0, nrb.dim):
            brk, mult = nrb.breaks(axis=axis, mults=True)
#            print ">> axis ", axis
#            print brk
#            print mult
            nbrk = len(mult)
            mult = np.asarray(mult)
            times = nrb.degree[axis] * np.ones(nbrk, dtype=np.int) - mult
#            print ">> spans ", nrb.spans(axis=axis)

            list_r = []
            for t,k in zip(brk, times):
                for i in range(0, k):
                    list_r.append(t)
            list_t.append(list_r)

            knots   = nrb.knots[axis]
            n       = nrb.shape[axis]
            p       = nrb.degree[axis]
            P       = nrb.points
            dim     = P.shape[1]
#            print "%%%%%%%%%%%%"
#            print list_r
#            print p
#            print n
#            print knots
#            print "%%%%%%%%%%%%"

            M = spl.construct(list_r, p, n, knots)

            # ...
            if check:
                if nrb.dim == 1:
                    if verbose:
                        print("matrix shape ", M.shape)
                    R = M.dot(nrb.points[:,0])

#                    geo.refine(id=0, list_t=[list_r])
                    nrb     = geo[0]
                    if verbose:
                        print("== shape after ", nrb.shape)
                        print(nrb.knots)

                    P = np.asarray(nrb.points[:,0])
                    assert(np.allclose(P,R))
                    if verbose:
                        print("check: OK")
            # ...

            self._matrices.append(M)

        geo.refine(id=0, list_t=list_t)
        self._nrb_ref = geo[0]
Ejemplo n.º 37
0
# -*- coding: UTF-8 -*-
#! /usr/bin/python

import numpy as np
from matplotlib import pyplot as plt
from caid.io import geopdes
from caid.cad_geometry import cad_geometry

geo = cad_geometry()

filename = "/home/macahr/Téléchargements/geopdes_geometries/geo_Lshaped_mp.txt"
#filename = "geo_Lshaped_mp_b.txt"

IO = geopdes()
IO.read(filename, geo)

fig = plt.figure()
geo.plotMesh()
plt.xlim(-1.1, 1.1)
plt.ylim(-1.1, 1.1)
plt.show()
#geo.save(filename.split(".")[0]+".xml")

#nml_io.write('domain_selalib.nml',geo)
Ejemplo n.º 38
0
# ...
# ...
kx = 2. * pi
ky = 2. * pi
# ... exact solution
u = lambda x,y : [sin ( kx * x ) * sin ( ky * y )]
# ... rhs
f = lambda x,y : [( kx**2 + ky**2 ) * sin ( kx * x ) * sin ( ky * y )]
AllDirichlet = True
nx=15; ny = 15; px = 2; py = 2
geo = domain(n=[nx,ny],p=[px,py])
PDE = poisson(geometry=geo, AllDirichlet=AllDirichlet)
PDE.assembly(f=f)
PDE.solve()
# ...
# ...
normU = PDE.norm(exact=u)
print(("norm U   = ", normU))
U = PDE.unknown
u = U.tomatrix(0)
from caid.cad_geometry import cad_nurbs
nrb = geo[0]
C = np.zeros_like(nrb.points)
C[...,0]=u
nrb_f = cad_nurbs(nrb.knots, C, weights=nrb.weights)
from caid.cad_geometry import cad_geometry
geo_f = cad_geometry()
geo_f.append(nrb_f)
geo_f.save("u.xml")
geo.save("geo.xml")
Ejemplo n.º 39
0
    # ...
    u = lambda x,y : sin ( kx * x ) * sin ( ky * y )
    testcase['u'] = u
    # ...

    # ...
    # rhs
    # ...
    f = lambda x,y : ( kx**2 + ky**2 ) * sin ( kx * x ) * sin ( ky * y )
    testcase['f'] = f
    # ...

    # ...
    points = np.asarray([[[0.,0.],[0.,1.]],[[1.,0.],[1.,1.]]])
    nrb = bilinear(points)
    geo = cg.cad_geometry(geo=nrb)
    geo.refine(id=0,list_p=[2, 2])
    tx = np.linspace(0.,1.,7)[1:-1]
    ty = np.linspace(0.,1.,7)[1:-1]
    geo.refine(id=0, list_t=[tx, ty])
    # ...

    PDE = EllipticPDE(geometry=geo, testcase=testcase)

    PDE.assembly()

    # ...
    sl = spsolve(matrix=PDE.S_V)
    print(sl)

    size = PDE.V.size
Ejemplo n.º 40
0
    def OnClick(self, event):
        ID = event.GetId()
        if ID == self.BCK_ID:
            self.parent.ShowAction(self.parent.geometryActions)
        if ID == self.GO_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            geoItem = wk.inspector.currentGeometryItem
            _geo = cad_geometry()
            for nrb in geo:
                geo_t = cad_geometry()
                geo_t.append(nrb)

                # ... refinement
                list_t = None
                if self.n.sum() > 0:
                    list_t = []
                    for axis in range(0, nrb.dim):
                        ub = nrb.knots[axis][0]
                        ue = nrb.knots[axis][-1]
                        t = []
                        if self.n[axis] > 0:
                            t = np.linspace(ub, ue, self.n[axis] + 2)[1:-1]
                        list_t.append(t)

                list_p = None
                if self.p.sum() > 0:
                    list_p = []
                    for axis in range(0, nrb.dim):
                        list_p.append(
                            np.max(self.p[axis] - nrb.degree[axis], 0))

                list_m = None
                if self.m.sum() > 0:
                    list_m = []
                    for axis in range(0, nrb.dim):
                        list_m.append(self.m[axis])

                geo_t.refine(list_t=list_t, list_p=list_p, list_m=list_m)
                _geo.append(geo_t[0])

                # macro recording
                if wk.macroRecording:
                    macro_script = wk.macro_script
                    macro_script.new_line()
                    macro_script.append("# ... refine geometry")
                    macro_script.append("_geo = cad_geometry()")

                    geo_id = wk.list_geo.index(geo)
                    macro_script.append("geo_id = " + str(geo_id))
                    macro_script.append("geo = geometries[geo_id]")
                    macro_script.append("for nrb in geo:")
                    macro_script.append("\tgeo_t = cad_geometry()")
                    macro_script.append("\tgeo_t.append(nrb)")

                    str_list_t = [list(ts) for ts in list_t]
                    macro_script.append("\tlist_t = " + str(str_list_t))
                    macro_script.append("\tlist_p = " + str(list_p))
                    macro_script.append("\tlist_m = " + str(list_m))
                    macro_script.append(
                        "\tgeo_t.refine(list_t=list_t, list_p=list_p, list_m=list_m)"
                    )
                    macro_script.append("\t_geo.append(geo_t[0])")
                    macro_script.append("wk.add_geometry(geometry(_geo))")
                    macro_script.append("# ...")
            # ...

            _geo.set_internal_faces(geo.internal_faces)
            _geo.set_external_faces(geo.external_faces)
            _geo.set_connectivity(geo.connectivity)

            geo_new = geometry(_geo)
            geo_newItem = wk.add_geometry(geo_new)
Ejemplo n.º 41
0
    def OnClick(self, event):
        ID = event.GetId()
        if ID == self.NEW_ID:
            self.parent.ShowAction(self.parent.geometryActionsNew)
        if ID == self.ADD_ID:
            self.parent.ShowAction(self.parent.geometryActionsAdd)
        if ID == self.DEL_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            geoItem = wk.inspector.currentGeometryItem
            geo_id = wk.list_geo.index(geo)
            wk.remove_geometry(geoItem, geo)

            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... delete geometry")
                macro_script.append("geo_id = " + str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("geoItem = geo.treeItem")
                macro_script.append("wk.remove_geometry(geoItem, geo)")
                macro_script.append("# ...")

        if ID == self.DUP_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup

            geo = wk.inspector.currentGeometry
            geo_new = wk.inspector.currentGeometry.copy()
            geo_newItem = wk.add_geometry(geo_new)
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... copy geometry")
                geo_id = wk.list_geo.index(geo)
                macro_script.append("geo_id = " + str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("_geo = geo.copy()")
                macro_script.append("wk.add_geometry(geometry(_geo))")
                macro_script.append("# ...")

        if ID == self.PLJ_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            import matplotlib.pyplot as plt
            try:
                MeshResolution = geo.list_patchInfo[0].steps[0]
            except:
                MeshResolution = 10
            geo.plotJacobians(MeshResolution=MeshResolution)
            plt.colorbar()
            plt.show()
        if ID == self.PLM_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            import matplotlib.pyplot as plt
            MeshResolution = geo.list_patchInfo[0].steps[0]
            geo.plotMesh(MeshResolution=MeshResolution)
            plt.show()
        if ID == self.EXP_ID:
            from global_vars import CAIDwildcard
            # Create a save file dialog
            dialog = wx.FileDialog(None,
                                   style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
                                   wildcard=CAIDwildcard)
            # Show the dialog and get user input
            if dialog.ShowModal() == wx.ID_OK:
                ls_file = dialog.GetPath()
                wk = self.parent.WorkGroup
                geo = wk.inspector.currentGeometry
                geo.save(ls_file)

                # macro recording
                if wk.macroRecording:
                    macro_script = wk.macro_script
                    macro_script.new_line()
                    macro_script.append("# ... export geometry")
                    geo_id = wk.list_geo.index(geo)
                    macro_script.append("geo_id = " + str(geo_id))
                    macro_script.append("geo = geometries[geo_id]")
                    macro_script.append("filename = \"" + ls_file + "\"")
                    macro_script.append("geo.save(filename)")
                    macro_script.append("# ...")

            # Destroy the dialog
            dialog.Destroy()
        if ID == self.EDT_ID:
            from Editor import Editor
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            edt = Editor(wk.parent, -1, 'Editor')
            filename = edt.DoOpenGeometryAsFile(geo)
            # wait until the editor is closed
            createNewGeo = False
            while edt:
                if edt.modify:
                    createNewGeo = True
                wx.MilliSleep(10)
                wx.GetApp().Yield()
            if createNewGeo:
                newgeo = cad_geometry(filename)
                geo_new = geometry(newgeo)
                geo_newItem = wk.add_geometry(geo_new)
            try:
                os.remove(filename)
            except:
                pass
        if ID == self.TRS_ID:
            self.parent.objectActionsTranslate.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsTranslate)
        if ID == self.ROT_ID:
            self.parent.objectActionsRotate.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsRotate)
        if ID == self.SCL_ID:
            self.parent.objectActionsScale.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsScale)
        if ID == self.REF_ID:
            self.parent.ShowAction(self.parent.geometryActionsRefine)
        if ID == self.PEX_ID:
            self.parent.objectActionsPolarExtrude.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsPolarExtrude)
        if ID == self.EXD_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            geoItem = wk.inspector.currentGeometryItem
            list_geo = geo.expand()
            for _geo in list_geo:
                geo_new = geometry(_geo)
                geo_newItem = wk.add_geometry(geo_new)
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... expand geometry")
                geo_id = wk.list_geo.index(geo)
                macro_script.append("geo_id = " + str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("list_geo = geo.expand()")
                macro_script.append("for _geo in list_geo:")
                macro_script.append("\twk.add_geometry(geometry(_geo))")
                macro_script.append("# ...")

        if ID == self.IMP_ID:
            # Create an open file dialog
            dialog = wx.FileDialog(None, style=wx.FD_OPEN)
            # Show the dialog and get user input
            if dialog.ShowModal() == wx.ID_OK:
                filename = dialog.GetPath()
                # TODO update recent files
                #                self.UpdateRecentFiles(filename)
                geo = cad_geometry(filename)
                wk = self.parent.WorkGroup
                wk.add_geometry(geometry(geo))
                # macro recording
                if wk.macroRecording:
                    macro_script = wk.macro_script
                    macro_script.new_line()
                    macro_script.append("# ... import geometry")
                    macro_script.append("filename = \"" + filename + "\"")
                    macro_script.append("_geo = cad_geometry(filename)")
                    macro_script.append("wk.add_geometry(geometry(_geo))")
                    macro_script.append("# ...")
            # Destroy the dialog
            dialog.Destroy()
        if ID == self.REI_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            geoItem = wk.inspector.currentGeometryItem
            geo.initialize_info()
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... initialize info geometry")
                geo_id = wk.list_geo.index(geo)
                macro_script.append("geo_id = " + str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("geo.initialize_info()")
                macro_script.append("wk.Refresh(inspector=True)")
                macro_script.append("# ...")
            wk.Refresh(inspector=True)
        if ID == self.UPI_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            geo = wk.inspector.currentGeometry
            geoItem = wk.inspector.currentGeometryItem
            geo.update()
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... update geometry")
                geo_id = wk.list_geo.index(geo)
                macro_script.append("geo_id = " + str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("geo.update()")
                macro_script.append("wk.Refresh(inspector=True)")
                macro_script.append("# ...")
            wk.Refresh(inspector=True)
        if ID == self.T5P_ID:
            # inspector = self.parent
            wk = self.parent.WorkGroup
            item = wk.inspector.tree.GetSelection()
            geo_bnd = wk.inspector.tree.GetItemData(item)
            face = geo_bnd.face
            faceItem = wk.inspector.tree.GetItemParent(item)
            patchItem = wk.inspector.tree.GetItemParent(faceItem)
            geoItem = wk.inspector.tree.GetItemParent(patchItem)
            geo = wk.inspector.tree.GetItemData(geoItem)
            _geo = cad_geometry()
            _geo.append(geo[0])
            geo_new = geometry(_geo.to5patchs(face))
            geo_newItem = wk.add_geometry(geo_new)
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... to-5-patchs geometry")
                geo_id = wk.list_geo.index(geo)
                macro_script.append("geo_id = " + str(geo_id))
                macro_script.append("geo = geometries[geo_id]")
                macro_script.append("_geo = cad_geometry()")
                macro_script.append("_geo.append(geo[0])")
                macro_script.append("face = " + str(face))
                macro_script.append("_geo = _geo.to5patchs(face)")
                macro_script.append("wk.add_geometry(geometry(_geo))")
                macro_script.append("wk.Refresh()")
                macro_script.append("# ...")
            wk.Refresh()
Ejemplo n.º 42
0
    def OnClick(self, event):
        # inspector = self.parent
        wk = self.parent.WorkGroup

        ID = event.GetId()
        if ID == self.BCK_ID:
            self.parent.ShowAction(self.parent.geometryActions)
        if ID == self.EMP_ID:
            geo = cad_geometry()
            wk.add_geometry(geometry(geo))
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... create object")
                macro_script.append("_geo = cad_geometry()")
                macro_script.append("wk.add_geometry(geometry(_geo))")
                macro_script.append("# ...")
        if ID == self.LIN_ID:
            from caid.cad_geometry import line as domain
            geo = domain()
            wk.add_geometry(geometry(geo))
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... create object")
                macro_script.append("_geo = line()")
                macro_script.append("wk.add_geometry(geometry(_geo))")
                macro_script.append("# ...")
        if ID == self.LNR_ID:
            self.parent.objectActionsCreateLinear.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateLinear)
        if ID == self.ARC_ID:
            self.parent.objectActionsCreateArc.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateArc)
        if ID == self.CRV_ID:
            self.parent.objectActionsCurve.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCurve)
        if ID == self.SQR_ID:
            from caid.cad_geometry import square as domain
            geo = domain()
            wk.add_geometry(geometry(geo))
            # macro recording
            if wk.macroRecording:
                macro_script = wk.macro_script
                macro_script.new_line()
                macro_script.append("# ... create object")
                macro_script.append("_geo = square()")
                macro_script.append("wk.add_geometry(geometry(_geo))")
                macro_script.append("# ...")
        if ID == self.BIL_ID:
            self.parent.objectActionsCreateBilinear.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateBilinear)
        if ID == self.CRC_ID:
            self.parent.objectActionsCreateCircle.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateCircle)
        if ID == self.QCR_ID:
            self.parent.objectActionsCreateQuartCircle.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateQuartCircle)
        if ID == self.ANL_ID:
            self.parent.objectActionsCreateAnnulus.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateAnnulus)
        if ID == self.CR5_ID:
            self.parent.objectActionsCreateCircle_5mp.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateCircle_5mp)
        if ID == self.PC5_ID:
            self.parent.objectActionsCreatePinched_Circle_5mp.asGeometry()
            self.parent.ShowAction(
                self.parent.objectActionsCreatePinched_Circle_5mp)
        if ID == self.TRL_ID:
            self.parent.objectActionsCreateTriangle.asGeometry()
            self.parent.ShowAction(self.parent.objectActionsCreateTriangle)
        if ID == self.CUB_ID:
            #            from caid.cad_geometry import cube as domain
            from caid.cad_geometry import trilinear as domain
            geo = domain()
            wk.add_geometry(geometry(geo))
Ejemplo n.º 43
0
    nx = 2 * nx + 1
for i in range(0, nstagey):
    ny = 2 * ny + 1

geo = domain(n=[nx_in, ny_in], p=[px_in, py_in])
nrb = geo[0]

C = np.zeros_like(nrb.points)
# import the solution
_C = np.genfromtxt("u.txt")
shape = list(nrb.shape)
C = np.zeros(shape + [3])
C[..., 0] = _C
srf = cad_nurbs(nrb.knots, C, weights=nrb.weights)

geo_f = cad_geometry()
geo_f.append(srf)

geo_tmp = domain(n=[nx, ny], p=[px, py])
tx = [t for t in geo_tmp[0].knots[0] if t not in geo[0].knots[0]]
ty = [t for t in geo_tmp[0].knots[1] if t not in geo[0].knots[1]]

geo_f.refine(list_t=[tx, ty], list_p=[px - px_in, py - py_in])
u = geo_f[0].points[..., 0]
import pylab as pl
pl.contourf(u)
pl.colorbar()
pl.show()
print(u.shape)
np.savetxt("u_ini.txt", u)
Ejemplo n.º 44
0
# -*- coding: UTF-8 -*-
import sys
import numpy as np
import caid.cad_geometry as cg

# ...
try:
    ls_file_in = sys.argv[1]
except:
    print("You must specify a domain description file.")
    sys.exit(0)
# ...

# ...
geo = cg.cad_geometry(ls_file_in)
dim = geo.dim
# ...

# ...
if dim == 1:
    try:
        nin = [int(sys.argv[2])]
        pin = [int(sys.argv[3])]
    except:
        print("Incompatible data. The script will stop!")
        sys.exit(0)

    try:
        ls_file_out = sys.argv[4]
    except:
        ls_file_out = "domain.xml"