repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_documentation_string
stringlengths
1
47.2k
func_code_url
stringlengths
85
339
ssalentin/plip
plip/modules/preparation.py
Ligand.find_charged
def find_charged(self, all_atoms): """Identify all positively charged groups in a ligand. This search is not exhaustive, as the cases can be quite diverse. The typical cases seem to be protonated amines, quaternary ammoinium and sulfonium as mentioned in 'Cation-pi interactions in ligand recognition and catalysis' (Zacharias et al., 2002)). Identify negatively charged groups in the ligand. """ data = namedtuple('lcharge', 'atoms orig_atoms atoms_orig_idx type center fgroup') a_set = [] for a in all_atoms: a_orig_idx = self.Mapper.mapid(a.idx, mtype=self.mtype, bsid=self.bsid) a_orig = self.Mapper.id_to_atom(a_orig_idx) if self.is_functional_group(a, 'quartamine'): a_set.append(data(atoms=[a, ], orig_atoms=[a_orig, ], atoms_orig_idx=[a_orig_idx, ], type='positive', center=list(a.coords), fgroup='quartamine')) elif self.is_functional_group(a, 'tertamine'): a_set.append(data(atoms=[a, ], orig_atoms=[a_orig, ], atoms_orig_idx=[a_orig_idx, ], type='positive', center=list(a.coords), fgroup='tertamine')) if self.is_functional_group(a, 'sulfonium'): a_set.append(data(atoms=[a, ], orig_atoms=[a_orig, ], atoms_orig_idx=[a_orig_idx, ], type='positive', center=list(a.coords), fgroup='sulfonium')) if self.is_functional_group(a, 'phosphate'): a_contributing = [a, ] a_contributing_orig_idx = [a_orig_idx, ] [a_contributing.append(pybel.Atom(neighbor)) for neighbor in pybel.ob.OBAtomAtomIter(a.OBAtom)] [a_contributing_orig_idx.append(self.Mapper.mapid(neighbor.idx, mtype=self.mtype, bsid=self.bsid)) for neighbor in a_contributing] orig_contributing = [self.Mapper.id_to_atom(idx) for idx in a_contributing_orig_idx] a_set.append(data(atoms=a_contributing, orig_atoms=orig_contributing, atoms_orig_idx=a_contributing_orig_idx, type='negative', center=a.coords, fgroup='phosphate')) if self.is_functional_group(a, 'sulfonicacid'): a_contributing = [a, ] a_contributing_orig_idx = [a_orig_idx, ] [a_contributing.append(pybel.Atom(neighbor)) for neighbor in pybel.ob.OBAtomAtomIter(a.OBAtom) if neighbor.GetAtomicNum() == 8] [a_contributing_orig_idx.append(self.Mapper.mapid(neighbor.idx, mtype=self.mtype, bsid=self.bsid)) for neighbor in a_contributing] orig_contributing = [self.Mapper.id_to_atom(idx) for idx in a_contributing_orig_idx] a_set.append(data(atoms=a_contributing, orig_atoms=orig_contributing, atoms_orig_idx=a_contributing_orig_idx, type='negative', center=a.coords, fgroup='sulfonicacid')) elif self.is_functional_group(a, 'sulfate'): a_contributing = [a, ] a_contributing_orig_idx = [a_orig_idx, ] [a_contributing_orig_idx.append(self.Mapper.mapid(neighbor.idx, mtype=self.mtype, bsid=self.bsid)) for neighbor in a_contributing] [a_contributing.append(pybel.Atom(neighbor)) for neighbor in pybel.ob.OBAtomAtomIter(a.OBAtom)] orig_contributing = [self.Mapper.id_to_atom(idx) for idx in a_contributing_orig_idx] a_set.append(data(atoms=a_contributing, orig_atoms=orig_contributing, atoms_orig_idx=a_contributing_orig_idx, type='negative', center=a.coords, fgroup='sulfate')) if self.is_functional_group(a, 'carboxylate'): a_contributing = [pybel.Atom(neighbor) for neighbor in pybel.ob.OBAtomAtomIter(a.OBAtom) if neighbor.GetAtomicNum() == 8] a_contributing_orig_idx = [self.Mapper.mapid(neighbor.idx, mtype=self.mtype, bsid=self.bsid) for neighbor in a_contributing] orig_contributing = [self.Mapper.id_to_atom(idx) for idx in a_contributing_orig_idx] a_set.append(data(atoms=a_contributing, orig_atoms=orig_contributing, atoms_orig_idx=a_contributing_orig_idx, type='negative', center=centroid([a.coords for a in a_contributing]), fgroup='carboxylate')) elif self.is_functional_group(a, 'guanidine'): a_contributing = [pybel.Atom(neighbor) for neighbor in pybel.ob.OBAtomAtomIter(a.OBAtom) if neighbor.GetAtomicNum() == 7] a_contributing_orig_idx = [self.Mapper.mapid(neighbor.idx, mtype=self.mtype, bsid=self.bsid) for neighbor in a_contributing] orig_contributing = [self.Mapper.id_to_atom(idx) for idx in a_contributing_orig_idx] a_set.append(data(atoms=a_contributing, orig_atoms=orig_contributing, atoms_orig_idx=a_contributing_orig_idx, type='positive', center=a.coords, fgroup='guanidine')) return a_set
python
def find_charged(self, all_atoms): """Identify all positively charged groups in a ligand. This search is not exhaustive, as the cases can be quite diverse. The typical cases seem to be protonated amines, quaternary ammoinium and sulfonium as mentioned in 'Cation-pi interactions in ligand recognition and catalysis' (Zacharias et al., 2002)). Identify negatively charged groups in the ligand. """ data = namedtuple('lcharge', 'atoms orig_atoms atoms_orig_idx type center fgroup') a_set = [] for a in all_atoms: a_orig_idx = self.Mapper.mapid(a.idx, mtype=self.mtype, bsid=self.bsid) a_orig = self.Mapper.id_to_atom(a_orig_idx) if self.is_functional_group(a, 'quartamine'): a_set.append(data(atoms=[a, ], orig_atoms=[a_orig, ], atoms_orig_idx=[a_orig_idx, ], type='positive', center=list(a.coords), fgroup='quartamine')) elif self.is_functional_group(a, 'tertamine'): a_set.append(data(atoms=[a, ], orig_atoms=[a_orig, ], atoms_orig_idx=[a_orig_idx, ], type='positive', center=list(a.coords), fgroup='tertamine')) if self.is_functional_group(a, 'sulfonium'): a_set.append(data(atoms=[a, ], orig_atoms=[a_orig, ], atoms_orig_idx=[a_orig_idx, ], type='positive', center=list(a.coords), fgroup='sulfonium')) if self.is_functional_group(a, 'phosphate'): a_contributing = [a, ] a_contributing_orig_idx = [a_orig_idx, ] [a_contributing.append(pybel.Atom(neighbor)) for neighbor in pybel.ob.OBAtomAtomIter(a.OBAtom)] [a_contributing_orig_idx.append(self.Mapper.mapid(neighbor.idx, mtype=self.mtype, bsid=self.bsid)) for neighbor in a_contributing] orig_contributing = [self.Mapper.id_to_atom(idx) for idx in a_contributing_orig_idx] a_set.append(data(atoms=a_contributing, orig_atoms=orig_contributing, atoms_orig_idx=a_contributing_orig_idx, type='negative', center=a.coords, fgroup='phosphate')) if self.is_functional_group(a, 'sulfonicacid'): a_contributing = [a, ] a_contributing_orig_idx = [a_orig_idx, ] [a_contributing.append(pybel.Atom(neighbor)) for neighbor in pybel.ob.OBAtomAtomIter(a.OBAtom) if neighbor.GetAtomicNum() == 8] [a_contributing_orig_idx.append(self.Mapper.mapid(neighbor.idx, mtype=self.mtype, bsid=self.bsid)) for neighbor in a_contributing] orig_contributing = [self.Mapper.id_to_atom(idx) for idx in a_contributing_orig_idx] a_set.append(data(atoms=a_contributing, orig_atoms=orig_contributing, atoms_orig_idx=a_contributing_orig_idx, type='negative', center=a.coords, fgroup='sulfonicacid')) elif self.is_functional_group(a, 'sulfate'): a_contributing = [a, ] a_contributing_orig_idx = [a_orig_idx, ] [a_contributing_orig_idx.append(self.Mapper.mapid(neighbor.idx, mtype=self.mtype, bsid=self.bsid)) for neighbor in a_contributing] [a_contributing.append(pybel.Atom(neighbor)) for neighbor in pybel.ob.OBAtomAtomIter(a.OBAtom)] orig_contributing = [self.Mapper.id_to_atom(idx) for idx in a_contributing_orig_idx] a_set.append(data(atoms=a_contributing, orig_atoms=orig_contributing, atoms_orig_idx=a_contributing_orig_idx, type='negative', center=a.coords, fgroup='sulfate')) if self.is_functional_group(a, 'carboxylate'): a_contributing = [pybel.Atom(neighbor) for neighbor in pybel.ob.OBAtomAtomIter(a.OBAtom) if neighbor.GetAtomicNum() == 8] a_contributing_orig_idx = [self.Mapper.mapid(neighbor.idx, mtype=self.mtype, bsid=self.bsid) for neighbor in a_contributing] orig_contributing = [self.Mapper.id_to_atom(idx) for idx in a_contributing_orig_idx] a_set.append(data(atoms=a_contributing, orig_atoms=orig_contributing, atoms_orig_idx=a_contributing_orig_idx, type='negative', center=centroid([a.coords for a in a_contributing]), fgroup='carboxylate')) elif self.is_functional_group(a, 'guanidine'): a_contributing = [pybel.Atom(neighbor) for neighbor in pybel.ob.OBAtomAtomIter(a.OBAtom) if neighbor.GetAtomicNum() == 7] a_contributing_orig_idx = [self.Mapper.mapid(neighbor.idx, mtype=self.mtype, bsid=self.bsid) for neighbor in a_contributing] orig_contributing = [self.Mapper.id_to_atom(idx) for idx in a_contributing_orig_idx] a_set.append(data(atoms=a_contributing, orig_atoms=orig_contributing, atoms_orig_idx=a_contributing_orig_idx, type='positive', center=a.coords, fgroup='guanidine')) return a_set
Identify all positively charged groups in a ligand. This search is not exhaustive, as the cases can be quite diverse. The typical cases seem to be protonated amines, quaternary ammoinium and sulfonium as mentioned in 'Cation-pi interactions in ligand recognition and catalysis' (Zacharias et al., 2002)). Identify negatively charged groups in the ligand.
https://github.com/ssalentin/plip/blob/906c8d36463689779b403f6c2c9ed06174acaf9a/plip/modules/preparation.py#L1131-L1195
ssalentin/plip
plip/modules/preparation.py
Ligand.find_metal_binding
def find_metal_binding(self, lig_atoms, water_oxygens): """Looks for atoms that could possibly be involved in binding a metal ion. This can be any water oxygen, as well as oxygen from carboxylate, phophoryl, phenolate, alcohol; nitrogen from imidazole; sulfur from thiolate. """ a_set = [] data = namedtuple('metal_binding', 'atom orig_atom atom_orig_idx type fgroup restype resnr reschain location') for oxygen in water_oxygens: a_set.append(data(atom=oxygen.oxy, atom_orig_idx=oxygen.oxy_orig_idx, type='O', fgroup='water', restype=whichrestype(oxygen.oxy), resnr=whichresnumber(oxygen.oxy), reschain=whichchain(oxygen.oxy), location='water', orig_atom=self.Mapper.id_to_atom(oxygen.oxy_orig_idx))) # #@todo Refactor code for a in lig_atoms: a_orig_idx = self.Mapper.mapid(a.idx, mtype='ligand', bsid=self.bsid) n_atoms = pybel.ob.OBAtomAtomIter(a.OBAtom) # Neighboring atoms # All atomic numbers of neighboring atoms n_atoms_atomicnum = [n.GetAtomicNum() for n in pybel.ob.OBAtomAtomIter(a.OBAtom)] if a.atomicnum == 8: # Oxygen if n_atoms_atomicnum.count('1') == 1 and len(n_atoms_atomicnum) == 2: # Oxygen in alcohol (R-[O]-H) a_set.append(data(atom=a, atom_orig_idx=a_orig_idx, type='O', fgroup='alcohol', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if True in [n.IsAromatic() for n in n_atoms] and not a.OBAtom.IsAromatic(): # Phenolate oxygen a_set.append(data(atom=a, atom_orig_idx=a_orig_idx, type='O', fgroup='phenolate', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if a.atomicnum == 6: # It's a carbon atom if n_atoms_atomicnum.count(8) == 2 and n_atoms_atomicnum.count(6) == 1: # It's a carboxylate group for neighbor in [n for n in n_atoms if n.GetAtomicNum() == 8]: neighbor_orig_idx = self.Mapper.mapid(neighbor.GetIdx(), mtype='ligand', bsid=self.bsid) a_set.append(data(atom=pybel.Atom(neighbor), atom_orig_idx=neighbor_orig_idx, type='O', fgroup='carboxylate', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if a.atomicnum == 15: # It's a phosphor atom if n_atoms_atomicnum.count(8) >= 3: # It's a phosphoryl for neighbor in [n for n in n_atoms if n.GetAtomicNum() == 8]: neighbor_orig_idx = self.Mapper.mapid(neighbor.GetIdx(), mtype='ligand', bsid=self.bsid) a_set.append(data(atom=pybel.Atom(neighbor), atom_orig_idx=neighbor_orig_idx, type='O', fgroup='phosphoryl', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if n_atoms_atomicnum.count(8) == 2: # It's another phosphor-containing group #@todo (correct name?) for neighbor in [n for n in n_atoms if n.GetAtomicNum() == 8]: neighbor_orig_idx = self.Mapper.mapid(neighbor.GetIdx(), mtype='ligand', bsid=self.bsid) a_set.append(data(atom=pybel.Atom(neighbor), atom_orig_idx=neighbor_orig_idx, type='O', fgroup='phosphor.other', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if a.atomicnum == 7: # It's a nitrogen atom if n_atoms_atomicnum.count(6) == 2: # It's imidazole/pyrrole or similar a_set.append(data(atom=a, atom_orig_idx=a_orig_idx, type='N', fgroup='imidazole/pyrrole', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if a.atomicnum == 16: # It's a sulfur atom if True in [n.IsAromatic() for n in n_atoms] and not a.OBAtom.IsAromatic(): # Thiolate a_set.append(data(atom=a, atom_orig_idx=a_orig_idx, type='S', fgroup='thiolate', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if set(n_atoms_atomicnum) == {26}: # Sulfur in Iron sulfur cluster a_set.append(data(atom=a, atom_orig_idx=a_orig_idx, type='S', fgroup='iron-sulfur.cluster', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) return a_set
python
def find_metal_binding(self, lig_atoms, water_oxygens): """Looks for atoms that could possibly be involved in binding a metal ion. This can be any water oxygen, as well as oxygen from carboxylate, phophoryl, phenolate, alcohol; nitrogen from imidazole; sulfur from thiolate. """ a_set = [] data = namedtuple('metal_binding', 'atom orig_atom atom_orig_idx type fgroup restype resnr reschain location') for oxygen in water_oxygens: a_set.append(data(atom=oxygen.oxy, atom_orig_idx=oxygen.oxy_orig_idx, type='O', fgroup='water', restype=whichrestype(oxygen.oxy), resnr=whichresnumber(oxygen.oxy), reschain=whichchain(oxygen.oxy), location='water', orig_atom=self.Mapper.id_to_atom(oxygen.oxy_orig_idx))) # #@todo Refactor code for a in lig_atoms: a_orig_idx = self.Mapper.mapid(a.idx, mtype='ligand', bsid=self.bsid) n_atoms = pybel.ob.OBAtomAtomIter(a.OBAtom) # Neighboring atoms # All atomic numbers of neighboring atoms n_atoms_atomicnum = [n.GetAtomicNum() for n in pybel.ob.OBAtomAtomIter(a.OBAtom)] if a.atomicnum == 8: # Oxygen if n_atoms_atomicnum.count('1') == 1 and len(n_atoms_atomicnum) == 2: # Oxygen in alcohol (R-[O]-H) a_set.append(data(atom=a, atom_orig_idx=a_orig_idx, type='O', fgroup='alcohol', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if True in [n.IsAromatic() for n in n_atoms] and not a.OBAtom.IsAromatic(): # Phenolate oxygen a_set.append(data(atom=a, atom_orig_idx=a_orig_idx, type='O', fgroup='phenolate', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if a.atomicnum == 6: # It's a carbon atom if n_atoms_atomicnum.count(8) == 2 and n_atoms_atomicnum.count(6) == 1: # It's a carboxylate group for neighbor in [n for n in n_atoms if n.GetAtomicNum() == 8]: neighbor_orig_idx = self.Mapper.mapid(neighbor.GetIdx(), mtype='ligand', bsid=self.bsid) a_set.append(data(atom=pybel.Atom(neighbor), atom_orig_idx=neighbor_orig_idx, type='O', fgroup='carboxylate', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if a.atomicnum == 15: # It's a phosphor atom if n_atoms_atomicnum.count(8) >= 3: # It's a phosphoryl for neighbor in [n for n in n_atoms if n.GetAtomicNum() == 8]: neighbor_orig_idx = self.Mapper.mapid(neighbor.GetIdx(), mtype='ligand', bsid=self.bsid) a_set.append(data(atom=pybel.Atom(neighbor), atom_orig_idx=neighbor_orig_idx, type='O', fgroup='phosphoryl', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if n_atoms_atomicnum.count(8) == 2: # It's another phosphor-containing group #@todo (correct name?) for neighbor in [n for n in n_atoms if n.GetAtomicNum() == 8]: neighbor_orig_idx = self.Mapper.mapid(neighbor.GetIdx(), mtype='ligand', bsid=self.bsid) a_set.append(data(atom=pybel.Atom(neighbor), atom_orig_idx=neighbor_orig_idx, type='O', fgroup='phosphor.other', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if a.atomicnum == 7: # It's a nitrogen atom if n_atoms_atomicnum.count(6) == 2: # It's imidazole/pyrrole or similar a_set.append(data(atom=a, atom_orig_idx=a_orig_idx, type='N', fgroup='imidazole/pyrrole', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if a.atomicnum == 16: # It's a sulfur atom if True in [n.IsAromatic() for n in n_atoms] and not a.OBAtom.IsAromatic(): # Thiolate a_set.append(data(atom=a, atom_orig_idx=a_orig_idx, type='S', fgroup='thiolate', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) if set(n_atoms_atomicnum) == {26}: # Sulfur in Iron sulfur cluster a_set.append(data(atom=a, atom_orig_idx=a_orig_idx, type='S', fgroup='iron-sulfur.cluster', restype=self.hetid, resnr=self.position, reschain=self.chain, location='ligand', orig_atom=self.Mapper.id_to_atom(a_orig_idx))) return a_set
Looks for atoms that could possibly be involved in binding a metal ion. This can be any water oxygen, as well as oxygen from carboxylate, phophoryl, phenolate, alcohol; nitrogen from imidazole; sulfur from thiolate.
https://github.com/ssalentin/plip/blob/906c8d36463689779b403f6c2c9ed06174acaf9a/plip/modules/preparation.py#L1197-L1263
ssalentin/plip
plip/modules/preparation.py
PDBComplex.load_pdb
def load_pdb(self, pdbpath, as_string=False): """Loads a pdb file with protein AND ligand(s), separates and prepares them. If specified 'as_string', the input is a PDB string instead of a path.""" if as_string: self.sourcefiles['pdbcomplex.original'] = None self.sourcefiles['pdbcomplex'] = None self.sourcefiles['pdbstring'] = pdbpath else: self.sourcefiles['pdbcomplex.original'] = pdbpath self.sourcefiles['pdbcomplex'] = pdbpath self.information['pdbfixes'] = False pdbparser = PDBParser(pdbpath, as_string=as_string) # Parse PDB file to find errors and get additonal data # #@todo Refactor and rename here self.Mapper.proteinmap = pdbparser.proteinmap self.Mapper.reversed_proteinmap = {v: k for k, v in self.Mapper.proteinmap.items()} self.modres = pdbparser.modres self.covalent = pdbparser.covalent self.altconf = pdbparser.altconformations self.corrected_pdb = pdbparser.corrected_pdb if not config.PLUGIN_MODE: if pdbparser.num_fixed_lines > 0: write_message('%i lines automatically fixed in PDB input file.\n' % pdbparser.num_fixed_lines) # Save modified PDB file if not as_string: basename = os.path.basename(pdbpath).split('.')[0] else: basename = "from_stdin" pdbpath_fixed = tmpfile(prefix='plipfixed.' + basename + '_', direc=self.output_path) create_folder_if_not_exists(self.output_path) self.sourcefiles['pdbcomplex'] = pdbpath_fixed self.corrected_pdb = re.sub(r'[^\x00-\x7F]+', ' ', self.corrected_pdb) # Strip non-unicode chars if not config.NOFIXFILE: # Only write to file if this option is not activated with open(pdbpath_fixed, 'w') as f: f.write(self.corrected_pdb) self.information['pdbfixes'] = True if not as_string: self.sourcefiles['filename'] = os.path.basename(self.sourcefiles['pdbcomplex']) self.protcomplex, self.filetype = read_pdb(self.corrected_pdb, as_string=True) # Update the model in the Mapper class instance self.Mapper.original_structure = self.protcomplex.OBMol write_message('PDB structure successfully read.\n') # Determine (temporary) PyMOL Name from Filename self.pymol_name = pdbpath.split('/')[-1].split('.')[0] + '-Protein' # Replace characters causing problems in PyMOL self.pymol_name = self.pymol_name.replace(' ', '').replace('(', '').replace(')', '').replace('-', '_') # But if possible, name it after PDBID in Header if 'HEADER' in self.protcomplex.data: # If the PDB file has a proper header potential_name = self.protcomplex.data['HEADER'][56:60].lower() if extract_pdbid(potential_name) != 'UnknownProtein': self.pymol_name = potential_name write_message("Pymol Name set as: '%s'\n" % self.pymol_name, mtype='debug') # Extract and prepare ligands ligandfinder = LigandFinder(self.protcomplex, self.altconf, self.modres, self.covalent, self.Mapper) self.ligands = ligandfinder.ligands self.excluded = ligandfinder.excluded # Add polar hydrogens self.protcomplex.OBMol.AddPolarHydrogens() for atm in self.protcomplex: self.atoms[atm.idx] = atm write_message("Assigned polar hydrogens\n", mtype='debug') if len(self.excluded) != 0: write_message("Excluded molecules as ligands: %s\n" % ','.join([lig for lig in self.excluded])) if config.DNARECEPTOR: self.resis = [obres for obres in pybel.ob.OBResidueIter( self.protcomplex.OBMol) if obres.GetName() in config.DNA+config.RNA] else: self.resis = [obres for obres in pybel.ob.OBResidueIter( self.protcomplex.OBMol) if obres.GetResidueProperty(0)] num_ligs = len(self.ligands) if num_ligs == 1: write_message("Analyzing one ligand...\n") elif num_ligs > 1: write_message("Analyzing %i ligands...\n" % num_ligs) else: write_message("Structure contains no ligands.\n\n")
python
def load_pdb(self, pdbpath, as_string=False): """Loads a pdb file with protein AND ligand(s), separates and prepares them. If specified 'as_string', the input is a PDB string instead of a path.""" if as_string: self.sourcefiles['pdbcomplex.original'] = None self.sourcefiles['pdbcomplex'] = None self.sourcefiles['pdbstring'] = pdbpath else: self.sourcefiles['pdbcomplex.original'] = pdbpath self.sourcefiles['pdbcomplex'] = pdbpath self.information['pdbfixes'] = False pdbparser = PDBParser(pdbpath, as_string=as_string) # Parse PDB file to find errors and get additonal data # #@todo Refactor and rename here self.Mapper.proteinmap = pdbparser.proteinmap self.Mapper.reversed_proteinmap = {v: k for k, v in self.Mapper.proteinmap.items()} self.modres = pdbparser.modres self.covalent = pdbparser.covalent self.altconf = pdbparser.altconformations self.corrected_pdb = pdbparser.corrected_pdb if not config.PLUGIN_MODE: if pdbparser.num_fixed_lines > 0: write_message('%i lines automatically fixed in PDB input file.\n' % pdbparser.num_fixed_lines) # Save modified PDB file if not as_string: basename = os.path.basename(pdbpath).split('.')[0] else: basename = "from_stdin" pdbpath_fixed = tmpfile(prefix='plipfixed.' + basename + '_', direc=self.output_path) create_folder_if_not_exists(self.output_path) self.sourcefiles['pdbcomplex'] = pdbpath_fixed self.corrected_pdb = re.sub(r'[^\x00-\x7F]+', ' ', self.corrected_pdb) # Strip non-unicode chars if not config.NOFIXFILE: # Only write to file if this option is not activated with open(pdbpath_fixed, 'w') as f: f.write(self.corrected_pdb) self.information['pdbfixes'] = True if not as_string: self.sourcefiles['filename'] = os.path.basename(self.sourcefiles['pdbcomplex']) self.protcomplex, self.filetype = read_pdb(self.corrected_pdb, as_string=True) # Update the model in the Mapper class instance self.Mapper.original_structure = self.protcomplex.OBMol write_message('PDB structure successfully read.\n') # Determine (temporary) PyMOL Name from Filename self.pymol_name = pdbpath.split('/')[-1].split('.')[0] + '-Protein' # Replace characters causing problems in PyMOL self.pymol_name = self.pymol_name.replace(' ', '').replace('(', '').replace(')', '').replace('-', '_') # But if possible, name it after PDBID in Header if 'HEADER' in self.protcomplex.data: # If the PDB file has a proper header potential_name = self.protcomplex.data['HEADER'][56:60].lower() if extract_pdbid(potential_name) != 'UnknownProtein': self.pymol_name = potential_name write_message("Pymol Name set as: '%s'\n" % self.pymol_name, mtype='debug') # Extract and prepare ligands ligandfinder = LigandFinder(self.protcomplex, self.altconf, self.modres, self.covalent, self.Mapper) self.ligands = ligandfinder.ligands self.excluded = ligandfinder.excluded # Add polar hydrogens self.protcomplex.OBMol.AddPolarHydrogens() for atm in self.protcomplex: self.atoms[atm.idx] = atm write_message("Assigned polar hydrogens\n", mtype='debug') if len(self.excluded) != 0: write_message("Excluded molecules as ligands: %s\n" % ','.join([lig for lig in self.excluded])) if config.DNARECEPTOR: self.resis = [obres for obres in pybel.ob.OBResidueIter( self.protcomplex.OBMol) if obres.GetName() in config.DNA+config.RNA] else: self.resis = [obres for obres in pybel.ob.OBResidueIter( self.protcomplex.OBMol) if obres.GetResidueProperty(0)] num_ligs = len(self.ligands) if num_ligs == 1: write_message("Analyzing one ligand...\n") elif num_ligs > 1: write_message("Analyzing %i ligands...\n" % num_ligs) else: write_message("Structure contains no ligands.\n\n")
Loads a pdb file with protein AND ligand(s), separates and prepares them. If specified 'as_string', the input is a PDB string instead of a path.
https://github.com/ssalentin/plip/blob/906c8d36463689779b403f6c2c9ed06174acaf9a/plip/modules/preparation.py#L1294-L1377
ssalentin/plip
plip/modules/preparation.py
PDBComplex.characterize_complex
def characterize_complex(self, ligand): """Handles all basic functions for characterizing the interactions for one ligand""" single_sites = [] for member in ligand.members: single_sites.append(':'.join([str(x) for x in member])) site = ' + '.join(single_sites) site = site if not len(site) > 20 else site[:20] + '...' longname = ligand.longname if not len(ligand.longname) > 20 else ligand.longname[:20] + '...' ligtype = 'Unspecified type' if ligand.type == 'UNSPECIFIED' else ligand.type ligtext = "\n%s [%s] -- %s" % (longname, ligtype, site) if ligtype == 'PEPTIDE': ligtext = '\n Chain %s [PEPTIDE / INTER-CHAIN]' % ligand.chain if ligtype == 'INTRA': ligtext = "\n Chain %s [INTRA-CHAIN]" % ligand.chain any_in_biolip = len(set([x[0] for x in ligand.members]).intersection(config.biolip_list)) != 0 write_message(ligtext) write_message('\n' + '-' * len(ligtext) + '\n') if ligtype not in ['POLYMER', 'DNA', 'ION', 'DNA+ION', 'RNA+ION', 'SMALLMOLECULE+ION'] and any_in_biolip: write_message('may be biologically irrelevant\n', mtype='info', indent=True) lig_obj = Ligand(self, ligand) cutoff = lig_obj.max_dist_to_center + config.BS_DIST bs_res = self.extract_bs(cutoff, lig_obj.centroid, self.resis) # Get a list of all atoms belonging to the binding site, search by idx bs_atoms = [self.atoms[idx] for idx in [i for i in self.atoms.keys() if self.atoms[i].OBAtom.GetResidue().GetIdx() in bs_res] if idx in self.Mapper.proteinmap and self.Mapper.mapid(idx, mtype='protein') not in self.altconf] if ligand.type == 'PEPTIDE': # If peptide, don't consider the peptide chain as part of the protein binding site bs_atoms = [a for a in bs_atoms if a.OBAtom.GetResidue().GetChain() != lig_obj.chain] if ligand.type == 'INTRA': # Interactions within the chain bs_atoms = [a for a in bs_atoms if a.OBAtom.GetResidue().GetChain() == lig_obj.chain] bs_atoms_refined = [] # Create hash with BSRES -> (MINDIST_TO_LIG, AA_TYPE) # and refine binding site atom selection with exact threshold min_dist = {} for r in bs_atoms: bs_res_id = ''.join([str(whichresnumber(r)), whichchain(r)]) for l in ligand.mol.atoms: distance = euclidean3d(r.coords, l.coords) if bs_res_id not in min_dist: min_dist[bs_res_id] = (distance, whichrestype(r)) elif min_dist[bs_res_id][0] > distance: min_dist[bs_res_id] = (distance, whichrestype(r)) if distance <= config.BS_DIST and r not in bs_atoms_refined: bs_atoms_refined.append(r) num_bs_atoms = len(bs_atoms_refined) write_message('Binding site atoms in vicinity (%.1f A max. dist: %i).\n' % (config.BS_DIST, num_bs_atoms), indent=True) bs_obj = BindingSite(bs_atoms_refined, self.protcomplex, self, self.altconf, min_dist, self.Mapper) pli_obj = PLInteraction(lig_obj, bs_obj, self) self.interaction_sets[ligand.mol.title] = pli_obj
python
def characterize_complex(self, ligand): """Handles all basic functions for characterizing the interactions for one ligand""" single_sites = [] for member in ligand.members: single_sites.append(':'.join([str(x) for x in member])) site = ' + '.join(single_sites) site = site if not len(site) > 20 else site[:20] + '...' longname = ligand.longname if not len(ligand.longname) > 20 else ligand.longname[:20] + '...' ligtype = 'Unspecified type' if ligand.type == 'UNSPECIFIED' else ligand.type ligtext = "\n%s [%s] -- %s" % (longname, ligtype, site) if ligtype == 'PEPTIDE': ligtext = '\n Chain %s [PEPTIDE / INTER-CHAIN]' % ligand.chain if ligtype == 'INTRA': ligtext = "\n Chain %s [INTRA-CHAIN]" % ligand.chain any_in_biolip = len(set([x[0] for x in ligand.members]).intersection(config.biolip_list)) != 0 write_message(ligtext) write_message('\n' + '-' * len(ligtext) + '\n') if ligtype not in ['POLYMER', 'DNA', 'ION', 'DNA+ION', 'RNA+ION', 'SMALLMOLECULE+ION'] and any_in_biolip: write_message('may be biologically irrelevant\n', mtype='info', indent=True) lig_obj = Ligand(self, ligand) cutoff = lig_obj.max_dist_to_center + config.BS_DIST bs_res = self.extract_bs(cutoff, lig_obj.centroid, self.resis) # Get a list of all atoms belonging to the binding site, search by idx bs_atoms = [self.atoms[idx] for idx in [i for i in self.atoms.keys() if self.atoms[i].OBAtom.GetResidue().GetIdx() in bs_res] if idx in self.Mapper.proteinmap and self.Mapper.mapid(idx, mtype='protein') not in self.altconf] if ligand.type == 'PEPTIDE': # If peptide, don't consider the peptide chain as part of the protein binding site bs_atoms = [a for a in bs_atoms if a.OBAtom.GetResidue().GetChain() != lig_obj.chain] if ligand.type == 'INTRA': # Interactions within the chain bs_atoms = [a for a in bs_atoms if a.OBAtom.GetResidue().GetChain() == lig_obj.chain] bs_atoms_refined = [] # Create hash with BSRES -> (MINDIST_TO_LIG, AA_TYPE) # and refine binding site atom selection with exact threshold min_dist = {} for r in bs_atoms: bs_res_id = ''.join([str(whichresnumber(r)), whichchain(r)]) for l in ligand.mol.atoms: distance = euclidean3d(r.coords, l.coords) if bs_res_id not in min_dist: min_dist[bs_res_id] = (distance, whichrestype(r)) elif min_dist[bs_res_id][0] > distance: min_dist[bs_res_id] = (distance, whichrestype(r)) if distance <= config.BS_DIST and r not in bs_atoms_refined: bs_atoms_refined.append(r) num_bs_atoms = len(bs_atoms_refined) write_message('Binding site atoms in vicinity (%.1f A max. dist: %i).\n' % (config.BS_DIST, num_bs_atoms), indent=True) bs_obj = BindingSite(bs_atoms_refined, self.protcomplex, self, self.altconf, min_dist, self.Mapper) pli_obj = PLInteraction(lig_obj, bs_obj, self) self.interaction_sets[ligand.mol.title] = pli_obj
Handles all basic functions for characterizing the interactions for one ligand
https://github.com/ssalentin/plip/blob/906c8d36463689779b403f6c2c9ed06174acaf9a/plip/modules/preparation.py#L1384-L1440
ssalentin/plip
plip/modules/preparation.py
PDBComplex.extract_bs
def extract_bs(self, cutoff, ligcentroid, resis): """Return list of ids from residues belonging to the binding site""" return [obres.GetIdx() for obres in resis if self.res_belongs_to_bs(obres, cutoff, ligcentroid)]
python
def extract_bs(self, cutoff, ligcentroid, resis): """Return list of ids from residues belonging to the binding site""" return [obres.GetIdx() for obres in resis if self.res_belongs_to_bs(obres, cutoff, ligcentroid)]
Return list of ids from residues belonging to the binding site
https://github.com/ssalentin/plip/blob/906c8d36463689779b403f6c2c9ed06174acaf9a/plip/modules/preparation.py#L1442-L1444
ssalentin/plip
plip/modules/preparation.py
PDBComplex.res_belongs_to_bs
def res_belongs_to_bs(self, res, cutoff, ligcentroid): """Check for each residue if its centroid is within a certain distance to the ligand centroid. Additionally checks if a residue belongs to a chain restricted by the user (e.g. by defining a peptide chain)""" rescentroid = centroid([(atm.x(), atm.y(), atm.z()) for atm in pybel.ob.OBResidueAtomIter(res)]) # Check geometry near_enough = True if euclidean3d(rescentroid, ligcentroid) < cutoff else False # Check chain membership restricted_chain = True if res.GetChain() in config.PEPTIDES else False return (near_enough and not restricted_chain)
python
def res_belongs_to_bs(self, res, cutoff, ligcentroid): """Check for each residue if its centroid is within a certain distance to the ligand centroid. Additionally checks if a residue belongs to a chain restricted by the user (e.g. by defining a peptide chain)""" rescentroid = centroid([(atm.x(), atm.y(), atm.z()) for atm in pybel.ob.OBResidueAtomIter(res)]) # Check geometry near_enough = True if euclidean3d(rescentroid, ligcentroid) < cutoff else False # Check chain membership restricted_chain = True if res.GetChain() in config.PEPTIDES else False return (near_enough and not restricted_chain)
Check for each residue if its centroid is within a certain distance to the ligand centroid. Additionally checks if a residue belongs to a chain restricted by the user (e.g. by defining a peptide chain)
https://github.com/ssalentin/plip/blob/906c8d36463689779b403f6c2c9ed06174acaf9a/plip/modules/preparation.py#L1446-L1454
ella/ella
ella/core/context_processors.py
url_info
def url_info(request): """ Make MEDIA_URL and current HttpRequest object available in template code. """ return { 'MEDIA_URL' : core_settings.MEDIA_URL, 'STATIC_URL': core_settings.STATIC_URL, 'VERSION' : core_settings.VERSION, 'SERVER_INFO' : core_settings.SERVER_INFO, 'SITE_NAME' : current_site_name, 'CURRENT_SITE': current_site, }
python
def url_info(request): """ Make MEDIA_URL and current HttpRequest object available in template code. """ return { 'MEDIA_URL' : core_settings.MEDIA_URL, 'STATIC_URL': core_settings.STATIC_URL, 'VERSION' : core_settings.VERSION, 'SERVER_INFO' : core_settings.SERVER_INFO, 'SITE_NAME' : current_site_name, 'CURRENT_SITE': current_site, }
Make MEDIA_URL and current HttpRequest object available in template code.
https://github.com/ella/ella/blob/4a1414991f649dc21c4b777dc6b41a922a13faa7/ella/core/context_processors.py#L9-L22
ella/ella
ella/core/middleware.py
UpdateCacheMiddleware.process_response
def process_response(self, request, response): """Sets the cache, if needed.""" # never cache headers + ETag add_never_cache_headers(response) if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache: # We don't need to update the cache, just return. return response if request.method != 'GET': # This is a stronger requirement than above. It is needed # because of interactions between this middleware and the # HTTPMiddleware, which throws the body of a HEAD-request # away before this middleware gets a chance to cache it. return response if not response.status_code == 200: return response # use the precomputed cache_key if request._cache_middleware_key: cache_key = request._cache_middleware_key else: cache_key = learn_cache_key(request, response, self.cache_timeout, self.key_prefix) # include the orig_time information within the cache cache.set(cache_key, (time.time(), response), self.cache_timeout) return response
python
def process_response(self, request, response): """Sets the cache, if needed.""" # never cache headers + ETag add_never_cache_headers(response) if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache: # We don't need to update the cache, just return. return response if request.method != 'GET': # This is a stronger requirement than above. It is needed # because of interactions between this middleware and the # HTTPMiddleware, which throws the body of a HEAD-request # away before this middleware gets a chance to cache it. return response if not response.status_code == 200: return response # use the precomputed cache_key if request._cache_middleware_key: cache_key = request._cache_middleware_key else: cache_key = learn_cache_key(request, response, self.cache_timeout, self.key_prefix) # include the orig_time information within the cache cache.set(cache_key, (time.time(), response), self.cache_timeout) return response
Sets the cache, if needed.
https://github.com/ella/ella/blob/4a1414991f649dc21c4b777dc6b41a922a13faa7/ella/core/middleware.py#L85-L111
ella/ella
ella/core/middleware.py
FetchFromCacheMiddleware.process_request
def process_request(self, request): """ Checks whether the page is already cached and returns the cached version if available. """ if self.cache_anonymous_only: assert hasattr(request, 'user'), "The Django cache middleware with CACHE_MIDDLEWARE_ANONYMOUS_ONLY=True requires authentication middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.auth.middleware.AuthenticationMiddleware' before the CacheMiddleware." if not request.method in ('GET', 'HEAD') or request.GET: request._cache_update_cache = False return None # Don't bother checking the cache. if self.cache_anonymous_only and request.user.is_authenticated(): request._cache_update_cache = False return None # Don't cache requests from authenticated users. cache_key = get_cache_key(request, self.key_prefix) request._cache_middleware_key = cache_key if cache_key is None: request._cache_update_cache = True return None # No cache information available, need to rebuild. response = cache.get(cache_key, None) if response is None: request._cache_update_cache = True return None # No cache information available, need to rebuild. orig_time, response = response # time to refresh the cache if orig_time and ((time.time() - orig_time) > self.cache_refresh_timeout): request._cache_update_cache = True # keep the response in the cache for just self.timeout seconds and mark it for update # other requests will continue werving this response from cache while I alone work on refreshing it cache.set(cache_key, (None, response), self.timeout) return None request._cache_update_cache = False return response
python
def process_request(self, request): """ Checks whether the page is already cached and returns the cached version if available. """ if self.cache_anonymous_only: assert hasattr(request, 'user'), "The Django cache middleware with CACHE_MIDDLEWARE_ANONYMOUS_ONLY=True requires authentication middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.auth.middleware.AuthenticationMiddleware' before the CacheMiddleware." if not request.method in ('GET', 'HEAD') or request.GET: request._cache_update_cache = False return None # Don't bother checking the cache. if self.cache_anonymous_only and request.user.is_authenticated(): request._cache_update_cache = False return None # Don't cache requests from authenticated users. cache_key = get_cache_key(request, self.key_prefix) request._cache_middleware_key = cache_key if cache_key is None: request._cache_update_cache = True return None # No cache information available, need to rebuild. response = cache.get(cache_key, None) if response is None: request._cache_update_cache = True return None # No cache information available, need to rebuild. orig_time, response = response # time to refresh the cache if orig_time and ((time.time() - orig_time) > self.cache_refresh_timeout): request._cache_update_cache = True # keep the response in the cache for just self.timeout seconds and mark it for update # other requests will continue werving this response from cache while I alone work on refreshing it cache.set(cache_key, (None, response), self.timeout) return None request._cache_update_cache = False return response
Checks whether the page is already cached and returns the cached version if available.
https://github.com/ella/ella/blob/4a1414991f649dc21c4b777dc6b41a922a13faa7/ella/core/middleware.py#L128-L166
ella/ella
ella/core/managers.py
RelatedManager.collect_related
def collect_related(self, finder_funcs, obj, count, *args, **kwargs): """ Collects objects related to ``obj`` using a list of ``finder_funcs``. Stops when required count is collected or the function list is exhausted. """ collected = [] for func in finder_funcs: gathered = func(obj, count, collected, *args, **kwargs) if gathered: collected += gathered if len(collected) >= count: return collected[:count] return collected
python
def collect_related(self, finder_funcs, obj, count, *args, **kwargs): """ Collects objects related to ``obj`` using a list of ``finder_funcs``. Stops when required count is collected or the function list is exhausted. """ collected = [] for func in finder_funcs: gathered = func(obj, count, collected, *args, **kwargs) if gathered: collected += gathered if len(collected) >= count: return collected[:count] return collected
Collects objects related to ``obj`` using a list of ``finder_funcs``. Stops when required count is collected or the function list is exhausted.
https://github.com/ella/ella/blob/4a1414991f649dc21c4b777dc6b41a922a13faa7/ella/core/managers.py#L83-L97
ella/ella
ella/core/managers.py
RelatedManager.get_related_for_object
def get_related_for_object(self, obj, count, finder=None, mods=[], only_from_same_site=True): """ Returns at most ``count`` publishable objects related to ``obj`` using named related finder ``finder``. If only specific type of publishable is prefered, use ``mods`` attribute to list required classes. Finally, use ``only_from_same_site`` if you don't want cross-site content. ``finder`` atribute uses ``RELATED_FINDERS`` settings to find out what finder function to use. If none is specified, ``default`` is used to perform the query. """ return self.collect_related(self._get_finders(finder), obj, count, mods, only_from_same_site)
python
def get_related_for_object(self, obj, count, finder=None, mods=[], only_from_same_site=True): """ Returns at most ``count`` publishable objects related to ``obj`` using named related finder ``finder``. If only specific type of publishable is prefered, use ``mods`` attribute to list required classes. Finally, use ``only_from_same_site`` if you don't want cross-site content. ``finder`` atribute uses ``RELATED_FINDERS`` settings to find out what finder function to use. If none is specified, ``default`` is used to perform the query. """ return self.collect_related(self._get_finders(finder), obj, count, mods, only_from_same_site)
Returns at most ``count`` publishable objects related to ``obj`` using named related finder ``finder``. If only specific type of publishable is prefered, use ``mods`` attribute to list required classes. Finally, use ``only_from_same_site`` if you don't want cross-site content. ``finder`` atribute uses ``RELATED_FINDERS`` settings to find out what finder function to use. If none is specified, ``default`` is used to perform the query.
https://github.com/ella/ella/blob/4a1414991f649dc21c4b777dc6b41a922a13faa7/ella/core/managers.py#L123-L138
ella/ella
ella/core/managers.py
ListingManager.get_listing
def get_listing(self, category=None, children=ListingHandler.NONE, count=10, offset=0, content_types=[], date_range=(), exclude=None, **kwargs): """ Get top objects for given category and potentionally also its child categories. Params: category - Category object to list objects for. None if any category will do count - number of objects to output, defaults to 10 offset - starting with object number... 1-based content_types - list of ContentTypes to list, if empty, object from all models are included date_range - range for listing's publish_from field **kwargs - rest of the parameter are passed to the queryset unchanged """ assert offset >= 0, "Offset must be a positive integer" assert count >= 0, "Count must be a positive integer" if not count: return [] limit = offset + count qset = self.get_listing_queryset(category, children, content_types, date_range, exclude, **kwargs) # direct listings, we don't need to check for duplicates if children == ListingHandler.NONE: return qset[offset:limit] seen = set() out = [] while len(out) < count: skip = 0 # 2 i a reasonable value for padding, wouldn't you say dear Watson? for l in qset[offset:limit + 2]: if l.publishable_id not in seen: seen.add(l.publishable_id) out.append(l) if len(out) == count: break else: skip += 1 # no enough skipped, or not enough listings to work with, no need for another try if skip <= 2 or (len(out) + skip) < (count + 2): break # get another page to fill in the gaps offset += count limit += count return out
python
def get_listing(self, category=None, children=ListingHandler.NONE, count=10, offset=0, content_types=[], date_range=(), exclude=None, **kwargs): """ Get top objects for given category and potentionally also its child categories. Params: category - Category object to list objects for. None if any category will do count - number of objects to output, defaults to 10 offset - starting with object number... 1-based content_types - list of ContentTypes to list, if empty, object from all models are included date_range - range for listing's publish_from field **kwargs - rest of the parameter are passed to the queryset unchanged """ assert offset >= 0, "Offset must be a positive integer" assert count >= 0, "Count must be a positive integer" if not count: return [] limit = offset + count qset = self.get_listing_queryset(category, children, content_types, date_range, exclude, **kwargs) # direct listings, we don't need to check for duplicates if children == ListingHandler.NONE: return qset[offset:limit] seen = set() out = [] while len(out) < count: skip = 0 # 2 i a reasonable value for padding, wouldn't you say dear Watson? for l in qset[offset:limit + 2]: if l.publishable_id not in seen: seen.add(l.publishable_id) out.append(l) if len(out) == count: break else: skip += 1 # no enough skipped, or not enough listings to work with, no need for another try if skip <= 2 or (len(out) + skip) < (count + 2): break # get another page to fill in the gaps offset += count limit += count return out
Get top objects for given category and potentionally also its child categories. Params: category - Category object to list objects for. None if any category will do count - number of objects to output, defaults to 10 offset - starting with object number... 1-based content_types - list of ContentTypes to list, if empty, object from all models are included date_range - range for listing's publish_from field **kwargs - rest of the parameter are passed to the queryset unchanged
https://github.com/ella/ella/blob/4a1414991f649dc21c4b777dc6b41a922a13faa7/ella/core/managers.py#L258-L306
ella/ella
ella/core/templatetags/pagination.py
paginator
def paginator(context, adjacent_pages=2, template_name=None): """ Renders a ``inclusion_tags/paginator.html`` or ``inc/paginator.html`` template with additional pagination context. To be used in conjunction with the ``object_list`` generic view. If ``TEMPLATE_NAME`` parameter is given, ``inclusion_tags/paginator_TEMPLATE_NAME.html`` or ``inc/paginator_TEMPLATE_NAME.html`` will be used instead. Adds pagination context variables for use in displaying first, adjacent pages and last page links in addition to those created by the ``object_list`` generic view. Taken from http://www.djangosnippets.org/snippets/73/ Syntax:: {% paginator [NUMBER_OF_ADJACENT_PAGES] [TEMPLATE_NAME] %} Examples:: {% paginator %} {% paginator 5 %} {% paginator 5 "special" %} # with Django 1.4 and above you can also do: {% paginator template_name="special" %} """ tname, context = _do_paginator(context, adjacent_pages, template_name) return render_to_string(tname, context)
python
def paginator(context, adjacent_pages=2, template_name=None): """ Renders a ``inclusion_tags/paginator.html`` or ``inc/paginator.html`` template with additional pagination context. To be used in conjunction with the ``object_list`` generic view. If ``TEMPLATE_NAME`` parameter is given, ``inclusion_tags/paginator_TEMPLATE_NAME.html`` or ``inc/paginator_TEMPLATE_NAME.html`` will be used instead. Adds pagination context variables for use in displaying first, adjacent pages and last page links in addition to those created by the ``object_list`` generic view. Taken from http://www.djangosnippets.org/snippets/73/ Syntax:: {% paginator [NUMBER_OF_ADJACENT_PAGES] [TEMPLATE_NAME] %} Examples:: {% paginator %} {% paginator 5 %} {% paginator 5 "special" %} # with Django 1.4 and above you can also do: {% paginator template_name="special" %} """ tname, context = _do_paginator(context, adjacent_pages, template_name) return render_to_string(tname, context)
Renders a ``inclusion_tags/paginator.html`` or ``inc/paginator.html`` template with additional pagination context. To be used in conjunction with the ``object_list`` generic view. If ``TEMPLATE_NAME`` parameter is given, ``inclusion_tags/paginator_TEMPLATE_NAME.html`` or ``inc/paginator_TEMPLATE_NAME.html`` will be used instead. Adds pagination context variables for use in displaying first, adjacent pages and last page links in addition to those created by the ``object_list`` generic view. Taken from http://www.djangosnippets.org/snippets/73/ Syntax:: {% paginator [NUMBER_OF_ADJACENT_PAGES] [TEMPLATE_NAME] %} Examples:: {% paginator %} {% paginator 5 %} {% paginator 5 "special" %} # with Django 1.4 and above you can also do: {% paginator template_name="special" %}
https://github.com/ella/ella/blob/4a1414991f649dc21c4b777dc6b41a922a13faa7/ella/core/templatetags/pagination.py#L45-L75
ella/ella
ella/core/templatetags/authors.py
do_author_listing
def do_author_listing(parser, token): """ Get N listing objects that were published by given author recently and optionally omit a publishable object in results. **Usage**:: {% author_listing <author> <limit> as <result> [omit <obj>] %} **Parameters**:: ================================== ================================================ Option Description ================================== ================================================ ``author`` Author to load objects for. ``limit`` Maximum number of objects to store, ``result`` Store the resulting list in context under given name. ================================== ================================================ **Examples**:: {% author_listing object.authors.all.0 10 as article_listing %} """ contents = token.split_contents() if len(contents) not in [5, 7]: raise template.TemplateSyntaxError('%r tag requires 4 or 6 arguments.' % contents[0]) elif len(contents) == 5: tag, obj_var, count, fill, var_name = contents return AuthorListingNode(obj_var, count, var_name) else: tag, obj_var, count, fill, var_name, filll, omit_var = contents return AuthorListingNode(obj_var, count, var_name, omit_var)
python
def do_author_listing(parser, token): """ Get N listing objects that were published by given author recently and optionally omit a publishable object in results. **Usage**:: {% author_listing <author> <limit> as <result> [omit <obj>] %} **Parameters**:: ================================== ================================================ Option Description ================================== ================================================ ``author`` Author to load objects for. ``limit`` Maximum number of objects to store, ``result`` Store the resulting list in context under given name. ================================== ================================================ **Examples**:: {% author_listing object.authors.all.0 10 as article_listing %} """ contents = token.split_contents() if len(contents) not in [5, 7]: raise template.TemplateSyntaxError('%r tag requires 4 or 6 arguments.' % contents[0]) elif len(contents) == 5: tag, obj_var, count, fill, var_name = contents return AuthorListingNode(obj_var, count, var_name) else: tag, obj_var, count, fill, var_name, filll, omit_var = contents return AuthorListingNode(obj_var, count, var_name, omit_var)
Get N listing objects that were published by given author recently and optionally omit a publishable object in results. **Usage**:: {% author_listing <author> <limit> as <result> [omit <obj>] %} **Parameters**:: ================================== ================================================ Option Description ================================== ================================================ ``author`` Author to load objects for. ``limit`` Maximum number of objects to store, ``result`` Store the resulting list in context under given name. ================================== ================================================ **Examples**:: {% author_listing object.authors.all.0 10 as article_listing %}
https://github.com/ella/ella/blob/4a1414991f649dc21c4b777dc6b41a922a13faa7/ella/core/templatetags/authors.py#L40-L72
jjgomera/iapws
iapws/iapws08.py
_Tb
def _Tb(P, S): """Procedure to calculate the boiling temperature of seawater Parameters ---------- P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- Tb : float Boiling temperature, [K] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 7 """ def f(T): pw = _Region1(T, P) gw = pw["h"]-T*pw["s"] pv = _Region2(T, P) gv = pv["h"]-T*pv["s"] ps = SeaWater._saline(T, P, S) return -ps["g"]+S*ps["gs"]-gw+gv Tb = fsolve(f, 300)[0] return Tb
python
def _Tb(P, S): """Procedure to calculate the boiling temperature of seawater Parameters ---------- P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- Tb : float Boiling temperature, [K] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 7 """ def f(T): pw = _Region1(T, P) gw = pw["h"]-T*pw["s"] pv = _Region2(T, P) gv = pv["h"]-T*pv["s"] ps = SeaWater._saline(T, P, S) return -ps["g"]+S*ps["gs"]-gw+gv Tb = fsolve(f, 300)[0] return Tb
Procedure to calculate the boiling temperature of seawater Parameters ---------- P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- Tb : float Boiling temperature, [K] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 7
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L408-L439
jjgomera/iapws
iapws/iapws08.py
_Tf
def _Tf(P, S): """Procedure to calculate the freezing temperature of seawater Parameters ---------- P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- Tf : float Freezing temperature, [K] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 12 """ def f(T): T = float(T) pw = _Region1(T, P) gw = pw["h"]-T*pw["s"] gih = _Ice(T, P)["g"] ps = SeaWater._saline(T, P, S) return -ps["g"]+S*ps["gs"]-gw+gih Tf = fsolve(f, 300)[0] return Tf
python
def _Tf(P, S): """Procedure to calculate the freezing temperature of seawater Parameters ---------- P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- Tf : float Freezing temperature, [K] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 12 """ def f(T): T = float(T) pw = _Region1(T, P) gw = pw["h"]-T*pw["s"] gih = _Ice(T, P)["g"] ps = SeaWater._saline(T, P, S) return -ps["g"]+S*ps["gs"]-gw+gih Tf = fsolve(f, 300)[0] return Tf
Procedure to calculate the freezing temperature of seawater Parameters ---------- P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- Tf : float Freezing temperature, [K] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 12
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L442-L473
jjgomera/iapws
iapws/iapws08.py
_Triple
def _Triple(S): """Procedure to calculate the triple point pressure and temperature for seawater Parameters ---------- S : float Salinity, [kg/kg] Returns ------- prop : dict Dictionary with the triple point properties: * Tt: Triple point temperature, [K] * Pt: Triple point pressure, [MPa] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 7 """ def f(parr): T, P = parr pw = _Region1(T, P) gw = pw["h"]-T*pw["s"] pv = _Region2(T, P) gv = pv["h"]-T*pv["s"] gih = _Ice(T, P)["g"] ps = SeaWater._saline(T, P, S) return -ps["g"]+S*ps["gs"]-gw+gih, -ps["g"]+S*ps["gs"]-gw+gv Tt, Pt = fsolve(f, [273, 6e-4]) prop = {} prop["Tt"] = Tt prop["Pt"] = Pt return prop
python
def _Triple(S): """Procedure to calculate the triple point pressure and temperature for seawater Parameters ---------- S : float Salinity, [kg/kg] Returns ------- prop : dict Dictionary with the triple point properties: * Tt: Triple point temperature, [K] * Pt: Triple point pressure, [MPa] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 7 """ def f(parr): T, P = parr pw = _Region1(T, P) gw = pw["h"]-T*pw["s"] pv = _Region2(T, P) gv = pv["h"]-T*pv["s"] gih = _Ice(T, P)["g"] ps = SeaWater._saline(T, P, S) return -ps["g"]+S*ps["gs"]-gw+gih, -ps["g"]+S*ps["gs"]-gw+gv Tt, Pt = fsolve(f, [273, 6e-4]) prop = {} prop["Tt"] = Tt prop["Pt"] = Pt return prop
Procedure to calculate the triple point pressure and temperature for seawater Parameters ---------- S : float Salinity, [kg/kg] Returns ------- prop : dict Dictionary with the triple point properties: * Tt: Triple point temperature, [K] * Pt: Triple point pressure, [MPa] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 7
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L476-L516
jjgomera/iapws
iapws/iapws08.py
_OsmoticPressure
def _OsmoticPressure(T, P, S): """Procedure to calculate the osmotic pressure of seawater Parameters ---------- T : float Tmperature, [K] P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- Posm : float Osmotic pressure, [MPa] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 15 """ pw = _Region1(T, P) gw = pw["h"]-T*pw["s"] def f(Posm): pw2 = _Region1(T, P+Posm) gw2 = pw2["h"]-T*pw2["s"] ps = SeaWater._saline(T, P+Posm, S) return -ps["g"]+S*ps["gs"]-gw+gw2 Posm = fsolve(f, 0)[0] return Posm
python
def _OsmoticPressure(T, P, S): """Procedure to calculate the osmotic pressure of seawater Parameters ---------- T : float Tmperature, [K] P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- Posm : float Osmotic pressure, [MPa] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 15 """ pw = _Region1(T, P) gw = pw["h"]-T*pw["s"] def f(Posm): pw2 = _Region1(T, P+Posm) gw2 = pw2["h"]-T*pw2["s"] ps = SeaWater._saline(T, P+Posm, S) return -ps["g"]+S*ps["gs"]-gw+gw2 Posm = fsolve(f, 0)[0] return Posm
Procedure to calculate the osmotic pressure of seawater Parameters ---------- T : float Tmperature, [K] P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- Posm : float Osmotic pressure, [MPa] References ---------- IAPWS, Advisory Note No. 5: Industrial Calculation of the Thermodynamic Properties of Seawater, http://www.iapws.org/relguide/Advise5.html, Eq 15
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L519-L551
jjgomera/iapws
iapws/iapws08.py
_ThCond_SeaWater
def _ThCond_SeaWater(T, P, S): """Equation for the thermal conductivity of seawater Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- k : float Thermal conductivity excess relative to that of the pure water, [W/mK] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 273.15 ≤ T ≤ 523.15 * 0 ≤ P ≤ 140 * 0 ≤ S ≤ 0.17 Examples -------- >>> _ThCond_Seawater(293.15, 0.1, 0.035) -0.00418604 References ---------- IAPWS, Guideline on the Thermal Conductivity of Seawater, http://www.iapws.org/relguide/Seawater-ThCond.html """ # Check input parameters if T < 273.15 or T > 523.15 or P < 0 or P > 140 or S < 0 or S > 0.17: raise NotImplementedError("Incoming out of bound") # Eq 4 a1 = -7.180891e-5+1.831971e-7*P a2 = 1.048077e-3-4.494722e-6*P # Eq 5 b1 = 1.463375e-1+9.208586e-4*P b2 = -3.086908e-3+1.798489e-5*P a = a1*exp(a2*(T-273.15)) # Eq 2 b = b1*exp(b2*(T-273.15)) # Eq 3 # Eq 1 DL = a*(1000*S)**(1+b) return DL
python
def _ThCond_SeaWater(T, P, S): """Equation for the thermal conductivity of seawater Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- k : float Thermal conductivity excess relative to that of the pure water, [W/mK] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 273.15 ≤ T ≤ 523.15 * 0 ≤ P ≤ 140 * 0 ≤ S ≤ 0.17 Examples -------- >>> _ThCond_Seawater(293.15, 0.1, 0.035) -0.00418604 References ---------- IAPWS, Guideline on the Thermal Conductivity of Seawater, http://www.iapws.org/relguide/Seawater-ThCond.html """ # Check input parameters if T < 273.15 or T > 523.15 or P < 0 or P > 140 or S < 0 or S > 0.17: raise NotImplementedError("Incoming out of bound") # Eq 4 a1 = -7.180891e-5+1.831971e-7*P a2 = 1.048077e-3-4.494722e-6*P # Eq 5 b1 = 1.463375e-1+9.208586e-4*P b2 = -3.086908e-3+1.798489e-5*P a = a1*exp(a2*(T-273.15)) # Eq 2 b = b1*exp(b2*(T-273.15)) # Eq 3 # Eq 1 DL = a*(1000*S)**(1+b) return DL
Equation for the thermal conductivity of seawater Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] S : float Salinity, [kg/kg] Returns ------- k : float Thermal conductivity excess relative to that of the pure water, [W/mK] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 273.15 ≤ T ≤ 523.15 * 0 ≤ P ≤ 140 * 0 ≤ S ≤ 0.17 Examples -------- >>> _ThCond_Seawater(293.15, 0.1, 0.035) -0.00418604 References ---------- IAPWS, Guideline on the Thermal Conductivity of Seawater, http://www.iapws.org/relguide/Seawater-ThCond.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L554-L606
jjgomera/iapws
iapws/iapws08.py
_solNa2SO4
def _solNa2SO4(T, mH2SO4, mNaCl): """Equation for the solubility of sodium sulfate in aqueous mixtures of sodium chloride and sulfuric acid Parameters ---------- T : float Temperature, [K] mH2SO4 : float Molality of sufuric acid, [mol/kg(water)] mNaCl : float Molality of sodium chloride, [mol/kg(water)] Returns ------- S : float Molal solutility of sodium sulfate, [mol/kg(water)] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 523.15 ≤ T ≤ 623.15 * 0 ≤ mH2SO4 ≤ 0.75 * 0 ≤ mNaCl ≤ 2.25 Examples -------- >>> _solNa2SO4(523.15, 0.25, 0.75) 2.68 References ---------- IAPWS, Solubility of Sodium Sulfate in Aqueous Mixtures of Sodium Chloride and Sulfuric Acid from Water to Concentrated Solutions, http://www.iapws.org/relguide/na2so4.pdf """ # Check input parameters if T < 523.15 or T > 623.15 or mH2SO4 < 0 or mH2SO4 > 0.75 or \ mNaCl < 0 or mNaCl > 2.25: raise NotImplementedError("Incoming out of bound") A00 = -0.8085987*T+81.4613752+0.10537803*T*log(T) A10 = 3.4636364*T-281.63322-0.46779874*T*log(T) A20 = -6.0029634*T+480.60108+0.81382854*T*log(T) A30 = 4.4540258*T-359.36872-0.60306734*T*log(T) A01 = 0.4909061*T-46.556271-0.064612393*T*log(T) A02 = -0.002781314*T+1.722695+0.0000013319698*T*log(T) A03 = -0.014074108*T+0.99020227+0.0019397832*T*log(T) A11 = -0.87146573*T+71.808756+0.11749585*T*log(T) S = A00 + A10*mH2SO4 + A20*mH2SO4**2 + A30*mH2SO4**3 + A01*mNaCl + \ A02*mNaCl**2 + A03*mNaCl**3 + A11*mH2SO4*mNaCl return S
python
def _solNa2SO4(T, mH2SO4, mNaCl): """Equation for the solubility of sodium sulfate in aqueous mixtures of sodium chloride and sulfuric acid Parameters ---------- T : float Temperature, [K] mH2SO4 : float Molality of sufuric acid, [mol/kg(water)] mNaCl : float Molality of sodium chloride, [mol/kg(water)] Returns ------- S : float Molal solutility of sodium sulfate, [mol/kg(water)] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 523.15 ≤ T ≤ 623.15 * 0 ≤ mH2SO4 ≤ 0.75 * 0 ≤ mNaCl ≤ 2.25 Examples -------- >>> _solNa2SO4(523.15, 0.25, 0.75) 2.68 References ---------- IAPWS, Solubility of Sodium Sulfate in Aqueous Mixtures of Sodium Chloride and Sulfuric Acid from Water to Concentrated Solutions, http://www.iapws.org/relguide/na2so4.pdf """ # Check input parameters if T < 523.15 or T > 623.15 or mH2SO4 < 0 or mH2SO4 > 0.75 or \ mNaCl < 0 or mNaCl > 2.25: raise NotImplementedError("Incoming out of bound") A00 = -0.8085987*T+81.4613752+0.10537803*T*log(T) A10 = 3.4636364*T-281.63322-0.46779874*T*log(T) A20 = -6.0029634*T+480.60108+0.81382854*T*log(T) A30 = 4.4540258*T-359.36872-0.60306734*T*log(T) A01 = 0.4909061*T-46.556271-0.064612393*T*log(T) A02 = -0.002781314*T+1.722695+0.0000013319698*T*log(T) A03 = -0.014074108*T+0.99020227+0.0019397832*T*log(T) A11 = -0.87146573*T+71.808756+0.11749585*T*log(T) S = A00 + A10*mH2SO4 + A20*mH2SO4**2 + A30*mH2SO4**3 + A01*mNaCl + \ A02*mNaCl**2 + A03*mNaCl**3 + A11*mH2SO4*mNaCl return S
Equation for the solubility of sodium sulfate in aqueous mixtures of sodium chloride and sulfuric acid Parameters ---------- T : float Temperature, [K] mH2SO4 : float Molality of sufuric acid, [mol/kg(water)] mNaCl : float Molality of sodium chloride, [mol/kg(water)] Returns ------- S : float Molal solutility of sodium sulfate, [mol/kg(water)] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 523.15 ≤ T ≤ 623.15 * 0 ≤ mH2SO4 ≤ 0.75 * 0 ≤ mNaCl ≤ 2.25 Examples -------- >>> _solNa2SO4(523.15, 0.25, 0.75) 2.68 References ---------- IAPWS, Solubility of Sodium Sulfate in Aqueous Mixtures of Sodium Chloride and Sulfuric Acid from Water to Concentrated Solutions, http://www.iapws.org/relguide/na2so4.pdf
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L609-L663
jjgomera/iapws
iapws/iapws08.py
_critNaCl
def _critNaCl(x): """Equation for the critical locus of aqueous solutions of sodium chloride Parameters ---------- x : float Mole fraction of NaCl, [-] Returns ------- prop : dict A dictionary withe the properties: * Tc: critical temperature, [K] * Pc: critical pressure, [MPa] * rhoc: critical density, [kg/m³] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0 ≤ x ≤ 0.12 Examples -------- >>> _critNaCl(0.1) 975.571016 References ---------- IAPWS, Revised Guideline on the Critical Locus of Aqueous Solutions of Sodium Chloride, http://www.iapws.org/relguide/critnacl.html """ # Check input parameters if x < 0 or x > 0.12: raise NotImplementedError("Incoming out of bound") T1 = Tc*(1 + 2.3e1*x - 3.3e2*x**1.5 - 1.8e3*x**2) T2 = Tc*(1 + 1.757e1*x - 3.026e2*x**1.5 + 2.838e3*x**2 - 1.349e4*x**2.5 + 3.278e4*x**3 - 3.674e4*x**3.5 + 1.437e4*x**4) f1 = (abs(10000*x-10-1)-abs(10000*x-10+1))/4+0.5 f2 = (abs(10000*x-10+1)-abs(10000*x-10-1))/4+0.5 # Eq 1 tc = f1*T1+f2*T2 # Eq 7 rc = rhoc*(1 + 1.7607e2*x - 2.9693e3*x**1.5 + 2.4886e4*x**2 - 1.1377e5*x**2.5 + 2.8847e5*x**3 - 3.8195e5*x**3.5 + 2.0633e5*x**4) # Eq 8 DT = tc-Tc pc = Pc*(1+9.1443e-3*DT+5.1636e-5*DT**2-2.5360e-7*DT**3+3.6494e-10*DT**4) prop = {} prop["Tc"] = tc prop["rhoc"] = rc prop["Pc"] = pc return prop
python
def _critNaCl(x): """Equation for the critical locus of aqueous solutions of sodium chloride Parameters ---------- x : float Mole fraction of NaCl, [-] Returns ------- prop : dict A dictionary withe the properties: * Tc: critical temperature, [K] * Pc: critical pressure, [MPa] * rhoc: critical density, [kg/m³] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0 ≤ x ≤ 0.12 Examples -------- >>> _critNaCl(0.1) 975.571016 References ---------- IAPWS, Revised Guideline on the Critical Locus of Aqueous Solutions of Sodium Chloride, http://www.iapws.org/relguide/critnacl.html """ # Check input parameters if x < 0 or x > 0.12: raise NotImplementedError("Incoming out of bound") T1 = Tc*(1 + 2.3e1*x - 3.3e2*x**1.5 - 1.8e3*x**2) T2 = Tc*(1 + 1.757e1*x - 3.026e2*x**1.5 + 2.838e3*x**2 - 1.349e4*x**2.5 + 3.278e4*x**3 - 3.674e4*x**3.5 + 1.437e4*x**4) f1 = (abs(10000*x-10-1)-abs(10000*x-10+1))/4+0.5 f2 = (abs(10000*x-10+1)-abs(10000*x-10-1))/4+0.5 # Eq 1 tc = f1*T1+f2*T2 # Eq 7 rc = rhoc*(1 + 1.7607e2*x - 2.9693e3*x**1.5 + 2.4886e4*x**2 - 1.1377e5*x**2.5 + 2.8847e5*x**3 - 3.8195e5*x**3.5 + 2.0633e5*x**4) # Eq 8 DT = tc-Tc pc = Pc*(1+9.1443e-3*DT+5.1636e-5*DT**2-2.5360e-7*DT**3+3.6494e-10*DT**4) prop = {} prop["Tc"] = tc prop["rhoc"] = rc prop["Pc"] = pc return prop
Equation for the critical locus of aqueous solutions of sodium chloride Parameters ---------- x : float Mole fraction of NaCl, [-] Returns ------- prop : dict A dictionary withe the properties: * Tc: critical temperature, [K] * Pc: critical pressure, [MPa] * rhoc: critical density, [kg/m³] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0 ≤ x ≤ 0.12 Examples -------- >>> _critNaCl(0.1) 975.571016 References ---------- IAPWS, Revised Guideline on the Critical Locus of Aqueous Solutions of Sodium Chloride, http://www.iapws.org/relguide/critnacl.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L666-L725
jjgomera/iapws
iapws/iapws08.py
SeaWater.calculo
def calculo(self): """Calculate procedure""" T = self.kwargs["T"] P = self.kwargs["P"] S = self.kwargs["S"] self.m = S/(1-S)/Ms if self.kwargs["fast"] and T <= 313.15: pw = self._waterSupp(T, P) elif self.kwargs["IF97"]: pw = self._waterIF97(T, P) else: pw = self._water(T, P) ps = self._saline(T, P, S) prop = {} for key in ps: prop[key] = pw[key]+ps[key] self.__setattr__(key, prop[key]) self.T = T self.P = P self.rho = 1./prop["gp"] self.v = prop["gp"] self.s = -prop["gt"] self.cp = -T*prop["gtt"] self.cv = T*(prop["gtp"]**2/prop["gpp"]-prop["gtt"]) self.h = prop["g"]-T*prop["gt"] self.u = prop["g"]-T*prop["gt"]-P*1000*prop["gp"] self.a = prop["g"]-P*1000*prop["gp"] self.alfav = prop["gtp"]/prop["gp"] self.betas = -prop["gtp"]/prop["gtt"] self.xkappa = -prop["gpp"]/prop["gp"] self.ks = (prop["gtp"]**2-prop["gtt"]*prop["gpp"])/prop["gp"] / \ prop["gtt"] self.w = prop["gp"]*(prop["gtt"]*1000/(prop["gtp"]**2 - prop["gtt"]*1000*prop["gpp"]*1e-6))**0.5 if "thcond" in pw: kw = pw["thcond"] else: kw = _ThCond(1/pw["gp"], T) try: self.k = _ThCond_SeaWater(T, P, S)+kw except NotImplementedError: self.k = None if S: self.mu = prop["gs"] self.muw = prop["g"]-S*prop["gs"] self.mus = prop["g"]+(1-S)*prop["gs"] self.osm = -(ps["g"]-S*prop["gs"])/self.m/Rm/T self.haline = -prop["gsp"]/prop["gp"] else: self.mu = None self.muw = None self.mus = None self.osm = None self.haline = None
python
def calculo(self): """Calculate procedure""" T = self.kwargs["T"] P = self.kwargs["P"] S = self.kwargs["S"] self.m = S/(1-S)/Ms if self.kwargs["fast"] and T <= 313.15: pw = self._waterSupp(T, P) elif self.kwargs["IF97"]: pw = self._waterIF97(T, P) else: pw = self._water(T, P) ps = self._saline(T, P, S) prop = {} for key in ps: prop[key] = pw[key]+ps[key] self.__setattr__(key, prop[key]) self.T = T self.P = P self.rho = 1./prop["gp"] self.v = prop["gp"] self.s = -prop["gt"] self.cp = -T*prop["gtt"] self.cv = T*(prop["gtp"]**2/prop["gpp"]-prop["gtt"]) self.h = prop["g"]-T*prop["gt"] self.u = prop["g"]-T*prop["gt"]-P*1000*prop["gp"] self.a = prop["g"]-P*1000*prop["gp"] self.alfav = prop["gtp"]/prop["gp"] self.betas = -prop["gtp"]/prop["gtt"] self.xkappa = -prop["gpp"]/prop["gp"] self.ks = (prop["gtp"]**2-prop["gtt"]*prop["gpp"])/prop["gp"] / \ prop["gtt"] self.w = prop["gp"]*(prop["gtt"]*1000/(prop["gtp"]**2 - prop["gtt"]*1000*prop["gpp"]*1e-6))**0.5 if "thcond" in pw: kw = pw["thcond"] else: kw = _ThCond(1/pw["gp"], T) try: self.k = _ThCond_SeaWater(T, P, S)+kw except NotImplementedError: self.k = None if S: self.mu = prop["gs"] self.muw = prop["g"]-S*prop["gs"] self.mus = prop["g"]+(1-S)*prop["gs"] self.osm = -(ps["g"]-S*prop["gs"])/self.m/Rm/T self.haline = -prop["gsp"]/prop["gp"] else: self.mu = None self.muw = None self.mus = None self.osm = None self.haline = None
Calculate procedure
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L178-L236
jjgomera/iapws
iapws/iapws08.py
SeaWater._water
def _water(cls, T, P): """Get properties of pure water, Table4 pag 8""" water = IAPWS95(P=P, T=T) prop = {} prop["g"] = water.h-T*water.s prop["gt"] = -water.s prop["gp"] = 1./water.rho prop["gtt"] = -water.cp/T prop["gtp"] = water.betas*water.cp/T prop["gpp"] = -1e6/(water.rho*water.w)**2-water.betas**2*1e3*water.cp/T prop["gs"] = 0 prop["gsp"] = 0 prop["thcond"] = water.k return prop
python
def _water(cls, T, P): """Get properties of pure water, Table4 pag 8""" water = IAPWS95(P=P, T=T) prop = {} prop["g"] = water.h-T*water.s prop["gt"] = -water.s prop["gp"] = 1./water.rho prop["gtt"] = -water.cp/T prop["gtp"] = water.betas*water.cp/T prop["gpp"] = -1e6/(water.rho*water.w)**2-water.betas**2*1e3*water.cp/T prop["gs"] = 0 prop["gsp"] = 0 prop["thcond"] = water.k return prop
Get properties of pure water, Table4 pag 8
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L244-L257
jjgomera/iapws
iapws/iapws08.py
SeaWater._waterSupp
def _waterSupp(cls, T, P): """Get properties of pure water using the supplementary release SR7-09, Table4 pag 6""" tau = (T-273.15)/40 pi = (P-0.101325)/100 J = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7] K = [0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1] G = [0.101342743139674e3, 0.100015695367145e6, -0.254457654203630e4, 0.284517778446287e3, -0.333146754253611e2, 0.420263108803084e1, -0.546428511471039, 0.590578347909402e1, -0.270983805184062e3, 0.776153611613101e3, -0.196512550881220e3, 0.289796526294175e2, -0.213290083518327e1, -0.123577859330390e5, 0.145503645404680e4, -0.756558385769359e3, 0.273479662323528e3, -0.555604063817218e2, 0.434420671917197e1, 0.736741204151612e3, -0.672507783145070e3, 0.499360390819152e3, -0.239545330654412e3, 0.488012518593872e2, -0.166307106208905e1, -0.148185936433658e3, 0.397968445406972e3, -0.301815380621876e3, 0.152196371733841e3, -0.263748377232802e2, 0.580259125842571e2, -0.194618310617595e3, 0.120520654902025e3, -0.552723052340152e2, 0.648190668077221e1, -0.189843846514172e2, 0.635113936641785e2, -0.222897317140459e2, 0.817060541818112e1, 0.305081646487967e1, -0.963108119393062e1] g, gt, gp, gtt, gtp, gpp = 0, 0, 0, 0, 0, 0 for j, k, gi in zip(J, K, G): g += gi*tau**j*pi**k if j >= 1: gt += gi*j*tau**(j-1)*pi**k if k >= 1: gp += k*gi*tau**j*pi**(k-1) if j >= 2: gtt += j*(j-1)*gi*tau**(j-2)*pi**k if j >= 1 and k >= 1: gtp += j*k*gi*tau**(j-1)*pi**(k-1) if k >= 2: gpp += k*(k-1)*gi*tau**j*pi**(k-2) prop = {} prop["g"] = g*1e-3 prop["gt"] = gt/40*1e-3 prop["gp"] = gp/100*1e-6 prop["gtt"] = gtt/40**2*1e-3 prop["gtp"] = gtp/40/100*1e-6 prop["gpp"] = gpp/100**2*1e-6 prop["gs"] = 0 prop["gsp"] = 0 return prop
python
def _waterSupp(cls, T, P): """Get properties of pure water using the supplementary release SR7-09, Table4 pag 6""" tau = (T-273.15)/40 pi = (P-0.101325)/100 J = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7] K = [0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1] G = [0.101342743139674e3, 0.100015695367145e6, -0.254457654203630e4, 0.284517778446287e3, -0.333146754253611e2, 0.420263108803084e1, -0.546428511471039, 0.590578347909402e1, -0.270983805184062e3, 0.776153611613101e3, -0.196512550881220e3, 0.289796526294175e2, -0.213290083518327e1, -0.123577859330390e5, 0.145503645404680e4, -0.756558385769359e3, 0.273479662323528e3, -0.555604063817218e2, 0.434420671917197e1, 0.736741204151612e3, -0.672507783145070e3, 0.499360390819152e3, -0.239545330654412e3, 0.488012518593872e2, -0.166307106208905e1, -0.148185936433658e3, 0.397968445406972e3, -0.301815380621876e3, 0.152196371733841e3, -0.263748377232802e2, 0.580259125842571e2, -0.194618310617595e3, 0.120520654902025e3, -0.552723052340152e2, 0.648190668077221e1, -0.189843846514172e2, 0.635113936641785e2, -0.222897317140459e2, 0.817060541818112e1, 0.305081646487967e1, -0.963108119393062e1] g, gt, gp, gtt, gtp, gpp = 0, 0, 0, 0, 0, 0 for j, k, gi in zip(J, K, G): g += gi*tau**j*pi**k if j >= 1: gt += gi*j*tau**(j-1)*pi**k if k >= 1: gp += k*gi*tau**j*pi**(k-1) if j >= 2: gtt += j*(j-1)*gi*tau**(j-2)*pi**k if j >= 1 and k >= 1: gtp += j*k*gi*tau**(j-1)*pi**(k-1) if k >= 2: gpp += k*(k-1)*gi*tau**j*pi**(k-2) prop = {} prop["g"] = g*1e-3 prop["gt"] = gt/40*1e-3 prop["gp"] = gp/100*1e-6 prop["gtt"] = gtt/40**2*1e-3 prop["gtp"] = gtp/40/100*1e-6 prop["gpp"] = gpp/100**2*1e-6 prop["gs"] = 0 prop["gsp"] = 0 return prop
Get properties of pure water using the supplementary release SR7-09, Table4 pag 6
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L275-L323
jjgomera/iapws
iapws/iapws08.py
SeaWater._saline
def _saline(cls, T, P, S): """Eq 4""" # Check input in range of validity if T <= 261 or T > 353 or P <= 0 or P > 100 or S < 0 or S > 0.12: warnings.warn("Incoming out of bound") S_ = 0.03516504*40/35 X = (S/S_)**0.5 tau = (T-273.15)/40 pi = (P-0.101325)/100 I = [1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 4, 2, 2, 3, 4, 5, 2, 3, 4, 2, 3, 2, 3, 2, 3, 2, 3, 4, 2, 3, 2, 3, 2, 2, 2, 3, 4, 2, 3, 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2] J = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0, 0, 1, 1, 2, 2, 3, 4, 0, 0, 0, 1, 1, 2, 2, 3, 4, 0, 0, 1, 2, 3, 0, 1, 2] K = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5] G = [0.581281456626732e4, 0.141627648484197e4, -0.243214662381794e4, 0.202580115603697e4, -0.109166841042967e4, 0.374601237877840e3, -0.485891069025409e2, 0.851226734946706e3, 0.168072408311545e3, -0.493407510141682e3, 0.543835333000098e3, -0.196028306689776e3, 0.367571622995805e2, 0.880031352997204e3, -0.430664675978042e2, -0.685572509204491e2, -0.225267649263401e3, -0.100227370861875e2, 0.493667694856254e2, 0.914260447751259e2, 0.875600661808945, -0.171397577419788e2, -0.216603240875311e2, 0.249697009569508e1, 0.213016970847183e1, -0.331049154044839e4, 0.199459603073901e3, -0.547919133532887e2, 0.360284195611086e2, 0.729116529735046e3, -0.175292041186547e3, -0.226683558512829e2, -0.860764303783977e3, 0.383058066002476e3, 0.694244814133268e3, -0.460319931801257e3, -0.297728741987187e3, 0.234565187611355e3, 0.384794152978599e3, -0.522940909281335e2, -0.408193978912261e1, -0.343956902961561e3, 0.831923927801819e2, 0.337409530269367e3, -0.541917262517112e2, -0.204889641964903e3, 0.747261411387560e2, -0.965324320107458e2, 0.680444942726459e2, -0.301755111971161e2, 0.124687671116248e3, -0.294830643494290e2, -0.178314556207638e3, 0.256398487389914e2, 0.113561697840594e3, -0.364872919001588e2, 0.158408172766824e2, -0.341251932441282e1, -0.316569643860730e2, 0.442040358308000e2, -0.111282734326413e2, -0.262480156590992e1, 0.704658803315449e1, -0.792001547211682e1] g, gt, gp, gtt, gtp, gpp, gs, gsp = 0, 0, 0, 0, 0, 0, 0, 0 # Calculate only for some salinity if S != 0: for i, j, k, gi in zip(I, J, K, G): if i == 1: g += gi*X**2*log(X)*tau**j*pi**k gs += gi*(2*log(X)+1)*tau**j*pi**k else: g += gi*X**i*tau**j*pi**k gs += i*gi*X**(i-2)*tau**j*pi**k if j >= 1: if i == 1: gt += gi*X**2*log(X)*j*tau**(j-1)*pi**k else: gt += gi*X**i*j*tau**(j-1)*pi**k if k >= 1: gp += k*gi*X**i*tau**j*pi**(k-1) gsp += i*k*gi*X**(i-2)*tau**j*pi**(k-1) if j >= 2: gtt += j*(j-1)*gi*X**i*tau**(j-2)*pi**k if j >= 1 and k >= 1: gtp += j*k*gi*X**i*tau**(j-1)*pi**(k-1) if k >= 2: gpp += k*(k-1)*gi*X**i*tau**j*pi**(k-2) prop = {} prop["g"] = g*1e-3 prop["gt"] = gt/40*1e-3 prop["gp"] = gp/100*1e-6 prop["gtt"] = gtt/40**2*1e-3 prop["gtp"] = gtp/40/100*1e-6 prop["gpp"] = gpp/100**2*1e-6 prop["gs"] = gs/S_/2*1e-3 prop["gsp"] = gsp/S_/2/100*1e-6 return prop
python
def _saline(cls, T, P, S): """Eq 4""" # Check input in range of validity if T <= 261 or T > 353 or P <= 0 or P > 100 or S < 0 or S > 0.12: warnings.warn("Incoming out of bound") S_ = 0.03516504*40/35 X = (S/S_)**0.5 tau = (T-273.15)/40 pi = (P-0.101325)/100 I = [1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 4, 2, 2, 3, 4, 5, 2, 3, 4, 2, 3, 2, 3, 2, 3, 2, 3, 4, 2, 3, 2, 3, 2, 2, 2, 3, 4, 2, 3, 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2] J = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0, 0, 1, 1, 2, 2, 3, 4, 0, 0, 0, 1, 1, 2, 2, 3, 4, 0, 0, 1, 2, 3, 0, 1, 2] K = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5] G = [0.581281456626732e4, 0.141627648484197e4, -0.243214662381794e4, 0.202580115603697e4, -0.109166841042967e4, 0.374601237877840e3, -0.485891069025409e2, 0.851226734946706e3, 0.168072408311545e3, -0.493407510141682e3, 0.543835333000098e3, -0.196028306689776e3, 0.367571622995805e2, 0.880031352997204e3, -0.430664675978042e2, -0.685572509204491e2, -0.225267649263401e3, -0.100227370861875e2, 0.493667694856254e2, 0.914260447751259e2, 0.875600661808945, -0.171397577419788e2, -0.216603240875311e2, 0.249697009569508e1, 0.213016970847183e1, -0.331049154044839e4, 0.199459603073901e3, -0.547919133532887e2, 0.360284195611086e2, 0.729116529735046e3, -0.175292041186547e3, -0.226683558512829e2, -0.860764303783977e3, 0.383058066002476e3, 0.694244814133268e3, -0.460319931801257e3, -0.297728741987187e3, 0.234565187611355e3, 0.384794152978599e3, -0.522940909281335e2, -0.408193978912261e1, -0.343956902961561e3, 0.831923927801819e2, 0.337409530269367e3, -0.541917262517112e2, -0.204889641964903e3, 0.747261411387560e2, -0.965324320107458e2, 0.680444942726459e2, -0.301755111971161e2, 0.124687671116248e3, -0.294830643494290e2, -0.178314556207638e3, 0.256398487389914e2, 0.113561697840594e3, -0.364872919001588e2, 0.158408172766824e2, -0.341251932441282e1, -0.316569643860730e2, 0.442040358308000e2, -0.111282734326413e2, -0.262480156590992e1, 0.704658803315449e1, -0.792001547211682e1] g, gt, gp, gtt, gtp, gpp, gs, gsp = 0, 0, 0, 0, 0, 0, 0, 0 # Calculate only for some salinity if S != 0: for i, j, k, gi in zip(I, J, K, G): if i == 1: g += gi*X**2*log(X)*tau**j*pi**k gs += gi*(2*log(X)+1)*tau**j*pi**k else: g += gi*X**i*tau**j*pi**k gs += i*gi*X**(i-2)*tau**j*pi**k if j >= 1: if i == 1: gt += gi*X**2*log(X)*j*tau**(j-1)*pi**k else: gt += gi*X**i*j*tau**(j-1)*pi**k if k >= 1: gp += k*gi*X**i*tau**j*pi**(k-1) gsp += i*k*gi*X**(i-2)*tau**j*pi**(k-1) if j >= 2: gtt += j*(j-1)*gi*X**i*tau**(j-2)*pi**k if j >= 1 and k >= 1: gtp += j*k*gi*X**i*tau**(j-1)*pi**(k-1) if k >= 2: gpp += k*(k-1)*gi*X**i*tau**j*pi**(k-2) prop = {} prop["g"] = g*1e-3 prop["gt"] = gt/40*1e-3 prop["gp"] = gp/100*1e-6 prop["gtt"] = gtt/40**2*1e-3 prop["gtp"] = gtp/40/100*1e-6 prop["gpp"] = gpp/100**2*1e-6 prop["gs"] = gs/S_/2*1e-3 prop["gsp"] = gsp/S_/2/100*1e-6 return prop
Eq 4
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws08.py#L326-L405
jjgomera/iapws
iapws/iapws95.py
_phir
def _phir(tau, delta, coef): """Residual contribution to the adimensional free Helmholtz energy Parameters ---------- tau : float Inverse reduced temperature Tc/T, [-] delta : float Reduced density rho/rhoc, [-] coef : dict Dictionary with equation of state parameters Returns ------- fir : float Adimensional free Helmholtz energy References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 5 http://www.iapws.org/relguide/IAPWS-95.html """ fir = 0 # Polinomial terms nr1 = coef.get("nr1", []) d1 = coef.get("d1", []) t1 = coef.get("t1", []) for n, d, t in zip(nr1, d1, t1): fir += n*delta**d*tau**t # Exponential terms nr2 = coef.get("nr2", []) d2 = coef.get("d2", []) g2 = coef.get("gamma2", []) t2 = coef.get("t2", []) c2 = coef.get("c2", []) for n, d, g, t, c in zip(nr2, d2, g2, t2, c2): fir += n*delta**d*tau**t*exp(-g*delta**c) # Gaussian terms nr3 = coef.get("nr3", []) d3 = coef.get("d3", []) t3 = coef.get("t3", []) a3 = coef.get("alfa3", []) e3 = coef.get("epsilon3", []) b3 = coef.get("beta3", []) g3 = coef.get("gamma3", []) for n, d, t, a, e, b, g in zip(nr3, d3, t3, a3, e3, b3, g3): fir += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2) # Non analitic terms nr4 = coef.get("nr4", []) a4 = coef.get("a4", []) b4 = coef.get("b4", []) Ai = coef.get("A", []) Bi = coef.get("B", []) Ci = coef.get("C", []) Di = coef.get("D", []) bt4 = coef.get("beta4", []) for n, a, b, A, B, C, D, bt in zip(nr4, a4, b4, Ai, Bi, Ci, Di, bt4): Tita = (1-tau)+A*((delta-1)**2)**(0.5/bt) F = exp(-C*(delta-1)**2-D*(tau-1)**2) Delta = Tita**2+B*((delta-1)**2)**a fir += n*Delta**b*delta*F return fir
python
def _phir(tau, delta, coef): """Residual contribution to the adimensional free Helmholtz energy Parameters ---------- tau : float Inverse reduced temperature Tc/T, [-] delta : float Reduced density rho/rhoc, [-] coef : dict Dictionary with equation of state parameters Returns ------- fir : float Adimensional free Helmholtz energy References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 5 http://www.iapws.org/relguide/IAPWS-95.html """ fir = 0 # Polinomial terms nr1 = coef.get("nr1", []) d1 = coef.get("d1", []) t1 = coef.get("t1", []) for n, d, t in zip(nr1, d1, t1): fir += n*delta**d*tau**t # Exponential terms nr2 = coef.get("nr2", []) d2 = coef.get("d2", []) g2 = coef.get("gamma2", []) t2 = coef.get("t2", []) c2 = coef.get("c2", []) for n, d, g, t, c in zip(nr2, d2, g2, t2, c2): fir += n*delta**d*tau**t*exp(-g*delta**c) # Gaussian terms nr3 = coef.get("nr3", []) d3 = coef.get("d3", []) t3 = coef.get("t3", []) a3 = coef.get("alfa3", []) e3 = coef.get("epsilon3", []) b3 = coef.get("beta3", []) g3 = coef.get("gamma3", []) for n, d, t, a, e, b, g in zip(nr3, d3, t3, a3, e3, b3, g3): fir += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2) # Non analitic terms nr4 = coef.get("nr4", []) a4 = coef.get("a4", []) b4 = coef.get("b4", []) Ai = coef.get("A", []) Bi = coef.get("B", []) Ci = coef.get("C", []) Di = coef.get("D", []) bt4 = coef.get("beta4", []) for n, a, b, A, B, C, D, bt in zip(nr4, a4, b4, Ai, Bi, Ci, Di, bt4): Tita = (1-tau)+A*((delta-1)**2)**(0.5/bt) F = exp(-C*(delta-1)**2-D*(tau-1)**2) Delta = Tita**2+B*((delta-1)**2)**a fir += n*Delta**b*delta*F return fir
Residual contribution to the adimensional free Helmholtz energy Parameters ---------- tau : float Inverse reduced temperature Tc/T, [-] delta : float Reduced density rho/rhoc, [-] coef : dict Dictionary with equation of state parameters Returns ------- fir : float Adimensional free Helmholtz energy References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 5 http://www.iapws.org/relguide/IAPWS-95.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L28-L96
jjgomera/iapws
iapws/iapws95.py
mainClassDoc
def mainClassDoc(): """Function decorator used to automatic adiction of base class MEoS in subclass __doc__""" def decorator(f): # __doc__ is only writable in python3. # The doc build must be done with python3 so this snnippet do the work py_version = platform.python_version() if py_version[0] == "3": doc = f.__doc__.split(os.linesep) try: ind = doc.index("") except ValueError: ind = 1 doc1 = os.linesep.join(doc[:ind]) doc3 = os.linesep.join(doc[ind:]) doc2 = os.linesep.join(MEoS.__doc__.split(os.linesep)[3:]) f.__doc__ = doc1 + os.linesep + os.linesep + \ doc2 + os.linesep + os.linesep + doc3 return f return decorator
python
def mainClassDoc(): """Function decorator used to automatic adiction of base class MEoS in subclass __doc__""" def decorator(f): # __doc__ is only writable in python3. # The doc build must be done with python3 so this snnippet do the work py_version = platform.python_version() if py_version[0] == "3": doc = f.__doc__.split(os.linesep) try: ind = doc.index("") except ValueError: ind = 1 doc1 = os.linesep.join(doc[:ind]) doc3 = os.linesep.join(doc[ind:]) doc2 = os.linesep.join(MEoS.__doc__.split(os.linesep)[3:]) f.__doc__ = doc1 + os.linesep + os.linesep + \ doc2 + os.linesep + os.linesep + doc3 return f return decorator
Function decorator used to automatic adiction of base class MEoS in subclass __doc__
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L2195-L2217
jjgomera/iapws
iapws/iapws95.py
MEoS.calculable
def calculable(self): """Check if inputs are enough to define state""" self._mode = "" if self.kwargs["T"] and self.kwargs["P"]: self._mode = "TP" elif self.kwargs["T"] and self.kwargs["rho"]: self._mode = "Trho" elif self.kwargs["T"] and self.kwargs["h"] is not None: self._mode = "Th" elif self.kwargs["T"] and self.kwargs["s"] is not None: self._mode = "Ts" elif self.kwargs["T"] and self.kwargs["u"] is not None: self._mode = "Tu" elif self.kwargs["P"] and self.kwargs["rho"]: self._mode = "Prho" elif self.kwargs["P"] and self.kwargs["h"] is not None: self._mode = "Ph" elif self.kwargs["P"] and self.kwargs["s"] is not None: self._mode = "Ps" elif self.kwargs["P"] and self.kwargs["u"] is not None: self._mode = "Pu" elif self.kwargs["rho"] and self.kwargs["h"] is not None: self._mode = "rhoh" elif self.kwargs["rho"] and self.kwargs["s"] is not None: self._mode = "rhos" elif self.kwargs["rho"] and self.kwargs["u"] is not None: self._mode = "rhou" elif self.kwargs["h"] is not None and self.kwargs["s"] is not None: self._mode = "hs" elif self.kwargs["h"] is not None and self.kwargs["u"] is not None: self._mode = "hu" elif self.kwargs["s"] is not None and self.kwargs["u"] is not None: self._mode = "su" elif self.kwargs["T"] and self.kwargs["x"] is not None: self._mode = "Tx" elif self.kwargs["P"] and self.kwargs["x"] is not None: self._mode = "Px" return bool(self._mode)
python
def calculable(self): """Check if inputs are enough to define state""" self._mode = "" if self.kwargs["T"] and self.kwargs["P"]: self._mode = "TP" elif self.kwargs["T"] and self.kwargs["rho"]: self._mode = "Trho" elif self.kwargs["T"] and self.kwargs["h"] is not None: self._mode = "Th" elif self.kwargs["T"] and self.kwargs["s"] is not None: self._mode = "Ts" elif self.kwargs["T"] and self.kwargs["u"] is not None: self._mode = "Tu" elif self.kwargs["P"] and self.kwargs["rho"]: self._mode = "Prho" elif self.kwargs["P"] and self.kwargs["h"] is not None: self._mode = "Ph" elif self.kwargs["P"] and self.kwargs["s"] is not None: self._mode = "Ps" elif self.kwargs["P"] and self.kwargs["u"] is not None: self._mode = "Pu" elif self.kwargs["rho"] and self.kwargs["h"] is not None: self._mode = "rhoh" elif self.kwargs["rho"] and self.kwargs["s"] is not None: self._mode = "rhos" elif self.kwargs["rho"] and self.kwargs["u"] is not None: self._mode = "rhou" elif self.kwargs["h"] is not None and self.kwargs["s"] is not None: self._mode = "hs" elif self.kwargs["h"] is not None and self.kwargs["u"] is not None: self._mode = "hu" elif self.kwargs["s"] is not None and self.kwargs["u"] is not None: self._mode = "su" elif self.kwargs["T"] and self.kwargs["x"] is not None: self._mode = "Tx" elif self.kwargs["P"] and self.kwargs["x"] is not None: self._mode = "Px" return bool(self._mode)
Check if inputs are enough to define state
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L434-L471
jjgomera/iapws
iapws/iapws95.py
MEoS.calculo
def calculo(self): """Calculate procedure""" T = self.kwargs["T"] rho = self.kwargs["rho"] P = self.kwargs["P"] s = self.kwargs["s"] h = self.kwargs["h"] u = self.kwargs["u"] x = self.kwargs["x"] # Initial values T0 = self.kwargs["T0"] rho0 = self.kwargs["rho0"] if T0 or rho0: To = T0 rhoo = rho0 elif self.name == "air": To = 300 rhoo = 1e-3 else: try: st0 = IAPWS97(**self.kwargs) except NotImplementedError: To = 300 rhoo = 900 else: if st0.status: To = st0.T rhoo = st0.rho else: To = 300 rhoo = 900 self.R = self._constants["R"]/self._constants.get("M", self.M) rhoc = self._constants.get("rhoref", self.rhoc) Tc = self._constants.get("Tref", self.Tc) propiedades = None if self._mode not in ("Tx", "Px"): # Method with iteration necessary to get x if self._mode == "TP": try: if self.name == "air": raise ValueError st0 = IAPWS97(**self.kwargs) rhoo = st0.rho except NotImplementedError: if rho0: rhoo = rho0 elif T < self.Tc and P < self.Pc and \ self._Vapor_Pressure(T) < P: rhoo = self._Liquid_Density(T) elif T < self.Tc and P < self.Pc: rhoo = self._Vapor_Density(T) else: rhoo = self.rhoc*3 except ValueError: rhoo = 1e-3 def f(rho): delta = rho/rhoc tau = Tc/T fird = _phird(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho return Po-P*1000 rho = fsolve(f, rhoo)[0] # Calculate quality if T > self.Tc: x = 1 else: Ps = self._Vapor_Pressure(T) if Ps*0.95 < P < Ps*1.05: rhol, rhov, Ps = self._saturation(T) Ps *= 1e-3 if Ps > P: x = 1 else: x = 0 elif self._mode == "Th": tau = Tc/T ideal = self._phi0(tau, 1) fiot = ideal["fiot"] def f(rho): delta = rho/rhoc fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-h if T >= self.Tc: rhoo = self.rhoc rho = fsolve(f, rhoo)[0] else: x0 = self.kwargs["x0"] rhov = self._Vapor_Density(T) rhol = self._Liquid_Density(T) deltaL = rhol/rhoc deltaG = rhov/rhoc firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hl = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) hv = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) if x0 not in (0, 1) and hl <= h <= hv: rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) hv = vapor["h"] hl = liquido["h"] x = (h-hl)/(hv-hl) rho = 1/(x/rhov+(1-x)/rhol) P = Ps/1000 else: if h > hv: rhoo = rhov else: rhoo = rhol rho = fsolve(f, rhoo)[0] elif self._mode == "Ts": tau = Tc/T def f(rho): if rho < 0: rho = 1e-20 delta = rho/rhoc ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fir = _phir(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) so = self.R*(tau*(fiot+firt)-fio-fir) return so-s if T >= self.Tc: rhoo = self.rhoc rho = fsolve(f, rhoo)[0] else: rhov = self._Vapor_Density(T) rhol = self._Liquid_Density(T) deltaL = rhol/rhoc deltaG = rhov/rhoc idealL = self._phi0(tau, deltaL) idealG = self._phi0(tau, deltaG) fioL = idealL["fio"] fioG = idealG["fio"] fiot = idealL["fiot"] firL = _phir(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) sl = self.R*(tau*(fiot+firtL)-fioL-firL) firG = _phir(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) sv = self.R*(tau*(fiot+firtG)-fioG-firG) if sl <= s <= sv: rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) sv = vapor["s"] sl = liquido["s"] x = (s-sl)/(sv-sl) rho = 1/(x/rhov+(1-x)/rhol) P = Ps/1000 else: if s > sv: rhoo = rhov else: rhoo = rhol rho = fsolve(f, rhoo)[0] elif self._mode == "Tu": tau = Tc/T ideal = self._phi0(tau, 1) fiot = ideal["fiot"] def f(rho): delta = rho/rhoc fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-Po/rho-u if T >= self.Tc: rhoo = self.rhoc rho = fsolve(f, rhoo)[0] else: rhov = self._Vapor_Density(T) rhol = self._Liquid_Density(T) deltaL = rhol/rhoc deltaG = rhov/rhoc firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) PoL = (1+deltaL*firdL)*self.R*T*rhol PoG = (1+deltaG*firdG)*self.R*T*rhov hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) uv = hoG-PoG/rhov ul = hoL-PoL/rhol if ul <= u <= uv: rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) uv = vapor["h"]-vapor["P"]/rhov ul = liquido["h"]-liquido["P"]/rhol x = (u-ul)/(uv-ul) rho = 1/(x/rhov-(1-x)/rhol) P = Ps/1000 else: if u > uv: rhoo = rhov else: rhoo = rhol rho = fsolve(f, rhoo)[0] elif self._mode == "Prho": delta = rho/rhoc def f(T): tau = Tc/T fird = _phird(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho return Po-P*1000 T = fsolve(f, To)[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if T == To or rhov <= rho <= rhol: def f(parr): T, rhol, rhog = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, Ps - P*1000) for to in [To, 300, 400, 500, 600]: rhoLo = self._Liquid_Density(to) rhoGo = self._Vapor_Density(to) sol = fsolve(f, [to, rhoLo, rhoGo], full_output=True) T, rhoL, rhoG = sol[0] x = (1./rho-1/rhoL)/(1/rhoG-1/rhoL) if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "Ph": def funcion(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return Po-P*1000, ho-h rho, T = fsolve(funcion, [rhoo, To]) rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if rho == rhoo or rhov <= rho <= rhol: def f(parr): T, rhol, rhog, x = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc ideal = self._phi0(tau, deltaL) fiot = ideal["fiot"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, hoL*(1-x)+hoG*x - h, Ps - P*1000) for to in [To, 300, 400, 500, 600]: rLo = self._Liquid_Density(to) rGo = self._Vapor_Density(to) sol = fsolve(f, [to, rLo, rGo, 0.5], full_output=True) T, rhoL, rhoG, x = sol[0] if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "Ps": try: x0 = st0.x except NameError: x0 = None if x0 is None or x0 == 0 or x0 == 1: def f(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) fir = _phir(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho so = self.R*(tau*(fiot+firt)-fio-fir) return Po-P*1000, so-s rho, T = fsolve(f, [rhoo, To]) else: def funcion(parr): rho, T = parr rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) x = (1./rho-1/rhol)/(1/rhov-1/rhol) return Ps-P*1000, vapor["s"]*x+liquido["s"]*(1-x)-s rho, T = fsolve(funcion, [2., 500.]) rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) sv = vapor["s"] sl = liquido["s"] x = (s-sl)/(sv-sl) elif self._mode == "Pu": def f(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-Po/rho-u, Po-P*1000 sol = fsolve(f, [rhoo, To], full_output=True) rho, T = sol[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if rho == rhoo or sol[2] != 1: def f(parr): T, rhol, rhog, x = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc ideal = self._phi0(tau, deltaL) fiot = ideal["fiot"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) vu = hoG-Ps/rhog lu = hoL-Ps/rhol return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, lu*(1-x)+vu*x - u, Ps - P*1000) for to in [To, 300, 400, 500, 600]: rLo = self._Liquid_Density(to) rGo = self._Vapor_Density(to) sol = fsolve(f, [to, rLo, rGo, 0.5], full_output=True) T, rhoL, rhoG, x = sol[0] if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "rhoh": delta = rho/rhoc def f(T): tau = Tc/T ideal = self._phi0(tau, delta) fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-h T = fsolve(f, To)[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if T == To or rhov <= rho <= rhol: def f(parr): T, rhol, rhog = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc ideal = self._phi0(tau, deltaL) fiot = ideal["fiot"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG x = (1./rho-1/rhol)/(1/rhog-1/rhol) return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, hoL*(1-x)+hoG*x - h) for to in [To, 300, 400, 500, 600]: rhoLo = self._Liquid_Density(to) rhoGo = self._Vapor_Density(to) sol = fsolve(f, [to, rhoLo, rhoGo], full_output=True) T, rhoL, rhoG = sol[0] x = (1./rho-1/rhoL)/(1/rhoG-1/rhoL) if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "rhos": delta = rho/rhoc def f(T): tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fir = _phir(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) so = self.R*(tau*(fiot+firt)-fio-fir) return so-s T = fsolve(f, To)[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if T == To or rhov <= rho <= rhol: def f(parr): T, rhol, rhog = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc idealL = self._phi0(tau, deltaL) fioL = idealL["fio"] fiot = idealL["fiot"] idealG = self._phi0(tau, deltaG) fioG = idealG["fio"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) soL = self.R*(tau*(fiot+firtL)-fioL-firL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) soG = self.R*(tau*(fiot+firtG)-fioG-firG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG x = (1./rho-1/rhol)/(1/rhog-1/rhol) return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, soL*(1-x)+soG*x - s) for to in [To, 300, 400, 500, 600]: rhoLo = self._Liquid_Density(to) rhoGo = self._Vapor_Density(to) sol = fsolve(f, [to, rhoLo, rhoGo], full_output=True) T, rhoL, rhoG = sol[0] x = (1./rho-1/rhoL)/(1/rhoG-1/rhoL) if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "rhou": delta = rho/rhoc def f(T): tau = Tc/T ideal = self._phi0(tau, delta) fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-Po/rho-u T = fsolve(f, To)[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if T == To or rhov <= rho <= rhol: def f(parr): T, rhol, rhog = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc ideal = self._phi0(tau, deltaL) fiot = ideal["fiot"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG x = (1./rho-1/rhol)/(1/rhog-1/rhol) Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) vu = hoG-Ps/rhog lu = hoL-Ps/rhol return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, lu*(1-x)+vu*x - u) for to in [To, 300, 400, 500, 600]: rhoLo = self._Liquid_Density(to) rhoGo = self._Vapor_Density(to) sol = fsolve(f, [to, rhoLo, rhoGo], full_output=True) T, rhoL, rhoG = sol[0] x = (1./rho-1/rhoL)/(1/rhoG-1/rhoL) if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "hs": def f(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) fir = _phir(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) so = self.R*(tau*(fiot+firt)-fio-fir) return ho-h, so-s rho, T = fsolve(f, [rhoo, To]) rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if rhov <= rho <= rhol: def f(parr): T, rhol, rhog, x = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc idealL = self._phi0(tau, deltaL) fiot = idealL["fiot"] fioL = idealL["fio"] idealG = self._phi0(tau, deltaG) fioG = idealG["fio"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) soL = self.R*(tau*(fiot+firtL)-fioL-firL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) soG = self.R*(tau*(fiot+firtG)-fioG-firG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, hoL*(1-x)+hoG*x - h, soL*(1-x)+soG*x - s) for to in [To, 300, 400, 500, 600]: rLo = self._Liquid_Density(to) rGo = self._Vapor_Density(to) sol = fsolve(f, [to, rLo, rGo, 0.5], full_output=True) T, rhoL, rhoG, x = sol[0] if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "hu": def f(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-Po/rho-u, ho-h sol = fsolve(f, [rhoo, To], full_output=True) rho, T = sol[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if sol[2] != 1 or rhov <= rho <= rhol: def f(parr): T, rhol, rhog, x = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc ideal = self._phi0(tau, deltaL) fiot = ideal["fiot"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) vu = hoG-Ps/rhog lu = hoL-Ps/rhol return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, hoL*(1-x)+hoG*x - h, lu*(1-x)+vu*x - u) for to in [To, 300, 400, 500, 600]: rLo = self._Liquid_Density(to) rGo = self._Vapor_Density(to) sol = fsolve(f, [to, rLo, rGo, 0.5], full_output=True) T, rhoL, rhoG, x = sol[0] if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "su": def f(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) fir = _phir(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) so = self.R*(tau*(fiot+firt)-fio-fir) Po = (1+delta*fird)*self.R*T*rho return ho-Po/rho-u, so-s sol = fsolve(f, [rhoo, To], full_output=True) rho, T = sol[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if sol[2] != 1 or rhov <= rho <= rhol: def f(parr): T, rhol, rhog, x = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc idealL = self._phi0(tau, deltaL) fiot = idealL["fiot"] fioL = idealL["fio"] idealG = self._phi0(tau, deltaG) fioG = idealG["fio"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) soL = self.R*(tau*(fiot+firtL)-fioL-firL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) soG = self.R*(tau*(fiot+firtG)-fioG-firG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) vu = hoG-Ps/rhog lu = hoL-Ps/rhol return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, soL*(1-x)+soG*x - s, lu*(1-x)+vu*x - u) for to in [To, 300, 400, 500, 600]: rLo = self._Liquid_Density(to) rGo = self._Vapor_Density(to) sol = fsolve(f, [to, rLo, rGo, 0.5], full_output=True) T, rhoL, rhoG, x = sol[0] if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "Trho": if T < self.Tc: rhov = self._Vapor_Density(T) rhol = self._Liquid_Density(T) if rhol > rho > rhov: rhol, rhov, Ps = self._saturation(T) if rhol > rho > rhov: vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) x = (1/rho-1/rhol)/(1/rhov-1/rhol) P = Ps/1000 rho = float(rho) T = float(T) propiedades = self._Helmholtz(rho, T) if T > self.Tc: x = 1 elif x is None: x = 0 if not P: P = propiedades["P"]/1000. elif self._mode == "Tx": # Check input T in saturation range if self.Tt > T or self.Tc < T or x > 1 or x < 0: raise NotImplementedError("Incoming out of bound") rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) if x == 0: propiedades = liquido elif x == 1: propiedades = vapor P = Ps/1000. elif self._mode == "Px": # Check input P in saturation range if self.Pc < P or x > 1 or x < 0: raise NotImplementedError("Incoming out of bound") # Iterate over saturation routine to get T def f(T): rhol = self._Liquid_Density(T) rhog = self._Vapor_Density(T) deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc tau = Tc/T firL = _phir(tau, deltaL, self._constants) firG = _phir(tau, deltaG, self._constants) Ps = self.R*T*rhol*rhog/(rhol-rhog)*( firL-firG+log(deltaL/deltaG)) return Ps/1000-P if T0: To = T0 elif self.name == "water": To = _TSat_P(P) else: To = (self.Tc+self.Tt)/2 T = fsolve(f, To)[0] rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) if x == 0: propiedades = liquido elif x == 1: propiedades = vapor self.T = T self.Tr = T/self.Tc self.P = P self.Pr = self.P/self.Pc self.x = x if self._mode in ["Tx", "Px"] or 0 < x < 1: region = 4 else: region = 0 self.phase = getphase(self.Tc, self.Pc, self.T, self.P, self.x, region) self.Liquid = _fase() self.Gas = _fase() if x == 0: # liquid phase self.fill(self.Liquid, propiedades) self.fill(self, propiedades) elif x == 1: # vapor phase self.fill(self.Gas, propiedades) self.fill(self, propiedades) else: self.fill(self.Liquid, liquido) self.fill(self.Gas, vapor) self.v = x*self.Gas.v+(1-x)*self.Liquid.v self.rho = 1./self.v self.h = x*self.Gas.h+(1-x)*self.Liquid.h self.s = x*self.Gas.s+(1-x)*self.Liquid.s self.u = x*self.Gas.u+(1-x)*self.Liquid.u self.a = x*self.Gas.a+(1-x)*self.Liquid.a self.g = x*self.Gas.g+(1-x)*self.Liquid.g self.Z = x*self.Gas.Z+(1-x)*self.Liquid.Z self.f = x*self.Gas.f+(1-x)*self.Liquid.f self.Z_rho = x*self.Gas.Z_rho+(1-x)*self.Liquid.Z_rho self.IntP = x*self.Gas.IntP+(1-x)*self.Liquid.IntP # Calculate special properties useful only for one phase if self._mode in ("Px", "Tx") or (x < 1 and self.Tt <= T <= self.Tc): self.sigma = self._surface(T) else: self.sigma = None vir = self._virial(T) self.virialB = vir["B"]/self.rhoc self.virialC = vir["C"]/self.rhoc**2 if 0 < x < 1: self.Hvap = vapor["h"]-liquido["h"] self.Svap = vapor["s"]-liquido["s"] else: self.Hvap = None self.Svap = None self.invT = -1/self.T # Ideal properties cp0 = self._prop0(self.rho, self.T) self.v0 = self.R*self.T/self.P/1000 self.rho0 = 1./self.v0 self.h0 = cp0.h self.u0 = self.h0-self.P*self.v0 self.s0 = cp0.s self.a0 = self.u0-self.T*self.s0 self.g0 = self.h0-self.T*self.s0 self.cp0 = cp0.cp self.cv0 = cp0.cv self.cp0_cv = self.cp0/self.cv0 cp0.v = self.v0 self.gamma0 = -self.v0/self.P/1000*self.derivative("P", "v", "s", cp0)
python
def calculo(self): """Calculate procedure""" T = self.kwargs["T"] rho = self.kwargs["rho"] P = self.kwargs["P"] s = self.kwargs["s"] h = self.kwargs["h"] u = self.kwargs["u"] x = self.kwargs["x"] # Initial values T0 = self.kwargs["T0"] rho0 = self.kwargs["rho0"] if T0 or rho0: To = T0 rhoo = rho0 elif self.name == "air": To = 300 rhoo = 1e-3 else: try: st0 = IAPWS97(**self.kwargs) except NotImplementedError: To = 300 rhoo = 900 else: if st0.status: To = st0.T rhoo = st0.rho else: To = 300 rhoo = 900 self.R = self._constants["R"]/self._constants.get("M", self.M) rhoc = self._constants.get("rhoref", self.rhoc) Tc = self._constants.get("Tref", self.Tc) propiedades = None if self._mode not in ("Tx", "Px"): # Method with iteration necessary to get x if self._mode == "TP": try: if self.name == "air": raise ValueError st0 = IAPWS97(**self.kwargs) rhoo = st0.rho except NotImplementedError: if rho0: rhoo = rho0 elif T < self.Tc and P < self.Pc and \ self._Vapor_Pressure(T) < P: rhoo = self._Liquid_Density(T) elif T < self.Tc and P < self.Pc: rhoo = self._Vapor_Density(T) else: rhoo = self.rhoc*3 except ValueError: rhoo = 1e-3 def f(rho): delta = rho/rhoc tau = Tc/T fird = _phird(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho return Po-P*1000 rho = fsolve(f, rhoo)[0] # Calculate quality if T > self.Tc: x = 1 else: Ps = self._Vapor_Pressure(T) if Ps*0.95 < P < Ps*1.05: rhol, rhov, Ps = self._saturation(T) Ps *= 1e-3 if Ps > P: x = 1 else: x = 0 elif self._mode == "Th": tau = Tc/T ideal = self._phi0(tau, 1) fiot = ideal["fiot"] def f(rho): delta = rho/rhoc fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-h if T >= self.Tc: rhoo = self.rhoc rho = fsolve(f, rhoo)[0] else: x0 = self.kwargs["x0"] rhov = self._Vapor_Density(T) rhol = self._Liquid_Density(T) deltaL = rhol/rhoc deltaG = rhov/rhoc firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hl = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) hv = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) if x0 not in (0, 1) and hl <= h <= hv: rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) hv = vapor["h"] hl = liquido["h"] x = (h-hl)/(hv-hl) rho = 1/(x/rhov+(1-x)/rhol) P = Ps/1000 else: if h > hv: rhoo = rhov else: rhoo = rhol rho = fsolve(f, rhoo)[0] elif self._mode == "Ts": tau = Tc/T def f(rho): if rho < 0: rho = 1e-20 delta = rho/rhoc ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fir = _phir(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) so = self.R*(tau*(fiot+firt)-fio-fir) return so-s if T >= self.Tc: rhoo = self.rhoc rho = fsolve(f, rhoo)[0] else: rhov = self._Vapor_Density(T) rhol = self._Liquid_Density(T) deltaL = rhol/rhoc deltaG = rhov/rhoc idealL = self._phi0(tau, deltaL) idealG = self._phi0(tau, deltaG) fioL = idealL["fio"] fioG = idealG["fio"] fiot = idealL["fiot"] firL = _phir(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) sl = self.R*(tau*(fiot+firtL)-fioL-firL) firG = _phir(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) sv = self.R*(tau*(fiot+firtG)-fioG-firG) if sl <= s <= sv: rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) sv = vapor["s"] sl = liquido["s"] x = (s-sl)/(sv-sl) rho = 1/(x/rhov+(1-x)/rhol) P = Ps/1000 else: if s > sv: rhoo = rhov else: rhoo = rhol rho = fsolve(f, rhoo)[0] elif self._mode == "Tu": tau = Tc/T ideal = self._phi0(tau, 1) fiot = ideal["fiot"] def f(rho): delta = rho/rhoc fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-Po/rho-u if T >= self.Tc: rhoo = self.rhoc rho = fsolve(f, rhoo)[0] else: rhov = self._Vapor_Density(T) rhol = self._Liquid_Density(T) deltaL = rhol/rhoc deltaG = rhov/rhoc firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) PoL = (1+deltaL*firdL)*self.R*T*rhol PoG = (1+deltaG*firdG)*self.R*T*rhov hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) uv = hoG-PoG/rhov ul = hoL-PoL/rhol if ul <= u <= uv: rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) uv = vapor["h"]-vapor["P"]/rhov ul = liquido["h"]-liquido["P"]/rhol x = (u-ul)/(uv-ul) rho = 1/(x/rhov-(1-x)/rhol) P = Ps/1000 else: if u > uv: rhoo = rhov else: rhoo = rhol rho = fsolve(f, rhoo)[0] elif self._mode == "Prho": delta = rho/rhoc def f(T): tau = Tc/T fird = _phird(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho return Po-P*1000 T = fsolve(f, To)[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if T == To or rhov <= rho <= rhol: def f(parr): T, rhol, rhog = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, Ps - P*1000) for to in [To, 300, 400, 500, 600]: rhoLo = self._Liquid_Density(to) rhoGo = self._Vapor_Density(to) sol = fsolve(f, [to, rhoLo, rhoGo], full_output=True) T, rhoL, rhoG = sol[0] x = (1./rho-1/rhoL)/(1/rhoG-1/rhoL) if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "Ph": def funcion(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return Po-P*1000, ho-h rho, T = fsolve(funcion, [rhoo, To]) rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if rho == rhoo or rhov <= rho <= rhol: def f(parr): T, rhol, rhog, x = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc ideal = self._phi0(tau, deltaL) fiot = ideal["fiot"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, hoL*(1-x)+hoG*x - h, Ps - P*1000) for to in [To, 300, 400, 500, 600]: rLo = self._Liquid_Density(to) rGo = self._Vapor_Density(to) sol = fsolve(f, [to, rLo, rGo, 0.5], full_output=True) T, rhoL, rhoG, x = sol[0] if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "Ps": try: x0 = st0.x except NameError: x0 = None if x0 is None or x0 == 0 or x0 == 1: def f(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) fir = _phir(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho so = self.R*(tau*(fiot+firt)-fio-fir) return Po-P*1000, so-s rho, T = fsolve(f, [rhoo, To]) else: def funcion(parr): rho, T = parr rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) x = (1./rho-1/rhol)/(1/rhov-1/rhol) return Ps-P*1000, vapor["s"]*x+liquido["s"]*(1-x)-s rho, T = fsolve(funcion, [2., 500.]) rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) sv = vapor["s"] sl = liquido["s"] x = (s-sl)/(sv-sl) elif self._mode == "Pu": def f(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-Po/rho-u, Po-P*1000 sol = fsolve(f, [rhoo, To], full_output=True) rho, T = sol[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if rho == rhoo or sol[2] != 1: def f(parr): T, rhol, rhog, x = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc ideal = self._phi0(tau, deltaL) fiot = ideal["fiot"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) vu = hoG-Ps/rhog lu = hoL-Ps/rhol return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, lu*(1-x)+vu*x - u, Ps - P*1000) for to in [To, 300, 400, 500, 600]: rLo = self._Liquid_Density(to) rGo = self._Vapor_Density(to) sol = fsolve(f, [to, rLo, rGo, 0.5], full_output=True) T, rhoL, rhoG, x = sol[0] if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "rhoh": delta = rho/rhoc def f(T): tau = Tc/T ideal = self._phi0(tau, delta) fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-h T = fsolve(f, To)[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if T == To or rhov <= rho <= rhol: def f(parr): T, rhol, rhog = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc ideal = self._phi0(tau, deltaL) fiot = ideal["fiot"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG x = (1./rho-1/rhol)/(1/rhog-1/rhol) return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, hoL*(1-x)+hoG*x - h) for to in [To, 300, 400, 500, 600]: rhoLo = self._Liquid_Density(to) rhoGo = self._Vapor_Density(to) sol = fsolve(f, [to, rhoLo, rhoGo], full_output=True) T, rhoL, rhoG = sol[0] x = (1./rho-1/rhoL)/(1/rhoG-1/rhoL) if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "rhos": delta = rho/rhoc def f(T): tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fir = _phir(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) so = self.R*(tau*(fiot+firt)-fio-fir) return so-s T = fsolve(f, To)[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if T == To or rhov <= rho <= rhol: def f(parr): T, rhol, rhog = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc idealL = self._phi0(tau, deltaL) fioL = idealL["fio"] fiot = idealL["fiot"] idealG = self._phi0(tau, deltaG) fioG = idealG["fio"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) soL = self.R*(tau*(fiot+firtL)-fioL-firL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) soG = self.R*(tau*(fiot+firtG)-fioG-firG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG x = (1./rho-1/rhol)/(1/rhog-1/rhol) return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, soL*(1-x)+soG*x - s) for to in [To, 300, 400, 500, 600]: rhoLo = self._Liquid_Density(to) rhoGo = self._Vapor_Density(to) sol = fsolve(f, [to, rhoLo, rhoGo], full_output=True) T, rhoL, rhoG = sol[0] x = (1./rho-1/rhoL)/(1/rhoG-1/rhoL) if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "rhou": delta = rho/rhoc def f(T): tau = Tc/T ideal = self._phi0(tau, delta) fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-Po/rho-u T = fsolve(f, To)[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if T == To or rhov <= rho <= rhol: def f(parr): T, rhol, rhog = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc ideal = self._phi0(tau, deltaL) fiot = ideal["fiot"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG x = (1./rho-1/rhol)/(1/rhog-1/rhol) Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) vu = hoG-Ps/rhog lu = hoL-Ps/rhol return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, lu*(1-x)+vu*x - u) for to in [To, 300, 400, 500, 600]: rhoLo = self._Liquid_Density(to) rhoGo = self._Vapor_Density(to) sol = fsolve(f, [to, rhoLo, rhoGo], full_output=True) T, rhoL, rhoG = sol[0] x = (1./rho-1/rhoL)/(1/rhoG-1/rhoL) if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "hs": def f(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) fir = _phir(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) so = self.R*(tau*(fiot+firt)-fio-fir) return ho-h, so-s rho, T = fsolve(f, [rhoo, To]) rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if rhov <= rho <= rhol: def f(parr): T, rhol, rhog, x = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc idealL = self._phi0(tau, deltaL) fiot = idealL["fiot"] fioL = idealL["fio"] idealG = self._phi0(tau, deltaG) fioG = idealG["fio"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) soL = self.R*(tau*(fiot+firtL)-fioL-firL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) soG = self.R*(tau*(fiot+firtG)-fioG-firG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, hoL*(1-x)+hoG*x - h, soL*(1-x)+soG*x - s) for to in [To, 300, 400, 500, 600]: rLo = self._Liquid_Density(to) rGo = self._Vapor_Density(to) sol = fsolve(f, [to, rLo, rGo, 0.5], full_output=True) T, rhoL, rhoG, x = sol[0] if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "hu": def f(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) Po = (1+delta*fird)*self.R*T*rho ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) return ho-Po/rho-u, ho-h sol = fsolve(f, [rhoo, To], full_output=True) rho, T = sol[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if sol[2] != 1 or rhov <= rho <= rhol: def f(parr): T, rhol, rhog, x = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc ideal = self._phi0(tau, deltaL) fiot = ideal["fiot"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) vu = hoG-Ps/rhog lu = hoL-Ps/rhol return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, hoL*(1-x)+hoG*x - h, lu*(1-x)+vu*x - u) for to in [To, 300, 400, 500, 600]: rLo = self._Liquid_Density(to) rGo = self._Vapor_Density(to) sol = fsolve(f, [to, rLo, rGo, 0.5], full_output=True) T, rhoL, rhoG, x = sol[0] if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "su": def f(parr): rho, T = parr delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fird = _phird(tau, delta, self._constants) fir = _phir(tau, delta, self._constants) firt = _phirt(tau, delta, self._constants) ho = self.R*T*(1+tau*(fiot+firt)+delta*fird) so = self.R*(tau*(fiot+firt)-fio-fir) Po = (1+delta*fird)*self.R*T*rho return ho-Po/rho-u, so-s sol = fsolve(f, [rhoo, To], full_output=True) rho, T = sol[0] rhol = self._Liquid_Density(T) rhov = self._Vapor_Density(T) if sol[2] != 1 or rhov <= rho <= rhol: def f(parr): T, rhol, rhog, x = parr tau = Tc/T deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc idealL = self._phi0(tau, deltaL) fiot = idealL["fiot"] fioL = idealL["fio"] idealG = self._phi0(tau, deltaG) fioG = idealG["fio"] firL = _phir(tau, deltaL, self._constants) firdL = _phird(tau, deltaL, self._constants) firtL = _phirt(tau, deltaL, self._constants) hoL = self.R*T*(1+tau*(fiot+firtL)+deltaL*firdL) soL = self.R*(tau*(fiot+firtL)-fioL-firL) firG = _phir(tau, deltaG, self._constants) firdG = _phird(tau, deltaG, self._constants) firtG = _phirt(tau, deltaG, self._constants) hoG = self.R*T*(1+tau*(fiot+firtG)+deltaG*firdG) soG = self.R*(tau*(fiot+firtG)-fioG-firG) Jl = rhol*(1+deltaL*firdL) Jv = rhog*(1+deltaG*firdG) K = firL-firG Ps = self.R*T*rhol*rhog/(rhol-rhog)*(K+log(rhol/rhog)) vu = hoG-Ps/rhog lu = hoL-Ps/rhol return (Jl-Jv, Jl*(1/rhog-1/rhol)-log(rhol/rhog)-K, soL*(1-x)+soG*x - s, lu*(1-x)+vu*x - u) for to in [To, 300, 400, 500, 600]: rLo = self._Liquid_Density(to) rGo = self._Vapor_Density(to) sol = fsolve(f, [to, rLo, rGo, 0.5], full_output=True) T, rhoL, rhoG, x = sol[0] if sol[2] == 1 and 0 <= x <= 1 and \ sum(abs(sol[1]["fvec"])) < 1e-5: break if sum(abs(sol[1]["fvec"])) > 1e-5: raise(RuntimeError(sol[3])) liquido = self._Helmholtz(rhoL, T) vapor = self._Helmholtz(rhoG, T) P = self.R*T*rhoL*rhoG/(rhoL-rhoG)*( liquido["fir"]-vapor["fir"]+log(rhoL/rhoG))/1000 elif self._mode == "Trho": if T < self.Tc: rhov = self._Vapor_Density(T) rhol = self._Liquid_Density(T) if rhol > rho > rhov: rhol, rhov, Ps = self._saturation(T) if rhol > rho > rhov: vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) x = (1/rho-1/rhol)/(1/rhov-1/rhol) P = Ps/1000 rho = float(rho) T = float(T) propiedades = self._Helmholtz(rho, T) if T > self.Tc: x = 1 elif x is None: x = 0 if not P: P = propiedades["P"]/1000. elif self._mode == "Tx": # Check input T in saturation range if self.Tt > T or self.Tc < T or x > 1 or x < 0: raise NotImplementedError("Incoming out of bound") rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) if x == 0: propiedades = liquido elif x == 1: propiedades = vapor P = Ps/1000. elif self._mode == "Px": # Check input P in saturation range if self.Pc < P or x > 1 or x < 0: raise NotImplementedError("Incoming out of bound") # Iterate over saturation routine to get T def f(T): rhol = self._Liquid_Density(T) rhog = self._Vapor_Density(T) deltaL = rhol/self.rhoc deltaG = rhog/self.rhoc tau = Tc/T firL = _phir(tau, deltaL, self._constants) firG = _phir(tau, deltaG, self._constants) Ps = self.R*T*rhol*rhog/(rhol-rhog)*( firL-firG+log(deltaL/deltaG)) return Ps/1000-P if T0: To = T0 elif self.name == "water": To = _TSat_P(P) else: To = (self.Tc+self.Tt)/2 T = fsolve(f, To)[0] rhol, rhov, Ps = self._saturation(T) vapor = self._Helmholtz(rhov, T) liquido = self._Helmholtz(rhol, T) if x == 0: propiedades = liquido elif x == 1: propiedades = vapor self.T = T self.Tr = T/self.Tc self.P = P self.Pr = self.P/self.Pc self.x = x if self._mode in ["Tx", "Px"] or 0 < x < 1: region = 4 else: region = 0 self.phase = getphase(self.Tc, self.Pc, self.T, self.P, self.x, region) self.Liquid = _fase() self.Gas = _fase() if x == 0: # liquid phase self.fill(self.Liquid, propiedades) self.fill(self, propiedades) elif x == 1: # vapor phase self.fill(self.Gas, propiedades) self.fill(self, propiedades) else: self.fill(self.Liquid, liquido) self.fill(self.Gas, vapor) self.v = x*self.Gas.v+(1-x)*self.Liquid.v self.rho = 1./self.v self.h = x*self.Gas.h+(1-x)*self.Liquid.h self.s = x*self.Gas.s+(1-x)*self.Liquid.s self.u = x*self.Gas.u+(1-x)*self.Liquid.u self.a = x*self.Gas.a+(1-x)*self.Liquid.a self.g = x*self.Gas.g+(1-x)*self.Liquid.g self.Z = x*self.Gas.Z+(1-x)*self.Liquid.Z self.f = x*self.Gas.f+(1-x)*self.Liquid.f self.Z_rho = x*self.Gas.Z_rho+(1-x)*self.Liquid.Z_rho self.IntP = x*self.Gas.IntP+(1-x)*self.Liquid.IntP # Calculate special properties useful only for one phase if self._mode in ("Px", "Tx") or (x < 1 and self.Tt <= T <= self.Tc): self.sigma = self._surface(T) else: self.sigma = None vir = self._virial(T) self.virialB = vir["B"]/self.rhoc self.virialC = vir["C"]/self.rhoc**2 if 0 < x < 1: self.Hvap = vapor["h"]-liquido["h"] self.Svap = vapor["s"]-liquido["s"] else: self.Hvap = None self.Svap = None self.invT = -1/self.T # Ideal properties cp0 = self._prop0(self.rho, self.T) self.v0 = self.R*self.T/self.P/1000 self.rho0 = 1./self.v0 self.h0 = cp0.h self.u0 = self.h0-self.P*self.v0 self.s0 = cp0.s self.a0 = self.u0-self.T*self.s0 self.g0 = self.h0-self.T*self.s0 self.cp0 = cp0.cp self.cv0 = cp0.cv self.cp0_cv = self.cp0/self.cv0 cp0.v = self.v0 self.gamma0 = -self.v0/self.P/1000*self.derivative("P", "v", "s", cp0)
Calculate procedure
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L473-L1477
jjgomera/iapws
iapws/iapws95.py
MEoS.fill
def fill(self, fase, estado): """Fill phase properties""" fase.rho = estado["rho"] fase.v = 1/fase.rho fase.h = estado["h"] fase.s = estado["s"] fase.u = fase.h-self.P*1000*fase.v fase.a = fase.u-self.T*fase.s fase.g = fase.h-self.T*fase.s fase.Z = self.P*fase.v/self.T/self.R*1e3 fase.fi = exp(estado["fir"]+estado["delta"]*estado["fird"] - log(1+estado["delta"]*estado["fird"])) fase.f = fase.fi*self.P fase.cv = estado["cv"] fase.rhoM = fase.rho/self.M fase.hM = fase.h*self.M fase.sM = fase.s*self.M fase.uM = fase.u*self.M fase.aM = fase.a*self.M fase.gM = fase.g*self.M fase.alfap = estado["alfap"] fase.betap = estado["betap"] fase.cp = self.derivative("h", "T", "P", fase) fase.cp_cv = fase.cp/fase.cv fase.w = (self.derivative("P", "rho", "s", fase)*1000)**0.5 fase.cvM = fase.cv*self.M fase.cpM = fase.cp*self.M fase.joule = self.derivative("T", "P", "h", fase)*1e3 fase.Gruneisen = fase.v/fase.cv*self.derivative("P", "T", "v", fase) fase.alfav = self.derivative("v", "T", "P", fase)/fase.v fase.kappa = -self.derivative("v", "P", "T", fase)/fase.v*1e3 fase.betas = self.derivative("T", "P", "s", fase) fase.gamma = -fase.v/self.P*self.derivative("P", "v", "s", fase)*1e-3 fase.kt = -fase.v/self.P*self.derivative("P", "v", "T", fase)*1e-3 fase.ks = -self.derivative("v", "P", "s", fase)/fase.v*1e3 fase.Kt = -fase.v*self.derivative("P", "v", "s", fase)*1e-3 fase.Ks = -fase.v*self.derivative("P", "v", "T", fase)*1e-3 fase.dhdT_rho = self.derivative("h", "T", "rho", fase) fase.dhdT_P = self.derivative("h", "T", "P", fase) fase.dhdP_T = self.derivative("h", "P", "T", fase)*1e3 fase.dhdP_rho = self.derivative("h", "P", "rho", fase)*1e3 fase.dhdrho_T = self.derivative("h", "rho", "T", fase) fase.dhdrho_P = self.derivative("h", "rho", "P", fase) fase.dpdT_rho = self.derivative("P", "T", "rho", fase)*1e-3 fase.dpdrho_T = self.derivative("P", "rho", "T", fase)*1e-3 fase.drhodP_T = self.derivative("rho", "P", "T", fase)*1e3 fase.drhodT_P = self.derivative("rho", "T", "P", fase) fase.Z_rho = (fase.Z-1)/fase.rho fase.IntP = self.T*self.derivative("P", "T", "rho", fase)*1e-3-self.P fase.hInput = fase.v*self.derivative("h", "v", "P", fase) fase.mu = self._visco(fase.rho, self.T, fase) fase.k = self._thermo(fase.rho, self.T, fase) fase.nu = fase.mu/fase.rho fase.alfa = fase.k/1000/fase.rho/fase.cp fase.Prandt = fase.mu*fase.cp*1000/fase.k if self.name == "water": try: fase.epsilon = _Dielectric(fase.rho, self.T) except NotImplementedError: fase.epsilon = None try: fase.n = _Refractive(fase.rho, self.T, self.kwargs["l"]) except NotImplementedError: fase.n = None else: fase.epsilon = None fase.n = None
python
def fill(self, fase, estado): """Fill phase properties""" fase.rho = estado["rho"] fase.v = 1/fase.rho fase.h = estado["h"] fase.s = estado["s"] fase.u = fase.h-self.P*1000*fase.v fase.a = fase.u-self.T*fase.s fase.g = fase.h-self.T*fase.s fase.Z = self.P*fase.v/self.T/self.R*1e3 fase.fi = exp(estado["fir"]+estado["delta"]*estado["fird"] - log(1+estado["delta"]*estado["fird"])) fase.f = fase.fi*self.P fase.cv = estado["cv"] fase.rhoM = fase.rho/self.M fase.hM = fase.h*self.M fase.sM = fase.s*self.M fase.uM = fase.u*self.M fase.aM = fase.a*self.M fase.gM = fase.g*self.M fase.alfap = estado["alfap"] fase.betap = estado["betap"] fase.cp = self.derivative("h", "T", "P", fase) fase.cp_cv = fase.cp/fase.cv fase.w = (self.derivative("P", "rho", "s", fase)*1000)**0.5 fase.cvM = fase.cv*self.M fase.cpM = fase.cp*self.M fase.joule = self.derivative("T", "P", "h", fase)*1e3 fase.Gruneisen = fase.v/fase.cv*self.derivative("P", "T", "v", fase) fase.alfav = self.derivative("v", "T", "P", fase)/fase.v fase.kappa = -self.derivative("v", "P", "T", fase)/fase.v*1e3 fase.betas = self.derivative("T", "P", "s", fase) fase.gamma = -fase.v/self.P*self.derivative("P", "v", "s", fase)*1e-3 fase.kt = -fase.v/self.P*self.derivative("P", "v", "T", fase)*1e-3 fase.ks = -self.derivative("v", "P", "s", fase)/fase.v*1e3 fase.Kt = -fase.v*self.derivative("P", "v", "s", fase)*1e-3 fase.Ks = -fase.v*self.derivative("P", "v", "T", fase)*1e-3 fase.dhdT_rho = self.derivative("h", "T", "rho", fase) fase.dhdT_P = self.derivative("h", "T", "P", fase) fase.dhdP_T = self.derivative("h", "P", "T", fase)*1e3 fase.dhdP_rho = self.derivative("h", "P", "rho", fase)*1e3 fase.dhdrho_T = self.derivative("h", "rho", "T", fase) fase.dhdrho_P = self.derivative("h", "rho", "P", fase) fase.dpdT_rho = self.derivative("P", "T", "rho", fase)*1e-3 fase.dpdrho_T = self.derivative("P", "rho", "T", fase)*1e-3 fase.drhodP_T = self.derivative("rho", "P", "T", fase)*1e3 fase.drhodT_P = self.derivative("rho", "T", "P", fase) fase.Z_rho = (fase.Z-1)/fase.rho fase.IntP = self.T*self.derivative("P", "T", "rho", fase)*1e-3-self.P fase.hInput = fase.v*self.derivative("h", "v", "P", fase) fase.mu = self._visco(fase.rho, self.T, fase) fase.k = self._thermo(fase.rho, self.T, fase) fase.nu = fase.mu/fase.rho fase.alfa = fase.k/1000/fase.rho/fase.cp fase.Prandt = fase.mu*fase.cp*1000/fase.k if self.name == "water": try: fase.epsilon = _Dielectric(fase.rho, self.T) except NotImplementedError: fase.epsilon = None try: fase.n = _Refractive(fase.rho, self.T, self.kwargs["l"]) except NotImplementedError: fase.n = None else: fase.epsilon = None fase.n = None
Fill phase properties
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L1479-L1555
jjgomera/iapws
iapws/iapws95.py
MEoS.derivative
def derivative(self, z, x, y, fase): """Wrapper derivative for custom derived properties where x, y, z can be: P, T, v, rho, u, h, s, g, a""" return deriv_H(self, z, x, y, fase)
python
def derivative(self, z, x, y, fase): """Wrapper derivative for custom derived properties where x, y, z can be: P, T, v, rho, u, h, s, g, a""" return deriv_H(self, z, x, y, fase)
Wrapper derivative for custom derived properties where x, y, z can be: P, T, v, rho, u, h, s, g, a
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L1557-L1560
jjgomera/iapws
iapws/iapws95.py
MEoS._saturation
def _saturation(self, T): """Saturation calculation for two phase search""" rhoc = self._constants.get("rhoref", self.rhoc) Tc = self._constants.get("Tref", self.Tc) if T > Tc: T = Tc tau = Tc/T rhoLo = self._Liquid_Density(T) rhoGo = self._Vapor_Density(T) def f(parr): rhol, rhog = parr deltaL = rhol/rhoc deltaG = rhog/rhoc phirL = _phir(tau, deltaL, self._constants) phirG = _phir(tau, deltaG, self._constants) phirdL = _phird(tau, deltaL, self._constants) phirdG = _phird(tau, deltaG, self._constants) Jl = deltaL*(1+deltaL*phirdL) Jv = deltaG*(1+deltaG*phirdG) Kl = deltaL*phirdL+phirL+log(deltaL) Kv = deltaG*phirdG+phirG+log(deltaG) return Kv-Kl, Jv-Jl rhoL, rhoG = fsolve(f, [rhoLo, rhoGo]) if rhoL == rhoG: Ps = self.Pc else: deltaL = rhoL/self.rhoc deltaG = rhoG/self.rhoc firL = _phir(tau, deltaL, self._constants) firG = _phir(tau, deltaG, self._constants) Ps = self.R*T*rhoL*rhoG/(rhoL-rhoG)*(firL-firG+log(deltaL/deltaG)) return rhoL, rhoG, Ps
python
def _saturation(self, T): """Saturation calculation for two phase search""" rhoc = self._constants.get("rhoref", self.rhoc) Tc = self._constants.get("Tref", self.Tc) if T > Tc: T = Tc tau = Tc/T rhoLo = self._Liquid_Density(T) rhoGo = self._Vapor_Density(T) def f(parr): rhol, rhog = parr deltaL = rhol/rhoc deltaG = rhog/rhoc phirL = _phir(tau, deltaL, self._constants) phirG = _phir(tau, deltaG, self._constants) phirdL = _phird(tau, deltaL, self._constants) phirdG = _phird(tau, deltaG, self._constants) Jl = deltaL*(1+deltaL*phirdL) Jv = deltaG*(1+deltaG*phirdG) Kl = deltaL*phirdL+phirL+log(deltaL) Kv = deltaG*phirdG+phirG+log(deltaG) return Kv-Kl, Jv-Jl rhoL, rhoG = fsolve(f, [rhoLo, rhoGo]) if rhoL == rhoG: Ps = self.Pc else: deltaL = rhoL/self.rhoc deltaG = rhoG/self.rhoc firL = _phir(tau, deltaL, self._constants) firG = _phir(tau, deltaG, self._constants) Ps = self.R*T*rhoL*rhoG/(rhoL-rhoG)*(firL-firG+log(deltaL/deltaG)) return rhoL, rhoG, Ps
Saturation calculation for two phase search
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L1562-L1598
jjgomera/iapws
iapws/iapws95.py
MEoS._Helmholtz
def _Helmholtz(self, rho, T): """Calculated properties from helmholtz free energy and derivatives Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- prop : dict Dictionary with calculated properties: * fir: [-] * fird: ∂fir/∂δ|τ * firdd: ∂²fir/∂δ²|τ * delta: Reducen density rho/rhoc, [-] * P: Pressure, [kPa] * h: Enthalpy, [kJ/kg] * s: Entropy, [kJ/kgK] * cv: Isochoric specific heat, [kJ/kgK] * alfav: Thermal expansion coefficient, [1/K] * betap: Isothermal compressibility, [1/kPa] References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 3 http://www.iapws.org/relguide/IAPWS-95.html """ if isinstance(rho, ndarray): rho = rho[0] if isinstance(T, ndarray): T = T[0] if rho < 0: rho = 1e-20 if T < 50: T = 50 rhoc = self._constants.get("rhoref", self.rhoc) Tc = self._constants.get("Tref", self.Tc) delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fiott = ideal["fiott"] res = self._phir(tau, delta) fir = res["fir"] firt = res["firt"] firtt = res["firtt"] fird = res["fird"] firdd = res["firdd"] firdt = res["firdt"] propiedades = {} propiedades["fir"] = fir propiedades["fird"] = fird propiedades["firdd"] = firdd propiedades["delta"] = delta propiedades["rho"] = rho propiedades["P"] = (1+delta*fird)*self.R*T*rho propiedades["h"] = self.R*T*(1+tau*(fiot+firt)+delta*fird) propiedades["s"] = self.R*(tau*(fiot+firt)-fio-fir) propiedades["cv"] = -self.R*tau**2*(fiott+firtt) propiedades["alfap"] = (1-delta*tau*firdt/(1+delta*fird))/T propiedades["betap"] = rho*( 1+(delta*fird+delta**2*firdd)/(1+delta*fird)) return propiedades
python
def _Helmholtz(self, rho, T): """Calculated properties from helmholtz free energy and derivatives Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- prop : dict Dictionary with calculated properties: * fir: [-] * fird: ∂fir/∂δ|τ * firdd: ∂²fir/∂δ²|τ * delta: Reducen density rho/rhoc, [-] * P: Pressure, [kPa] * h: Enthalpy, [kJ/kg] * s: Entropy, [kJ/kgK] * cv: Isochoric specific heat, [kJ/kgK] * alfav: Thermal expansion coefficient, [1/K] * betap: Isothermal compressibility, [1/kPa] References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 3 http://www.iapws.org/relguide/IAPWS-95.html """ if isinstance(rho, ndarray): rho = rho[0] if isinstance(T, ndarray): T = T[0] if rho < 0: rho = 1e-20 if T < 50: T = 50 rhoc = self._constants.get("rhoref", self.rhoc) Tc = self._constants.get("Tref", self.Tc) delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fiott = ideal["fiott"] res = self._phir(tau, delta) fir = res["fir"] firt = res["firt"] firtt = res["firtt"] fird = res["fird"] firdd = res["firdd"] firdt = res["firdt"] propiedades = {} propiedades["fir"] = fir propiedades["fird"] = fird propiedades["firdd"] = firdd propiedades["delta"] = delta propiedades["rho"] = rho propiedades["P"] = (1+delta*fird)*self.R*T*rho propiedades["h"] = self.R*T*(1+tau*(fiot+firt)+delta*fird) propiedades["s"] = self.R*(tau*(fiot+firt)-fio-fir) propiedades["cv"] = -self.R*tau**2*(fiott+firtt) propiedades["alfap"] = (1-delta*tau*firdt/(1+delta*fird))/T propiedades["betap"] = rho*( 1+(delta*fird+delta**2*firdd)/(1+delta*fird)) return propiedades
Calculated properties from helmholtz free energy and derivatives Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- prop : dict Dictionary with calculated properties: * fir: [-] * fird: ∂fir/∂δ|τ * firdd: ∂²fir/∂δ²|τ * delta: Reducen density rho/rhoc, [-] * P: Pressure, [kPa] * h: Enthalpy, [kJ/kg] * s: Entropy, [kJ/kgK] * cv: Isochoric specific heat, [kJ/kgK] * alfav: Thermal expansion coefficient, [1/K] * betap: Isothermal compressibility, [1/kPa] References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 3 http://www.iapws.org/relguide/IAPWS-95.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L1600-L1671
jjgomera/iapws
iapws/iapws95.py
MEoS._prop0
def _prop0(self, rho, T): """Ideal gas properties""" rhoc = self._constants.get("rhoref", self.rhoc) Tc = self._constants.get("Tref", self.Tc) delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fiott = ideal["fiott"] propiedades = _fase() propiedades.h = self.R*T*(1+tau*fiot) propiedades.s = self.R*(tau*fiot-fio) propiedades.cv = -self.R*tau**2*fiott propiedades.cp = self.R*(-tau**2*fiott+1) propiedades.alfap = 1/T propiedades.betap = rho return propiedades
python
def _prop0(self, rho, T): """Ideal gas properties""" rhoc = self._constants.get("rhoref", self.rhoc) Tc = self._constants.get("Tref", self.Tc) delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fiott = ideal["fiott"] propiedades = _fase() propiedades.h = self.R*T*(1+tau*fiot) propiedades.s = self.R*(tau*fiot-fio) propiedades.cv = -self.R*tau**2*fiott propiedades.cp = self.R*(-tau**2*fiott+1) propiedades.alfap = 1/T propiedades.betap = rho return propiedades
Ideal gas properties
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L1673-L1691
jjgomera/iapws
iapws/iapws95.py
MEoS._phi0
def _phi0(self, tau, delta): """Ideal gas Helmholtz free energy and derivatives Parameters ---------- tau : float Inverse reduced temperature Tc/T, [-] delta : float Reduced density rho/rhoc, [-] Returns ------- prop : dictionary with ideal adimensional helmholtz energy and deriv fio, [-] fiot: ∂fio/∂τ|δ fiod: ∂fio/∂δ|τ fiott: ∂²fio/∂τ²|δ fiodt: ∂²fio/∂τ∂δ fiodd: ∂²fio/∂δ²|τ References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 4 http://www.iapws.org/relguide/IAPWS-95.html """ Fi0 = self.Fi0 fio = Fi0["ao_log"][0]*log(delta)+Fi0["ao_log"][1]*log(tau) fiot = +Fi0["ao_log"][1]/tau fiott = -Fi0["ao_log"][1]/tau**2 fiod = 1/delta fiodd = -1/delta**2 fiodt = 0 for n, t in zip(Fi0["ao_pow"], Fi0["pow"]): fio += n*tau**t if t != 0: fiot += t*n*tau**(t-1) if t not in [0, 1]: fiott += n*t*(t-1)*tau**(t-2) for n, t in zip(Fi0["ao_exp"], Fi0["titao"]): fio += n*log(1-exp(-tau*t)) fiot += n*t*((1-exp(-t*tau))**-1-1) fiott -= n*t**2*exp(-t*tau)*(1-exp(-t*tau))**-2 # Extension to especial terms of air if "ao_exp2" in Fi0: for n, g, C in zip(Fi0["ao_exp2"], Fi0["titao2"], Fi0["sum2"]): fio += n*log(C+exp(g*tau)) fiot += n*g/(C*exp(-g*tau)+1) fiott += C*n*g**2*exp(-g*tau)/(C*exp(-g*tau)+1)**2 prop = {} prop["fio"] = fio prop["fiot"] = fiot prop["fiott"] = fiott prop["fiod"] = fiod prop["fiodd"] = fiodd prop["fiodt"] = fiodt return prop
python
def _phi0(self, tau, delta): """Ideal gas Helmholtz free energy and derivatives Parameters ---------- tau : float Inverse reduced temperature Tc/T, [-] delta : float Reduced density rho/rhoc, [-] Returns ------- prop : dictionary with ideal adimensional helmholtz energy and deriv fio, [-] fiot: ∂fio/∂τ|δ fiod: ∂fio/∂δ|τ fiott: ∂²fio/∂τ²|δ fiodt: ∂²fio/∂τ∂δ fiodd: ∂²fio/∂δ²|τ References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 4 http://www.iapws.org/relguide/IAPWS-95.html """ Fi0 = self.Fi0 fio = Fi0["ao_log"][0]*log(delta)+Fi0["ao_log"][1]*log(tau) fiot = +Fi0["ao_log"][1]/tau fiott = -Fi0["ao_log"][1]/tau**2 fiod = 1/delta fiodd = -1/delta**2 fiodt = 0 for n, t in zip(Fi0["ao_pow"], Fi0["pow"]): fio += n*tau**t if t != 0: fiot += t*n*tau**(t-1) if t not in [0, 1]: fiott += n*t*(t-1)*tau**(t-2) for n, t in zip(Fi0["ao_exp"], Fi0["titao"]): fio += n*log(1-exp(-tau*t)) fiot += n*t*((1-exp(-t*tau))**-1-1) fiott -= n*t**2*exp(-t*tau)*(1-exp(-t*tau))**-2 # Extension to especial terms of air if "ao_exp2" in Fi0: for n, g, C in zip(Fi0["ao_exp2"], Fi0["titao2"], Fi0["sum2"]): fio += n*log(C+exp(g*tau)) fiot += n*g/(C*exp(-g*tau)+1) fiott += C*n*g**2*exp(-g*tau)/(C*exp(-g*tau)+1)**2 prop = {} prop["fio"] = fio prop["fiot"] = fiot prop["fiott"] = fiott prop["fiod"] = fiod prop["fiodd"] = fiodd prop["fiodt"] = fiodt return prop
Ideal gas Helmholtz free energy and derivatives Parameters ---------- tau : float Inverse reduced temperature Tc/T, [-] delta : float Reduced density rho/rhoc, [-] Returns ------- prop : dictionary with ideal adimensional helmholtz energy and deriv fio, [-] fiot: ∂fio/∂τ|δ fiod: ∂fio/∂δ|τ fiott: ∂²fio/∂τ²|δ fiodt: ∂²fio/∂τ∂δ fiodd: ∂²fio/∂δ²|τ References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 4 http://www.iapws.org/relguide/IAPWS-95.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L1693-L1756
jjgomera/iapws
iapws/iapws95.py
MEoS._phir
def _phir(self, tau, delta): """Residual contribution to the free Helmholtz energy Parameters ---------- tau : float Inverse reduced temperature Tc/T, [-] delta : float Reduced density rho/rhoc, [-] Returns ------- prop : dict Dictionary with residual adimensional helmholtz energy and deriv: * fir * firt: ∂fir/∂τ|δ,x * fird: ∂fir/∂δ|τ,x * firtt: ∂²fir/∂τ²|δ,x * firdt: ∂²fir/∂τ∂δ|x * firdd: ∂²fir/∂δ²|τ,x References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 5 http://www.iapws.org/relguide/IAPWS-95.html """ fir = fird = firdd = firt = firtt = firdt = 0 # Polinomial terms nr1 = self._constants.get("nr1", []) d1 = self._constants.get("d1", []) t1 = self._constants.get("t1", []) for n, d, t in zip(nr1, d1, t1): fir += n*delta**d*tau**t fird += n*d*delta**(d-1)*tau**t firdd += n*d*(d-1)*delta**(d-2)*tau**t firt += n*t*delta**d*tau**(t-1) firtt += n*t*(t-1)*delta**d*tau**(t-2) firdt += n*t*d*delta**(d-1)*tau**(t-1) # Exponential terms nr2 = self._constants.get("nr2", []) d2 = self._constants.get("d2", []) g2 = self._constants.get("gamma2", []) t2 = self._constants.get("t2", []) c2 = self._constants.get("c2", []) for n, d, g, t, c in zip(nr2, d2, g2, t2, c2): fir += n*delta**d*tau**t*exp(-g*delta**c) fird += n*exp(-g*delta**c)*delta**(d-1)*tau**t*(d-g*c*delta**c) firdd += n*exp(-g*delta**c)*delta**(d-2)*tau**t * \ ((d-g*c*delta**c)*(d-1-g*c*delta**c)-g**2*c**2*delta**c) firt += n*t*delta**d*tau**(t-1)*exp(-g*delta**c) firtt += n*t*(t-1)*delta**d*tau**(t-2)*exp(-g*delta**c) firdt += n*t*delta**(d-1)*tau**(t-1)*(d-g*c*delta**c)*exp( -g*delta**c) # Gaussian terms nr3 = self._constants.get("nr3", []) d3 = self._constants.get("d3", []) t3 = self._constants.get("t3", []) a3 = self._constants.get("alfa3", []) e3 = self._constants.get("epsilon3", []) b3 = self._constants.get("beta3", []) g3 = self._constants.get("gamma3", []) for n, d, t, a, e, b, g in zip(nr3, d3, t3, a3, e3, b3, g3): fir += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2) fird += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( d/delta-2*a*(delta-e)) firdd += n*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( -2*a*delta**d + 4*a**2*delta**d*(delta-e)**2 - 4*d*a*delta**(d-1)*(delta-e) + d*(d-1)*delta**(d-2)) firt += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( t/tau-2*b*(tau-g)) firtt += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( (t/tau-2*b*(tau-g))**2-t/tau**2-2*b) firdt += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( t/tau-2*b*(tau-g))*(d/delta-2*a*(delta-e)) # Non analitic terms nr4 = self._constants.get("nr4", []) a4 = self._constants.get("a4", []) b4 = self._constants.get("b4", []) Ai = self._constants.get("A", []) Bi = self._constants.get("B", []) Ci = self._constants.get("C", []) Di = self._constants.get("D", []) bt4 = self._constants.get("beta4", []) for n, a, b, A, B, C, D, bt in zip(nr4, a4, b4, Ai, Bi, Ci, Di, bt4): Tita = (1-tau)+A*((delta-1)**2)**(0.5/bt) F = exp(-C*(delta-1)**2-D*(tau-1)**2) Fd = -2*C*F*(delta-1) Fdd = 2*C*F*(2*C*(delta-1)**2-1) Ft = -2*D*F*(tau-1) Ftt = 2*D*F*(2*D*(tau-1)**2-1) Fdt = 4*C*D*F*(delta-1)*(tau-1) Delta = Tita**2+B*((delta-1)**2)**a Deltad = (delta-1)*(A*Tita*2/bt*((delta-1)**2)**(0.5/bt-1) + 2*B*a*((delta-1)**2)**(a-1)) if delta == 1: Deltadd = 0 else: Deltadd = Deltad/(delta-1)+(delta-1)**2*( 4*B*a*(a-1)*((delta-1)**2)**(a-2) + 2*A**2/bt**2*(((delta-1)**2)**(0.5/bt-1))**2 + A*Tita*4/bt*(0.5/bt-1)*((delta-1)**2)**(0.5/bt-2)) DeltaBd = b*Delta**(b-1)*Deltad DeltaBdd = b*(Delta**(b-1)*Deltadd+(b-1)*Delta**(b-2)*Deltad**2) DeltaBt = -2*Tita*b*Delta**(b-1) DeltaBtt = 2*b*Delta**(b-1)+4*Tita**2*b*(b-1)*Delta**(b-2) DeltaBdt = -A*b*2/bt*Delta**(b-1)*(delta-1)*((delta-1)**2)**( 0.5/bt-1)-2*Tita*b*(b-1)*Delta**(b-2)*Deltad fir += n*Delta**b*delta*F fird += n*(Delta**b*(F+delta*Fd)+DeltaBd*delta*F) firdd += n*(Delta**b*(2*Fd+delta*Fdd) + 2*DeltaBd*(F+delta*Fd) + DeltaBdd*delta*F) firt += n*delta*(DeltaBt*F+Delta**b*Ft) firtt += n*delta*(DeltaBtt*F+2*DeltaBt*Ft+Delta**b*Ftt) firdt += n*(Delta**b*(Ft+delta*Fdt)+delta*DeltaBd*Ft + DeltaBt*(F+delta*Fd)+DeltaBdt*delta*F) prop = {} prop["fir"] = fir prop["firt"] = firt prop["firtt"] = firtt prop["fird"] = fird prop["firdd"] = firdd prop["firdt"] = firdt return prop
python
def _phir(self, tau, delta): """Residual contribution to the free Helmholtz energy Parameters ---------- tau : float Inverse reduced temperature Tc/T, [-] delta : float Reduced density rho/rhoc, [-] Returns ------- prop : dict Dictionary with residual adimensional helmholtz energy and deriv: * fir * firt: ∂fir/∂τ|δ,x * fird: ∂fir/∂δ|τ,x * firtt: ∂²fir/∂τ²|δ,x * firdt: ∂²fir/∂τ∂δ|x * firdd: ∂²fir/∂δ²|τ,x References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 5 http://www.iapws.org/relguide/IAPWS-95.html """ fir = fird = firdd = firt = firtt = firdt = 0 # Polinomial terms nr1 = self._constants.get("nr1", []) d1 = self._constants.get("d1", []) t1 = self._constants.get("t1", []) for n, d, t in zip(nr1, d1, t1): fir += n*delta**d*tau**t fird += n*d*delta**(d-1)*tau**t firdd += n*d*(d-1)*delta**(d-2)*tau**t firt += n*t*delta**d*tau**(t-1) firtt += n*t*(t-1)*delta**d*tau**(t-2) firdt += n*t*d*delta**(d-1)*tau**(t-1) # Exponential terms nr2 = self._constants.get("nr2", []) d2 = self._constants.get("d2", []) g2 = self._constants.get("gamma2", []) t2 = self._constants.get("t2", []) c2 = self._constants.get("c2", []) for n, d, g, t, c in zip(nr2, d2, g2, t2, c2): fir += n*delta**d*tau**t*exp(-g*delta**c) fird += n*exp(-g*delta**c)*delta**(d-1)*tau**t*(d-g*c*delta**c) firdd += n*exp(-g*delta**c)*delta**(d-2)*tau**t * \ ((d-g*c*delta**c)*(d-1-g*c*delta**c)-g**2*c**2*delta**c) firt += n*t*delta**d*tau**(t-1)*exp(-g*delta**c) firtt += n*t*(t-1)*delta**d*tau**(t-2)*exp(-g*delta**c) firdt += n*t*delta**(d-1)*tau**(t-1)*(d-g*c*delta**c)*exp( -g*delta**c) # Gaussian terms nr3 = self._constants.get("nr3", []) d3 = self._constants.get("d3", []) t3 = self._constants.get("t3", []) a3 = self._constants.get("alfa3", []) e3 = self._constants.get("epsilon3", []) b3 = self._constants.get("beta3", []) g3 = self._constants.get("gamma3", []) for n, d, t, a, e, b, g in zip(nr3, d3, t3, a3, e3, b3, g3): fir += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2) fird += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( d/delta-2*a*(delta-e)) firdd += n*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( -2*a*delta**d + 4*a**2*delta**d*(delta-e)**2 - 4*d*a*delta**(d-1)*(delta-e) + d*(d-1)*delta**(d-2)) firt += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( t/tau-2*b*(tau-g)) firtt += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( (t/tau-2*b*(tau-g))**2-t/tau**2-2*b) firdt += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( t/tau-2*b*(tau-g))*(d/delta-2*a*(delta-e)) # Non analitic terms nr4 = self._constants.get("nr4", []) a4 = self._constants.get("a4", []) b4 = self._constants.get("b4", []) Ai = self._constants.get("A", []) Bi = self._constants.get("B", []) Ci = self._constants.get("C", []) Di = self._constants.get("D", []) bt4 = self._constants.get("beta4", []) for n, a, b, A, B, C, D, bt in zip(nr4, a4, b4, Ai, Bi, Ci, Di, bt4): Tita = (1-tau)+A*((delta-1)**2)**(0.5/bt) F = exp(-C*(delta-1)**2-D*(tau-1)**2) Fd = -2*C*F*(delta-1) Fdd = 2*C*F*(2*C*(delta-1)**2-1) Ft = -2*D*F*(tau-1) Ftt = 2*D*F*(2*D*(tau-1)**2-1) Fdt = 4*C*D*F*(delta-1)*(tau-1) Delta = Tita**2+B*((delta-1)**2)**a Deltad = (delta-1)*(A*Tita*2/bt*((delta-1)**2)**(0.5/bt-1) + 2*B*a*((delta-1)**2)**(a-1)) if delta == 1: Deltadd = 0 else: Deltadd = Deltad/(delta-1)+(delta-1)**2*( 4*B*a*(a-1)*((delta-1)**2)**(a-2) + 2*A**2/bt**2*(((delta-1)**2)**(0.5/bt-1))**2 + A*Tita*4/bt*(0.5/bt-1)*((delta-1)**2)**(0.5/bt-2)) DeltaBd = b*Delta**(b-1)*Deltad DeltaBdd = b*(Delta**(b-1)*Deltadd+(b-1)*Delta**(b-2)*Deltad**2) DeltaBt = -2*Tita*b*Delta**(b-1) DeltaBtt = 2*b*Delta**(b-1)+4*Tita**2*b*(b-1)*Delta**(b-2) DeltaBdt = -A*b*2/bt*Delta**(b-1)*(delta-1)*((delta-1)**2)**( 0.5/bt-1)-2*Tita*b*(b-1)*Delta**(b-2)*Deltad fir += n*Delta**b*delta*F fird += n*(Delta**b*(F+delta*Fd)+DeltaBd*delta*F) firdd += n*(Delta**b*(2*Fd+delta*Fdd) + 2*DeltaBd*(F+delta*Fd) + DeltaBdd*delta*F) firt += n*delta*(DeltaBt*F+Delta**b*Ft) firtt += n*delta*(DeltaBtt*F+2*DeltaBt*Ft+Delta**b*Ftt) firdt += n*(Delta**b*(Ft+delta*Fdt)+delta*DeltaBd*Ft + DeltaBt*(F+delta*Fd)+DeltaBdt*delta*F) prop = {} prop["fir"] = fir prop["firt"] = firt prop["firtt"] = firtt prop["fird"] = fird prop["firdd"] = firdd prop["firdt"] = firdt return prop
Residual contribution to the free Helmholtz energy Parameters ---------- tau : float Inverse reduced temperature Tc/T, [-] delta : float Reduced density rho/rhoc, [-] Returns ------- prop : dict Dictionary with residual adimensional helmholtz energy and deriv: * fir * firt: ∂fir/∂τ|δ,x * fird: ∂fir/∂δ|τ,x * firtt: ∂²fir/∂τ²|δ,x * firdt: ∂²fir/∂τ∂δ|x * firdd: ∂²fir/∂δ²|τ,x References ---------- IAPWS, Revised Release on the IAPWS Formulation 1995 for the Thermodynamic Properties of Ordinary Water Substance for General and Scientific Use, September 2016, Table 5 http://www.iapws.org/relguide/IAPWS-95.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L1758-L1890
jjgomera/iapws
iapws/iapws95.py
MEoS._virial
def _virial(self, T): """Virial coefficient Parameters ---------- T : float Temperature [K] Returns ------- prop : dict Dictionary with residual adimensional helmholtz energy: * B: ∂fir/∂δ|δ->0 * C: ∂²fir/∂δ²|δ->0 """ Tc = self._constants.get("Tref", self.Tc) tau = Tc/T B = C = 0 delta = 1e-200 # Polinomial terms nr1 = self._constants.get("nr1", []) d1 = self._constants.get("d1", []) t1 = self._constants.get("t1", []) for n, d, t in zip(nr1, d1, t1): B += n*d*delta**(d-1)*tau**t C += n*d*(d-1)*delta**(d-2)*tau**t # Exponential terms nr2 = self._constants.get("nr2", []) d2 = self._constants.get("d2", []) g2 = self._constants.get("gamma2", []) t2 = self._constants.get("t2", []) c2 = self._constants.get("c2", []) for n, d, g, t, c in zip(nr2, d2, g2, t2, c2): B += n*exp(-g*delta**c)*delta**(d-1)*tau**t*(d-g*c*delta**c) C += n*exp(-g*delta**c)*(delta**(d-2)*tau**t*( (d-g*c*delta**c)*(d-1-g*c*delta**c)-g**2*c**2*delta**c)) # Gaussian terms nr3 = self._constants.get("nr3", []) d3 = self._constants.get("d3", []) t3 = self._constants.get("t3", []) a3 = self._constants.get("alfa3", []) e3 = self._constants.get("epsilon3", []) b3 = self._constants.get("beta3", []) g3 = self._constants.get("gamma3", []) for n, d, t, a, e, b, g in zip(nr3, d3, t3, a3, e3, b3, g3): B += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( d/delta-2*a*(delta-e)) C += n*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( -2*a*delta**d+4*a**2*delta**d*( delta-e)**2-4*d*a*delta**2*( delta-e)+d*2*delta) # Non analitic terms nr4 = self._constants.get("nr4", []) a4 = self._constants.get("a4", []) b4 = self._constants.get("b4", []) Ai = self._constants.get("A", []) Bi = self._constants.get("B", []) Ci = self._constants.get("C", []) Di = self._constants.get("D", []) bt4 = self._constants.get("beta4", []) for n, a, b, A, B, C, D, bt in zip(nr4, a4, b4, Ai, Bi, Ci, Di, bt4): Tita = (1-tau)+A*((delta-1)**2)**(0.5/bt) Delta = Tita**2+B*((delta-1)**2)**a Deltad = (delta-1)*(A*Tita*2/bt*((delta-1)**2)**( 0.5/bt-1)+2*B*a*((delta-1)**2)**(a-1)) Deltadd = Deltad/(delta-1) + (delta-1)**2*( 4*B*a*(a-1)*((delta-1)**2)**(a-2) + 2*A**2/bt**2*(((delta-1)**2)**(0.5/bt-1))**2 + A*Tita*4/bt*(0.5/bt-1)*((delta-1)**2)**(0.5/bt-2)) DeltaBd = b*Delta**(b-1)*Deltad DeltaBdd = b*(Delta**(b-1)*Deltadd+(b-1)*Delta**(b-2)*Deltad**2) F = exp(-C*(delta-1)**2-D*(tau-1)**2) Fd = -2*C*F*(delta-1) Fdd = 2*C*F*(2*C*(delta-1)**2-1) B += n*(Delta**b*(F+delta*Fd)+DeltaBd*delta*F) C += n*(Delta**b*(2*Fd+delta*Fdd)+2*DeltaBd*(F+delta*Fd) + DeltaBdd*delta*F) prop = {} prop["B"] = B prop["C"] = C return prop
python
def _virial(self, T): """Virial coefficient Parameters ---------- T : float Temperature [K] Returns ------- prop : dict Dictionary with residual adimensional helmholtz energy: * B: ∂fir/∂δ|δ->0 * C: ∂²fir/∂δ²|δ->0 """ Tc = self._constants.get("Tref", self.Tc) tau = Tc/T B = C = 0 delta = 1e-200 # Polinomial terms nr1 = self._constants.get("nr1", []) d1 = self._constants.get("d1", []) t1 = self._constants.get("t1", []) for n, d, t in zip(nr1, d1, t1): B += n*d*delta**(d-1)*tau**t C += n*d*(d-1)*delta**(d-2)*tau**t # Exponential terms nr2 = self._constants.get("nr2", []) d2 = self._constants.get("d2", []) g2 = self._constants.get("gamma2", []) t2 = self._constants.get("t2", []) c2 = self._constants.get("c2", []) for n, d, g, t, c in zip(nr2, d2, g2, t2, c2): B += n*exp(-g*delta**c)*delta**(d-1)*tau**t*(d-g*c*delta**c) C += n*exp(-g*delta**c)*(delta**(d-2)*tau**t*( (d-g*c*delta**c)*(d-1-g*c*delta**c)-g**2*c**2*delta**c)) # Gaussian terms nr3 = self._constants.get("nr3", []) d3 = self._constants.get("d3", []) t3 = self._constants.get("t3", []) a3 = self._constants.get("alfa3", []) e3 = self._constants.get("epsilon3", []) b3 = self._constants.get("beta3", []) g3 = self._constants.get("gamma3", []) for n, d, t, a, e, b, g in zip(nr3, d3, t3, a3, e3, b3, g3): B += n*delta**d*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( d/delta-2*a*(delta-e)) C += n*tau**t*exp(-a*(delta-e)**2-b*(tau-g)**2)*( -2*a*delta**d+4*a**2*delta**d*( delta-e)**2-4*d*a*delta**2*( delta-e)+d*2*delta) # Non analitic terms nr4 = self._constants.get("nr4", []) a4 = self._constants.get("a4", []) b4 = self._constants.get("b4", []) Ai = self._constants.get("A", []) Bi = self._constants.get("B", []) Ci = self._constants.get("C", []) Di = self._constants.get("D", []) bt4 = self._constants.get("beta4", []) for n, a, b, A, B, C, D, bt in zip(nr4, a4, b4, Ai, Bi, Ci, Di, bt4): Tita = (1-tau)+A*((delta-1)**2)**(0.5/bt) Delta = Tita**2+B*((delta-1)**2)**a Deltad = (delta-1)*(A*Tita*2/bt*((delta-1)**2)**( 0.5/bt-1)+2*B*a*((delta-1)**2)**(a-1)) Deltadd = Deltad/(delta-1) + (delta-1)**2*( 4*B*a*(a-1)*((delta-1)**2)**(a-2) + 2*A**2/bt**2*(((delta-1)**2)**(0.5/bt-1))**2 + A*Tita*4/bt*(0.5/bt-1)*((delta-1)**2)**(0.5/bt-2)) DeltaBd = b*Delta**(b-1)*Deltad DeltaBdd = b*(Delta**(b-1)*Deltadd+(b-1)*Delta**(b-2)*Deltad**2) F = exp(-C*(delta-1)**2-D*(tau-1)**2) Fd = -2*C*F*(delta-1) Fdd = 2*C*F*(2*C*(delta-1)**2-1) B += n*(Delta**b*(F+delta*Fd)+DeltaBd*delta*F) C += n*(Delta**b*(2*Fd+delta*Fdd)+2*DeltaBd*(F+delta*Fd) + DeltaBdd*delta*F) prop = {} prop["B"] = B prop["C"] = C return prop
Virial coefficient Parameters ---------- T : float Temperature [K] Returns ------- prop : dict Dictionary with residual adimensional helmholtz energy: * B: ∂fir/∂δ|δ->0 * C: ∂²fir/∂δ²|δ->0
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L1892-L1978
jjgomera/iapws
iapws/iapws95.py
MEoS._derivDimensional
def _derivDimensional(self, rho, T): """Calcule the dimensional form or Helmholtz free energy derivatives Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- prop : dict Dictionary with residual helmholtz energy and derivatives: * fir, [kJ/kg] * firt: ∂fir/∂T|ρ, [kJ/kgK] * fird: ∂fir/∂ρ|T, [kJ/m³kg²] * firtt: ∂²fir/∂T²|ρ, [kJ/kgK²] * firdt: ∂²fir/∂T∂ρ, [kJ/m³kg²K] * firdd: ∂²fir/∂ρ²|T, [kJ/m⁶kg] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 7, http://www.iapws.org/relguide/SeaAir.html """ if not rho: prop = {} prop["fir"] = 0 prop["firt"] = 0 prop["fird"] = 0 prop["firtt"] = 0 prop["firdt"] = 0 prop["firdd"] = 0 return prop R = self._constants.get("R")/self._constants.get("M", self.M) rhoc = self._constants.get("rhoref", self.rhoc) Tc = self._constants.get("Tref", self.Tc) delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fiott = ideal["fiott"] fiod = ideal["fiod"] fiodd = ideal["fiodd"] res = self._phir(tau, delta) fir = res["fir"] firt = res["firt"] firtt = res["firtt"] fird = res["fird"] firdd = res["firdd"] firdt = res["firdt"] prop = {} prop["fir"] = R*T*(fio+fir) prop["firt"] = R*(fio+fir-(fiot+firt)*tau) prop["fird"] = R*T/rhoc*(fiod+fird) prop["firtt"] = R*tau**2/T*(fiott+firtt) prop["firdt"] = R/rhoc*(fiod+fird-firdt*tau) prop["firdd"] = R*T/rhoc**2*(fiodd+firdd) return prop
python
def _derivDimensional(self, rho, T): """Calcule the dimensional form or Helmholtz free energy derivatives Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- prop : dict Dictionary with residual helmholtz energy and derivatives: * fir, [kJ/kg] * firt: ∂fir/∂T|ρ, [kJ/kgK] * fird: ∂fir/∂ρ|T, [kJ/m³kg²] * firtt: ∂²fir/∂T²|ρ, [kJ/kgK²] * firdt: ∂²fir/∂T∂ρ, [kJ/m³kg²K] * firdd: ∂²fir/∂ρ²|T, [kJ/m⁶kg] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 7, http://www.iapws.org/relguide/SeaAir.html """ if not rho: prop = {} prop["fir"] = 0 prop["firt"] = 0 prop["fird"] = 0 prop["firtt"] = 0 prop["firdt"] = 0 prop["firdd"] = 0 return prop R = self._constants.get("R")/self._constants.get("M", self.M) rhoc = self._constants.get("rhoref", self.rhoc) Tc = self._constants.get("Tref", self.Tc) delta = rho/rhoc tau = Tc/T ideal = self._phi0(tau, delta) fio = ideal["fio"] fiot = ideal["fiot"] fiott = ideal["fiott"] fiod = ideal["fiod"] fiodd = ideal["fiodd"] res = self._phir(tau, delta) fir = res["fir"] firt = res["firt"] firtt = res["firtt"] fird = res["fird"] firdd = res["firdd"] firdt = res["firdt"] prop = {} prop["fir"] = R*T*(fio+fir) prop["firt"] = R*(fio+fir-(fiot+firt)*tau) prop["fird"] = R*T/rhoc*(fiod+fird) prop["firtt"] = R*tau**2/T*(fiott+firtt) prop["firdt"] = R/rhoc*(fiod+fird-firdt*tau) prop["firdd"] = R*T/rhoc**2*(fiodd+firdd) return prop
Calcule the dimensional form or Helmholtz free energy derivatives Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- prop : dict Dictionary with residual helmholtz energy and derivatives: * fir, [kJ/kg] * firt: ∂fir/∂T|ρ, [kJ/kgK] * fird: ∂fir/∂ρ|T, [kJ/m³kg²] * firtt: ∂²fir/∂T²|ρ, [kJ/kgK²] * firdt: ∂²fir/∂T∂ρ, [kJ/m³kg²K] * firdd: ∂²fir/∂ρ²|T, [kJ/m⁶kg] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 7, http://www.iapws.org/relguide/SeaAir.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L1980-L2047
jjgomera/iapws
iapws/iapws95.py
MEoS._surface
def _surface(self, T): """Generic equation for the surface tension Parameters ---------- T : float Temperature, [K] Returns ------- σ : float Surface tension, [N/m] Notes ----- Need a _surf dict in the derived class with the parameters keys: sigma: coefficient exp: exponent """ tau = 1-T/self.Tc sigma = 0 for n, t in zip(self._surf["sigma"], self._surf["exp"]): sigma += n*tau**t return sigma
python
def _surface(self, T): """Generic equation for the surface tension Parameters ---------- T : float Temperature, [K] Returns ------- σ : float Surface tension, [N/m] Notes ----- Need a _surf dict in the derived class with the parameters keys: sigma: coefficient exp: exponent """ tau = 1-T/self.Tc sigma = 0 for n, t in zip(self._surf["sigma"], self._surf["exp"]): sigma += n*tau**t return sigma
Generic equation for the surface tension Parameters ---------- T : float Temperature, [K] Returns ------- σ : float Surface tension, [N/m] Notes ----- Need a _surf dict in the derived class with the parameters keys: sigma: coefficient exp: exponent
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L2049-L2072
jjgomera/iapws
iapws/iapws95.py
MEoS._Vapor_Pressure
def _Vapor_Pressure(cls, T): """Auxiliary equation for the vapour pressure Parameters ---------- T : float Temperature, [K] Returns ------- Pv : float Vapour pressure, [Pa] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, Eq.1 """ Tita = 1-T/cls.Tc suma = 0 for n, x in zip(cls._Pv["ao"], cls._Pv["exp"]): suma += n*Tita**x Pr = exp(cls.Tc/T*suma) Pv = Pr*cls.Pc return Pv
python
def _Vapor_Pressure(cls, T): """Auxiliary equation for the vapour pressure Parameters ---------- T : float Temperature, [K] Returns ------- Pv : float Vapour pressure, [Pa] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, Eq.1 """ Tita = 1-T/cls.Tc suma = 0 for n, x in zip(cls._Pv["ao"], cls._Pv["exp"]): suma += n*Tita**x Pr = exp(cls.Tc/T*suma) Pv = Pr*cls.Pc return Pv
Auxiliary equation for the vapour pressure Parameters ---------- T : float Temperature, [K] Returns ------- Pv : float Vapour pressure, [Pa] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, Eq.1
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L2075-L2100
jjgomera/iapws
iapws/iapws95.py
MEoS._Liquid_Density
def _Liquid_Density(cls, T): """Auxiliary equation for the density of saturated liquid Parameters ---------- T : float Temperature, [K] Returns ------- rho : float Saturated liquid density, [kg/m³] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, Eq.2 """ eq = cls._rhoL["eq"] Tita = 1-T/cls.Tc if eq == 2: Tita = Tita**(1./3) suma = 0 for n, x in zip(cls._rhoL["ao"], cls._rhoL["exp"]): suma += n*Tita**x Pr = suma+1 rho = Pr*cls.rhoc return rho
python
def _Liquid_Density(cls, T): """Auxiliary equation for the density of saturated liquid Parameters ---------- T : float Temperature, [K] Returns ------- rho : float Saturated liquid density, [kg/m³] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, Eq.2 """ eq = cls._rhoL["eq"] Tita = 1-T/cls.Tc if eq == 2: Tita = Tita**(1./3) suma = 0 for n, x in zip(cls._rhoL["ao"], cls._rhoL["exp"]): suma += n*Tita**x Pr = suma+1 rho = Pr*cls.rhoc return rho
Auxiliary equation for the density of saturated liquid Parameters ---------- T : float Temperature, [K] Returns ------- rho : float Saturated liquid density, [kg/m³] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, Eq.2
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L2103-L2131
jjgomera/iapws
iapws/iapws95.py
MEoS._Vapor_Density
def _Vapor_Density(cls, T): """Auxiliary equation for the density of saturated vapor Parameters ---------- T : float Temperature, [K] Returns ------- rho : float Saturated vapor density, [kg/m³] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, Eq.3 """ eq = cls._rhoG["eq"] Tita = 1-T/cls.Tc if eq == 4: Tita = Tita**(1./3) suma = 0 for n, x in zip(cls._rhoG["ao"], cls._rhoG["exp"]): suma += n*Tita**x Pr = exp(suma) rho = Pr*cls.rhoc return rho
python
def _Vapor_Density(cls, T): """Auxiliary equation for the density of saturated vapor Parameters ---------- T : float Temperature, [K] Returns ------- rho : float Saturated vapor density, [kg/m³] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, Eq.3 """ eq = cls._rhoG["eq"] Tita = 1-T/cls.Tc if eq == 4: Tita = Tita**(1./3) suma = 0 for n, x in zip(cls._rhoG["ao"], cls._rhoG["exp"]): suma += n*Tita**x Pr = exp(suma) rho = Pr*cls.rhoc return rho
Auxiliary equation for the density of saturated vapor Parameters ---------- T : float Temperature, [K] Returns ------- rho : float Saturated vapor density, [kg/m³] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, Eq.3
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L2134-L2162
jjgomera/iapws
iapws/iapws95.py
MEoS._dPdT_sat
def _dPdT_sat(cls, T): """Auxiliary equation for the dP/dT along saturation line Parameters ---------- T : float Temperature, [K] Returns ------- dPdT : float dPdT, [MPa/K] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, derived from Eq.1 """ Tita = 1-T/cls.Tc suma1 = 0 suma2 = 0 for n, x in zip(cls._Pv["ao"], cls._Pv["exp"]): suma1 -= n*x*Tita**(x-1)/cls.Tc suma2 += n*Tita**x Pr = (cls.Tc*suma1/T-cls.Tc/T**2*suma2)*exp(cls.Tc/T*suma2) dPdT = Pr*cls.Pc return dPdT
python
def _dPdT_sat(cls, T): """Auxiliary equation for the dP/dT along saturation line Parameters ---------- T : float Temperature, [K] Returns ------- dPdT : float dPdT, [MPa/K] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, derived from Eq.1 """ Tita = 1-T/cls.Tc suma1 = 0 suma2 = 0 for n, x in zip(cls._Pv["ao"], cls._Pv["exp"]): suma1 -= n*x*Tita**(x-1)/cls.Tc suma2 += n*Tita**x Pr = (cls.Tc*suma1/T-cls.Tc/T**2*suma2)*exp(cls.Tc/T*suma2) dPdT = Pr*cls.Pc return dPdT
Auxiliary equation for the dP/dT along saturation line Parameters ---------- T : float Temperature, [K] Returns ------- dPdT : float dPdT, [MPa/K] References ---------- IAPWS, Revised Supplementary Release on Saturation Properties of Ordinary Water Substance September 1992, http://www.iapws.org/relguide/Supp-sat.html, derived from Eq.1
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws95.py#L2165-L2192
jjgomera/iapws
iapws/humidAir.py
_virial
def _virial(T): """Virial equations for humid air Parameters ---------- T : float Temperature [K] Returns ------- prop : dict Dictionary with critical coefficient: * Baa: Second virial coefficient of dry air, [m³/mol] * Baw: Second air-water cross virial coefficient, [m³/mol] * Bww: Second virial coefficient of water, [m³/mol] * Caaa: Third virial coefficient of dry air, [m⁶/mol] * Caaw: Third air-water cross virial coefficient, [m⁶/mol] * Caww: Third air-water cross virial coefficient, [m⁶/mol] * Cwww: Third virial coefficient of dry air, [m⁶/mol] * Bawt: dBaw/dT, [m³/molK] * Bawtt: d²Baw/dT², [m³/molK²] * Caawt: dCaaw/dT, [m⁶/molK] * Caawtt: d²Caaw/dT², [m⁶/molK²] * Cawwt: dCaww/dT, [m⁶/molK] * Cawwtt: d²Caww/dT², [m⁶/molK²] Notes ------ Raise :class:`Warning` if T isn't in range of validity: * Baa: 60 ≤ T ≤ 2000 * Baw: 130 ≤ T ≤ 2000 * Bww: 130 ≤ T ≤ 1273 * Caaa: 60 ≤ T ≤ 2000 * Caaw: 193 ≤ T ≤ 493 * Caww: 173 ≤ T ≤ 473 * Cwww: 130 ≤ T ≤ 1273 Examples -------- >>> _virial(200)["Baa"] -3.92722567e-5 References ---------- IAPWS, Guideline on a Virial Equation for the Fugacity of H2O in Humid Air, http://www.iapws.org/relguide/VirialFugacity.html IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 10, http://www.iapws.org/relguide/SeaAir.html """ # Check input parameters if T < 60 or T > 2000: warnings.warn("Baa out of validity range") if T < 130 or T > 2000: warnings.warn("Baw out of validity range") if T < 130 or T > 1273: warnings.warn("Bww out of validity range") if T < 60 or T > 2000: warnings.warn("Caaa out of validity range") if T < 193 or T > 493: warnings.warn("Caaw out of validity range") if T < 173 or T > 473: warnings.warn("Caww out of validity range") if T < 130 or T > 1273: warnings.warn("Cwww out of validity range") T_ = T/100 tau = IAPWS95.Tc/T # Table 1 # Reorganizated to easy use in equations tb = [-0.5, 0.875, 1, 4, 6, 12, 7] nb = [0.12533547935523e-1, 0.78957634722828e1, -0.87803203303561e1, -0.66856572307965, 0.20433810950965, -0.66212605039687e-4, -0.10793600908932] bc = [0.5, 0.75, 1, 5, 1, 9, 10] nc = [0.31802509345418, -0.26145533859358, -0.19232721156002, -0.25709043003438, 0.17611491008752e-1, 0.22132295167546, -0.40247669763528] bc2 = [4, 6, 12] nc2 = [-0.66856572307965, 0.20433810950965, -0.66212605039687e-4] # Table 2 ai = [3.5, 3.5] bi = [0.85, 0.95] Bi = [0.2, 0.2] ni = [-0.14874640856724, 0.31806110878444] Ci = [28, 32] Di = [700, 800] Ai = [0.32, 0.32] betai = [0.3, 0.3] # Eq 5 sum1 = sum([n*tau**t for n, t in zip(nb, tb)]) sum2 = 0 for n, b, B, A, C, D in zip(ni, bi, Bi, Ai, Ci, Di): sum2 += n*((A+1-tau)**2+B)**b*exp(-C-D*(tau-1)**2) Bww = Mw/IAPWS95.rhoc*(sum1+sum2) # Eq 6 sum1 = sum([n*tau**t for n, t in zip(nc, bc)]) sum2 = sum([n*tau**t for n, t in zip(nc2, bc2)]) sum3 = 0 for a, b, B, n, C, D, A, beta in zip(ai, bi, Bi, ni, Ci, Di, Ai, betai): Tita = A+1-tau sum3 += n*(C*(Tita**2+B)-b*(A*Tita/beta+B*a))*(Tita**2+B)**(b-1) * \ exp(-C-D*(tau-1)**2) Cwww = 2*(Mw/IAPWS95.rhoc)**2*(sum1-sum2+2*sum3) # Table 3 ai = [0.482737e-3, 0.105678e-2, -0.656394e-2, 0.294442e-1, -0.319317e-1] bi = [-10.728876, 34.7802, -38.3383, 33.406] ci = [66.5687, -238.834, -176.755] di = [-0.237, -1.048, -3.183] Baw = 1e-6*sum([c*T_**d for c, d in zip(ci, di)]) # Eq 7 Caaw = 1e-6*sum([a/T_**i for i, a in enumerate(ai)]) # Eq 8 Caww = -1e-6*exp(sum([b/T_**i for i, b in enumerate(bi)])) # Eq 9 # Eq T56 Bawt = 1e-6*T_/T*sum([c*d*T_**(d-1) for c, d in zip(ci, di)]) # Eq T57 Bawtt = 1e-6*T_**2/T**2*sum( [c*d*(d-1)*T_**(d-2) for c, d in zip(ci, di)]) # Eq T59 Caawt = -1e-6*T_/T*sum([i*a*T_**(-i-1) for i, a in enumerate(ai)]) # Eq T60 Caawtt = 1e-6*T_**2/T**2*sum( [i*(i+1)*a*T_**(-i-2) for i, a in enumerate(ai)]) # Eq T62 Cawwt = 1e-6*T_/T*sum([i*b*T_**(-i-1) for i, b in enumerate(bi)]) * \ exp(sum([b/T_**i for i, b in enumerate(bi)])) # Eq T63 Cawwtt = -1e-6*T_**2/T**2*(( sum([i*(i+1)*b*T_**(-i-2) for i, b in enumerate(bi)]) + sum([i*b*T_**(-i-1) for i, b in enumerate(bi)])**2) * exp(sum([b/T_**i for i, b in enumerate(bi)]))) # Table 4 # Reorganizated to easy use in equations ji = [0, 0.33, 1.01, 1.6, 3.6, 3.5] ni = [0.118160747229, 0.713116392079, -0.161824192067e1, -0.101365037912, -0.146629609713, 0.148287891978e-1] tau = 132.6312/T Baa = 1/10.4477*sum([n*tau**j for j, n in zip(ji, ni)]) # Eq 10 Caaa = 2/10.4477**2*(0.714140178971e-1+0.101365037912*tau**1.6) # Eq 11 prop = {} prop["Baa"] = Baa/1000 prop["Baw"] = Baw prop["Bww"] = Bww/1000 prop["Caaa"] = Caaa/1e6 prop["Caaw"] = Caaw prop["Caww"] = Caww prop["Cwww"] = Cwww/1e6 prop["Bawt"] = Bawt prop["Bawtt"] = Bawtt prop["Caawt"] = Caawt prop["Caawtt"] = Caawtt prop["Cawwt"] = Cawwt prop["Cawwtt"] = Cawwtt return prop
python
def _virial(T): """Virial equations for humid air Parameters ---------- T : float Temperature [K] Returns ------- prop : dict Dictionary with critical coefficient: * Baa: Second virial coefficient of dry air, [m³/mol] * Baw: Second air-water cross virial coefficient, [m³/mol] * Bww: Second virial coefficient of water, [m³/mol] * Caaa: Third virial coefficient of dry air, [m⁶/mol] * Caaw: Third air-water cross virial coefficient, [m⁶/mol] * Caww: Third air-water cross virial coefficient, [m⁶/mol] * Cwww: Third virial coefficient of dry air, [m⁶/mol] * Bawt: dBaw/dT, [m³/molK] * Bawtt: d²Baw/dT², [m³/molK²] * Caawt: dCaaw/dT, [m⁶/molK] * Caawtt: d²Caaw/dT², [m⁶/molK²] * Cawwt: dCaww/dT, [m⁶/molK] * Cawwtt: d²Caww/dT², [m⁶/molK²] Notes ------ Raise :class:`Warning` if T isn't in range of validity: * Baa: 60 ≤ T ≤ 2000 * Baw: 130 ≤ T ≤ 2000 * Bww: 130 ≤ T ≤ 1273 * Caaa: 60 ≤ T ≤ 2000 * Caaw: 193 ≤ T ≤ 493 * Caww: 173 ≤ T ≤ 473 * Cwww: 130 ≤ T ≤ 1273 Examples -------- >>> _virial(200)["Baa"] -3.92722567e-5 References ---------- IAPWS, Guideline on a Virial Equation for the Fugacity of H2O in Humid Air, http://www.iapws.org/relguide/VirialFugacity.html IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 10, http://www.iapws.org/relguide/SeaAir.html """ # Check input parameters if T < 60 or T > 2000: warnings.warn("Baa out of validity range") if T < 130 or T > 2000: warnings.warn("Baw out of validity range") if T < 130 or T > 1273: warnings.warn("Bww out of validity range") if T < 60 or T > 2000: warnings.warn("Caaa out of validity range") if T < 193 or T > 493: warnings.warn("Caaw out of validity range") if T < 173 or T > 473: warnings.warn("Caww out of validity range") if T < 130 or T > 1273: warnings.warn("Cwww out of validity range") T_ = T/100 tau = IAPWS95.Tc/T # Table 1 # Reorganizated to easy use in equations tb = [-0.5, 0.875, 1, 4, 6, 12, 7] nb = [0.12533547935523e-1, 0.78957634722828e1, -0.87803203303561e1, -0.66856572307965, 0.20433810950965, -0.66212605039687e-4, -0.10793600908932] bc = [0.5, 0.75, 1, 5, 1, 9, 10] nc = [0.31802509345418, -0.26145533859358, -0.19232721156002, -0.25709043003438, 0.17611491008752e-1, 0.22132295167546, -0.40247669763528] bc2 = [4, 6, 12] nc2 = [-0.66856572307965, 0.20433810950965, -0.66212605039687e-4] # Table 2 ai = [3.5, 3.5] bi = [0.85, 0.95] Bi = [0.2, 0.2] ni = [-0.14874640856724, 0.31806110878444] Ci = [28, 32] Di = [700, 800] Ai = [0.32, 0.32] betai = [0.3, 0.3] # Eq 5 sum1 = sum([n*tau**t for n, t in zip(nb, tb)]) sum2 = 0 for n, b, B, A, C, D in zip(ni, bi, Bi, Ai, Ci, Di): sum2 += n*((A+1-tau)**2+B)**b*exp(-C-D*(tau-1)**2) Bww = Mw/IAPWS95.rhoc*(sum1+sum2) # Eq 6 sum1 = sum([n*tau**t for n, t in zip(nc, bc)]) sum2 = sum([n*tau**t for n, t in zip(nc2, bc2)]) sum3 = 0 for a, b, B, n, C, D, A, beta in zip(ai, bi, Bi, ni, Ci, Di, Ai, betai): Tita = A+1-tau sum3 += n*(C*(Tita**2+B)-b*(A*Tita/beta+B*a))*(Tita**2+B)**(b-1) * \ exp(-C-D*(tau-1)**2) Cwww = 2*(Mw/IAPWS95.rhoc)**2*(sum1-sum2+2*sum3) # Table 3 ai = [0.482737e-3, 0.105678e-2, -0.656394e-2, 0.294442e-1, -0.319317e-1] bi = [-10.728876, 34.7802, -38.3383, 33.406] ci = [66.5687, -238.834, -176.755] di = [-0.237, -1.048, -3.183] Baw = 1e-6*sum([c*T_**d for c, d in zip(ci, di)]) # Eq 7 Caaw = 1e-6*sum([a/T_**i for i, a in enumerate(ai)]) # Eq 8 Caww = -1e-6*exp(sum([b/T_**i for i, b in enumerate(bi)])) # Eq 9 # Eq T56 Bawt = 1e-6*T_/T*sum([c*d*T_**(d-1) for c, d in zip(ci, di)]) # Eq T57 Bawtt = 1e-6*T_**2/T**2*sum( [c*d*(d-1)*T_**(d-2) for c, d in zip(ci, di)]) # Eq T59 Caawt = -1e-6*T_/T*sum([i*a*T_**(-i-1) for i, a in enumerate(ai)]) # Eq T60 Caawtt = 1e-6*T_**2/T**2*sum( [i*(i+1)*a*T_**(-i-2) for i, a in enumerate(ai)]) # Eq T62 Cawwt = 1e-6*T_/T*sum([i*b*T_**(-i-1) for i, b in enumerate(bi)]) * \ exp(sum([b/T_**i for i, b in enumerate(bi)])) # Eq T63 Cawwtt = -1e-6*T_**2/T**2*(( sum([i*(i+1)*b*T_**(-i-2) for i, b in enumerate(bi)]) + sum([i*b*T_**(-i-1) for i, b in enumerate(bi)])**2) * exp(sum([b/T_**i for i, b in enumerate(bi)]))) # Table 4 # Reorganizated to easy use in equations ji = [0, 0.33, 1.01, 1.6, 3.6, 3.5] ni = [0.118160747229, 0.713116392079, -0.161824192067e1, -0.101365037912, -0.146629609713, 0.148287891978e-1] tau = 132.6312/T Baa = 1/10.4477*sum([n*tau**j for j, n in zip(ji, ni)]) # Eq 10 Caaa = 2/10.4477**2*(0.714140178971e-1+0.101365037912*tau**1.6) # Eq 11 prop = {} prop["Baa"] = Baa/1000 prop["Baw"] = Baw prop["Bww"] = Bww/1000 prop["Caaa"] = Caaa/1e6 prop["Caaw"] = Caaw prop["Caww"] = Caww prop["Cwww"] = Cwww/1e6 prop["Bawt"] = Bawt prop["Bawtt"] = Bawtt prop["Caawt"] = Caawt prop["Caawtt"] = Caawtt prop["Cawwt"] = Cawwt prop["Cawwtt"] = Cawwtt return prop
Virial equations for humid air Parameters ---------- T : float Temperature [K] Returns ------- prop : dict Dictionary with critical coefficient: * Baa: Second virial coefficient of dry air, [m³/mol] * Baw: Second air-water cross virial coefficient, [m³/mol] * Bww: Second virial coefficient of water, [m³/mol] * Caaa: Third virial coefficient of dry air, [m⁶/mol] * Caaw: Third air-water cross virial coefficient, [m⁶/mol] * Caww: Third air-water cross virial coefficient, [m⁶/mol] * Cwww: Third virial coefficient of dry air, [m⁶/mol] * Bawt: dBaw/dT, [m³/molK] * Bawtt: d²Baw/dT², [m³/molK²] * Caawt: dCaaw/dT, [m⁶/molK] * Caawtt: d²Caaw/dT², [m⁶/molK²] * Cawwt: dCaww/dT, [m⁶/molK] * Cawwtt: d²Caww/dT², [m⁶/molK²] Notes ------ Raise :class:`Warning` if T isn't in range of validity: * Baa: 60 ≤ T ≤ 2000 * Baw: 130 ≤ T ≤ 2000 * Bww: 130 ≤ T ≤ 1273 * Caaa: 60 ≤ T ≤ 2000 * Caaw: 193 ≤ T ≤ 493 * Caww: 173 ≤ T ≤ 473 * Cwww: 130 ≤ T ≤ 1273 Examples -------- >>> _virial(200)["Baa"] -3.92722567e-5 References ---------- IAPWS, Guideline on a Virial Equation for the Fugacity of H2O in Humid Air, http://www.iapws.org/relguide/VirialFugacity.html IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 10, http://www.iapws.org/relguide/SeaAir.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/humidAir.py#L32-L198
jjgomera/iapws
iapws/humidAir.py
_fugacity
def _fugacity(T, P, x): """Fugacity equation for humid air Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] x : float Mole fraction of water-vapor, [-] Returns ------- fv : float fugacity coefficient, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in range of validity: * 193 ≤ T ≤ 473 * 0 ≤ P ≤ 5 * 0 ≤ x ≤ 1 Really the xmax is the xsaturation but isn't implemented Examples -------- >>> _fugacity(300, 1, 0.1) 0.0884061686 References ---------- IAPWS, Guideline on a Virial Equation for the Fugacity of H2O in Humid Air, http://www.iapws.org/relguide/VirialFugacity.html """ # Check input parameters if T < 193 or T > 473 or P < 0 or P > 5 or x < 0 or x > 1: raise(NotImplementedError("Input not in range of validity")) R = 8.314462 # J/molK # Virial coefficients vir = _virial(T) # Eq 3 beta = x*(2-x)*vir["Bww"]+(1-x)**2*(2*vir["Baw"]-vir["Baa"]) # Eq 4 gamma = x**2*(3-2*x)*vir["Cwww"] + \ (1-x)**2*(6*x*vir["Caww"]+3*(1-2*x)*vir["Caaw"]-2*(1-x)*vir["Caaa"]) +\ (x**2*vir["Bww"]+2*x*(1-x)*vir["Baw"]+(1-x)**2*vir["Baa"]) * \ (x*(3*x-4)*vir["Bww"]+2*(1-x)*(3*x-2)*vir["Baw"]+3*(1-x)**2*vir["Baa"]) # Eq 2 fv = x*P*exp(beta*P*1e6/R/T+0.5*gamma*(P*1e6/R/T)**2) return fv
python
def _fugacity(T, P, x): """Fugacity equation for humid air Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] x : float Mole fraction of water-vapor, [-] Returns ------- fv : float fugacity coefficient, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in range of validity: * 193 ≤ T ≤ 473 * 0 ≤ P ≤ 5 * 0 ≤ x ≤ 1 Really the xmax is the xsaturation but isn't implemented Examples -------- >>> _fugacity(300, 1, 0.1) 0.0884061686 References ---------- IAPWS, Guideline on a Virial Equation for the Fugacity of H2O in Humid Air, http://www.iapws.org/relguide/VirialFugacity.html """ # Check input parameters if T < 193 or T > 473 or P < 0 or P > 5 or x < 0 or x > 1: raise(NotImplementedError("Input not in range of validity")) R = 8.314462 # J/molK # Virial coefficients vir = _virial(T) # Eq 3 beta = x*(2-x)*vir["Bww"]+(1-x)**2*(2*vir["Baw"]-vir["Baa"]) # Eq 4 gamma = x**2*(3-2*x)*vir["Cwww"] + \ (1-x)**2*(6*x*vir["Caww"]+3*(1-2*x)*vir["Caaw"]-2*(1-x)*vir["Caaa"]) +\ (x**2*vir["Bww"]+2*x*(1-x)*vir["Baw"]+(1-x)**2*vir["Baa"]) * \ (x*(3*x-4)*vir["Bww"]+2*(1-x)*(3*x-2)*vir["Baw"]+3*(1-x)**2*vir["Baa"]) # Eq 2 fv = x*P*exp(beta*P*1e6/R/T+0.5*gamma*(P*1e6/R/T)**2) return fv
Fugacity equation for humid air Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] x : float Mole fraction of water-vapor, [-] Returns ------- fv : float fugacity coefficient, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in range of validity: * 193 ≤ T ≤ 473 * 0 ≤ P ≤ 5 * 0 ≤ x ≤ 1 Really the xmax is the xsaturation but isn't implemented Examples -------- >>> _fugacity(300, 1, 0.1) 0.0884061686 References ---------- IAPWS, Guideline on a Virial Equation for the Fugacity of H2O in Humid Air, http://www.iapws.org/relguide/VirialFugacity.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/humidAir.py#L201-L258
jjgomera/iapws
iapws/humidAir.py
MEoSBlend._bubbleP
def _bubbleP(cls, T): """Using ancillary equation return the pressure of bubble point""" c = cls._blend["bubble"] Tj = cls._blend["Tj"] Pj = cls._blend["Pj"] Tita = 1-T/Tj suma = 0 for i, n in zip(c["i"], c["n"]): suma += n*Tita**(i/2.) P = Pj*exp(Tj/T*suma) return P
python
def _bubbleP(cls, T): """Using ancillary equation return the pressure of bubble point""" c = cls._blend["bubble"] Tj = cls._blend["Tj"] Pj = cls._blend["Pj"] Tita = 1-T/Tj suma = 0 for i, n in zip(c["i"], c["n"]): suma += n*Tita**(i/2.) P = Pj*exp(Tj/T*suma) return P
Using ancillary equation return the pressure of bubble point
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/humidAir.py#L279-L290
jjgomera/iapws
iapws/humidAir.py
HumidAir.calculable
def calculable(self): """Check if inputs are enough to define state""" self._mode = "" if self.kwargs["T"] and self.kwargs["P"]: self._mode = "TP" elif self.kwargs["T"] and self.kwargs["rho"]: self._mode = "Trho" elif self.kwargs["P"] and self.kwargs["rho"]: self._mode = "Prho" # Composition definition self._composition = "" if self.kwargs["A"] is not None: self._composition = "A" elif self.kwargs["xa"] is not None: self._composition = "xa" return bool(self._mode) and bool(self._composition)
python
def calculable(self): """Check if inputs are enough to define state""" self._mode = "" if self.kwargs["T"] and self.kwargs["P"]: self._mode = "TP" elif self.kwargs["T"] and self.kwargs["rho"]: self._mode = "Trho" elif self.kwargs["P"] and self.kwargs["rho"]: self._mode = "Prho" # Composition definition self._composition = "" if self.kwargs["A"] is not None: self._composition = "A" elif self.kwargs["xa"] is not None: self._composition = "xa" return bool(self._mode) and bool(self._composition)
Check if inputs are enough to define state
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/humidAir.py#L643-L660
jjgomera/iapws
iapws/humidAir.py
HumidAir.calculo
def calculo(self): """Calculate procedure""" T = self.kwargs["T"] rho = self.kwargs["rho"] P = self.kwargs["P"] # Composition alternate definition if self._composition == "A": A = self.kwargs["A"] elif self._composition == "xa": xa = self.kwargs["xa"] A = xa/(1-(1-xa)*(1-Mw/Ma)) # Thermodynamic definition if self._mode == "TP": def f(rho): fav = self._fav(T, rho, A) return rho**2*fav["fird"]/1000-P rho = fsolve(f, 1)[0] elif self._mode == "Prho": def f(T): fav = self._fav(T, rho, A) return rho**2*fav["fird"]/1000-P T = fsolve(f, 300)[0] # General calculation procedure fav = self._fav(T, rho, A) # Common thermodynamic properties prop = self._prop(T, rho, fav) self.T = T self.rho = rho self.v = 1/rho self.P = prop["P"] self.s = prop["s"] self.cp = prop["cp"] self.h = prop["h"] self.g = prop["g"] self.u = self.h-self.P*1000*self.v self.alfav = prop["alfav"] self.betas = prop["betas"] self.xkappa = prop["xkappa"] self.ks = prop["ks"] self.w = prop["w"] # Coligative properties coligative = self._coligative(rho, A, fav) self.A = A self.W = 1-A self.mu = coligative["mu"] self.muw = coligative["muw"] self.M = coligative["M"] self.HR = coligative["HR"] self.xa = coligative["xa"] self.xw = coligative["xw"] self.Pv = (1-self.xa)*self.P # Saturation related properties A_sat = self._eq(self.T, self.P) self.xa_sat = A_sat*Mw/Ma/(1-A_sat*(1-Mw/Ma)) self.RH = (1-self.xa)/(1-self.xa_sat)
python
def calculo(self): """Calculate procedure""" T = self.kwargs["T"] rho = self.kwargs["rho"] P = self.kwargs["P"] # Composition alternate definition if self._composition == "A": A = self.kwargs["A"] elif self._composition == "xa": xa = self.kwargs["xa"] A = xa/(1-(1-xa)*(1-Mw/Ma)) # Thermodynamic definition if self._mode == "TP": def f(rho): fav = self._fav(T, rho, A) return rho**2*fav["fird"]/1000-P rho = fsolve(f, 1)[0] elif self._mode == "Prho": def f(T): fav = self._fav(T, rho, A) return rho**2*fav["fird"]/1000-P T = fsolve(f, 300)[0] # General calculation procedure fav = self._fav(T, rho, A) # Common thermodynamic properties prop = self._prop(T, rho, fav) self.T = T self.rho = rho self.v = 1/rho self.P = prop["P"] self.s = prop["s"] self.cp = prop["cp"] self.h = prop["h"] self.g = prop["g"] self.u = self.h-self.P*1000*self.v self.alfav = prop["alfav"] self.betas = prop["betas"] self.xkappa = prop["xkappa"] self.ks = prop["ks"] self.w = prop["w"] # Coligative properties coligative = self._coligative(rho, A, fav) self.A = A self.W = 1-A self.mu = coligative["mu"] self.muw = coligative["muw"] self.M = coligative["M"] self.HR = coligative["HR"] self.xa = coligative["xa"] self.xw = coligative["xw"] self.Pv = (1-self.xa)*self.P # Saturation related properties A_sat = self._eq(self.T, self.P) self.xa_sat = A_sat*Mw/Ma/(1-A_sat*(1-Mw/Ma)) self.RH = (1-self.xa)/(1-self.xa_sat)
Calculate procedure
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/humidAir.py#L662-L722
jjgomera/iapws
iapws/humidAir.py
HumidAir._eq
def _eq(self, T, P): """Procedure for calculate the composition in saturation state Parameters ---------- T : float Temperature [K] P : float Pressure [MPa] Returns ------- Asat : float Saturation mass fraction of dry air in humid air [kg/kg] """ if T <= 273.16: ice = _Ice(T, P) gw = ice["g"] else: water = IAPWS95(T=T, P=P) gw = water.g def f(parr): rho, a = parr if a > 1: a = 1 fa = self._fav(T, rho, a) muw = fa["fir"]+rho*fa["fird"]-a*fa["fira"] return gw-muw, rho**2*fa["fird"]/1000-P rinput = fsolve(f, [1, 0.95], full_output=True) Asat = rinput[0][1] return Asat
python
def _eq(self, T, P): """Procedure for calculate the composition in saturation state Parameters ---------- T : float Temperature [K] P : float Pressure [MPa] Returns ------- Asat : float Saturation mass fraction of dry air in humid air [kg/kg] """ if T <= 273.16: ice = _Ice(T, P) gw = ice["g"] else: water = IAPWS95(T=T, P=P) gw = water.g def f(parr): rho, a = parr if a > 1: a = 1 fa = self._fav(T, rho, a) muw = fa["fir"]+rho*fa["fird"]-a*fa["fira"] return gw-muw, rho**2*fa["fird"]/1000-P rinput = fsolve(f, [1, 0.95], full_output=True) Asat = rinput[0][1] return Asat
Procedure for calculate the composition in saturation state Parameters ---------- T : float Temperature [K] P : float Pressure [MPa] Returns ------- Asat : float Saturation mass fraction of dry air in humid air [kg/kg]
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/humidAir.py#L729-L761
jjgomera/iapws
iapws/humidAir.py
HumidAir._prop
def _prop(self, T, rho, fav): """Thermodynamic properties of humid air Parameters ---------- T : float Temperature, [K] rho : float Density, [kg/m³] fav : dict dictionary with helmholtz energy and derivatives Returns ------- prop : dict Dictionary with thermodynamic properties of humid air: * P: Pressure, [MPa] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * h: Specific enthalpy, [kJ/kg] * g: Specific gibbs energy, [kJ/kg] * alfav: Thermal expansion coefficient, [1/K] * betas: Isentropic T-P coefficient, [K/MPa] * xkappa: Isothermal compressibility, [1/MPa] * ks: Isentropic compressibility, [1/MPa] * w: Speed of sound, [m/s] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 5, http://www.iapws.org/relguide/SeaAir.html """ prop = {} prop["P"] = rho**2*fav["fird"]/1000 # Eq T1 prop["s"] = -fav["firt"] # Eq T2 prop["cp"] = -T*fav["firtt"]+T*rho*fav["firdt"]**2/( # Eq T3 2*fav["fird"]+rho*fav["firdd"]) prop["h"] = fav["fir"]-T*fav["firt"]+rho*fav["fird"] # Eq T4 prop["g"] = fav["fir"]+rho*fav["fird"] # Eq T5 prop["alfav"] = fav["firdt"]/(2*fav["fird"]+rho*fav["firdd"]) # Eq T6 prop["betas"] = 1000*fav["firdt"]/rho/( # Eq T7 rho*fav["firdt"]**2-fav["firtt"]*(2*fav["fird"]+rho*fav["firdd"])) prop["xkappa"] = 1e3/(rho**2*(2*fav["fird"]+rho*fav["firdd"])) # Eq T8 prop["ks"] = 1000*fav["firtt"]/rho**2/( # Eq T9 fav["firtt"]*(2*fav["fird"]+rho*fav["firdd"])-rho*fav["firdt"]**2) prop["w"] = (rho**2*1000*(fav["firtt"]*fav["firdd"]-fav["firdt"]**2) / fav["firtt"]+2*rho*fav["fird"]*1000)**0.5 # Eq T10 return prop
python
def _prop(self, T, rho, fav): """Thermodynamic properties of humid air Parameters ---------- T : float Temperature, [K] rho : float Density, [kg/m³] fav : dict dictionary with helmholtz energy and derivatives Returns ------- prop : dict Dictionary with thermodynamic properties of humid air: * P: Pressure, [MPa] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * h: Specific enthalpy, [kJ/kg] * g: Specific gibbs energy, [kJ/kg] * alfav: Thermal expansion coefficient, [1/K] * betas: Isentropic T-P coefficient, [K/MPa] * xkappa: Isothermal compressibility, [1/MPa] * ks: Isentropic compressibility, [1/MPa] * w: Speed of sound, [m/s] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 5, http://www.iapws.org/relguide/SeaAir.html """ prop = {} prop["P"] = rho**2*fav["fird"]/1000 # Eq T1 prop["s"] = -fav["firt"] # Eq T2 prop["cp"] = -T*fav["firtt"]+T*rho*fav["firdt"]**2/( # Eq T3 2*fav["fird"]+rho*fav["firdd"]) prop["h"] = fav["fir"]-T*fav["firt"]+rho*fav["fird"] # Eq T4 prop["g"] = fav["fir"]+rho*fav["fird"] # Eq T5 prop["alfav"] = fav["firdt"]/(2*fav["fird"]+rho*fav["firdd"]) # Eq T6 prop["betas"] = 1000*fav["firdt"]/rho/( # Eq T7 rho*fav["firdt"]**2-fav["firtt"]*(2*fav["fird"]+rho*fav["firdd"])) prop["xkappa"] = 1e3/(rho**2*(2*fav["fird"]+rho*fav["firdd"])) # Eq T8 prop["ks"] = 1000*fav["firtt"]/rho**2/( # Eq T9 fav["firtt"]*(2*fav["fird"]+rho*fav["firdd"])-rho*fav["firdt"]**2) prop["w"] = (rho**2*1000*(fav["firtt"]*fav["firdd"]-fav["firdt"]**2) / fav["firtt"]+2*rho*fav["fird"]*1000)**0.5 # Eq T10 return prop
Thermodynamic properties of humid air Parameters ---------- T : float Temperature, [K] rho : float Density, [kg/m³] fav : dict dictionary with helmholtz energy and derivatives Returns ------- prop : dict Dictionary with thermodynamic properties of humid air: * P: Pressure, [MPa] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * h: Specific enthalpy, [kJ/kg] * g: Specific gibbs energy, [kJ/kg] * alfav: Thermal expansion coefficient, [1/K] * betas: Isentropic T-P coefficient, [K/MPa] * xkappa: Isothermal compressibility, [1/MPa] * ks: Isentropic compressibility, [1/MPa] * w: Speed of sound, [m/s] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 5, http://www.iapws.org/relguide/SeaAir.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/humidAir.py#L763-L813
jjgomera/iapws
iapws/humidAir.py
HumidAir._coligative
def _coligative(self, rho, A, fav): """Miscelaneous properties of humid air Parameters ---------- rho : float Density, [kg/m³] A : float Mass fraction of dry air in humid air, [kg/kg] fav : dict dictionary with helmholtz energy and derivatives Returns ------- prop : dict Dictionary with calculated properties: * mu: Relative chemical potential, [kJ/kg] * muw: Chemical potential of water, [kJ/kg] * M: Molar mass of humid air, [g/mol] * HR: Humidity ratio, [-] * xa: Mole fraction of dry air, [-] * xw: Mole fraction of water, [-] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 12, http://www.iapws.org/relguide/SeaAir.html """ prop = {} prop["mu"] = fav["fira"] prop["muw"] = fav["fir"]+rho*fav["fird"]-A*fav["fira"] prop["M"] = 1/((1-A)/Mw+A/Ma) prop["HR"] = 1/A-1 prop["xa"] = A*Mw/Ma/(1-A*(1-Mw/Ma)) prop["xw"] = 1-prop["xa"] return prop
python
def _coligative(self, rho, A, fav): """Miscelaneous properties of humid air Parameters ---------- rho : float Density, [kg/m³] A : float Mass fraction of dry air in humid air, [kg/kg] fav : dict dictionary with helmholtz energy and derivatives Returns ------- prop : dict Dictionary with calculated properties: * mu: Relative chemical potential, [kJ/kg] * muw: Chemical potential of water, [kJ/kg] * M: Molar mass of humid air, [g/mol] * HR: Humidity ratio, [-] * xa: Mole fraction of dry air, [-] * xw: Mole fraction of water, [-] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 12, http://www.iapws.org/relguide/SeaAir.html """ prop = {} prop["mu"] = fav["fira"] prop["muw"] = fav["fir"]+rho*fav["fird"]-A*fav["fira"] prop["M"] = 1/((1-A)/Mw+A/Ma) prop["HR"] = 1/A-1 prop["xa"] = A*Mw/Ma/(1-A*(1-Mw/Ma)) prop["xw"] = 1-prop["xa"] return prop
Miscelaneous properties of humid air Parameters ---------- rho : float Density, [kg/m³] A : float Mass fraction of dry air in humid air, [kg/kg] fav : dict dictionary with helmholtz energy and derivatives Returns ------- prop : dict Dictionary with calculated properties: * mu: Relative chemical potential, [kJ/kg] * muw: Chemical potential of water, [kJ/kg] * M: Molar mass of humid air, [g/mol] * HR: Humidity ratio, [-] * xa: Mole fraction of dry air, [-] * xw: Mole fraction of water, [-] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 12, http://www.iapws.org/relguide/SeaAir.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/humidAir.py#L815-L853
jjgomera/iapws
iapws/humidAir.py
HumidAir._fav
def _fav(self, T, rho, A): r"""Specific Helmholtz energy of humid air and derivatives Parameters ---------- T : float Temperature, [K] rho : float Density, [kg/m³] A : float Mass fraction of dry air in humid air, [kg/kg] Returns ------- prop : dict Dictionary with helmholtz energy and derivatives: * fir, [kJ/kg] * fira: :math:`\left.\frac{\partial f_{av}}{\partial A}\right|_{T,\rho}`, [kJ/kg] * firt: :math:`\left.\frac{\partial f_{av}}{\partial T}\right|_{A,\rho}`, [kJ/kgK] * fird: :math:`\left.\frac{\partial f_{av}}{\partial \rho}\right|_{A,T}`, [kJ/m³kg²] * firaa: :math:`\left.\frac{\partial^2 f_{av}}{\partial A^2}\right|_{T, \rho}`, [kJ/kg] * firat: :math:`\left.\frac{\partial^2 f_{av}}{\partial A \partial T}\right|_{\rho}`, [kJ/kgK] * firad: :math:`\left.\frac{\partial^2 f_{av}}{\partial A \partial \rho}\right|_T`, [kJ/m³kg²] * firtt: :math:`\left.\frac{\partial^2 f_{av}}{\partial T^2}\right|_{A, \rho}`, [kJ/kgK²] * firdt: :math:`\left.\frac{\partial^2 f_{av}}{\partial \rho \partial T}\right|_A`, [kJ/m³kg²K] * firdd: :math:`\left.\frac{\partial^2 f_{av}}{\partial \rho^2}\right|_{A, T}`, [kJ/m⁶kg³] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 6, http://www.iapws.org/relguide/SeaAir.html """ water = IAPWS95() rhov = (1-A)*rho fv = water._derivDimensional(rhov, T) air = Air() rhoa = A*rho fa = air._derivDimensional(rhoa, T) fmix = self._fmix(T, rho, A) prop = {} # Eq T11 prop["fir"] = (1-A)*fv["fir"] + A*fa["fir"] + fmix["fir"] # Eq T12 prop["fira"] = -fv["fir"]-rhov*fv["fird"]+fa["fir"] + \ rhoa*fa["fird"]+fmix["fira"] # Eq T13 prop["firt"] = (1-A)*fv["firt"]+A*fa["firt"]+fmix["firt"] # Eq T14 prop["fird"] = (1-A)**2*fv["fird"]+A**2*fa["fird"]+fmix["fird"] # Eq T15 prop["firaa"] = rho*(2*fv["fird"]+rhov*fv["firdd"] + 2*fa["fird"]+rhoa*fa["firdd"])+fmix["firaa"] # Eq T16 prop["firat"] = -fv["firt"]-rhov*fv["firdt"]+fa["firt"] + \ rhoa*fa["firdt"]+fmix["firat"] # Eq T17 prop["firad"] = -(1-A)*(2*fv["fird"]+rhov*fv["firdd"]) + \ A*(2*fa["fird"]+rhoa*fa["firdd"])+fmix["firad"] # Eq T18 prop["firtt"] = (1-A)*fv["firtt"]+A*fa["firtt"]+fmix["firtt"] # Eq T19 prop["firdt"] = (1-A)**2*fv["firdt"]+A**2*fa["firdt"]+fmix["firdt"] # Eq T20 prop["firdd"] = (1-A)**3*fv["firdd"]+A**3*fa["firdd"]+fmix["firdd"] return prop
python
def _fav(self, T, rho, A): r"""Specific Helmholtz energy of humid air and derivatives Parameters ---------- T : float Temperature, [K] rho : float Density, [kg/m³] A : float Mass fraction of dry air in humid air, [kg/kg] Returns ------- prop : dict Dictionary with helmholtz energy and derivatives: * fir, [kJ/kg] * fira: :math:`\left.\frac{\partial f_{av}}{\partial A}\right|_{T,\rho}`, [kJ/kg] * firt: :math:`\left.\frac{\partial f_{av}}{\partial T}\right|_{A,\rho}`, [kJ/kgK] * fird: :math:`\left.\frac{\partial f_{av}}{\partial \rho}\right|_{A,T}`, [kJ/m³kg²] * firaa: :math:`\left.\frac{\partial^2 f_{av}}{\partial A^2}\right|_{T, \rho}`, [kJ/kg] * firat: :math:`\left.\frac{\partial^2 f_{av}}{\partial A \partial T}\right|_{\rho}`, [kJ/kgK] * firad: :math:`\left.\frac{\partial^2 f_{av}}{\partial A \partial \rho}\right|_T`, [kJ/m³kg²] * firtt: :math:`\left.\frac{\partial^2 f_{av}}{\partial T^2}\right|_{A, \rho}`, [kJ/kgK²] * firdt: :math:`\left.\frac{\partial^2 f_{av}}{\partial \rho \partial T}\right|_A`, [kJ/m³kg²K] * firdd: :math:`\left.\frac{\partial^2 f_{av}}{\partial \rho^2}\right|_{A, T}`, [kJ/m⁶kg³] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 6, http://www.iapws.org/relguide/SeaAir.html """ water = IAPWS95() rhov = (1-A)*rho fv = water._derivDimensional(rhov, T) air = Air() rhoa = A*rho fa = air._derivDimensional(rhoa, T) fmix = self._fmix(T, rho, A) prop = {} # Eq T11 prop["fir"] = (1-A)*fv["fir"] + A*fa["fir"] + fmix["fir"] # Eq T12 prop["fira"] = -fv["fir"]-rhov*fv["fird"]+fa["fir"] + \ rhoa*fa["fird"]+fmix["fira"] # Eq T13 prop["firt"] = (1-A)*fv["firt"]+A*fa["firt"]+fmix["firt"] # Eq T14 prop["fird"] = (1-A)**2*fv["fird"]+A**2*fa["fird"]+fmix["fird"] # Eq T15 prop["firaa"] = rho*(2*fv["fird"]+rhov*fv["firdd"] + 2*fa["fird"]+rhoa*fa["firdd"])+fmix["firaa"] # Eq T16 prop["firat"] = -fv["firt"]-rhov*fv["firdt"]+fa["firt"] + \ rhoa*fa["firdt"]+fmix["firat"] # Eq T17 prop["firad"] = -(1-A)*(2*fv["fird"]+rhov*fv["firdd"]) + \ A*(2*fa["fird"]+rhoa*fa["firdd"])+fmix["firad"] # Eq T18 prop["firtt"] = (1-A)*fv["firtt"]+A*fa["firtt"]+fmix["firtt"] # Eq T19 prop["firdt"] = (1-A)**2*fv["firdt"]+A**2*fa["firdt"]+fmix["firdt"] # Eq T20 prop["firdd"] = (1-A)**3*fv["firdd"]+A**3*fa["firdd"]+fmix["firdd"] return prop
r"""Specific Helmholtz energy of humid air and derivatives Parameters ---------- T : float Temperature, [K] rho : float Density, [kg/m³] A : float Mass fraction of dry air in humid air, [kg/kg] Returns ------- prop : dict Dictionary with helmholtz energy and derivatives: * fir, [kJ/kg] * fira: :math:`\left.\frac{\partial f_{av}}{\partial A}\right|_{T,\rho}`, [kJ/kg] * firt: :math:`\left.\frac{\partial f_{av}}{\partial T}\right|_{A,\rho}`, [kJ/kgK] * fird: :math:`\left.\frac{\partial f_{av}}{\partial \rho}\right|_{A,T}`, [kJ/m³kg²] * firaa: :math:`\left.\frac{\partial^2 f_{av}}{\partial A^2}\right|_{T, \rho}`, [kJ/kg] * firat: :math:`\left.\frac{\partial^2 f_{av}}{\partial A \partial T}\right|_{\rho}`, [kJ/kgK] * firad: :math:`\left.\frac{\partial^2 f_{av}}{\partial A \partial \rho}\right|_T`, [kJ/m³kg²] * firtt: :math:`\left.\frac{\partial^2 f_{av}}{\partial T^2}\right|_{A, \rho}`, [kJ/kgK²] * firdt: :math:`\left.\frac{\partial^2 f_{av}}{\partial \rho \partial T}\right|_A`, [kJ/m³kg²K] * firdd: :math:`\left.\frac{\partial^2 f_{av}}{\partial \rho^2}\right|_{A, T}`, [kJ/m⁶kg³] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 6, http://www.iapws.org/relguide/SeaAir.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/humidAir.py#L855-L925
jjgomera/iapws
iapws/humidAir.py
HumidAir._fmix
def _fmix(self, T, rho, A): r"""Specific Helmholtz energy of air-water interaction Parameters ---------- T : float Temperature, [K] rho : float Density, [kg/m³] A : float Mass fraction of dry air in humid air, [kg/kg] Returns ------- prop : dict Dictionary with helmholtz energy and derivatives: * fir, [kJ/kg] * fira: :math:`\left.\frac{\partial f_{mix}}{\partial A}\right|_{T,\rho}`, [kJ/kg] * firt: :math:`\left.\frac{\partial f_{mix}}{\partial T}\right|_{A,\rho}`, [kJ/kgK] * fird: :math:`\left.\frac{\partial f_{mix}}{\partial \rho}\right|_{A,T}`, [kJ/m³kg²] * firaa: :math:`\left.\frac{\partial^2 f_{mix}}{\partial A^2}\right|_{T, \rho}`, [kJ/kg] * firat: :math:`\left.\frac{\partial^2 f_{mix}}{\partial A \partial T}\right|_{\rho}`, [kJ/kgK] * firad: :math:`\left.\frac{\partial^2 f_{mix}}{\partial A \partial \rho}\right|_T`, [kJ/m³kg²] * firtt: :math:`\left.\frac{\partial^2 f_{mix}}{\partial T^2}\right|_{A, \rho}`, [kJ/kgK²] * firdt: :math:`\left.\frac{\partial^2 f_{mix}}{\partial \rho \partial T}\right|_A`, [kJ/m³kg²K] * firdd: :math:`\left.\frac{\partial^2 f_{mix}}{\partial \rho^2}\right|_{A, T}`, [kJ/m⁶kg³] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 10, http://www.iapws.org/relguide/SeaAir.html """ Ma = Air.M/1000 Mw = IAPWS95.M/1000 vir = _virial(T) Baw = vir["Baw"] Bawt = vir["Bawt"] Bawtt = vir["Bawtt"] Caaw = vir["Caaw"] Caawt = vir["Caawt"] Caawtt = vir["Caawtt"] Caww = vir["Caww"] Cawwt = vir["Cawwt"] Cawwtt = vir["Cawwtt"] # Eq T45 f = 2*A*(1-A)*rho*R*T/Ma/Mw*(Baw+3*rho/4*(A/Ma*Caaw+(1-A)/Mw*Caww)) # Eq T46 fa = 2*rho*R*T/Ma/Mw*((1-2*A)*Baw+3*rho/4*( A*(2-3*A)/Ma*Caaw+(1-A)*(1-3*A)/Mw*Caww)) # Eq T47 ft = 2*A*(1-A)*rho*R/Ma/Mw*( Baw+T*Bawt+3*rho/4*(A/Ma*(Caaw+T*Caawt)+(1-A)/Mw*(Caww+T*Cawwt))) # Eq T48 fd = A*(1-A)*R*T/Ma/Mw*(2*Baw+3*rho*(A/Ma*Caaw+(1-A)/Mw*Caww)) # Eq T49 faa = rho*R*T/Ma/Mw*(-4*Baw+3*rho*((1-3*A)/Ma*Caaw-(2-3*A)/Mw*Caww)) # Eq T50 fat = 2*rho*R/Ma/Mw*(1-2*A)*(Baw+T*Bawt)+3*rho**2*R/2/Ma/Mw*( A*(2-3*A)/Ma*(Caaw+T*Caawt)+(1-A)*(1-3*A)/Mw*(Caww+T*Cawwt)) # Eq T51 fad = 2*R*T/Ma/Mw*((1-2*A)*Baw+3/2*rho*( A*(2-3*A)/Ma*Caaw+(1-A)*(1-3*A)/Mw*Caww)) # Eq T52 ftt = 2*A*(1-A)*rho*R/Ma/Mw*(2*Bawt+T*Bawtt+3*rho/4*( A/Ma*(2*Caawt+T*Caawtt)+(1-A)/Mw*(2*Cawwt+T*Cawwtt))) # Eq T53 ftd = 2*A*(1-A)*R/Ma/Mw*(Baw+T*Bawt+3*rho/2*( A/Ma*(Caaw+T*Caawt)+(1-A)/Mw*(Caww+T*Cawwt))) # Eq T54 fdd = 3*A*(1-A)*R*T/Ma/Mw*(A/Ma*Caaw+(1-A)/Mw*Caww) prop = {} prop["fir"] = f/1000 prop["fira"] = fa/1000 prop["firt"] = ft/1000 prop["fird"] = fd/1000 prop["firaa"] = faa/1000 prop["firat"] = fat/1000 prop["firad"] = fad/1000 prop["firtt"] = ftt/1000 prop["firdt"] = ftd/1000 prop["firdd"] = fdd/1000 return prop
python
def _fmix(self, T, rho, A): r"""Specific Helmholtz energy of air-water interaction Parameters ---------- T : float Temperature, [K] rho : float Density, [kg/m³] A : float Mass fraction of dry air in humid air, [kg/kg] Returns ------- prop : dict Dictionary with helmholtz energy and derivatives: * fir, [kJ/kg] * fira: :math:`\left.\frac{\partial f_{mix}}{\partial A}\right|_{T,\rho}`, [kJ/kg] * firt: :math:`\left.\frac{\partial f_{mix}}{\partial T}\right|_{A,\rho}`, [kJ/kgK] * fird: :math:`\left.\frac{\partial f_{mix}}{\partial \rho}\right|_{A,T}`, [kJ/m³kg²] * firaa: :math:`\left.\frac{\partial^2 f_{mix}}{\partial A^2}\right|_{T, \rho}`, [kJ/kg] * firat: :math:`\left.\frac{\partial^2 f_{mix}}{\partial A \partial T}\right|_{\rho}`, [kJ/kgK] * firad: :math:`\left.\frac{\partial^2 f_{mix}}{\partial A \partial \rho}\right|_T`, [kJ/m³kg²] * firtt: :math:`\left.\frac{\partial^2 f_{mix}}{\partial T^2}\right|_{A, \rho}`, [kJ/kgK²] * firdt: :math:`\left.\frac{\partial^2 f_{mix}}{\partial \rho \partial T}\right|_A`, [kJ/m³kg²K] * firdd: :math:`\left.\frac{\partial^2 f_{mix}}{\partial \rho^2}\right|_{A, T}`, [kJ/m⁶kg³] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 10, http://www.iapws.org/relguide/SeaAir.html """ Ma = Air.M/1000 Mw = IAPWS95.M/1000 vir = _virial(T) Baw = vir["Baw"] Bawt = vir["Bawt"] Bawtt = vir["Bawtt"] Caaw = vir["Caaw"] Caawt = vir["Caawt"] Caawtt = vir["Caawtt"] Caww = vir["Caww"] Cawwt = vir["Cawwt"] Cawwtt = vir["Cawwtt"] # Eq T45 f = 2*A*(1-A)*rho*R*T/Ma/Mw*(Baw+3*rho/4*(A/Ma*Caaw+(1-A)/Mw*Caww)) # Eq T46 fa = 2*rho*R*T/Ma/Mw*((1-2*A)*Baw+3*rho/4*( A*(2-3*A)/Ma*Caaw+(1-A)*(1-3*A)/Mw*Caww)) # Eq T47 ft = 2*A*(1-A)*rho*R/Ma/Mw*( Baw+T*Bawt+3*rho/4*(A/Ma*(Caaw+T*Caawt)+(1-A)/Mw*(Caww+T*Cawwt))) # Eq T48 fd = A*(1-A)*R*T/Ma/Mw*(2*Baw+3*rho*(A/Ma*Caaw+(1-A)/Mw*Caww)) # Eq T49 faa = rho*R*T/Ma/Mw*(-4*Baw+3*rho*((1-3*A)/Ma*Caaw-(2-3*A)/Mw*Caww)) # Eq T50 fat = 2*rho*R/Ma/Mw*(1-2*A)*(Baw+T*Bawt)+3*rho**2*R/2/Ma/Mw*( A*(2-3*A)/Ma*(Caaw+T*Caawt)+(1-A)*(1-3*A)/Mw*(Caww+T*Cawwt)) # Eq T51 fad = 2*R*T/Ma/Mw*((1-2*A)*Baw+3/2*rho*( A*(2-3*A)/Ma*Caaw+(1-A)*(1-3*A)/Mw*Caww)) # Eq T52 ftt = 2*A*(1-A)*rho*R/Ma/Mw*(2*Bawt+T*Bawtt+3*rho/4*( A/Ma*(2*Caawt+T*Caawtt)+(1-A)/Mw*(2*Cawwt+T*Cawwtt))) # Eq T53 ftd = 2*A*(1-A)*R/Ma/Mw*(Baw+T*Bawt+3*rho/2*( A/Ma*(Caaw+T*Caawt)+(1-A)/Mw*(Caww+T*Cawwt))) # Eq T54 fdd = 3*A*(1-A)*R*T/Ma/Mw*(A/Ma*Caaw+(1-A)/Mw*Caww) prop = {} prop["fir"] = f/1000 prop["fira"] = fa/1000 prop["firt"] = ft/1000 prop["fird"] = fd/1000 prop["firaa"] = faa/1000 prop["firat"] = fat/1000 prop["firad"] = fad/1000 prop["firtt"] = ftt/1000 prop["firdt"] = ftd/1000 prop["firdd"] = fdd/1000 return prop
r"""Specific Helmholtz energy of air-water interaction Parameters ---------- T : float Temperature, [K] rho : float Density, [kg/m³] A : float Mass fraction of dry air in humid air, [kg/kg] Returns ------- prop : dict Dictionary with helmholtz energy and derivatives: * fir, [kJ/kg] * fira: :math:`\left.\frac{\partial f_{mix}}{\partial A}\right|_{T,\rho}`, [kJ/kg] * firt: :math:`\left.\frac{\partial f_{mix}}{\partial T}\right|_{A,\rho}`, [kJ/kgK] * fird: :math:`\left.\frac{\partial f_{mix}}{\partial \rho}\right|_{A,T}`, [kJ/m³kg²] * firaa: :math:`\left.\frac{\partial^2 f_{mix}}{\partial A^2}\right|_{T, \rho}`, [kJ/kg] * firat: :math:`\left.\frac{\partial^2 f_{mix}}{\partial A \partial T}\right|_{\rho}`, [kJ/kgK] * firad: :math:`\left.\frac{\partial^2 f_{mix}}{\partial A \partial \rho}\right|_T`, [kJ/m³kg²] * firtt: :math:`\left.\frac{\partial^2 f_{mix}}{\partial T^2}\right|_{A, \rho}`, [kJ/kgK²] * firdt: :math:`\left.\frac{\partial^2 f_{mix}}{\partial \rho \partial T}\right|_A`, [kJ/m³kg²K] * firdd: :math:`\left.\frac{\partial^2 f_{mix}}{\partial \rho^2}\right|_{A, T}`, [kJ/m⁶kg³] References ---------- IAPWS, Guideline on an Equation of State for Humid Air in Contact with Seawater and Ice, Consistent with the IAPWS Formulation 2008 for the Thermodynamic Properties of Seawater, Table 10, http://www.iapws.org/relguide/SeaAir.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/humidAir.py#L927-L1013
jjgomera/iapws
iapws/_iapws.py
_Ice
def _Ice(T, P): """Basic state equation for Ice Ih Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties of ice. The available properties are: * rho: Density, [kg/m³] * h: Specific enthalpy, [kJ/kg] * u: Specific internal energy, [kJ/kg] * a: Specific Helmholtz energy, [kJ/kg] * g: Specific Gibbs energy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * alfav: Cubic expansion coefficient, [1/K] * beta: Pressure coefficient, [MPa/K] * xkappa: Isothermal compressibility, [1/MPa] * ks: Isentropic compressibility, [1/MPa] * gt: [∂g/∂T]P * gtt: [∂²g/∂T²]P * gp: [∂g/∂P]T * gpp: [∂²g/∂P²]T * gtp: [∂²g/∂T∂P] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * T ≤ 273.16 * P ≤ 208.566 * State below the melting and sublimation lines Examples -------- >>> st1 = _Ice(100, 100) >>> st1["rho"], st1["h"], st1["s"] 941.678203297 -483.491635676 -2.61195122589 >>> st2 = _Ice(273.152519,0.101325) >>> st2["a"], st2["u"], st2["cp"] -0.00918701567 -333.465403393 2.09671391024 >>> st3 = _Ice(273.16,611.657e-6) >>> st3["alfav"], st3["beta"], st3["xkappa"], st3["ks"] 0.000159863102566 1.35714764659 1.17793449348e-04 1.14161597779e-04 References ---------- IAPWS, Revised Release on the Equation of State 2006 for H2O Ice Ih September 2009, http://iapws.org/relguide/Ice-2009.html """ # Check input in range of validity if T > 273.16: # No Ice Ih stable warnings.warn("Metastable ice") elif P > 208.566: # Ice Ih limit upper pressure raise NotImplementedError("Incoming out of bound") elif P < Pt: Psub = _Sublimation_Pressure(T) if Psub > P: # Zone Gas warnings.warn("Metastable ice in vapor region") elif 251.165 < T: Pmel = _Melting_Pressure(T) if Pmel < P: # Zone Liquid warnings.warn("Metastable ice in liquid region") Tr = T/Tt Pr = P/Pt P0 = 101325e-6/Pt s0 = -0.332733756492168e4*1e-3 # Express in kJ/kgK gok = [-0.632020233335886e6, 0.655022213658955, -0.189369929326131e-7, 0.339746123271053e-14, -0.556464869058991e-21] r2k = [complex(-0.725974574329220e2, -0.781008427112870e2)*1e-3, complex(-0.557107698030123e-4, 0.464578634580806e-4)*1e-3, complex(0.234801409215913e-10, -0.285651142904972e-10)*1e-3] t1 = complex(0.368017112855051e-1, 0.510878114959572e-1) t2 = complex(0.337315741065416, 0.335449415919309) r1 = complex(0.447050716285388e2, 0.656876847463481e2)*1e-3 go = gop = gopp = 0 for k in range(5): go += gok[k]*1e-3*(Pr-P0)**k for k in range(1, 5): gop += gok[k]*1e-3*k/Pt*(Pr-P0)**(k-1) for k in range(2, 5): gopp += gok[k]*1e-3*k*(k-1)/Pt**2*(Pr-P0)**(k-2) r2 = r2p = 0 for k in range(3): r2 += r2k[k]*(Pr-P0)**k for k in range(1, 3): r2p += r2k[k]*k/Pt*(Pr-P0)**(k-1) r2pp = r2k[2]*2/Pt**2 c = r1*((t1-Tr)*log_c(t1-Tr)+(t1+Tr)*log_c(t1+Tr)-2*t1*log_c( t1)-Tr**2/t1)+r2*((t2-Tr)*log_c(t2-Tr)+(t2+Tr)*log_c( t2+Tr)-2*t2*log_c(t2)-Tr**2/t2) ct = r1*(-log_c(t1-Tr)+log_c(t1+Tr)-2*Tr/t1)+r2*( -log_c(t2-Tr)+log_c(t2+Tr)-2*Tr/t2) ctt = r1*(1/(t1-Tr)+1/(t1+Tr)-2/t1) + r2*(1/(t2-Tr)+1/(t2+Tr)-2/t2) cp = r2p*((t2-Tr)*log_c(t2-Tr)+(t2+Tr)*log_c( t2+Tr)-2*t2*log_c(t2)-Tr**2/t2) ctp = r2p*(-log_c(t2-Tr)+log_c(t2+Tr)-2*Tr/t2) cpp = r2pp*((t2-Tr)*log_c(t2-Tr)+(t2+Tr)*log_c( t2+Tr)-2*t2*log_c(t2)-Tr**2/t2) g = go-s0*Tt*Tr+Tt*c.real gt = -s0+ct.real gp = gop+Tt*cp.real gtt = ctt.real/Tt gtp = ctp.real gpp = gopp+Tt*cpp.real propiedades = {} propiedades["gt"] = gt propiedades["gp"] = gp propiedades["gtt"] = gtt propiedades["gpp"] = gpp propiedades["gtp"] = gtp propiedades["T"] = T propiedades["P"] = P propiedades["v"] = gp/1000 propiedades["rho"] = 1000./gp propiedades["h"] = g-T*gt propiedades["s"] = -gt propiedades["cp"] = -T*gtt propiedades["u"] = g-T*gt-P*gp propiedades["g"] = g propiedades["a"] = g-P*gp propiedades["alfav"] = gtp/gp propiedades["beta"] = -gtp/gpp propiedades["xkappa"] = -gpp/gp propiedades["ks"] = (gtp**2-gtt*gpp)/gp/gtt return propiedades
python
def _Ice(T, P): """Basic state equation for Ice Ih Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties of ice. The available properties are: * rho: Density, [kg/m³] * h: Specific enthalpy, [kJ/kg] * u: Specific internal energy, [kJ/kg] * a: Specific Helmholtz energy, [kJ/kg] * g: Specific Gibbs energy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * alfav: Cubic expansion coefficient, [1/K] * beta: Pressure coefficient, [MPa/K] * xkappa: Isothermal compressibility, [1/MPa] * ks: Isentropic compressibility, [1/MPa] * gt: [∂g/∂T]P * gtt: [∂²g/∂T²]P * gp: [∂g/∂P]T * gpp: [∂²g/∂P²]T * gtp: [∂²g/∂T∂P] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * T ≤ 273.16 * P ≤ 208.566 * State below the melting and sublimation lines Examples -------- >>> st1 = _Ice(100, 100) >>> st1["rho"], st1["h"], st1["s"] 941.678203297 -483.491635676 -2.61195122589 >>> st2 = _Ice(273.152519,0.101325) >>> st2["a"], st2["u"], st2["cp"] -0.00918701567 -333.465403393 2.09671391024 >>> st3 = _Ice(273.16,611.657e-6) >>> st3["alfav"], st3["beta"], st3["xkappa"], st3["ks"] 0.000159863102566 1.35714764659 1.17793449348e-04 1.14161597779e-04 References ---------- IAPWS, Revised Release on the Equation of State 2006 for H2O Ice Ih September 2009, http://iapws.org/relguide/Ice-2009.html """ # Check input in range of validity if T > 273.16: # No Ice Ih stable warnings.warn("Metastable ice") elif P > 208.566: # Ice Ih limit upper pressure raise NotImplementedError("Incoming out of bound") elif P < Pt: Psub = _Sublimation_Pressure(T) if Psub > P: # Zone Gas warnings.warn("Metastable ice in vapor region") elif 251.165 < T: Pmel = _Melting_Pressure(T) if Pmel < P: # Zone Liquid warnings.warn("Metastable ice in liquid region") Tr = T/Tt Pr = P/Pt P0 = 101325e-6/Pt s0 = -0.332733756492168e4*1e-3 # Express in kJ/kgK gok = [-0.632020233335886e6, 0.655022213658955, -0.189369929326131e-7, 0.339746123271053e-14, -0.556464869058991e-21] r2k = [complex(-0.725974574329220e2, -0.781008427112870e2)*1e-3, complex(-0.557107698030123e-4, 0.464578634580806e-4)*1e-3, complex(0.234801409215913e-10, -0.285651142904972e-10)*1e-3] t1 = complex(0.368017112855051e-1, 0.510878114959572e-1) t2 = complex(0.337315741065416, 0.335449415919309) r1 = complex(0.447050716285388e2, 0.656876847463481e2)*1e-3 go = gop = gopp = 0 for k in range(5): go += gok[k]*1e-3*(Pr-P0)**k for k in range(1, 5): gop += gok[k]*1e-3*k/Pt*(Pr-P0)**(k-1) for k in range(2, 5): gopp += gok[k]*1e-3*k*(k-1)/Pt**2*(Pr-P0)**(k-2) r2 = r2p = 0 for k in range(3): r2 += r2k[k]*(Pr-P0)**k for k in range(1, 3): r2p += r2k[k]*k/Pt*(Pr-P0)**(k-1) r2pp = r2k[2]*2/Pt**2 c = r1*((t1-Tr)*log_c(t1-Tr)+(t1+Tr)*log_c(t1+Tr)-2*t1*log_c( t1)-Tr**2/t1)+r2*((t2-Tr)*log_c(t2-Tr)+(t2+Tr)*log_c( t2+Tr)-2*t2*log_c(t2)-Tr**2/t2) ct = r1*(-log_c(t1-Tr)+log_c(t1+Tr)-2*Tr/t1)+r2*( -log_c(t2-Tr)+log_c(t2+Tr)-2*Tr/t2) ctt = r1*(1/(t1-Tr)+1/(t1+Tr)-2/t1) + r2*(1/(t2-Tr)+1/(t2+Tr)-2/t2) cp = r2p*((t2-Tr)*log_c(t2-Tr)+(t2+Tr)*log_c( t2+Tr)-2*t2*log_c(t2)-Tr**2/t2) ctp = r2p*(-log_c(t2-Tr)+log_c(t2+Tr)-2*Tr/t2) cpp = r2pp*((t2-Tr)*log_c(t2-Tr)+(t2+Tr)*log_c( t2+Tr)-2*t2*log_c(t2)-Tr**2/t2) g = go-s0*Tt*Tr+Tt*c.real gt = -s0+ct.real gp = gop+Tt*cp.real gtt = ctt.real/Tt gtp = ctp.real gpp = gopp+Tt*cpp.real propiedades = {} propiedades["gt"] = gt propiedades["gp"] = gp propiedades["gtt"] = gtt propiedades["gpp"] = gpp propiedades["gtp"] = gtp propiedades["T"] = T propiedades["P"] = P propiedades["v"] = gp/1000 propiedades["rho"] = 1000./gp propiedades["h"] = g-T*gt propiedades["s"] = -gt propiedades["cp"] = -T*gtt propiedades["u"] = g-T*gt-P*gp propiedades["g"] = g propiedades["a"] = g-P*gp propiedades["alfav"] = gtp/gp propiedades["beta"] = -gtp/gpp propiedades["xkappa"] = -gpp/gp propiedades["ks"] = (gtp**2-gtt*gpp)/gp/gtt return propiedades
Basic state equation for Ice Ih Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties of ice. The available properties are: * rho: Density, [kg/m³] * h: Specific enthalpy, [kJ/kg] * u: Specific internal energy, [kJ/kg] * a: Specific Helmholtz energy, [kJ/kg] * g: Specific Gibbs energy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * alfav: Cubic expansion coefficient, [1/K] * beta: Pressure coefficient, [MPa/K] * xkappa: Isothermal compressibility, [1/MPa] * ks: Isentropic compressibility, [1/MPa] * gt: [∂g/∂T]P * gtt: [∂²g/∂T²]P * gp: [∂g/∂P]T * gpp: [∂²g/∂P²]T * gtp: [∂²g/∂T∂P] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * T ≤ 273.16 * P ≤ 208.566 * State below the melting and sublimation lines Examples -------- >>> st1 = _Ice(100, 100) >>> st1["rho"], st1["h"], st1["s"] 941.678203297 -483.491635676 -2.61195122589 >>> st2 = _Ice(273.152519,0.101325) >>> st2["a"], st2["u"], st2["cp"] -0.00918701567 -333.465403393 2.09671391024 >>> st3 = _Ice(273.16,611.657e-6) >>> st3["alfav"], st3["beta"], st3["xkappa"], st3["ks"] 0.000159863102566 1.35714764659 1.17793449348e-04 1.14161597779e-04 References ---------- IAPWS, Revised Release on the Equation of State 2006 for H2O Ice Ih September 2009, http://iapws.org/relguide/Ice-2009.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L62-L206
jjgomera/iapws
iapws/_iapws.py
_Liquid
def _Liquid(T, P=0.1): """Supplementary release on properties of liquid water at 0.1 MPa Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Although this relation is for P=0.1MPa, can be extrapoled at pressure 0.3 MPa Returns ------- prop : dict Dict with calculated properties of water. The available properties are: * h: Specific enthalpy, [kJ/kg] * u: Specific internal energy, [kJ/kg] * a: Specific Helmholtz energy, [kJ/kg] * g: Specific Gibbs energy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isochoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s²] * rho: Density, [kg/m³] * v: Specific volume, [m³/kg] * vt: [∂v/∂T]P, [m³/kgK] * vtt: [∂²v/∂T²]P, [m³/kgK²] * vp: [∂v/∂P]T, [m³/kg/MPa] * vtp: [∂²v/∂T∂P], [m³/kg/MPa] * alfav: Cubic expansion coefficient, [1/K] * xkappa : Isothermal compressibility, [1/MPa] * ks: Isentropic compressibility, [1/MPa] * mu: Viscosity, [mPas] * k: Thermal conductivity, [W/mK] * epsilon: Dielectric constant, [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 253.15 ≤ T ≤ 383.15 * 0.1 ≤ P ≤ 0.3 Examples -------- >>> st1 = _Liquid(260) >>> st1["rho"], st1["h"], st1["s"] 997.0683602710492 -55.86223174460868 -0.20998554842619535 References ---------- IAPWS, Revised Supplementary Release on Properties of Liquid Water at 0.1 MPa, http://www.iapws.org/relguide/LiquidWater.html """ # Check input in range of validity if T <= 253.15 or T >= 383.15 or P < 0.1 or P > 0.3: raise NotImplementedError("Incoming out of bound") elif P != 0.1: # Raise a warning if the P value is extrapolated warnings.warn("Using extrapolated values") R = 0.46151805 # kJ/kgK Po = 0.1 Tr = 10 tau = T/Tr alfa = Tr/(593-T) beta = Tr/(T-232) a = [None, -1.661470539e5, 2.708781640e6, -1.557191544e8, None, 1.93763157e-2, 6.74458446e3, -2.22521604e5, 1.00231247e8, -1.63552118e9, 8.32299658e9, -7.5245878e-6, -1.3767418e-2, 1.0627293e1, -2.0457795e2, 1.2037414e3] b = [None, -8.237426256e-1, 1.908956353, -2.017597384, 8.546361348e-1, 5.78545292e-3, -1.53195665E-2, 3.11337859e-2, -4.23546241e-2, 3.38713507e-2, -1.19946761e-2, -3.1091470e-6, 2.8964919e-5, -1.3112763e-4, 3.0410453e-4, -3.9034594e-4, 2.3403117e-4, -4.8510101e-5] c = [None, -2.452093414e2, 3.869269598e1, -8.983025854] n = [None, 4, 5, 7, None, None, 4, 5, 7, 8, 9, 1, 3, 5, 6, 7] m = [None, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 1, 3, 4, 5, 6, 7, 9] suma1 = sum([a[i]*alfa**n[i] for i in range(1, 4)]) suma2 = sum([b[i]*beta**m[i] for i in range(1, 5)]) go = R*Tr*(c[1]+c[2]*tau+c[3]*tau*log(tau)+suma1+suma2) suma1 = sum([a[i]*alfa**n[i] for i in range(6, 11)]) suma2 = sum([b[i]*beta**m[i] for i in range(5, 11)]) vo = R*Tr/Po/1000*(a[5]+suma1+suma2) suma1 = sum([a[i]*alfa**n[i] for i in range(11, 16)]) suma2 = sum([b[i]*beta**m[i] for i in range(11, 18)]) vpo = R*Tr/Po**2/1000*(suma1+suma2) suma1 = sum([n[i]*a[i]*alfa**(n[i]+1) for i in range(1, 4)]) suma2 = sum([m[i]*b[i]*beta**(m[i]+1) for i in range(1, 5)]) so = -R*(c[2]+c[3]*(1+log(tau))+suma1-suma2) suma1 = sum([n[i]*(n[i]+1)*a[i]*alfa**(n[i]+2) for i in range(1, 4)]) suma2 = sum([m[i]*(m[i]+1)*b[i]*beta**(m[i]+2) for i in range(1, 5)]) cpo = -R*(c[3]+tau*suma1+tau*suma2) suma1 = sum([n[i]*a[i]*alfa**(n[i]+1) for i in range(6, 11)]) suma2 = sum([m[i]*b[i]*beta**(m[i]+1) for i in range(5, 11)]) vto = R/Po/1000*(suma1-suma2) # This properties are only neccessary for computing thermodynamic # properties at pressures different from 0.1 MPa suma1 = sum([n[i]*(n[i]+1)*a[i]*alfa**(n[i]+2) for i in range(6, 11)]) suma2 = sum([m[i]*(m[i]+1)*b[i]*beta**(m[i]+2) for i in range(5, 11)]) vtto = R/Tr/Po/1000*(suma1+suma2) suma1 = sum([n[i]*a[i]*alfa**(n[i]+1) for i in range(11, 16)]) suma2 = sum([m[i]*b[i]*beta**(m[i]+1) for i in range(11, 18)]) vpto = R/Po**2/1000*(suma1-suma2) if P != 0.1: go += vo*(P-0.1) so -= vto*(P-0.1) cpo -= T*vtto*(P-0.1) vo -= vpo*(P-0.1) vto += vpto*(P-0.1) vppo = 3.24e-10*R*Tr/0.1**3 vpo += vppo*(P-0.1) h = go+T*so u = h-P*vo a = go-P*vo cv = cpo+T*vto**2/vpo xkappa = -vpo/vo alfa = vto/vo ks = -(T*vto**2/cpo+vpo)/vo w = (-vo**2*1e9/(vpo*1e3+T*vto**2*1e6/cpo))**0.5 propiedades = {} propiedades["g"] = go propiedades["T"] = T propiedades["P"] = P propiedades["v"] = vo propiedades["vt"] = vto propiedades["vp"] = vpo propiedades["vpt"] = vpto propiedades["vtt"] = vtto propiedades["rho"] = 1/vo propiedades["h"] = h propiedades["s"] = so propiedades["cp"] = cpo propiedades["cv"] = cv propiedades["u"] = u propiedades["a"] = a propiedades["xkappa"] = xkappa propiedades["alfav"] = vto/vo propiedades["ks"] = ks propiedades["w"] = w # Viscosity correlation, Eq 7 a = [None, 280.68, 511.45, 61.131, 0.45903] b = [None, -1.9, -7.7, -19.6, -40] T_ = T/300 mu = sum([a[i]*T_**b[i] for i in range(1, 5)])/1e6 propiedades["mu"] = mu # Thermal conductivity correlation, Eq 8 c = [None, 1.6630, -1.7781, 1.1567, -0.432115] d = [None, -1.15, -3.4, -6.0, -7.6] k = sum([c[i]*T_**d[i] for i in range(1, 5)]) propiedades["k"] = k # Dielectric constant correlation, Eq 9 e = [None, -43.7527, 299.504, -399.364, 221.327] f = [None, -0.05, -1.47, -2.11, -2.31] epsilon = sum([e[i]*T_**f[i] for i in range(1, 5)]) propiedades["epsilon"] = epsilon return propiedades
python
def _Liquid(T, P=0.1): """Supplementary release on properties of liquid water at 0.1 MPa Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Although this relation is for P=0.1MPa, can be extrapoled at pressure 0.3 MPa Returns ------- prop : dict Dict with calculated properties of water. The available properties are: * h: Specific enthalpy, [kJ/kg] * u: Specific internal energy, [kJ/kg] * a: Specific Helmholtz energy, [kJ/kg] * g: Specific Gibbs energy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isochoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s²] * rho: Density, [kg/m³] * v: Specific volume, [m³/kg] * vt: [∂v/∂T]P, [m³/kgK] * vtt: [∂²v/∂T²]P, [m³/kgK²] * vp: [∂v/∂P]T, [m³/kg/MPa] * vtp: [∂²v/∂T∂P], [m³/kg/MPa] * alfav: Cubic expansion coefficient, [1/K] * xkappa : Isothermal compressibility, [1/MPa] * ks: Isentropic compressibility, [1/MPa] * mu: Viscosity, [mPas] * k: Thermal conductivity, [W/mK] * epsilon: Dielectric constant, [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 253.15 ≤ T ≤ 383.15 * 0.1 ≤ P ≤ 0.3 Examples -------- >>> st1 = _Liquid(260) >>> st1["rho"], st1["h"], st1["s"] 997.0683602710492 -55.86223174460868 -0.20998554842619535 References ---------- IAPWS, Revised Supplementary Release on Properties of Liquid Water at 0.1 MPa, http://www.iapws.org/relguide/LiquidWater.html """ # Check input in range of validity if T <= 253.15 or T >= 383.15 or P < 0.1 or P > 0.3: raise NotImplementedError("Incoming out of bound") elif P != 0.1: # Raise a warning if the P value is extrapolated warnings.warn("Using extrapolated values") R = 0.46151805 # kJ/kgK Po = 0.1 Tr = 10 tau = T/Tr alfa = Tr/(593-T) beta = Tr/(T-232) a = [None, -1.661470539e5, 2.708781640e6, -1.557191544e8, None, 1.93763157e-2, 6.74458446e3, -2.22521604e5, 1.00231247e8, -1.63552118e9, 8.32299658e9, -7.5245878e-6, -1.3767418e-2, 1.0627293e1, -2.0457795e2, 1.2037414e3] b = [None, -8.237426256e-1, 1.908956353, -2.017597384, 8.546361348e-1, 5.78545292e-3, -1.53195665E-2, 3.11337859e-2, -4.23546241e-2, 3.38713507e-2, -1.19946761e-2, -3.1091470e-6, 2.8964919e-5, -1.3112763e-4, 3.0410453e-4, -3.9034594e-4, 2.3403117e-4, -4.8510101e-5] c = [None, -2.452093414e2, 3.869269598e1, -8.983025854] n = [None, 4, 5, 7, None, None, 4, 5, 7, 8, 9, 1, 3, 5, 6, 7] m = [None, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 1, 3, 4, 5, 6, 7, 9] suma1 = sum([a[i]*alfa**n[i] for i in range(1, 4)]) suma2 = sum([b[i]*beta**m[i] for i in range(1, 5)]) go = R*Tr*(c[1]+c[2]*tau+c[3]*tau*log(tau)+suma1+suma2) suma1 = sum([a[i]*alfa**n[i] for i in range(6, 11)]) suma2 = sum([b[i]*beta**m[i] for i in range(5, 11)]) vo = R*Tr/Po/1000*(a[5]+suma1+suma2) suma1 = sum([a[i]*alfa**n[i] for i in range(11, 16)]) suma2 = sum([b[i]*beta**m[i] for i in range(11, 18)]) vpo = R*Tr/Po**2/1000*(suma1+suma2) suma1 = sum([n[i]*a[i]*alfa**(n[i]+1) for i in range(1, 4)]) suma2 = sum([m[i]*b[i]*beta**(m[i]+1) for i in range(1, 5)]) so = -R*(c[2]+c[3]*(1+log(tau))+suma1-suma2) suma1 = sum([n[i]*(n[i]+1)*a[i]*alfa**(n[i]+2) for i in range(1, 4)]) suma2 = sum([m[i]*(m[i]+1)*b[i]*beta**(m[i]+2) for i in range(1, 5)]) cpo = -R*(c[3]+tau*suma1+tau*suma2) suma1 = sum([n[i]*a[i]*alfa**(n[i]+1) for i in range(6, 11)]) suma2 = sum([m[i]*b[i]*beta**(m[i]+1) for i in range(5, 11)]) vto = R/Po/1000*(suma1-suma2) # This properties are only neccessary for computing thermodynamic # properties at pressures different from 0.1 MPa suma1 = sum([n[i]*(n[i]+1)*a[i]*alfa**(n[i]+2) for i in range(6, 11)]) suma2 = sum([m[i]*(m[i]+1)*b[i]*beta**(m[i]+2) for i in range(5, 11)]) vtto = R/Tr/Po/1000*(suma1+suma2) suma1 = sum([n[i]*a[i]*alfa**(n[i]+1) for i in range(11, 16)]) suma2 = sum([m[i]*b[i]*beta**(m[i]+1) for i in range(11, 18)]) vpto = R/Po**2/1000*(suma1-suma2) if P != 0.1: go += vo*(P-0.1) so -= vto*(P-0.1) cpo -= T*vtto*(P-0.1) vo -= vpo*(P-0.1) vto += vpto*(P-0.1) vppo = 3.24e-10*R*Tr/0.1**3 vpo += vppo*(P-0.1) h = go+T*so u = h-P*vo a = go-P*vo cv = cpo+T*vto**2/vpo xkappa = -vpo/vo alfa = vto/vo ks = -(T*vto**2/cpo+vpo)/vo w = (-vo**2*1e9/(vpo*1e3+T*vto**2*1e6/cpo))**0.5 propiedades = {} propiedades["g"] = go propiedades["T"] = T propiedades["P"] = P propiedades["v"] = vo propiedades["vt"] = vto propiedades["vp"] = vpo propiedades["vpt"] = vpto propiedades["vtt"] = vtto propiedades["rho"] = 1/vo propiedades["h"] = h propiedades["s"] = so propiedades["cp"] = cpo propiedades["cv"] = cv propiedades["u"] = u propiedades["a"] = a propiedades["xkappa"] = xkappa propiedades["alfav"] = vto/vo propiedades["ks"] = ks propiedades["w"] = w # Viscosity correlation, Eq 7 a = [None, 280.68, 511.45, 61.131, 0.45903] b = [None, -1.9, -7.7, -19.6, -40] T_ = T/300 mu = sum([a[i]*T_**b[i] for i in range(1, 5)])/1e6 propiedades["mu"] = mu # Thermal conductivity correlation, Eq 8 c = [None, 1.6630, -1.7781, 1.1567, -0.432115] d = [None, -1.15, -3.4, -6.0, -7.6] k = sum([c[i]*T_**d[i] for i in range(1, 5)]) propiedades["k"] = k # Dielectric constant correlation, Eq 9 e = [None, -43.7527, 299.504, -399.364, 221.327] f = [None, -0.05, -1.47, -2.11, -2.31] epsilon = sum([e[i]*T_**f[i] for i in range(1, 5)]) propiedades["epsilon"] = epsilon return propiedades
Supplementary release on properties of liquid water at 0.1 MPa Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Although this relation is for P=0.1MPa, can be extrapoled at pressure 0.3 MPa Returns ------- prop : dict Dict with calculated properties of water. The available properties are: * h: Specific enthalpy, [kJ/kg] * u: Specific internal energy, [kJ/kg] * a: Specific Helmholtz energy, [kJ/kg] * g: Specific Gibbs energy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isochoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s²] * rho: Density, [kg/m³] * v: Specific volume, [m³/kg] * vt: [∂v/∂T]P, [m³/kgK] * vtt: [∂²v/∂T²]P, [m³/kgK²] * vp: [∂v/∂P]T, [m³/kg/MPa] * vtp: [∂²v/∂T∂P], [m³/kg/MPa] * alfav: Cubic expansion coefficient, [1/K] * xkappa : Isothermal compressibility, [1/MPa] * ks: Isentropic compressibility, [1/MPa] * mu: Viscosity, [mPas] * k: Thermal conductivity, [W/mK] * epsilon: Dielectric constant, [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 253.15 ≤ T ≤ 383.15 * 0.1 ≤ P ≤ 0.3 Examples -------- >>> st1 = _Liquid(260) >>> st1["rho"], st1["h"], st1["s"] 997.0683602710492 -55.86223174460868 -0.20998554842619535 References ---------- IAPWS, Revised Supplementary Release on Properties of Liquid Water at 0.1 MPa, http://www.iapws.org/relguide/LiquidWater.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L210-L385
jjgomera/iapws
iapws/_iapws.py
_Supercooled
def _Supercooled(T, P): """Guideline on thermodynamic properties of supercooled water Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties of water. The available properties are: * L: Ordering field, [-] * x: Mole fraction of low-density structure, [-] * rho: Density, [kg/m³] * s: Specific entropy, [kJ/kgK] * h: Specific enthalpy, [kJ/kg] * u: Specific internal energy, [kJ/kg] * a: Specific Helmholtz energy, [kJ/kg] * g: Specific Gibbs energy, [kJ/kg] * alfap: Thermal expansion coefficient, [1/K] * xkappa : Isothermal compressibility, [1/MPa] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isochoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s²] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * Tm ≤ T ≤ 300 * 0 < P ≤ 1000 The minimum temperature in range of validity is the melting temperature, it depend of pressure Examples -------- >>> liq = _Supercooled(235.15, 0.101325) >>> liq["rho"], liq["cp"], liq["w"] 968.09999 5.997563 1134.5855 References ---------- IAPWS, Guideline on Thermodynamic Properties of Supercooled Water, http://iapws.org/relguide/Supercooled.html """ # Check input in range of validity if P < 198.9: Tita = T/235.15 Ph = 0.1+228.27*(1-Tita**6.243)+15.724*(1-Tita**79.81) if P < Ph or T > 300: raise NotImplementedError("Incoming out of bound") else: Th = 172.82+0.03718*P+3.403e-5*P**2-1.573e-8*P**3 if T < Th or T > 300 or P > 1000: raise NotImplementedError("Incoming out of bound") # Parameters, Table 1 Tll = 228.2 rho0 = 1081.6482 R = 0.461523087 pi0 = 300e3/rho0/R/Tll omega0 = 0.5212269 L0 = 0.76317954 k0 = 0.072158686 k1 = -0.31569232 k2 = 5.2992608 # Reducing parameters, Eq 2 tau = T/Tll-1 p = P*1000/rho0/R/Tll tau_ = tau+1 p_ = p+pi0 # Eq 3 ci = [-8.1570681381655, 1.2875032, 7.0901673598012, -3.2779161e-2, 7.3703949e-1, -2.1628622e-1, -5.1782479, 4.2293517e-4, 2.3592109e-2, 4.3773754, -2.9967770e-3, -9.6558018e-1, 3.7595286, 1.2632441, 2.8542697e-1, -8.5994947e-1, -3.2916153e-1, 9.0019616e-2, 8.1149726e-2, -3.2788213] ai = [0, 0, 1, -0.2555, 1.5762, 1.6400, 3.6385, -0.3828, 1.6219, 4.3287, 3.4763, 5.1556, -0.3593, 5.0361, 2.9786, 6.2373, 4.0460, 5.3558, 9.0157, 1.2194] bi = [0, 1, 0, 2.1051, 1.1422, 0.9510, 0, 3.6402, 2.0760, -0.0016, 2.2769, 0.0008, 0.3706, -0.3975, 2.9730, -0.3180, 2.9805, 2.9265, 0.4456, 0.1298] di = [0, 0, 0, -0.0016, 0.6894, 0.0130, 0.0002, 0.0435, 0.0500, 0.0004, 0.0528, 0.0147, 0.8584, 0.9924, 1.0041, 1.0961, 1.0228, 1.0303, 1.6180, 0.5213] phir = phirt = phirp = phirtt = phirtp = phirpp = 0 for c, a, b, d in zip(ci, ai, bi, di): phir += c*tau_**a*p_**b*exp(-d*p_) phirt += c*a*tau_**(a-1)*p_**b*exp(-d*p_) phirp += c*tau_**a*p_**(b-1)*(b-d*p_)*exp(-d*p_) phirtt += c*a*(a-1)*tau_**(a-2)*p_**b*exp(-d*p_) phirtp += c*a*tau_**(a-1)*p_**(b-1)*(b-d*p_)*exp(-d*p_) phirpp += c*tau_**a*p_**(b-2)*((d*p_-b)**2-b)*exp(-d*p_) # Eq 5 K1 = ((1+k0*k2+k1*(p-k2*tau))**2-4*k0*k1*k2*(p-k2*tau))**0.5 K2 = (1+k2**2)**0.5 # Eq 6 omega = 2+omega0*p # Eq 4 L = L0*K2/2/k1/k2*(1+k0*k2+k1*(p+k2*tau)-K1) # Define interval of solution, Table 4 if omega < 10/9*(log(19)-L): xmin = 0.049 xmax = 0.5 elif 10/9*(log(19)-L) <= omega < 50/49*(log(99)-L): xmin = 0.0099 xmax = 0.051 else: xmin = 0.99*exp(-50/49*L-omega) xmax = min(1.1*exp(-L-omega), 0.0101) def f(x): return abs(L+log(x/(1-x))+omega*(1-2*x)) x = minimize(f, ((xmin+xmax)/2,), bounds=((xmin, xmax),))["x"][0] # Eq 12 fi = 2*x-1 Xi = 1/(2/(1-fi**2)-omega) # Derivatives, Table 3 Lt = L0*K2/2*(1+(1-k0*k2+k1*(p-k2*tau))/K1) Lp = L0*K2*(K1+k0*k2-k1*p+k1*k2*tau-1)/2/k2/K1 Ltt = -2*L0*K2*k0*k1*k2**2/K1**3 Ltp = 2*L0*K2*k0*k1*k2/K1**3 Lpp = -2*L0*K2*k0*k1/K1**3 prop = {} prop["L"] = L prop["x"] = x # Eq 13 prop["rho"] = rho0/((tau+1)/2*(omega0/2*(1-fi**2)+Lp*(fi+1))+phirp) # Eq 1 prop["g"] = phir+(tau+1)*(x*L+x*log(x)+(1-x)*log(1-x)+omega*x*(1-x)) # Eq 14 prop["s"] = -R*((tau+1)/2*Lt*(fi+1) + (x*L+x*log(x)+(1-x)*log(1-x)+omega*x*(1-x))+phirt) # Basic derived state properties prop["h"] = prop["g"]+T*prop["s"] prop["u"] = prop["h"]+P/prop["rho"] prop["a"] = prop["u"]-T*prop["s"] # Eq 15 prop["xkappa"] = prop["rho"]/rho0**2/R*1000/Tll*( (tau+1)/2*(Xi*(Lp-omega0*fi)**2-(fi+1)*Lpp)-phirpp) prop["alfap"] = prop["rho"]/rho0/Tll*( Ltp/2*(tau+1)*(fi+1) + (omega0*(1-fi**2)/2+Lp*(fi+1))/2 - (tau+1)*Lt/2*Xi*(Lp-omega0*fi) + phirtp) prop["cp"] = -R*(tau+1)*(Lt*(fi+1)+(tau+1)/2*(Ltt*(fi+1)-Lt**2*Xi)+phirtt) # Eq 16 prop["cv"] = prop["cp"]-T*prop["alfap"]**2/prop["rho"]/prop["xkappa"]*1e3 # Eq 17 prop["w"] = (prop["rho"]*prop["xkappa"]*1e-6*prop["cv"]/prop["cp"])**-0.5 return prop
python
def _Supercooled(T, P): """Guideline on thermodynamic properties of supercooled water Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties of water. The available properties are: * L: Ordering field, [-] * x: Mole fraction of low-density structure, [-] * rho: Density, [kg/m³] * s: Specific entropy, [kJ/kgK] * h: Specific enthalpy, [kJ/kg] * u: Specific internal energy, [kJ/kg] * a: Specific Helmholtz energy, [kJ/kg] * g: Specific Gibbs energy, [kJ/kg] * alfap: Thermal expansion coefficient, [1/K] * xkappa : Isothermal compressibility, [1/MPa] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isochoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s²] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * Tm ≤ T ≤ 300 * 0 < P ≤ 1000 The minimum temperature in range of validity is the melting temperature, it depend of pressure Examples -------- >>> liq = _Supercooled(235.15, 0.101325) >>> liq["rho"], liq["cp"], liq["w"] 968.09999 5.997563 1134.5855 References ---------- IAPWS, Guideline on Thermodynamic Properties of Supercooled Water, http://iapws.org/relguide/Supercooled.html """ # Check input in range of validity if P < 198.9: Tita = T/235.15 Ph = 0.1+228.27*(1-Tita**6.243)+15.724*(1-Tita**79.81) if P < Ph or T > 300: raise NotImplementedError("Incoming out of bound") else: Th = 172.82+0.03718*P+3.403e-5*P**2-1.573e-8*P**3 if T < Th or T > 300 or P > 1000: raise NotImplementedError("Incoming out of bound") # Parameters, Table 1 Tll = 228.2 rho0 = 1081.6482 R = 0.461523087 pi0 = 300e3/rho0/R/Tll omega0 = 0.5212269 L0 = 0.76317954 k0 = 0.072158686 k1 = -0.31569232 k2 = 5.2992608 # Reducing parameters, Eq 2 tau = T/Tll-1 p = P*1000/rho0/R/Tll tau_ = tau+1 p_ = p+pi0 # Eq 3 ci = [-8.1570681381655, 1.2875032, 7.0901673598012, -3.2779161e-2, 7.3703949e-1, -2.1628622e-1, -5.1782479, 4.2293517e-4, 2.3592109e-2, 4.3773754, -2.9967770e-3, -9.6558018e-1, 3.7595286, 1.2632441, 2.8542697e-1, -8.5994947e-1, -3.2916153e-1, 9.0019616e-2, 8.1149726e-2, -3.2788213] ai = [0, 0, 1, -0.2555, 1.5762, 1.6400, 3.6385, -0.3828, 1.6219, 4.3287, 3.4763, 5.1556, -0.3593, 5.0361, 2.9786, 6.2373, 4.0460, 5.3558, 9.0157, 1.2194] bi = [0, 1, 0, 2.1051, 1.1422, 0.9510, 0, 3.6402, 2.0760, -0.0016, 2.2769, 0.0008, 0.3706, -0.3975, 2.9730, -0.3180, 2.9805, 2.9265, 0.4456, 0.1298] di = [0, 0, 0, -0.0016, 0.6894, 0.0130, 0.0002, 0.0435, 0.0500, 0.0004, 0.0528, 0.0147, 0.8584, 0.9924, 1.0041, 1.0961, 1.0228, 1.0303, 1.6180, 0.5213] phir = phirt = phirp = phirtt = phirtp = phirpp = 0 for c, a, b, d in zip(ci, ai, bi, di): phir += c*tau_**a*p_**b*exp(-d*p_) phirt += c*a*tau_**(a-1)*p_**b*exp(-d*p_) phirp += c*tau_**a*p_**(b-1)*(b-d*p_)*exp(-d*p_) phirtt += c*a*(a-1)*tau_**(a-2)*p_**b*exp(-d*p_) phirtp += c*a*tau_**(a-1)*p_**(b-1)*(b-d*p_)*exp(-d*p_) phirpp += c*tau_**a*p_**(b-2)*((d*p_-b)**2-b)*exp(-d*p_) # Eq 5 K1 = ((1+k0*k2+k1*(p-k2*tau))**2-4*k0*k1*k2*(p-k2*tau))**0.5 K2 = (1+k2**2)**0.5 # Eq 6 omega = 2+omega0*p # Eq 4 L = L0*K2/2/k1/k2*(1+k0*k2+k1*(p+k2*tau)-K1) # Define interval of solution, Table 4 if omega < 10/9*(log(19)-L): xmin = 0.049 xmax = 0.5 elif 10/9*(log(19)-L) <= omega < 50/49*(log(99)-L): xmin = 0.0099 xmax = 0.051 else: xmin = 0.99*exp(-50/49*L-omega) xmax = min(1.1*exp(-L-omega), 0.0101) def f(x): return abs(L+log(x/(1-x))+omega*(1-2*x)) x = minimize(f, ((xmin+xmax)/2,), bounds=((xmin, xmax),))["x"][0] # Eq 12 fi = 2*x-1 Xi = 1/(2/(1-fi**2)-omega) # Derivatives, Table 3 Lt = L0*K2/2*(1+(1-k0*k2+k1*(p-k2*tau))/K1) Lp = L0*K2*(K1+k0*k2-k1*p+k1*k2*tau-1)/2/k2/K1 Ltt = -2*L0*K2*k0*k1*k2**2/K1**3 Ltp = 2*L0*K2*k0*k1*k2/K1**3 Lpp = -2*L0*K2*k0*k1/K1**3 prop = {} prop["L"] = L prop["x"] = x # Eq 13 prop["rho"] = rho0/((tau+1)/2*(omega0/2*(1-fi**2)+Lp*(fi+1))+phirp) # Eq 1 prop["g"] = phir+(tau+1)*(x*L+x*log(x)+(1-x)*log(1-x)+omega*x*(1-x)) # Eq 14 prop["s"] = -R*((tau+1)/2*Lt*(fi+1) + (x*L+x*log(x)+(1-x)*log(1-x)+omega*x*(1-x))+phirt) # Basic derived state properties prop["h"] = prop["g"]+T*prop["s"] prop["u"] = prop["h"]+P/prop["rho"] prop["a"] = prop["u"]-T*prop["s"] # Eq 15 prop["xkappa"] = prop["rho"]/rho0**2/R*1000/Tll*( (tau+1)/2*(Xi*(Lp-omega0*fi)**2-(fi+1)*Lpp)-phirpp) prop["alfap"] = prop["rho"]/rho0/Tll*( Ltp/2*(tau+1)*(fi+1) + (omega0*(1-fi**2)/2+Lp*(fi+1))/2 - (tau+1)*Lt/2*Xi*(Lp-omega0*fi) + phirtp) prop["cp"] = -R*(tau+1)*(Lt*(fi+1)+(tau+1)/2*(Ltt*(fi+1)-Lt**2*Xi)+phirtt) # Eq 16 prop["cv"] = prop["cp"]-T*prop["alfap"]**2/prop["rho"]/prop["xkappa"]*1e3 # Eq 17 prop["w"] = (prop["rho"]*prop["xkappa"]*1e-6*prop["cv"]/prop["cp"])**-0.5 return prop
Guideline on thermodynamic properties of supercooled water Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties of water. The available properties are: * L: Ordering field, [-] * x: Mole fraction of low-density structure, [-] * rho: Density, [kg/m³] * s: Specific entropy, [kJ/kgK] * h: Specific enthalpy, [kJ/kg] * u: Specific internal energy, [kJ/kg] * a: Specific Helmholtz energy, [kJ/kg] * g: Specific Gibbs energy, [kJ/kg] * alfap: Thermal expansion coefficient, [1/K] * xkappa : Isothermal compressibility, [1/MPa] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isochoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s²] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * Tm ≤ T ≤ 300 * 0 < P ≤ 1000 The minimum temperature in range of validity is the melting temperature, it depend of pressure Examples -------- >>> liq = _Supercooled(235.15, 0.101325) >>> liq["rho"], liq["cp"], liq["w"] 968.09999 5.997563 1134.5855 References ---------- IAPWS, Guideline on Thermodynamic Properties of Supercooled Water, http://iapws.org/relguide/Supercooled.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L389-L561
jjgomera/iapws
iapws/_iapws.py
_Sublimation_Pressure
def _Sublimation_Pressure(T): """Sublimation Pressure correlation Parameters ---------- T : float Temperature, [K] Returns ------- P : float Pressure at sublimation line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 50 ≤ T ≤ 273.16 Examples -------- >>> _Sublimation_Pressure(230) 8.947352740189152e-06 References ---------- IAPWS, Revised Release on the Pressure along the Melting and Sublimation Curves of Ordinary Water Substance, http://iapws.org/relguide/MeltSub.html. """ if 50 <= T <= 273.16: Tita = T/Tt suma = 0 a = [-0.212144006e2, 0.273203819e2, -0.61059813e1] expo = [0.333333333e-2, 1.20666667, 1.70333333] for ai, expi in zip(a, expo): suma += ai*Tita**expi return exp(suma/Tita)*Pt else: raise NotImplementedError("Incoming out of bound")
python
def _Sublimation_Pressure(T): """Sublimation Pressure correlation Parameters ---------- T : float Temperature, [K] Returns ------- P : float Pressure at sublimation line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 50 ≤ T ≤ 273.16 Examples -------- >>> _Sublimation_Pressure(230) 8.947352740189152e-06 References ---------- IAPWS, Revised Release on the Pressure along the Melting and Sublimation Curves of Ordinary Water Substance, http://iapws.org/relguide/MeltSub.html. """ if 50 <= T <= 273.16: Tita = T/Tt suma = 0 a = [-0.212144006e2, 0.273203819e2, -0.61059813e1] expo = [0.333333333e-2, 1.20666667, 1.70333333] for ai, expi in zip(a, expo): suma += ai*Tita**expi return exp(suma/Tita)*Pt else: raise NotImplementedError("Incoming out of bound")
Sublimation Pressure correlation Parameters ---------- T : float Temperature, [K] Returns ------- P : float Pressure at sublimation line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 50 ≤ T ≤ 273.16 Examples -------- >>> _Sublimation_Pressure(230) 8.947352740189152e-06 References ---------- IAPWS, Revised Release on the Pressure along the Melting and Sublimation Curves of Ordinary Water Substance, http://iapws.org/relguide/MeltSub.html.
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L564-L602
jjgomera/iapws
iapws/_iapws.py
_Melting_Pressure
def _Melting_Pressure(T, ice="Ih"): """Melting Pressure correlation Parameters ---------- T : float Temperature, [K] ice: string Type of ice: Ih, III, V, VI, VII. Below 273.15 is a mandatory input, the ice Ih is the default value. Above 273.15, the ice type is unnecesary. Returns ------- P : float Pressure at sublimation line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 251.165 ≤ T ≤ 715 Examples -------- >>> _Melting_Pressure(260) 8.947352740189152e-06 >>> _Melting_Pressure(254, "III") 268.6846466336108 References ---------- IAPWS, Revised Release on the Pressure along the Melting and Sublimation Curves of Ordinary Water Substance, http://iapws.org/relguide/MeltSub.html. """ if ice == "Ih" and 251.165 <= T <= 273.16: # Ice Ih Tref = Tt Pref = Pt Tita = T/Tref a = [0.119539337e7, 0.808183159e5, 0.33382686e4] expo = [3., 0.2575e2, 0.10375e3] suma = 1 for ai, expi in zip(a, expo): suma += ai*(1-Tita**expi) P = suma*Pref elif ice == "III" and 251.165 < T <= 256.164: # Ice III Tref = 251.165 Pref = 208.566 Tita = T/Tref P = Pref*(1-0.299948*(1-Tita**60.)) elif (ice == "V" and 256.164 < T <= 273.15) or 273.15 < T <= 273.31: # Ice V Tref = 256.164 Pref = 350.100 Tita = T/Tref P = Pref*(1-1.18721*(1-Tita**8.)) elif 273.31 < T <= 355: # Ice VI Tref = 273.31 Pref = 632.400 Tita = T/Tref P = Pref*(1-1.07476*(1-Tita**4.6)) elif 355. < T <= 715: # Ice VII Tref = 355 Pref = 2216.000 Tita = T/Tref P = Pref*exp(1.73683*(1-1./Tita)-0.544606e-1*(1-Tita**5) + 0.806106e-7*(1-Tita**22)) else: raise NotImplementedError("Incoming out of bound") return P
python
def _Melting_Pressure(T, ice="Ih"): """Melting Pressure correlation Parameters ---------- T : float Temperature, [K] ice: string Type of ice: Ih, III, V, VI, VII. Below 273.15 is a mandatory input, the ice Ih is the default value. Above 273.15, the ice type is unnecesary. Returns ------- P : float Pressure at sublimation line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 251.165 ≤ T ≤ 715 Examples -------- >>> _Melting_Pressure(260) 8.947352740189152e-06 >>> _Melting_Pressure(254, "III") 268.6846466336108 References ---------- IAPWS, Revised Release on the Pressure along the Melting and Sublimation Curves of Ordinary Water Substance, http://iapws.org/relguide/MeltSub.html. """ if ice == "Ih" and 251.165 <= T <= 273.16: # Ice Ih Tref = Tt Pref = Pt Tita = T/Tref a = [0.119539337e7, 0.808183159e5, 0.33382686e4] expo = [3., 0.2575e2, 0.10375e3] suma = 1 for ai, expi in zip(a, expo): suma += ai*(1-Tita**expi) P = suma*Pref elif ice == "III" and 251.165 < T <= 256.164: # Ice III Tref = 251.165 Pref = 208.566 Tita = T/Tref P = Pref*(1-0.299948*(1-Tita**60.)) elif (ice == "V" and 256.164 < T <= 273.15) or 273.15 < T <= 273.31: # Ice V Tref = 256.164 Pref = 350.100 Tita = T/Tref P = Pref*(1-1.18721*(1-Tita**8.)) elif 273.31 < T <= 355: # Ice VI Tref = 273.31 Pref = 632.400 Tita = T/Tref P = Pref*(1-1.07476*(1-Tita**4.6)) elif 355. < T <= 715: # Ice VII Tref = 355 Pref = 2216.000 Tita = T/Tref P = Pref*exp(1.73683*(1-1./Tita)-0.544606e-1*(1-Tita**5) + 0.806106e-7*(1-Tita**22)) else: raise NotImplementedError("Incoming out of bound") return P
Melting Pressure correlation Parameters ---------- T : float Temperature, [K] ice: string Type of ice: Ih, III, V, VI, VII. Below 273.15 is a mandatory input, the ice Ih is the default value. Above 273.15, the ice type is unnecesary. Returns ------- P : float Pressure at sublimation line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 251.165 ≤ T ≤ 715 Examples -------- >>> _Melting_Pressure(260) 8.947352740189152e-06 >>> _Melting_Pressure(254, "III") 268.6846466336108 References ---------- IAPWS, Revised Release on the Pressure along the Melting and Sublimation Curves of Ordinary Water Substance, http://iapws.org/relguide/MeltSub.html.
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L605-L678
jjgomera/iapws
iapws/_iapws.py
_Viscosity
def _Viscosity(rho, T, fase=None, drho=None): """Equation for the Viscosity Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] fase: dict, optional for calculate critical enhancement phase properties drho: float, optional for calculate critical enhancement [∂ρ/∂P]T at reference state, Returns ------- μ : float Viscosity, [Pa·s] Examples -------- >>> _Viscosity(998, 298.15) 0.0008897351001498108 >>> _Viscosity(600, 873.15) 7.743019522728247e-05 References ---------- IAPWS, Release on the IAPWS Formulation 2008 for the Viscosity of Ordinary Water Substance, http://www.iapws.org/relguide/viscosity.html """ Tr = T/Tc Dr = rho/rhoc # Eq 11 H = [1.67752, 2.20462, 0.6366564, -0.241605] mu0 = 100*Tr**0.5/sum([Hi/Tr**i for i, Hi in enumerate(H)]) # Eq 12 I = [0, 1, 2, 3, 0, 1, 2, 3, 5, 0, 1, 2, 3, 4, 0, 1, 0, 3, 4, 3, 5] J = [0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6] Hij = [0.520094, 0.850895e-1, -0.108374e1, -0.289555, 0.222531, 0.999115, 0.188797e1, 0.126613e1, 0.120573, -0.281378, -0.906851, -0.772479, -0.489837, -0.257040, 0.161913, 0.257399, -0.325372e-1, 0.698452e-1, 0.872102e-2, -0.435673e-2, -0.593264e-3] mu1 = exp(Dr*sum([(1/Tr-1)**i*h*(Dr-1)**j for i, j, h in zip(I, J, Hij)])) # Critical enhancement if fase and drho: qc = 1/1.9 qd = 1/1.1 # Eq 21 DeltaX = Pc*Dr**2*(fase.drhodP_T/rho-drho/rho*1.5/Tr) if DeltaX < 0: DeltaX = 0 # Eq 20 X = 0.13*(DeltaX/0.06)**(0.63/1.239) if X <= 0.3817016416: # Eq 15 Y = qc/5*X*(qd*X)**5*(1-qc*X+(qc*X)**2-765./504*(qd*X)**2) else: Fid = acos((1+qd**2*X**2)**-0.5) # Eq 17 w = abs((qc*X-1)/(qc*X+1))**0.5*tan(Fid/2) # Eq 19 # Eq 18 if qc*X > 1: Lw = log((1+w)/(1-w)) else: Lw = 2*atan(abs(w)) # Eq 16 Y = sin(3*Fid)/12-sin(2*Fid)/4/qc/X+(1-5/4*(qc*X)**2)/( qc*X)**2*sin(Fid)-((1-3/2*(qc*X)**2)*Fid-abs(( qc*X)**2-1)**1.5*Lw)/(qc*X)**3 # Eq 14 mu2 = exp(0.068*Y) else: mu2 = 1 # Eq 10 mu = mu0*mu1*mu2 return mu*1e-6
python
def _Viscosity(rho, T, fase=None, drho=None): """Equation for the Viscosity Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] fase: dict, optional for calculate critical enhancement phase properties drho: float, optional for calculate critical enhancement [∂ρ/∂P]T at reference state, Returns ------- μ : float Viscosity, [Pa·s] Examples -------- >>> _Viscosity(998, 298.15) 0.0008897351001498108 >>> _Viscosity(600, 873.15) 7.743019522728247e-05 References ---------- IAPWS, Release on the IAPWS Formulation 2008 for the Viscosity of Ordinary Water Substance, http://www.iapws.org/relguide/viscosity.html """ Tr = T/Tc Dr = rho/rhoc # Eq 11 H = [1.67752, 2.20462, 0.6366564, -0.241605] mu0 = 100*Tr**0.5/sum([Hi/Tr**i for i, Hi in enumerate(H)]) # Eq 12 I = [0, 1, 2, 3, 0, 1, 2, 3, 5, 0, 1, 2, 3, 4, 0, 1, 0, 3, 4, 3, 5] J = [0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6] Hij = [0.520094, 0.850895e-1, -0.108374e1, -0.289555, 0.222531, 0.999115, 0.188797e1, 0.126613e1, 0.120573, -0.281378, -0.906851, -0.772479, -0.489837, -0.257040, 0.161913, 0.257399, -0.325372e-1, 0.698452e-1, 0.872102e-2, -0.435673e-2, -0.593264e-3] mu1 = exp(Dr*sum([(1/Tr-1)**i*h*(Dr-1)**j for i, j, h in zip(I, J, Hij)])) # Critical enhancement if fase and drho: qc = 1/1.9 qd = 1/1.1 # Eq 21 DeltaX = Pc*Dr**2*(fase.drhodP_T/rho-drho/rho*1.5/Tr) if DeltaX < 0: DeltaX = 0 # Eq 20 X = 0.13*(DeltaX/0.06)**(0.63/1.239) if X <= 0.3817016416: # Eq 15 Y = qc/5*X*(qd*X)**5*(1-qc*X+(qc*X)**2-765./504*(qd*X)**2) else: Fid = acos((1+qd**2*X**2)**-0.5) # Eq 17 w = abs((qc*X-1)/(qc*X+1))**0.5*tan(Fid/2) # Eq 19 # Eq 18 if qc*X > 1: Lw = log((1+w)/(1-w)) else: Lw = 2*atan(abs(w)) # Eq 16 Y = sin(3*Fid)/12-sin(2*Fid)/4/qc/X+(1-5/4*(qc*X)**2)/( qc*X)**2*sin(Fid)-((1-3/2*(qc*X)**2)*Fid-abs(( qc*X)**2-1)**1.5*Lw)/(qc*X)**3 # Eq 14 mu2 = exp(0.068*Y) else: mu2 = 1 # Eq 10 mu = mu0*mu1*mu2 return mu*1e-6
Equation for the Viscosity Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] fase: dict, optional for calculate critical enhancement phase properties drho: float, optional for calculate critical enhancement [∂ρ/∂P]T at reference state, Returns ------- μ : float Viscosity, [Pa·s] Examples -------- >>> _Viscosity(998, 298.15) 0.0008897351001498108 >>> _Viscosity(600, 873.15) 7.743019522728247e-05 References ---------- IAPWS, Release on the IAPWS Formulation 2008 for the Viscosity of Ordinary Water Substance, http://www.iapws.org/relguide/viscosity.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L682-L768
jjgomera/iapws
iapws/_iapws.py
_ThCond
def _ThCond(rho, T, fase=None, drho=None): """Equation for the thermal conductivity Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] fase: dict, optional for calculate critical enhancement phase properties drho: float, optional for calculate critical enhancement [∂ρ/∂P]T at reference state, Returns ------- k : float Thermal conductivity, [W/mK] Examples -------- >>> _ThCond(998, 298.15) 0.6077128675880629 >>> _ThCond(0, 873.15) 0.07910346589648833 References ---------- IAPWS, Release on the IAPWS Formulation 2011 for the Thermal Conductivity of Ordinary Water Substance, http://www.iapws.org/relguide/ThCond.html """ d = rho/rhoc Tr = T/Tc # Eq 16 no = [2.443221e-3, 1.323095e-2, 6.770357e-3, -3.454586e-3, 4.096266e-4] k0 = Tr**0.5/sum([n/Tr**i for i, n in enumerate(no)]) # Eq 17 I = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4] J = [0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5] nij = [1.60397357, -0.646013523, 0.111443906, 0.102997357, -0.0504123634, 0.00609859258, 2.33771842, -2.78843778, 1.53616167, -0.463045512, 0.0832827019, -0.00719201245, 2.19650529, -4.54580785, 3.55777244, -1.40944978, 0.275418278, -0.0205938816, -1.21051378, 1.60812989, -0.621178141, 0.0716373224, -2.7203370, 4.57586331, -3.18369245, 1.1168348, -0.19268305, 0.012913842] k1 = exp(d*sum([(1/Tr-1)**i*n*(d-1)**j for i, j, n in zip(I, J, nij)])) # Critical enhancement if fase: R = 0.46151805 if not drho: # Industrial formulation # Eq 25 if d <= 0.310559006: ai = [6.53786807199516, -5.61149954923348, 3.39624167361325, -2.27492629730878, 10.2631854662709, 1.97815050331519] elif d <= 0.776397516: ai = [6.52717759281799, -6.30816983387575, 8.08379285492595, -9.82240510197603, 12.1358413791395, -5.54349664571295] elif d <= 1.242236025: ai = [5.35500529896124, -3.96415689925446, 8.91990208918795, -12.0338729505790, 9.19494865194302, -2.16866274479712] elif d <= 1.863354037: ai = [1.55225959906681, 0.464621290821181, 8.93237374861479, -11.0321960061126, 6.16780999933360, -0.965458722086812] else: ai = [1.11999926419994, 0.595748562571649, 9.88952565078920, -10.3255051147040, 4.66861294457414, -0.503243546373828] drho = 1/sum([a*d**i for i, a in enumerate(ai)])*rhoc/Pc DeltaX = d*(Pc/rhoc*fase.drhodP_T-Pc/rhoc*drho*1.5/Tr) if DeltaX < 0: DeltaX = 0 X = 0.13*(DeltaX/0.06)**(0.63/1.239) # Eq 22 y = X/0.4 # Eq 20 # Eq 19 if y < 1.2e-7: Z = 0 else: Z = 2/pi/y*(((1-1/fase.cp_cv)*atan(y)+y/fase.cp_cv)-( 1-exp(-1/(1/y+y**2/3/d**2)))) # Eq 18 k2 = 177.8514*d*fase.cp/R*Tr/fase.mu*1e-6*Z else: # No critical enhancement k2 = 0 # Eq 10 k = k0*k1+k2 return 1e-3*k
python
def _ThCond(rho, T, fase=None, drho=None): """Equation for the thermal conductivity Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] fase: dict, optional for calculate critical enhancement phase properties drho: float, optional for calculate critical enhancement [∂ρ/∂P]T at reference state, Returns ------- k : float Thermal conductivity, [W/mK] Examples -------- >>> _ThCond(998, 298.15) 0.6077128675880629 >>> _ThCond(0, 873.15) 0.07910346589648833 References ---------- IAPWS, Release on the IAPWS Formulation 2011 for the Thermal Conductivity of Ordinary Water Substance, http://www.iapws.org/relguide/ThCond.html """ d = rho/rhoc Tr = T/Tc # Eq 16 no = [2.443221e-3, 1.323095e-2, 6.770357e-3, -3.454586e-3, 4.096266e-4] k0 = Tr**0.5/sum([n/Tr**i for i, n in enumerate(no)]) # Eq 17 I = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4] J = [0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5] nij = [1.60397357, -0.646013523, 0.111443906, 0.102997357, -0.0504123634, 0.00609859258, 2.33771842, -2.78843778, 1.53616167, -0.463045512, 0.0832827019, -0.00719201245, 2.19650529, -4.54580785, 3.55777244, -1.40944978, 0.275418278, -0.0205938816, -1.21051378, 1.60812989, -0.621178141, 0.0716373224, -2.7203370, 4.57586331, -3.18369245, 1.1168348, -0.19268305, 0.012913842] k1 = exp(d*sum([(1/Tr-1)**i*n*(d-1)**j for i, j, n in zip(I, J, nij)])) # Critical enhancement if fase: R = 0.46151805 if not drho: # Industrial formulation # Eq 25 if d <= 0.310559006: ai = [6.53786807199516, -5.61149954923348, 3.39624167361325, -2.27492629730878, 10.2631854662709, 1.97815050331519] elif d <= 0.776397516: ai = [6.52717759281799, -6.30816983387575, 8.08379285492595, -9.82240510197603, 12.1358413791395, -5.54349664571295] elif d <= 1.242236025: ai = [5.35500529896124, -3.96415689925446, 8.91990208918795, -12.0338729505790, 9.19494865194302, -2.16866274479712] elif d <= 1.863354037: ai = [1.55225959906681, 0.464621290821181, 8.93237374861479, -11.0321960061126, 6.16780999933360, -0.965458722086812] else: ai = [1.11999926419994, 0.595748562571649, 9.88952565078920, -10.3255051147040, 4.66861294457414, -0.503243546373828] drho = 1/sum([a*d**i for i, a in enumerate(ai)])*rhoc/Pc DeltaX = d*(Pc/rhoc*fase.drhodP_T-Pc/rhoc*drho*1.5/Tr) if DeltaX < 0: DeltaX = 0 X = 0.13*(DeltaX/0.06)**(0.63/1.239) # Eq 22 y = X/0.4 # Eq 20 # Eq 19 if y < 1.2e-7: Z = 0 else: Z = 2/pi/y*(((1-1/fase.cp_cv)*atan(y)+y/fase.cp_cv)-( 1-exp(-1/(1/y+y**2/3/d**2)))) # Eq 18 k2 = 177.8514*d*fase.cp/R*Tr/fase.mu*1e-6*Z else: # No critical enhancement k2 = 0 # Eq 10 k = k0*k1+k2 return 1e-3*k
Equation for the thermal conductivity Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] fase: dict, optional for calculate critical enhancement phase properties drho: float, optional for calculate critical enhancement [∂ρ/∂P]T at reference state, Returns ------- k : float Thermal conductivity, [W/mK] Examples -------- >>> _ThCond(998, 298.15) 0.6077128675880629 >>> _ThCond(0, 873.15) 0.07910346589648833 References ---------- IAPWS, Release on the IAPWS Formulation 2011 for the Thermal Conductivity of Ordinary Water Substance, http://www.iapws.org/relguide/ThCond.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L771-L869
jjgomera/iapws
iapws/_iapws.py
_Tension
def _Tension(T): """Equation for the surface tension Parameters ---------- T : float Temperature, [K] Returns ------- σ : float Surface tension, [N/m] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 248.15 ≤ T ≤ 647 * Estrapolate to -25ºC in supercooled liquid metastable state Examples -------- >>> _Tension(300) 0.0716859625 >>> _Tension(450) 0.0428914992 References ---------- IAPWS, Revised Release on Surface Tension of Ordinary Water Substance June 2014, http://www.iapws.org/relguide/Surf-H2O.html """ if 248.15 <= T <= Tc: Tr = T/Tc return 1e-3*(235.8*(1-Tr)**1.256*(1-0.625*(1-Tr))) else: raise NotImplementedError("Incoming out of bound")
python
def _Tension(T): """Equation for the surface tension Parameters ---------- T : float Temperature, [K] Returns ------- σ : float Surface tension, [N/m] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 248.15 ≤ T ≤ 647 * Estrapolate to -25ºC in supercooled liquid metastable state Examples -------- >>> _Tension(300) 0.0716859625 >>> _Tension(450) 0.0428914992 References ---------- IAPWS, Revised Release on Surface Tension of Ordinary Water Substance June 2014, http://www.iapws.org/relguide/Surf-H2O.html """ if 248.15 <= T <= Tc: Tr = T/Tc return 1e-3*(235.8*(1-Tr)**1.256*(1-0.625*(1-Tr))) else: raise NotImplementedError("Incoming out of bound")
Equation for the surface tension Parameters ---------- T : float Temperature, [K] Returns ------- σ : float Surface tension, [N/m] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 248.15 ≤ T ≤ 647 * Estrapolate to -25ºC in supercooled liquid metastable state Examples -------- >>> _Tension(300) 0.0716859625 >>> _Tension(450) 0.0428914992 References ---------- IAPWS, Revised Release on Surface Tension of Ordinary Water Substance June 2014, http://www.iapws.org/relguide/Surf-H2O.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L872-L908
jjgomera/iapws
iapws/_iapws.py
_Dielectric
def _Dielectric(rho, T): """Equation for the Dielectric constant Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- epsilon : float Dielectric constant, [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 238 ≤ T ≤ 1200 Examples -------- >>> _Dielectric(999.242866, 298.15) 78.5907250 >>> _Dielectric(26.0569558, 873.15) 1.12620970 References ---------- IAPWS, Release on the Static Dielectric Constant of Ordinary Water Substance for Temperatures from 238 K to 873 K and Pressures up to 1000 MPa, http://www.iapws.org/relguide/Dielec.html """ # Check input parameters if T < 238 or T > 1200: raise NotImplementedError("Incoming out of bound") k = 1.380658e-23 Na = 6.0221367e23 alfa = 1.636e-40 epsilon0 = 8.854187817e-12 mu = 6.138e-30 d = rho/rhoc Tr = Tc/T I = [1, 1, 1, 2, 3, 3, 4, 5, 6, 7, 10, None] J = [0.25, 1, 2.5, 1.5, 1.5, 2.5, 2, 2, 5, 0.5, 10, None] n = [0.978224486826, -0.957771379375, 0.237511794148, 0.714692244396, -0.298217036956, -0.108863472196, .949327488264e-1, -.980469816509e-2, .165167634970e-4, .937359795772e-4, -.12317921872e-9, .196096504426e-2] g = 1+n[11]*d/(Tc/228/Tr-1)**1.2 for i in range(11): g += n[i]*d**I[i]*Tr**J[i] A = Na*mu**2*rho*g/M*1000/epsilon0/k/T B = Na*alfa*rho/3/M*1000/epsilon0 e = (1+A+5*B+(9+2*A+18*B+A**2+10*A*B+9*B**2)**0.5)/4/(1-B) return e
python
def _Dielectric(rho, T): """Equation for the Dielectric constant Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- epsilon : float Dielectric constant, [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 238 ≤ T ≤ 1200 Examples -------- >>> _Dielectric(999.242866, 298.15) 78.5907250 >>> _Dielectric(26.0569558, 873.15) 1.12620970 References ---------- IAPWS, Release on the Static Dielectric Constant of Ordinary Water Substance for Temperatures from 238 K to 873 K and Pressures up to 1000 MPa, http://www.iapws.org/relguide/Dielec.html """ # Check input parameters if T < 238 or T > 1200: raise NotImplementedError("Incoming out of bound") k = 1.380658e-23 Na = 6.0221367e23 alfa = 1.636e-40 epsilon0 = 8.854187817e-12 mu = 6.138e-30 d = rho/rhoc Tr = Tc/T I = [1, 1, 1, 2, 3, 3, 4, 5, 6, 7, 10, None] J = [0.25, 1, 2.5, 1.5, 1.5, 2.5, 2, 2, 5, 0.5, 10, None] n = [0.978224486826, -0.957771379375, 0.237511794148, 0.714692244396, -0.298217036956, -0.108863472196, .949327488264e-1, -.980469816509e-2, .165167634970e-4, .937359795772e-4, -.12317921872e-9, .196096504426e-2] g = 1+n[11]*d/(Tc/228/Tr-1)**1.2 for i in range(11): g += n[i]*d**I[i]*Tr**J[i] A = Na*mu**2*rho*g/M*1000/epsilon0/k/T B = Na*alfa*rho/3/M*1000/epsilon0 e = (1+A+5*B+(9+2*A+18*B+A**2+10*A*B+9*B**2)**0.5)/4/(1-B) return e
Equation for the Dielectric constant Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- epsilon : float Dielectric constant, [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 238 ≤ T ≤ 1200 Examples -------- >>> _Dielectric(999.242866, 298.15) 78.5907250 >>> _Dielectric(26.0569558, 873.15) 1.12620970 References ---------- IAPWS, Release on the Static Dielectric Constant of Ordinary Water Substance for Temperatures from 238 K to 873 K and Pressures up to 1000 MPa, http://www.iapws.org/relguide/Dielec.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L911-L970
jjgomera/iapws
iapws/_iapws.py
_Refractive
def _Refractive(rho, T, l=0.5893): """Equation for the refractive index Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] l : float, optional Light Wavelength, [μm] Returns ------- n : float Refractive index, [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0 ≤ ρ ≤ 1060 * 261.15 ≤ T ≤ 773.15 * 0.2 ≤ λ ≤ 1.1 Examples -------- >>> _Refractive(997.047435, 298.15, 0.2265) 1.39277824 >>> _Refractive(30.4758534, 773.15, 0.5893) 1.00949307 References ---------- IAPWS, Release on the Refractive Index of Ordinary Water Substance as a Function of Wavelength, Temperature and Pressure, http://www.iapws.org/relguide/rindex.pdf """ # Check input parameters if rho < 0 or rho > 1060 or T < 261.15 or T > 773.15 or l < 0.2 or l > 1.1: raise NotImplementedError("Incoming out of bound") Lir = 5.432937 Luv = 0.229202 d = rho/1000. Tr = T/273.15 L = l/0.589 a = [0.244257733, 0.974634476e-2, -0.373234996e-2, 0.268678472e-3, 0.158920570e-2, 0.245934259e-2, 0.900704920, -0.166626219e-1] A = d*(a[0]+a[1]*d+a[2]*Tr+a[3]*L**2*Tr+a[4]/L**2+a[5]/(L**2-Luv**2)+a[6]/( L**2-Lir**2)+a[7]*d**2) return ((2*A+1)/(1-A))**0.5
python
def _Refractive(rho, T, l=0.5893): """Equation for the refractive index Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] l : float, optional Light Wavelength, [μm] Returns ------- n : float Refractive index, [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0 ≤ ρ ≤ 1060 * 261.15 ≤ T ≤ 773.15 * 0.2 ≤ λ ≤ 1.1 Examples -------- >>> _Refractive(997.047435, 298.15, 0.2265) 1.39277824 >>> _Refractive(30.4758534, 773.15, 0.5893) 1.00949307 References ---------- IAPWS, Release on the Refractive Index of Ordinary Water Substance as a Function of Wavelength, Temperature and Pressure, http://www.iapws.org/relguide/rindex.pdf """ # Check input parameters if rho < 0 or rho > 1060 or T < 261.15 or T > 773.15 or l < 0.2 or l > 1.1: raise NotImplementedError("Incoming out of bound") Lir = 5.432937 Luv = 0.229202 d = rho/1000. Tr = T/273.15 L = l/0.589 a = [0.244257733, 0.974634476e-2, -0.373234996e-2, 0.268678472e-3, 0.158920570e-2, 0.245934259e-2, 0.900704920, -0.166626219e-1] A = d*(a[0]+a[1]*d+a[2]*Tr+a[3]*L**2*Tr+a[4]/L**2+a[5]/(L**2-Luv**2)+a[6]/( L**2-Lir**2)+a[7]*d**2) return ((2*A+1)/(1-A))**0.5
Equation for the refractive index Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] l : float, optional Light Wavelength, [μm] Returns ------- n : float Refractive index, [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0 ≤ ρ ≤ 1060 * 261.15 ≤ T ≤ 773.15 * 0.2 ≤ λ ≤ 1.1 Examples -------- >>> _Refractive(997.047435, 298.15, 0.2265) 1.39277824 >>> _Refractive(30.4758534, 773.15, 0.5893) 1.00949307 References ---------- IAPWS, Release on the Refractive Index of Ordinary Water Substance as a Function of Wavelength, Temperature and Pressure, http://www.iapws.org/relguide/rindex.pdf
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L973-L1024
jjgomera/iapws
iapws/_iapws.py
_Kw
def _Kw(rho, T): """Equation for the ionization constant of ordinary water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- pKw : float Ionization constant in -log10(kw), [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0 ≤ ρ ≤ 1250 * 273.15 ≤ T ≤ 1073.15 Examples -------- >>> _Kw(1000, 300) 13.906565 References ---------- IAPWS, Release on the Ionization Constant of H2O, http://www.iapws.org/relguide/Ionization.pdf """ # Check input parameters if rho < 0 or rho > 1250 or T < 273.15 or T > 1073.15: raise NotImplementedError("Incoming out of bound") # The internal method of calculation use rho in g/cm³ d = rho/1000. # Water molecular weight different Mw = 18.015268 gamma = [6.1415e-1, 4.825133e4, -6.770793e4, 1.01021e7] pKg = 0 for i, g in enumerate(gamma): pKg += g/T**i Q = d*exp(-0.864671+8659.19/T-22786.2/T**2*d**(2./3)) pKw = -12*(log10(1+Q)-Q/(Q+1)*d*(0.642044-56.8534/T-0.375754*d)) + \ pKg+2*log10(Mw/1000) return pKw
python
def _Kw(rho, T): """Equation for the ionization constant of ordinary water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- pKw : float Ionization constant in -log10(kw), [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0 ≤ ρ ≤ 1250 * 273.15 ≤ T ≤ 1073.15 Examples -------- >>> _Kw(1000, 300) 13.906565 References ---------- IAPWS, Release on the Ionization Constant of H2O, http://www.iapws.org/relguide/Ionization.pdf """ # Check input parameters if rho < 0 or rho > 1250 or T < 273.15 or T > 1073.15: raise NotImplementedError("Incoming out of bound") # The internal method of calculation use rho in g/cm³ d = rho/1000. # Water molecular weight different Mw = 18.015268 gamma = [6.1415e-1, 4.825133e4, -6.770793e4, 1.01021e7] pKg = 0 for i, g in enumerate(gamma): pKg += g/T**i Q = d*exp(-0.864671+8659.19/T-22786.2/T**2*d**(2./3)) pKw = -12*(log10(1+Q)-Q/(Q+1)*d*(0.642044-56.8534/T-0.375754*d)) + \ pKg+2*log10(Mw/1000) return pKw
Equation for the ionization constant of ordinary water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- pKw : float Ionization constant in -log10(kw), [-] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0 ≤ ρ ≤ 1250 * 273.15 ≤ T ≤ 1073.15 Examples -------- >>> _Kw(1000, 300) 13.906565 References ---------- IAPWS, Release on the Ionization Constant of H2O, http://www.iapws.org/relguide/Ionization.pdf
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L1027-L1077
jjgomera/iapws
iapws/_iapws.py
_Conductivity
def _Conductivity(rho, T): """Equation for the electrolytic conductivity of liquid and dense supercrítical water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- K : float Electrolytic conductivity, [S/m] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 600 ≤ ρ ≤ 1200 * 273.15 ≤ T ≤ 1073.15 Examples -------- >>> _Conductivity(1000, 373.15) 1.13 References ---------- IAPWS, Electrolytic Conductivity (Specific Conductance) of Liquid and Dense Supercritical Water from 0°C to 800°C and Pressures up to 1000 MPa, http://www.iapws.org/relguide/conduct.pdf """ # FIXME: Dont work rho_ = rho/1000 kw = 10**-_Kw(rho, T) A = [1850., 1410., 2.16417e-6, 1.81609e-7, -1.75297e-9, 7.20708e-12] B = [16., 11.6, 3.26e-4, -2.3e-6, 1.1e-8] t = T-273.15 Loo = A[0]-1/(1/A[1]+sum([A[i+2]*t**(i+1) for i in range(4)])) # Eq 5 rho_h = B[0]-1/(1/B[1]+sum([B[i+2]*t**(i+1) for i in range(3)])) # Eq 6 # Eq 4 L_o = (rho_h-rho_)*Loo/rho_h # Eq 1 k = 100*1e-3*L_o*kw**0.5*rho_ return k
python
def _Conductivity(rho, T): """Equation for the electrolytic conductivity of liquid and dense supercrítical water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- K : float Electrolytic conductivity, [S/m] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 600 ≤ ρ ≤ 1200 * 273.15 ≤ T ≤ 1073.15 Examples -------- >>> _Conductivity(1000, 373.15) 1.13 References ---------- IAPWS, Electrolytic Conductivity (Specific Conductance) of Liquid and Dense Supercritical Water from 0°C to 800°C and Pressures up to 1000 MPa, http://www.iapws.org/relguide/conduct.pdf """ # FIXME: Dont work rho_ = rho/1000 kw = 10**-_Kw(rho, T) A = [1850., 1410., 2.16417e-6, 1.81609e-7, -1.75297e-9, 7.20708e-12] B = [16., 11.6, 3.26e-4, -2.3e-6, 1.1e-8] t = T-273.15 Loo = A[0]-1/(1/A[1]+sum([A[i+2]*t**(i+1) for i in range(4)])) # Eq 5 rho_h = B[0]-1/(1/B[1]+sum([B[i+2]*t**(i+1) for i in range(3)])) # Eq 6 # Eq 4 L_o = (rho_h-rho_)*Loo/rho_h # Eq 1 k = 100*1e-3*L_o*kw**0.5*rho_ return k
Equation for the electrolytic conductivity of liquid and dense supercrítical water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- K : float Electrolytic conductivity, [S/m] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 600 ≤ ρ ≤ 1200 * 273.15 ≤ T ≤ 1073.15 Examples -------- >>> _Conductivity(1000, 373.15) 1.13 References ---------- IAPWS, Electrolytic Conductivity (Specific Conductance) of Liquid and Dense Supercritical Water from 0°C to 800°C and Pressures up to 1000 MPa, http://www.iapws.org/relguide/conduct.pdf
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L1080-L1130
jjgomera/iapws
iapws/_iapws.py
_D2O_Viscosity
def _D2O_Viscosity(rho, T): """Equation for the Viscosity of heavy water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- μ : float Viscosity, [Pa·s] Examples -------- >>> _D2O_Viscosity(998, 298.15) 0.0008897351001498108 >>> _D2O_Viscosity(600, 873.15) 7.743019522728247e-05 References ---------- IAPWS, Revised Release on Viscosity and Thermal Conductivity of Heavy Water Substance, http://www.iapws.org/relguide/TransD2O-2007.pdf """ Tr = T/643.847 rhor = rho/358.0 no = [1.0, 0.940695, 0.578377, -0.202044] fi0 = Tr**0.5/sum([n/Tr**i for i, n in enumerate(no)]) Li = [0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 2, 5, 0, 1, 2, 3, 0, 1, 3, 5, 0, 1, 5, 3] Lj = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6] Lij = [0.4864192, -0.2448372, -0.8702035, 0.8716056, -1.051126, 0.3458395, 0.3509007, 1.315436, 1.297752, 1.353448, -0.2847572, -1.037026, -1.287846, -0.02148229, 0.07013759, 0.4660127, 0.2292075, -0.4857462, 0.01641220, -0.02884911, 0.1607171, -.009603846, -.01163815, -.008239587, 0.004559914, -0.003886659] arr = [lij*(1./Tr-1)**i*(rhor-1)**j for i, j, lij in zip(Li, Lj, Lij)] fi1 = exp(rhor*sum(arr)) return 55.2651e-6*fi0*fi1
python
def _D2O_Viscosity(rho, T): """Equation for the Viscosity of heavy water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- μ : float Viscosity, [Pa·s] Examples -------- >>> _D2O_Viscosity(998, 298.15) 0.0008897351001498108 >>> _D2O_Viscosity(600, 873.15) 7.743019522728247e-05 References ---------- IAPWS, Revised Release on Viscosity and Thermal Conductivity of Heavy Water Substance, http://www.iapws.org/relguide/TransD2O-2007.pdf """ Tr = T/643.847 rhor = rho/358.0 no = [1.0, 0.940695, 0.578377, -0.202044] fi0 = Tr**0.5/sum([n/Tr**i for i, n in enumerate(no)]) Li = [0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 0, 1, 2, 5, 0, 1, 2, 3, 0, 1, 3, 5, 0, 1, 5, 3] Lj = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6] Lij = [0.4864192, -0.2448372, -0.8702035, 0.8716056, -1.051126, 0.3458395, 0.3509007, 1.315436, 1.297752, 1.353448, -0.2847572, -1.037026, -1.287846, -0.02148229, 0.07013759, 0.4660127, 0.2292075, -0.4857462, 0.01641220, -0.02884911, 0.1607171, -.009603846, -.01163815, -.008239587, 0.004559914, -0.003886659] arr = [lij*(1./Tr-1)**i*(rhor-1)**j for i, j, lij in zip(Li, Lj, Lij)] fi1 = exp(rhor*sum(arr)) return 55.2651e-6*fi0*fi1
Equation for the Viscosity of heavy water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- μ : float Viscosity, [Pa·s] Examples -------- >>> _D2O_Viscosity(998, 298.15) 0.0008897351001498108 >>> _D2O_Viscosity(600, 873.15) 7.743019522728247e-05 References ---------- IAPWS, Revised Release on Viscosity and Thermal Conductivity of Heavy Water Substance, http://www.iapws.org/relguide/TransD2O-2007.pdf
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L1134-L1180
jjgomera/iapws
iapws/_iapws.py
_D2O_ThCond
def _D2O_ThCond(rho, T): """Equation for the thermal conductivity of heavy water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- k : float Thermal conductivity, [W/mK] Examples -------- >>> _D2O_ThCond(998, 298.15) 0.6077128675880629 >>> _D2O_ThCond(0, 873.15) 0.07910346589648833 References ---------- IAPWS, Revised Release on Viscosity and Thermal Conductivity of Heavy Water Substance, http://www.iapws.org/relguide/TransD2O-2007.pdf """ rhor = rho/358 Tr = T/643.847 tau = Tr/(abs(Tr-1.1)+1.1) no = [1.0, 37.3223, 22.5485, 13.0465, 0.0, -2.60735] Lo = sum([Li*Tr**i for i, Li in enumerate(no)]) nr = [483.656, -191.039, 73.0358, -7.57467] Lr = -167.31*(1-exp(-2.506*rhor))+sum( [Li*rhor**(i+1) for i, Li in enumerate(nr)]) f1 = exp(0.144847*Tr-5.64493*Tr**2) f2 = exp(-2.8*(rhor-1)**2)-0.080738543*exp(-17.943*(rhor-0.125698)**2) f3 = 1+exp(60*(tau-1)+20) f4 = 1+exp(100*(tau-1)+15) Lc = 35429.6*f1*f2*(1+f2**2*(5e9*f1**4/f3+3.5*f2/f4)) Ll = -741.112*f1**1.2*(1-exp(-(rhor/2.5)**10)) return 0.742128e-3*(Lo+Lr+Lc+Ll)
python
def _D2O_ThCond(rho, T): """Equation for the thermal conductivity of heavy water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- k : float Thermal conductivity, [W/mK] Examples -------- >>> _D2O_ThCond(998, 298.15) 0.6077128675880629 >>> _D2O_ThCond(0, 873.15) 0.07910346589648833 References ---------- IAPWS, Revised Release on Viscosity and Thermal Conductivity of Heavy Water Substance, http://www.iapws.org/relguide/TransD2O-2007.pdf """ rhor = rho/358 Tr = T/643.847 tau = Tr/(abs(Tr-1.1)+1.1) no = [1.0, 37.3223, 22.5485, 13.0465, 0.0, -2.60735] Lo = sum([Li*Tr**i for i, Li in enumerate(no)]) nr = [483.656, -191.039, 73.0358, -7.57467] Lr = -167.31*(1-exp(-2.506*rhor))+sum( [Li*rhor**(i+1) for i, Li in enumerate(nr)]) f1 = exp(0.144847*Tr-5.64493*Tr**2) f2 = exp(-2.8*(rhor-1)**2)-0.080738543*exp(-17.943*(rhor-0.125698)**2) f3 = 1+exp(60*(tau-1)+20) f4 = 1+exp(100*(tau-1)+15) Lc = 35429.6*f1*f2*(1+f2**2*(5e9*f1**4/f3+3.5*f2/f4)) Ll = -741.112*f1**1.2*(1-exp(-(rhor/2.5)**10)) return 0.742128e-3*(Lo+Lr+Lc+Ll)
Equation for the thermal conductivity of heavy water Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- k : float Thermal conductivity, [W/mK] Examples -------- >>> _D2O_ThCond(998, 298.15) 0.6077128675880629 >>> _D2O_ThCond(0, 873.15) 0.07910346589648833 References ---------- IAPWS, Revised Release on Viscosity and Thermal Conductivity of Heavy Water Substance, http://www.iapws.org/relguide/TransD2O-2007.pdf
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L1183-L1229
jjgomera/iapws
iapws/_iapws.py
_D2O_Sublimation_Pressure
def _D2O_Sublimation_Pressure(T): """Sublimation Pressure correlation for heavy water Parameters ---------- T : float Temperature, [K] Returns ------- P : float Pressure at sublimation line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 210 ≤ T ≤ 276.969 Examples -------- >>> _Sublimation_Pressure(245) 3.27390934e-5 References ---------- IAPWS, Revised Release on the IAPWS Formulation 2017 for the Thermodynamic Properties of Heavy Water, http://www.iapws.org/relguide/Heavy.html. """ if 210 <= T <= 276.969: Tita = T/276.969 suma = 0 ai = [-0.1314226e2, 0.3212969e2] ti = [-1.73, -1.42] for a, t in zip(ai, ti): suma += a*(1-Tita**t) return exp(suma)*0.00066159 else: raise NotImplementedError("Incoming out of bound")
python
def _D2O_Sublimation_Pressure(T): """Sublimation Pressure correlation for heavy water Parameters ---------- T : float Temperature, [K] Returns ------- P : float Pressure at sublimation line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 210 ≤ T ≤ 276.969 Examples -------- >>> _Sublimation_Pressure(245) 3.27390934e-5 References ---------- IAPWS, Revised Release on the IAPWS Formulation 2017 for the Thermodynamic Properties of Heavy Water, http://www.iapws.org/relguide/Heavy.html. """ if 210 <= T <= 276.969: Tita = T/276.969 suma = 0 ai = [-0.1314226e2, 0.3212969e2] ti = [-1.73, -1.42] for a, t in zip(ai, ti): suma += a*(1-Tita**t) return exp(suma)*0.00066159 else: raise NotImplementedError("Incoming out of bound")
Sublimation Pressure correlation for heavy water Parameters ---------- T : float Temperature, [K] Returns ------- P : float Pressure at sublimation line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 210 ≤ T ≤ 276.969 Examples -------- >>> _Sublimation_Pressure(245) 3.27390934e-5 References ---------- IAPWS, Revised Release on the IAPWS Formulation 2017 for the Thermodynamic Properties of Heavy Water, http://www.iapws.org/relguide/Heavy.html.
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L1270-L1308
jjgomera/iapws
iapws/_iapws.py
_D2O_Melting_Pressure
def _D2O_Melting_Pressure(T, ice="Ih"): """Melting Pressure correlation for heavy water Parameters ---------- T : float Temperature, [K] ice: string Type of ice: Ih, III, V, VI, VII. Below 276.969 is a mandatory input, the ice Ih is the default value. Above 276.969, the ice type is unnecesary. Returns ------- P : float Pressure at melting line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 254.415 ≤ T ≤ 315 Examples -------- >>> _D2O__Melting_Pressure(260) 8.947352740189152e-06 >>> _D2O__Melting_Pressure(254, "III") 268.6846466336108 References ---------- IAPWS, Revised Release on the Pressure along the Melting and Sublimation Curves of Ordinary Water Substance, http://iapws.org/relguide/MeltSub.html. """ if ice == "Ih" and 254.415 <= T <= 276.969: # Ice Ih, Eq 9 Tita = T/276.969 ai = [-0.30153e5, 0.692503e6] ti = [5.5, 8.2] suma = 1 for a, t in zip(ai, ti): suma += a*(1-Tita**t) P = suma*0.00066159 elif ice == "III" and 254.415 < T <= 258.661: # Ice III, Eq 10 Tita = T/254.415 P = 222.41*(1-0.802871*(1-Tita**33)) elif ice == "V" and 258.661 < T <= 275.748: # Ice V, Eq 11 Tita = T/258.661 P = 352.19*(1-1.280388*(1-Tita**7.6)) elif (ice == "VI" and 275.748 < T <= 276.969) or 276.969 < T <= 315: # Ice VI Tita = T/275.748 P = 634.53*(1-1.276026*(1-Tita**4)) else: raise NotImplementedError("Incoming out of bound") return P
python
def _D2O_Melting_Pressure(T, ice="Ih"): """Melting Pressure correlation for heavy water Parameters ---------- T : float Temperature, [K] ice: string Type of ice: Ih, III, V, VI, VII. Below 276.969 is a mandatory input, the ice Ih is the default value. Above 276.969, the ice type is unnecesary. Returns ------- P : float Pressure at melting line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 254.415 ≤ T ≤ 315 Examples -------- >>> _D2O__Melting_Pressure(260) 8.947352740189152e-06 >>> _D2O__Melting_Pressure(254, "III") 268.6846466336108 References ---------- IAPWS, Revised Release on the Pressure along the Melting and Sublimation Curves of Ordinary Water Substance, http://iapws.org/relguide/MeltSub.html. """ if ice == "Ih" and 254.415 <= T <= 276.969: # Ice Ih, Eq 9 Tita = T/276.969 ai = [-0.30153e5, 0.692503e6] ti = [5.5, 8.2] suma = 1 for a, t in zip(ai, ti): suma += a*(1-Tita**t) P = suma*0.00066159 elif ice == "III" and 254.415 < T <= 258.661: # Ice III, Eq 10 Tita = T/254.415 P = 222.41*(1-0.802871*(1-Tita**33)) elif ice == "V" and 258.661 < T <= 275.748: # Ice V, Eq 11 Tita = T/258.661 P = 352.19*(1-1.280388*(1-Tita**7.6)) elif (ice == "VI" and 275.748 < T <= 276.969) or 276.969 < T <= 315: # Ice VI Tita = T/275.748 P = 634.53*(1-1.276026*(1-Tita**4)) else: raise NotImplementedError("Incoming out of bound") return P
Melting Pressure correlation for heavy water Parameters ---------- T : float Temperature, [K] ice: string Type of ice: Ih, III, V, VI, VII. Below 276.969 is a mandatory input, the ice Ih is the default value. Above 276.969, the ice type is unnecesary. Returns ------- P : float Pressure at melting line, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 254.415 ≤ T ≤ 315 Examples -------- >>> _D2O__Melting_Pressure(260) 8.947352740189152e-06 >>> _D2O__Melting_Pressure(254, "III") 268.6846466336108 References ---------- IAPWS, Revised Release on the Pressure along the Melting and Sublimation Curves of Ordinary Water Substance, http://iapws.org/relguide/MeltSub.html.
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L1311-L1369
jjgomera/iapws
iapws/_iapws.py
_Henry
def _Henry(T, gas, liquid="H2O"): """Equation for the calculation of Henry's constant Parameters ---------- T : float Temperature, [K] gas : string Name of gas to calculate solubility liquid : string Name of liquid solvent, can be H20 (default) or D2O Returns ------- kw : float Henry's constant, [MPa] Notes ----- The gas availables for H2O solvent are He, Ne, Ar, Kr, Xe, H2, N2, O2, CO, CO2, H2S, CH4, C2H6, SF6 For D2O as solvent He, Ne, Ar, Kr, Xe, D2, CH4 Raise :class:`NotImplementedError` if input gas or liquid are unsupported Examples -------- >>> _Henry(500, "He") 1.1973 >>> _Henry(300, "D2", "D2O") 1.6594 References ---------- IAPWS, Guideline on the Henry's Constant and Vapor-Liquid Distribution Constant for Gases in H2O and D2O at High Temperatures, http://www.iapws.org/relguide/HenGuide.html """ if liquid == "D2O": gas += "(D2O)" limit = { "He": (273.21, 553.18), "Ne": (273.20, 543.36), "Ar": (273.19, 568.36), "Kr": (273.19, 525.56), "Xe": (273.22, 574.85), "H2": (273.15, 636.09), "N2": (278.12, 636.46), "O2": (274.15, 616.52), "CO": (278.15, 588.67), "CO2": (274.19, 642.66), "H2S": (273.15, 533.09), "CH4": (275.46, 633.11), "C2H6": (275.44, 473.46), "SF6": (283.14, 505.55), "He(D2O)": (288.15, 553.18), "Ne(D2O)": (288.18, 549.96), "Ar(D2O)": (288.30, 583.76), "Kr(D2O)": (288.19, 523.06), "Xe(D2O)": (295.39, 574.85), "D2(D2O)": (288.17, 581.00), "CH4(D2O)": (288.16, 517.46)} # Check input parameters if liquid != "D2O" and liquid != "H2O": raise NotImplementedError("Solvent liquid unsupported") if gas not in limit: raise NotImplementedError("Gas unsupported") Tmin, Tmax = limit[gas] if T < Tmin or T > Tmax: warnings.warn("Temperature out of data of correlation") if liquid == "D2O": Tc = 643.847 Pc = 21.671 else: Tc = 647.096 Pc = 22.064 Tr = T/Tc tau = 1-Tr # Eq 4 if liquid == "H2O": ai = [-7.85951783, 1.84408259, -11.7866497, 22.6807411, -15.9618719, 1.80122502] bi = [1, 1.5, 3, 3.5, 4, 7.5] else: ai = [-7.896657, 24.73308, -27.81128, 9.355913, -9.220083] bi = [1, 1.89, 2, 3, 3.6] ps = Pc*exp(1/Tr*sum([a*tau**b for a, b in zip(ai, bi)])) # Select values from Table 2 par = { "He": (-3.52839, 7.12983, 4.47770), "Ne": (-3.18301, 5.31448, 5.43774), "Ar": (-8.40954, 4.29587, 10.52779), "Kr": (-8.97358, 3.61508, 11.29963), "Xe": (-14.21635, 4.00041, 15.60999), "H2": (-4.73284, 6.08954, 6.06066), "N2": (-9.67578, 4.72162, 11.70585), "O2": (-9.44833, 4.43822, 11.42005), "CO": (-10.52862, 5.13259, 12.01421), "CO2": (-8.55445, 4.01195, 9.52345), "H2S": (-4.51499, 5.23538, 4.42126), "CH4": (-10.44708, 4.66491, 12.12986), "C2H6": (-19.67563, 4.51222, 20.62567), "SF6": (-16.56118, 2.15289, 20.35440), "He(D2O)": (-0.72643, 7.02134, 2.04433), "Ne(D2O)": (-0.91999, 5.65327, 3.17247), "Ar(D2O)": (-7.17725, 4.48177, 9.31509), "Kr(D2O)": (-8.47059, 3.91580, 10.69433), "Xe(D2O)": (-14.46485, 4.42330, 15.60919), "D2(D2O)": (-5.33843, 6.15723, 6.53046), "CH4(D2O)": (-10.01915, 4.73368, 11.75711)} A, B, C = par[gas] # Eq 3 kh = ps*exp(A/Tr+B*tau**0.355/Tr+C*Tr**-0.41*exp(tau)) return kh
python
def _Henry(T, gas, liquid="H2O"): """Equation for the calculation of Henry's constant Parameters ---------- T : float Temperature, [K] gas : string Name of gas to calculate solubility liquid : string Name of liquid solvent, can be H20 (default) or D2O Returns ------- kw : float Henry's constant, [MPa] Notes ----- The gas availables for H2O solvent are He, Ne, Ar, Kr, Xe, H2, N2, O2, CO, CO2, H2S, CH4, C2H6, SF6 For D2O as solvent He, Ne, Ar, Kr, Xe, D2, CH4 Raise :class:`NotImplementedError` if input gas or liquid are unsupported Examples -------- >>> _Henry(500, "He") 1.1973 >>> _Henry(300, "D2", "D2O") 1.6594 References ---------- IAPWS, Guideline on the Henry's Constant and Vapor-Liquid Distribution Constant for Gases in H2O and D2O at High Temperatures, http://www.iapws.org/relguide/HenGuide.html """ if liquid == "D2O": gas += "(D2O)" limit = { "He": (273.21, 553.18), "Ne": (273.20, 543.36), "Ar": (273.19, 568.36), "Kr": (273.19, 525.56), "Xe": (273.22, 574.85), "H2": (273.15, 636.09), "N2": (278.12, 636.46), "O2": (274.15, 616.52), "CO": (278.15, 588.67), "CO2": (274.19, 642.66), "H2S": (273.15, 533.09), "CH4": (275.46, 633.11), "C2H6": (275.44, 473.46), "SF6": (283.14, 505.55), "He(D2O)": (288.15, 553.18), "Ne(D2O)": (288.18, 549.96), "Ar(D2O)": (288.30, 583.76), "Kr(D2O)": (288.19, 523.06), "Xe(D2O)": (295.39, 574.85), "D2(D2O)": (288.17, 581.00), "CH4(D2O)": (288.16, 517.46)} # Check input parameters if liquid != "D2O" and liquid != "H2O": raise NotImplementedError("Solvent liquid unsupported") if gas not in limit: raise NotImplementedError("Gas unsupported") Tmin, Tmax = limit[gas] if T < Tmin or T > Tmax: warnings.warn("Temperature out of data of correlation") if liquid == "D2O": Tc = 643.847 Pc = 21.671 else: Tc = 647.096 Pc = 22.064 Tr = T/Tc tau = 1-Tr # Eq 4 if liquid == "H2O": ai = [-7.85951783, 1.84408259, -11.7866497, 22.6807411, -15.9618719, 1.80122502] bi = [1, 1.5, 3, 3.5, 4, 7.5] else: ai = [-7.896657, 24.73308, -27.81128, 9.355913, -9.220083] bi = [1, 1.89, 2, 3, 3.6] ps = Pc*exp(1/Tr*sum([a*tau**b for a, b in zip(ai, bi)])) # Select values from Table 2 par = { "He": (-3.52839, 7.12983, 4.47770), "Ne": (-3.18301, 5.31448, 5.43774), "Ar": (-8.40954, 4.29587, 10.52779), "Kr": (-8.97358, 3.61508, 11.29963), "Xe": (-14.21635, 4.00041, 15.60999), "H2": (-4.73284, 6.08954, 6.06066), "N2": (-9.67578, 4.72162, 11.70585), "O2": (-9.44833, 4.43822, 11.42005), "CO": (-10.52862, 5.13259, 12.01421), "CO2": (-8.55445, 4.01195, 9.52345), "H2S": (-4.51499, 5.23538, 4.42126), "CH4": (-10.44708, 4.66491, 12.12986), "C2H6": (-19.67563, 4.51222, 20.62567), "SF6": (-16.56118, 2.15289, 20.35440), "He(D2O)": (-0.72643, 7.02134, 2.04433), "Ne(D2O)": (-0.91999, 5.65327, 3.17247), "Ar(D2O)": (-7.17725, 4.48177, 9.31509), "Kr(D2O)": (-8.47059, 3.91580, 10.69433), "Xe(D2O)": (-14.46485, 4.42330, 15.60919), "D2(D2O)": (-5.33843, 6.15723, 6.53046), "CH4(D2O)": (-10.01915, 4.73368, 11.75711)} A, B, C = par[gas] # Eq 3 kh = ps*exp(A/Tr+B*tau**0.355/Tr+C*Tr**-0.41*exp(tau)) return kh
Equation for the calculation of Henry's constant Parameters ---------- T : float Temperature, [K] gas : string Name of gas to calculate solubility liquid : string Name of liquid solvent, can be H20 (default) or D2O Returns ------- kw : float Henry's constant, [MPa] Notes ----- The gas availables for H2O solvent are He, Ne, Ar, Kr, Xe, H2, N2, O2, CO, CO2, H2S, CH4, C2H6, SF6 For D2O as solvent He, Ne, Ar, Kr, Xe, D2, CH4 Raise :class:`NotImplementedError` if input gas or liquid are unsupported Examples -------- >>> _Henry(500, "He") 1.1973 >>> _Henry(300, "D2", "D2O") 1.6594 References ---------- IAPWS, Guideline on the Henry's Constant and Vapor-Liquid Distribution Constant for Gases in H2O and D2O at High Temperatures, http://www.iapws.org/relguide/HenGuide.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L1372-L1493
jjgomera/iapws
iapws/_iapws.py
_Kvalue
def _Kvalue(T, gas, liquid="H2O"): """Equation for the vapor-liquid distribution constant Parameters ---------- T : float Temperature, [K] gas : string Name of gas to calculate solubility liquid : string Name of liquid solvent, can be H20 (default) or D2O Returns ------- kd : float Vapor-liquid distribution constant, [-] Notes ----- The gas availables for H2O solvent are He, Ne, Ar, Kr, Xe, H2, N2, O2, CO, CO2, H2S, CH4, C2H6, SF6 For D2O as solvent He, Ne, Ar, Kr, Xe, D2, CH4 Raise :class:`NotImplementedError` if input gas or liquid are unsupported Examples -------- >>> _Kvalue(600, "He") 3.8019 >>> _Kvalue(300, "D2", "D2O") 14.3520 References ---------- IAPWS, Guideline on the Henry's Constant and Vapor-Liquid Distribution Constant for Gases in H2O and D2O at High Temperatures, http://www.iapws.org/relguide/HenGuide.html """ if liquid == "D2O": gas += "(D2O)" limit = { "He": (273.21, 553.18), "Ne": (273.20, 543.36), "Ar": (273.19, 568.36), "Kr": (273.19, 525.56), "Xe": (273.22, 574.85), "H2": (273.15, 636.09), "N2": (278.12, 636.46), "O2": (274.15, 616.52), "CO": (278.15, 588.67), "CO2": (274.19, 642.66), "H2S": (273.15, 533.09), "CH4": (275.46, 633.11), "C2H6": (275.44, 473.46), "SF6": (283.14, 505.55), "He(D2O)": (288.15, 553.18), "Ne(D2O)": (288.18, 549.96), "Ar(D2O)": (288.30, 583.76), "Kr(D2O)": (288.19, 523.06), "Xe(D2O)": (295.39, 574.85), "D2(D2O)": (288.17, 581.00), "CH4(D2O)": (288.16, 517.46)} # Check input parameters if liquid != "D2O" and liquid != "H2O": raise NotImplementedError("Solvent liquid unsupported") if gas not in limit: raise NotImplementedError("Gas unsupported") Tmin, Tmax = limit[gas] if T < Tmin or T > Tmax: warnings.warn("Temperature out of data of correlation") if liquid == "D2O": Tc = 643.847 else: Tc = 647.096 Tr = T/Tc tau = 1-Tr # Eq 6 if liquid == "H2O": ci = [1.99274064, 1.09965342, -0.510839303, -1.75493479, -45.5170352, -6.7469445e5] di = [1/3, 2/3, 5/3, 16/3, 43/3, 110/3] q = -0.023767 else: ci = [2.7072, 0.58662, -1.3069, -45.663] di = [0.374, 1.45, 2.6, 12.3] q = -0.024552 f = sum([c*tau**d for c, d in zip(ci, di)]) # Select values from Table 2 par = {"He": (2267.4082, -2.9616, -3.2604, 7.8819), "Ne": (2507.3022, -38.6955, 110.3992, -71.9096), "Ar": (2310.5463, -46.7034, 160.4066, -118.3043), "Kr": (2276.9722, -61.1494, 214.0117, -159.0407), "Xe": (2022.8375, 16.7913, -61.2401, 41.9236), "H2": (2286.4159, 11.3397, -70.7279, 63.0631), "N2": (2388.8777, -14.9593, 42.0179, -29.4396), "O2": (2305.0674, -11.3240, 25.3224, -15.6449), "CO": (2346.2291, -57.6317, 204.5324, -152.6377), "CO2": (1672.9376, 28.1751, -112.4619, 85.3807), "H2S": (1319.1205, 14.1571, -46.8361, 33.2266), "CH4": (2215.6977, -0.1089, -6.6240, 4.6789), "C2H6": (2143.8121, 6.8859, -12.6084, 0), "SF6": (2871.7265, -66.7556, 229.7191, -172.7400), "He(D2O)": (2293.2474, -54.7707, 194.2924, -142.1257), "Ne(D2O)": (2439.6677, -93.4934, 330.7783, -243.0100), "Ar(D2O)": (2269.2352, -53.6321, 191.8421, -143.7659), "Kr(D2O)": (2250.3857, -42.0835, 140.7656, -102.7592), "Xe(D2O)": (2038.3656, 68.1228, -271.3390, 207.7984), "D2(D2O)": (2141.3214, -1.9696, 1.6136, 0), "CH4(D2O)": (2216.0181, -40.7666, 152.5778, -117.7430)} E, F, G, H = par[gas] # Eq 5 kd = exp(q*F+E/T*f+(F+G*tau**(2./3)+H*tau)*exp((273.15-T)/100)) return kd
python
def _Kvalue(T, gas, liquid="H2O"): """Equation for the vapor-liquid distribution constant Parameters ---------- T : float Temperature, [K] gas : string Name of gas to calculate solubility liquid : string Name of liquid solvent, can be H20 (default) or D2O Returns ------- kd : float Vapor-liquid distribution constant, [-] Notes ----- The gas availables for H2O solvent are He, Ne, Ar, Kr, Xe, H2, N2, O2, CO, CO2, H2S, CH4, C2H6, SF6 For D2O as solvent He, Ne, Ar, Kr, Xe, D2, CH4 Raise :class:`NotImplementedError` if input gas or liquid are unsupported Examples -------- >>> _Kvalue(600, "He") 3.8019 >>> _Kvalue(300, "D2", "D2O") 14.3520 References ---------- IAPWS, Guideline on the Henry's Constant and Vapor-Liquid Distribution Constant for Gases in H2O and D2O at High Temperatures, http://www.iapws.org/relguide/HenGuide.html """ if liquid == "D2O": gas += "(D2O)" limit = { "He": (273.21, 553.18), "Ne": (273.20, 543.36), "Ar": (273.19, 568.36), "Kr": (273.19, 525.56), "Xe": (273.22, 574.85), "H2": (273.15, 636.09), "N2": (278.12, 636.46), "O2": (274.15, 616.52), "CO": (278.15, 588.67), "CO2": (274.19, 642.66), "H2S": (273.15, 533.09), "CH4": (275.46, 633.11), "C2H6": (275.44, 473.46), "SF6": (283.14, 505.55), "He(D2O)": (288.15, 553.18), "Ne(D2O)": (288.18, 549.96), "Ar(D2O)": (288.30, 583.76), "Kr(D2O)": (288.19, 523.06), "Xe(D2O)": (295.39, 574.85), "D2(D2O)": (288.17, 581.00), "CH4(D2O)": (288.16, 517.46)} # Check input parameters if liquid != "D2O" and liquid != "H2O": raise NotImplementedError("Solvent liquid unsupported") if gas not in limit: raise NotImplementedError("Gas unsupported") Tmin, Tmax = limit[gas] if T < Tmin or T > Tmax: warnings.warn("Temperature out of data of correlation") if liquid == "D2O": Tc = 643.847 else: Tc = 647.096 Tr = T/Tc tau = 1-Tr # Eq 6 if liquid == "H2O": ci = [1.99274064, 1.09965342, -0.510839303, -1.75493479, -45.5170352, -6.7469445e5] di = [1/3, 2/3, 5/3, 16/3, 43/3, 110/3] q = -0.023767 else: ci = [2.7072, 0.58662, -1.3069, -45.663] di = [0.374, 1.45, 2.6, 12.3] q = -0.024552 f = sum([c*tau**d for c, d in zip(ci, di)]) # Select values from Table 2 par = {"He": (2267.4082, -2.9616, -3.2604, 7.8819), "Ne": (2507.3022, -38.6955, 110.3992, -71.9096), "Ar": (2310.5463, -46.7034, 160.4066, -118.3043), "Kr": (2276.9722, -61.1494, 214.0117, -159.0407), "Xe": (2022.8375, 16.7913, -61.2401, 41.9236), "H2": (2286.4159, 11.3397, -70.7279, 63.0631), "N2": (2388.8777, -14.9593, 42.0179, -29.4396), "O2": (2305.0674, -11.3240, 25.3224, -15.6449), "CO": (2346.2291, -57.6317, 204.5324, -152.6377), "CO2": (1672.9376, 28.1751, -112.4619, 85.3807), "H2S": (1319.1205, 14.1571, -46.8361, 33.2266), "CH4": (2215.6977, -0.1089, -6.6240, 4.6789), "C2H6": (2143.8121, 6.8859, -12.6084, 0), "SF6": (2871.7265, -66.7556, 229.7191, -172.7400), "He(D2O)": (2293.2474, -54.7707, 194.2924, -142.1257), "Ne(D2O)": (2439.6677, -93.4934, 330.7783, -243.0100), "Ar(D2O)": (2269.2352, -53.6321, 191.8421, -143.7659), "Kr(D2O)": (2250.3857, -42.0835, 140.7656, -102.7592), "Xe(D2O)": (2038.3656, 68.1228, -271.3390, 207.7984), "D2(D2O)": (2141.3214, -1.9696, 1.6136, 0), "CH4(D2O)": (2216.0181, -40.7666, 152.5778, -117.7430)} E, F, G, H = par[gas] # Eq 5 kd = exp(q*F+E/T*f+(F+G*tau**(2./3)+H*tau)*exp((273.15-T)/100)) return kd
Equation for the vapor-liquid distribution constant Parameters ---------- T : float Temperature, [K] gas : string Name of gas to calculate solubility liquid : string Name of liquid solvent, can be H20 (default) or D2O Returns ------- kd : float Vapor-liquid distribution constant, [-] Notes ----- The gas availables for H2O solvent are He, Ne, Ar, Kr, Xe, H2, N2, O2, CO, CO2, H2S, CH4, C2H6, SF6 For D2O as solvent He, Ne, Ar, Kr, Xe, D2, CH4 Raise :class:`NotImplementedError` if input gas or liquid are unsupported Examples -------- >>> _Kvalue(600, "He") 3.8019 >>> _Kvalue(300, "D2", "D2O") 14.3520 References ---------- IAPWS, Guideline on the Henry's Constant and Vapor-Liquid Distribution Constant for Gases in H2O and D2O at High Temperatures, http://www.iapws.org/relguide/HenGuide.html
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_iapws.py#L1496-L1617
jjgomera/iapws
iapws/_utils.py
getphase
def getphase(Tc, Pc, T, P, x, region): """Return fluid phase string name Parameters ---------- Tc : float Critical temperature, [K] Pc : float Critical pressure, [MPa] T : float Temperature, [K] P : float Pressure, [MPa] x : float Quality, [-] region: int Region number, used only for IAPWS97 region definition Returns ------- phase : str Phase name """ # Avoid round problem P = round(P, 8) T = round(T, 8) if P > Pc and T > Tc: phase = "Supercritical fluid" elif T > Tc: phase = "Gas" elif P > Pc: phase = "Compressible liquid" elif P == Pc and T == Tc: phase = "Critical point" elif region == 4 and x == 1: phase = "Saturated vapor" elif region == 4 and x == 0: phase = "Saturated liquid" elif region == 4: phase = "Two phases" elif x == 1: phase = "Vapour" elif x == 0: phase = "Liquid" return phase
python
def getphase(Tc, Pc, T, P, x, region): """Return fluid phase string name Parameters ---------- Tc : float Critical temperature, [K] Pc : float Critical pressure, [MPa] T : float Temperature, [K] P : float Pressure, [MPa] x : float Quality, [-] region: int Region number, used only for IAPWS97 region definition Returns ------- phase : str Phase name """ # Avoid round problem P = round(P, 8) T = round(T, 8) if P > Pc and T > Tc: phase = "Supercritical fluid" elif T > Tc: phase = "Gas" elif P > Pc: phase = "Compressible liquid" elif P == Pc and T == Tc: phase = "Critical point" elif region == 4 and x == 1: phase = "Saturated vapor" elif region == 4 and x == 0: phase = "Saturated liquid" elif region == 4: phase = "Two phases" elif x == 1: phase = "Vapour" elif x == 0: phase = "Liquid" return phase
Return fluid phase string name Parameters ---------- Tc : float Critical temperature, [K] Pc : float Critical pressure, [MPa] T : float Temperature, [K] P : float Pressure, [MPa] x : float Quality, [-] region: int Region number, used only for IAPWS97 region definition Returns ------- phase : str Phase name
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_utils.py#L17-L61
jjgomera/iapws
iapws/_utils.py
deriv_H
def deriv_H(state, z, x, y, fase): r"""Calculate generic partial derivative :math:`\left.\frac{\partial z}{\partial x}\right|_{y}` from a fundamental helmholtz free energy equation of state Parameters ---------- state : any python object Only need to define P and T properties, non phase specific properties z : str Name of variables in numerator term of derivatives x : str Name of variables in denominator term of derivatives y : str Name of constant variable in partial derivaritive fase : any python object Define phase specific properties (v, cv, alfap, s, betap) Notes ----- x, y and z can be the following values: * P: Pressure * T: Temperature * v: Specific volume * rho: Density * u: Internal Energy * h: Enthalpy * s: Entropy * g: Gibbs free energy * a: Helmholtz free energy Returns ------- deriv : float ∂z/∂x|y References ---------- IAPWS, Revised Advisory Note No. 3: Thermodynamic Derivatives from IAPWS Formulations, http://www.iapws.org/relguide/Advise3.pdf """ # We use the relation between rho and v and his partial derivative # ∂v/∂b|c = -1/ρ² ∂ρ/∂b|c # ∂a/∂v|c = -ρ² ∂a/∂ρ|c mul = 1 if z == "rho": mul = -fase.rho**2 z = "v" if x == "rho": mul = -1/fase.rho**2 x = "v" if y == "rho": y = "v" dT = {"P": state.P*1000*fase.alfap, "T": 1, "v": 0, "u": fase.cv, "h": fase.cv+state.P*1000*fase.v*fase.alfap, "s": fase.cv/state.T, "g": state.P*1000*fase.v*fase.alfap-fase.s, "a": -fase.s} dv = {"P": -state.P*1000*fase.betap, "T": 0, "v": 1, "u": state.P*1000*(state.T*fase.alfap-1), "h": state.P*1000*(state.T*fase.alfap-fase.v*fase.betap), "s": state.P*1000*fase.alfap, "g": -state.P*1000*fase.v*fase.betap, "a": -state.P*1000} deriv = (dv[z]*dT[y]-dT[z]*dv[y])/(dv[x]*dT[y]-dT[x]*dv[y]) return mul*deriv
python
def deriv_H(state, z, x, y, fase): r"""Calculate generic partial derivative :math:`\left.\frac{\partial z}{\partial x}\right|_{y}` from a fundamental helmholtz free energy equation of state Parameters ---------- state : any python object Only need to define P and T properties, non phase specific properties z : str Name of variables in numerator term of derivatives x : str Name of variables in denominator term of derivatives y : str Name of constant variable in partial derivaritive fase : any python object Define phase specific properties (v, cv, alfap, s, betap) Notes ----- x, y and z can be the following values: * P: Pressure * T: Temperature * v: Specific volume * rho: Density * u: Internal Energy * h: Enthalpy * s: Entropy * g: Gibbs free energy * a: Helmholtz free energy Returns ------- deriv : float ∂z/∂x|y References ---------- IAPWS, Revised Advisory Note No. 3: Thermodynamic Derivatives from IAPWS Formulations, http://www.iapws.org/relguide/Advise3.pdf """ # We use the relation between rho and v and his partial derivative # ∂v/∂b|c = -1/ρ² ∂ρ/∂b|c # ∂a/∂v|c = -ρ² ∂a/∂ρ|c mul = 1 if z == "rho": mul = -fase.rho**2 z = "v" if x == "rho": mul = -1/fase.rho**2 x = "v" if y == "rho": y = "v" dT = {"P": state.P*1000*fase.alfap, "T": 1, "v": 0, "u": fase.cv, "h": fase.cv+state.P*1000*fase.v*fase.alfap, "s": fase.cv/state.T, "g": state.P*1000*fase.v*fase.alfap-fase.s, "a": -fase.s} dv = {"P": -state.P*1000*fase.betap, "T": 0, "v": 1, "u": state.P*1000*(state.T*fase.alfap-1), "h": state.P*1000*(state.T*fase.alfap-fase.v*fase.betap), "s": state.P*1000*fase.alfap, "g": -state.P*1000*fase.v*fase.betap, "a": -state.P*1000} deriv = (dv[z]*dT[y]-dT[z]*dv[y])/(dv[x]*dT[y]-dT[x]*dv[y]) return mul*deriv
r"""Calculate generic partial derivative :math:`\left.\frac{\partial z}{\partial x}\right|_{y}` from a fundamental helmholtz free energy equation of state Parameters ---------- state : any python object Only need to define P and T properties, non phase specific properties z : str Name of variables in numerator term of derivatives x : str Name of variables in denominator term of derivatives y : str Name of constant variable in partial derivaritive fase : any python object Define phase specific properties (v, cv, alfap, s, betap) Notes ----- x, y and z can be the following values: * P: Pressure * T: Temperature * v: Specific volume * rho: Density * u: Internal Energy * h: Enthalpy * s: Entropy * g: Gibbs free energy * a: Helmholtz free energy Returns ------- deriv : float ∂z/∂x|y References ---------- IAPWS, Revised Advisory Note No. 3: Thermodynamic Derivatives from IAPWS Formulations, http://www.iapws.org/relguide/Advise3.pdf
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_utils.py#L119-L191
jjgomera/iapws
iapws/_utils.py
deriv_G
def deriv_G(state, z, x, y, fase): r"""Calculate generic partial derivative :math:`\left.\frac{\partial z}{\partial x}\right|_{y}` from a fundamental Gibbs free energy equation of state Parameters ---------- state : any python object Only need to define P and T properties, non phase specific properties z : str Name of variables in numerator term of derivatives x : str Name of variables in denominator term of derivatives y : str Name of constant variable in partial derivaritive fase : any python object Define phase specific properties (v, cp, alfav, s, xkappa) Notes ----- x, y and z can be the following values: * P: Pressure * T: Temperature * v: Specific volume * rho: Density * u: Internal Energy * h: Enthalpy * s: Entropy * g: Gibbs free energy * a: Helmholtz free energy Returns ------- deriv : float ∂z/∂x|y References ---------- IAPWS, Revised Advisory Note No. 3: Thermodynamic Derivatives from IAPWS Formulations, http://www.iapws.org/relguide/Advise3.pdf """ mul = 1 if z == "rho": mul = -fase.rho**2 z = "v" if x == "rho": mul = -1/fase.rho**2 x = "v" dT = {"P": 0, "T": 1, "v": fase.v*fase.alfav, "u": fase.cp-state.P*1000*fase.v*fase.alfav, "h": fase.cp, "s": fase.cp/state.T, "g": -fase.s, "a": -state.P*1000*fase.v*fase.alfav-fase.s} dP = {"P": 1, "T": 0, "v": -fase.v*fase.xkappa, "u": fase.v*(state.P*1000*fase.xkappa-state.T*fase.alfav), "h": fase.v*(1-state.T*fase.alfav), "s": -fase.v*fase.alfav, "g": fase.v, "a": state.P*1000*fase.v*fase.xkappa} deriv = (dP[z]*dT[y]-dT[z]*dP[y])/(dP[x]*dT[y]-dT[x]*dP[y]) return mul*deriv
python
def deriv_G(state, z, x, y, fase): r"""Calculate generic partial derivative :math:`\left.\frac{\partial z}{\partial x}\right|_{y}` from a fundamental Gibbs free energy equation of state Parameters ---------- state : any python object Only need to define P and T properties, non phase specific properties z : str Name of variables in numerator term of derivatives x : str Name of variables in denominator term of derivatives y : str Name of constant variable in partial derivaritive fase : any python object Define phase specific properties (v, cp, alfav, s, xkappa) Notes ----- x, y and z can be the following values: * P: Pressure * T: Temperature * v: Specific volume * rho: Density * u: Internal Energy * h: Enthalpy * s: Entropy * g: Gibbs free energy * a: Helmholtz free energy Returns ------- deriv : float ∂z/∂x|y References ---------- IAPWS, Revised Advisory Note No. 3: Thermodynamic Derivatives from IAPWS Formulations, http://www.iapws.org/relguide/Advise3.pdf """ mul = 1 if z == "rho": mul = -fase.rho**2 z = "v" if x == "rho": mul = -1/fase.rho**2 x = "v" dT = {"P": 0, "T": 1, "v": fase.v*fase.alfav, "u": fase.cp-state.P*1000*fase.v*fase.alfav, "h": fase.cp, "s": fase.cp/state.T, "g": -fase.s, "a": -state.P*1000*fase.v*fase.alfav-fase.s} dP = {"P": 1, "T": 0, "v": -fase.v*fase.xkappa, "u": fase.v*(state.P*1000*fase.xkappa-state.T*fase.alfav), "h": fase.v*(1-state.T*fase.alfav), "s": -fase.v*fase.alfav, "g": fase.v, "a": state.P*1000*fase.v*fase.xkappa} deriv = (dP[z]*dT[y]-dT[z]*dP[y])/(dP[x]*dT[y]-dT[x]*dP[y]) return mul*deriv
r"""Calculate generic partial derivative :math:`\left.\frac{\partial z}{\partial x}\right|_{y}` from a fundamental Gibbs free energy equation of state Parameters ---------- state : any python object Only need to define P and T properties, non phase specific properties z : str Name of variables in numerator term of derivatives x : str Name of variables in denominator term of derivatives y : str Name of constant variable in partial derivaritive fase : any python object Define phase specific properties (v, cp, alfav, s, xkappa) Notes ----- x, y and z can be the following values: * P: Pressure * T: Temperature * v: Specific volume * rho: Density * u: Internal Energy * h: Enthalpy * s: Entropy * g: Gibbs free energy * a: Helmholtz free energy Returns ------- deriv : float ∂z/∂x|y References ---------- IAPWS, Revised Advisory Note No. 3: Thermodynamic Derivatives from IAPWS Formulations, http://www.iapws.org/relguide/Advise3.pdf
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/_utils.py#L194-L261
jjgomera/iapws
iapws/iapws97.py
_h13_s
def _h13_s(s): """Define the boundary between Region 1 and 3, h=f(s) Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- h : float Specific enthalpy, [kJ/kg] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * s(100MPa,623.15K) ≤ s ≤ s'(623.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations p(h,s) for Region 3, Equations as a Function of h and s for the Region Boundaries, and an Equation Tsat(h,s) for Region 4 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-phs3-2014.pdf. Eq 7 Examples -------- >>> _h13_s(3.7) 1632.525047 >>> _h13_s(3.5) 1566.104611 """ # Check input parameters if s < 3.397782955 or s > 3.77828134: raise NotImplementedError("Incoming out of bound") sigma = s/3.8 I = [0, 1, 1, 3, 5, 6] J = [0, -2, 2, -12, -4, -3] n = [0.913965547600543, -0.430944856041991e-4, 0.603235694765419e2, 0.117518273082168e-17, 0.220000904781292, -0.690815545851641e2] suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (sigma-0.884)**i * (sigma-0.864)**j return 1700 * suma
python
def _h13_s(s): """Define the boundary between Region 1 and 3, h=f(s) Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- h : float Specific enthalpy, [kJ/kg] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * s(100MPa,623.15K) ≤ s ≤ s'(623.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations p(h,s) for Region 3, Equations as a Function of h and s for the Region Boundaries, and an Equation Tsat(h,s) for Region 4 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-phs3-2014.pdf. Eq 7 Examples -------- >>> _h13_s(3.7) 1632.525047 >>> _h13_s(3.5) 1566.104611 """ # Check input parameters if s < 3.397782955 or s > 3.77828134: raise NotImplementedError("Incoming out of bound") sigma = s/3.8 I = [0, 1, 1, 3, 5, 6] J = [0, -2, 2, -12, -4, -3] n = [0.913965547600543, -0.430944856041991e-4, 0.603235694765419e2, 0.117518273082168e-17, 0.220000904781292, -0.690815545851641e2] suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (sigma-0.884)**i * (sigma-0.864)**j return 1700 * suma
Define the boundary between Region 1 and 3, h=f(s) Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- h : float Specific enthalpy, [kJ/kg] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * s(100MPa,623.15K) ≤ s ≤ s'(623.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations p(h,s) for Region 3, Equations as a Function of h and s for the Region Boundaries, and an Equation Tsat(h,s) for Region 4 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-phs3-2014.pdf. Eq 7 Examples -------- >>> _h13_s(3.7) 1632.525047 >>> _h13_s(3.5) 1566.104611
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L106-L153
jjgomera/iapws
iapws/iapws97.py
_PSat_T
def _PSat_T(T): """Define the saturated line, P=f(T) Parameters ---------- T : float Temperature, [K] Returns ------- P : float Pressure, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 273.15 ≤ T ≤ 647.096 References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 30 Examples -------- >>> _PSat_T(500) 2.63889776 """ # Check input parameters if T < 273.15 or T > Tc: raise NotImplementedError("Incoming out of bound") n = [0, 0.11670521452767E+04, -0.72421316703206E+06, -0.17073846940092E+02, 0.12020824702470E+05, -0.32325550322333E+07, 0.14915108613530E+02, -0.48232657361591E+04, 0.40511340542057E+06, -0.23855557567849E+00, 0.65017534844798E+03] tita = T+n[9]/(T-n[10]) A = tita**2+n[1]*tita+n[2] B = n[3]*tita**2+n[4]*tita+n[5] C = n[6]*tita**2+n[7]*tita+n[8] return (2*C/(-B+(B**2-4*A*C)**0.5))**4
python
def _PSat_T(T): """Define the saturated line, P=f(T) Parameters ---------- T : float Temperature, [K] Returns ------- P : float Pressure, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 273.15 ≤ T ≤ 647.096 References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 30 Examples -------- >>> _PSat_T(500) 2.63889776 """ # Check input parameters if T < 273.15 or T > Tc: raise NotImplementedError("Incoming out of bound") n = [0, 0.11670521452767E+04, -0.72421316703206E+06, -0.17073846940092E+02, 0.12020824702470E+05, -0.32325550322333E+07, 0.14915108613530E+02, -0.48232657361591E+04, 0.40511340542057E+06, -0.23855557567849E+00, 0.65017534844798E+03] tita = T+n[9]/(T-n[10]) A = tita**2+n[1]*tita+n[2] B = n[3]*tita**2+n[4]*tita+n[5] C = n[6]*tita**2+n[7]*tita+n[8] return (2*C/(-B+(B**2-4*A*C)**0.5))**4
Define the saturated line, P=f(T) Parameters ---------- T : float Temperature, [K] Returns ------- P : float Pressure, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 273.15 ≤ T ≤ 647.096 References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 30 Examples -------- >>> _PSat_T(500) 2.63889776
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L278-L320
jjgomera/iapws
iapws/iapws97.py
_TSat_P
def _TSat_P(P): """Define the saturated line, T=f(P) Parameters ---------- P : float Pressure, [MPa] Returns ------- T : float Temperature, [K] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0.00061121 ≤ P ≤ 22.064 References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 31 Examples -------- >>> _TSat_P(10) 584.149488 """ # Check input parameters if P < 611.212677/1e6 or P > 22.064: raise NotImplementedError("Incoming out of bound") n = [0, 0.11670521452767E+04, -0.72421316703206E+06, -0.17073846940092E+02, 0.12020824702470E+05, -0.32325550322333E+07, 0.14915108613530E+02, -0.48232657361591E+04, 0.40511340542057E+06, -0.23855557567849E+00, 0.65017534844798E+03] beta = P**0.25 E = beta**2+n[3]*beta+n[6] F = n[1]*beta**2+n[4]*beta+n[7] G = n[2]*beta**2+n[5]*beta+n[8] D = 2*G/(-F-(F**2-4*E*G)**0.5) return (n[10]+D-((n[10]+D)**2-4*(n[9]+n[10]*D))**0.5)/2
python
def _TSat_P(P): """Define the saturated line, T=f(P) Parameters ---------- P : float Pressure, [MPa] Returns ------- T : float Temperature, [K] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0.00061121 ≤ P ≤ 22.064 References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 31 Examples -------- >>> _TSat_P(10) 584.149488 """ # Check input parameters if P < 611.212677/1e6 or P > 22.064: raise NotImplementedError("Incoming out of bound") n = [0, 0.11670521452767E+04, -0.72421316703206E+06, -0.17073846940092E+02, 0.12020824702470E+05, -0.32325550322333E+07, 0.14915108613530E+02, -0.48232657361591E+04, 0.40511340542057E+06, -0.23855557567849E+00, 0.65017534844798E+03] beta = P**0.25 E = beta**2+n[3]*beta+n[6] F = n[1]*beta**2+n[4]*beta+n[7] G = n[2]*beta**2+n[5]*beta+n[8] D = 2*G/(-F-(F**2-4*E*G)**0.5) return (n[10]+D-((n[10]+D)**2-4*(n[9]+n[10]*D))**0.5)/2
Define the saturated line, T=f(P) Parameters ---------- P : float Pressure, [MPa] Returns ------- T : float Temperature, [K] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 0.00061121 ≤ P ≤ 22.064 References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 31 Examples -------- >>> _TSat_P(10) 584.149488
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L323-L366
jjgomera/iapws
iapws/iapws97.py
_PSat_h
def _PSat_h(h): """Define the saturated line, P=f(h) for region 3 Parameters ---------- h : float Specific enthalpy, [kJ/kg] Returns ------- P : float Pressure, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * h'(623.15K) ≤ h ≤ h''(623.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 10 Examples -------- >>> _PSat_h(1700) 17.24175718 >>> _PSat_h(2400) 20.18090839 """ # Check input parameters hmin_Ps3 = _Region1(623.15, Ps_623)["h"] hmax_Ps3 = _Region2(623.15, Ps_623)["h"] if h < hmin_Ps3 or h > hmax_Ps3: raise NotImplementedError("Incoming out of bound") nu = h/2600 I = [0, 1, 1, 1, 1, 5, 7, 8, 14, 20, 22, 24, 28, 36] J = [0, 1, 3, 4, 36, 3, 0, 24, 16, 16, 3, 18, 8, 24] n = [0.600073641753024, -0.936203654849857e1, 0.246590798594147e2, -0.107014222858224e3, -0.915821315805768e14, -0.862332011700662e4, -0.235837344740032e2, 0.252304969384128e18, -0.389718771997719e19, -0.333775713645296e23, 0.356499469636328e11, -0.148547544720641e27, 0.330611514838798e19, 0.813641294467829e38] suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (nu-1.02)**i * (nu-0.608)**j return 22*suma
python
def _PSat_h(h): """Define the saturated line, P=f(h) for region 3 Parameters ---------- h : float Specific enthalpy, [kJ/kg] Returns ------- P : float Pressure, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * h'(623.15K) ≤ h ≤ h''(623.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 10 Examples -------- >>> _PSat_h(1700) 17.24175718 >>> _PSat_h(2400) 20.18090839 """ # Check input parameters hmin_Ps3 = _Region1(623.15, Ps_623)["h"] hmax_Ps3 = _Region2(623.15, Ps_623)["h"] if h < hmin_Ps3 or h > hmax_Ps3: raise NotImplementedError("Incoming out of bound") nu = h/2600 I = [0, 1, 1, 1, 1, 5, 7, 8, 14, 20, 22, 24, 28, 36] J = [0, 1, 3, 4, 36, 3, 0, 24, 16, 16, 3, 18, 8, 24] n = [0.600073641753024, -0.936203654849857e1, 0.246590798594147e2, -0.107014222858224e3, -0.915821315805768e14, -0.862332011700662e4, -0.235837344740032e2, 0.252304969384128e18, -0.389718771997719e19, -0.333775713645296e23, 0.356499469636328e11, -0.148547544720641e27, 0.330611514838798e19, 0.813641294467829e38] suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (nu-1.02)**i * (nu-0.608)**j return 22*suma
Define the saturated line, P=f(h) for region 3 Parameters ---------- h : float Specific enthalpy, [kJ/kg] Returns ------- P : float Pressure, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * h'(623.15K) ≤ h ≤ h''(623.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 10 Examples -------- >>> _PSat_h(1700) 17.24175718 >>> _PSat_h(2400) 20.18090839
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L369-L420
jjgomera/iapws
iapws/iapws97.py
_PSat_s
def _PSat_s(s): """Define the saturated line, P=f(s) for region 3 Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- P : float Pressure, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * s'(623.15K) ≤ s ≤ s''(623.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 11 Examples -------- >>> _PSat_s(3.8) 16.87755057 >>> _PSat_s(5.2) 16.68968482 """ # Check input parameters smin_Ps3 = _Region1(623.15, Ps_623)["s"] smax_Ps3 = _Region2(623.15, Ps_623)["s"] if s < smin_Ps3 or s > smax_Ps3: raise NotImplementedError("Incoming out of bound") sigma = s/5.2 I = [0, 1, 1, 4, 12, 12, 16, 24, 28, 32] J = [0, 1, 32, 7, 4, 14, 36, 10, 0, 18] n = [0.639767553612785, -0.129727445396014e2, -0.224595125848403e16, 0.177466741801846e7, 0.717079349571538e10, -0.378829107169011e18, -0.955586736431328e35, 0.187269814676188e24, 0.119254746466473e12, 0.110649277244882e37] suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (sigma-1.03)**i * (sigma-0.699)**j return 22*suma
python
def _PSat_s(s): """Define the saturated line, P=f(s) for region 3 Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- P : float Pressure, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * s'(623.15K) ≤ s ≤ s''(623.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 11 Examples -------- >>> _PSat_s(3.8) 16.87755057 >>> _PSat_s(5.2) 16.68968482 """ # Check input parameters smin_Ps3 = _Region1(623.15, Ps_623)["s"] smax_Ps3 = _Region2(623.15, Ps_623)["s"] if s < smin_Ps3 or s > smax_Ps3: raise NotImplementedError("Incoming out of bound") sigma = s/5.2 I = [0, 1, 1, 4, 12, 12, 16, 24, 28, 32] J = [0, 1, 32, 7, 4, 14, 36, 10, 0, 18] n = [0.639767553612785, -0.129727445396014e2, -0.224595125848403e16, 0.177466741801846e7, 0.717079349571538e10, -0.378829107169011e18, -0.955586736431328e35, 0.187269814676188e24, 0.119254746466473e12, 0.110649277244882e37] suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (sigma-1.03)**i * (sigma-0.699)**j return 22*suma
Define the saturated line, P=f(s) for region 3 Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- P : float Pressure, [MPa] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * s'(623.15K) ≤ s ≤ s''(623.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 11 Examples -------- >>> _PSat_s(3.8) 16.87755057 >>> _PSat_s(5.2) 16.68968482
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L423-L473
jjgomera/iapws
iapws/iapws97.py
_h2ab_s
def _h2ab_s(s): """Define the saturated line boundary between Region 4 and 2a-2b, h=f(s) Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- h : float Specific enthalpy, [kJ/kg] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 5.85 ≤ s ≤ s"(273.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations p(h,s) for Region 3, Equations as a Function of h and s for the Region Boundaries, and an Equation Tsat(h,s) for Region 4 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-phs3-2014.pdf. Eq 5 Examples -------- >>> _h2ab_s(7) 2723.729985 >>> _h2ab_s(9) 2511.861477 """ # Check input parameters if s < 5.85 or s > 9.155759395: raise NotImplementedError("Incoming out of bound") sigma1 = s/5.21 sigma2 = s/9.2 I = [1, 1, 2, 2, 4, 4, 7, 8, 8, 10, 12, 12, 18, 20, 24, 28, 28, 28, 28, 28, 32, 32, 32, 32, 32, 36, 36, 36, 36, 36] J = [8, 24, 4, 32, 1, 2, 7, 5, 12, 1, 0, 7, 10, 12, 32, 8, 12, 20, 22, 24, 2, 7, 12, 14, 24, 10, 12, 20, 22, 28] n = [-0.524581170928788e3, -0.926947218142218e7, -0.237385107491666e3, 0.210770155812776e11, -0.239494562010986e2, 0.221802480294197e3, -0.510472533393438e7, 0.124981396109147e7, 0.200008436996201e10, -0.815158509791035e3, -0.157612685637523e3, -0.114200422332791e11, 0.662364680776872e16, -0.227622818296144e19, -0.171048081348406e32, 0.660788766938091e16, 0.166320055886021e23, -0.218003784381501e30, -0.787276140295618e30, 0.151062329700346e32, 0.795732170300541e7, 0.131957647355347e16, -0.325097068299140e24, -0.418600611419248e26, 0.297478906557467e35, -0.953588761745473e20, 0.166957699620939e25, -0.175407764869978e33, 0.347581490626396e35, -0.710971318427851e39] suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (1/sigma1-0.513)**i * (sigma2-0.524)**j return 2800*exp(suma)
python
def _h2ab_s(s): """Define the saturated line boundary between Region 4 and 2a-2b, h=f(s) Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- h : float Specific enthalpy, [kJ/kg] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 5.85 ≤ s ≤ s"(273.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations p(h,s) for Region 3, Equations as a Function of h and s for the Region Boundaries, and an Equation Tsat(h,s) for Region 4 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-phs3-2014.pdf. Eq 5 Examples -------- >>> _h2ab_s(7) 2723.729985 >>> _h2ab_s(9) 2511.861477 """ # Check input parameters if s < 5.85 or s > 9.155759395: raise NotImplementedError("Incoming out of bound") sigma1 = s/5.21 sigma2 = s/9.2 I = [1, 1, 2, 2, 4, 4, 7, 8, 8, 10, 12, 12, 18, 20, 24, 28, 28, 28, 28, 28, 32, 32, 32, 32, 32, 36, 36, 36, 36, 36] J = [8, 24, 4, 32, 1, 2, 7, 5, 12, 1, 0, 7, 10, 12, 32, 8, 12, 20, 22, 24, 2, 7, 12, 14, 24, 10, 12, 20, 22, 28] n = [-0.524581170928788e3, -0.926947218142218e7, -0.237385107491666e3, 0.210770155812776e11, -0.239494562010986e2, 0.221802480294197e3, -0.510472533393438e7, 0.124981396109147e7, 0.200008436996201e10, -0.815158509791035e3, -0.157612685637523e3, -0.114200422332791e11, 0.662364680776872e16, -0.227622818296144e19, -0.171048081348406e32, 0.660788766938091e16, 0.166320055886021e23, -0.218003784381501e30, -0.787276140295618e30, 0.151062329700346e32, 0.795732170300541e7, 0.131957647355347e16, -0.325097068299140e24, -0.418600611419248e26, 0.297478906557467e35, -0.953588761745473e20, 0.166957699620939e25, -0.175407764869978e33, 0.347581490626396e35, -0.710971318427851e39] suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (1/sigma1-0.513)**i * (sigma2-0.524)**j return 2800*exp(suma)
Define the saturated line boundary between Region 4 and 2a-2b, h=f(s) Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- h : float Specific enthalpy, [kJ/kg] Notes ------ Raise :class:`NotImplementedError` if input isn't in limit: * 5.85 ≤ s ≤ s"(273.15K) References ---------- IAPWS, Revised Supplementary Release on Backward Equations p(h,s) for Region 3, Equations as a Function of h and s for the Region Boundaries, and an Equation Tsat(h,s) for Region 4 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-phs3-2014.pdf. Eq 5 Examples -------- >>> _h2ab_s(7) 2723.729985 >>> _h2ab_s(9) 2511.861477
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L590-L648
jjgomera/iapws
iapws/iapws97.py
_Region1
def _Region1(T, P): """Basic equation for region 1 Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties. The available properties are: * v: Specific volume, [m³/kg] * h: Specific enthalpy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isocoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s] * alfav: Cubic expansion coefficient, [1/K] * kt: Isothermal compressibility, [1/MPa] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 7 Examples -------- >>> _Region1(300,3)["v"] 0.00100215168 >>> _Region1(300,3)["h"] 115.331273 >>> _Region1(300,3)["h"]-3000*_Region1(300,3)["v"] 112.324818 >>> _Region1(300,80)["s"] 0.368563852 >>> _Region1(300,80)["cp"] 4.01008987 >>> _Region1(300,80)["cv"] 3.91736606 >>> _Region1(500,3)["w"] 1240.71337 >>> _Region1(500,3)["alfav"] 0.00164118128 >>> _Region1(500,3)["kt"] 0.00112892188 """ if P < 0: P = Pmin I = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 8, 8, 21, 23, 29, 30, 31, 32] J = [-2, -1, 0, 1, 2, 3, 4, 5, -9, -7, -1, 0, 1, 3, -3, 0, 1, 3, 17, -4, 0, 6, -5, -2, 10, -8, -11, -6, -29, -31, -38, -39, -40, -41] n = [0.14632971213167, -0.84548187169114, -0.37563603672040e1, 0.33855169168385e1, -0.95791963387872, 0.15772038513228, -0.16616417199501e-1, 0.81214629983568e-3, 0.28319080123804e-3, -0.60706301565874e-3, -0.18990068218419e-1, -0.32529748770505e-1, -0.21841717175414e-1, -0.52838357969930e-4, -0.47184321073267e-3, -0.30001780793026e-3, 0.47661393906987e-4, -0.44141845330846e-5, -0.72694996297594e-15, -0.31679644845054e-4, -0.28270797985312e-5, -0.85205128120103e-9, -0.22425281908000e-5, -0.65171222895601e-6, -0.14341729937924e-12, -0.40516996860117e-6, -0.12734301741641e-8, -0.17424871230634e-9, -0.68762131295531e-18, 0.14478307828521e-19, 0.26335781662795e-22, -0.11947622640071e-22, 0.18228094581404e-23, -0.93537087292458e-25] Tr = 1386/T Pr = P/16.53 g = gp = gpp = gt = gtt = gpt = 0 for i, j, ni in zip(I, J, n): g += ni * (7.1-Pr)**i * (Tr-1.222)**j gp -= ni*i * (7.1-Pr)**(i-1) * (Tr-1.222)**j gpp += ni*i*(i-1) * (7.1-Pr)**(i-2) * (Tr-1.222)**j gt += ni*j * (7.1-Pr)**i * (Tr-1.222)**(j-1) gtt += ni*j*(j-1) * (7.1-Pr)**i * (Tr-1.222)**(j-2) gpt -= ni*i*j * (7.1-Pr)**(i-1) * (Tr-1.222)**(j-1) propiedades = {} propiedades["T"] = T propiedades["P"] = P propiedades["v"] = Pr*gp*R*T/P/1000 propiedades["h"] = Tr*gt*R*T propiedades["s"] = R*(Tr*gt-g) propiedades["cp"] = -R*Tr**2*gtt propiedades["cv"] = R*(-Tr**2*gtt+(gp-Tr*gpt)**2/gpp) propiedades["w"] = sqrt(R*T*1000*gp**2/((gp-Tr*gpt)**2/(Tr**2*gtt)-gpp)) propiedades["alfav"] = (1-Tr*gpt/gp)/T propiedades["kt"] = -Pr*gpp/gp/P propiedades["region"] = 1 propiedades["x"] = 0 return propiedades
python
def _Region1(T, P): """Basic equation for region 1 Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties. The available properties are: * v: Specific volume, [m³/kg] * h: Specific enthalpy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isocoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s] * alfav: Cubic expansion coefficient, [1/K] * kt: Isothermal compressibility, [1/MPa] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 7 Examples -------- >>> _Region1(300,3)["v"] 0.00100215168 >>> _Region1(300,3)["h"] 115.331273 >>> _Region1(300,3)["h"]-3000*_Region1(300,3)["v"] 112.324818 >>> _Region1(300,80)["s"] 0.368563852 >>> _Region1(300,80)["cp"] 4.01008987 >>> _Region1(300,80)["cv"] 3.91736606 >>> _Region1(500,3)["w"] 1240.71337 >>> _Region1(500,3)["alfav"] 0.00164118128 >>> _Region1(500,3)["kt"] 0.00112892188 """ if P < 0: P = Pmin I = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 8, 8, 21, 23, 29, 30, 31, 32] J = [-2, -1, 0, 1, 2, 3, 4, 5, -9, -7, -1, 0, 1, 3, -3, 0, 1, 3, 17, -4, 0, 6, -5, -2, 10, -8, -11, -6, -29, -31, -38, -39, -40, -41] n = [0.14632971213167, -0.84548187169114, -0.37563603672040e1, 0.33855169168385e1, -0.95791963387872, 0.15772038513228, -0.16616417199501e-1, 0.81214629983568e-3, 0.28319080123804e-3, -0.60706301565874e-3, -0.18990068218419e-1, -0.32529748770505e-1, -0.21841717175414e-1, -0.52838357969930e-4, -0.47184321073267e-3, -0.30001780793026e-3, 0.47661393906987e-4, -0.44141845330846e-5, -0.72694996297594e-15, -0.31679644845054e-4, -0.28270797985312e-5, -0.85205128120103e-9, -0.22425281908000e-5, -0.65171222895601e-6, -0.14341729937924e-12, -0.40516996860117e-6, -0.12734301741641e-8, -0.17424871230634e-9, -0.68762131295531e-18, 0.14478307828521e-19, 0.26335781662795e-22, -0.11947622640071e-22, 0.18228094581404e-23, -0.93537087292458e-25] Tr = 1386/T Pr = P/16.53 g = gp = gpp = gt = gtt = gpt = 0 for i, j, ni in zip(I, J, n): g += ni * (7.1-Pr)**i * (Tr-1.222)**j gp -= ni*i * (7.1-Pr)**(i-1) * (Tr-1.222)**j gpp += ni*i*(i-1) * (7.1-Pr)**(i-2) * (Tr-1.222)**j gt += ni*j * (7.1-Pr)**i * (Tr-1.222)**(j-1) gtt += ni*j*(j-1) * (7.1-Pr)**i * (Tr-1.222)**(j-2) gpt -= ni*i*j * (7.1-Pr)**(i-1) * (Tr-1.222)**(j-1) propiedades = {} propiedades["T"] = T propiedades["P"] = P propiedades["v"] = Pr*gp*R*T/P/1000 propiedades["h"] = Tr*gt*R*T propiedades["s"] = R*(Tr*gt-g) propiedades["cp"] = -R*Tr**2*gtt propiedades["cv"] = R*(-Tr**2*gtt+(gp-Tr*gpt)**2/gpp) propiedades["w"] = sqrt(R*T*1000*gp**2/((gp-Tr*gpt)**2/(Tr**2*gtt)-gpp)) propiedades["alfav"] = (1-Tr*gpt/gp)/T propiedades["kt"] = -Pr*gpp/gp/P propiedades["region"] = 1 propiedades["x"] = 0 return propiedades
Basic equation for region 1 Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties. The available properties are: * v: Specific volume, [m³/kg] * h: Specific enthalpy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isocoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s] * alfav: Cubic expansion coefficient, [1/K] * kt: Isothermal compressibility, [1/MPa] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 7 Examples -------- >>> _Region1(300,3)["v"] 0.00100215168 >>> _Region1(300,3)["h"] 115.331273 >>> _Region1(300,3)["h"]-3000*_Region1(300,3)["v"] 112.324818 >>> _Region1(300,80)["s"] 0.368563852 >>> _Region1(300,80)["cp"] 4.01008987 >>> _Region1(300,80)["cv"] 3.91736606 >>> _Region1(500,3)["w"] 1240.71337 >>> _Region1(500,3)["alfav"] 0.00164118128 >>> _Region1(500,3)["kt"] 0.00112892188
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L706-L800
jjgomera/iapws
iapws/iapws97.py
_Backward1_T_Ph
def _Backward1_T_Ph(P, h): """ Backward equation for region 1, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 11 Examples -------- >>> _Backward1_T_Ph(3,500) 391.798509 >>> _Backward1_T_Ph(80,1500) 611.041229 """ I = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 5, 6] J = [0, 1, 2, 6, 22, 32, 0, 1, 2, 3, 4, 10, 32, 10, 32, 10, 32, 32, 32, 32] n = [-0.23872489924521e3, 0.40421188637945e3, 0.11349746881718e3, -0.58457616048039e1, -0.15285482413140e-3, -0.10866707695377e-5, -0.13391744872602e2, 0.43211039183559e2, -0.54010067170506e2, 0.30535892203916e2, -0.65964749423638e1, 0.93965400878363e-2, 0.11573647505340e-6, -0.25858641282073e-4, -0.40644363084799e-8, 0.66456186191635e-7, 0.80670734103027e-10, -0.93477771213947e-12, 0.58265442020601e-14, -0.15020185953503e-16] Pr = P/1 nu = h/2500 T = 0 for i, j, ni in zip(I, J, n): T += ni * Pr**i * (nu+1)**j return T
python
def _Backward1_T_Ph(P, h): """ Backward equation for region 1, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 11 Examples -------- >>> _Backward1_T_Ph(3,500) 391.798509 >>> _Backward1_T_Ph(80,1500) 611.041229 """ I = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 5, 6] J = [0, 1, 2, 6, 22, 32, 0, 1, 2, 3, 4, 10, 32, 10, 32, 10, 32, 32, 32, 32] n = [-0.23872489924521e3, 0.40421188637945e3, 0.11349746881718e3, -0.58457616048039e1, -0.15285482413140e-3, -0.10866707695377e-5, -0.13391744872602e2, 0.43211039183559e2, -0.54010067170506e2, 0.30535892203916e2, -0.65964749423638e1, 0.93965400878363e-2, 0.11573647505340e-6, -0.25858641282073e-4, -0.40644363084799e-8, 0.66456186191635e-7, 0.80670734103027e-10, -0.93477771213947e-12, 0.58265442020601e-14, -0.15020185953503e-16] Pr = P/1 nu = h/2500 T = 0 for i, j, ni in zip(I, J, n): T += ni * Pr**i * (nu+1)**j return T
Backward equation for region 1, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 11 Examples -------- >>> _Backward1_T_Ph(3,500) 391.798509 >>> _Backward1_T_Ph(80,1500) 611.041229
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L803-L847
jjgomera/iapws
iapws/iapws97.py
_Backward1_P_hs
def _Backward1_P_hs(h, s): """Backward equation for region 1, P=f(h,s) Parameters ---------- h : float Specific enthalpy, [kJ/kg] s : float Specific entropy, [kJ/kgK] Returns ------- P : float Pressure, [MPa] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Pressure as a Function of Enthalpy and Entropy p(h,s) for Regions 1 and 2 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-PHS12-2014.pdf, Eq 1 Examples -------- >>> _Backward1_P_hs(0.001,0) 0.0009800980612 >>> _Backward1_P_hs(90,0) 91.92954727 >>> _Backward1_P_hs(1500,3.4) 58.68294423 """ I = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 4, 4, 5] J = [0, 1, 2, 4, 5, 6, 8, 14, 0, 1, 4, 6, 0, 1, 10, 4, 1, 4, 0] n = [-0.691997014660582, -0.183612548787560e2, -0.928332409297335e1, 0.659639569909906e2, -0.162060388912024e2, 0.450620017338667e3, 0.854680678224170e3, 0.607523214001162e4, 0.326487682621856e2, -0.269408844582931e2, -0.319947848334300e3, -0.928354307043320e3, 0.303634537455249e2, -0.650540422444146e2, -0.430991316516130e4, -0.747512324096068e3, 0.730000345529245e3, 0.114284032569021e4, -0.436407041874559e3] nu = h/3400 sigma = s/7.6 P = 0 for i, j, ni in zip(I, J, n): P += ni * (nu+0.05)**i * (sigma+0.05)**j return 100*P
python
def _Backward1_P_hs(h, s): """Backward equation for region 1, P=f(h,s) Parameters ---------- h : float Specific enthalpy, [kJ/kg] s : float Specific entropy, [kJ/kgK] Returns ------- P : float Pressure, [MPa] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Pressure as a Function of Enthalpy and Entropy p(h,s) for Regions 1 and 2 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-PHS12-2014.pdf, Eq 1 Examples -------- >>> _Backward1_P_hs(0.001,0) 0.0009800980612 >>> _Backward1_P_hs(90,0) 91.92954727 >>> _Backward1_P_hs(1500,3.4) 58.68294423 """ I = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 4, 4, 5] J = [0, 1, 2, 4, 5, 6, 8, 14, 0, 1, 4, 6, 0, 1, 10, 4, 1, 4, 0] n = [-0.691997014660582, -0.183612548787560e2, -0.928332409297335e1, 0.659639569909906e2, -0.162060388912024e2, 0.450620017338667e3, 0.854680678224170e3, 0.607523214001162e4, 0.326487682621856e2, -0.269408844582931e2, -0.319947848334300e3, -0.928354307043320e3, 0.303634537455249e2, -0.650540422444146e2, -0.430991316516130e4, -0.747512324096068e3, 0.730000345529245e3, 0.114284032569021e4, -0.436407041874559e3] nu = h/3400 sigma = s/7.6 P = 0 for i, j, ni in zip(I, J, n): P += ni * (nu+0.05)**i * (sigma+0.05)**j return 100*P
Backward equation for region 1, P=f(h,s) Parameters ---------- h : float Specific enthalpy, [kJ/kg] s : float Specific entropy, [kJ/kgK] Returns ------- P : float Pressure, [MPa] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Pressure as a Function of Enthalpy and Entropy p(h,s) for Regions 1 and 2 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-PHS12-2014.pdf, Eq 1 Examples -------- >>> _Backward1_P_hs(0.001,0) 0.0009800980612 >>> _Backward1_P_hs(90,0) 91.92954727 >>> _Backward1_P_hs(1500,3.4) 58.68294423
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L896-L942
jjgomera/iapws
iapws/iapws97.py
_Region2
def _Region2(T, P): """Basic equation for region 2 Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties. The available properties are: * v: Specific volume, [m³/kg] * h: Specific enthalpy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isocoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s] * alfav: Cubic expansion coefficient, [1/K] * kt: Isothermal compressibility, [1/MPa] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 15-17 Examples -------- >>> _Region2(700,30)["v"] 0.00542946619 >>> _Region2(700,30)["h"] 2631.49474 >>> _Region2(700,30)["h"]-30000*_Region2(700,30)["v"] 2468.61076 >>> _Region2(700,0.0035)["s"] 10.1749996 >>> _Region2(700,0.0035)["cp"] 2.08141274 >>> _Region2(700,0.0035)["cv"] 1.61978333 >>> _Region2(300,0.0035)["w"] 427.920172 >>> _Region2(300,0.0035)["alfav"] 0.00337578289 >>> _Region2(300,0.0035)["kt"] 286.239651 """ if P < 0: P = Pmin Tr = 540/T Pr = P/1 go, gop, gopp, got, gott, gopt = Region2_cp0(Tr, Pr) Ir = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9, 10, 10, 10, 16, 16, 18, 20, 20, 20, 21, 22, 23, 24, 24, 24] Jr = [0, 1, 2, 3, 6, 1, 2, 4, 7, 36, 0, 1, 3, 6, 35, 1, 2, 3, 7, 3, 16, 35, 0, 11, 25, 8, 36, 13, 4, 10, 14, 29, 50, 57, 20, 35, 48, 21, 53, 39, 26, 40, 58] nr = [-0.0017731742473212999, -0.017834862292357999, -0.045996013696365003, -0.057581259083432, -0.050325278727930002, -3.3032641670203e-05, -0.00018948987516315, -0.0039392777243355001, -0.043797295650572998, -2.6674547914087001e-05, 2.0481737692308999e-08, 4.3870667284435001e-07, -3.2277677238570002e-05, -0.0015033924542148, -0.040668253562648998, -7.8847309559367001e-10, 1.2790717852285001e-08, 4.8225372718507002e-07, 2.2922076337661001e-06, -1.6714766451061001e-11, -0.0021171472321354998, -23.895741934103999, -5.9059564324270004e-18, -1.2621808899101e-06, -0.038946842435739003, 1.1256211360459e-11, -8.2311340897998004, 1.9809712802088e-08, 1.0406965210174e-19, -1.0234747095929e-13, -1.0018179379511e-09, -8.0882908646984998e-11, 0.10693031879409, -0.33662250574170999, 8.9185845355420999e-25, 3.0629316876231997e-13, -4.2002467698208001e-06, -5.9056029685639003e-26, 3.7826947613457002e-06, -1.2768608934681e-15, 7.3087610595061e-29, 5.5414715350778001e-17, -9.4369707241209998e-07] gr = grp = grpp = grt = grtt = grpt = 0 for i, j, ni in zip(Ir, Jr, nr): gr += ni * Pr**i * (Tr-0.5)**j grp += ni*i * Pr**(i-1) * (Tr-0.5)**j grpp += ni*i*(i-1) * Pr**(i-2) * (Tr-0.5)**j grt += ni*j * Pr**i * (Tr-0.5)**(j-1) grtt += ni*j*(j-1) * Pr**i * (Tr-0.5)**(j-2) grpt += ni*i*j * Pr**(i-1) * (Tr-0.5)**(j-1) propiedades = {} propiedades["T"] = T propiedades["P"] = P propiedades["v"] = Pr*(gop+grp)*R*T/P/1000 propiedades["h"] = Tr*(got+grt)*R*T propiedades["s"] = R*(Tr*(got+grt)-(go+gr)) propiedades["cp"] = -R*Tr**2*(gott+grtt) propiedades["cv"] = R*(-Tr**2*(gott+grtt)-(1+Pr*grp-Tr*Pr*grpt)**2 / (1-Pr**2*grpp)) propiedades["w"] = (R*T*1000*(1+2*Pr*grp+Pr**2*grp**2)/(1-Pr**2*grpp+( 1+Pr*grp-Tr*Pr*grpt)**2/Tr**2/(gott+grtt)))**0.5 propiedades["alfav"] = (1+Pr*grp-Tr*Pr*grpt)/(1+Pr*grp)/T propiedades["kt"] = (1-Pr**2*grpp)/(1+Pr*grp)/P propiedades["region"] = 2 propiedades["x"] = 1 return propiedades
python
def _Region2(T, P): """Basic equation for region 2 Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties. The available properties are: * v: Specific volume, [m³/kg] * h: Specific enthalpy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isocoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s] * alfav: Cubic expansion coefficient, [1/K] * kt: Isothermal compressibility, [1/MPa] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 15-17 Examples -------- >>> _Region2(700,30)["v"] 0.00542946619 >>> _Region2(700,30)["h"] 2631.49474 >>> _Region2(700,30)["h"]-30000*_Region2(700,30)["v"] 2468.61076 >>> _Region2(700,0.0035)["s"] 10.1749996 >>> _Region2(700,0.0035)["cp"] 2.08141274 >>> _Region2(700,0.0035)["cv"] 1.61978333 >>> _Region2(300,0.0035)["w"] 427.920172 >>> _Region2(300,0.0035)["alfav"] 0.00337578289 >>> _Region2(300,0.0035)["kt"] 286.239651 """ if P < 0: P = Pmin Tr = 540/T Pr = P/1 go, gop, gopp, got, gott, gopt = Region2_cp0(Tr, Pr) Ir = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9, 10, 10, 10, 16, 16, 18, 20, 20, 20, 21, 22, 23, 24, 24, 24] Jr = [0, 1, 2, 3, 6, 1, 2, 4, 7, 36, 0, 1, 3, 6, 35, 1, 2, 3, 7, 3, 16, 35, 0, 11, 25, 8, 36, 13, 4, 10, 14, 29, 50, 57, 20, 35, 48, 21, 53, 39, 26, 40, 58] nr = [-0.0017731742473212999, -0.017834862292357999, -0.045996013696365003, -0.057581259083432, -0.050325278727930002, -3.3032641670203e-05, -0.00018948987516315, -0.0039392777243355001, -0.043797295650572998, -2.6674547914087001e-05, 2.0481737692308999e-08, 4.3870667284435001e-07, -3.2277677238570002e-05, -0.0015033924542148, -0.040668253562648998, -7.8847309559367001e-10, 1.2790717852285001e-08, 4.8225372718507002e-07, 2.2922076337661001e-06, -1.6714766451061001e-11, -0.0021171472321354998, -23.895741934103999, -5.9059564324270004e-18, -1.2621808899101e-06, -0.038946842435739003, 1.1256211360459e-11, -8.2311340897998004, 1.9809712802088e-08, 1.0406965210174e-19, -1.0234747095929e-13, -1.0018179379511e-09, -8.0882908646984998e-11, 0.10693031879409, -0.33662250574170999, 8.9185845355420999e-25, 3.0629316876231997e-13, -4.2002467698208001e-06, -5.9056029685639003e-26, 3.7826947613457002e-06, -1.2768608934681e-15, 7.3087610595061e-29, 5.5414715350778001e-17, -9.4369707241209998e-07] gr = grp = grpp = grt = grtt = grpt = 0 for i, j, ni in zip(Ir, Jr, nr): gr += ni * Pr**i * (Tr-0.5)**j grp += ni*i * Pr**(i-1) * (Tr-0.5)**j grpp += ni*i*(i-1) * Pr**(i-2) * (Tr-0.5)**j grt += ni*j * Pr**i * (Tr-0.5)**(j-1) grtt += ni*j*(j-1) * Pr**i * (Tr-0.5)**(j-2) grpt += ni*i*j * Pr**(i-1) * (Tr-0.5)**(j-1) propiedades = {} propiedades["T"] = T propiedades["P"] = P propiedades["v"] = Pr*(gop+grp)*R*T/P/1000 propiedades["h"] = Tr*(got+grt)*R*T propiedades["s"] = R*(Tr*(got+grt)-(go+gr)) propiedades["cp"] = -R*Tr**2*(gott+grtt) propiedades["cv"] = R*(-Tr**2*(gott+grtt)-(1+Pr*grp-Tr*Pr*grpt)**2 / (1-Pr**2*grpp)) propiedades["w"] = (R*T*1000*(1+2*Pr*grp+Pr**2*grp**2)/(1-Pr**2*grpp+( 1+Pr*grp-Tr*Pr*grpt)**2/Tr**2/(gott+grtt)))**0.5 propiedades["alfav"] = (1+Pr*grp-Tr*Pr*grpt)/(1+Pr*grp)/T propiedades["kt"] = (1-Pr**2*grpp)/(1+Pr*grp)/P propiedades["region"] = 2 propiedades["x"] = 1 return propiedades
Basic equation for region 2 Parameters ---------- T : float Temperature, [K] P : float Pressure, [MPa] Returns ------- prop : dict Dict with calculated properties. The available properties are: * v: Specific volume, [m³/kg] * h: Specific enthalpy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isocoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s] * alfav: Cubic expansion coefficient, [1/K] * kt: Isothermal compressibility, [1/MPa] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 15-17 Examples -------- >>> _Region2(700,30)["v"] 0.00542946619 >>> _Region2(700,30)["h"] 2631.49474 >>> _Region2(700,30)["h"]-30000*_Region2(700,30)["v"] 2468.61076 >>> _Region2(700,0.0035)["s"] 10.1749996 >>> _Region2(700,0.0035)["cp"] 2.08141274 >>> _Region2(700,0.0035)["cv"] 1.61978333 >>> _Region2(300,0.0035)["w"] 427.920172 >>> _Region2(300,0.0035)["alfav"] 0.00337578289 >>> _Region2(300,0.0035)["kt"] 286.239651
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L946-L1053
jjgomera/iapws
iapws/iapws97.py
Region2_cp0
def Region2_cp0(Tr, Pr): """Ideal properties for Region 2 Parameters ---------- Tr : float Reduced temperature, [-] Pr : float Reduced pressure, [-] Returns ------- prop : array Array with ideal Gibbs energy partial derivatives: * g: Ideal Specific Gibbs energy [kJ/kg] * gp: ∂g/∂P|T * gpp: ∂²g/∂P²|T * gt: ∂g/∂T|P * gtt: ∂²g/∂T²|P * gpt: ∂²g/∂T∂P References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 16 """ Jo = [0, 1, -5, -4, -3, -2, -1, 2, 3] no = [-0.96927686500217E+01, 0.10086655968018E+02, -0.56087911283020E-02, 0.71452738081455E-01, -0.40710498223928E+00, 0.14240819171444E+01, -0.43839511319450E+01, -0.28408632460772E+00, 0.21268463753307E-01] go = log(Pr) gop = Pr**-1 gopp = -Pr**-2 got = gott = gopt = 0 for j, ni in zip(Jo, no): go += ni * Tr**j got += ni*j * Tr**(j-1) gott += ni*j*(j-1) * Tr**(j-2) return go, gop, gopp, got, gott, gopt
python
def Region2_cp0(Tr, Pr): """Ideal properties for Region 2 Parameters ---------- Tr : float Reduced temperature, [-] Pr : float Reduced pressure, [-] Returns ------- prop : array Array with ideal Gibbs energy partial derivatives: * g: Ideal Specific Gibbs energy [kJ/kg] * gp: ∂g/∂P|T * gpp: ∂²g/∂P²|T * gt: ∂g/∂T|P * gtt: ∂²g/∂T²|P * gpt: ∂²g/∂T∂P References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 16 """ Jo = [0, 1, -5, -4, -3, -2, -1, 2, 3] no = [-0.96927686500217E+01, 0.10086655968018E+02, -0.56087911283020E-02, 0.71452738081455E-01, -0.40710498223928E+00, 0.14240819171444E+01, -0.43839511319450E+01, -0.28408632460772E+00, 0.21268463753307E-01] go = log(Pr) gop = Pr**-1 gopp = -Pr**-2 got = gott = gopt = 0 for j, ni in zip(Jo, no): go += ni * Tr**j got += ni*j * Tr**(j-1) gott += ni*j*(j-1) * Tr**(j-2) return go, gop, gopp, got, gott, gopt
Ideal properties for Region 2 Parameters ---------- Tr : float Reduced temperature, [-] Pr : float Reduced pressure, [-] Returns ------- prop : array Array with ideal Gibbs energy partial derivatives: * g: Ideal Specific Gibbs energy [kJ/kg] * gp: ∂g/∂P|T * gpp: ∂²g/∂P²|T * gt: ∂g/∂T|P * gtt: ∂²g/∂T²|P * gpt: ∂²g/∂T∂P References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 16
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L1056-L1097
jjgomera/iapws
iapws/iapws97.py
_hab_s
def _hab_s(s): """Define the boundary between Region 2a and 2b, h=f(s) Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- h : float Specific enthalpy, [kJ/kg] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Pressure as a Function of Enthalpy and Entropy p(h,s) for Regions 1 and 2 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-PHS12-2014.pdf, Eq 2 Examples -------- >>> _hab_s(7) 3376.437884 """ smin = _Region2(_TSat_P(4), 4)["s"] smax = _Region2(1073.15, 4)["s"] if s < smin: h = 0 elif s > smax: h = 5000 else: h = -0.349898083432139e4 + 0.257560716905876e4*s - \ 0.421073558227969e3*s**2+0.276349063799944e2*s**3 return h
python
def _hab_s(s): """Define the boundary between Region 2a and 2b, h=f(s) Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- h : float Specific enthalpy, [kJ/kg] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Pressure as a Function of Enthalpy and Entropy p(h,s) for Regions 1 and 2 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-PHS12-2014.pdf, Eq 2 Examples -------- >>> _hab_s(7) 3376.437884 """ smin = _Region2(_TSat_P(4), 4)["s"] smax = _Region2(1073.15, 4)["s"] if s < smin: h = 0 elif s > smax: h = 5000 else: h = -0.349898083432139e4 + 0.257560716905876e4*s - \ 0.421073558227969e3*s**2+0.276349063799944e2*s**3 return h
Define the boundary between Region 2a and 2b, h=f(s) Parameters ---------- s : float Specific entropy, [kJ/kgK] Returns ------- h : float Specific enthalpy, [kJ/kg] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Pressure as a Function of Enthalpy and Entropy p(h,s) for Regions 1 and 2 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-PHS12-2014.pdf, Eq 2 Examples -------- >>> _hab_s(7) 3376.437884
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L1154-L1188
jjgomera/iapws
iapws/iapws97.py
_Backward2_T_Ph
def _Backward2_T_Ph(P, h): """Backward equation for region 2, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K] """ if P <= 4: T = _Backward2a_T_Ph(P, h) elif 4 < P <= 6.546699678: T = _Backward2b_T_Ph(P, h) else: hf = _hbc_P(P) if h >= hf: T = _Backward2b_T_Ph(P, h) else: T = _Backward2c_T_Ph(P, h) if P <= 22.064: Tsat = _TSat_P(P) T = max(Tsat, T) return T
python
def _Backward2_T_Ph(P, h): """Backward equation for region 2, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K] """ if P <= 4: T = _Backward2a_T_Ph(P, h) elif 4 < P <= 6.546699678: T = _Backward2b_T_Ph(P, h) else: hf = _hbc_P(P) if h >= hf: T = _Backward2b_T_Ph(P, h) else: T = _Backward2c_T_Ph(P, h) if P <= 22.064: Tsat = _TSat_P(P) T = max(Tsat, T) return T
Backward equation for region 2, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K]
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L1347-L1376
jjgomera/iapws
iapws/iapws97.py
_Backward2a_T_Ps
def _Backward2a_T_Ps(P, s): """Backward equation for region 2a, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 25 Examples -------- >>> _Backward2a_T_Ps(0.1,7.5) 399.517097 >>> _Backward2a_T_Ps(2.5,8) 1039.84917 """ I = [-1.5, -1.5, -1.5, -1.5, -1.5, -1.5, -1.25, -1.25, -1.25, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.75, -0.75, -0.5, -0.5, -0.5, -0.5, -0.25, -0.25, -0.25, -0.25, 0.25, 0.25, 0.25, 0.25, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.75, 0.75, 0.75, 0.75, 1.0, 1.0, 1.25, 1.25, 1.5, 1.5] J = [-24, -23, -19, -13, -11, -10, -19, -15, -6, -26, -21, -17, -16, -9, -8, -15, -14, -26, -13, -9, -7, -27, -25, -11, -6, 1, 4, 8, 11, 0, 1, 5, 6, 10, 14, 16, 0, 4, 9, 17, 7, 18, 3, 15, 5, 18] n = [-0.39235983861984e6, 0.51526573827270e6, 0.40482443161048e5, -0.32193790923902e3, 0.96961424218694e2, -0.22867846371773e2, -0.44942914124357e6, -0.50118336020166e4, 0.35684463560015, 0.44235335848190e5, -0.13673388811708e5, 0.42163260207864e6, 0.22516925837475e5, 0.47442144865646e3, -0.14931130797647e3, -0.19781126320452e6, -0.23554399470760e5, -0.19070616302076e5, 0.55375669883164e5, 0.38293691437363e4, -0.60391860580567e3, 0.19363102620331e4, 0.42660643698610e4, -0.59780638872718e4, -0.70401463926862e3, 0.33836784107553e3, 0.20862786635187e2, 0.33834172656196e-1, -0.43124428414893e-4, 0.16653791356412e3, -0.13986292055898e3, -0.78849547999872, 0.72132411753872e-1, -0.59754839398283e-2, -0.12141358953904e-4, 0.23227096733871e-6, -0.10538463566194e2, 0.20718925496502e1, -0.72193155260427e-1, 0.20749887081120e-6, -0.18340657911379e-1, 0.29036272348696e-6, 0.21037527893619, 0.25681239729999e-3, -0.12799002933781e-1, -0.82198102652018e-5] Pr = P/1 sigma = s/2 T = 0 for i, j, ni in zip(I, J, n): T += ni * Pr**i * (sigma-2)**j return T
python
def _Backward2a_T_Ps(P, s): """Backward equation for region 2a, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 25 Examples -------- >>> _Backward2a_T_Ps(0.1,7.5) 399.517097 >>> _Backward2a_T_Ps(2.5,8) 1039.84917 """ I = [-1.5, -1.5, -1.5, -1.5, -1.5, -1.5, -1.25, -1.25, -1.25, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.75, -0.75, -0.5, -0.5, -0.5, -0.5, -0.25, -0.25, -0.25, -0.25, 0.25, 0.25, 0.25, 0.25, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.75, 0.75, 0.75, 0.75, 1.0, 1.0, 1.25, 1.25, 1.5, 1.5] J = [-24, -23, -19, -13, -11, -10, -19, -15, -6, -26, -21, -17, -16, -9, -8, -15, -14, -26, -13, -9, -7, -27, -25, -11, -6, 1, 4, 8, 11, 0, 1, 5, 6, 10, 14, 16, 0, 4, 9, 17, 7, 18, 3, 15, 5, 18] n = [-0.39235983861984e6, 0.51526573827270e6, 0.40482443161048e5, -0.32193790923902e3, 0.96961424218694e2, -0.22867846371773e2, -0.44942914124357e6, -0.50118336020166e4, 0.35684463560015, 0.44235335848190e5, -0.13673388811708e5, 0.42163260207864e6, 0.22516925837475e5, 0.47442144865646e3, -0.14931130797647e3, -0.19781126320452e6, -0.23554399470760e5, -0.19070616302076e5, 0.55375669883164e5, 0.38293691437363e4, -0.60391860580567e3, 0.19363102620331e4, 0.42660643698610e4, -0.59780638872718e4, -0.70401463926862e3, 0.33836784107553e3, 0.20862786635187e2, 0.33834172656196e-1, -0.43124428414893e-4, 0.16653791356412e3, -0.13986292055898e3, -0.78849547999872, 0.72132411753872e-1, -0.59754839398283e-2, -0.12141358953904e-4, 0.23227096733871e-6, -0.10538463566194e2, 0.20718925496502e1, -0.72193155260427e-1, 0.20749887081120e-6, -0.18340657911379e-1, 0.29036272348696e-6, 0.21037527893619, 0.25681239729999e-3, -0.12799002933781e-1, -0.82198102652018e-5] Pr = P/1 sigma = s/2 T = 0 for i, j, ni in zip(I, J, n): T += ni * Pr**i * (sigma-2)**j return T
Backward equation for region 2a, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 25 Examples -------- >>> _Backward2a_T_Ps(0.1,7.5) 399.517097 >>> _Backward2a_T_Ps(2.5,8) 1039.84917
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L1379-L1436
jjgomera/iapws
iapws/iapws97.py
_Backward2_T_Ps
def _Backward2_T_Ps(P, s): """Backward equation for region 2, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K] """ if P <= 4: T = _Backward2a_T_Ps(P, s) elif s >= 5.85: T = _Backward2b_T_Ps(P, s) else: T = _Backward2c_T_Ps(P, s) if P <= 22.064: Tsat = _TSat_P(P) T = max(Tsat, T) return T
python
def _Backward2_T_Ps(P, s): """Backward equation for region 2, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K] """ if P <= 4: T = _Backward2a_T_Ps(P, s) elif s >= 5.85: T = _Backward2b_T_Ps(P, s) else: T = _Backward2c_T_Ps(P, s) if P <= 22.064: Tsat = _TSat_P(P) T = max(Tsat, T) return T
Backward equation for region 2, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K]
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L1547-L1572
jjgomera/iapws
iapws/iapws97.py
_Backward2_P_hs
def _Backward2_P_hs(h, s): """Backward equation for region 2, P=f(h,s) Parameters ---------- h : float Specific enthalpy, [kJ/kg] s : float Specific entropy, [kJ/kgK] Returns ------- P : float Pressure, [MPa] """ sfbc = 5.85 hamin = _hab_s(s) if h <= hamin: P = _Backward2a_P_hs(h, s) elif s >= sfbc: P = _Backward2b_P_hs(h, s) else: P = _Backward2c_P_hs(h, s) return P
python
def _Backward2_P_hs(h, s): """Backward equation for region 2, P=f(h,s) Parameters ---------- h : float Specific enthalpy, [kJ/kg] s : float Specific entropy, [kJ/kgK] Returns ------- P : float Pressure, [MPa] """ sfbc = 5.85 hamin = _hab_s(s) if h <= hamin: P = _Backward2a_P_hs(h, s) elif s >= sfbc: P = _Backward2b_P_hs(h, s) else: P = _Backward2c_P_hs(h, s) return P
Backward equation for region 2, P=f(h,s) Parameters ---------- h : float Specific enthalpy, [kJ/kg] s : float Specific entropy, [kJ/kgK] Returns ------- P : float Pressure, [MPa]
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L1739-L1762
jjgomera/iapws
iapws/iapws97.py
_Region3
def _Region3(rho, T): """Basic equation for region 3 Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- prop : dict Dict with calculated properties. The available properties are: * v: Specific volume, [m³/kg] * h: Specific enthalpy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isocoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s] * alfav: Cubic expansion coefficient, [1/K] * kt: Isothermal compressibility, [1/MPa] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 28 Examples -------- >>> _Region3(500,650)["P"] 25.5837018 >>> _Region3(500,650)["h"] 1863.43019 >>> p = _Region3(500, 650) >>> p["h"]-p["P"]*1000*p["v"] 1812.26279 >>> _Region3(200,650)["s"] 4.85438792 >>> _Region3(200,650)["cp"] 44.6579342 >>> _Region3(200,650)["cv"] 4.04118076 >>> _Region3(200,650)["w"] 383.444594 >>> _Region3(500,750)["alfav"] 0.00441515098 >>> _Region3(500,750)["kt"] 0.00806710817 """ I = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 8, 9, 9, 10, 10, 11] J = [0, 1, 2, 7, 10, 12, 23, 2, 6, 15, 17, 0, 2, 6, 7, 22, 26, 0, 2, 4, 16, 26, 0, 2, 4, 26, 1, 3, 26, 0, 2, 26, 2, 26, 2, 26, 0, 1, 26] n = [-0.15732845290239e2, 0.20944396974307e2, -0.76867707878716e1, 0.26185947787954e1, -0.28080781148620e1, 0.12053369696517e1, -0.84566812812502e-2, -0.12654315477714e1, -0.11524407806681e1, 0.88521043984318, -0.64207765181607, 0.38493460186671, -0.85214708824206, 0.48972281541877e1, -0.30502617256965e1, 0.39420536879154e-1, 0.12558408424308, -0.27999329698710, 0.13899799569460e1, -0.20189915023570e1, -0.82147637173963e-2, -0.47596035734923, 0.43984074473500e-1, -0.44476435428739, 0.90572070719733, .70522450087967, .10770512626332, -0.32913623258954, -0.50871062041158, -0.22175400873096e-1, 0.94260751665092e-1, 0.16436278447961, -0.13503372241348e-1, -0.14834345352472e-1, 0.57922953628084e-3, 0.32308904703711e-2, 0.80964802996215e-4, -0.16557679795037e-3, -0.44923899061815e-4] d = rho/rhoc Tr = Tc/T g = 1.0658070028513*log(d) gd = 1.0658070028513/d gdd = -1.0658070028513/d**2 gt = gtt = gdt = 0 for i, j, ni in zip(I, J, n): g += ni * d**i * Tr**j gd += ni*i * d**(i-1) * Tr**j gdd += ni*i*(i-1) * d**(i-2) * Tr**j gt += ni*j * d**i * Tr**(j-1) gtt += ni*j*(j-1) * d**i * Tr**(j-2) gdt += ni*i*j * d**(i-1) * Tr**(j-1) propiedades = {} propiedades["T"] = T propiedades["P"] = d*gd*R*T*rho/1000 propiedades["v"] = 1/rho propiedades["h"] = R*T*(Tr*gt+d*gd) propiedades["s"] = R*(Tr*gt-g) propiedades["cp"] = R*(-Tr**2*gtt+(d*gd-d*Tr*gdt)**2/(2*d*gd+d**2*gdd)) propiedades["cv"] = -R*Tr**2*gtt propiedades["w"] = sqrt(R*T*1000*(2*d*gd+d**2*gdd-(d*gd-d*Tr*gdt)**2 / Tr**2/gtt)) propiedades["alfav"] = (gd-Tr*gdt)/(2*gd+d*gdd)/T propiedades["kt"] = 1/(2*d*gd+d**2*gdd)/rho/R/T*1000 propiedades["region"] = 3 propiedades["x"] = 1 return propiedades
python
def _Region3(rho, T): """Basic equation for region 3 Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- prop : dict Dict with calculated properties. The available properties are: * v: Specific volume, [m³/kg] * h: Specific enthalpy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isocoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s] * alfav: Cubic expansion coefficient, [1/K] * kt: Isothermal compressibility, [1/MPa] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 28 Examples -------- >>> _Region3(500,650)["P"] 25.5837018 >>> _Region3(500,650)["h"] 1863.43019 >>> p = _Region3(500, 650) >>> p["h"]-p["P"]*1000*p["v"] 1812.26279 >>> _Region3(200,650)["s"] 4.85438792 >>> _Region3(200,650)["cp"] 44.6579342 >>> _Region3(200,650)["cv"] 4.04118076 >>> _Region3(200,650)["w"] 383.444594 >>> _Region3(500,750)["alfav"] 0.00441515098 >>> _Region3(500,750)["kt"] 0.00806710817 """ I = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 8, 9, 9, 10, 10, 11] J = [0, 1, 2, 7, 10, 12, 23, 2, 6, 15, 17, 0, 2, 6, 7, 22, 26, 0, 2, 4, 16, 26, 0, 2, 4, 26, 1, 3, 26, 0, 2, 26, 2, 26, 2, 26, 0, 1, 26] n = [-0.15732845290239e2, 0.20944396974307e2, -0.76867707878716e1, 0.26185947787954e1, -0.28080781148620e1, 0.12053369696517e1, -0.84566812812502e-2, -0.12654315477714e1, -0.11524407806681e1, 0.88521043984318, -0.64207765181607, 0.38493460186671, -0.85214708824206, 0.48972281541877e1, -0.30502617256965e1, 0.39420536879154e-1, 0.12558408424308, -0.27999329698710, 0.13899799569460e1, -0.20189915023570e1, -0.82147637173963e-2, -0.47596035734923, 0.43984074473500e-1, -0.44476435428739, 0.90572070719733, .70522450087967, .10770512626332, -0.32913623258954, -0.50871062041158, -0.22175400873096e-1, 0.94260751665092e-1, 0.16436278447961, -0.13503372241348e-1, -0.14834345352472e-1, 0.57922953628084e-3, 0.32308904703711e-2, 0.80964802996215e-4, -0.16557679795037e-3, -0.44923899061815e-4] d = rho/rhoc Tr = Tc/T g = 1.0658070028513*log(d) gd = 1.0658070028513/d gdd = -1.0658070028513/d**2 gt = gtt = gdt = 0 for i, j, ni in zip(I, J, n): g += ni * d**i * Tr**j gd += ni*i * d**(i-1) * Tr**j gdd += ni*i*(i-1) * d**(i-2) * Tr**j gt += ni*j * d**i * Tr**(j-1) gtt += ni*j*(j-1) * d**i * Tr**(j-2) gdt += ni*i*j * d**(i-1) * Tr**(j-1) propiedades = {} propiedades["T"] = T propiedades["P"] = d*gd*R*T*rho/1000 propiedades["v"] = 1/rho propiedades["h"] = R*T*(Tr*gt+d*gd) propiedades["s"] = R*(Tr*gt-g) propiedades["cp"] = R*(-Tr**2*gtt+(d*gd-d*Tr*gdt)**2/(2*d*gd+d**2*gdd)) propiedades["cv"] = -R*Tr**2*gtt propiedades["w"] = sqrt(R*T*1000*(2*d*gd+d**2*gdd-(d*gd-d*Tr*gdt)**2 / Tr**2/gtt)) propiedades["alfav"] = (gd-Tr*gdt)/(2*gd+d*gdd)/T propiedades["kt"] = 1/(2*d*gd+d**2*gdd)/rho/R/T*1000 propiedades["region"] = 3 propiedades["x"] = 1 return propiedades
Basic equation for region 3 Parameters ---------- rho : float Density, [kg/m³] T : float Temperature, [K] Returns ------- prop : dict Dict with calculated properties. The available properties are: * v: Specific volume, [m³/kg] * h: Specific enthalpy, [kJ/kg] * s: Specific entropy, [kJ/kgK] * cp: Specific isobaric heat capacity, [kJ/kgK] * cv: Specific isocoric heat capacity, [kJ/kgK] * w: Speed of sound, [m/s] * alfav: Cubic expansion coefficient, [1/K] * kt: Isothermal compressibility, [1/MPa] References ---------- IAPWS, Revised Release on the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam August 2007, http://www.iapws.org/relguide/IF97-Rev.html, Eq 28 Examples -------- >>> _Region3(500,650)["P"] 25.5837018 >>> _Region3(500,650)["h"] 1863.43019 >>> p = _Region3(500, 650) >>> p["h"]-p["P"]*1000*p["v"] 1812.26279 >>> _Region3(200,650)["s"] 4.85438792 >>> _Region3(200,650)["cp"] 44.6579342 >>> _Region3(200,650)["cv"] 4.04118076 >>> _Region3(200,650)["w"] 383.444594 >>> _Region3(500,750)["alfav"] 0.00441515098 >>> _Region3(500,750)["kt"] 0.00806710817
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L1766-L1865
jjgomera/iapws
iapws/iapws97.py
_tab_P
def _tab_P(P): """Define the boundary between Region 3a-3b, T=f(P) Parameters ---------- P : float Pressure, [MPa] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Specific Volume as a Function of Pressure and Temperature v(p,T) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-VPT3-2016.pdf, Eq. 2 Examples -------- >>> _tab_P(40) 693.0341408 """ I = [0, 1, 2, -1, -2] n = [0.154793642129415e4, -0.187661219490113e3, 0.213144632222113e2, -0.191887498864292e4, 0.918419702359447e3] Pr = P/1 T = 0 for i, ni in zip(I, n): T += ni * log(Pr)**i return T
python
def _tab_P(P): """Define the boundary between Region 3a-3b, T=f(P) Parameters ---------- P : float Pressure, [MPa] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Specific Volume as a Function of Pressure and Temperature v(p,T) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-VPT3-2016.pdf, Eq. 2 Examples -------- >>> _tab_P(40) 693.0341408 """ I = [0, 1, 2, -1, -2] n = [0.154793642129415e4, -0.187661219490113e3, 0.213144632222113e2, -0.191887498864292e4, 0.918419702359447e3] Pr = P/1 T = 0 for i, ni in zip(I, n): T += ni * log(Pr)**i return T
Define the boundary between Region 3a-3b, T=f(P) Parameters ---------- P : float Pressure, [MPa] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Specific Volume as a Function of Pressure and Temperature v(p,T) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-VPT3-2016.pdf, Eq. 2 Examples -------- >>> _tab_P(40) 693.0341408
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L1890-L1923
jjgomera/iapws
iapws/iapws97.py
_txx_P
def _txx_P(P, xy): """Define the boundary between 3x-3y, T=f(P) Parameters ---------- P : float Pressure, [MPa] xy: string Subregions options: cd, gh, ij, jk, mn, qu, rx, uv Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Specific Volume as a Function of Pressure and Temperature v(p,T) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-VPT3-2016.pdf, Eq. 1 Examples -------- >>> _txx_P(25,"cd") 649.3659208 >>> _txx_P(23,"gh") 649.8873759 >>> _txx_P(23,"ij") 651.5778091 >>> _txx_P(23,"jk") 655.8338344 >>> _txx_P(22.8,"mn") 649.6054133 >>> _txx_P(22,"qu") 645.6355027 >>> _txx_P(22,"rx") 648.2622754 >>> _txx_P(22.3,"uv") 647.7996121 """ ng = { "cd": [0.585276966696349e3, 0.278233532206915e1, -0.127283549295878e-1, 0.159090746562729e-3], "gh": [-0.249284240900418e5, 0.428143584791546e4, -0.269029173140130e3, 0.751608051114157e1, -0.787105249910383e-1], "ij": [0.584814781649163e3, -0.616179320924617, 0.260763050899562, -0.587071076864459e-2, 0.515308185433082e-4], "jk": [0.617229772068439e3, -0.770600270141675e1, 0.697072596851896, -0.157391839848015e-1, 0.137897492684194e-3], "mn": [0.535339483742384e3, 0.761978122720128e1, -0.158365725441648, 0.192871054508108e-2], "qu": [0.565603648239126e3, 0.529062258221222e1, -0.102020639611016, 0.122240301070145e-2], "rx": [0.584561202520006e3, -0.102961025163669e1, 0.243293362700452, -0.294905044740799e-2], "uv": [0.528199646263062e3, 0.890579602135307e1, -0.222814134903755, 0.286791682263697e-2]} n = ng[xy] Pr = P/1 T = 0 for i, ni in enumerate(n): T += ni * Pr**i return T
python
def _txx_P(P, xy): """Define the boundary between 3x-3y, T=f(P) Parameters ---------- P : float Pressure, [MPa] xy: string Subregions options: cd, gh, ij, jk, mn, qu, rx, uv Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Specific Volume as a Function of Pressure and Temperature v(p,T) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-VPT3-2016.pdf, Eq. 1 Examples -------- >>> _txx_P(25,"cd") 649.3659208 >>> _txx_P(23,"gh") 649.8873759 >>> _txx_P(23,"ij") 651.5778091 >>> _txx_P(23,"jk") 655.8338344 >>> _txx_P(22.8,"mn") 649.6054133 >>> _txx_P(22,"qu") 645.6355027 >>> _txx_P(22,"rx") 648.2622754 >>> _txx_P(22.3,"uv") 647.7996121 """ ng = { "cd": [0.585276966696349e3, 0.278233532206915e1, -0.127283549295878e-1, 0.159090746562729e-3], "gh": [-0.249284240900418e5, 0.428143584791546e4, -0.269029173140130e3, 0.751608051114157e1, -0.787105249910383e-1], "ij": [0.584814781649163e3, -0.616179320924617, 0.260763050899562, -0.587071076864459e-2, 0.515308185433082e-4], "jk": [0.617229772068439e3, -0.770600270141675e1, 0.697072596851896, -0.157391839848015e-1, 0.137897492684194e-3], "mn": [0.535339483742384e3, 0.761978122720128e1, -0.158365725441648, 0.192871054508108e-2], "qu": [0.565603648239126e3, 0.529062258221222e1, -0.102020639611016, 0.122240301070145e-2], "rx": [0.584561202520006e3, -0.102961025163669e1, 0.243293362700452, -0.294905044740799e-2], "uv": [0.528199646263062e3, 0.890579602135307e1, -0.222814134903755, 0.286791682263697e-2]} n = ng[xy] Pr = P/1 T = 0 for i, ni in enumerate(n): T += ni * Pr**i return T
Define the boundary between 3x-3y, T=f(P) Parameters ---------- P : float Pressure, [MPa] xy: string Subregions options: cd, gh, ij, jk, mn, qu, rx, uv Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for Specific Volume as a Function of Pressure and Temperature v(p,T) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-VPT3-2016.pdf, Eq. 1 Examples -------- >>> _txx_P(25,"cd") 649.3659208 >>> _txx_P(23,"gh") 649.8873759 >>> _txx_P(23,"ij") 651.5778091 >>> _txx_P(23,"jk") 655.8338344 >>> _txx_P(22.8,"mn") 649.6054133 >>> _txx_P(22,"qu") 645.6355027 >>> _txx_P(22,"rx") 648.2622754 >>> _txx_P(22.3,"uv") 647.7996121
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L2026-L2090
jjgomera/iapws
iapws/iapws97.py
_Backward3a_v_Ph
def _Backward3a_v_Ph(P, h): """Backward equation for region 3a, v=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 4 Returns ------- v : float Specific volume, [m³/kg] Examples -------- >>> _Backward3a_v_Ph(20,1700) 0.001749903962 >>> _Backward3a_v_Ph(100,2100) 0.001676229776 """ I = [-12, -12, -12, -12, -10, -10, -10, -8, -8, -6, -6, -6, -4, -4, -3, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 8] J = [6, 8, 12, 18, 4, 7, 10, 5, 12, 3, 4, 22, 2, 3, 7, 3, 16, 0, 1, 2, 3, 0, 1, 0, 1, 2, 0, 2, 0, 2, 2, 2] n = [0.529944062966028e-2, -0.170099690234461, 0.111323814312927e2, -0.217898123145125e4, -0.506061827980875e-3, 0.556495239685324, -0.943672726094016e1, -0.297856807561527, 0.939353943717186e2, 0.192944939465981e-1, 0.421740664704763, -0.368914126282330e7, -0.737566847600639e-2, -0.354753242424366, -0.199768169338727e1, 0.115456297059049e1, 0.568366875815960e4, 0.808169540124668e-2, 0.172416341519307, 0.104270175292927e1, -0.297691372792847, 0.560394465163593, 0.275234661176914, -0.148347894866012, -0.651142513478515e-1, -0.292468715386302e1, 0.664876096952665e-1, 0.352335014263844e1, -0.146340792313332e-1, -0.224503486668184e1, 0.110533464706142e1, -0.408757344495612e-1] Pr = P/100 nu = h/2100 suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (Pr+0.128)**i * (nu-0.727)**j return 0.0028*suma
python
def _Backward3a_v_Ph(P, h): """Backward equation for region 3a, v=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 4 Returns ------- v : float Specific volume, [m³/kg] Examples -------- >>> _Backward3a_v_Ph(20,1700) 0.001749903962 >>> _Backward3a_v_Ph(100,2100) 0.001676229776 """ I = [-12, -12, -12, -12, -10, -10, -10, -8, -8, -6, -6, -6, -4, -4, -3, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 8] J = [6, 8, 12, 18, 4, 7, 10, 5, 12, 3, 4, 22, 2, 3, 7, 3, 16, 0, 1, 2, 3, 0, 1, 0, 1, 2, 0, 2, 0, 2, 2, 2] n = [0.529944062966028e-2, -0.170099690234461, 0.111323814312927e2, -0.217898123145125e4, -0.506061827980875e-3, 0.556495239685324, -0.943672726094016e1, -0.297856807561527, 0.939353943717186e2, 0.192944939465981e-1, 0.421740664704763, -0.368914126282330e7, -0.737566847600639e-2, -0.354753242424366, -0.199768169338727e1, 0.115456297059049e1, 0.568366875815960e4, 0.808169540124668e-2, 0.172416341519307, 0.104270175292927e1, -0.297691372792847, 0.560394465163593, 0.275234661176914, -0.148347894866012, -0.651142513478515e-1, -0.292468715386302e1, 0.664876096952665e-1, 0.352335014263844e1, -0.146340792313332e-1, -0.224503486668184e1, 0.110533464706142e1, -0.408757344495612e-1] Pr = P/100 nu = h/2100 suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (Pr+0.128)**i * (nu-0.727)**j return 0.0028*suma
Backward equation for region 3a, v=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 4 Returns ------- v : float Specific volume, [m³/kg] Examples -------- >>> _Backward3a_v_Ph(20,1700) 0.001749903962 >>> _Backward3a_v_Ph(100,2100) 0.001676229776
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L2093-L2143
jjgomera/iapws
iapws/iapws97.py
_Backward3_v_Ph
def _Backward3_v_Ph(P, h): """Backward equation for region 3, v=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- v : float Specific volume, [m³/kg] """ hf = _h_3ab(P) if h <= hf: return _Backward3a_v_Ph(P, h) else: return _Backward3b_v_Ph(P, h)
python
def _Backward3_v_Ph(P, h): """Backward equation for region 3, v=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- v : float Specific volume, [m³/kg] """ hf = _h_3ab(P) if h <= hf: return _Backward3a_v_Ph(P, h) else: return _Backward3b_v_Ph(P, h)
Backward equation for region 3, v=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- v : float Specific volume, [m³/kg]
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L2198-L2217
jjgomera/iapws
iapws/iapws97.py
_Backward3a_T_Ph
def _Backward3a_T_Ph(P, h): """Backward equation for region 3a, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 2 Examples -------- >>> _Backward3a_T_Ph(20,1700) 629.3083892 >>> _Backward3a_T_Ph(100,2100) 733.6163014 """ I = [-12, -12, -12, -12, -12, -12, -12, -12, -10, -10, -10, -8, -8, -8, -8, -5, -3, -2, -2, -2, -1, -1, 0, 0, 1, 3, 3, 4, 4, 10, 12] J = [0, 1, 2, 6, 14, 16, 20, 22, 1, 5, 12, 0, 2, 4, 10, 2, 0, 1, 3, 4, 0, 2, 0, 1, 1, 0, 1, 0, 3, 4, 5] n = [-0.133645667811215e-6, 0.455912656802978e-5, -0.146294640700979e-4, 0.639341312970080e-2, 0.372783927268847e3, -0.718654377460447e4, 0.573494752103400e6, -0.267569329111439e7, -0.334066283302614e-4, -0.245479214069597e-1, 0.478087847764996e2, 0.764664131818904e-5, 0.128350627676972e-2, 0.171219081377331e-1, -0.851007304583213e1, -0.136513461629781e-1, -0.384460997596657e-5, 0.337423807911655e-2, -0.551624873066791, 0.729202277107470, -0.992522757376041e-2, -.119308831407288, .793929190615421, .454270731799386, .20999859125991, -0.642109823904738e-2, -0.235155868604540e-1, 0.252233108341612e-2, -0.764885133368119e-2, 0.136176427574291e-1, -0.133027883575669e-1] Pr = P/100. nu = h/2300. suma = 0 for i, j, n in zip(I, J, n): suma += n*(Pr+0.240)**i*(nu-0.615)**j return 760*suma
python
def _Backward3a_T_Ph(P, h): """Backward equation for region 3a, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 2 Examples -------- >>> _Backward3a_T_Ph(20,1700) 629.3083892 >>> _Backward3a_T_Ph(100,2100) 733.6163014 """ I = [-12, -12, -12, -12, -12, -12, -12, -12, -10, -10, -10, -8, -8, -8, -8, -5, -3, -2, -2, -2, -1, -1, 0, 0, 1, 3, 3, 4, 4, 10, 12] J = [0, 1, 2, 6, 14, 16, 20, 22, 1, 5, 12, 0, 2, 4, 10, 2, 0, 1, 3, 4, 0, 2, 0, 1, 1, 0, 1, 0, 3, 4, 5] n = [-0.133645667811215e-6, 0.455912656802978e-5, -0.146294640700979e-4, 0.639341312970080e-2, 0.372783927268847e3, -0.718654377460447e4, 0.573494752103400e6, -0.267569329111439e7, -0.334066283302614e-4, -0.245479214069597e-1, 0.478087847764996e2, 0.764664131818904e-5, 0.128350627676972e-2, 0.171219081377331e-1, -0.851007304583213e1, -0.136513461629781e-1, -0.384460997596657e-5, 0.337423807911655e-2, -0.551624873066791, 0.729202277107470, -0.992522757376041e-2, -.119308831407288, .793929190615421, .454270731799386, .20999859125991, -0.642109823904738e-2, -0.235155868604540e-1, 0.252233108341612e-2, -0.764885133368119e-2, 0.136176427574291e-1, -0.133027883575669e-1] Pr = P/100. nu = h/2300. suma = 0 for i, j, n in zip(I, J, n): suma += n*(Pr+0.240)**i*(nu-0.615)**j return 760*suma
Backward equation for region 3a, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 2 Examples -------- >>> _Backward3a_T_Ph(20,1700) 629.3083892 >>> _Backward3a_T_Ph(100,2100) 733.6163014
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L2220-L2270
jjgomera/iapws
iapws/iapws97.py
_Backward3_T_Ph
def _Backward3_T_Ph(P, h): """Backward equation for region 3, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K] """ hf = _h_3ab(P) if h <= hf: T = _Backward3a_T_Ph(P, h) else: T = _Backward3b_T_Ph(P, h) return T
python
def _Backward3_T_Ph(P, h): """Backward equation for region 3, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K] """ hf = _h_3ab(P) if h <= hf: T = _Backward3a_T_Ph(P, h) else: T = _Backward3b_T_Ph(P, h) return T
Backward equation for region 3, T=f(P,h) Parameters ---------- P : float Pressure, [MPa] h : float Specific enthalpy, [kJ/kg] Returns ------- T : float Temperature, [K]
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L2326-L2346
jjgomera/iapws
iapws/iapws97.py
_Backward3_v_Ps
def _Backward3_v_Ps(P, s): """Backward equation for region 3, v=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- v : float Specific volume, [m³/kg] """ if s <= sc: return _Backward3a_v_Ps(P, s) else: return _Backward3b_v_Ps(P, s)
python
def _Backward3_v_Ps(P, s): """Backward equation for region 3, v=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- v : float Specific volume, [m³/kg] """ if s <= sc: return _Backward3a_v_Ps(P, s) else: return _Backward3b_v_Ps(P, s)
Backward equation for region 3, v=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- v : float Specific volume, [m³/kg]
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L2454-L2472
jjgomera/iapws
iapws/iapws97.py
_Backward3a_T_Ps
def _Backward3a_T_Ps(P, s): """Backward equation for region 3a, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 6 Examples -------- >>> _Backward3a_T_Ps(20,3.8) 628.2959869 >>> _Backward3a_T_Ps(100,4) 705.6880237 """ I = [-12, -12, -10, -10, -10, -10, -8, -8, -8, -8, -6, -6, -6, -5, -5, -5, -4, -4, -4, -2, -2, -1, -1, 0, 0, 0, 1, 2, 2, 3, 8, 8, 10] J = [28, 32, 4, 10, 12, 14, 5, 7, 8, 28, 2, 6, 32, 0, 14, 32, 6, 10, 36, 1, 4, 1, 6, 0, 1, 4, 0, 0, 3, 2, 0, 1, 2] n = [0.150042008263875e10, -0.159397258480424e12, 0.502181140217975e-3, -0.672057767855466e2, 0.145058545404456e4, -0.823889534888890e4, -0.154852214233853, 0.112305046746695e2, -0.297000213482822e2, 0.438565132635495e11, 0.137837838635464e-2, -0.297478527157462e1, 0.971777947349413e13, -0.571527767052398e-4, 0.288307949778420e5, -0.744428289262703e14, 0.128017324848921e2, -0.368275545889071e3, 0.664768904779177e16, 0.449359251958880e-1, -0.422897836099655e1, -0.240614376434179, -0.474341365254924e1, 0.724093999126110, 0.923874349695897, 0.399043655281015e1, 0.384066651868009e-1, -0.359344365571848e-2, -0.735196448821653, 0.188367048396131, 0.141064266818704e-3, -0.257418501496337e-2, 0.123220024851555e-2] Pr = P/100 sigma = s/4.4 suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (Pr+0.240)**i * (sigma-0.703)**j return 760*suma
python
def _Backward3a_T_Ps(P, s): """Backward equation for region 3a, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 6 Examples -------- >>> _Backward3a_T_Ps(20,3.8) 628.2959869 >>> _Backward3a_T_Ps(100,4) 705.6880237 """ I = [-12, -12, -10, -10, -10, -10, -8, -8, -8, -8, -6, -6, -6, -5, -5, -5, -4, -4, -4, -2, -2, -1, -1, 0, 0, 0, 1, 2, 2, 3, 8, 8, 10] J = [28, 32, 4, 10, 12, 14, 5, 7, 8, 28, 2, 6, 32, 0, 14, 32, 6, 10, 36, 1, 4, 1, 6, 0, 1, 4, 0, 0, 3, 2, 0, 1, 2] n = [0.150042008263875e10, -0.159397258480424e12, 0.502181140217975e-3, -0.672057767855466e2, 0.145058545404456e4, -0.823889534888890e4, -0.154852214233853, 0.112305046746695e2, -0.297000213482822e2, 0.438565132635495e11, 0.137837838635464e-2, -0.297478527157462e1, 0.971777947349413e13, -0.571527767052398e-4, 0.288307949778420e5, -0.744428289262703e14, 0.128017324848921e2, -0.368275545889071e3, 0.664768904779177e16, 0.449359251958880e-1, -0.422897836099655e1, -0.240614376434179, -0.474341365254924e1, 0.724093999126110, 0.923874349695897, 0.399043655281015e1, 0.384066651868009e-1, -0.359344365571848e-2, -0.735196448821653, 0.188367048396131, 0.141064266818704e-3, -0.257418501496337e-2, 0.123220024851555e-2] Pr = P/100 sigma = s/4.4 suma = 0 for i, j, ni in zip(I, J, n): suma += ni * (Pr+0.240)**i * (sigma-0.703)**j return 760*suma
Backward equation for region 3a, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K] References ---------- IAPWS, Revised Supplementary Release on Backward Equations for the Functions T(p,h), v(p,h) and T(p,s), v(p,s) for Region 3 of the IAPWS Industrial Formulation 1997 for the Thermodynamic Properties of Water and Steam, http://www.iapws.org/relguide/Supp-Tv%28ph,ps%293-2014.pdf, Eq 6 Examples -------- >>> _Backward3a_T_Ps(20,3.8) 628.2959869 >>> _Backward3a_T_Ps(100,4) 705.6880237
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L2475-L2525
jjgomera/iapws
iapws/iapws97.py
_Backward3_T_Ps
def _Backward3_T_Ps(P, s): """Backward equation for region 3, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K] """ sc = 4.41202148223476 if s <= sc: T = _Backward3a_T_Ps(P, s) else: T = _Backward3b_T_Ps(P, s) return T
python
def _Backward3_T_Ps(P, s): """Backward equation for region 3, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K] """ sc = 4.41202148223476 if s <= sc: T = _Backward3a_T_Ps(P, s) else: T = _Backward3b_T_Ps(P, s) return T
Backward equation for region 3, T=f(P,s) Parameters ---------- P : float Pressure, [MPa] s : float Specific entropy, [kJ/kgK] Returns ------- T : float Temperature, [K]
https://github.com/jjgomera/iapws/blob/1e5812aab38212fb8a63736f61cdcfa427d223b1/iapws/iapws97.py#L2580-L2600