def __init__(self, propID, valueType, units, objectID=0, metaData={}): """ Initializes the property. :param PropertyID propID: Property ID :param ValueType valueType: Type of a property, i.e. scalar, vector, tensor. Tensor is by default a tuple of 9 values, being compatible with Field's tensor. :param units: Property units or string :type units: Physics.PhysicalUnits or string :param int objectID: Optional ID of problem object/subdomain to which property is related, default = 0 """ MupifObject.MupifObject.__init__(self) self.propID = propID # self.units = units self.valueType = valueType self.objectID = objectID if PhysicalQuantities.isPhysicalUnit(units): self.unit = units else: self.unit = PhysicalQuantities.findUnit(units) self.setMetadata('Type', 'mupif.Property.Property') self.setMetadata('Type_ID', str(self.propID)) self.setMetadata('Units', self.unit.name()) self.setMetadata('ValueType', str(self.valueType)) self.updateMetadata(metaData)
def convertToUnit(self, unit): """ Change the unit and adjust the value such that the combination is equivalent to the original one. The new unit must be compatible with the previous unit of the object. :param C{str} unit: a unit :raise TypeError: if the unit string is not a known unit or a unit incompatible with the current one """ unit = PhysicalQuantities.findUnit(unit) self.value = self._convertValue(self.value, self.unit, unit) self.unit = unit
def __init__(self, t, dt, targetTime, units=None, n=1): """ Initializes time step. :param t: Time(time at the end of time step) :type t: PQ.PhysicalQuantity :param dt: Step length (time increment), type depends on 'units' :type dt: PQ.PhysicalQuantity :param targetTime: target simulation time (time at the end of simulation, not of a single TimeStep) :type targetTime: PQ.PhysicalQuantity. targetTime is not related to particular time step rather to the material model (load duration, relaxation spectra etc.) :param PQ.PhysicalUnit or str units: optional units for t, dt, targetTime if given as float values :param int n: Optional, solution time step number, default = 1 """ self.number = n # solution step number, dimensionless if units is None: if not PQ.isPhysicalQuantity(t): raise TypeError(str(t) + ' is not physical quantity') if not PQ.isPhysicalQuantity(dt): raise TypeError(str(dt) + ' is not physical quantity') if not PQ.isPhysicalQuantity(targetTime): raise TypeError(str(targetTime) + ' is not physical quantity') self.time = t self.dt = dt self.targetTime = targetTime else: if PQ.isPhysicalUnit(units): units_temp = units else: units_temp = PQ.findUnit(units) self.time = PQ.PhysicalQuantity(t, units_temp) self.dt = PQ.PhysicalQuantity(dt, units_temp) self.targetTime = PQ.PhysicalQuantity(targetTime, units_temp)