Beispiel #1
0
    def getMesh(handler, meshId):
        meshDb = MeshWrapper.get_by_id(int(meshId))

        if meshDb == None:
            return None

        return meshDb.toJSON(reduced = False)
Beispiel #2
0
    def getMesh(handler, meshId):
        meshDb = MeshWrapper.get_by_id(int(meshId))

        if meshDb == None:
            return None

        return meshDb.toJSON(reduced=False)
Beispiel #3
0
    def updateMesh(handler, jsonMesh, rename = False):
        if "undeletable" not in jsonMesh:
            jsonMesh["undeletable"] = False

        # This basically says to prefer the userId in the input
        if 'user_id' in jsonMesh:
            userId = jsonMesh['user_id']
        else:
            userId = handler.user.user_id()

        if "id" in jsonMesh:
            meshDb = MeshWrapper.get_by_id(jsonMesh["id"])
            name = jsonMesh["name"]
        else:
            # Make sure name isn't taken, or build one that isn't taken
            if "name" in jsonMesh:
                name = jsonMesh["name"]
                usedNames = set([x.name for x in db.Query(MeshWrapper).filter('user_id =', userId).run()])
                if name in usedNames:
                    if rename:
                        i = 1
                        name = '{0}_{1}'.format(jsonMesh["name"], i)
                        
                        while name in usedNames:
                            i = i + 1
                            name = '{0}_{1}'.format(jsonMesh["name"], i)
                    else:
                        raise Exception("Name is required on new meshes")

            meshDb = MeshWrapper()

        meshDb.user_id = userId
        meshDb.name = name
        meshDb.description = jsonMesh["description"]
        meshDb.meshFileId = jsonMesh["meshFileId"]
        meshDb.subdomains = jsonMesh["subdomains"]
        meshDb.uniqueSubdomains = jsonMesh["uniqueSubdomains"]
        meshDb.undeletable = jsonMesh["undeletable"]

        pymodel = pyurdme.URDMEModel(name = 'test')
        meshFileObj = fileserver.FileManager.getFile(handler, meshDb.meshFileId)
        pymodel.mesh = pyurdme.URDMEMesh.read_dolfin_mesh(str(meshFileObj["storePath"]))
        coordinates = pymodel.mesh.coordinates()
        minx = numpy.min(coordinates[:, 0])
        maxx = numpy.max(coordinates[:, 0])
        miny = numpy.min(coordinates[:, 1])
        maxy = numpy.max(coordinates[:, 1])
        minz = numpy.min(coordinates[:, 2])
        maxz = numpy.max(coordinates[:, 2])
        pymodel.add_species(pyurdme.Species('T', 1))

        if len(meshDb.subdomains) == 0:
            meshDb.subdomains = [1] * len(coordinates)
            meshDb.uniqueSubdomains = [1]

        pymodel.set_subdomain_vector(numpy.array(meshDb.subdomains))
        sd = pymodel.get_subdomain_vector()
        vol_accumulator = numpy.zeros(numpy.unique(sd).shape)
        for ndx, v in enumerate(pymodel.get_solver_datastructure()['vol']):
            vol_accumulator[sd[ndx] - 1] += v

        volumes = {}

        for s, v in enumerate(vol_accumulator):
            volumes[s + 1] = v

        meshDb.volumes = volumes
        meshDb.boundingBox = [[minx, maxx], [miny, maxy], [minz, maxz]]

        return meshDb.put().id()
Beispiel #4
0
 def deleteMesh(handler, meshId):
     meshDb = MeshWrapper.get_by_id(meshId)
     meshDb.ghost = True
     meshDb.put()
Beispiel #5
0
    def updateMesh(handler, jsonMesh, rename=False):
        if "undeletable" not in jsonMesh:
            jsonMesh["undeletable"] = False

        # This basically says to prefer the userId in the input
        if 'user_id' in jsonMesh:
            userId = jsonMesh['user_id']
        else:
            userId = handler.user.user_id()

        if "id" in jsonMesh:
            meshDb = MeshWrapper.get_by_id(jsonMesh["id"])
            name = jsonMesh["name"]
        else:
            # Make sure name isn't taken, or build one that isn't taken
            if "name" in jsonMesh:
                name = jsonMesh["name"]
                usedNames = set([
                    x.name for x in db.Query(MeshWrapper).filter(
                        'user_id =', userId).run()
                ])
                if name in usedNames:
                    if rename:
                        i = 1
                        name = '{0}_{1}'.format(jsonMesh["name"], i)

                        while name in usedNames:
                            i = i + 1
                            name = '{0}_{1}'.format(jsonMesh["name"], i)
                    else:
                        raise Exception("Name is required on new meshes")

            meshDb = MeshWrapper()

        meshDb.user_id = userId
        meshDb.name = name
        meshDb.description = jsonMesh["description"]
        meshDb.meshFileId = jsonMesh["meshFileId"]
        meshDb.subdomains = jsonMesh["subdomains"]
        meshDb.uniqueSubdomains = jsonMesh["uniqueSubdomains"]
        meshDb.undeletable = jsonMesh["undeletable"]

        pymodel = pyurdme.URDMEModel(name='test')
        meshFileObj = fileserver.FileManager.getFile(handler,
                                                     meshDb.meshFileId)
        pymodel.mesh = pyurdme.URDMEMesh.read_dolfin_mesh(
            str(meshFileObj["storePath"]))
        coordinates = pymodel.mesh.coordinates()
        minx = numpy.min(coordinates[:, 0])
        maxx = numpy.max(coordinates[:, 0])
        miny = numpy.min(coordinates[:, 1])
        maxy = numpy.max(coordinates[:, 1])
        minz = numpy.min(coordinates[:, 2])
        maxz = numpy.max(coordinates[:, 2])
        pymodel.add_species(pyurdme.Species('T', 1))

        if len(meshDb.subdomains) == 0:
            meshDb.subdomains = [1] * len(coordinates)
            meshDb.uniqueSubdomains = [1]

        pymodel.set_subdomain_vector(numpy.array(meshDb.subdomains))
        sd = pymodel.get_subdomain_vector()
        vol_accumulator = numpy.zeros(numpy.unique(sd).shape)
        for ndx, v in enumerate(pymodel.get_solver_datastructure()['vol']):
            vol_accumulator[sd[ndx] - 1] += v

        volumes = {}

        for s, v in enumerate(vol_accumulator):
            volumes[s + 1] = v

        meshDb.volumes = volumes
        meshDb.boundingBox = [[minx, maxx], [miny, maxy], [minz, maxz]]

        return meshDb.put().id()
Beispiel #6
0
 def deleteMesh(handler, meshId):
     meshDb = MeshWrapper.get_by_id(meshId)
     meshDb.ghost = True
     meshDb.put()