Example #1
0
    def setField(self, field):
        """
        Registers the given (remote) field in application.

        :param Field field: Remote field to be registered by the application
        """
        if not isinstance(field, Field.Field):
            raise ValueError("field must be a Field.Field.")
        # convert Field.Field into liboofem.UnstructredGridField first
        mesh = field.getMesh()
        target = liboofem.UnstructuredGridField(mesh.getNumberOfVertices(),
                                                mesh.getNumberOfCells())
        # convert vertices first
        for node in mesh.vertices():
            c = node.getCoordinates()  # tuple -> FloatArray conversion
            cc = liboofem.FloatArray(len(c))
            for i in range(len(c)):
                cc[i] = c[i]
            target.addVertex(node.getNumber(), cc)
        for cell in mesh.cells():
            v = cell.getVertices()
            vv = liboofem.IntArray(len(v))
            for i in range(len(v)):
                vv[i] = v[i].getNumber()
            target.addCell(cell.number,
                           elementTypeMap.get(cell.getGeometryType()), vv)
        # set values
        if (field.getFieldType() == Field.FieldType.FT_vertexBased):
            for node in mesh.vertices():
                target.setVertexValue(node.getNumber(),
                                      field.getVertexValue(node.getNumber()))
        else:
            for node in mesh.vertices():
                target.setVertexValue(node.getNumber(),
                                      field.evaluate(node.getCoordinates()))
        # register converted field in oofem
        ft = fieldTypeMap.get((field.getFieldID()))[0]
        if ft == None: raise ValueError("Field type not recognized")
        print("oofem: registering extermal field ", field, "as ...", target)
        #print "Check: ", field.evaluate((2.5,0.9,0)), " == ", target.evaluateAtPos (t2f((2.5,0.9,0)), liboofem.ValueModeType.VM_Total)

        self.oofem_pb.giveContext().giveFieldManager().registerField(
            target, ft)
Example #2
0
import liboofem

a = liboofem.FloatArray(2)
b = liboofem.FloatArray(4)
ind = liboofem.IntArray(2)

a.zero()
b.zero()
a[1] = 15.0
a[0] = 10.0
print a[0], a[1]
a.printYourself()

c = liboofem.FloatArray(a)
print c[0], c[1]
c.printYourself()

d = liboofem.FloatMatrix(2, 2)
d.beUnitMatrix()
d[0, 1] = 1.0
d.printYourself()

b.beProductOf(d, a)
b.printYourself()

b.resize(4)
b.zero()
ind[0] = 1
ind[1] = 3
b.assemble(a, ind)
b.printYourself()
Example #3
0
    def createFromTempField(self, mshID, someField, cellType=1):
        if mshID == 0:
            TotMeshNNodes = len(someField.mesh.vertexList)
            TotMeshNCells = len(someField.mesh.cellList)
            if cellType == 1:
                self.setType(0, TotMeshNNodes, TotMeshNCells)
            if cellType == 0:
                self.setType(0, TotMeshNNodes, TotMeshNCells * 6)
            for i in range(0, TotMeshNNodes):
                coo = liboofem.FloatArray(3)
                coo[0] = someField.mesh.vertexList[i].coords[0]
                coo[1] = someField.mesh.vertexList[i].coords[1]
                coo[2] = someField.mesh.vertexList[i].coords[2]
                self.TField.addVertex(i, coo)
            for i in range(0, TotMeshNCells):
                cvlp = someField.mesh.cellList[i].vertices
                if cellType == 1:
                    verts = liboofem.IntArray(8)
                    for j in range(0, 8):
                        verts[j] = cvlp[j]
                    self.TField.addCell(
                        i, liboofem.Element_Geometry_Type.EGT_hexa_1, verts)

                if cellType == 0:
                    verts = liboofem.IntArray(4)
                    verts[0] = cvlp[0]
                    verts[1] = cvlp[3]
                    verts[2] = cvlp[4]
                    verts[3] = cvlp[1]
                    self.TField.addCell(
                        6 * i, liboofem.Element_Geometry_Type.EGT_tetra_1,
                        verts)
                    verts = liboofem.IntArray(4)
                    verts[0] = cvlp[4]
                    verts[1] = cvlp[1]
                    verts[2] = cvlp[3]
                    verts[3] = cvlp[2]
                    self.TField.addCell(
                        6 * i + 1, liboofem.Element_Geometry_Type.EGT_tetra_1,
                        verts)
                    verts = liboofem.IntArray(4)
                    verts[0] = cvlp[4]
                    verts[1] = cvlp[1]
                    verts[2] = cvlp[2]
                    verts[3] = cvlp[5]
                    self.TField.addCell(
                        6 * i + 2, liboofem.Element_Geometry_Type.EGT_tetra_1,
                        verts)
                    verts = liboofem.IntArray(4)
                    verts[0] = cvlp[4]
                    verts[1] = cvlp[3]
                    verts[2] = cvlp[7]
                    verts[3] = cvlp[6]
                    self.TField.addCell(
                        6 * i + 3, liboofem.Element_Geometry_Type.EGT_tetra_1,
                        verts)
                    verts = liboofem.IntArray(4)
                    verts[0] = cvlp[4]
                    verts[1] = cvlp[3]
                    verts[2] = cvlp[6]
                    verts[3] = cvlp[2]
                    self.TField.addCell(
                        6 * i + 4, liboofem.Element_Geometry_Type.EGT_tetra_1,
                        verts)
                    verts = liboofem.IntArray(4)
                    verts[0] = cvlp[4]
                    verts[1] = cvlp[2]
                    verts[2] = cvlp[6]
                    verts[3] = cvlp[5]
                    self.TField.addCell(
                        6 * i + 5, liboofem.Element_Geometry_Type.EGT_tetra_1,
                        verts)
        else:
            self.setType(1)
            # get min and max and the division numerically
            locerrtol = 0.01
            self.domainSize = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
            self.meshSize = [0, 0, 0]
            a = someField.mesh.vertexList[0].coords
            b = someField.mesh.vertexList[len(someField.mesh.vertexList) -
                                          1].coords
            self.domainSize = [a[0], a[1], a[2], b[0], b[1], b[2]]

            for i in range(0, len(someField.mesh.vertexList)):
                for j in range(0, 3):
                    inLine = 1
                    for k in range(0, 3):
                        if j != k:
                            if (someField.mesh.vertexList[i].coords[k] >
                                    a[k] + locerrtol
                                    or someField.mesh.vertexList[i].coords[k] <
                                    a[k] - locerrtol):
                                inLine = 0
                    if inLine:
                        self.meshSize[j] = self.meshSize[j] + 1

            boxSize = self.domainSize
            meshDiv = self.meshSize
            self.TField.setGeometry(lo=(boxSize[0], boxSize[1], boxSize[2]),
                                    hi=(boxSize[3], boxSize[4], boxSize[5]),
                                    div=(meshDiv[0] - 1, meshDiv[1] - 1,
                                         meshDiv[2] - 1))
            self.nnodes = meshDiv[0] * meshDiv[1] * meshDiv[2]
            self.nnodes = (meshDiv[0] - 1) * (meshDiv[1] - 1) * (meshDiv[2] -
                                                                 1)
Example #4
0
 def t2i(t):
     # conver tuple to floatArray
     ans = liboofem.IntArray(len(t))
     for i in range(len(t)):
         ans[i] = t[i]
     return ans