[docs]@_phasedocsdefsalinity(phase,T='pore.temperature',conc='pore.concentration',):r""" Calculates the salinity in g salt per kg of solution from concentration Parameters ---------- %(phase)s %(T)s %(conc)s Returns ------- salinity : ndarray The salinity in g of solute per kg of solution. Notes ----- This model is useful for converting known concentration values (e.g. calculated by a transport algorithm) into salinity values, which can then be used for finding other physical properties of water which are available as a function of salinity. The salinity correlations are valid for salinity up to 160 g/kg, which corresponds to a concentration of 0.05 mol/L (assuming NaCl is the only solute) """C=phase[conc]T=phase[T]a=8.73220929e+00b=6.00389629e+01c=-1.19083743e-01d=-1.77796042e+00e=3.26987130e-04f=-1.09636011e-01g=-1.83933426e-07S=a+b*C+c*T+d*C**2+e*T**2+f*C**3+g*T**3returnS
[docs]@_phasedocsdefmixing_rule(phase,prop,mode='logarithmic',power=1,):r""" Computes the property of a mixture using the specified mixing rule Parameters ---------- %(phase)s prop : str The dictionary key containing the property of interest on each component mode : str The mixing rule to to use. Options are: ============== ======================================================== mode ============== ======================================================== 'logarithmic' (default) Uses the natural logarithm of the property as: :math:`ln(z) = \Sigma (x_i \cdot ln(\z_i))` 'linear' Basic mole fraction weighting of the form :math:`z = \Sigma (x_i \cdot \z_i)` 'power Applies an exponent to the property as: :math:`\z^{power} = \Sigma (x_i \cdot \z_i^{power})` ============== ======================================================== power : scalar If ``mode='power'`` this indicates the value of the exponent, otherwise this is ignored. """xs=phase['pore.mole_fraction']ys=phase.get_comp_vals(prop)z=0.0ifmode=='logarithmic':foriinxs.keys():z+=xs[i]*np.log(ys[i])z=np.exp(z)elifmodein['linear','simple']:foriinxs.keys():z+=xs[i]*ys[i]elifmode=='power':foriinxs.keys():z+=xs[i]*ys[i]**powerz=z**(1/power)returnz
[docs]@_phasedocsdefmole_to_mass_fraction(phase,MWs='param.molecular_weight'):r""" Computes the mass fraction in each pore Parameters ---------- %(phase)s %(MWs)s Returns ------- ws : ndarray An ndarray containing the mass fraction in each pore computed from the mole fractions of each component and their molecular weights. """xs=phase['pore.mole_fraction']MW=phase.get_comp_vals(MWs)num=[xs[k]*MW[k]forkinxs.keys()]denom=np.sum(num,axis=0)ws=num/denomcomps=list(phase.components.keys())d={comps[i]:ws[i,:]foriinrange(len(comps))}returnd
[docs]@_phasedocsdefmole_summation(phase):r""" Computes total mole fraction in each pore given component values Parameters ---------- %(phase)s Returns ------- vals : ND-array An ND-array containing the total mole fraction. Note that this is not guaranteed to sum to 1.0. """xs=[phase['pore.mole_fraction.'+c.name]forcinphase.components.values()]iflen(xs)>0:xs=np.sum(xs,axis=0)else:xs=np.nanreturnxs
[docs]@_phasedocsdeffrom_component(phase,prop,compname):r""" Fetches the given values from the specified object Parameters ---------- %(phase)s prop : str The name of the array to retreive compname : str The name of the object possessing the desired data Returns ------- vals : ND-array An ND-array containing the request data """comp=phase.project[compname]vals=comp[prop]returnvals