def __init__(self, body, value): """ The initial condition section may be used to set initial values - One or several bodies (object Support or StructuredMesh or list of) - The value is of type Displacement, temperature or chemical state """ CommonInitialCondition.__init__(self, body, value) for val in value: memberShip(val,[Displacement, Temperature, ChemicalState]) ok = 0 for val in value: if val.__class__.__name__ == "ChemicalState": ok = 1 self.chemicalState = val break pass if ok == 0: raise Warning(" the association of a chemical state to a boundary is mandatory ") ok = 0 for val in value: if val.__class__.__name__ in ["Displacement","NormalForce"]: ok = 1 self.value = val break if ok == 0: raise Warning(" check the definition of the initial condition linked to").with_traceback(body.bodyName) return None
def checkValue(self, value): valueOK = 0 try: if type(value) not in [FloatType, IntType]: raise Exception("value should be a float") value = float(value) valueOK = 1 pass except TypeError: pass if not valueOK: try: memberShip(value, [Field, LinearFunction,TimeTabulatedFunction,\ SpaceAndTimeTabulatedFunction,\ PolynomialFunction,TimeFunction]) valueOK = 1 pass except TypeError: pass pass if not valueOK: raise Exception( "physical quantity can\"t be defined, see the value %s" % (value)) self.value = value return
def __init__(self, domain=None, value=None): """ domain can be a region of the domain, it could also be a simple body associated to . """ memberShip(domain.support, [CartesianMesh, Body]) self.domain = domain # if domain !=None: # if isinstance(domain,Region): # memberShip(domain.support,[CartesianMesh, Body]) # elif isinstance(domain,Body): # pass # elif isinstance(domain,CartesianMesh): # pass # self.domain = domain # # # print("dbg CommonInitialCondition", value) if type(value) == None: self.value = Head(0.0, "m") elif isinstance(value, Head): self.value = value else: raise Exception(" to modify, the pressure must be scaled ")
def verifyValue(self, value): # valueOK = verifyValueIsUnknown(value) valueOK = 0 if not valueOK: if type(value) in [FloatType, IntType]: value = float(value) valueOK = 1 pass if type(value) in [ListType]: value = list(map(float, value)) valueOK = 1 pass pass if not valueOK: # value : instance de Field ou de LinearFunction2D try: memberShip(value, [ LinearFunction, TimeTabulatedFunction, SpaceAndTimeTabulatedFunction, PolynomialFunction, TimeFunction ]) valueOK = 1 ## to do : add a linear function 2D,3D except TypeError: pass pass if not valueOK: # Exception levee raise Warning("IncorrectValue for a physical quantity") self.value = value return
def __init__(self, domain = None, value = None): """ domain can be a region of the domain, it could also be a simple body associated to . """ memberShip(domain.support,[CartesianMesh, Body]) self.domain = domain # if domain !=None: # if isinstance(domain,Region): # memberShip(domain.support,[CartesianMesh, Body]) # elif isinstance(domain,Body): # pass # elif isinstance(domain,CartesianMesh): # pass # self.domain = domain # # # print("dbg CommonInitialCondition",value) if type(value) == None: self.value = Head(0.0,"m") elif isinstance(value,Head): self.value = value else: raise Exception(" to modify, the pressure must be scaled ")
def makeTableFromLinearFunction(function,coords,time_list,name=None,columnUnits=None): """Constructs a table consisting of two columns. The first column contains a time list and the second column contains function values for space coordinates coords and times defined in the time list.""" verifyType(time_list,ListType) from functions import LinearFunction memberShip(function,LinearFunction) nb_coeff = function.getNbCoefficients() coeffs = function.getCoefficients() if name: verifyType(name,StringType) tab=Table(name) pass else: tab = Table('Table') pass if columnUnits: listTypeCheck(columnUnits, StringType) if len(columnUnits) !=2: raise Exception("makeTableFromLinearFunction creates a two columns table : time and value. You have to give two units") tab.setColumnUnits(columnUnits) pass value_list = [] for t in time_list: coo = coords + [t] value = function.eval(coo) value_list.append(value) pass tab.addColumn('time',time_list) tab.addColumn('value',value_list) return tab
def __init__(self, zone, value=None): """ constructor with : - zone : object CartesianMesh - OPTINAL : --> value : a PhysicalQuantity or a list of couple (PhysicalQuantity,species) or a ChemicalState """ if type(zone) is types.ListType: verifyClassList(zone,[CartesianMesh]) pass else: memberShip(zone,[CartesianMesh]) pass self.zone = zone self.value_species = None self.value_property = None self.value = None if value: memberShip(value,[PhysicalQuantity,ChemicalState]) if (isInstance(value, PhysicalQuantity) or type(value) is types.ListType): self.value_species, self.value_property = createList(value, PhysicalQuantity) pass else: self.value = value pass pass
def verifyValue(self, value): # valueOK = verifyValueIsUnknown(value) valueOK = 0 if not valueOK: # print "Tensor value : float ou int ??",value,type(value) if type(value) in [FloatType, IntType]: # print "Tensor value ok " value = IsotropicTensor(float(value)) valueOK = 1 pass pass # print "Tensor what value 0",valueOK if not valueOK: # value : Tensor, or IsotropicTensor try: memberShip(value, [Tensor, IsotropicTensor]) valueOK = 1 except TypeError: pass pass if not valueOK: # value : instance de Field ou de LinearFunction2D try: memberShip(value, [Field, LinearFunction, TimeTabulatedFunction, PolynomialFunction]) valueOK = 1 ## to do : add a linear function 2D,3D except TypeError: pass pass if not valueOK: raise ValueError("physical quantity") # print " at the end ",value,type(value) return value
def __init__(self, body = None, value = None, description = None): """ domain can be a region of the domain, it could also be a simple body associated to . """ if isInstance(body,[CartesianMesh, Body]): pass else: memberShip(body.support,[CartesianMesh, Body]) pass self.body = body self.zone = body self.domain = body # if domain !=None: # if isinstance(domain,Region): # memberShip(domain.support,[CartesianMesh, Body]) # elif isinstance(domain,Body): # pass # elif isinstance(domain,CartesianMesh): # pass # self.domain = domain # # # if not isinstance(value,(Head,Pressure)): pass else: #print "dbg CommonInitialCondition",value if type(value) == None: self.value = Head(0.0,"m") pass elif isinstance(value,Head): self.value = value pass else: raise Exception(" to modify, the pressure must be scaled to be entered as a head") if not isinstance(value,(Displacement)): pass else: #print "dbg CommonInitialCondition",value if type(value) == None: self.value = Displacement(0.0,"m") pass elif isinstance(value,Displacement): self.value = value pass else: raise Exception(" to modify, the pressure must be scaled to be entered as a head") if description == None: self.description = None pass else: self.description = description pass return None
def __init__(self, support, material): """ Constructor with : -support : unstructured or CartesianMesh - material : object Material """ print support memberShip(material, Material) self.material = material memberShip(support,[CartesianMesh, Body]) self.support = support return
def __init__(self, edge, nb_points): """ constructor with : - edge : instance of Edge - nb_points : integer """ DiscreteObject.__init__(self) memberShip(edge, Edge) self.edge = edge from types import IntType if type(nb_points) != IntType: raise TypeError, "nb_points should be an integer" self.nb_points = nb_points return None
def isEqual(self, other, epsilon=None): """ Enables to compare the table to an other one. Compares two tables. Returns 1 if they are completely identical, otherwise - 0. epsilon is the equality evaluator """ memberShip(other, DataTable) Ok = 0 nbc1 = len(self.getColumnNames()) nbc2 = len(other.getColumnNames()) if nbc1 != nbc2: return 0 nbu1 = len(self.getColumnUnits()) nbu2 = len(other.getColumnUnits()) if nbu1 != nbu2: return 0 for i in range(nbc1): if self.getColumnNames()[i].lower().strip()!=\ other.getColumnNames()[i].lower().strip(): return 0 pass for i in range(nbu1): if self.getColumnUnits()[i].lower().strip()!=\ other.getColumnUnits()[i].lower().strip(): return 0 pass nbc1 = self.getNbColumns() nbc2 = other.getNbColumns() if nbc1 != nbc2: return 0 nbl1 = self.getNbColumns() nbl2 = other.getNbColumns() if nbl1 != nbl2: return 0 for i in range(nbl1): for j in range(nbc1): v1 = self.getItem(j, i) v2 = other.getItem(j, i) if not epsilon: if v1 != v2: return 0 pass elif not areClose(float(v1), float(v2), epsilon, 'rel'): return 0 pass pass return 1
def isEqual(self,other,epsilon=None): """ Enables to compare the table to an other one. Compares two tables. Returns 1 if they are completely identical, otherwise - 0. epsilon is the equality evaluator """ memberShip(other,DataTable) Ok=0 nbc1=len(self.getColumnNames()) nbc2=len(other.getColumnNames()) if nbc1!=nbc2: return 0 nbu1 = len(self.getColumnUnits()) nbu2 = len(other.getColumnUnits()) if nbu1!=nbu2: return 0 for i in range(nbc1): if self.getColumnNames()[i].lower().strip()!=\ other.getColumnNames()[i].lower().strip(): return 0 pass for i in range(nbu1): if self.getColumnUnits()[i].lower().strip()!=\ other.getColumnUnits()[i].lower().strip(): return 0 pass nbc1=self.getNbColumns() nbc2=other.getNbColumns() if nbc1!=nbc2: return 0 nbl1=self.getNbColumns() nbl2=other.getNbColumns() if nbl1!=nbl2: return 0 for i in range(nbl1): for j in range(nbc1): v1=self.getItem(j,i) v2=other.getItem(j,i) if not epsilon: if v1!=v2: return 0 pass elif not areClose(float(v1),float(v2),epsilon,'rel'): return 0 pass pass return 1
def __init__(self, zone, value, rate=None): """constructor with : - zone : Mesh support - value : a PhysicalQuantity or a list of couple (PhysicalQuantity,species) or a ChemicalState - OPTIONAL : --> rate : FlowRate """ memberShip(zone, [CartesianMesh]) self.zone = zone self.value_species = None self.value_property = None self.value = None if value: memberShip(value,[PhysicalQuantity,ChemicalState]) if (isInstance(value, PhysicalQuantity) or type(value) is types.ListType): self.value_species,self.value_property = createList(value, PhysicalQuantity) pass else: self.value = value pass pass if rate: memberShip(value, Flowrate) self.rate = rate return
def verifyValue(self, value): # valueOK = verifyValueIsUnknown(value) valueOK = 0 if not valueOK: #print "Tensor value : float ou int ??",value,type(value) if type(value) in [FloatType, IntType]: # print "Tensor value ok " value = IsotropicTensor(float(value)) valueOK = 1 pass pass # print "Tensor what value 0",valueOK if not valueOK: # value : Tensor, or IsotropicTensor try: memberShip(value, [Tensor, IsotropicTensor]) valueOK = 1 except TypeError: pass pass if not valueOK: # value : instance de Field ou de LinearFunction2D try: memberShip(value, [ Field, LinearFunction, TimeTabulatedFunction, PolynomialFunction ]) valueOK = 1 ## to do : add a linear function 2D,3D except TypeError: pass pass if not valueOK: raise ValueError("physical quantity") # print " at the end ",value,type(value) return value
def __init__(self, boundary, kind, value, bcdict, porosity=None, description=None): """Boundary condition initialisation with : - one boundary - a boundary condition type. We verify that it's a key of bcdict dictionnary - a boundary condition value. Value depend of boundary condition type. -bcdict : a dictionnary with key = type of boundary condition and value = Possible class of boundary condition value """ self.value_species = None memberShip(boundary.support, [CartesianMesh, Body]) # verifyClass(boundary,[CartesianMesh,Body]) self.boundary = boundary if type(kind) != StringType: raise TypeError(" type should be a string") if kind not in list(bcdict.keys()): raise Exception(" check the boundary condition type ") self.type = kind value = toList(value) for val in value: if type(val) is TupleType: checked = val[0] for i in range(1, len(val)): memberShip(val[i], Species) pass pass else: checked = val pass for definedtype in bcdict: if kind == definedtype: memberShip(checked, bcdict[kind]) pass pass pass if not self.value_species: from PhysicalQuantities import PhysicalQuantity from species import createList print(value) self.value_species, self.value_property = createList( value, PhysicalQuantity) pass if description == None: self.description = "" pass else: self.description = description pass return
def __init__(self, coefList = None, timeCoef = None): """ - coefList : list of real or integer - the timecoeff is a table """ if coefList: # print coefList,type(coefList) verifyType(coefList, [list]) for coef in coefList: # print " c ",c verifyType(coef, [float,int]) pass self.coefList = coefList pass else: self.coefList =[] pass if timeCoef: memberShip(timeCoef, Table) pass self.timecoeff = timeCoef return
def checkValue(self, value): valueOK=0 try: if type(value) not in [FloatType,IntType]: raise Exception("value should be a float") value = float(value) valueOK = 1 except TypeError: pass if not valueOK: try: memberShip(value, [Field, LinearFunction,TimeTabulatedFunction,\ SpaceAndTimeTabulatedFunction,\ PolynomialFunction,TimeFunction]) valueOK = 1 pass except TypeError: pass pass if not valueOK: raise Exception("physical quantity can\"t be defined, see the value %s"%(value)) self.value = value return
def __init__(self, coefList=None, timeCoef=None): """ - coefList : list of real or integer - the timecoeff is a table """ if coefList: # print coefList,type(coefList) verifyType(coefList, [list]) for coef in coefList: # print " c ",c verifyType(coef, [float, int]) pass self.coefList = coefList pass else: self.coefList = [] pass if timeCoef: memberShip(timeCoef, Table) pass self.timecoeff = timeCoef return
def verifyValue(self, value): # valueOK = verifyValueIsUnknown(value) valueOK = 0 if not valueOK: if type(value) in [FloatType, IntType]: value = float(value) valueOK = 1 pass if type(value) in [ListType]: value = list(map(float, value)) valueOK = 1 pass pass if not valueOK: # value : instance de Field ou de LinearFunction2D try: memberShip( value, [ LinearFunction, TimeTabulatedFunction, SpaceAndTimeTabulatedFunction, PolynomialFunction, TimeFunction, ], ) valueOK = 1 ## to do : add a linear function 2D,3D except TypeError: pass pass if not valueOK: # Exception levee raise Warning("IncorrectValue for a physical quantity") self.value = value return
def __init__(self, boundary, kind, value, bcdict, porosity = None, description = None): """Boundary condition initialisation with : - one boundary - a boundary condition type. We verify that it's a key of bcdict dictionnary - a boundary condition value. Value depend of boundary condition type. -bcdict : a dictionnary with key = type of boundary condition and value = Possible class of boundary condition value """ self.value_species =None memberShip(boundary.support,[CartesianMesh, Body]) # verifyClass(boundary,[CartesianMesh,Body]) self.boundary = boundary if type(kind) != StringType: raise TypeError(" type should be a string") if kind not in list(bcdict.keys()): raise Exception(" check the boundary condition type ") self.type = kind value = toList(value) for val in value: if type(val) is TupleType: checked = val[0] for i in range(1,len(val)): from datamodel import Species memberShip(val[i], Species) pass pass else: checked = val pass for definedtype in bcdict: if kind == definedtype: memberShip(checked, bcdict[kind]) pass pass pass if not self.value_species: from PhysicalQuantities import PhysicalQuantity from species import createList print(value) self.value_species, self.value_property = createList(value, PhysicalQuantity) pass if description == None: self.description = "" pass else: self.description = description pass return
def _associateZoneValue(zone, value, some_classes): zones = toList(zone) verifyClassList(zones, [CartesianMesh]) value = toList(value) for val in value: if type(val) is TupleType: from datamodel import Species memberShip(val[0], some_classes) memberShip(val[1], Species) pass else: memberShip(val, some_classes) pass pass from datamodel import createList from datamodel import PhysicalQuantity value_species, value_property = createList(value, PhysicalQuantity) return value_species, value_property
def _associateZoneValue(zone,value,some_classes): zones=toList(zone) verifyClassList(zones,[CartesianMesh]) value = toList(value) for val in value: if type(val) is TupleType: from datamodel import Species memberShip(val[0], some_classes) memberShip(val[1], Species) pass else: memberShip(val, some_classes) pass pass from datamodel import createList from datamodel import PhysicalQuantity value_species, value_property = createList(value, PhysicalQuantity) return value_species, value_property
def setSaturatedWaterContent(self, saturatedWaterContent): """ That function enables to set the liquid saturated property """ memberShip(saturatedWaterContent, saturatedWaterContent) self.saturatedWaterContent = residualWaterContent
def __init__(self, body, value, description = None): """ constructor with : - body : object body or CartesianMesh - value : a PhysicalQuantity, a list of tuples (PhysicalQuantity,species) a ChemicalState or a tuple to introduce a function on a specific variable """ if type(body) is types.ListType: verifyClassList(body,[CartesianMesh]) pass else: memberShip(body,[CartesianMesh, Body]) pass self.zone = body self.body = body self.value_species = None self.value_property = None self.value = None self.headValue = None # # Linked to the treatment of a wellbore # self.enthalpyInitialCondition = None self.wellFeedZoneInitialCondition = None self.temperatureInitialCondition = None self.wellMassFlowInitialCondition = None self.wellPressureInitialCondition = None # if type(value) is types.ListType: for i in value: print ("dbg commonmodel",type(i)) pass verifyClassList(value, [ Head, ChemicalState, Displacement, types.TupleType]) for ic in value: if isinstance(ic, Head): self.headValue = ic # It should be the charge pass elif isinstance(ic, (Displacement, ChemicalState)) : self.value = ic # It should be chemistry or a displacement pass elif isinstance(ic, types.TupleType): #print("debug commonmodel ic %s\n"%(ic[0].lower())) if ic[0].lower() == "enthalpy": # It can also be an enthalpy in the # case of a well if type(ic[1]) == types.StringType: #raw_input("common model debug") self.enthalpyInitialCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'), ic[1]) pass pass elif ic[0].lower().replace(" ","") == "feedzoneheatsource": # We introduce here a heat source linked to a feed zone. if type(ic[1]) in [types.TupleType, types.ListType]: # It should be a tuple: position and value of the source term. self.wellFeedZoneInitialCondition = ic[1] pass elif type(ic[1]) is types.StringType: # It should be a tuple: position and value of the source term. self.wellFeedZoneInitialCondition = refindall(recompile(r'([ifelsxyzXYZ0-9.*;()/+-<>=])'), ic[1]) pass #print("in commonmodel ",self.wellFeedZoneInitialCondition) #raw_input() pass elif ic[0].lower() == "temperature": # It should be temperature otherwise a warning # is raised. We extract the formula thanks to != # regular expressions modules. if type(ic[1]) == types.StringType: self.temperatureInitialCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'), ic[1]) pass pass elif ic[0].lower().replace(" ","") == "wellmassflow": # It can also be the mass flow in the # case of a well if type(ic[1]) == types.StringType: self.wellMassFlowInitialCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'), ic[1]) pass elif type(ic[1]) in [types.FloatType,types.IntType]: self.wellMassFlowInitialCondition = ic[1] pass pass elif ic[0].lower().replace(" ","") == "wellpressure": # It can also be the pressure in the # case of a well if type(ic[1]) == types.StringType: self.wellPressureInitialCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'), ic[1]) pass elif type(ic[1]) in [types.FloatType, types.IntType]: self.wellPressureInitialCondition = ic[1] #print("commonmodel well pressure debug yes\n") #raw_input() pass pass else: raise Warning, "check the name of the variable " pass else: if (isinstance(ic, PhysicalQuantity) or type(ic) is types.ListType): self.value_species, self.value_property = createList(ic, PhysicalQuantity) pass else: self.value = ic pass pass pass pass else: memberShip(value,[PhysicalQuantity,ChemicalState]) if (isinstance(value, PhysicalQuantity) or type(value) is types.ListType): self.value_species,self.value_property = createList(value, PhysicalQuantity) pass else: self.value = value pass pass self.description = description return None
def __init__(self, alltype,facetype,quantity, support, name = None, unit=None, timeSpecification=None,where=None,variables=[]): """ExpectedOutput initialisation with : - all possible expected output quantity - expected output quantity which can be define with attribute 'where=face' or 'where = border' - an expected output quantity. - a support. Support depends on wanted quantity. If Flux, support is a tuple (boundary, zone) (possible type for boundary or for zone : MedSupport or CartesianMesh) If TotalFlux or TotalInflux, support can be MedSupport or CartesianMesh If other quantities, support can be MedSupport, CartesianMesh - OPTIONAL : --> a name (string). If None given, name is set to quantity --> a unit (string) --> where (string) : represents expected output localisation. It's only available if quantity is Pressure,, Saturation or DarcyVelocity and support is MedSupport or CartesianMesh and on all elements. Value can be center, face or border --> timeSpecification (TimeSpecification) : define times to get expected output --> variables (default value = []) : define specific wanted species """ if type(quantity) != StringType: raise TypeError(" quantity for CommonExpectedOutput_old should be a string") if quantity not in alltype: raise Exception("check the quantity you want to plot ") self.quantity = quantity partialtype = alltype[:] partialtype.remove('Flux') partialtype.remove('TotalFlux') partialtype.remove('TotalInflux') if self.quantity in partialtype: supports=toList(support) if len(supports) != 1: raise Exception(" the support has not the good length") verifyClassList(supports, [CartesianMesh]) for sup in supports: pass pass elif (self.quantity == 'Flux'): # Support should be TupleType of Boundary, Zone if type(support) != TupleType: raise TypeError(" support should be a tuple ") if (len(support) !=2): Message = repr(len(support[sup])) + ' MedSupport given, 2 wanted for a flux expected output' raise Message fzone = support[1] fbound = support[0] memberShip(fbound, MedSupport) memberShip(fzone, MedSupport) verifyZones(toList(fzone)) #verifyBoundaries(toList(fbound)) pass elif self.quantity in ['TotalFlux','TotalInflux']: supports=toList(support) if len(supports) !=1: raise Exception(" the support has not the good length ") # Support should be Zone verifyClassList(supports, [MedSupport, CartesianMesh]) for sup in supports: pass pass self.support = support if name: if type(name) != StringType: raise TypError("name should be a string within CommonExpectedOutput_old") self.name = name pass else: self.name = self.quantity # if unit: if type(unit) != StringType: raise typeError(" unit should be a string ") self.unit = unit if timeSpecification: from timespecification import TimeSpecification memberShip(timeSpecification, TimeSpecification) mode=timeSpecification.getSpecification() if mode not in ['frequency','period','times']: raise Exception(" check the mode argument in CommonExpectedOutput") pass self.timespecification = timeSpecification self.where=where if len(variables): from datamodel import Species verifyClassList(variables,Species) self.variables=variables
def setIntrinsicPermeability(self, intrinsicpermeability): """set intrinsic permeability""" memberShip(intrinsicpermeability, IntrinsicPermeability) self.intrinsicPermeability = intrinsicpermeability
def setPermeability(self, permeability): """set permeability property""" memberShip(permeability, Permeability) self.permeability = permeability
def setSaturationLaw(self, saturationLaw): """set saturation law""" memberShip(saturationLaw, SaturationLaw) self.saturationLaw = saturationLaw
def setSpecificStorage(self, SpecificStorage): """set SpecificStorage""" memberShip(SpecificStorage, SpecificStorage) self.specificStorage = SpecificStorage
def setMatrixCompressibilityFactor(self, matrixCompressibilityFactor): """set MatrixCompressibilityFactor""" memberShip(matrixCompressibilityFactor, MatrixCompressibilityFactor) self.matrixCompressibilityFactor = matrixCompressibilityFactor return
def __init__(self, radius, height): memberShip(radius, Length) self.radius = radius memberShip(height, Length) self.height = height return None
def __init__(self, boundary, btype, value, bcdict, porosity = None, description = None): """ Boundary condition initialisation with : - one boundary - a boundary condition type. We verify that it's a key of bcdict dictionnary - a boundary condition value. Value depend of boundary condition type. - bcdict : a dictionnary with key = type of boundary condition and value = Possible class of boundary condition value All boundary conditions satisfy that format. It should enable the lecture of hydraulic, mechanical and chemical-transport boundary conditions. Exemple: bcdict = {'Flux': [class chemistry.ChemicalState , class PhysicalQuantities.HeadGradient], 'Dirichlet': [class chemistry.ChemicalState, class PhysicalQuantities.Head,\ class PhysicalQuantities.Displacement, class PhysicalQuantities.NormalForce], 'Neumann': [class chemistry.ChemicalState, class PhysicalQuantities.HeadGradient]} """ self.value = None self.value_species = None #print " here we are 1, bcdict ", bcdict #print " here we are 2, bcdict ", bcdict.keys() #print value #raw_input() #print("dbg bcdict ",list(bcdict.keys())) if isInstance(boundary,[CartesianMesh, Body]): pass else: memberShip(boundary.support,[CartesianMesh, Body]) pass self.boundary = boundary if type(btype) != StringType: raise TypeError(" type should be a string ") if btype not in list(bcdict.keys()): print("bcdict.keys():",list(bcdict.keys())) print("btype : ",btype) raise Exception(" check the boundary condition type ") self.type = btype print("value: ",type(value.__class__.__name__),value.__class__.__name__) #print "dbg bcdict ",bcdict.keys() #raw_input( "valuefffffffff fff") #if value.__class__.__name__ == 'Head': # print "valueeeee Head",value.__class__.__name__ #else: # print "valueeeef",value.__class__.__name__ if isinstance(value,ListType): print(" value is of type ListType") for val in value: if isinstance(val,Displacement): self.value = {"Displacement":val.getValue()} pass elif isinstance(val,NormalForce): if self.value != None: self.value["NormalForce"] = val.getValue() pass else: self.value = {"NormalForce":val.getValue()} pass elif isinstance(value,Head): valeurs=toList (val) for vale in valeurs: if type(val) is TupleType: checked = val[0] for i in range(1,len(val)): memberShip(val[i], Species) pass pass else: checked = val pass pass pass elif isinstance(value,Displacement): print(" value is of type Displacement") self.value = {"Displacement":value.getValue()} pass elif isinstance(value,NormalForce): print(" value is of type NormalForce") if self.value != None: self.value["NormalForce"] = value.getValue() pass else: self.value = {"NormalForce":value.getValue()} pass pass elif isinstance(value,Head): print(" value is of type Head") from datamodel import Species value=toList (value) for val in value: if type(val) is TupleType: checked = val[0] for i in range(1,len(val)): memberShip(val[i], Species) pass pass else: checked = val pass for definedType in bcdict: if btype == definedType: memberShip(checked, bcdict[btype]) #raw_input("here we are") pass pass pass if not self.value_species: from PhysicalQuantities import PhysicalQuantity from species import createList print(value) self.value_species, self.value_property = createList(value, PhysicalQuantity) pass if description == None: self.description = None pass else: self.description = description pass return None
def setSolidDensity(self, solidDensity): """set solid density""" memberShip(solidDensity, SolidDensity) self.solidDensity = solidDensity
def __init__(self, zone, value,some_classes,some_solid_classes=None): """ Initial condition initialisation with - one or several zones - a value instance of a class defined in some_classes or a list of couple (Value,Species) or a list with a defaut value and couples (Value,Species) for example [c,(c1,species1),(c2,species2)] - some_classes : list of possible classes of value (soluble classes) - some_solid_classes : list of possible classes of value (solid classes) """ zones=toList(zone) #verifyZones(zones) self.zone = zone if some_solid_classes: all_classes = some_classes + some_solid_classes pass else: all_classes = some_classes pass val_solub=[] val_solid=[] self.value_species=[] self.value_property=[] self.value_solid_species=[] self.value_solid_property=[] value = toList(value) for val in value: solubOK = 0 if type(val) is TupleType: from datamodel import Species memberShip(val[0], all_classes) memberShip(val[1], Species) for sc in some_classes: if isInstance(val[0], sc): val_solub.append(val) solub0K = 1 break pass if some_solid_classes and not solubOK: for sc in some_solid_classes: if isInstance(val[0], sc): val_solid.append(val) break pass pass pass else: memberShip(val, all_classes) for sc in some_classes: if isInstance(val, sc): val_solub.append(val) solub0K = 1 break if some_solid_classes and not solubOK: for sc in some_solid_classes: if isInstance(val, sc): val_solid.append(val) break pass pass pass if val_solub: from datamodel import createList from datamodel import PhysicalQuantity self.value_species, self.value_property = createList(val_solub, PhysicalQuantity) pass if val_solid: from datamodel import createList from datamodel import PhysicalQuantity self.value_solid_species, self.value_solid_property = createList(val_solid, PhysicalQuantity) pass return
def __init__(self,\ name,\ saturation,\ regions,\ boundaryConditions,\ initialConditions = None,\ state = None,\ simulationType = None,\ calculationTimes = None,\ gravity = None,\ density = None,\ source = None,\ viscosity = None,\ outputs = None,\ description = None): """ Problem initialisation with : - name : name given by the user to the problem - saturation: determines the state to be modelled. Depending on the way the problem is defined, it can be modified. - boundary conditions: - initial conditions: - regions: all regions covering the entire mesh. Regions make up a partition of the mesh - gravity: default None - density: default None - viscosity: default None - sources default None - outputs default None """ # # name should be a string # if type(name) != bytes: raise TypeError("name should be a string ") self.name = name # # saturation # self.problemType = "saturated" self.saturation = "saturated" if type(saturation) == bytes: if saturation == "unsaturated" or saturation.lower()=="no": self.saturation = "unsaturated" self.problemType = "unsaturated" pass pass # # regions treatment # verifyClassList(regions, Region) regions_zones = [region.getZone() for region in regions] self.regions = regions # # gravity treatment # check = -1 if gravity: memberShip(gravity, Gravity) try: value=gravity.getValue() if type(value) not in [float, int]: raise TypeError(" value should be a float or an int ") meshdim = regions_zones[0].getSpaceDimension() value=[0.]*meshdim value[-1] = 9.81 if meshdim == 2: value.append(0.) gravity=Vector(value) except: pass pass else: meshdim = regions_zones[0].getSpaceDimension() value=[0.]*meshdim value[-1] = 9.81 if meshdim == 2: value.append(0.) gravity=Vector(value) print(value) self.gravity = gravity # # density treatment # if density: if type(density) == FloatType: density = Density(density, 'kg/m**3') memberShip(density, Density) check = 2*check pass self.density = density # # viscosity treatment # print(" dbg viscosity ",viscosity);#raw_input() if viscosity: if type(viscosity) == FloatType: viscosity = Viscosity(viscosity, 'kg/m/s') memberShip(viscosity, Viscosity) check = 3*check pass else: viscosity = Viscosity(1.0, 'kg/m/s') pass print(" dbg viscosity 1",viscosity);#raw_input() self.viscosity = viscosity # # Do we use intrinsic permeability # if self.saturation == "unsaturated": intrinsicPermeabilityCheck(self.regions, check) # # times definition # self.simulationType = simulationType # #raw_input("calculation times ") if calculationTimes: self.calculationTimes = calculationTimes self.simulationType = "Transient" pass else: self.calculationTimes = None self.simulationType = "Steady" pass self.steadyState = 1 if self.calculationTimes!= None: if type(calculationTimes) != list: raise TypeError(" calculationTimes should be a list ") CalculationTimes=toFloatList( self.calculationTimes) # for item in CalculationTimes: if type(item) != float: raise TypeError(" item should be a float ") pass self.calculationTimes = sorted( CalculationTimes) # print self.calculationTimes;#raw_input(" within the loop, calculation times are printed here") self.steadyState = 0 # The simulation is transient pass # # Permeability # if self.saturation == "unsaturated": # # only Richards for the moment # pass #raise Exception, " for the moment, undersaturated flows are not implemented" #regionPhysicalQuantitiesCheck([Permeability, IntrinsicPermeability], regions) # # boundaryConditions treatment # self.defaultBC = None boundaryConditions = toList(boundaryConditions) print(" problem type ",self.problemType) # raw_input(str(self.problemType)) print(dir(boundaryConditions[0])) # verification if all boundaries are treated. # If some are not, affect a default value (an homogeneous # neumann boundarycondition) boundaries = [] for boundaryElement in boundaryConditions: boundary = toList(boundaryElement.getBoundary()) for bound in boundary: boundaries.append(bound) pass # In case of structured mesh, not all the boundary could be defined for the problem if self.defaultBC: if not self.density: self.density = Density(1.) pass if not self.gravity: mesh_dim=regions[0].getZone().getMesh().getSpaceDimension() if mesh_dim==2: self.gravity=Gravity(Vector(0.,1.)) elif mesh_dim==3: self.gravity=Gravity(Vector(0.,0.,1.)) else: raise Warning('Dimension ????') pass pass # Verification if a pressure condition has been set # that density and gravity have been set # verifySomeOfPhysicalQuantitiesExists([Permeability, IntrinsicPermeability], regions) # verifyPressureBoundaryConditions(boundaryConditions, self.density, self.gravity) self.boundaryConditions = boundaryConditions # # initialConditions treatment # self.initialConditions = initialConditions # print " initialConditions",initialConditions;raw_input() # # source treatment # if source: verifyClassList(source, Source) self.source = source # # outputs treatment # if outputs: outputs1 = toList(outputs) verifyClassList(outputs1, _dicoproblem[type].ExpectedOutput) if not hasattr(self,'output_names'): self.output_names=[] for output in outputs1: if output.getName() in self.output_names: msg = '\n\nDifferent outputs should not share the same name.\n' msg+= 'End of the hydraulic problem run.\n\n' raise Warning(msg) self.output_names.append(output.getName()) pass # self.outputs = outputs return
def __init__(self, boundary, btype, value = None, massTCoef = None, velocity = None, flowRate = None, porosity = None, timeVariation = None, description = None): """ Constructor with : - boundary : a mesh part element of type Cartesian or Unstructured ( made of bodies) - btype : is a string and should be "Dirichlet", "Flux", "Mixed", "Neumann" For a "symmetry", a Neumann boundary condition with g = 0 must be specified - OPTIONAL : --> value : a PhysicalQuantity or a list of tuples (PhysicalQuantity,species) or a ChemicalState --> massTCoef : float : mass transfer coefficient or set to zero --> velocity : object Velocity --> porosity : a scalar. --> flowRate : a Flowrate, see PhysicalQuantities --> timeVariation : a list of tuples [(time,chemical state)] , [(time,(list of species and eventually temperature))]; the temperature can also be introduced through a file. -- description a string which will be eventually set as a support for the model comprehension """ bcDico = makeDico(Dirichlet = [ChemicalState, Head, Displacement, NormalForce],\ Flux = [ChemicalState, HeadGradient],\ Neumann = [ChemicalState, HeadGradient]) CommonBoundaryCondition.__init__(self,boundary, btype, value, bcDico, description) # print "dbg commonmodel CommonBoundaryCondition1" if type(boundary) is types.ListType: # print "type of boundary is list type " #raw_input("type of boundary is list type ") verifyClassList(boundary,[ CartesianMesh, Body]) pass else: memberShip(boundary,[ CartesianMesh, Body]) #raw_input("membership ") pass #raw_input("dbg commonmodel CommonBoundaryCondition2") self.boundary = boundary if type(btype) != types.StringType: raise TypeError, " problem on the definition of the boundary type " if btype.lower() not in ["dirichlet","symmetry","flux","mixed","neumann","noflux"]: raise Exception, " check the boundary condition kind" self.btype = btype self.chemicalStateValue = None self.headValue = None self.massTCoef = 0. self.value_species = None self.value_property = None self.value = None # # the next ones are linked to a well sim. # self.enthalpyBoundaryCondition = None self.wellMassFlowBoundaryCondition = None self.wellPressureBoundaryCondition = None # # We treat B.C. # by default, a chemical state is introduced # and in the case of a transient flow, eventually a list # made of a chemical state, a displacement, a head. # if type(value) is types.ListType: # # useful for debugging # #for i in value: # print "dbg commonmodel",type(i) # pass verifyClassList(value, [ Head, ChemicalState, Displacement, NormalForce, TupleType]) for bc in value: if isinstance(bc, Head): self.headValue = bc # it should be the charge pass elif isinstance(bc, NormalForce): self.normalForceValue = bc # it should be NormalForce pass elif isinstance(bc, Displacement): self.displacementValue = bc # it should be Displacement pass elif isinstance(bc, ChemicalState): self.value = bc self.chemicalStateValue = bc # it should be ChemicalState pass elif bc[0].lower() =="enthalpy": # it can also be an enthalpy in the # case of a well # if type(bc[1]) == types.StringType: self.enthalpyBoundaryCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'),bc[1]) pass elif type(bc[1]) in [types.FloatType,types.IntType]: self.enthalpyBoundaryCondition = bc[1] pass elif bc[0].lower() =="wellpressure": # it can also be the pressure in the # case of a well # if type(bc[1]) == types.StringType: self.wellPressureBoundaryCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'),bc[1]) pass elif type(bc[1]) in [types.FloatType,types.IntType]: self.wellPressureBoundaryCondition = bc[1] #print("commonmodel well pressure debug yes\n") #raw_input() pass pass elif bc[0].lower() =="wellmassflow": # it can also be the mass flow in the # case of a well # if type(bc[1]) == types.StringType: self.wellMassFlowBoundaryCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'),bc[1]) pass elif type(bc[1]) in [types.FloatType,types.IntType]: self.wellMassFlowBoundaryCondition = bc[1] pass pass else: #self.value = bc # it should be chemistry pass pass pass else: memberShip(value,[PhysicalQuantity, ChemicalState, Displacement, NormalForce]) if (isinstance(value, PhysicalQuantity) or type(value) is types.ListType): self.value_species, self.value_property = createList(value, PhysicalQuantity) pass else: self.value = value self.chemicalStateValue = value pass pass print "massTCoef",massTCoef,type(massTCoef) if massTCoef: memberShip(massTCoef,[types.FloatType]) if (type(massTCoef) is types.FloatType): self.massTCoef = massTCoef pass else: self.massTCoef = 0.0 pass print " common model mass transfer coefficient ",self.massTCoef pass if porosity: self.porosity = porosity pass if velocity: memberShip(velocity,Velocity) pass self.velocity = velocity if flowRate: if flowRate.__class__.__name__=="FlowRate": pass else: flowrate = FlowRate(flowrate,"m**3/s") # the flow rate is supposed to be in m**3/s pass self.flowRate = flowRate if timeVariation: if type(timeVariation) != types.ListType: raise typeError, " Time variation should be a list" for item in timeVariation: if type(item[0]) not in [types.FloatType,types.IntType]: raise typeError, "item[@] should be a list" memberShip(item[1],[ChemicalState]) pass pass self.timeVariation = timeVariation return None
def setProperty(self, keyword, property): """ To set a material property """ #print "dbg property: ",self.name, keyword,property.__class__ #raw_input("keyword property1") keyword = keyword.lower() if keyword not in list(self.propdict.keys()): print(list(self.propdict.keys())) raise Exception(" check the set property function, property: " + keyword) #print "dbg property: ",self.name, keyword,property.__class__ #raw_input("keyword property2") if isInstance( property, [PhysicalLaw, PQuantity, AquiferProperty, SolidProperty]): #print "setproperty propClass is ok " propClass = property.__class__ #raw_input("keyword property2 isInstance(property,[PhysicalLaw,PQuantity,AquiferProperty,SolidProperty])") pass elif type(property) is ListType: # # if property type is of ListType: : # # if we have as input : # ["Na", Prop('3.7), "Cl", Prop(3.8)] # it becomes # [("Na", Prop('3.7)), ("CL", Prop(3.8))] # #raw_input("keyword property3 type(property) is ListType") myProperty = [] aNewProp = [] for prop in property: if len(aNewProp) == 1: aNewProp.append(prop) myProperty.append(tuple(aNewProp)) aNewProp = [] pass from types import StringType if type(prop, StringType): if len(aNewProp) != 0: message = "\n\n" message += "Exception catched\n" message += "to improve ...\n" raise Exception(message) aNewProp.append(prop) pass pass if myProperty: property = myProperty pass # # property_buf = [] for prop in property: if isInstance( prop, [PhysicalLaw, PQuantity, AquiferProperty, SolidProperty]): property_buf.append(prop) pass elif type(prop, TupleType): if isInstance(prop[0], [ AquiferProperty, PhysicalLaw, PQuantity, SolidProperty ]): property_buf.append(prop) pass else: property_buf.append((prop[1], prop[0])) pass pass else: raise Exception( "object membership should be verified : %s" % prop) pass property = property_buf for prop in property: if isInstance( prop, [AquiferProperty, PhysicalLaw, PQuantity, SolidProperty]): propClass = prop.__class__ pass elif type(prop, TupleType): memberShip(prop[0], [ AquiferProperty, PhysicalLaw, PQuantity, SolidProperty ]) propClass = prop[0].__class__ if propClass == self.propdict[keyword]: PQ = propClass pass elif issubclass(propClass, self.propdict[keyword]): PQ = self.propdict[keyword] ## if propClass=='SolubilityByElement': ## print 'houla element' ## flag='SolubilityByElement' pass key = PQ.__name__ key = key[0].lower() + key[1:] if not hasattr(self, key + '_species'): raise Exception("No species allowed for %s" % key) pass else: raise Exception( "object membership should be verified : %s" % prop) pass pass else: if property: raise Exception("object membership should be verified : %s" % property) else: propClass = self.propdict[keyword] #propClass=property.__class__ #print (" dbg keyword ",keyword) #print (" dbg propClass ",propClass) #print (" dbg propdict ",self.propdict[keyword]) if propClass != self.propdict[keyword]: if not issubclass(propClass, self.propdict[keyword]): raise Exception(" problem with property class ") #self.changeProperty(propClass,property) self.changeProperty(self.propdict[keyword], property)
def setResidualSaturation(self, residualSaturation): """ That function enables to set the liquid residual saturation property """ memberShip(residualSaturation, ResidualSaturation) self.residualSaturation = residualSaturation
def __init__(self, body, value, description = None): """ constructor with : - body : object body or CartesianMesh - value : a PhysicalQuantity, a list of tuples (PhysicalQuantity,species) a ChemicalState or a tuple to introduce a function on a specific variable """ if type(body) is types.ListType: verifyClassList(body,[CartesianMesh]) pass else: memberShip(body,[CartesianMesh, Body]) pass self.zone = body self.body = body self.value_species = None self.value_property = None self.value = None self.enthalpyInitialCondition = None self.headValue = None self.temperatureInitialCondition = None self.wellMassFlowInitialCondition = None self.wellPressureInitialCondition = None if type(value) is types.ListType: for i in value: print ("dbg commonmodel",type(i)) pass verifyClassList(value, [ Head, ChemicalState, Displacement, types.TupleType]) for ic in value: if isinstance(ic, Head): self.headValue = ic # it should be the charge pass elif isinstance(ic, (Displacement,ChemicalState)) : self.value = ic # it should be chemistry or a displacement pass elif isinstance(ic, types.TupleType): #print("debug commonmodel ic %s\n"%(ic[0].lower())) if ic[0].lower() =="temperature": # it should be temperature otherwise a warning # is raised. we extract the formula thanks to != # regular expressions modules. # if type(ic[1]) == types.StringType: self.temperatureInitialCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'),ic[1]) pass pass elif ic[0].lower() =="enthalpy": # it can also be an enthalpy in the # case of a well # if type(ic[1]) == types.StringType: #raw_input("common model debug") self.enthalpyInitialCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'),ic[1]) pass pass elif ic[0].lower() =="wellpressure": # it can also be the pressure in the # case of a well # if type(ic[1]) == types.StringType: self.wellPressureInitialCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'),ic[1]) pass elif type(ic[1]) in [types.FloatType,types.IntType]: self.wellPressureInitialCondition = ic[1] #print("commonmodel well pressure debug yes\n") #raw_input() pass pass elif ic[0].lower() =="wellmassflow": # it can also be the mass flow in the # case of a well # if type(ic[1]) == types.StringType: self.wellMassFlowInitialCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'),ic[1]) pass elif type(ic[1]) in [types.FloatType,types.IntType]: self.wellMassFlowInitialCondition = ic[1] pass pass else: raise Warning, "check the name of the vriable " pass else: if (isinstance(ic, PhysicalQuantity) or type(ic) is types.ListType): self.value_species, self.value_property = createList(ic, PhysicalQuantity) pass else: self.value = ic pass pass pass pass else: memberShip(value,[PhysicalQuantity,ChemicalState]) if (isinstance(value, PhysicalQuantity) or type(value) is types.ListType): self.value_species,self.value_property = createList(value, PhysicalQuantity) pass else: self.value = value pass pass self.description = description return None
def setResidualWaterContent(self, residualWaterContent): """ That function enables to set the liquid residual water content property """ memberShip(residualWaterContent, ResidualWaterContent) self.residualWaterContent = residualWaterContent
def __init__(self, boundary, btype, value = None, massTCoef = None, velocity = None, flowRate = None, porosity = None, timeVariation = None, description = None): """ Constructor with : - boundary : a mesh part element of type Cartesian or Unstructured ( made of bodies) - btype : is a string and should be "Dirichlet", "Flux", "Mixed", "Neumann" For a "symmetry", a Neumann boundary condition with g = 0 must be specified - OPTIONAL : --> value : a PhysicalQuantity or a list of tuples (PhysicalQuantity,species) or a ChemicalState --> massTCoef : float : mass transfer coefficient or set to zero --> velocity : object Velocity --> porosity : a scalar. --> flowRate : a Flowrate, see PhysicalQuantities --> timeVariation : a list of tuples [(time,chemical state)] , [(time,(list of species and eventually temperature))]; the temperature can also be introduced through a file. -- description a string which will be eventually set as a support for the model comprehension """ bcDico = makeDico(Dirichlet = [ChemicalState, Head, Displacement, NormalForce],\ Flux = [ChemicalState, HeadGradient],\ Neumann = [ChemicalState, HeadGradient]) CommonBoundaryCondition.__init__(self,boundary, btype, value, bcDico, description) # print "dbg commonmodel CommonBoundaryCondition1" if type(boundary) is types.ListType: # print "type of boundary is list type " #raw_input("type of boundary is list type ") verifyClassList(boundary,[ CartesianMesh, Body]) pass else: memberShip(boundary,[ CartesianMesh, Body]) #raw_input("membership ") pass #raw_input("dbg commonmodel CommonBoundaryCondition2") self.boundary = boundary if type(btype) != types.StringType: raise TypeError, " problem on the definition of the boundary type " if btype.lower() not in ["dirichlet","symmetry","flux","mixed","neumann","noflux"]: raise Exception, " check the boundary condition kind" self.btype = btype self.chemicalStateValue = None self.headValue = None self.massTCoef = 0. self.value_species = None self.value_property = None self.value = None # # the next ones are linked to a well sim. # self.enthalpyBoundaryCondition = None self.wellMassFlowBoundaryCondition = None self.wellPressureBoundaryCondition = None # # We treat B.C. # by default, a chemical state is introduced # and in the case of a transient flow, eventually a list # made of a chemical state, a displacement, a head. # if type(value) is types.ListType: # # useful for debugging # #for i in value: # print "dbg commonmodel",type(i) # pass verifyClassList(value, [ Head, ChemicalState, Displacement, NormalForce, TupleType]) for bc in value: if isinstance(bc, Head): self.headValue = bc # it should be the charge pass elif isinstance(bc, NormalForce): self.normalForceValue = bc # it should be NormalForce pass elif isinstance(bc, Displacement): self.displacementValue = bc # it should be Displacement pass elif isinstance(bc, ChemicalState): self.value = bc self.chemicalStateValue = bc # it should be ChemicalState pass elif bc[0].lower() == "enthalpy": # it can also be an enthalpy in the # case of a well # if type(bc[1]) == types.StringType: self.enthalpyBoundaryCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'),bc[1]) pass elif type(bc[1]) in [types.FloatType,types.IntType]: self.enthalpyBoundaryCondition = bc[1] pass elif bc[0].lower() == "wellpressure": # it can also be the pressure in the # case of a well # if type(bc[1]) == types.StringType: self.wellPressureBoundaryCondition = refindall(recompile(r'([xyzXYZ0-9.*/+-])'),bc[1]) pass elif type(bc[1]) in [types.FloatType,types.IntType]: self.wellPressureBoundaryCondition = bc[1] #print("commonmodel well pressure debug yes\n") #raw_input() pass pass elif bc[0].lower() == "wellmassflow": # it can also be the mass flow in the # case of a well # if type(bc[1]) == types.StringType: self.wellMassFlowBoundaryCondition = refindall(recompile(r'([$mfunction()ifelse{} ><_=xyzXYZ0-9.*/+-])'),bc[1]) pass elif type(bc[1]) in [types.FloatType,types.IntType]: self.wellMassFlowBoundaryCondition = bc[1] pass elif type(bc[1]) is tuple: self.wellMassFlowBoundaryCondition = bc[1] pass pass else: #self.value = bc # it should be chemistry pass pass pass else: memberShip(value,[PhysicalQuantity, ChemicalState, Displacement, NormalForce]) if (isinstance(value, PhysicalQuantity) or type(value) is types.ListType): self.value_species, self.value_property = createList(value, PhysicalQuantity) pass else: self.value = value self.chemicalStateValue = value pass pass print "massTCoef",massTCoef,type(massTCoef) if massTCoef: memberShip(massTCoef,[types.FloatType]) if (type(massTCoef) is types.FloatType): self.massTCoef = massTCoef pass else: self.massTCoef = 0.0 pass print " common model mass transfer coefficient ",self.massTCoef pass if porosity: self.porosity = porosity pass if velocity: memberShip(velocity,Velocity) pass self.velocity = velocity if flowRate: if flowRate.__class__.__name__=="FlowRate": pass else: flowrate = FlowRate(flowrate,"m**3/s") # the flow rate is supposed to be in m**3/s pass self.flowRate = flowRate if timeVariation: if type(timeVariation) != types.ListType: raise typeError, " Time variation should be a list" for item in timeVariation: if type(item[0]) not in [types.FloatType,types.IntType]: raise typeError, "item[@] should be a list" memberShip(item[1],[ChemicalState]) pass pass self.timeVariation = timeVariation return None
def setMaximumSaturation(self, maximumSaturation): """ That function enables to set the liquid saturated property """ memberShip(maximumSaturation, MaximumSaturation) self.maximumSaturation = maximumSaturation
def __init__(self, length): memberShip(length, Length) self.length = length return None
def __init__(self, alltype, facetype, quantity, support = None, name = None, unit = None, timeSpecification = None, where = None, unknown = [],save = 'memory',chemical = 0): if type(quantity) != StringType: raise TypeError(" the quantity must be a string ") alltypeupper = [q.upper() for q in alltype] #print "alltypeupper",alltypeupper quantityupper = quantity.upper() if quantityupper not in alltypeupper: raise Exception("the quantity "+quantityupper+" must be checked in Output") self.quantity = quantity mecanic = ( chemical == 2) chemical = (chemical == 1) hydrau_transport_type = ['HEAD','PRESSURE','DARCYVELOCITY','SATURATION','CONCENTRATION','SOLIDCONCENTRATION'] if quantityupper in hydrau_transport_type and not chemical: supports=toList(support) if len(supports) != 1: raise Exception("The support hans not the good length") # Support should be Point or Zone verifyClassList(supports, [CartesianMesh]) pass elif (quantityupper == 'FLUX'): # Support should be TupleType of Boundary, Zone if type(support) != TupleType: raise TypeError(" support should be a tuple ") if (len(support) !=2): raise Exception("support must have a length of 2") fzone = support[1] fbound = support[0] fbounds = toList(fbound) entity = fbounds[0].getMesh().getBoundariesEntity() memberShip(fbound, MedSupport) memberShip(fzone, MedSupport) verifyZones(toList(fzone)) # verifyBoundaries verify now that bounds are borders. We use verifySupports in place verifySupports(fbounds,entity) pass elif quantityupper in ['TOTALFLUX','TOTALINFLUX']: supports=toList(support) if len(supports) != 1: raise Exception("the support has not the good length") # Support should be Zone verifyClassList(supports, [CartesianMesh]) pass else: if support and chemical: # chemical transport quantity : support is optionnal memberShip(support, [CartesianMesh]) pass elif mecanic: # mecanic quantity : support class is verified by XData pass pass self.support = support if name: if type(name) != StringType: raise TypeError("the name of a CommonExpectedOutput must be a string") self.name = name pass else: self.name = self.quantity pass # if unit: if type(unit) != StringType: raise TypeError(" unit should be a string ") self.unit = unit if timeSpecification: from timespecification import TimeSpecification memberShip(timeSpecification, TimeSpecification) mode=timeSpecification.getSpecification() if mode not in ['frequency','period','times']: raise Exception(" check the mode argument in CommonExpectedOutput") pass self.timeSpecification = timeSpecification self.where=where if save: if save not in ['memory','file']: raise Exception(" check the save argument in CommonExpectedOutput") pass self.save = save if unknown: if chemical: if type(unknown) is ListType: for unbekannte in unknown: if type(unbekannte) != StringType: raise TypeError(" unknown should be a string ") pass pass pass else: if type(unknown) != StringType: raise TypeError(" the unknown must be a string ") pass pass elif mecanic: unknown=toList(unknown) for u in unknown: if type(u) != StringType: raise TypeError(" u should be a string ") pass pass else: from datamodel import Species verifyClassList(unknown,Species) pass pass self.unknown=unknown
def __init__(self,\ name,\ regions,\ boundaryConditions,\ initialConditions = None,\ state = None,\ simulationType = None,\ calculationTimes = None,\ gravity = None,\ density = None,\ sources = None,\ outputs = None,\ description = None): """ Problem initialisation with : - name : name given by the user to the problem - saturation: determines the state to be modelled. Depending on the way the problem is defined, it can be modified. - boundary conditions: - initial conditions: - regions: all regions covering the entire mesh. Regions make up a partition of the mesh - gravity: default None - density: default None - sources default None - outputs default None """ # # name should be a string # if type(name) != bytes: raise TypeError("name should be a string ") self.name = name # # mechanical # self.problemType = "elasticity" # # regions treatment # verifyClassList(regions, Region) regions_zones = [region.getZone() for region in regions] self.regions = regions # # gravity treatment # check = -1 if gravity: memberShip(gravity, Gravity) try: value = gravity.getValue() if type(value) not in [float, int]: raise TypeError(" value should be a float or an int ") meshdim = regions_zones[0].getSpaceDimension() value = [0.] * meshdim value[-1] = 9.81 if meshdim == 2: value.append(0.) gravity = Vector(value) except: pass pass else: meshdim = regions_zones[0].getSpaceDimension() value = [0.] * meshdim value[-1] = 9.81 if meshdim == 2: value.append(0.) pass gravity = Vector(value) print(value) pass # self.gravity = gravity # # density treatment # if density: if type(density) == FloatType: density = Density(density, 'kg/m**3') pass memberShip(density, Density) check = 2 * check pass self.solidDensity = density # # times definition # self.simulationType = simulationType # #raw_input("calculation times ") if calculationTimes: self.calculationTimes = calculationTimes self.simulationType = "Transient" pass else: self.calculationTimes = None self.simulationType = "Steady" pass self.steadyState = 1 if self.calculationTimes != None: if type(calculationTimes) != list: raise typeError(" calculationTimes should be a list ") CalculationTimes = toFloatList(self.calculationTimes) # for item in CalculationTimes: if type(item) != float: raise TypeError(" item should be a float ") pass self.calculationTimes = sorted(CalculationTimes) # print self.calculationTimes;#raw_input(" within the loop, calculation times are printed here") # # The simulation is transient # self.steadyState = 0 pass # # boundaryConditions treatment # self.defaultBC = None boundaryConditions = toList(boundaryConditions) print(" problem type ", self.problemType) print(dir(boundaryConditions[0])) # # boundaryConditions treatment # boundaries = [] for boundaryElement in boundaryConditions: boundary = toList(boundaryElement.getBoundary()) for bound in boundary: boundaries.append(bound) pass pass if self.defaultBC: if not self.density: self.density = Density(1.) pass if not self.gravity: mesh_dim = regions[0].getZone().getMesh().getSpaceDimension() if mesh_dim == 2: self.gravity = Gravity(Vector(0., 1.)) pass elif mesh_dim == 3: self.gravity = Gravity(Vector(0., 0., 1.)) pass else: raise Exception('Dimension ????') pass pass self.boundaryConditions = boundaryConditions # # initialConditions treatment # self.initialConditions = initialConditions # # sources treatment # if sources: verifyClassList(sources, Source) self.sources = sources # # outputs treatment # if outputs: outputs1 = toList(outputs) verifyClassList(outputs1, _dicoproblem[type].ExpectedOutput) if not hasattr(self, 'output_names'): self.output_names = [] pass for output in outputs1: if output.getName() in self.output_names: msg = '\n\nDifferent outputs should not share the same name.\n' msg += 'End of the hydraulic problem run.\n\n' raise Exception(msg) self.output_names.append(output.getName()) pass # self.outputs = outputs # return None