示例#1
0
文件: poisson.py 项目: gdrealm/caid
def run(geo, AllDirichlet=True, f=None):
    with context():
        from pigasus.gallery.poisson import poisson
        import numpy as np
        import matplotlib.pyplot as plt
        PDE = poisson(geo, AllDirichlet=True)
        if f is None:
            sin = np.sin ; pi = np.pi ; kx = 2. * pi ; ky = 2. * pi
            f = lambda x,y : [( kx**2 + ky**2 ) * sin ( kx * x ) * sin ( ky * y )]
        PDE.assembly(f=f)
        PDE.solve()
        PDE.plot()
        plt.colorbar(); plt.show()
        PDE.free()
except:
    px = 2

try:
    py = int(sys.argv[4])
except:
    py = 2

geo = circle(radius=1. / sqrt(2), n=[nx, ny], p=[px, py])
#-----------------------------------

# ...
u_exact = lambda x, y: [-2.0 * log(x**2 + y**2 + 0.5)]
# ...

with context():

    PDE = poisson_picard(  geometry=geo \
                         , AllDirichlet=AllDirichlet )

    # ...
    print(">>> Solving using Picard <<<")
    # ...
    if PDE.Dirichlet:
        U = PDE.unknown_dirichlet
    else:
        U = PDE.unknown
    # ...

    from pigasus.fem.utils import function
示例#3
0
def run(patch, method, nx, px, alpha, nsteps, ub=None, ue=None):
    with context():
        import numpy as np
        if ub is None:
            ub = patch.knots[0][0]
        if ue is None:
            ue = patch.knots[0][-1]
        u = np.linspace(ub, ue, nsteps)
        P = patch.evaluate(u)
        x = P[:, 0]
        y = P[:, 1]
        z = P[:, 2]

        #-----------------------------------
        def MakeConstraint(cond, face=None, value=None):
            if cond.lower() == "closed":
                constraint = {}
                constraint['patch_id_m'] = 0
                constraint['face_m'] = 0
                constraint['patch_id_s'] = 0
                constraint['face_s'] = 1
            if cond.lower() == "c0":
                constraint = {}
                constraint['patch_id_m'] = 0
                constraint['face_m'] = face
                constraint['type'] = "C0"
                constraint['values'] = [value]
            if cond.lower() == "c1":
                constraint = {}
                constraint['patch_id_m'] = 0
                constraint['face_m'] = face
                constraint['type'] = "C1"
                constraint['values'] = [value]
            return constraint

        #-----------------------------------

        from pigasus.fit.curfit import curfit
        from pigasus.fit.curfit import compute_uk

        #-----------------------------------
        print(("Approximation using " + method + " knots"))
        print(("n " + str(nx) + " p ", str(px)))
        #-----------------------------------

        #-----------------------------------
        # ...
        list_x = list(x)
        list_y = list(y)
        # ...

        # ...
        list_Q = list(zip(list_x, list_y))
        uk = compute_uk(list_Q, method=method)
        U1 = []
        U1 += list(uk)
        list_xk = []
        list_yk = []
        list_xk += list_x
        list_yk += list_y

        lists_uk = [U1]
        lists_xk = [list_xk]
        lists_yk = [list_yk]
        # ...
        #-----------------------------------

        #-----------------------------------
        constraints = []

        # ... C0_COND
        constraint = MakeConstraint("C0", 0, [x[0], y[0]])
        constraints.append(constraint)

        constraint = MakeConstraint("C0", 1, [x[-1], y[-1]])
        constraints.append(constraint)
        #-----------------------------------

        #-----------------------------------
        from igakit.cad_geometry import line
        geo = line(n=[nx], p=[px])
        #-----------------------------------

        #-----------------------------------
        fit = curfit(geometry=geo, constraints=constraints, alpha=alpha)
        #-----------------------------------

        #-----------------------------------
        patch_id = 0
        xk = lists_xk[patch_id]
        yk = lists_yk[patch_id]

        geo = fit.construct([xk, yk], uk=lists_uk)
        #-----------------------------------

        fit.PDE.free()

        return geo
示例#4
0
文件: curfit.py 项目: ratnania/caid
def run(patch, method, nx, px, alpha, nsteps, ub=None, ue=None):
    with context():
        import numpy as np
        if ub is None:
            ub = patch.knots[0][0]
        if ue is None:
            ue = patch.knots[0][-1]
        u = np.linspace(ub,ue,nsteps)
        P = patch.evaluate(u)
        x = P[:,0] ; y = P[:,1] ; z = P[:,2]

        #-----------------------------------
        def MakeConstraint(cond, face=None, value=None):
            if cond.lower() == "closed":
                constraint = {}
                constraint['patch_id_m'] = 0
                constraint['face_m']     = 0
                constraint['patch_id_s'] = 0
                constraint['face_s']     = 1
            if cond.lower() == "c0":
                constraint = {}
                constraint['patch_id_m'] = 0
                constraint['face_m']     = face
                constraint['type']       = "C0"
                constraint['values']     = [value]
            if cond.lower() == "c1":
                constraint = {}
                constraint['patch_id_m'] = 0
                constraint['face_m']     = face
                constraint['type']       = "C1"
                constraint['values']     = [value]
            return constraint
        #-----------------------------------

        from pigasus.fit.curfit import curfit
        from pigasus.fit.curfit import compute_uk

        #-----------------------------------
        print(("Approximation using " + method + " knots"))
        print(("n " + str(nx) + " p ", str(px)))
        #-----------------------------------

        #-----------------------------------
        # ...
        list_x = list(x) ; list_y = list(y)
        # ...

        # ...
        list_Q = list(zip(list_x, list_y))
        uk = compute_uk(list_Q, method=method)
        U1       = []
        U1      += list(uk)
        list_xk  = []     ; list_yk  = []
        list_xk += list_x ; list_yk += list_y

        lists_uk = [U1]
        lists_xk = [list_xk]
        lists_yk = [list_yk]
        # ...
        #-----------------------------------

        #-----------------------------------
        constraints = []

        # ... C0_COND
        constraint = MakeConstraint("C0", 0, [x[0], y[0]])
        constraints.append(constraint)

        constraint = MakeConstraint("C0", 1, [x[-1], y[-1]])
        constraints.append(constraint)
        #-----------------------------------

        #-----------------------------------
        from igakit.cad_geometry import line
        geo = line(n=[nx], p=[px])
        #-----------------------------------

        #-----------------------------------
        fit = curfit(geometry=geo, constraints=constraints, alpha=alpha)
        #-----------------------------------

        #-----------------------------------
        patch_id = 0
        xk = lists_xk[patch_id]
        yk = lists_yk[patch_id]

        geo = fit.construct([xk, yk], uk=lists_uk)
        #-----------------------------------

        fit.PDE.free()

        return geo