Esempio n. 1
0
    def update(self, e_or_h, part):
        for axis in list(self.axes):
            for str_f in common_exchange.str_fs_dict[axis][e_or_h]:
                f = self.mainf.get(str_f)
                sl_get = common_exchange.slice_dict[axis][e_or_h]['get']
                sl_set = common_exchange.slice_dict[axis][e_or_h]['set']
                sl_part = common_buffer.slice_dict[e_or_h][part]

                sl_src = common.overlap_two_slices(self.mainf.ns, sl_get, sl_part)
                sl_dest = common.overlap_two_slices(self.mainf.ns, sl_set, sl_part)
                f[sl_dest] = f[sl_src]
Esempio n. 2
0
    def __init__(self, fields, str_f, pt0, pt1, tfunc, spatial_value=1., is_overwrite=False):
        """
        """
        
        common.check_type('fields', fields, Fields)
        common.check_value('str_f', str_f, ('ex', 'ey', 'ez', 'hx', 'hy', 'hz'))
        common.check_type('pt0', pt0, (list, tuple), (int, float))
        common.check_type('pt1', pt1, (list, tuple), (int, float))
        common.check_type('tfunc', tfunc, types.FunctionType)
        common.check_type('spatial_value', spatial_value, \
                (np.ndarray, np.number, types.FloatType, types.IntType) )
        common.check_type('is_overwrite', is_overwrite, bool)

        pt0 = list( common.convert_indices(fields.ns, pt0) )
        pt1 = list( common.convert_indices(fields.ns, pt1) )

        # local variables
        e_or_h = str_f[0]
        dtype = fields.dtype
        is_buffer = True if isinstance(fields, BufferFields) else False
        is_array = True if isinstance(spatial_value, np.ndarray) else False

        for axis, n, p0, p1 in zip(['x', 'y', 'z'], fields.ns, pt0, pt1):
            common.check_value('pt0 %s' % axis, p0, range(n))
            common.check_value('pt1 %s' % axis, p1, range(n))

        if is_array:
            shape = common.shape_two_points(pt0, pt1)
            assert shape == spatial_value.shape, \
                    'shape mismatch : %s, %s' % (shape, spatial_value.shape)
            assert dtype == spatial_value.dtype, \
                    'dtype mismatch : %s, %s' % (dtype, spatial_value.dtype)
        else:
            spatial_value = dtype(spatial_value)

        # create the SetFields instances
        is_update_dict = {}
        setf_dict = {}
        svalue_dict = {}

        if is_buffer:
            for part in ['', 'pre', 'post']:
                sl0 = common.slices_two_points(pt0, pt1)
                sl1 = common_buffer.slice_dict[e_or_h][part]
                overlap = common.overlap_two_slices(fields.ns, sl0, sl1)

                if overlap == None:
                    setf_dict[part] = None
                else:
                    opt0, opt1 = common.two_points_slices(fields.ns, overlap)
                    setf_dict[part] = SetFields(fields, str_f, opt0, opt1, is_array, is_overwrite)
                    svalue_dict[part] = self.overlap_svalue(pt0, pt1, opt0, opt1, spatial_value, is_array)

        else:
            setf_dict[''] = SetFields(fields, str_f, pt0, pt1, is_array, is_overwrite)
            svalue_dict[''] = spatial_value

        # global variables
        self.mainf = fields
        self.tfunc = tfunc
        self.setf_dict = setf_dict
        self.svalue_dict = svalue_dict

        self.e_or_h = e_or_h
        self.tstep = 1

        # append to the update list
        self.priority_type = 'incident'
        fields.append_instance(self)
Esempio n. 3
0
    def __init__(self,
                 fields,
                 str_f,
                 pt0,
                 pt1,
                 tfunc,
                 spatial_value=1.,
                 is_overwrite=False):
        """
        """

        common.check_type('fields', fields, (Fields, BufferFields))
        common.check_value('str_f', str_f,
                           ('ex', 'ey', 'ez', 'hx', 'hy', 'hz'))
        common.check_type('pt0', pt0, (list, tuple), int)
        common.check_type('pt1', pt1, (list, tuple), int)
        common.check_type('tfunc', tfunc, types.FunctionType)
        common.check_type('spatial_value', spatial_value, \
                (np.ndarray, np.number, types.FloatType, types.IntType) )
        common.check_type('is_overwrite', is_overwrite, bool)

        # local variables
        e_or_h = str_f[0]
        dtype = fields.dtype
        is_buffer = True if isinstance(fields, BufferFields) else False
        is_array = True if isinstance(spatial_value, np.ndarray) else False

        for axis, n, p0, p1 in zip(['x', 'y', 'z'], fields.ns, pt0, pt1):
            common.check_value('pt0 %s' % axis, p0, range(n))
            common.check_value('pt1 %s' % axis, p1, range(n))

        if is_array:
            shape = common.shape_two_points(pt0, pt1)
            assert shape == spatial_value.shape, \
                    'shape mismatch : %s, %s' % (shape, spatial_value.shape)
            assert dtype == spatial_value.dtype, \
                    'dtype mismatch : %s, %s' % (dtype, spatial_value.dtype)
        else:
            spatial_value = dtype(spatial_value)

        # create the SetFields instances
        is_update_dict = {}
        setf_dict = {}
        svalue_dict = {}

        if is_buffer:
            for part in ['', 'pre', 'post']:
                sl0 = common.slices_two_points(pt0, pt1)
                sl1 = common_buffer.slice_dict[e_or_h][part]
                overlap = common.overlap_two_slices(fields.ns, sl0, sl1)

                if overlap == None:
                    setf_dict[part] = None
                else:
                    opt0, opt1 = common.two_points_slices(fields.ns, overlap)
                    setf_dict[part] = SetFields(fields, str_f, opt0, opt1,
                                                is_array, is_overwrite)
                    svalue_dict[part] = self.overlap_svalue(
                        pt0, pt1, opt0, opt1, spatial_value, is_array)

        else:
            setf_dict[''] = SetFields(fields, str_f, pt0, pt1, is_array,
                                      is_overwrite)
            svalue_dict[''] = spatial_value

        # global variables
        self.mainf = fields
        self.tfunc = tfunc
        self.setf_dict = setf_dict
        self.svalue_dict = svalue_dict

        self.e_or_h = e_or_h
        self.tstep = 1

        # append to the update list
        self.priority_type = 'incident'
        fields.append_instance(self)