コード例 #1
0
ファイル: analysissample.py プロジェクト: santiama/OOF3D
 def make_samples(self, domain):
     self.sample_list = []
     els = domain.get_elements()
     ## Setting sample_list to a MappedIterable here allows us to
     ## avoid making a list of ContinuumSamples, which may be a bad
     ## idea if the SampleSet is very large.  However, we should
     ## check to see which method is actually faster.
     self.sample_list = utils.MappedIterable(ContinuumSample, els)
     ## See the TODO in analysisdomain.py about size(). Because els
     ## may be an iterator, we don't know whether or not the domain
     ## is empty here, so we have to assume that it's not, and
     ## always return True.
     return True
コード例 #2
0
ファイル: analysissample.py プロジェクト: santiama/OOF3D
 def make_samples(self, domain):
     size = domain.ms.sizeOfPixels()
     # class PxlSmplFactory(object):
     #     def __init__(self, pxlsize):
     #         self.pxlsize = pxlsize
     #     def __call__(self, pxl):
     #         return PixelSample(pxl, self.pxlsize)
     # factory = PxlSmplFactory(size)
     # self.sample_list = utils.MappedIterable(factory, domain.get_pixels())
     pxls = domain.get_pixels()
     if pxls:
         self.sample_list = utils.MappedIterable(
             lambda x: PixelSample(x, size), domain.get_pixels())
         return True
     else:
         return False
コード例 #3
0
ファイル: output.py プロジェクト: santiama/OOF3D
    def evaluate(self, mesh, domain, elements, coords):
        # elements is a list (or other iterable container) of Elements
        # on which to evaluate the output.  coords is a list of lists
        # of MasterCoords, one list per each Element, at which to
        # evaluate the output.  The Elements may be either bulk or
        # surface elements.  Some outputs can only be evaluated on one
        # type of element, so this routine needs to convert from
        # surface to bulk if necessary (using information from the
        # domain to translate from one to the other).  It should never
        # be necessary to translate from bulk to surface.  The
        # translation is moderately expensive, so it's done before
        # calling the inputs' evaluation routines, which will reduce
        # but not eliminate redundancy.

        # Do any inputs or evaluatable parameters require bulk or
        # surface elements?
        bulk_required = self.bulk_only
        surf_required = self.surface_only
        for inpt in self.inputs.values():
            if inpt.bulk_only:
                bulk_required = True
            if inpt.surface_only:
                surf_required = True
        for param in self.params.values():
            if isinstance(param, OutputParameter):
                if param.value.bulk_only:
                    bulk_required = True
                if param.value.surface_only:
                    surf_required = True
        # What kind of elements did we get?  (Don't use elements[0] to
        # get the first element, because elements may be iterable but
        # not indexable.)
        elementdim = next(iter(elements)).dimension()

        if elementdim == 3:
            bulk_elements = elements
            bulk_coords = coords
            if surf_required:
                # We got bulk elements, but we need surface elements.  Tough.
                raise ooferror.ErrPyProgrammingError(
                    "Can't evaluate surface outputs on bulk elements!")
        else:
            # We got surface elements.
            surf_elements = elements
            surf_coords = coords
            if bulk_required:
                # Convert surface elements to bulk.
                bulk_elements = utils.MappedIterable(domain.convertToBulk,
                                                     elements)

                # Convert surface coords to bulk
                def convertCoordsToBulk(surf_elem, bulk_elem, surf_coords):
                    real_coords = map(surf_elem.from_master, surf_coords)
                    return map(bulk_elem.to_master, real_coords)

                bulk_coords = utils.MappedIterable(convertCoordsToBulk,
                                                   elements, bulk_elements,
                                                   coords)

        argdict = {}
        for inputname, inpt in self.inputs.items():
            if inpt.bulk_only:
                argdict[inputname] = inpt.evaluate(mesh, domain, bulk_elements,
                                                   bulk_coords)
            elif inpt.surface_only:
                argdict[inputname] = inpt.evaluate(mesh, domain, surf_elements,
                                                   surf_coords)
            else:
                argdict[inputname] = inpt.evaluate(mesh, domain, elements,
                                                   coords)
        for paramname, param in self.params.items():
            # Some parameters are OutputParameters, which need to be
            # evaluated before calling the callback.
            if isinstance(param, OutputParameter):
                if param.value.bulk_only:
                    argdict[paramname] = param.value.evaluate(
                        mesh, domain, bulk_elements, bulk_coords)
                elif param.value.surface_only:
                    argdict[paramname] = param.value.evaluate(
                        mesh, domain, surf_elements, surf_coords)
                else:
                    argdict[paramname] = param.value.evaluate(
                        mesh, domain, elements, coords)
            else:  # just a regular Parameter, not an OutputParameter
                argdict[paramname] = param.value

        if self.bulk_only:
            result = self.callback(mesh, bulk_elements, bulk_coords, **argdict)
        elif self.surface_only:
            result = self.callback(mesh, surf_elements, surf_coords, **argdict)
        else:
            result = self.callback(mesh, elements, coords, **argdict)
        return result