Exemplo n.º 1
0
    def assemble_F(self, Y=None):
        if Y is None:
            Y = zeros((self._ndofs,))
        F = zeros((self._ndofs,))
        for m in self._meshes:
            for el_num, e in enumerate(m.elements):
                for i in range(len(e.dofs)):
                    i_glob = e.dofs[i]
                    if i_glob == -1:
                        continue
                    mi = self.get_mesh_number(i_glob)
                    def func1(x):
                        # x is the integration point, we need to determine
                        # the values of y1, y2, ... at this integration
                        # point.

                        v = 0.
                        for j in range(len(e.dofs)):
                            g = e.dofs[j]
                            if g == -1:
                                coeff = e.get_dirichlet_value(j)
                                #print "XX", e.dofs, j
                            else:
                                coeff = Y[g]
                            v += coeff*e.shape_function_deriv(j, x)
                        #print "deriv", el_num, x, v
                        v = v*e.shape_function(i, x)
                        return v
                    du_phi, err = quadrature(func1, -1, 1)
                    def func2(x):
                        # x is the integration point, we need to determine
                        # the values of y1, y2, ... at this integration
                        # point.

                        # XXX: this only works if all the meshes are the same:
                        y = [self.get_sol_value(_i, el_num, Y, x) for _i \
                                in range(len(self._meshes))]
                        x_phys = e.ref2phys(x)
                        return self._F(mi, y, x_phys) * e.shape_function(i, x)
                    #if el_num == 0:
                    #    print "func", func2(array([-1, -0.9, -0.5, 0, 0.5, 0.9,
                    #        1]))
                    #print "f", f(0, array([-1, -0.9, -0.5, 0, 0.5, 0.9,
                    #        1]))
                    #print "func", func2(array([-1, -0.9, -0.5, 0, 0.5, 0.9,
                    #        1]))
                    #stop

                    f_phi, err = quadrature(func2, -1., 1.)
                    f_phi *= e.jacobian
                    #print "X", i_glob, el_num, i, du_phi, f_phi
                    F[i_glob] += du_phi - f_phi
        #print Y
        #print "get_sol_value"
        #print self.get_sol_value(0, 0, Y, 1)
        return F
Exemplo n.º 2
0
 def integrate_dphi_phi(self, i, j):
     """
     Calculates the integral of dphi*phi on the reference element
     """
     def func(x):
         return self.shape_function_deriv(i, x) * self.shape_function(j, x)
     i, err = quadrature(func, -1, 1)
     return i
Exemplo n.º 3
0
    def assemble_J(self, Y):
        J = zeros((self._ndofs, self._ndofs))
        for m in self._meshes:
            for e in m.elements:
                for i in range(len(e.dofs)):
                    for j in range(len(e.dofs)):
                        i_glob = e.dofs[i]
                        j_glob = e.dofs[j]
                        if i_glob == -1 or j_glob == -1:
                            continue
                        mi = self.get_mesh_number(i_glob)
                        mj = self.get_mesh_number(j_glob)
                        def func(x):
                            # x is the integration point, we need to determine
                            # the values of y1, y2, ... at this integration
                            # point.

                            # XXX: This only works for linear problems (it
                            # doesn't matter what  those values are), but it's
                            # wrong for nonlinear ones and it needs to be
                            # fixed:
                            nmeshes = len(self._meshes)
                            W = [0]*nmeshes
                            x_phys = e.ref2phys(x)
                            f_user = self._DFDY(mi, mj, W, x_phys)
                            return f_user * \
                                        e.shape_function(i, x) * \
                                        e.shape_function(j, x)
                        dphi_phi = e.integrate_dphi_phi(j, i)
                        df_phi_phi, err = quadrature(func, -1, 1)
                        df_phi_phi *= e.jacobian
                        J[i_glob, j_glob] += dphi_phi - df_phi_phi
                        #print f(0, array([-1, -0.9, 0, 0.7, 0.9, 1]))
                        #stop
                        #print "X", i_glob, j_glob, i, dphi_phi, df_phi_phi
        return J