def setValues(self, val_field): if self.uniform == 1: o_field = liboofem.FloatArray(len(val_field)) for i in range(0, len(val_field)): o_field[i] = float(val_field[i]) self.TField.setValues( o_field ) # it is a different "setValues"...it is an oofem function else: if self.uniform == 0 or self.uniform == -1: for i in range(0, self.nnodes): var_val = liboofem.FloatArray(1) var_val[0] = float(val_field[i]) self.TField.setVertexValue(i, var_val)
def createFromASTField(self, someField): TotMeshNNodes = len(someField.mesh.vertexList) self.setType(-1, TotMeshNNodes) 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)
def createUniformGridTempBCField(self, lo, hi, div, temp=0.): self.TFBC.setType(1) self.TFBC.TField.setGeometry(lo, hi, div) self.TFBC.nnodes = (div[0] + 1) * (div[1] + 1) * (div[2] + 1) self.TFBC.ncells = (div[0]) * (div[1]) * (div[2]) o_field = liboofem.FloatArray(self.TFBC.nnodes) for i in range(0, self.TFBC.nnodes): o_field[i] = float(temp) self.TFBC.TField.setValues(o_field) self.field_man.registerField(self.TFBC.TField, liboofem.FieldType.FT_TemperatureAmbient)
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)
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()
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)
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();
def t2f(t): # conver tuple to floatArray ans = liboofem.FloatArray(len(t)) for i in range(len(t)): ans[i] = t[i] return ans
def makeField(fieldID, timestep=None, valueModeType=liboofem.ValueModeType.VM_Total, units=None): '''Return field object for the model. TODO: pass timestep (uses current step at the moment), valueModeType and units as arguments? :param FieldID: type of field to be returned :param timestep: time step representation :param liboofem.ValueModeType valueModeType: determines the mode of requested value (total or incremental) :return: Field :rtype: mupif.Field.Field ''' if timestep is None: timestep = model.giveCurrentStep() elif not isinstance(timestep, liboofem.TimeStep): raise ValueError("timestep must be a liboofem.TimeStep.") # user can give units in which oofem field is represented if units: raise RuntimeError("units not yet implemented.") dom = self.domain oofemFieldInfo = fieldTypeMap.get(fieldID) if not oofemFieldInfo: raise ValueError( 'Field type %d (%s) not found in this oofem model.' % (fieldID, fieldID.value)) field = self.model.giveField(oofemFieldInfo[0], timestep) # determine valuye type from the first DOF if dom.giveNumberOfDofManagers() < 1: raise ValueError( "Field has zero DofManagers, unable to determine value type.") val = liboofem.FloatArray() field.evaluateAtDman(val, dom.giveDofManager(1), valueModeType, timestep) valueType = { 1: ValueType.Scalar, 3: ValueType.Vector, 9: ValueType.Tensor }.get(len(val)) if not valueType: raise ValueError( "Unhandled value length in field: %d (should be 1, 3 or 9)" % (len(val))) checkLen = len(val) # create empty field, values set in the loop below ret = Field.Field(self._getMesh(), fieldID=fieldID, valueType=valueType, units=units, time=timestep.getTargetTime(), values=None, fieldType=FieldType.FT_vertexBased) # assign values at DOFs for dn in range(1, dom.giveNumberOfDofManagers() + 1): dof = dom.giveDofManager(dn) field.evaluateAtDman(val, dof, valueModeType, timestep) if len(val) != checkLen: raise ValueError( "Invalid length at DofManager #%d: %d, should be %d." % (dn, len(val), checkLen)) ret.setValue(dn - 1, val) return ret