_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q262400 | RhoT.calculate | validation | def calculate(self, **state):
"""
Calculate the density at the specified temperature.
:param T: [K] temperature
:returns: [kg/m3] density
The **state parameter contains the keyword argument(s) specified above\
that are used to describe the state of the material.
"""
super().calculate(**state)
return self.mm * self.P / R / state["T"] | python | {
"resource": ""
} |
q262401 | RhoTPx.calculate | validation | def calculate(self, **state):
"""
Calculate the density at the specified temperature, pressure, and
composition.
:param T: [K] temperature
:param P: [Pa] pressure
:param x: [mole fraction] dictionary of compounds and mole fractions
:returns: [kg/m3] density
The **state parameter contains the keyword argument(s) specified above\
that are used to describe the state of the material.
"""
super().calculate(**state)
mm_average = 0.0
for compound, molefraction in state["x"].items():
mm_average += molefraction * mm(compound)
mm_average /= 1000.0
return mm_average * state["P"] / R / state["T"] | python | {
"resource": ""
} |
q262402 | GeneralLedgerAccount.set_parent_path | validation | def set_parent_path(self, value):
"""
Set the parent path and the path from the new parent path.
:param value: The path to the object's parent
"""
self._parent_path = value
self.path = value + r'/' + self.name
self._update_childrens_parent_path() | python | {
"resource": ""
} |
q262403 | GeneralLedgerAccount.create_account | validation | def create_account(self, name, number=None, description=None):
"""
Create a sub account in the account.
:param name: The account name.
:param description: The account description.
:param number: The account number.
:returns: The created account.
"""
new_account = GeneralLedgerAccount(name, description, number,
self.account_type)
new_account.set_parent_path(self.path)
self.accounts.append(new_account)
return new_account | python | {
"resource": ""
} |
q262404 | GeneralLedgerAccount.remove_account | validation | def remove_account(self, name):
"""
Remove an account from the account's sub accounts.
:param name: The name of the account to remove.
"""
acc_to_remove = None
for a in self.accounts:
if a.name == name:
acc_to_remove = a
if acc_to_remove is not None:
self.accounts.remove(acc_to_remove) | python | {
"resource": ""
} |
q262405 | GeneralLedgerAccount.get_child_account | validation | def get_child_account(self, account_name):
"""
Retrieves a child account.
This could be a descendant nested at any level.
:param account_name: The name of the account to retrieve.
:returns: The child account, if found, else None.
"""
if r'/' in account_name:
accs_in_path = account_name.split(r'/', 1)
curr_acc = self[accs_in_path[0]]
if curr_acc is None:
return None
return curr_acc.get_child_account(accs_in_path[1])
pass
else:
return self[account_name] | python | {
"resource": ""
} |
q262406 | GeneralLedgerStructure._create_account_ | validation | def _create_account_(self, name, number, account_type):
"""
Create an account in the general ledger structure.
:param name: The account name.
:param number: The account number.
:param account_type: The account type.
:returns: The created account.
"""
new_acc = GeneralLedgerAccount(name, None, number, account_type)
self.accounts.append(new_acc)
return new_acc | python | {
"resource": ""
} |
q262407 | GeneralLedgerStructure.get_account_descendants | validation | def get_account_descendants(self, account):
"""
Retrieves an account's descendants from the general ledger structure
given the account name.
:param account_name: The account name.
:returns: The decendants of the account.
"""
result = []
for child in account.accounts:
self._get_account_and_descendants_(child, result)
return result | python | {
"resource": ""
} |
q262408 | GeneralLedgerStructure._get_account_and_descendants_ | validation | def _get_account_and_descendants_(self, account, result):
"""
Returns the account and all of it's sub accounts.
:param account: The account.
:param result: The list to add all the accounts to.
"""
result.append(account)
for child in account.accounts:
self._get_account_and_descendants_(child, result) | python | {
"resource": ""
} |
q262409 | GeneralLedgerStructure.validate_account_names | validation | def validate_account_names(self, names):
"""
Validates whether the accounts in a list of account names exists.
:param names: The names of the accounts.
:returns: The descendants of the account.
"""
for name in names:
if self.get_account(name) is None:
raise ValueError("The account '{}' does not exist in the"
" general ledger structure.".format(name)) | python | {
"resource": ""
} |
q262410 | GeneralLedgerStructure.report | validation | def report(self, format=ReportFormat.printout, output_path=None):
"""
Returns a report of this class.
:param format: The format of the report.
:param output_path: The path to the file the report is written to.
If None, then the report is not written to a file.
:returns: The descendants of the account.
"""
rpt = GlsRpt(self, output_path)
return rpt.render(format) | python | {
"resource": ""
} |
q262411 | GeneralLedger.create_transaction | validation | def create_transaction(self, name, description=None,
tx_date=datetime.min.date(),
dt_account=None, cr_account=None,
source=None, amount=0.00):
"""
Create a transaction in the general ledger.
:param name: The transaction's name.
:param description: The transaction's description.
:param tx_date: The date of the transaction.
:param cr_account: The transaction's credit account's name.
:param dt_account: The transaction's debit account's name.
:param source: The name of source the transaction originated from.
:param amount: The transaction amount.
:returns: The created transaction.
"""
new_tx = Transaction(name, description, tx_date,
dt_account, cr_account, source, amount)
self.transactions.append(new_tx)
return new_tx | python | {
"resource": ""
} |
q262412 | get_path_relative_to_module | validation | def get_path_relative_to_module(module_file_path, relative_target_path):
"""
Calculate a path relative to the specified module file.
:param module_file_path: The file path to the module.
"""
module_path = os.path.dirname(module_file_path)
path = os.path.join(module_path, relative_target_path)
path = os.path.abspath(path)
return path | python | {
"resource": ""
} |
q262413 | get_date | validation | def get_date(date):
"""
Get the date from a value that could be a date object or a string.
:param date: The date object or string.
:returns: The date object.
"""
if type(date) is str:
return datetime.strptime(date, '%Y-%m-%d').date()
else:
return date | python | {
"resource": ""
} |
q262414 | IsothermalFlatSurface.Nu_x | validation | def Nu_x(self, L, theta, Ts, **statef):
"""
Calculate the local Nusselt number.
:param L: [m] characteristic length of the heat transfer surface
:param theta: [°] angle of the surface with the vertical
:param Ts: [K] heat transfer surface temperature
:param Tf: [K] bulk fluid temperature
:returns: float
"""
Tf = statef['T']
thetar = radians(theta)
if self._isgas:
self.Tr = Ts - 0.38 * (Ts - Tf)
beta = self._fluid.beta(T=Tf)
else: # for liquids
self.Tr = Ts - 0.5 * (Ts - Tf)
beta = self._fluid.beta(T=self.Tr)
if Ts > Tf: # hot surface
if 0.0 < theta < 45.0:
g = const.g*cos(thetar)
else:
g = const.g
else: # cold surface
if -45.0 < theta < 0.0:
g = const.g*cos(thetar)
else:
g = const.g
nu = self._fluid.nu(T=self.Tr)
alpha = self._fluid.alpha(T=self.Tr)
Gr = dq.Gr(L, Ts, Tf, beta, nu, g)
Pr = dq.Pr(nu, alpha)
Ra = Gr * Pr
eq = [self.equation_dict[r]
for r in self.regions if r.contains_point(theta, Ra)][0]
return eq(self, Ra, Pr) | python | {
"resource": ""
} |
q262415 | IsothermalFlatSurface.Nu_L | validation | def Nu_L(self, L, theta, Ts, **statef):
"""
Calculate the average Nusselt number.
:param L: [m] characteristic length of the heat transfer surface
:param theta: [°] angle of the surface with the vertical
:param Ts: [K] heat transfer surface temperature
:param **statef: [K] bulk fluid temperature
:returns: float
"""
return self.Nu_x(L, theta, Ts, **statef) / 0.75 | python | {
"resource": ""
} |
q262416 | IsothermalFlatSurface.h_x | validation | def h_x(self, L, theta, Ts, **statef):
"""
Calculate the local heat transfer coefficient.
:param L: [m] characteristic length of the heat transfer surface
:param theta: [°] angle of the surface with the vertical
:param Ts: [K] heat transfer surface temperature
:param Tf: [K] bulk fluid temperature
:returns: [W/m2/K] float
"""
Nu_x = self.Nu_x(L, theta, Ts, **statef)
k = self._fluid.k(T=self.Tr)
return Nu_x * k / L | python | {
"resource": ""
} |
q262417 | IsothermalFlatSurface.h_L | validation | def h_L(self, L, theta, Ts, **statef):
"""
Calculate the average heat transfer coefficient.
:param L: [m] characteristic length of the heat transfer surface
:param theta: [°] angle of the surface with the vertical
:param Ts: [K] heat transfer surface temperature
:param Tf: [K] bulk fluid temperature
:returns: [W/m2/K] float
"""
Nu_L = self.Nu_L(L, theta, Ts, **statef)
k = self._fluid.k(T=self.Tr)
return Nu_L * k / L | python | {
"resource": ""
} |
q262418 | MaterialPackage.clear | validation | def clear(self):
"""
Set all the size class masses and H20_mass in the package to zero
and the solid_density to 1.0
"""
self.solid_density = 1.0
self.H2O_mass = 0.0
self.size_class_masses = self.size_class_masses * 0.0 | python | {
"resource": ""
} |
q262419 | DataSet.create_template | validation | def create_template(material, path, show=False):
"""
Create a template csv file for a data set.
:param material: the name of the material
:param path: the path of the directory where the file must be written
:param show: a boolean indicating whether the created file should be \
displayed after creation
"""
file_name = 'dataset-%s.csv' % material.lower()
file_path = os.path.join(path, file_name)
with open(file_path, 'w', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=',',
quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(['Name', material])
writer.writerow(['Description', '<Add a data set description '
'here.>'])
writer.writerow(['Reference', '<Add a reference to the source of '
'the data set here.>'])
writer.writerow(['Temperature', '<parameter 1 name>',
'<parameter 2 name>', '<parameter 3 name>'])
writer.writerow(['T', '<parameter 1 display symbol>',
'<parameter 2 display symbol>',
'<parameter 3 display symbol>'])
writer.writerow(['K', '<parameter 1 units>',
'<parameter 2 units>', '<parameter 3 units>'])
writer.writerow(['T', '<parameter 1 symbol>',
'<parameter 2 symbol>', '<parameter 3 symbol>'])
for i in range(10):
writer.writerow([100.0 + i*50, float(i), 10.0 + i, 100.0 + i])
if show is True:
webbrowser.open_new(file_path) | python | {
"resource": ""
} |
q262420 | Api._url | validation | def _url(self, endpoint, url_data=None, parameters=None):
"""Generate URL on the modularized endpoints and url parameters"""
try:
url = '%s/%s' % (self.base_url, self.endpoints[endpoint])
except KeyError:
raise EndPointDoesNotExist(endpoint)
if url_data:
url = url % url_data
if parameters:
# url = url?key=value&key=value&key=value...
url = '%s?%s' % (url, urllib.urlencode(parameters, True))
return url | python | {
"resource": ""
} |
q262421 | Api._httplib2_init | validation | def _httplib2_init(username, password):
"""Used to instantiate a regular HTTP request object"""
obj = httplib2.Http()
if username and password:
obj.add_credentials(username, password)
return obj | python | {
"resource": ""
} |
q262422 | Material.alpha | validation | def alpha(self, **state):
"""
Calculate the alpha value given the material state.
:param **state: material state
:returns: float
"""
return self.k(**state) / self.rho(**state) / self.Cp(**state) | python | {
"resource": ""
} |
q262423 | DafHTy.calculate | validation | def calculate(self, **state):
"""
Calculate the enthalpy at the specified temperature and composition
using equation 9 in Merrick1983b.
:param T: [K] temperature
:param y_C: Carbon mass fraction
:param y_H: Hydrogen mass fraction
:param y_O: Oxygen mass fraction
:param y_N: Nitrogen mass fraction
:param y_S: Sulphur mass fraction
:returns: [J/kg] enthalpy
The **state parameter contains the keyword argument(s) specified above
that are used to describe the state of the material.
"""
T = state['T']
y_C = state['y_C']
y_H = state['y_H']
y_O = state['y_O']
y_N = state['y_N']
y_S = state['y_S']
a = self._calc_a(y_C, y_H, y_O, y_N, y_S) / 1000 # kg/mol
result = (R/a) * (380*self._calc_g0(380/T) + 3600*self._calc_g0(1800/T))
return result | python | {
"resource": ""
} |
q262424 | TimeBasedModel.create_entity | validation | def create_entity(self, name, gl_structure, description=None):
"""
Create an entity and add it to the model.
:param name: The entity name.
:param gl_structure: The entity's general ledger structure.
:param description: The entity description.
:returns: The created entity.
"""
new_entity = Entity(name, gl_structure, description=description)
self.entities.append(new_entity)
return new_entity | python | {
"resource": ""
} |
q262425 | TimeBasedModel.remove_entity | validation | def remove_entity(self, name):
"""
Remove an entity from the model.
:param name: The name of the entity to remove.
"""
entity_to_remove = None
for e in self.entities:
if e.name == name:
entity_to_remove = e
if entity_to_remove is not None:
self.entities.remove(entity_to_remove) | python | {
"resource": ""
} |
q262426 | TimeBasedModel.prepare_to_run | validation | def prepare_to_run(self):
"""
Prepare the model for execution.
"""
self.clock.reset()
for e in self.entities:
e.prepare_to_run(self.clock, self.period_count) | python | {
"resource": ""
} |
q262427 | TimeBasedModel.run | validation | def run(self):
"""
Execute the model.
"""
self.prepare_to_run()
for i in range(0, self.period_count):
for e in self.entities:
e.run(self.clock)
self.clock.tick() | python | {
"resource": ""
} |
q262428 | Material._create_element_list | validation | def _create_element_list(self):
"""
Extract an alphabetically sorted list of elements from the
material's compounds.
:returns: Alphabetically sorted list of elements.
"""
element_set = stoich.elements(self.compounds)
return sorted(list(element_set)) | python | {
"resource": ""
} |
q262429 | Material.create_stream | validation | def create_stream(self, assay=None, mfr=0.0, P=1.0, T=25.0,
normalise=True):
"""
Create a MaterialStream based on the specified parameters.
:param assay: Name of the assay to be used to create the stream.
:param mfr: Stream mass flow rate. [kg/h]
:param P: Stream pressure. [atm]
:param T: Stream temperature. [°C]
:param normalise: Indicates whether the assay must be normalised
before creating the Stream.
:returns: MaterialStream object.
"""
if assay is None:
return MaterialStream(self, self.create_empty_assay(), P, T)
if normalise:
assay_total = self.get_assay_total(assay)
else:
assay_total = 1.0
return MaterialStream(self, mfr * self.converted_assays[assay] /
assay_total, P, T, self._isCoal(assay),
self._get_HHV(assay)) | python | {
"resource": ""
} |
q262430 | MaterialPackage._calculate_H | validation | def _calculate_H(self, T):
"""
Calculate the enthalpy of the package at the specified temperature.
:param T: Temperature. [°C]
:returns: Enthalpy. [kWh]
"""
if self.isCoal:
return self._calculate_Hfr_coal(T)
H = 0.0
for compound in self.material.compounds:
index = self.material.get_compound_index(compound)
dH = thermo.H(compound, T, self._compound_masses[index])
H = H + dH
return H | python | {
"resource": ""
} |
q262431 | MaterialPackage._calculate_H_coal | validation | def _calculate_H_coal(self, T):
"""
Calculate the enthalpy of the package at the specified temperature, in
case the material is coal.
:param T: [°C] temperature
:returns: [kWh] enthalpy
"""
m_C = 0 # kg
m_H = 0 # kg
m_O = 0 # kg
m_N = 0 # kg
m_S = 0 # kg
H = 0.0 # kWh/h
for compound in self.material.compounds:
index = self.material.get_compound_index(compound)
if stoich.element_mass_fraction(compound, 'C') == 1.0:
m_C += self._compound_masses[index]
elif stoich.element_mass_fraction(compound, 'H') == 1.0:
m_H += self._compound_masses[index]
elif stoich.element_mass_fraction(compound, 'O') == 1.0:
m_O += self._compound_masses[index]
elif stoich.element_mass_fraction(compound, 'N') == 1.0:
m_N += self._compound_masses[index]
elif stoich.element_mass_fraction(compound, 'S') == 1.0:
m_S += self._compound_masses[index]
else:
dH = thermo.H(compound, T, self._compound_masses[index])
H += dH
m_total = y_C + y_H + y_O + y_N + y_S # kg/h
y_C = m_C / m_total
y_H = m_H / m_total
y_O = m_O / m_total
y_N = m_N / m_total
y_S = m_S / m_total
hmodel = coals.DafHTy()
H = hmodel.calculate(T=T+273.15, y_C=y_C, y_H=y_H, y_O=y_O, y_N=y_N,
y_S=y_S) / 3.6e6 # kWh/kg
H298 = hmodel.calculate(T=298.15, y_C=y_C, y_H=y_H, y_O=y_O, y_N=y_N,
y_S=y_S) / 3.6e6 # kWh/kg
Hdaf = H - H298 + self._DH298 # kWh/kg
Hdaf *= m_total # kWh
H += Hdaf
return H | python | {
"resource": ""
} |
q262432 | MaterialPackage._calculate_T | validation | def _calculate_T(self, H):
"""
Calculate the temperature of the package given the specified
enthalpy using a secant algorithm.
:param H: Enthalpy. [kWh]
:returns: Temperature. [°C]
"""
# Create the initial guesses for temperature.
x = list()
x.append(self._T)
x.append(self._T + 10.0)
# Evaluate the enthalpy for the initial guesses.
y = list()
y.append(self._calculate_H(x[0]) - H)
y.append(self._calculate_H(x[1]) - H)
# Solve for temperature.
for i in range(2, 50):
x.append(x[i-1] - y[i-1]*((x[i-1] - x[i-2])/(y[i-1] - y[i-2])))
y.append(self._calculate_H(x[i]) - H)
if abs(y[i-1]) < 1.0e-5:
break
return x[len(x) - 1] | python | {
"resource": ""
} |
q262433 | MaterialPackage.H | validation | def H(self, H):
"""
Set the enthalpy of the package to the specified value, and
recalculate it's temperature.
:param H: The new enthalpy value. [kWh]
"""
self._H = H
self._T = self._calculate_T(H) | python | {
"resource": ""
} |
q262434 | MaterialPackage.T | validation | def T(self, T):
"""
Set the temperature of the package to the specified value, and
recalculate it's enthalpy.
:param T: Temperature. [°C]
"""
self._T = T
self._H = self._calculate_H(T) | python | {
"resource": ""
} |
q262435 | MaterialPackage.clone | validation | def clone(self):
"""Create a complete copy of the package.
:returns: A new MaterialPackage object."""
result = copy.copy(self)
result._compound_masses = copy.deepcopy(self._compound_masses)
return result | python | {
"resource": ""
} |
q262436 | MaterialPackage.clear | validation | def clear(self):
"""
Set all the compound masses in the package to zero.
Set the pressure to 1, the temperature to 25 and the enthalpy to zero.
"""
self._compound_masses = self._compound_masses * 0.0
self._P = 1.0
self._T = 25.0
self._H = 0.0 | python | {
"resource": ""
} |
q262437 | MaterialPackage.get_compound_mass | validation | def get_compound_mass(self, compound):
"""
Determine the mass of the specified compound in the package.
:param compound: Formula and phase of a compound, e.g. "Fe2O3[S1]".
:returns: Mass. [kg]
"""
if compound in self.material.compounds:
return self._compound_masses[
self.material.get_compound_index(compound)]
else:
return 0.0 | python | {
"resource": ""
} |
q262438 | MaterialPackage.get_compound_amounts | validation | def get_compound_amounts(self):
"""
Determine the mole amounts of all the compounds.
:returns: List of amounts. [kmol]
"""
result = self._compound_masses * 1.0
for compound in self.material.compounds:
index = self.material.get_compound_index(compound)
result[index] = stoich.amount(compound, result[index])
return result | python | {
"resource": ""
} |
q262439 | MaterialPackage.get_compound_amount | validation | def get_compound_amount(self, compound):
"""
Determine the mole amount of the specified compound.
:returns: Amount. [kmol]
"""
index = self.material.get_compound_index(compound)
return stoich.amount(compound, self._compound_masses[index]) | python | {
"resource": ""
} |
q262440 | MaterialPackage.amount | validation | def amount(self):
"""
Determine the sum of mole amounts of all the compounds.
:returns: Amount. [kmol]
"""
return sum(self.get_compound_amount(c) for c in self.material.compounds) | python | {
"resource": ""
} |
q262441 | MaterialPackage.get_element_mass_dictionary | validation | def get_element_mass_dictionary(self):
"""
Determine the masses of elements in the package and return as a
dictionary.
:returns: Dictionary of element symbols and masses. [kg]
"""
element_symbols = self.material.elements
element_masses = self.get_element_masses()
return {s: m for s, m in zip(element_symbols, element_masses)} | python | {
"resource": ""
} |
q262442 | MaterialPackage.get_element_mass | validation | def get_element_mass(self, element):
"""
Determine the mass of the specified elements in the package.
:returns: Masses. [kg]
"""
result = numpy.zeros(1)
for compound in self.material.compounds:
result += self.get_compound_mass(compound) *\
numpy.array(stoich.element_mass_fractions(compound, [element]))
return result[0] | python | {
"resource": ""
} |
q262443 | MaterialPackage.extract | validation | def extract(self, other):
"""
Extract 'other' from this package, modifying this package and
returning the extracted material as a new package.
:param other: Can be one of the following:
* float: A mass equal to other is extracted from self. Self is
reduced by other and the extracted package is returned as
a new package.
* tuple (compound, mass): The other tuple specifies the mass
of a compound to be extracted. It is extracted from self and
the extracted mass is returned as a new package.
* string: The 'other' string specifies the compound to be
extracted. All of the mass of that compound will be removed
from self and a new package created with it.
* Material: The 'other' material specifies the list of
compounds to extract.
:returns: New MaterialPackage object.
"""
# Extract the specified mass.
if type(other) is float or \
type(other) is numpy.float64 or \
type(other) is numpy.float32:
return self._extract_mass(other)
# Extract the specified mass of the specified compound.
elif self._is_compound_mass_tuple(other):
return self._extract_compound_mass(other[0], other[1])
# Extract all of the specified compound.
elif type(other) is str:
return self._extract_compound(other)
# TODO: Test
# Extract all of the compounds of the specified material.
elif type(other) is Material:
return self._extract_material(other)
# If not one of the above, it must be an invalid argument.
else:
raise TypeError("Invalid extraction argument.") | python | {
"resource": ""
} |
q262444 | MaterialStream._calculate_Hfr | validation | def _calculate_Hfr(self, T):
"""
Calculate the enthalpy flow rate of the stream at the specified
temperature.
:param T: Temperature. [°C]
:returns: Enthalpy flow rate. [kWh/h]
"""
if self.isCoal:
return self._calculate_Hfr_coal(T)
Hfr = 0.0
for compound in self.material.compounds:
index = self.material.get_compound_index(compound)
dHfr = thermo.H(compound, T, self._compound_mfrs[index])
Hfr = Hfr + dHfr
return Hfr | python | {
"resource": ""
} |
q262445 | MaterialStream._calculate_Hfr_coal | validation | def _calculate_Hfr_coal(self, T):
"""
Calculate the enthalpy flow rate of the stream at the specified
temperature, in the case of it being coal.
:param T: Temperature. [°C]
:returns: Enthalpy flow rate. [kWh/h]
"""
m_C = 0 # kg/h
m_H = 0 # kg/h
m_O = 0 # kg/h
m_N = 0 # kg/h
m_S = 0 # kg/h
Hfr = 0.0 # kWh/h
for compound in self.material.compounds:
index = self.material.get_compound_index(compound)
formula = compound.split('[')[0]
if stoich.element_mass_fraction(formula, 'C') == 1.0:
m_C += self._compound_mfrs[index]
elif stoich.element_mass_fraction(formula, 'H') == 1.0:
m_H += self._compound_mfrs[index]
elif stoich.element_mass_fraction(formula, 'O') == 1.0:
m_O += self._compound_mfrs[index]
elif stoich.element_mass_fraction(formula, 'N') == 1.0:
m_N += self._compound_mfrs[index]
elif stoich.element_mass_fraction(formula, 'S') == 1.0:
m_S += self._compound_mfrs[index]
else:
dHfr = thermo.H(compound, T, self._compound_mfrs[index])
Hfr += dHfr
m_total = m_C + m_H + m_O + m_N + m_S # kg/h
y_C = m_C / m_total
y_H = m_H / m_total
y_O = m_O / m_total
y_N = m_N / m_total
y_S = m_S / m_total
hmodel = coals.DafHTy()
H = hmodel.calculate(T=T+273.15, y_C=y_C, y_H=y_H, y_O=y_O, y_N=y_N,
y_S=y_S) / 3.6e6 # kWh/kg
H298 = hmodel.calculate(T=298.15, y_C=y_C, y_H=y_H, y_O=y_O, y_N=y_N,
y_S=y_S) / 3.6e6 # kWh/kg
Hdaf = H - H298 + self._DH298 # kWh/kg
Hdaf *= m_total # kWh/h
Hfr += Hdaf
return Hfr | python | {
"resource": ""
} |
q262446 | MaterialStream._calculate_T | validation | def _calculate_T(self, Hfr):
"""
Calculate the temperature of the stream given the specified
enthalpy flow rate using a secant algorithm.
:param H: Enthalpy flow rate. [kWh/h]
:returns: Temperature. [°C]
"""
# Create the initial guesses for temperature.
x = list()
x.append(self._T)
x.append(self._T + 10.0)
# Evaluate the enthalpy for the initial guesses.
y = list()
y.append(self._calculate_Hfr(x[0]) - Hfr)
y.append(self._calculate_Hfr(x[1]) - Hfr)
# Solve for temperature.
for i in range(2, 50):
x.append(x[i-1] - y[i-1]*((x[i-1] - x[i-2])/(y[i-1] - y[i-2])))
y.append(self._calculate_Hfr(x[i]) - Hfr)
if abs(y[i-1]) < 1.0e-5:
break
return x[len(x) - 1] | python | {
"resource": ""
} |
q262447 | MaterialStream.Hfr | validation | def Hfr(self, Hfr):
"""
Set the enthalpy flow rate of the stream to the specified value, and
recalculate it's temperature.
:param H: The new enthalpy flow rate value. [kWh/h]
"""
self._Hfr = Hfr
self._T = self._calculate_T(Hfr) | python | {
"resource": ""
} |
q262448 | MaterialStream.T | validation | def T(self, T):
"""
Set the temperature of the stream to the specified value, and
recalculate it's enthalpy.
:param T: Temperature. [°C]
"""
self._T = T
self._Hfr = self._calculate_Hfr(T) | python | {
"resource": ""
} |
q262449 | MaterialStream.HHV | validation | def HHV(self, HHV):
"""
Set the higher heating value of the stream to the specified value, and
recalculate the formation enthalpy of the daf coal.
:param HHV: MJ/kg coal, higher heating value
"""
self._HHV = HHV # MJ/kg coal
if self.isCoal:
self._DH298 = self._calculate_DH298_coal() | python | {
"resource": ""
} |
q262450 | MaterialStream.clone | validation | def clone(self):
"""Create a complete copy of the stream.
:returns: A new MaterialStream object."""
result = copy.copy(self)
result._compound_mfrs = copy.deepcopy(self._compound_mfrs)
return result | python | {
"resource": ""
} |
q262451 | MaterialStream.clear | validation | def clear(self):
"""
Set all the compound mass flow rates in the stream to zero.
Set the pressure to 1, the temperature to 25 and the enthalpy to zero.
"""
self._compound_mfrs = self._compound_mfrs * 0.0
self._P = 1.0
self._T = 25.0
self._H = 0.0 | python | {
"resource": ""
} |
q262452 | MaterialStream.get_compound_mfr | validation | def get_compound_mfr(self, compound):
"""
Determine the mass flow rate of the specified compound in the stream.
:param compound: Formula and phase of a compound, e.g. "Fe2O3[S1]".
:returns: Mass flow rate. [kg/h]
"""
if compound in self.material.compounds:
return self._compound_mfrs[
self.material.get_compound_index(compound)]
else:
return 0.0 | python | {
"resource": ""
} |
q262453 | MaterialStream.get_compound_afrs | validation | def get_compound_afrs(self):
"""
Determine the amount flow rates of all the compounds.
:returns: List of amount flow rates. [kmol/h]
"""
result = self._compound_mfrs * 1.0
for compound in self.material.compounds:
index = self.material.get_compound_index(compound)
result[index] = stoich.amount(compound, result[index])
return result | python | {
"resource": ""
} |
q262454 | MaterialStream.get_compound_afr | validation | def get_compound_afr(self, compound):
"""
Determine the amount flow rate of the specified compound.
:returns: Amount flow rate. [kmol/h]
"""
index = self.material.get_compound_index(compound)
return stoich.amount(compound, self._compound_mfrs[index]) | python | {
"resource": ""
} |
q262455 | MaterialStream.afr | validation | def afr(self):
"""
Determine the sum of amount flow rates of all the compounds.
:returns: Amount flow rate. [kmol/h]
"""
result = 0.0
for compound in self.material.compounds:
result += self.get_compound_afr(compound)
return result | python | {
"resource": ""
} |
q262456 | MaterialStream.get_element_mfrs | validation | def get_element_mfrs(self, elements=None):
"""
Determine the mass flow rates of elements in the stream.
:returns: Array of element mass flow rates. [kg/h]
"""
if elements is None:
elements = self.material.elements
result = numpy.zeros(len(elements))
for compound in self.material.compounds:
result += self.get_compound_mfr(compound) *\
stoich.element_mass_fractions(compound, elements)
return result | python | {
"resource": ""
} |
q262457 | MaterialStream.get_element_mfr_dictionary | validation | def get_element_mfr_dictionary(self):
"""
Determine the mass flow rates of elements in the stream and return as
a dictionary.
:returns: Dictionary of element symbols and mass flow rates. [kg/h]
"""
element_symbols = self.material.elements
element_mfrs = self.get_element_mfrs()
result = dict()
for s, mfr in zip(element_symbols, element_mfrs):
result[s] = mfr
return result | python | {
"resource": ""
} |
q262458 | MaterialStream.get_element_mfr | validation | def get_element_mfr(self, element):
"""
Determine the mass flow rate of the specified elements in the stream.
:returns: Mass flow rates. [kg/h]
"""
result = 0.0
for compound in self.material.compounds:
formula = compound.split('[')[0]
result += self.get_compound_mfr(compound) *\
stoich.element_mass_fraction(formula, element)
return result | python | {
"resource": ""
} |
q262459 | MaterialStream.extract | validation | def extract(self, other):
"""
Extract 'other' from this stream, modifying this stream and returning
the extracted material as a new stream.
:param other: Can be one of the following:
* float: A mass flow rate equal to other is extracted from self. Self
is reduced by other and the extracted stream is returned as
a new stream.
* tuple (compound, mass): The other tuple specifies the mass flow
rate of a compound to be extracted. It is extracted from self and
the extracted mass flow rate is returned as a new stream.
* string: The 'other' string specifies the compound to be
extracted. All of the mass flow rate of that compound will be
removed from self and a new stream created with it.
* Material: The 'other' material specifies the list of
compounds to extract.
:returns: New MaterialStream object.
"""
# Extract the specified mass flow rate.
if type(other) is float or \
type(other) is numpy.float64 or \
type(other) is numpy.float32:
return self._extract_mfr(other)
# Extract the specified mass flow rateof the specified compound.
elif self._is_compound_mfr_tuple(other):
return self._extract_compound_mfr(other[0], other[1])
# Extract all of the specified compound.
elif type(other) is str:
return self._extract_compound(other)
# TODO: Test
# Extract all of the compounds of the specified material.
elif type(other) is Material:
return self._extract_material(other)
# If not one of the above, it must be an invalid argument.
else:
raise TypeError("Invalid extraction argument.") | python | {
"resource": ""
} |
q262460 | Gr | validation | def Gr(L: float, Ts: float, Tf: float, beta: float, nu: float, g: float):
"""
Calculate the Grashof number.
:param L: [m] heat transfer surface characteristic length.
:param Ts: [K] heat transfer surface temperature.
:param Tf: [K] bulk fluid temperature.
:param beta: [1/K] fluid coefficient of thermal expansion.
:param nu: [m2/s] fluid kinematic viscosity.
:returns: float
.. math::
\\mathrm{Gr} = \\frac{g \\beta (Ts - Tinf ) L^3}{\\nu ^2}
Characteristic dimensions:
* vertical plate: vertical length
* pipe: diameter
* bluff body: diameter
"""
return g * beta * (Ts - Tf) * L**3.0 / nu**2.0 | python | {
"resource": ""
} |
q262461 | Re | validation | def Re(L: float, v: float, nu: float) -> float:
"""
Calculate the Reynolds number.
:param L: [m] surface characteristic length.
:param v: [m/s] fluid velocity relative to the object.
:param nu: [m2/s] fluid kinematic viscosity.
:returns: float
"""
return v * L / nu | python | {
"resource": ""
} |
q262462 | Ra | validation | def Ra(L: float, Ts: float, Tf: float, alpha: float, beta: float, nu: float
) -> float:
"""
Calculate the Ralleigh number.
:param L: [m] heat transfer surface characteristic length.
:param Ts: [K] heat transfer surface temperature.
:param Tf: [K] bulk fluid temperature.
:param alpha: [m2/s] fluid thermal diffusivity.
:param beta: [1/K] fluid coefficient of thermal expansion.
:param nu: [m2/s] fluid kinematic viscosity.
:returns: float
Ra = Gr*Pr
Characteristic dimensions:
* vertical plate: vertical length
* pipe: diameter
* bluff body: diameter
"""
return g * beta * (Ts - Tinf) * L**3.0 / (nu * alpha) | python | {
"resource": ""
} |
q262463 | Nu | validation | def Nu(L: float, h: float, k: float) -> float:
"""
Calculate the Nusselt number.
:param L: [m] heat transfer surface characteristic length.
:param h: [W/K/m2] convective heat transfer coefficient.
:param k: [W/K/m] fluid thermal conductivity.
:returns: float
"""
return h * L / k | python | {
"resource": ""
} |
q262464 | Sh | validation | def Sh(L: float, h: float, D: float) -> float:
"""
Calculate the Sherwood number.
:param L: [m] mass transfer surface characteristic length.
:param h: [m/s] mass transfer coefficient.
:param D: [m2/s] fluid mass diffusivity.
:returns: float
"""
return h * L / D | python | {
"resource": ""
} |
q262465 | PolynomialModelT.create | validation | def create(dataset, symbol, degree):
"""
Create a model object from the data set for the property specified by
the supplied symbol, using the specified polynomial degree.
:param dataset: a DataSet object
:param symbol: the symbol of the property to be described, e.g. 'rho'
:param degree: the polynomial degree to use
:returns: a new PolynomialModelT object
"""
x_vals = dataset.data['T'].tolist()
y_vals = dataset.data[symbol].tolist()
coeffs = np.polyfit(x_vals, y_vals, degree)
result = PolynomialModelT(dataset.material,
dataset.names_dict[symbol],
symbol, dataset.display_symbols_dict[symbol],
dataset.units_dict[symbol],
None, [dataset.name], coeffs)
result.state_schema['T']['min'] = float(min(x_vals))
result.state_schema['T']['max'] = float(max(x_vals))
return result | python | {
"resource": ""
} |
q262466 | PolynomialModelT.calculate | validation | def calculate(self, **state):
"""
Calculate the material physical property at the specified temperature
in the units specified by the object's 'property_units' property.
:param T: [K] temperature
:returns: physical property value
"""
super().calculate(**state)
return np.polyval(self._coeffs, state['T']) | python | {
"resource": ""
} |
q262467 | Component.create_component | validation | def create_component(self, name, description=None):
"""
Create a sub component in the business component.
:param name: The new component's name.
:param description: The new component's description.
:returns: The created component.
"""
new_comp = Component(name, self.gl, description=description)
new_comp.set_parent_path(self.path)
self.components.append(new_comp)
return new_comp | python | {
"resource": ""
} |
q262468 | Component.remove_component | validation | def remove_component(self, name):
"""
Remove a sub component from the component.
:param name: The name of the component to remove.
"""
component_to_remove = None
for c in self.components:
if c.name == name:
component_to_remove = c
if component_to_remove is not None:
self.components.remove(component_to_remove) | python | {
"resource": ""
} |
q262469 | Component.get_component | validation | def get_component(self, name):
"""
Retrieve a child component given its name.
:param name: The name of the component.
:returns: The component.
"""
return [c for c in self.components if c.name == name][0] | python | {
"resource": ""
} |
q262470 | Component.add_activity | validation | def add_activity(self, activity):
"""
Add an activity to the component.
:param activity: The activity.
"""
self.gl.structure.validate_account_names(
activity.get_referenced_accounts())
self.activities.append(activity)
activity.set_parent_path(self.path) | python | {
"resource": ""
} |
q262471 | Component.get_activity | validation | def get_activity(self, name):
"""
Retrieve an activity given its name.
:param name: The name of the activity.
:returns: The activity.
"""
return [a for a in self.activities if a.name == name][0] | python | {
"resource": ""
} |
q262472 | Component.prepare_to_run | validation | def prepare_to_run(self, clock, period_count):
"""
Prepare the component for execution.
:param clock: The clock containing the execution start time and
execution period information.
:param period_count: The total amount of periods this activity will be
requested to be run for.
"""
for c in self.components:
c.prepare_to_run(clock, period_count)
for a in self.activities:
a.prepare_to_run(clock, period_count) | python | {
"resource": ""
} |
q262473 | Component.run | validation | def run(self, clock, generalLedger):
"""
Execute the component at the current clock cycle.
:param clock: The clock containing the current execution time and
period information.
:param generalLedger: The general ledger into which to create the
transactions.
"""
for c in self.components:
c.run(clock, generalLedger)
for a in self.activities:
a.run(clock, generalLedger) | python | {
"resource": ""
} |
q262474 | Entity.prepare_to_run | validation | def prepare_to_run(self, clock, period_count):
"""
Prepare the entity for execution.
:param clock: The clock containing the execution start time and
execution period information.
:param period_count: The total amount of periods this activity will be
requested to be run for.
"""
self.period_count = period_count
self._exec_year_end_datetime = clock.get_datetime_at_period_ix(
period_count)
self._prev_year_end_datetime = clock.start_datetime
self._curr_year_end_datetime = clock.start_datetime + relativedelta(
years=1)
# Remove all the transactions
del self.gl.transactions[:]
for c in self.components:
c.prepare_to_run(clock, period_count)
self.negative_income_tax_total = 0 | python | {
"resource": ""
} |
q262475 | Entity.run | validation | def run(self, clock):
"""
Execute the entity at the current clock cycle.
:param clock: The clock containing the current execution time and
period information.
"""
if clock.timestep_ix >= self.period_count:
return
for c in self.components:
c.run(clock, self.gl)
self._perform_year_end_procedure(clock) | python | {
"resource": ""
} |
q262476 | count_with_multiplier | validation | def count_with_multiplier(groups, multiplier):
""" Update group counts with multiplier
This is for handling atom counts on groups like (OH)2
:param groups: iterable of Group/Element
:param multiplier: the number to multiply by
"""
counts = collections.defaultdict(float)
for group in groups:
for element, count in group.count().items():
counts[element] += count*multiplier
return counts | python | {
"resource": ""
} |
q262477 | amounts | validation | def amounts(masses):
"""
Calculate the amounts from the specified compound masses.
:param masses: [kg] dictionary, e.g. {'SiO2': 3.0, 'FeO': 1.5}
:returns: [kmol] dictionary
"""
return {compound: amount(compound, masses[compound])
for compound in masses.keys()} | python | {
"resource": ""
} |
q262478 | amount_fractions | validation | def amount_fractions(masses):
"""
Calculate the mole fractions from the specified compound masses.
:param masses: [kg] dictionary, e.g. {'SiO2': 3.0, 'FeO': 1.5}
:returns: [mole fractions] dictionary
"""
n = amounts(masses)
n_total = sum(n.values())
return {compound: n[compound]/n_total for compound in n.keys()} | python | {
"resource": ""
} |
q262479 | masses | validation | def masses(amounts):
"""
Calculate the masses from the specified compound amounts.
:param masses: [kmol] dictionary, e.g. {'SiO2': 3.0, 'FeO': 1.5}
:returns: [kg] dictionary
"""
return {compound: mass(compound, amounts[compound])
for compound in amounts.keys()} | python | {
"resource": ""
} |
q262480 | mass_fractions | validation | def mass_fractions(amounts):
"""
Calculate the mole fractions from the specified compound amounts.
:param amounts: [kmol] dictionary, e.g. {'SiO2': 3.0, 'FeO': 1.5}
:returns: [mass fractions] dictionary
"""
m = masses(amounts)
m_total = sum(m.values())
return {compound: m[compound]/m_total for compound in m.keys()} | python | {
"resource": ""
} |
q262481 | convert_compound | validation | def convert_compound(mass, source, target, element):
"""
Convert the specified mass of the source compound to the target using
element as basis.
:param mass: Mass of from_compound. [kg]
:param source: Formula and phase of the original compound, e.g.
'Fe2O3[S1]'.
:param target: Formula and phase of the target compound, e.g. 'Fe[S1]'.
:param element: Element to use as basis for the conversion, e.g. 'Fe' or
'O'.
:returns: Mass of target. [kg]
"""
# Perform the conversion.
target_mass_fraction = element_mass_fraction(target, element)
if target_mass_fraction == 0.0:
# If target_formula does not contain element, just return 0.0.
return 0.0
else:
source_mass_fraction = element_mass_fraction(source, element)
return mass * source_mass_fraction / target_mass_fraction | python | {
"resource": ""
} |
q262482 | element_mass_fraction | validation | def element_mass_fraction(compound, element):
"""
Determine the mass fraction of an element in a chemical compound.
:param compound: Formula of the chemical compound, 'FeCr2O4'.
:param element: Element, e.g. 'Cr'.
:returns: Element mass fraction.
"""
coeff = stoichiometry_coefficient(compound, element)
if coeff == 0.0:
return 0.0
formula_mass = molar_mass(compound)
element_mass = molar_mass(element)
return coeff * element_mass / formula_mass | python | {
"resource": ""
} |
q262483 | elements | validation | def elements(compounds):
"""
Determine the set of elements present in a list of chemical compounds.
The list of elements is sorted alphabetically.
:param compounds: List of compound formulas and phases, e.g.
['Fe2O3[S1]', 'Al2O3[S1]'].
:returns: List of elements.
"""
elementlist = [parse_compound(compound).count().keys()
for compound in compounds]
return set().union(*elementlist) | python | {
"resource": ""
} |
q262484 | molar_mass | validation | def molar_mass(compound=''):
"""Determine the molar mass of a chemical compound.
The molar mass is usually the mass of one mole of the substance, but here
it is the mass of 1000 moles, since the mass unit used in auxi is kg.
:param compound: Formula of a chemical compound, e.g. 'Fe2O3'.
:returns: Molar mass. [kg/kmol]
"""
result = 0.0
if compound is None or len(compound) == 0:
return result
compound = compound.strip()
parsed = parse_compound(compound)
return parsed.molar_mass() | python | {
"resource": ""
} |
q262485 | stoichiometry_coefficient | validation | def stoichiometry_coefficient(compound, element):
"""
Determine the stoichiometry coefficient of an element in a chemical
compound.
:param compound: Formula of a chemical compound, e.g. 'SiO2'.
:param element: Element, e.g. 'Si'.
:returns: Stoichiometry coefficient.
"""
stoichiometry = parse_compound(compound.strip()).count()
return stoichiometry[element] | python | {
"resource": ""
} |
q262486 | stoichiometry_coefficients | validation | def stoichiometry_coefficients(compound, elements):
"""
Determine the stoichiometry coefficients of the specified elements in
the specified chemical compound.
:param compound: Formula of a chemical compound, e.g. 'SiO2'.
:param elements: List of elements, e.g. ['Si', 'O', 'C'].
:returns: List of stoichiometry coefficients.
"""
stoichiometry = parse_compound(compound.strip()).count()
return [stoichiometry[element] for element in elements] | python | {
"resource": ""
} |
q262487 | MaterialPackage.add_to | validation | def add_to(self, other):
"""
Add another psd material package to this material package.
:param other: The other material package.
"""
# Add another package.
if type(other) is MaterialPackage:
# Packages of the same material.
if self.material == other.material:
self.size_class_masses = \
self.size_class_masses + other.size_class_masses
else: # Packages of different materials.
for size_class in other.material.size_classes:
if size_class not in self.material.size_classes:
raise Exception(
"Packages of '" + other.material.name +
"' cannot be added to packages of '" +
self.material.name +
"'. The size class '" + size_class +
"' was not found in '" + self.material.name + "'.")
self.add_to(
(size_class, other.get_size_class_mass(size_class)))
# Add the specified mass of the specified size class.
elif self._is_size_class_mass_tuple(other):
# Added material variables.
size_class = other[0]
compound_index = self.material.get_size_class_index(size_class)
mass = other[1]
# Create the result package.
self.size_class_masses[compound_index] = \
self.size_class_masses[compound_index] + mass
# If not one of the above, it must be an invalid argument.
else:
raise TypeError("Invalid addition argument.") | python | {
"resource": ""
} |
q262488 | Clock.get_datetime_at_period_ix | validation | def get_datetime_at_period_ix(self, ix):
"""
Get the datetime at a given period.
:param period: The index of the period.
:returns: The datetime.
"""
if self.timestep_period_duration == TimePeriod.millisecond:
return self.start_datetime + timedelta(milliseconds=ix)
elif self.timestep_period_duration == TimePeriod.second:
return self.start_datetime + timedelta(seconds=ix)
elif self.timestep_period_duration == TimePeriod.minute:
return self.start_datetime + timedelta(minutes=ix)
elif self.timestep_period_duration == TimePeriod.hour:
return self.start_datetime + timedelta(hours=ix)
elif self.timestep_period_duration == TimePeriod.day:
return self.start_datetime + relativedelta(days=ix)
elif self.timestep_period_duration == TimePeriod.week:
return self.start_datetime + relativedelta(days=ix*7)
elif self.timestep_period_duration == TimePeriod.month:
return self.start_datetime + relativedelta(months=ix)
elif self.timestep_period_duration == TimePeriod.year:
return self.start_datetime + relativedelta(years=ix) | python | {
"resource": ""
} |
q262489 | _get_default_data_path_ | validation | def _get_default_data_path_():
"""
Calculate the default path in which thermochemical data is stored.
:returns: Default path.
"""
module_path = os.path.dirname(sys.modules[__name__].__file__)
data_path = os.path.join(module_path, r'data/rao')
data_path = os.path.abspath(data_path)
return data_path | python | {
"resource": ""
} |
q262490 | _split_compound_string_ | validation | def _split_compound_string_(compound_string):
"""
Split a compound's combined formula and phase into separate strings for
the formula and phase.
:param compound_string: Formula and phase of a chemical compound, e.g.
'SiO2[S1]'.
:returns: Formula of chemical compound.
:returns: Phase of chemical compound.
"""
formula = compound_string.replace(']', '').split('[')[0]
phase = compound_string.replace(']', '').split('[')[1]
return formula, phase | python | {
"resource": ""
} |
q262491 | _finalise_result_ | validation | def _finalise_result_(compound, value, mass):
"""
Convert the value to its final form by unit conversions and multiplying
by mass.
:param compound: Compound object.
:param value: [J/mol] Value to be finalised.
:param mass: [kg] Mass of compound.
:returns: [kWh] Finalised value.
"""
result = value / 3.6E6 # J/x -> kWh/x
result = result / compound.molar_mass # x/mol -> x/kg
result = result * mass # x/kg -> x
return result | python | {
"resource": ""
} |
q262492 | write_compound_to_auxi_file | validation | def write_compound_to_auxi_file(directory, compound):
"""
Writes a compound to an auxi file at the specified directory.
:param dir: The directory.
:param compound: The compound.
"""
file_name = "Compound_" + compound.formula + ".json"
with open(os.path.join(directory, file_name), 'w') as f:
f.write(str(compound)) | python | {
"resource": ""
} |
q262493 | load_data_factsage | validation | def load_data_factsage(path=''):
"""
Load all the thermochemical data factsage files located at a path.
:param path: Path at which the data files are located.
"""
compounds.clear()
if path == '':
path = default_data_path
if not os.path.exists(path):
warnings.warn('The specified data file path does not exist. (%s)' % path)
return
files = glob.glob(os.path.join(path, 'Compound_*.txt'))
for file in files:
compound = Compound(_read_compound_from_factsage_file_(file))
compounds[compound.formula] = compound | python | {
"resource": ""
} |
q262494 | load_data_auxi | validation | def load_data_auxi(path=''):
"""
Load all the thermochemical data auxi files located at a path.
:param path: Path at which the data files are located.
"""
compounds.clear()
if path == '':
path = default_data_path
if not os.path.exists(path):
warnings.warn('The specified data file path does not exist. (%s)' % path)
return
files = glob.glob(os.path.join(path, 'Compound_*.json'))
for file in files:
compound = Compound.read(file)
compounds[compound.formula] = compound | python | {
"resource": ""
} |
q262495 | list_compounds | validation | def list_compounds():
"""
List all compounds that are currently loaded in the thermo module, and
their phases.
"""
print('Compounds currently loaded:')
for compound in sorted(compounds.keys()):
phases = compounds[compound].get_phase_list()
print('%s: %s' % (compound, ', '.join(phases))) | python | {
"resource": ""
} |
q262496 | Cp | validation | def Cp(compound_string, T, mass=1.0):
"""
Calculate the heat capacity of the compound for the specified temperature
and mass.
:param compound_string: Formula and phase of chemical compound, e.g.
'Fe2O3[S1]'.
:param T: [°C] temperature
:param mass: [kg]
:returns: [kWh/K] Heat capacity.
"""
formula, phase = _split_compound_string_(compound_string)
TK = T + 273.15
compound = compounds[formula]
result = compound.Cp(phase, TK)
return _finalise_result_(compound, result, mass) | python | {
"resource": ""
} |
q262497 | CpRecord.Cp | validation | def Cp(self, T):
"""
Calculate the heat capacity of the compound phase.
:param T: [K] temperature
:returns: [J/mol/K] Heat capacity.
"""
result = 0.0
for c, e in zip(self._coefficients, self._exponents):
result += c*T**e
return result | python | {
"resource": ""
} |
q262498 | CpRecord.H | validation | def H(self, T):
"""
Calculate the portion of enthalpy of the compound phase covered by this
Cp record.
:param T: [K] temperature
:returns: [J/mol] Enthalpy.
"""
result = 0.0
if T < self.Tmax:
lT = T
else:
lT = self.Tmax
Tref = self.Tmin
for c, e in zip(self._coefficients, self._exponents):
# Analytically integrate Cp(T).
if e == -1.0:
result += c * math.log(lT/Tref)
else:
result += c * (lT**(e+1.0) - Tref**(e+1.0)) / (e+1.0)
return result | python | {
"resource": ""
} |
q262499 | CpRecord.S | validation | def S(self, T):
"""
Calculate the portion of entropy of the compound phase covered by this
Cp record.
:param T: [K] temperature
:returns: Entropy. [J/mol/K]
"""
result = 0.0
if T < self.Tmax:
lT = T
else:
lT = self.Tmax
Tref = self.Tmin
for c, e in zip(self._coefficients, self._exponents):
# Create a modified exponent to analytically integrate Cp(T)/T
# instead of Cp(T).
e_modified = e - 1.0
if e_modified == -1.0:
result += c * math.log(lT/Tref)
else:
e_mod = e_modified + 1.0
result += c * (lT**e_mod - Tref**e_mod) / e_mod
return result | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.