Пример #1
0
 def get_A_GaNi(self, N, primaldual='primal'):
     """
     Returns stiffness matrix for a scheme with trapezoidal quadrature rule.
     """
     coord = Grid.get_coordinates(N, self.Y)
     A = self.evaluate(coord)
     if primaldual is 'dual':
         A = A.inv()
     return A
Пример #2
0
 def get_A_GaNi(self, N, primaldual='primal'):
     """
     Returns stiffness matrix for a scheme with trapezoidal quadrature rule.
     """
     coord = Grid.get_coordinates(N, self.Y)
     A = self.evaluate(coord)
     if primaldual is 'dual':
         A = A.inv()
     return A
Пример #3
0
    def get_A_Ga(self, Nbar, primaldual='primal', order=None, P=None):
        """ Returns stiffness matrix for scheme with exact integration."""

        if order is None and 'order' in self.conf:
            order = self.conf['order']

        if order is None:
            shape_funs = self.get_shape_functions(Nbar)
            val = np.zeros(self.conf['vals'][0].shape + shape_funs[0].shape)
            for ii in range(len(self.conf['inclusions'])):
                if primaldual is 'primal':
                    Aincl = self.conf['vals'][ii]
                elif primaldual is 'dual':
                    Aincl = np.linalg.inv(self.conf['vals'][ii])
                val += np.einsum('ij...,k...->ijk...', Aincl, shape_funs[ii])
            return Matrix(name='A_Ga', val=val, Fourier=False)

        else:
            if P is None and 'P' in self.conf:
                P = self.conf['P']
            coord = Grid.get_coordinates(P, self.Y)
            vals = self.evaluate(coord)
            dim = vals.d
            if primaldual is 'dual':
                vals = vals.inv()

            h = self.Y/P
            if order in [0, 'constant']:
                Wraw = get_weights_con(h, Nbar, self.Y)
            elif order in [1, 'bilinear']:
                Wraw = get_weights_lin(h, Nbar, self.Y)

            Aapp = np.zeros(np.hstack([dim, dim, Nbar]))
            for m in np.arange(dim):
                for n in np.arange(dim):
                    hAM0 = DFT.fftnc(vals[m, n], P)
                    if np.allclose(P, Nbar):
                        hAM = hAM0
                    elif np.all(np.greater_equal(P, Nbar)):
                        hAM = decrease(hAM0, Nbar)
                    elif np.all(np.less(P, Nbar)):
                        factor = np.ceil(np.array(Nbar, dtype=np.float64) / P)
                        hAM0per = np.tile(hAM0, 2*factor-1)
                        hAM = decrease(hAM0per, Nbar)
                    else:
                        raise ValueError()

                    pNbar = np.prod(Nbar)
                    """ if DFT is normalized in accordance with articles there
                    should be np.prod(M) instead of np.prod(Nbar)"""
                    Aapp[m, n] = np.real(pNbar*DFT.ifftnc(Wraw*hAM, Nbar))

            name = 'A_Ga_o%d_P%d' % (order, P.max())
            return Matrix(name=name, val=Aapp, Fourier=False)
Пример #4
0
 def savefig(self, fname='material.pdf', N=50*np.ones(2)):
     import pylab as pl
     pl.figure(num=None, figsize=(3,3), dpi=1000)
     coord = Grid.get_coordinates(N, self.Y)
     vals = self.evaluate(coord)[0, 0]
     pl.pcolor(coord[0], coord[1], -vals)
     pl.xlim([-self.Y[0]/2, self.Y[0]/2])
     pl.ylim([-self.Y[1]/2, self.Y[1]/2])
     pl.xlabel(r'coordinate $x_1$')
     pl.ylabel(r'coordinate $x_2$')
     pl.savefig(fname, pad_inches=0.02, bbox_inches='tight')
     pl.close()
Пример #5
0
 def savefig(self, fname='material.pdf', N=50 * np.ones(2)):
     import pylab as pl
     pl.figure(num=None, figsize=(3, 3), dpi=1000)
     coord = Grid.get_coordinates(N, self.Y)
     vals = self.evaluate(coord)[0, 0]
     pl.pcolor(coord[0], coord[1], -vals)
     pl.xlim([-self.Y[0] / 2, self.Y[0] / 2])
     pl.ylim([-self.Y[1] / 2, self.Y[1] / 2])
     pl.xlabel(r'coordinate $x_1$')
     pl.ylabel(r'coordinate $x_2$')
     pl.savefig(fname, pad_inches=0.02, bbox_inches='tight')
     pl.close()
Пример #6
0
    def get_A_Ga(self, Nbar, primaldual='primal', order=-1, P=None):
        """
        Returns stiffness matrix for scheme with exact integration.
        """
        if order == -1:
            if 'order' in self.conf:
                order = self.conf['order']
            else:
                raise ValueError('The material order is undefined!')
        elif order not in [None, 'exact', 0, 1]:
            raise ValueError('Wrong material order (%s)!' % str(order))

        if order in [None, 'exact']:
            shape_funs = self.get_shape_functions(Nbar)
            val = np.zeros(self.conf['vals'][0].shape + shape_funs[0].shape)
            for ii in range(len(self.conf['inclusions'])):
                if primaldual is 'primal':
                    Aincl = self.conf['vals'][ii]
                elif primaldual is 'dual':
                    Aincl = np.linalg.inv(self.conf['vals'][ii])
                val += np.einsum('ij...,k...->ijk...', Aincl, shape_funs[ii])
            name = 'A_Ga'

        else:
            if P is None and 'P' in self.conf:
                P = self.conf['P']
            coord = Grid.get_coordinates(P, self.Y)
            vals = self.evaluate(coord)
            dim = vals.d
            if primaldual is 'dual':
                vals = vals.inv()

            h = self.Y / P
            if order in [0, 'constant']:
                Wraw = get_weights_con(h, Nbar, self.Y)
            elif order in [1, 'bilinear']:
                Wraw = get_weights_lin(h, Nbar, self.Y)

            val = np.zeros(np.hstack([dim, dim, Nbar]))
            for m in np.arange(dim):
                for n in np.arange(dim):
                    hAM0 = DFT.fftnc(vals[m, n], P)
                    if np.allclose(P, Nbar):
                        hAM = hAM0
                    elif np.all(np.greater_equal(P, Nbar)):
                        hAM = decrease(hAM0, Nbar)
                    elif np.all(np.less(P, Nbar)):
                        factor = np.ceil(np.array(Nbar, dtype=np.float64) / P)
                        hAM0per = np.tile(hAM0, 2 * factor - 1)
                        hAM = decrease(hAM0per, Nbar)
                    else:
                        raise ValueError()

                    pNbar = np.prod(Nbar)
                    """ if DFT is normalized in accordance with articles there
                    should be np.prod(M) instead of np.prod(Nbar)"""
                    val[m, n] = np.real(pNbar * DFT.ifftnc(Wraw * hAM, Nbar))

            name = 'A_Ga_o%d_P%d' % (order, P.max())

        return Matrix(name=name, val=val, Fourier=False)
Пример #7
0
 def get_A_GaNi(self, N, primaldual='primal'):
     coord = Grid.get_coordinates(N, self.Y)
     A = self.evaluate(coord)
     if primaldual is 'dual':
         A = A.inv()
     return A