Beispiel #1
0
    def __subdomain_finalize__(self, dimensions, shape):
        # Create the SubDomain's SubDimensions
        sub_dimensions = []
        for k, v in self.define(dimensions).items():
            if isinstance(v, Dimension):
                sub_dimensions.append(v)
            else:
                try:
                    # Case ('middle', int, int)
                    side, thickness_left, thickness_right = v
                    if side != 'middle':
                        raise ValueError("Expected side 'middle', not `%s`" %
                                         side)
                    sub_dimensions.append(
                        SubDimension.middle('%si' % k.name, k, thickness_left,
                                            thickness_right))
                except ValueError:
                    side, thickness = v
                    if side == 'left':
                        sub_dimensions.append(
                            SubDimension.left('%sleft' % k.name, k, thickness))
                    elif side == 'right':
                        sub_dimensions.append(
                            SubDimension.right('%sright' % k.name, k,
                                               thickness))
                    else:
                        raise ValueError(
                            "Expected sides 'left|right', not `%s`" % side)
        self._dimensions = tuple(sub_dimensions)

        # Compute the SubDomain shape
        self._shape = tuple(s -
                            (sum(d._thickness_map.values()) if d.is_Sub else 0)
                            for d, s in zip(self._dimensions, shape))
Beispiel #2
0
    def __subdomain_finalize__(self, dimensions, shape):
        # Create the SubDomain's SubDimensions
        sub_dimensions = []
        for k, v in self.define(dimensions).items():
            if isinstance(v, Dimension):
                sub_dimensions.append(v)
            else:
                try:
                    # Case ('middle', int, int)
                    side, thickness_left, thickness_right = v
                    if side != 'middle':
                        raise ValueError("Expected side 'middle', not `%s`" % side)
                    sub_dimensions.append(SubDimension.middle('%si' % k.name, k,
                                                              thickness_left,
                                                              thickness_right))
                except ValueError:
                    side, thickness = v
                    if side == 'left':
                        sub_dimensions.append(SubDimension.left('%sleft' % k.name, k,
                                                                thickness))
                    elif side == 'right':
                        sub_dimensions.append(SubDimension.right('%sright' % k.name, k,
                                                                 thickness))
                    else:
                        raise ValueError("Expected sides 'left|right', not `%s`" % side)
        self._dimensions = tuple(sub_dimensions)

        # Compute the SubDomain shape
        self._shape = tuple(s - (sum(d._thickness_map.values()) if d.is_Sub else 0)
                            for d, s in zip(self._dimensions, shape))
Beispiel #3
0
    def __subdomain_finalize__(self, dimensions, shape, **kwargs):
        # Create the SubDomain's SubDimensions
        sub_dimensions = []
        sdshape = []
        counter = kwargs.get('counter', 0) - 1
        for k, v, s in zip(
                self.define(dimensions).keys(),
                self.define(dimensions).values(), shape):
            if isinstance(v, Dimension):
                sub_dimensions.append(v)
                sdshape.append(s)
            else:
                try:
                    # Case ('middle', int, int)
                    side, thickness_left, thickness_right = v
                    if side != 'middle':
                        raise ValueError("Expected side 'middle', not `%s`" %
                                         side)
                    sub_dimensions.append(
                        SubDimension.middle('i%d%s' % (counter, k.name), k,
                                            thickness_left, thickness_right))
                    thickness = s - thickness_left - thickness_right
                    sdshape.append(thickness)
                except ValueError:
                    side, thickness = v
                    if side == 'left':
                        if s - thickness < 0:
                            raise ValueError(
                                "Maximum thickness of dimension %s "
                                "is %d, not %d" % (k.name, s, thickness))
                        sub_dimensions.append(
                            SubDimension.left('i%d%s' % (counter, k.name), k,
                                              thickness))
                        sdshape.append(thickness)
                    elif side == 'right':
                        if s - thickness < 0:
                            raise ValueError(
                                "Maximum thickness of dimension %s "
                                "is %d, not %d" % (k.name, s, thickness))
                        sub_dimensions.append(
                            SubDimension.right('i%d%s' % (counter, k.name), k,
                                               thickness))
                        sdshape.append(thickness)
                    else:
                        raise ValueError(
                            "Expected sides 'left|right', not `%s`" % side)
        self._dimensions = tuple(sub_dimensions)

        # Compute the SubDomain shape
        self._shape = tuple(sdshape)
Beispiel #4
0
 def __subdomain_finalize__(self, dimensions, shape, **kwargs):
     # Create the SubDomain's SubDimensions
     sub_dimensions = []
     for d in dimensions:
         sub_dimensions.append(
             SubDimension.middle('%si_%s' % (d.name, self.implicit_dimension.name),
                                 d, 0, 0))
     self._dimensions = tuple(sub_dimensions)
     # Compute the SubDomain shape
     self._shape = tuple(s - (sum(d._thickness_map.values()) if d.is_Sub else 0)
                         for d, s in zip(self._dimensions, shape))
Beispiel #5
0
 def __subdomain_finalize__(self, dimensions, shape):
     # Create the SubDomain's SubDimensions
     sub_dimensions = []
     for d in dimensions:
         sub_dimensions.append(
             SubDimension.middle('%si_%s' % (d.name, self.implicit_dimension.name),
                                 d, 0, 0))
     self._dimensions = tuple(sub_dimensions)
     # Compute the SubDomain shape
     self._shape = tuple(s - (sum(d._thickness_map.values()) if d.is_Sub else 0)
                         for d, s in zip(self._dimensions, shape))
Beispiel #6
0
    def __subdomain_finalize__(self, dimensions, shape, distributor=None, **kwargs):
        # Create the SubDomain's SubDimensions
        sub_dimensions = []
        for d in dimensions:
            sub_dimensions.append(SubDimension.middle
                                  ('%si_%s' % (d.name, self.implicit_dimension.name),
                                   d, 0, 0))
        self._dimensions = tuple(sub_dimensions)

        # Compute the SubDomainSet shapes
        global_bounds = []
        for i in self._global_bounds:
            if isinstance(i, int):
                global_bounds.append(np.full(self._n_domains, i, dtype=np.int32))
            else:
                global_bounds.append(i)
        d_m = global_bounds[0::2]
        d_M = global_bounds[1::2]
        shapes = []
        for i in range(self._n_domains):
            dshape = []
            for s, m, M in zip(shape, d_m, d_M):
                assert(m.size == M.size)
                dshape.append(s-m[i]-M[i])
            shapes.append(as_tuple(dshape))
        self._shape = as_tuple(shapes)

        if distributor and distributor.is_parallel:
            # Now create local bounds based on distributor
            processed = []
            for dim, d, m, M in zip(dimensions, distributor.decomposition, d_m, d_M):
                bounds_m = np.zeros(m.shape, dtype=m.dtype)
                bounds_M = np.zeros(m.shape, dtype=m.dtype)
                for j in range(m.size):
                    lmin = d.glb_min + m[j]
                    lmax = d.glb_max - M[j]

                    # Check if the subdomain doesn't intersect with the decomposition
                    if lmin < d.loc_abs_min and lmax < d.loc_abs_min:
                        bounds_m[j] = d.loc_abs_max
                        bounds_M[j] = d.loc_abs_max
                        continue
                    if lmin > d.loc_abs_max and lmax > d.loc_abs_max:
                        bounds_m[j] = d.loc_abs_max
                        bounds_M[j] = d.loc_abs_max
                        continue

                    if lmin < d.loc_abs_min:
                        bounds_m[j] = 0
                    elif lmin > d.loc_abs_max:
                        bounds_m[j] = d.loc_abs_max
                        bounds_M[j] = d.loc_abs_max
                        continue
                    else:
                        bounds_m[j] = d.index_glb_to_loc(m[j], LEFT)

                    if lmax < d.loc_abs_min:
                        bounds_m[j] = d.loc_abs_max
                        bounds_M[j] = d.loc_abs_max
                        continue
                    elif lmax >= d.loc_abs_max:
                        bounds_M[j] = 0
                    else:
                        bounds_M[j] = d.index_glb_to_loc(M[j], RIGHT)

                processed.append(bounds_m)
                processed.append(bounds_M)
            self._local_bounds = as_tuple(processed)
        else:
            # Not distributed and hence local and global bounds are
            # equivalent.
            self._local_bounds = self._global_bounds