HidroUFF Density Calculator
Versão 1.3.0
Developer's Guide
This application's main feature is the calculation of the density of gas mixtures, through the resolution of Peng Robinson's cubic equation of state. Currently, there are 20 substances already registered in the tool and support for adding new substances by the user. In addition, the tool has an interface in English, Portuguese and Spanish.
Getting started • Technology • Directory and file structure • Development • Quoting
Technology
- Python - version 3
- Python libraries:
- PyQt5
- Sympy
- Matplotlib
Directory and file structure
/bin
The /bin directory stores the application's executable files.
/data
The /data directory stores CSV files that contain the properties of the substances registered in the application, such as molar mass (g/mol), critical pressure (KPa), critical temperature (K) and acentric factor. Furthermore, it contains the values of the kij parameters that represent the interaction between each pair of substances.
/utility
The /utility directory contains the utility responsible for adding new substances to the application by transforming the files contained in /data into a single file called "constant.py" in /src for use by the application. To add new substances just follow the instructions in Getting started.
/src
Directory that stores the application's source code, composed of six modules:
main.py
Used to launch the application.
constant.py
They contain constants that store the values of the properties of substances that can be used by the program. This file is generated by the csvToPy utility from the files in /data. At each generation the file is overwritten.
imagesAndFonts.py
Stores the images and fonts used by the application in binary format. It is recommended not to make any changes to this file in order not to render it unusable.
gui.py
Module responsible for building the user interface through the PyQt5 library.
Class Ui_MainWindoow and your methods
-
add(self) -> None
Dynamically add frames for new substances.
:param self:
:rtype: None -
ajuda(self) -> None
Displays help screen.
:param self:
:rtype: None -
calcular(self) -> None
Reads data from the interface, gets the result for calculation when there is a single pressure and displays it on the screen.
:param self:
:rtype: None -
delete(self, botao) -> None
Delete frames of dynamically added substances.
:param self:
:rtype: None -
fecharTela(self) -> None
Closes the screen over the software or help screen.
:param self:
:rtype: None -
filtrar(self) -> list
Gets index of items already selected in the existing comboBox.
:param self:
:return aux: vector with indices of items already selected in the existing comboBox.
:rtype: list -
gerarGraficoAPartirDeArq(self) -> None
Opens file dialog for user to choose a .csv file separated by “;” with two columns: the first with pressure values and the second with specific mass values and generates the isotherm graph.
:param self:
:rtype: None -
gerarGraficoDaIsoterma(self) -> None
It reads data from the interface, gets the result for the calculation when there is a range of pressure values and generates the graph of the isotherm.
:param self:
:rtype: None -
getBotaoClicado(self, botao) -> int
Find which of the dynamic buttons was clicked.
:param self:
:return i: clicked dynamic button index :rtype: int -
getIndiceAtual(self) -> int
Gets index of the next item not yet selected in the existing comboBox.
:param self:
:return indice: index of the next item not yet selected in the existing comboBox. :rtype: int -
getLanguage(self) -> str
Discover system default language to set appropriate language according to languages available in application.
:param self:
:rtype: None -
input(self) -> list
Reads the data entered in the interface and checks if there is any problem with the data.
:param self:
:return inputs: inputs = [composicao, temperatura, pressao]
:rtype: list -
limparCampos(self) -> None
Clear the filled fields.
:param self:
:rtype: None -
mostrarMsgmDeErro(self, mensagem) -> None
Shows an error message on the screen.
:param self:
:param mensagem: string mostrada na tela
:rtype: None -
onClicked(self) -> bool
Checks if the radio button was clicked and displays the corresponding frame.
:param self:
:rtype: bool -
retranslateUi(self, MainWindow) -> None
Performs the translation of the elements present in the user interface to the selected language.
:param self:
:rtype: None -
salvarResultado(self) -> None
It reads data from the interface, gets the result for the calculation when there is a range of pressure values and saves the result in a CSV file.
:param self:
:rtype: None -
setarIdioma(self, MainWindow) -> None
Applies language change event when corresponding button is clicked according to chosen language.
:param self:
:rtype: None - setupUi(self, MainWindow) -> None
- Responsible for building all user interface elements on screen.
:param self:
:rtype: None -
sobre(self) -> None
Displays the screen about the software.
:param self:
:rtype: None
verificacaoDeEntrada.py
Contains the methods used to perform file and data entry verification.
Functions
-
verificar_arquivo(dados, t) -> bool
Checks if input .csv file has content in correct format.
:param dados: vector containing all lines of the read file.
:return: True, if the file is whole; false otherwise.
:rtype: bool -
verificar_campos_em_branco(vetor, pressaoUnica) -> bool
Checks for blank fields in input data.
:param vetor: list with all input data in format vector = [data regarding the composition of the mixture, temperature, pressure].
:param presssaoUnica: boolean indicating if there is a single pressure value or an interval.
:return: True, if there are blank fields; False otherwise.
:rtype: bool -
verificar_substancias_repetidas(vetor) -> bool
Checks whether repeated substances were selected from the mixture composition input data.
:param vetor: matrix with the dynamic elements of the interface referring to the composition of the mixture each line corresponds to a vector = [frame, comboBox, lineEdit, pushButton].
:return: True, if there are repeated substances; false otherwise.
:rtype: bool
calculadora.py
Contém os métodos utilizados para realização dos cálculos e processamento dos dados. Nos cálculos utiliza as propriedades das substâncias armazenadas em constant.py.
Functions
-
Ai(vsubs2, vki, vt, r) -> list
Calculates the ai term of each component.
:param vsubs2: list with substances
:param vki: ki term of the elements
:param vt: temperature in kelvin
:rtype: list -
Subs2(velementos, vsubs) -> list
Creates a new list of substances from ‘subs’ so that it is in the same order as the ‘elements’ list, to facilitate the calculation of aij.
:param velementos:
:param vsubs:
:rtype: list -
calcular_pressao_intervalo(composicao, temperatura, pressao_inicial, pressao_final, passo) -> list
Realiza o cálculo da massa específica quando é fornecido Performs the calculation of the specific mass when a range of pressure values is provided through the data received from the user in the interface mediated by the gui module.
:param composicao:
:param temperatura:
:param pressao_inicial:
:param pressao_final:
:param passo:
:return pressoes, mEspIsoterma: list of pressures and densities
:rtype: list -
calcular_pressao_unica(composicao, temperatura, pressao) -> float
It performs the calculation of the specific mass when a pressure value is provided through the data received from the user in the interface mediated by the gui module.
:param composicao:
:param temperatura:
:param pressao:
:return es: density
:rtype: float -
calculo_a(vsubs2, vx, vaij) -> float
Creating matrix aij and a.
:param vsubs2: list with the elements used
:rtype: list -
calculo_aij(vk_ij, vai, subs) -> list
Calculates the term ‘aij’ from the Peng Robison eq by multiplying the terms of the matrices aij and kij.
:param vk_ij: kij matrix already adjusted for the components used
:param go: matrix ‘ai’
:return: matrix aij
:rtype: list -
calculo_bi_PREOS(vsubs2, x) -> list
Calculates the bi parameters of Peng Robinson’s eq.
:param vsubs2: list with the elements used
:rtype: list -
calculo_ki_PREOS(vsubs2, x) -> list
Calculates the ki parameters of Peng Robinson’s eq.
:param vsubs2: list with the elements used
:rtype: list -
cont_massa_molar_mistura(vmassa, subs, x) -> list
Molar Mass Contribution of Each Fluid Molar Mass Contribution of Each Fluid.
:param vmassa: list with molar mass of each component of the mixture
:rtype: list -
conversao_atm(p_list) -> list
Converts ATM pressure to kPa.
:param p_list: lista com as pressoes em atm
:type p_list: list
:rtype: list -
converter_temperatura_kelvin(unidade, valor) -> float
Converts the given temperature in celsius or fahrenheit to kelvin.
:param unidade: indicates the temperature unit
:param valor: indicates the temperature value in the referred unit
:return valor: temperature value in kelvin
:rtype: float -
eq_cubica(b, c, d) -> list
Solves a cubic eq by returning a list of real roots.
:param b: parameter b of cubic eq of type ax³ + bx² + cx + d = 0
:type b: float
:param c: parameter c of cubic eq of type ax³ + bx² + cx + d = 0
:type c: float
:param d: parameter d of cubic eq of type ax³ + bx² + cx + d = 0
:type d: float
:return: retorna as raizes reais
:rtype: list -
formatar_dados_arquivo(dados) -> list
Transforms strings read from the file into an array of numbers.
:rtype: list
-
formatar_input_composicao(matrizComposicao) -> list
Format mix composition input so that it is in the order used by the program
:param matrizComposicao:
:return composicaoFormatada:
:rtype: list -
fracao_molar_substancias(velementos, vsubs, vfracao_molar) -> list
Create new molar fraction list from ‘molar fraction and subs’ so that it is in the same order as the ‘elements’ list, to facilitate the calculation of aij.
:param velementos: list with all available elements
:param vsubs: list with chosen elements
:param vfracao_molar: molar fraction of chosen elements
:return: list with molar fraction in correct order for calculations
:rtype: list -
input_composicao(composicao) -> list Create a list with the compositions.
:param composicao:
:rtype: list -
input_fracao(composicao) -> list
Create a list of molar fractions.
:param composicao:
:rtype: list -
ler_arquivo(nomeArquivo, codigo) -> list
Read data from file.
:return data: file data
:rtype: list -
lista_pressoes(p_inicial, p_final, passo) -> list
Creates a list with pressures according to the chosen step.
:param composicao:
:rtype: list -
massa_especifica_estavel(r_estavel, press, r, t, massa_molar_total) -> float
Calculates the stable density from the stable Z root.
:param r_stable: root stable
:return: returns stable root mass
:rtype: float -
massa_especifica_geral(b1, c1, d1, massa_molar_total, p, r, t) -> list
Calculate the density for all actual Z results.
:rtype: list
-
massa_especifica_isoterma(p_inicial, p_final, passo, a, r, t, b, massa_molar_total) -> list
Calculates the density according to the defined isotherm.
:rtype: list
-
matriz_kij(velementos, vsubs) -> list
Creates a matrix with the Kij that will be used in the calculation.
:param velementos: list with all available elements
:param vsubs: list with the elements used
:rtype: list -
obter_nome_padrao(codigo) -> str
Creates a default name for the file to be saved.
:return nomePadraoArquivo: name of file
:rtype: str -
plot_isoterma(listaPressoes, listaMassaEspIsoterma, t, codigo_idioma) -> None
Displays isotherm graph in a matplotlib window.
:rtype: None
-
prop_criticas(subs2) -> list
Creates lists for the critical properties of each element of the mix in element order.
:rtype: list
-
salvar_csv(m_esp, temperatura, composicao, nomeArquivo, codigo) -> None
Creates a csv file with the calculated specific masses.
:param m_esp: list in table form with the specific masses
:rtype: None -
salvar_txt(m_esp, temperatura, composicao, nomeArquivo, codigo) -> None
Creates a txt file with the calculated specific masses.
:param m_esp: list in table form with the specific masses
:rtype: None -
stable_root(Zlist, pressure, A, B) -> float
Defines the stable Z root from the fugacity calculation.
:param Zlist: list of Z values
:type Zlist: list
:param pressure: pressure value
:type pressure: float
:param A: parameter A of the cubic equation of PR
:type A: float
:param B: parameter B of the cubic equation of PR
:type B: float
:rtype: float -
tabela_massa_especifica(pressoes, me) -> list
Creates a table with the specific masses of the defined isotherm.
:rtype: list
-
to_tabela_composicao(composicao) -> list
Turns the composition dictionary into a table with the composition used in the calculation.
:param composition: list in table form with specific masses and pressure values :return: matrix with compositions
:rtype: list -
verificar_soma_fracao_molar(matrizComposicao) -> bool
Check if the sum of molar fractions is different from 1.0.
:param matrizComposicao: matrix that contains the name and value of each substance in the composition matrizComposicao[[SubstanceName, SubstanceValue],…]
:return: true, if sum is different from 1.0. false otherwise
:rtype: bool
Development
- Developed by:
- Mateus Pereira de Sousa
- Valesca Moura de Sousa
- Advisors:
- Felipe Pereira de Moura
- Fernanda Gonçalves de Oliveira Passos
- Rogério Fernandes de Lacerda
- HidroUFF Laboratory
- Creation date: 08/18/2020
- Last revised: 09/14/2021
- Any suggestions or questions about the application, communicate one of the responsible: lab.hidrouff.tce@id.uff.br
Quoting
If the HidroUFF Specific Mass Calculator contributed to any project or research that resulted in a publication, please cite it.