Ejemplo n.º 1
0
    nx = 31

try:
    px = int(sys.argv[2])
except:
    px = 2
#-----------------------------------

# ...
from caid.cad_geometry import line as domain
geo = domain(n=[nx], p=[px])
# ...

with context():
    # ...
    PDE = basicPDE(geometry=geo, testcase=tc)
    # ...

    # ...
    PDE.assembly()
    PDE.solve()

    # ...
    normU = PDE.norm(exact=u)
    print("norm U   = ", normU)
    # ...

    # ...
    if PDE.Dirichlet:
        U = PDE.unknown_dirichlet
    else:
Ejemplo n.º 2
0
try:
    px = int(sys.argv[3])
except:
    px = 2

try:
    py = int(sys.argv[4])
except:
    py = 2
#-----------------------------------
# ...
from igakit.cad_geometry import square as domain
geo = domain(n=[nx,ny],p=[px,px])

# ...
PDE = basicPDE(geometry=geo, testcase=tc)
# ...

# ...
PDE.assembly()
PDE.solve()
# ...

# ...
normU = PDE.norm(exact=u)
print "norm U   = ", normU
# ...

# ...
if PLOT:
    PDE.plot()  ; plt.colorbar(); plt.title('$u_h$')
Ejemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        """Creates a nonlinear poisson PDE solver based on Picard algorithm.

        geometry:
            The geometry must be an object cad_geometry.

        Returns:
           A PDE object.

        .. note::

            See also: :ref:`fem.gallery.poisson`.

        """
        try:
            geometry = kwargs['geometry']
        except:
            pass
        # ...
        dim = geometry.dim
        if dim == 1:
            func_one = lambda x: [1.]
            func_zero = lambda x: [0.]
            func_stiff = lambda x: [1.]
        if dim == 2:
            func_one = lambda x, y: [1.]
            func_zero = lambda x, y: [0.]
            func_stiff  = lambda x,y : [  1., 0. \
                                        , 0., 1. ]
        if dim == 3:
            func_one = lambda x, y, z: [1.]
            func_zero = lambda x, y, z: [0.]
            func_stiff  = lambda x,y,z : [ 1., 0., 0. \
                                         , 0., 1., 0. \
                                         , 0., 0., 1. ]
        # ...

        # ...
        tc_d = {}
        tc_d['A'] = func_stiff
        tc_d['b'] = func_zero
        try:
            tc_d['AllDirichlet'] = kwargs['AllDirichlet']
        except:
            pass
        try:
            tc_d['bc_dirichlet'] = kwargs['bc_dirichlet']
        except:
            pass
        try:
            tc_d['bc_neumann'] = kwargs['bc_neumann']
        except:
            pass
        try:
            tc_d['Metric'] = kwargs['Metric']
        except:
            pass
        # ...

        # ...
        poisson.__init__(self, *args, **kwargs)
        self.Dn = basicPDE(geometry=geometry, testcase=tc_d)
Ejemplo n.º 4
0
    def __init__(self, size, dict_testcases=None, dict_PDE=None, geometry=None, same_space=True):
        """
        a block of basicPDEs. size must a list of two integers, describing the
        number of rows and columns of the block PDEs
        """
#        pigasus.__init__(self)

        # TODO PDEs with different spaces
        if not same_space:
            print("block_basicPDE: NOT YET IMPLEMENTED when same_space=False")
        self._size          = size
        self._dict_PDE      = {}
        self._list_PDE      = []
        self._system        = None
        self._dict_system   = {}
        self._list_rhs      = []
        self._list_unknown  = []
        self._list_norm     = []
        self._dict_testcases= dict_testcases
        self._geometry      = geometry

        if dict_PDE is not None:
            self._dict_PDE  = dict_PDE

        if (dict_testcases is None) and (dict_PDE is None):
            raise ("You should specify either dict_testcases or dict_PDE")

        if (dict_testcases is not None) and (dict_PDE is not None):
            raise ("You should specify either dict_testcases or dict_PDE")

        if dict_testcases is not None:
            # ... first, we create PDEs correponsing to the testcases dictionary
            #     the result is also a dictionary of PDEs
            iteration = 0
            PDE = None
            V = None
            for keys, tc in dict_testcases.items():
                i = keys[0] ; j = keys[1]
                if (iteration == 0) or not same_space:
                    PDE = basicPDE(geometry=geometry, testcase=tc)
                    V   = PDE.V
                else:
                    PDE = basicPDE(geometry=geometry, testcase=tc, V=V)
                self._dict_PDE[i,j] = PDE
                iteration += 1
            # ...

        # ... second, we create a list of PDEs, and initialize all PDE to None
        for i in range(0,self.size[0]):
            line = []
            for j in range(0,self.size[1]):
                line.append(None)
            self._list_PDE.append(line)
        # ...

        # ... then, initialize the PDEs (double) list with the PDEs dictionary
        for keys, PDE in self._dict_PDE.items():
            i = keys[0] ; j = keys[1]
            self._list_PDE[i][j] = PDE
        # ...

        # ... create the fem reference
        for j in range(0,self.size[1]):
            self._fem = None
            # ... find a non-None PDE in the same block column as M
            for i in range(0,self.size[0]):
                PDE = self._list_PDE[i][j]
                if PDE is not None:
                    self._fem = PDE.fem
                    break
            if self._fem is not None:
                break
        # ...

        # ... create the list of rhs and unknowns
        for j in range(0,self.size[1]):
            rhs = None
            # ... find a non-None PDE in the same block column as M
            for i in range(0,self.size[0]):
                PDE = self._list_PDE[i][j]
                if PDE is not None:
                    U   = PDE.unknown
                    rhs = PDE.rhs
                    break

            self._list_rhs.append(rhs)
        # ...

        # ... create the list of unknowns and their norms
        for i in range(0,self.size[0]):
            U   = None
            N_U = None
            # ... find a non-None PDE in the same block line as M
            for j in range(0,self.size[j]):
                PDE = self._list_PDE[i][j]
                if PDE is not None:
                    U   = PDE.unknown
                    N_U = PDE.N_U
                    break

            self._list_unknown.append(U)
            self._list_norm.append(N_U)
Ejemplo n.º 5
0
#-----------------------------------

# ...
tc_1i, tc_1e = testcase_1()
tc_2i, tc_2e = testcase_2()
# ...

# ...
from caid.cad_geometry import square as domain
geo = domain(n=[nx, ny], p=[px, px])

with context():

    # ...
    PDE_1e = basicPDE(geometry=geo, testcase=tc_1e)
    PDE_1i = basicPDE(geometry=geo, testcase=tc_1i, V=PDE_1e.V)
    PDE_2e = basicPDE(geometry=geo, testcase=tc_2e, V=PDE_1e.V)
    PDE_2i = basicPDE(geometry=geo, testcase=tc_2i, V=PDE_1e.V)
    # ...

    # ...
    U_1e = get_unknwon(PDE_1e)
    U_1i = get_unknwon(PDE_1i)
    U_2e = get_unknwon(PDE_2e)
    U_2i = get_unknwon(PDE_2i)
    # ...

    # ...
    Advection_1e = PDE_1e.advection
    Advection_1e.func = create_function(U_2e)