Пример #1
0
        group = store.addGroup(0, 'Test Group')
        # Add a volume and 4 faces the hard way:
        volume = smtk.model.Entity.create(int(smtk.model.CELL_ENTITY), 3)
        f1 = smtk.model.Entity.create(int(smtk.model.CELL_ENTITY), 2)
        f2 = smtk.model.Entity.create(int(smtk.model.CELL_ENTITY), 2)
        f3 = smtk.model.Entity.create(int(smtk.model.CELL_ENTITY), 2)
        f4 = smtk.model.Entity.create(int(smtk.model.CELL_ENTITY), 2)
        u01 = store.addEntity(f1)
        u02 = store.addEntity(f2)
        u03 = store.addEntity(f3)
        u04 = store.addEntity(f4)
        volume.pushRelation(u01).\
            pushRelation(u02).\
            pushRelation(u03).\
            pushRelation(u04).\
            pushRelation(model.entity())

        u00 = store.addEntity(volume)
        # Now verify that the faces refer back to the volume:
        status = False if store.findEntity(u01, True).relations()[
            0] == u00 else True
        # Add cells to the group, the group and cells to the model, submodels
        # to the model:
        [store.findOrAddEntityToGroup(group.entity(), x)
         for x in [u00, u01, u02, u03, u04]]
        [model.addCell(smtk.model.CellEntity(x)) for x in group.members()]
        store.assignDefaultNames()
        model.addGroup(group)
        model.addSubmodel(model2)
        model.addSubmodel(model3)
        # Does the model contain the cells we just added?
Пример #2
0
    def operateInternal(self):

        # Access the DEFORM point and element files
        point_file = self.specification().findFile('point-file').value(0)
        element_file = self.specification().findFile('element-file').value(0)

        # Access the timestep to process
        timestep = self.specification().findInt('timestep').value(0)

        # Access the Dream3D PipelineRunner exectuable
        pipeline_executable = self.specification().findFile(
            'pipeline-executable').value(0)

        # Access the name of the attribute to use for zoning
        attribute = self.specification().findString('attribute').value(0)

        # Access the microscale statistics parameters
        stats = self.specification().findGroup('stats')

        # Access the Dream3D ouptut file
        output_file = self.specification().findFile('output-file').value(0)

        # The location of the template pipeline is hard-coded w.r.t. the AFRL
        # directory
        template_pipeline_file = AFRLDir.description.replace('\n', '') + \
            '/Dream3DPipelines/Pipelines/DREAM3D_Phase1_Pipeline.json'

        # Extract the parameters into python lists
        mu = []
        sigma = []
        min_cutoff = []
        max_cutoff = []

        for i in range(stats.numberOfGroups()):
            for p in ['mu', 'sigma', 'min_cutoff', 'max_cutoff']:
                eval(p).append(
                    smtk.attribute.to_concrete(stats.find(i, p)).value(0))

        # Access the Dream3D output file
        output_file = self.specification().findFile('output-file').value(0)

        # Ensure that the executable is, in fact, an executable
        pipeline = Dream3DPipeline.which(pipeline_executable)
        if pipeline is None:
            print('Cannot find PipelineRunner')
            return self.createResult(smtk.model.OPERATION_FAILED)

        # Generate the Dream3D pipeline for this operation
        pipeline_file = \
            Dream3DPipeline.generate_pipeline(template_pipeline_file,
                                              point_file, timestep,
                                              element_file,
                                              attribute, mu, sigma,
                                              min_cutoff, max_cutoff,
                                              output_file)
        # Execute the Dream3D pipeline
        pipelineargs = [pipeline, '-p', '%s' % os.path.abspath(pipeline_file)]
        subprocess.call(pipelineargs)

        # Remove the pipeline file
        os.remove(pipeline_file)

        # Read DREAM3D Xdmf file as a VTK data object
        xdmfReader = vtk.vtkXdmfReader()
        xdmfReader.SetFileName(os.path.splitext(output_file)[0] + '.xdmf')
        xdmfReader.Update()

        dataNames = [
            xdmfReader.GetOutputDataObject(0).GetMetaData(i).Get(
                vtk.vtkCompositeDataSet.NAME())
            for i in xrange(xdmfReader.GetNumberOfGrids())
        ]

        volumeDataContainer = xdmfReader.GetOutputDataObject(0).GetBlock(
            dataNames.index("VolumeDataContainer"))

        # Import the vtk data object as an SMTK mesh
        cnvrt = smtk.io.vtk.ImportVTKData()
        collection = cnvrt(volumeDataContainer, self.meshManager(), 'ZoneIds')

        # Ensure that the import succeeded
        if not collection or not collection.isValid():
            return self.createResult(smtk.model.OPERATION_FAILED)

        # Assign its model manager to the one associated with this session
        collection.modelManager = self.manager()
        collection.name("DEFORM mesh")

        # Construct the topology
        self.activeSession().addTopology(smtk.bridge.mesh.Topology(collection))

        # Our collections will already have a UUID, so here we create a model
        # given the model manager and UUID
        model = self.manager().insertModel(collection.entity(), 2, 2,
                                           "DEFORM model")

        # Declare the model as "dangling" so it will be transcribed
        self.session().declareDanglingEntity(model)

        # Set the model's session to point to the current session
        model.setSession(
            smtk.model.SessionRef(self.manager(),
                                  self.session().sessionId()))

        collection.associateToModel(model.entity())

        # If we don't call "transcribe" ourselves, it never gets called.
        self.activeSession().transcribe(model, smtk.model.SESSION_EVERYTHING,
                                        False)

        result = self.createResult(smtk.model.OPERATION_SUCCEEDED)

        resultModels = result.findModelEntity("model")
        resultModels.setValue(model)

        created = result.findModelEntity("created")
        created.setNumberOfValues(1)
        created.setValue(model)
        created.setIsEnabled(True)

        result.findModelEntity("mesh_created").setValue(model)

        # Return with success
        return result
Пример #3
0
    def import_model(self, filepath, resource, model_name):
        # Create mesh resource
        mesh_resource = smtk.mesh.Resource.create()

        # Get the mesh resource from file
        print('Load file from {}'.format(filepath))
        smtk.io.importMesh(
            filepath, mesh_resource, model_name)
        
        # Get dimension
        if self.dim == 0:
            self.dim = smtk.mesh.highestDimension(mesh_resource.meshes())
        else:
            model_dim = smtk.mesh.highestDimension(mesh_resource.meshes())
            if model_dim != self.dim:
                raise Exception("Solid model and fluid model dimensions are inconsistent!")
        print('{}\'s dimension is {}'.format(model_name, self.dim))
        if int(self.dim) < 2:
            raise Exception("1D models are not supported!")

        # Get meshset for new mesh
        meshes = mesh_resource.meshes()

        # Remove the mesh without domains
        meshes_without_domains = []
        for i in range(meshes.size()):
            submesh = meshes.subset(i)
            if len(submesh.domains()) == 0:
                meshes_without_domains.append(submesh)

        for mesh_without_domain in meshes_without_domains:
            mesh_resource.removeMeshes(mesh_without_domain)

        # If no mesh found return failue message
        if not mesh_resource or not mesh_resource.isValid():
            return self.createResult(smtk.operation.Operation.Outcome.FAILED)

        # Set name on mesh and resource
        mesh_resource.setName(model_name)

        # Set association between resource and mesh resource
        mesh_resource.modelResource = resource
        resource.setMeshTessellations(mesh_resource)

        # Create a model
        model = resource.addModel(self.dim, self.dim)
        model.setName(model_name)

        # Construct the topology
        self.session.addTopology(resource, smtk.session.mesh.Topology(
            model.entity(), meshes, False))

        model.setStringProperty('url', filepath)
        model.setStringProperty('type', 'gmsh')

        self.session.declareDanglingEntity(model)

        model.setSession(smtk.model.SessionRef(
            resource, self.session.sessionId()))

        mesh_resource.associateToModel(model.entity())

        # transcribe
        resource.session().transcribe(
            model, smtk.model.SESSION_EVERYTHING, False)

        # Set string property to the model and its entities
        model.setStringProperty('Analysis', model_name)
        entities = model.cells()
        for e in entities:
            e.setStringProperty('Analysis', model_name)

        # Rename model entities
        # The bitflag 100 indicates all the edges, faces and volumes
        sub_entities = resource.findEntitiesOfType(0x00000100)
        for entity in sub_entities:
            # Edge entities
            if entity.entityFlags() == 0x00000102:
                new_name = re.sub('Domain', model_name +
                                  ' Edge', entity.name())
                entity.setName(new_name)
            # Face entities
            elif entity.entityFlags() == 0x00000104:
                new_name = re.sub('Domain', model_name +
                                  ' Face', entity.name())
                entity.setName(new_name)
            # Volume entities
            elif entity.entityFlags() == 0x00000108:
                new_name = re.sub('Domain', model_name +
                                  ' Volume', entity.name())
                entity.setName(new_name)

        return model
Пример #4
0
        group = store.addGroup(0, 'Test Group')
        # Add a volume and 4 faces the hard way:
        volume = smtk.model.Entity.create(int(smtk.model.CELL_ENTITY), 3)
        f1 = smtk.model.Entity.create(int(smtk.model.CELL_ENTITY), 2)
        f2 = smtk.model.Entity.create(int(smtk.model.CELL_ENTITY), 2)
        f3 = smtk.model.Entity.create(int(smtk.model.CELL_ENTITY), 2)
        f4 = smtk.model.Entity.create(int(smtk.model.CELL_ENTITY), 2)
        u01 = store.addEntity(f1)
        u02 = store.addEntity(f2)
        u03 = store.addEntity(f3)
        u04 = store.addEntity(f4)
        volume.pushRelation(u01).\
            pushRelation(u02).\
            pushRelation(u03).\
            pushRelation(u04).\
            pushRelation(model.entity())

        u00 = store.addEntity(volume)
        # Now verify that the faces refer back to the volume:
        status = False if store.findEntity(u01, True).relations()[
            0] == u00 else True
        # Add cells to the group, the group and cells to the model, submodels
        # to the model:
        [store.findOrAddEntityToGroup(group.entity(), x)
         for x in [u00, u01, u02, u03, u04]]
        [model.addCell(smtk.model.CellEntity(x)) for x in group.members()]
        store.assignDefaultNames()
        model.addGroup(group)
        model.addSubmodel(model2)
        model.addSubmodel(model3)
        # Does the model contain the cells we just added?