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 setRegions(self,regions): """ set ChemicalTransportProblem regions """ verifyClassList(regions, Region) self.regions = regions return
def setBoundaryConditions(self, boundaryConditions): """ set ChemicalTransportProblem boundary conditions """ verifyClassList(boundaryConditions, BoundaryCondition) self.boundaryConditions = boundaryConditions return
def setRegions(self, regions): """ set ChemicalTransportProblem regions """ verifyClassList(regions, Region) self.regions = regions return
def setBoundaryConditions(self,boundaryConditions): """ set ChemicalTransportProblem boundary conditions """ verifyClassList(boundaryConditions, BoundaryCondition) self.boundaryConditions = boundaryConditions return
def setInitialConditions(self, initialConditions): """ Get ChemicalTransportProblem initial conditions Ouput : (list of InitialCondition) """ verifyClassList(initialConditions, InitialCondition) self.initialConditions = initialConditions return
def setSources(self,sources): """ set ChemicalTransportProblem sources """ if sources != None: verifyClassList(sources, Source) pass self.sources = sources return
def setSpeciesBaseAddenda(self,speciesBaseAddenda): """ set ChemicalTransportProblem new species """ if speciesBaseAddenda != None: verifyClassList(speciesBaseAddenda, Species) pass self.speciesBaseAddenda = speciesBaseAddenda return
def setSpeciesBaseAddenda(self, speciesBaseAddenda): """ set ChemicalTransportProblem new species """ if speciesBaseAddenda != None: verifyClassList(speciesBaseAddenda, Species) pass self.speciesBaseAddenda = speciesBaseAddenda return
def setSources(self, sources): """ set ChemicalTransportProblem sources """ if sources != None: verifyClassList(sources, Source) pass self.sources = sources return
def setKineticLaws(self,kineticLaws): """ set ChemicalTransportProblem kinetic laws """ if kineticLaws != None : verifyClassList(kineticLaws,KineticLaw) self.kineticLaws = kineticLaws pass else : self.kineticLaws = None pass return
def setKineticLaws(self, kineticLaws): """ set ChemicalTransportProblem kinetic laws """ if kineticLaws != None: verifyClassList(kineticLaws, KineticLaw) self.kineticLaws = kineticLaws pass else: self.kineticLaws = None pass return
def setOutputs(self,outputs=None): """ Get ChemicalTransportProblem expected outputs Ouput : (None or list of expectedOuputs) """ if outputs != None : verifyClassList(outputs, ExpectedOutput) self.outputs = outputs pass else : self.outputs = None pass return None
def setOutputs(self, outputs=None): """ Get ChemicalTransportProblem expected outputs Ouput : (None or list of expectedOuputs) """ if outputs != None: verifyClassList(outputs, ExpectedOutput) self.outputs = outputs pass else: self.outputs = None pass return None
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 __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 __init__(self,\ name,\ saturation,\ regions,\ boundaryConditions,\ initialConditions = None,\ state = None,\ simulationType = None,\ calculationTimes = None,\ gravity = None,\ density = None,\ source = None,\ intrinsicPermeability = 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 - intrinsicPermeability: 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) pass 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 # # intrinsicPermeability treatment # the introduction of the intrinsic permeability # is related to the introduction of the openfoam solver. # #print (intrinsicPermeability) #print (type(intrinsicPermeability)) #raw_input("problem type intrinsicPermeability") if intrinsicPermeability: if type(intrinsicPermeability) == FloatType: intrinsicPermeability = IntrinsicPermeability( intrinsicPermeability, 'm**2') memberShip(intrinsicPermeability, IntrinsicPermeability) check = 2 * check pass self.intrinsicPermeability = intrinsicPermeability #print (intrinsicPermeability) #print (type(intrinsicPermeability)) #raw_input("problem type intrinsicPermeability b") # # 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 pass # self.outputs = outputs return
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,\ calculationTimes,\ chemistryDB,\ darcyVelocity = None, # darcy velocity speciesBaseAddenda = None,\ kineticLaws = None,\ timeUnit = None, \ activityLaw = None,\ porosityState = None,\ headVPorosity = None, state = None,\ simulationType = None,\ gravity = None,\ density = None,\ diffusionLaw = None,\ permeabilityLaw = None,\ sources = None,\ outputs = None,\ userProcessing = None,\ userFunctionList = None,\ variablePorosity = None,\ variableElasticity = None,\ temperature = 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 # # Elsasticy modulus variation # self.variableElasticity = variableElasticity # # # self.mpiEnv = None # simulation times to be recovered if type(calculationTimes) != list: raise TypeError(" simulationTimes must be a list of times ") i = 0 for item in calculationTimes: if type(item) not in [float,int]: raise TypeError(" calculationTimes must be a list of times ") calculationTimes[i] = calculationTimes[i] i += 1 pass previous = calculationTimes[0] for item in calculationTimes: if item < 0.: raise Exception('Error : Negative calculation time unexpected') if item < previous: raise Exception('Error : Decreasing calculation time unexpected') previous = item self.calculationTimes = calculationTimes pass # # we dont' consider a wellbore # self.wellbore = False # # species Addenda # if speciesBaseAddenda not in [None,[]]: verifyClassList(speciesBaseAddenda, Species) self.speciesBaseAddenda = speciesBaseAddenda pass else: self.speciesBaseAddenda = [] pass if type(name) != bytes: raise TypeError("name should be a string ") self.name = name # # mechanical # self.problemType = "thmc" # # Darcy and seepage Velocity treatment : # if isinstance(darcyVelocity,Velocity): self.darcyVelocity = darcyVelocity # elif isinstance(seepageVelocity,Velocity): # self.darcyVelocity = seepageVelocity # warnings.warn("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\ # seepage velocity is not handled and is equivalent to Darcy velocity for Elmer\n\ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n") elif type(darcyVelocity) == bytes: if darcyVelocity.lower() == "read": # # The Darcy velocity will be read from # the velocity.ep file # self.darcyVelocity = "read" pass elif darcyVelocity.lower() == "computed": # the Darcy velocity is transient self.darcyVelocity = "computed" pass else: self.darcyVelocity = None pass # # data Base # if type(chemistryDB) != bytes: raise TypeError("The chemistryDB argument of the THMC Problem must be a string ") self.chemistryDB = chemistryDB # # 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) pass # self.gravity = gravity # # activity law # if activityLaw: if not isinstance(activityLaw,ActivityLaw): raise Exception(" the activity law instantiation must be checked") ## else: ## self.activityLaw = TruncatedDavies() pass self.activityLaw = activityLaw # # density treatment # if density: if type(density) in [int,float]: density = Density(density, 'kg/m**3') memberShip(density, Density) check = 2*check pass self.solidDensity = density # # variable porosity: diffusion law # if diffusionLaw: if not isinstance(diffusionLaw,EffectiveDiffusionLaw): raise Exceptio(" the diffusion law instanciation must be checked") pass self.diffusionLaw = diffusionLaw self.permeabilityLaw = permeabilityLaw if headVPorosity!= None: if headVPorosity not in ["constant","variable","constante"]: self.headVPorosity = "constant" pass else: self.headVPorosity = headVPorosity pass else: self.headVPorosity = "constant" pass # # user processing set up # if userProcessing and type(userFunctionList) == types.ListType: self.userProcessing = True self.processingList = userFunctionList for processingFunction in range(len(self.processingList)): self.processingList[processingFunction]+="(self)" print(self.processingList[processingFunction]) pass pass else: self.userProcessing = False self.processingList = None pass # # Kinetics Laws # if kineticLaws != None : verifyClassList(kineticLaws, KineticLaw) self.kineticLaws = kineticLaws pass else : self.kineticLaws = None pass # # times definition # self.simulationType = simulationType # #raw_input("calculation times ") if calculationTimes: self.calculationTimes = calculationTimes self.simulationType = "Transient" else: self.calculationTimes = None self.simulationType = "Steady" 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 ") self.calculationTimes = sorted( CalculationTimes) # # 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 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 self.boundaryConditions = boundaryConditions # # initialConditions treatment # self.initialConditions = initialConditions # # variable porosity # if porosityState: if type(porosityState) != bytes: raise TypeError(" the porosityState argument of the ChemicalTransportProblem must be a string ") porosityState = porosityState.lower() if (porosityState == 'constant') or (porosityState == 'variable'): self.porosityState = porosityState pass elif porosityState in ['steady',"cst"]: self.porosityState = 'constant' elif porosityState in ['transient',"var"]: self.porosityState = 'constant' else: ## self.porosityState = None mess = "porosityState badly defined (default : 'constant', else 'variable')" raise mess pass else: self.porosityState = 'constant' pass # # sources treatment # if sources != None: verifyClassList(sources, Source) self.sources = sources pass else : self.sources = None pass # # temperature # if temperature == None: self.temperature = "constant" pass else: self.temperature = temperature pass # # time unit # if timeUnit: if type(timeUnit) != bytes: raise TypeError(" the time unit argument of the ChemicalTransportProblem must be a string ") pass self.timeUnit = timeUnit # # outputs treatment # if outputs: outputs1 = toList(outputs) verifyClassList(outputs1, 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 msg self.output_names.append(output.getName()) pass # self.outputs = outputs # 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, 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 __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, 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,\ 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
def __init__(self, name, regions, boundaryConditions, initialConditions, calculationTimes, chemistryDB, sources = None, darcyVelocity = None, # darcy velocity seepageVelocity = None, speciesBaseAddenda = None, kineticLaws = None, timeUnit = None, activityLaw = None, # variable porosity porosityState = None, headVPorosity = None, mpiSize = None, gaseousDiffusion = None, # variable porosity and variable diffusion diffusionLaw = None, permeabilityLaw = None, outputs = None, userProcessing = None, userFunctionList = None, # a list of user defined functions to enable interactivity with the module. variablePorosity = None, wellbore = None, # wellbore analysis (1D) saturation = None, temperature = None, temperatureField = None, outputTimeStudy = None) : self.mpiEnv = None environ["MPIROOT"] = "" self.outputTimeStudy = outputTimeStudy print("dbg argv ",argv) #raw_input("problem") if mpiSize!=None: self.mpiEnv = 1 environ["MPIROOT"] = "MPI" print("mpi is in argv ",argv,system("echo $MPIROOT")) else: system("unset MPIROOT") #raw_input("argv") # # gas diffusion in water set by default to the CO2(g) one # at 25°C, expressed in S.I. units (m2/s) if gaseousDiffusion == None: self.gaseousDiffusion = EffectiveDiffusion(1.91e-9,unit="m**2/s") pass else: self.gaseousDiffusion = gaseousDiffusion pass # # the problem is saturated # self.saturation = "saturated" # name if type(name) != bytes: raise TypeError("the name of the ChemicalTransportProblem must be a string ") self.name = name # boundary conditions #print " dbg bd",dir(boundaryConditions[0]) #print " dbg bd",boundaryConditions[0].type #print " dbg bd",boundaryConditions[0].value #print " dbg bd",boundaryConditions[0].headValue #raw_input() verifyClassList(boundaryConditions, BoundaryCondition) self.boundaryConditions = boundaryConditions # # regions # verifyClassList(regions, Region) self.regions = regions # # Darcy and seepage Velocity treatment: # # Darcy vel. = porosity * seepage vel. # # if isinstance(darcyVelocity,Velocity): self.darcyVelocity = darcyVelocity pass elif isinstance(seepageVelocity,Velocity): self.darcyVelocity = seepageVelocity warnings.warn("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\ seepage velocity is for the moment identified with Darcy velocity for Elmer \n\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n") pass elif type(darcyVelocity) == bytes: if darcyVelocity.lower() == "read": # # The Darcy velocity will be read from # the velocity.ep file # self.darcyVelocity = "read" pass elif darcyVelocity.lower() == "computed": # the Darcy velocity is transient self.darcyVelocity = "computed" # # we check that materials contain relevant properties # meshdim = self.regions[0].support.getSpaceDimension() for region in self.regions: meshdim = max(meshdim,region.support.getSpaceDimension()) verifyPhysicalQuantityOnRegion(["porosity"],region) if region.getMaterial().getHydraulicConductivity(): continue if region.getMaterial().getIntrinsicPermeability() == None and region.getMaterial().getPermeability() == None: raise Exception(" the permeability or the intrinsic permeability should be set") elif (self.permeability and self.intrinsicPermeability): raise Exception("A Material with both permeability and intrinsicpermeability can\'t be defined") self.meshdim = meshdim # # default values are set here for density, gravity and density # value=[0.]*meshdim value[-1] = 9.81 if meshdim == 2: value.append(0.) gravity=Vector(value) self.gravity = gravity self.density = Density(1.0,'kg/l') self.viscosity = Viscosity(1.0,'kg/m/s') else: self.darcyVelocity = None pass # # data Base # if type(chemistryDB) != bytes: raise TypeError(" the chemistryDB argument of the ChemicalTransportProblem must be a string ") self.chemistryDB = chemistryDB # # initial conditions # verifyClassList(initialConditions, InitialCondition) self.initialConditions = initialConditions # # Sources # if sources != None: verifyClassList(sources, Source) self.sources = sources pass else : self.sources = None pass # simulation times to be recovered if type(calculationTimes) != list: raise TypeError(" simulationTimes must be a list of times ") i = 0 for item in calculationTimes: if type(item) not in [float,int]: raise TypeError(" calculationTimes must be a list of times ") calculationTimes[i] = calculationTimes[i] i += 1 pass previous = calculationTimes[0] for item in calculationTimes: if item < 0.: raise Exception('Error : Negative calculation time unexpected') if item < previous: raise Exception('Error : Decreasing calculation time unexpected') previous = item self.calculationTimes = calculationTimes pass # New chemical species if speciesBaseAddenda not in [None,[]]: verifyClassList(speciesBaseAddenda, [Salt,Species]) self.speciesBaseAddenda = speciesBaseAddenda pass else: self.speciesBaseAddenda = [] pass # Kinetics Laws if kineticLaws != None : verifyClassList(kineticLaws,KineticLaw) self.kineticLaws = kineticLaws pass else : self.kineticLaws = None pass # time unit if timeUnit: if type(timeUnit) != bytes: raise TypeError(" the time unit argument of the ChemicalTransportProblem must be a string ") pass self.timeUnit = timeUnit # # Activity Law # TODO : check the default activity law # if activityLaw: if not isinstance(activityLaw,ActivityLaw): raise Exception(" the activity law instantiation must be checked") ## else: ## self.activityLaw = TruncatedDavies() pass self.activityLaw = activityLaw # # variable porosity # if porosityState: if type(porosityState) != bytes: raise TypeError(" the porosityState argument of the ChemicalTransportProblem must be a string ") porosityState = porosityState.lower() if (porosityState == 'constant') or (porosityState == 'variable'): self.porosityState = porosityState pass elif porosityState in ['steady',"cst"]: self.porosityState = 'constant' pass elif porosityState in ['transient',"var"]: self.porosityState = 'constant' pass else: ## self.porosityState = None mess = "porosityState badly defined (default : 'constant', else 'variable')" raise mess pass else: self.porosityState = 'constant' pass # # user processing set up # if userProcessing and type(userFunctionList) == ListType: self.userProcessing = True self.processingList = userFunctionList for processingFunction in range(len(self.processingList)): self.processingList[processingFunction]+="(self)" print(self.processingList[processingFunction]) pass pass elif type(userFunctionList) == ListType: self.userProcessing = True self.processingList = userFunctionList for processingFunction in range(len(self.processingList)): self.processingList[processingFunction]+="(self)" print(self.processingList[processingFunction]) pass pass else: self.userProcessing = False self.processingList = None pass # # variable porosity: diffusion law # if diffusionLaw: if not isinstance(diffusionLaw,EffectiveDiffusionLaw): raise Exceptio(" the diffusion law instanciation must be checked") pass self.diffusionLaw = diffusionLaw self.permeabilityLaw = permeabilityLaw if headVPorosity!= None: if headVPorosity not in ["constant","variable","constante"]: self.headVPorosity = "constant" pass else: self.headVPorosity = headVPorosity pass else: self.headVPorosity = "constant" pass # Outputs if outputs != None : verifyClassList(outputs, ExpectedOutput) self.outputs = outputs pass else : self.outputs = None pass # timeVaryingBoundaryConditionList self.timeBoundaryConditionVariation = None # Mpi print("environ ",environ.get('WMPI')) # if environ.get('WMPI') != None: # opts = argv[:] # self.mpiSize = argv[1] # print "self.mpiSize ",self.mpiSize # else : # self.mpiSize = None self.mpiSize = mpiSize #temperature is by default constant if temperature == None: self.temperature = "constant" pass else: self.temperature = temperature pass if temperatureField == None: self.temperatureField = None pass else: self.temperatureField = temperatureField pass # # wellbore analysis # self.wellbore = wellbore return None
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 __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 __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 __init__( self, name, regions, boundaryConditions, initialConditions, calculationTimes, chemistryDB, sources=None, darcyVelocity=None, # darcy velocity seepageVelocity=None, speciesBaseAddenda=None, kineticLaws=None, timeUnit=None, activityLaw=None, # variable porosity porosityState=None, headVPorosity=None, mpiSize=None, gaseousDiffusion=None, # variable porosity and variable diffusion diffusionLaw=None, permeabilityLaw=None, outputs=None, userProcessing=None, userFunctionList=None, # a list of user defined functions to enable interactivity with the module. variablePorosity=None, wellbore=None, # wellbore analysis (1D) saturation=None, temperature=None, temperatureField=None, outputTimeStudy=None): self.mpiEnv = None environ["MPIROOT"] = "" self.outputTimeStudy = outputTimeStudy print("dbg argv ", argv) #raw_input("problem") if mpiSize != None: self.mpiEnv = 1 environ["MPIROOT"] = "MPI" print("mpi is in argv ", argv, system("echo $MPIROOT")) else: system("unset MPIROOT") #raw_input("argv") # # gas diffusion in water set by default to the CO2(g) one # at 25°C, expressed in S.I. units (m2/s) if gaseousDiffusion == None: self.gaseousDiffusion = EffectiveDiffusion(1.91e-9, unit="m**2/s") pass else: self.gaseousDiffusion = gaseousDiffusion pass # # the problem is saturated # self.saturation = "saturated" # name if type(name) != bytes: raise TypeError( "the name of the ChemicalTransportProblem must be a string ") self.name = name # boundary conditions #print " dbg bd",dir(boundaryConditions[0]) #print " dbg bd",boundaryConditions[0].type #print " dbg bd",boundaryConditions[0].value #print " dbg bd",boundaryConditions[0].headValue #raw_input() verifyClassList(boundaryConditions, BoundaryCondition) self.boundaryConditions = boundaryConditions # # regions # verifyClassList(regions, Region) self.regions = regions # # Darcy and seepage Velocity treatment: # # Darcy vel. = porosity * seepage vel. # # if isinstance(darcyVelocity, Velocity): self.darcyVelocity = darcyVelocity pass elif isinstance(seepageVelocity, Velocity): self.darcyVelocity = seepageVelocity warnings.warn( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\ seepage velocity is for the moment identified with Darcy velocity for Elmer \n\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" ) pass elif type(darcyVelocity) == bytes: if darcyVelocity.lower() == "read": # # The Darcy velocity will be read from # the velocity.ep file # self.darcyVelocity = "read" pass elif darcyVelocity.lower( ) == "computed": # the Darcy velocity is transient self.darcyVelocity = "computed" # # we check that materials contain relevant properties # meshdim = self.regions[0].support.getSpaceDimension() for region in self.regions: meshdim = max(meshdim, region.support.getSpaceDimension()) verifyPhysicalQuantityOnRegion(["porosity"], region) if region.getMaterial().getHydraulicConductivity(): continue if region.getMaterial().getIntrinsicPermeability( ) == None and region.getMaterial().getPermeability( ) == None: raise Exception( " the permeability or the intrinsic permeability should be set" ) elif (self.permeability and self.intrinsicPermeability): raise Exception( "A Material with both permeability and intrinsicpermeability can\'t be defined" ) self.meshdim = meshdim # # default values are set here for density, gravity and density # value = [0.] * meshdim value[-1] = 9.81 if meshdim == 2: value.append(0.) gravity = Vector(value) self.gravity = gravity self.density = Density(1.0, 'kg/l') self.viscosity = Viscosity(1.0, 'kg/m/s') else: self.darcyVelocity = None pass # # data Base # if type(chemistryDB) != bytes: raise TypeError( " the chemistryDB argument of the ChemicalTransportProblem must be a string " ) self.chemistryDB = chemistryDB # # initial conditions # verifyClassList(initialConditions, InitialCondition) self.initialConditions = initialConditions # # Sources # if sources != None: verifyClassList(sources, Source) self.sources = sources pass else: self.sources = None pass # simulation times to be recovered if type(calculationTimes) != list: raise TypeError(" simulationTimes must be a list of times ") i = 0 for item in calculationTimes: if type(item) not in [float, int]: raise TypeError(" calculationTimes must be a list of times ") calculationTimes[i] = calculationTimes[i] i += 1 pass previous = calculationTimes[0] for item in calculationTimes: if item < 0.: raise Exception('Error : Negative calculation time unexpected') if item < previous: raise Exception( 'Error : Decreasing calculation time unexpected') previous = item self.calculationTimes = calculationTimes pass # New chemical species if speciesBaseAddenda not in [None, []]: verifyClassList(speciesBaseAddenda, [Salt, Species]) self.speciesBaseAddenda = speciesBaseAddenda pass else: self.speciesBaseAddenda = [] pass # Kinetics Laws if kineticLaws != None: verifyClassList(kineticLaws, KineticLaw) self.kineticLaws = kineticLaws pass else: self.kineticLaws = None pass # time unit if timeUnit: if type(timeUnit) != bytes: raise TypeError( " the time unit argument of the ChemicalTransportProblem must be a string " ) pass self.timeUnit = timeUnit # # Activity Law # TODO : check the default activity law # if activityLaw: if not isinstance(activityLaw, ActivityLaw): raise Exception( " the activity law instantiation must be checked") ## else: ## self.activityLaw = TruncatedDavies() pass self.activityLaw = activityLaw # # variable porosity # if porosityState: if type(porosityState) != bytes: raise TypeError( " the porosityState argument of the ChemicalTransportProblem must be a string " ) porosityState = porosityState.lower() if (porosityState == 'constant') or (porosityState == 'variable'): self.porosityState = porosityState pass elif porosityState in ['steady', "cst"]: self.porosityState = 'constant' pass elif porosityState in ['transient', "var"]: self.porosityState = 'constant' pass else: ## self.porosityState = None mess = "porosityState badly defined (default : 'constant', else 'variable')" raise mess pass else: self.porosityState = 'constant' pass # # user processing set up # if userProcessing and type(userFunctionList) == ListType: self.userProcessing = True self.processingList = userFunctionList for processingFunction in range(len(self.processingList)): self.processingList[processingFunction] += "(self)" print(self.processingList[processingFunction]) pass pass elif type(userFunctionList) == ListType: self.userProcessing = True self.processingList = userFunctionList for processingFunction in range(len(self.processingList)): self.processingList[processingFunction] += "(self)" print(self.processingList[processingFunction]) pass pass else: self.userProcessing = False self.processingList = None pass # # variable porosity: diffusion law # if diffusionLaw: if not isinstance(diffusionLaw, EffectiveDiffusionLaw): raise Exceptio( " the diffusion law instanciation must be checked") pass self.diffusionLaw = diffusionLaw self.permeabilityLaw = permeabilityLaw if headVPorosity != None: if headVPorosity not in ["constant", "variable", "constante"]: self.headVPorosity = "constant" pass else: self.headVPorosity = headVPorosity pass else: self.headVPorosity = "constant" pass # Outputs if outputs != None: verifyClassList(outputs, ExpectedOutput) self.outputs = outputs pass else: self.outputs = None pass # timeVaryingBoundaryConditionList self.timeBoundaryConditionVariation = None # Mpi print("environ ", environ.get('WMPI')) # if environ.get('WMPI') != None: # opts = argv[:] # self.mpiSize = argv[1] # print "self.mpiSize ",self.mpiSize # else : # self.mpiSize = None self.mpiSize = mpiSize #temperature is by default constant if temperature == None: self.temperature = "constant" pass else: self.temperature = temperature pass if temperatureField == None: self.temperatureField = None pass else: self.temperatureField = temperatureField pass # # wellbore analysis # self.wellbore = wellbore return None