Exemple #1
0
    def matChanged(self, materialname):
        # The given material has changed.  Look through the materials
        # in our Microstructure to see if we care.
        matl = materialmanager.getMaterial(materialname)
        #Interface branch
        ##TODO: Should we look at the material associated with the
        ##edgements instead?
        if config.dimension() == 2 and runtimeflags.surface_mode:
            interfacemsplugin = self.microstructure.getPlugIn("Interfaces")
            interfacemats = interfacemsplugin.getInterfaceMaterials()


#         elif config.dimension() == 3:
        else:
            interfacemats = []

        if matl in material.getMaterials(self.microstructure) or \
               materialname in interfacemats:
            # We *do* care. Really.  Tell all the SubProblems
            # belonging to the microstructure that the material has
            # changed.
            msname = self.microstructure.name()
            subppaths = subproblemcontext.subproblems.keys(base=msname)
            for subppath in subppaths:
                subpctxt = subproblemcontext.subproblems[[msname] + subppath]
                subpctxt.changed("Material properties changed.")
 def Identity(self):
     global refdata
     OOF.Property.Parametrize.Orientation(
         angles=Abg(alpha=0.0, beta=0.0, gamma=0.0))
     OOF.Subproblem.Set_Solver(
         subproblem='r3bug:skeleton:mesh:default',
         solver_mode=AdvancedSolverMode(
             nonlinear_solver=NoNonlinearSolver(),
             time_stepper=StaticDriver(),
             symmetric_solver=ConjugateGradient(
                 preconditioner=ILUPreconditioner(),
                 tolerance=1e-13,
                 max_iterations=1000),
             asymmetric_solver=GeneralizedMinResidual(
                 preconditioner=ILUPreconditioner(),
                 tolerance=1e-13,
                 max_iterations=1000,krylov_dimension=100)))
     OOF.Mesh.Solve(mesh='r3bug:skeleton:mesh', endtime=0.0)
     from ooflib.engine import materialmanager
     m = materialmanager.getMaterial('material')
     p = m.fetchProperty('PiezoElectricity')
     d = p.dijk()
     for i in range(3):
         for j in range(3):
             for k in range(j,3):
                 self.assertAlmostEqual(d[i,j,k],
                                        refdata['identity'][(i,j,k)],
                                        6)
Exemple #3
0
def _assign_matl(menuitem, skeleton, group, material):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    if not groupset.isGroup(group):
        raise ooferror.ErrUserError("Group %s does not exist." % group)
    groupset.assignMaterial(group, materialmanager.getMaterial(material))
    switchboard.notify("redraw")
Exemple #4
0
 def Identity(self):
     global refdata
     OOF.Property.Parametrize.Orientation(
         angles=Abg(alpha=0.0, beta=0.0, gamma=0.0))
     OOF.Subproblem.Set_Solver(
         subproblem='r3bug:skeleton:mesh:default',
         solver_mode=AdvancedSolverMode(
             nonlinear_solver=NoNonlinearSolver(),
             time_stepper=StaticDriver(),
             symmetric_solver=ConjugateGradient(
                 preconditioner=ILUPreconditioner(),
                 tolerance=1e-13,
                 max_iterations=1000),
             asymmetric_solver=SparseLU()))
     OOF.Mesh.Solve(mesh='r3bug:skeleton:mesh', endtime=0.0)
     from ooflib.engine import materialmanager
     m = materialmanager.getMaterial('material')
     p = m.fetchProperty('PiezoElectricity')
     d = p.dijk()
     for i in range(3):
         for j in range(3):
             for k in range(j,3):
                 self.assertAlmostEqual(d[i,j,k],
                                        refdata['identity'][(i,j,k)],
                                        6)
Exemple #5
0
    def matChanged(self, materialname):
        # The given material has changed.  Look through the materials
        # in our Microstructure to see if we care.
        matl = materialmanager.getMaterial(materialname)
        #Interface branch
        if config.dimension() == 2 and runtimeflags.surface_mode:
            interfacemsplugin = self.microstructure.getPlugIn("Interfaces")
            interfacemats = interfacemsplugin.getInterfaceMaterials()


#         elif config.dimension() == 3:
        else:
            interfacemats = []

        if matl in material.getMaterials(self.microstructure) or \
               materialname in interfacemats:
            # We *do* care. Really.  Tell all the SubProblems
            # belonging to the microstructure that the material has
            # changed.
            msname = self.microstructure.name()
            subppaths = subproblemcontext.subproblems.keys(base=msname)
            for subppath in subppaths:
                subpctxt = subproblemcontext.subproblems[[msname] + subppath]
                subpctxt.changed("Material properties changed.")
            # Also tell everything that cares whether the mesh data
            # has changed.  This includes PropertyOutputs that may be
            # displayed in a mesh data viewer.
            meshpaths = mesh.meshes.keys(base=msname)
            for meshpath in meshpaths:
                meshctxt = mesh.meshes[[msname] + meshpath]
                switchboard.notify("mesh data changed", meshctxt)
Exemple #6
0
 def select(self, ms, selection):
     mobj = ms.getObject()
     if self.material == '<Any>':
         courier = pixelselectioncouriere.AnyMaterialSelection(mobj)
     elif self.material == '<None>':
         courier = pixelselectioncouriere.NoMaterialSelection(mobj)
     else:
         courier = pixelselectioncouriere.MaterialSelection(
             mobj, materialmanager.getMaterial(self.material))
     self.operator.operate(selection, courier)
Exemple #7
0
 def __call__(self, ms, selection):
     selection.start()
     if self.material == '<Any>':
         selection.select(AnyMaterialSelection(ms))
     elif self.material == '<None>':
         courier = NoMaterialSelection(ms)
         selection.select(courier)
     else:
         selection.select(MaterialSelection(
             ms, materialmanager.getMaterial(self.material)))
Exemple #8
0
 def __call__(self, ms, selection):
     selection.start()
     if self.material == '<Any>':
         selection.select(AnyMaterialSelection(ms))
     elif self.material == '<None>':
         courier = NoMaterialSelection(ms)
         selection.select(courier)
     else:
         selection.select(MaterialSelection(
             ms, materialmanager.getMaterial(self.material)))
Exemple #9
0
def _readMSMaterial(menuitem, microstructure, category, material):
    if material is not None:
        mscontext = ooflib.common.microstructure.microStructures[microstructure]
        ms = mscontext.getObject()
        mscontext.begin_writing()
        try:
            mat = materialmanager.getMaterial(material)
            pxls = microstructureIO.getCategoryPixels(microstructure, category)
            mat.assignToPixels(ms, pxls)
        finally:
            mscontext.end_writing()
Exemple #10
0
def _readMSMaterial(menuitem, microstructure, category, material):
    if material is not None:
        mscontext = ooflib.common.microstructure.microStructures[
            microstructure]
        ms = mscontext.getObject()
        mscontext.begin_writing()
        try:
            mat = materialmanager.getMaterial(material)
            pxls = microstructureIO.getCategoryPixels(microstructure, category)
            mat.assignToPixels(ms, pxls)
        finally:
            mscontext.end_writing()
Exemple #11
0
def materialCheck(materialname, propertypaths):
    # Check that given Material contains the given Properties.
    from ooflib.engine import materialmanager
    from ooflib.engine import propertyregistration
    matl = materialmanager.getMaterial(materialname)
    regs = [prop.registration() for prop in matl.properties()]
    if len(propertypaths) != len(regs):
        return False
    for path in propertypaths:
        if propertyregistration.AllProperties[path] not in regs:
            print >> sys.stderr, "Property", path, "not found in", materialname
            return False
    return True
Exemple #12
0
 def select(self, skelctxt, selection):
     clist, plist = selection.trackerlist()
     if self.material == '<Any>':
         courier = skeletonselectioncourier.AnyMaterialElementCourier(
             skelctxt.getObject(), clist, plist)
     elif self.material == '<None>':
         courier = skeletonselectioncourier.NoMaterialElementCourier(
             skelctxt.getObject(), clist, plist)
     else:
         courier = skeletonselectioncourier.MaterialElementCourier(
             skelctxt.getObject(),
             materialmanager.getMaterial(self.material), clist, plist)
     self.operator.operate(selection, courier)
Exemple #13
0
def materialCheck(materialname, propertypaths):
    # Check that given Material contains the given Properties.
    from ooflib.engine import materialmanager
    from ooflib.engine import propertyregistration
    matl = materialmanager.getMaterial(materialname)
    regs = [prop.registration() for prop in matl.properties()]
    if len(propertypaths) != len(regs):
        return False
    for path in propertypaths:
        if propertyregistration.AllProperties[path] not in regs:
            print >> sys.stderr, "Property", path, "not found in", materialname
            return False
    return True
Exemple #14
0
def copymaterialNameResolver(param, startname):
    if param.automatic():
        matactual=materialmanager.getMaterial(param.group['name'].value)
        # Outside of surface_mode, MATERIALTYPE_INTERFACE is not defined.
        if runtimeflags.surface_mode:
            if matactual.type()==MATERIALTYPE_INTERFACE:
                basename = 'interfacematerial'
            else:
                basename = 'material'
        else:
            basename = 'material'
    else:
        basename = startname
    return utils.uniqueName(basename, materialmanager.getMaterialNames())
Exemple #15
0
def copymaterialNameResolver(param, startname):
    if param.automatic():
        matactual = materialmanager.getMaterial(param.group['name'].value)
        # Outside of surface_mode, MATERIALTYPE_INTERFACE is not defined.
        if runtimeflags.surface_mode:
            if matactual.type() == MATERIALTYPE_INTERFACE:
                basename = 'interfacematerial'
            else:
                basename = 'material'
        else:
            basename = 'material'
    else:
        basename = startname
    return utils.uniqueName(basename, materialmanager.getMaterialNames())
Exemple #16
0
def _assignmat(material, microstructure, pixels):
    themat = materialmanager.getMaterial(material)
    ms = ooflib.common.microstructure.microStructures[microstructure].getObject()
    pxls = placeholder.getPlaceHolderFromString(pixels)
    if pxls == placeholder.every:
        themat.assignToAllPixels(ms)
    else:
        if pxls == placeholder.selection:
            group = ms.pixelselection.getSelectionAsGroup()
        else:
            group = ms.findGroup(pixels)
        if group:
            themat.assignToPixelGroup(ms, group)
    switchboard.notify("materials changed in microstructure", ms)
    switchboard.notify("redraw")
Exemple #17
0
def _assignmat(material, microstructure, pixels):
    themat = materialmanager.getMaterial(material)
    ms = ooflib.common.microstructure.microStructures[
        microstructure].getObject()
    pxls = placeholder.getPlaceHolderFromString(pixels)
    if pxls == placeholder.every:
        themat.assignToAllPixels(ms)
    else:
        if pxls == placeholder.selection:
            group = ms.pixelselection.getSelectionAsGroup()
        else:
            group = ms.findGroup(pixels)
        if group:
            themat.assignToPixelGroup(ms, group)
    switchboard.notify("materials changed in microstructure", ms)
    switchboard.notify("redraw")
Exemple #18
0
def writeInterface(datafile, mscontext):
    #Interface branch
    #TODO: The bulk materials that define the interfaces must be written,
    #even if the material is not assigned to pixels.
    #Interface materials are not assigned to pixels. They must be
    #explicitly listed here.
    msobj = mscontext.getObject()
    interfacemsplugin = msobj.getPlugIn("Interfaces")
    for interfacename, interfacedef in interfacemsplugin.namedinterfaces.items(
    ):
        datafile.startCmd(OOF.LoadData.Microstructure.Interface.New)
        datafile.argument('microstructure', msobj.name())
        datafile.argument('name', interfacename)
        datafile.argument('interface_type', interfacedef)
        datafile.endCmd()

    #Write interface properties and materials.
    #An interface material is saved only if it has been assigned to
    #an interface.
    materialmenu.writeMaterials(datafile, [
        materialmanager.getMaterial(m)
        for m in interfacemsplugin.getInterfaceMaterials()
    ])

    #Assign interface materials to interfaces
    for matname, interfacenames in interfacemsplugin._materialassignments.items(
    ):
        if len(interfacenames) == 0:
            continue


##        datafile.startCmd(OOF.LoadData.MaterialandType)
##        datafile.argument('name',matname)
##        matobj=materialmanager.getMaterial(matname)
##        datafile.argument('properties', [prop.registration().name()
##                                         for prop in matobj.properties()])
##        datafile.argument('materialtype',matobj.type())
##        datafile.endCmd()
        datafile.startCmd(OOF.LoadData.Material.Interface.Assign)
        datafile.argument('microstructure', msobj.name())
        datafile.argument('material', matname)
        datafile.argument('interfaces', interfacenames)
        datafile.endCmd()
Exemple #19
0
def writeInterface(datafile, mscontext):
    #Interface branch
    #TODO: The bulk materials that define the interfaces must be written,
    #even if the material is not assigned to pixels.
    #Interface materials are not assigned to pixels. They must be
    #explicitly listed here.
    msobj=mscontext.getObject()
    interfacemsplugin=msobj.getPlugIn("Interfaces")
    for interfacename, interfacedef in interfacemsplugin.namedinterfaces.items():
        datafile.startCmd(OOF.LoadData.Microstructure.Interface.New)
        datafile.argument('microstructure',msobj.name())
        datafile.argument('name',interfacename)
        datafile.argument('interface_type',interfacedef)
        datafile.endCmd()

    #Write interface properties and materials.
    #An interface material is saved only if it has been assigned to
    #an interface.
    materialmenu.writeMaterials(datafile,
                                [materialmanager.getMaterial(m)
                                 for m in interfacemsplugin.getInterfaceMaterials()])

    #Assign interface materials to interfaces
    for matname, interfacenames in interfacemsplugin._materialassignments.items():
        if len(interfacenames)==0:
            continue
##        datafile.startCmd(OOF.LoadData.MaterialandType)
##        datafile.argument('name',matname)
##        matobj=materialmanager.getMaterial(matname)
##        datafile.argument('properties', [prop.registration().name()
##                                         for prop in matobj.properties()])
##        datafile.argument('materialtype',matobj.type())
##        datafile.endCmd()
        datafile.startCmd(OOF.LoadData.Material.Interface.Assign)
        datafile.argument('microstructure',msobj.name())
        datafile.argument('material',matname)
        datafile.argument('interfaces',interfacenames)
        datafile.endCmd()
Exemple #20
0
    def matChanged(self, materialname):
        # The given material has changed.  Look through the materials
        # in our Microstructure to see if we care.
        matl = materialmanager.getMaterial(materialname)
        #Interface branch
        ##TODO: Should we look at the material associated with the
        ##edgements instead?
        if config.dimension() == 2 and runtimeflags.surface_mode:
            interfacemsplugin=self.microstructure.getPlugIn("Interfaces")
            interfacemats=interfacemsplugin.getInterfaceMaterials()
#         elif config.dimension() == 3:
        else:
            interfacemats = []

        if matl in material.getMaterials(self.microstructure) or \
               materialname in interfacemats:
            # We *do* care. Really.  Tell all the SubProblems
            # belonging to the microstructure that the material has
            # changed.
            msname = self.microstructure.name()
            subppaths = subproblemcontext.subproblems.keys(base=msname)
            for subppath in subppaths:
                subpctxt = subproblemcontext.subproblems[[msname]+subppath]
                subpctxt.changed("Material properties changed.")
Exemple #21
0
def saveMaterials(menuitem, filename, mode, format, materials):
    dfile = datafile.writeDataFile(filename, mode.string(), format)
    writeMaterials(dfile, [materialmanager.getMaterial(m) for m in materials])
    dfile.close()
Exemple #22
0
 def material(self):
     return materialmanager.getMaterial(self.materialName)
Exemple #23
0
 def material(self):
     return materialmanager.getMaterial(self.materialName)
Exemple #24
0
def _checkSymmetry(subproblem, material, fn, symmetric):
    subpctxt = ooflib.engine.subproblemcontext.subproblems[subproblem]
    mat = materialmanager.getMaterial('material')
    if fn(subpctxt, mat) != symmetric:
        raise ooferror.ErrPyProgrammingError("symmetry check failed")
Exemple #25
0
def _checkSymmetry(subproblem, material, fn, symmetric):
    subpctxt = ooflib.engine.subproblemcontext.subproblems[subproblem]
    mat = materialmanager.getMaterial('material')
    if fn(subpctxt, mat) != symmetric:
        raise ooferror.ErrPyProgrammingError("symmetry check failed")
Exemple #26
0
def _assign_matl(menuitem, skeleton, group, material):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    if not groupset.isGroup(group):
        raise ooferror.ErrUserError("Group %s does not exist." % group)
    groupset.assignMaterial(group, materialmanager.getMaterial(material))
Exemple #27
0
def saveMaterials(menuitem, filename, mode, format, materials):
    dfile = datafile.writeDataFile(filename, mode.string(), format)
    writeMaterials(dfile,
                   [materialmanager.getMaterial(m) for m in materials])
    dfile.close()
Exemple #28
0
def _addMaterialToElementGroup(menuitem, skeleton, group, material):
    skelcontext = skeletoncontext.skeletonContexts[skeleton]
    groupset = skelcontext.elementgroups
    groupset.assignMaterial(group, materialmanager.getMaterial(material))
Exemple #29
0
def _addMaterialToElementGroup(menuitem, skeleton, group, material):
    skelcontext = skeletoncontext.skeletonContexts[skeleton]
    groupset = skelcontext.elementgroups
    groupset.assignMaterial(group, materialmanager.getMaterial(material))
Exemple #30
0
 def currentMaterial(self):
     name = self.currentMaterialName()
     if name:
         return materialmanager.getMaterial(name)
Exemple #31
0
 def currentMaterial(self):
     name = self.currentMaterialName()
     if name:
         return materialmanager.getMaterial(name)