barotropy 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- barotropy-0.0.2/LICENSE.md +9 -0
- barotropy-0.0.2/PKG-INFO +218 -0
- barotropy-0.0.2/README.md +191 -0
- barotropy-0.0.2/barotropy/__init__.py +69 -0
- barotropy-0.0.2/barotropy/barotropic_model.py +322 -0
- barotropy-0.0.2/barotropy/fluent_automation/__init__.py +5 -0
- barotropy-0.0.2/barotropy/fluent_automation/fluent_automation.py +970 -0
- barotropy-0.0.2/barotropy/fluent_automation/fluent_plot_nozzle_data.py +183 -0
- barotropy-0.0.2/barotropy/fluent_automation/stream_residuals.py +93 -0
- barotropy-0.0.2/barotropy/fluent_automation/stream_transcript.py +24 -0
- barotropy-0.0.2/barotropy/fluid_properties/__init__.py +5 -0
- barotropy-0.0.2/barotropy/fluid_properties/core.py +1470 -0
- barotropy-0.0.2/barotropy/fluid_properties/low_level_interface.py +918 -0
- barotropy-0.0.2/barotropy/isentropic_nozzle.py +102 -0
- barotropy-0.0.2/barotropy/math.py +446 -0
- barotropy-0.0.2/barotropy/matlab/FluidCoolProp_2Phase.m +365 -0
- barotropy-0.0.2/barotropy/matlab/compute_properties_isentrope.m +36 -0
- barotropy-0.0.2/barotropy/matlab/compute_properties_metastable_Td.m +53 -0
- barotropy-0.0.2/barotropy/matlab/compute_properties_metastable_ps.m +64 -0
- barotropy-0.0.2/barotropy/matlab/compute_pseudocritical_line.m +27 -0
- barotropy-0.0.2/barotropy/matlab/compute_pseudocritical_point.m +36 -0
- barotropy-0.0.2/barotropy/matlab/compute_saturation_line.m +49 -0
- barotropy-0.0.2/barotropy/matlab/compute_saturation_point_entropy.m +48 -0
- barotropy-0.0.2/barotropy/matlab/compute_spinodal_line.m +65 -0
- barotropy-0.0.2/barotropy/matlab/compute_spinodal_point.m +125 -0
- barotropy-0.0.2/barotropy/matlab/compute_spinodal_point_entropy.m +192 -0
- barotropy-0.0.2/barotropy/matlab/create_barotropic_model.m +281 -0
- barotropy-0.0.2/barotropy/matlab/create_barotropic_model_segment.m +48 -0
- barotropy-0.0.2/barotropy/matlab/evaluate_isentrope_polynomials.m +58 -0
- barotropy-0.0.2/barotropy/matlab/export_fluent_expressions.m +122 -0
- barotropy-0.0.2/barotropy/matlab/plot_barotropic_model.m +106 -0
- barotropy-0.0.2/barotropy/matlab/plot_barotropic_polynomials.m +86 -0
- barotropy-0.0.2/barotropy/matlab/plot_barotropic_process_ps.m +90 -0
- barotropy-0.0.2/barotropy/matlab/plot_phase_diagram.m +83 -0
- barotropy-0.0.2/barotropy/matlab/set_plot_options.m +70 -0
- barotropy-0.0.2/barotropy/plot_options.py +260 -0
- barotropy-0.0.2/barotropy/pysolver_view/__init__.py +25 -0
- barotropy-0.0.2/barotropy/pysolver_view/nonlinear_system.py +614 -0
- barotropy-0.0.2/barotropy/pysolver_view/nonlinear_system_problems.py +59 -0
- barotropy-0.0.2/barotropy/pysolver_view/numerical_differentiation.py +236 -0
- barotropy-0.0.2/barotropy/pysolver_view/optimization.py +988 -0
- barotropy-0.0.2/barotropy/pysolver_view/optimization_problems.py +273 -0
- barotropy-0.0.2/barotropy/pysolver_view/optimization_wrappers.py +509 -0
- barotropy-0.0.2/barotropy/pysolver_view/pysolver_utilities.py +288 -0
- barotropy-0.0.2/barotropy/sCO2_utilities.py +259 -0
- barotropy-0.0.2/barotropy/utilities.py +780 -0
- barotropy-0.0.2/pyproject.toml +42 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Roberto Agromayor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
barotropy-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: barotropy
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A Python tool for barotropic fluid property modeling.
|
|
5
|
+
Home-page: https://github.com/turbo-sim/barotropy
|
|
6
|
+
License: MIT
|
|
7
|
+
Author: Roberto Agromayor
|
|
8
|
+
Requires-Python: >=3.11,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Requires-Dist: CoolProp (>=6.6.0,<7.0.0)
|
|
14
|
+
Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
|
|
15
|
+
Requires-Dist: cycler (>=0.12.1,<0.13.0)
|
|
16
|
+
Requires-Dist: matplotlib (>=3.9.0,<4.0.0)
|
|
17
|
+
Requires-Dist: numpy (>=1.26.4,<2.0.0)
|
|
18
|
+
Requires-Dist: openpyxl (>=3.1.2,<4.0.0)
|
|
19
|
+
Requires-Dist: pandas (>=2.2.2,<3.0.0)
|
|
20
|
+
Requires-Dist: parse (>=1.20.2,<2.0.0)
|
|
21
|
+
Requires-Dist: scipy (>=1.13.1,<2.0.0)
|
|
22
|
+
Requires-Dist: toml (>=0.10.2,<0.11.0)
|
|
23
|
+
Project-URL: Documentation, https://turbo-sim.github.io/barotropy/
|
|
24
|
+
Project-URL: Repository, https://github.com/turbo-sim/barotropy
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# Barotropic Model
|
|
28
|
+
|
|
29
|
+
[Documentation hosted here](https://turbo-sim.github.io/barotropy/)
|
|
30
|
+
|
|
31
|
+
## Description
|
|
32
|
+
This repository contains functions to generate a barotropic model for fluid properties. A barotropic model is a simplified mathematical representation that assumes the fluid's properties are only a function of pressure. This is simplification can be useful to model flows in which the fluid approximatelly follows a known thermodynamic process, such as an isentropic process within a turbine or compressor
|
|
33
|
+
|
|
34
|
+
>Note that using a barotropic model in the context of a CFD simulation does not imply that the flow is frictionless since the momentum equations can have dissipation terms due to viscous friction. Instead, the implication of using the barotropic model is that the variation of fluid properties caused by viscous dissipation (i.e., entropy generation and heating) is ignored.
|
|
35
|
+
|
|
36
|
+
The script `barotropic_model.m` evaluates the properties of the fluid (e.g., density, viscosity, heat capacity, conductivity) along a line of constant entropy using the CoolProp library. Once computed, the fluid properties are automatically fitted with piece-wise polynomials and exported as [Fluent Expressions](https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v232/en/flu_ug/flu_ug_expressions_intro.html) to be used in conjuction with Fluent's pressure-based solver.
|
|
37
|
+
|
|
38
|
+
The fluid properties between the saturation line and the spinodal line can be computed according to phase-equilibrium or by extrapolation the Helmholtz-energy equation of state into the metastable region. Check the [documentation](./documentation/thermodynamic_properties.md) for more information about extrapolating the equation of state beyond the saturation line and its limitations.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Getting started
|
|
42
|
+
|
|
43
|
+
The installation instructions ar edetailed in the next section. The script below contains a minimum working example to get started with the code:
|
|
44
|
+
|
|
45
|
+
``` matlab
|
|
46
|
+
%% Minimum working example showcasing the barotropic model
|
|
47
|
+
% Clear the workspace
|
|
48
|
+
clear all %#ok
|
|
49
|
+
close all
|
|
50
|
+
clc
|
|
51
|
+
|
|
52
|
+
% Add path to utility functions
|
|
53
|
+
addpath(genpath("dependencies"))
|
|
54
|
+
|
|
55
|
+
% Set plot options
|
|
56
|
+
save_figures = false;
|
|
57
|
+
set_plot_options()
|
|
58
|
+
|
|
59
|
+
% Define the fluid name and create the fluid object
|
|
60
|
+
fluid_name = 'CO2';
|
|
61
|
+
fluid = FluidCoolProp_2Phase('HEOS', fluid_name);
|
|
62
|
+
|
|
63
|
+
% Define the inlet state
|
|
64
|
+
T_in = 300; % Kelvin degrees
|
|
65
|
+
p_in = 90e5; % Pascals
|
|
66
|
+
|
|
67
|
+
% Define the order of the polynomials
|
|
68
|
+
polynomial_order = 6;
|
|
69
|
+
|
|
70
|
+
% Extrapolate equation of state between the saturation and spinodal lines
|
|
71
|
+
include_metastable = true;
|
|
72
|
+
|
|
73
|
+
% Compute properties along isentrope
|
|
74
|
+
isentrope_segments = create_barotropic_model(T_in, p_in, fluid, ...
|
|
75
|
+
include_metastable=include_metastable, ...
|
|
76
|
+
polynomial_order=polynomial_order, ...
|
|
77
|
+
properties={'rhomass'});
|
|
78
|
+
|
|
79
|
+
% Plot barotropic process in p-s diagram
|
|
80
|
+
plot_barotropic_process_ps(fluid, isentrope_segments, ...
|
|
81
|
+
save_figures=save_figures, ...
|
|
82
|
+
plot_spinodal_line=true, ...
|
|
83
|
+
spinodal_line_method='robust', ...
|
|
84
|
+
plot_quality_isolines=true, ...
|
|
85
|
+
quality_labels=true, ...
|
|
86
|
+
show_in_legend=false)
|
|
87
|
+
|
|
88
|
+
% Plot barotropic model fitting
|
|
89
|
+
plot_barotropic_polynomials(fluid, isentrope_segments, save_figures=save_figures)
|
|
90
|
+
|
|
91
|
+
% Export fitted polynomials
|
|
92
|
+
export_fluent_expressions(fluid, isentrope_segments)
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Executing this script will evaluate the density of carbon dioxide along the isentrope passing through the thermodynamic state defined by $T=300$ K and $p=90$ bar. If we set `include_metastable=true`, the code will extrapolate the equation of state between the saturation and spinodal lines. Therefore, the isentrope line will be divided in 3 segments:
|
|
97
|
+
1. Single-phase region
|
|
98
|
+
2. Metastable region
|
|
99
|
+
3. Two-phase region
|
|
100
|
+
|
|
101
|
+
In addition, the script will fit a polynomial of degree 4 to each of the isentrope segments and will plot the piece-wise polynomials and the fitting error:
|
|
102
|
+
|
|
103
|
+

|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
Finally, the code will generate the following Fluent Expression that can be directly copy-pasted into the [Fluent Expression Manager](https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v232/en/flu_ug/flu_ug_expressions_create_and_use.html):
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
Fluent expressions of CO2 properties along an isentrope
|
|
110
|
+
Creation datetime: 14-Aug-2023 15:24:58
|
|
111
|
+
|
|
112
|
+
rhomass_barotropic_model_CO2
|
|
113
|
+
IF(AbsolutePressure>=5.179643e+05 [Pa],
|
|
114
|
+
IF(AbsolutePressure>=4.189928e+06 [Pa],
|
|
115
|
+
IF(AbsolutePressure>=5.936887e+06 [Pa],
|
|
116
|
+
+6.381823e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
117
|
+
(+2.748104e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
118
|
+
(-2.408267e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
119
|
+
(+1.217994e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
120
|
+
(-2.491639e+01)))),
|
|
121
|
+
-1.123298e+03 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
122
|
+
(+1.004366e+04 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
123
|
+
(-2.056259e+04 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
124
|
+
(+1.890792e+04 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
125
|
+
(-6.534217e+03))))),
|
|
126
|
+
+1.298915e+00 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
127
|
+
(+4.120057e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
128
|
+
(+3.715987e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
129
|
+
(+7.977732e+01 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
130
|
+
(+3.169611e+02))))),
|
|
131
|
+
3.209318e+01*exp((AbsolutePressure - 5.179643e+05 [Pa])/7.377300e+06 [Pa])) * 1 [kg/m^3]
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Note the following aspects of the Fluent expression:
|
|
135
|
+
- The absolute pressure is normalized by the critical pressure to improve the [conditioning of the polynomial fitting](https://www.mathworks.com/help/matlab/ref/polyfit.html).
|
|
136
|
+
- The polynomials are represented in [Horner's form](https://en.wikipedia.org/wiki/Horner%27s_method) to reduce the computational cost and improve the numerical stability of the model.
|
|
137
|
+
- The expression uses an exponential function to extend the properties below the triple pressure. This is necessary to ensure that the barotropic model can handle negative pressures that might take place before the Fluent solver converges to a physically meaningful solution.
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
## Installation
|
|
141
|
+
In order to use the code you need a MATLAB installation. Also, make sure that the `barotropic_model.m` script includes a code-line to add the folder [`dependencies`](./dependencies) to the MATLAB path:
|
|
142
|
+
``` matlab
|
|
143
|
+
addpath(genpath("dependencies"))
|
|
144
|
+
```
|
|
145
|
+
In addition, you need to install the CoolProp fluid property library and interface it with MATLAB through Python. Check the step-by-step instructions below to learn how to interface MATLAB with CoolProp in a Windows operating system. The installation for Linux or Mac operating systems would be similar.
|
|
146
|
+
#### Step 1 - Download and install Miniconda
|
|
147
|
+
[Download the installer](https://docs.conda.io/projects/conda/en/latest/user-guide/install/windows.html) and follow the instructions until the installation is completed.
|
|
148
|
+
|
|
149
|
+
In order to use the Conda from from the [Git Bash](https://gitforwindows.org/) teminal, you have to initialize it in your terminal session. The easiest way to achieve this in a permanent way is to modify your `.bashrc` file to initialize conda each time that bash is started. Open your bash terminal and type the following command:
|
|
150
|
+
``` bash
|
|
151
|
+
echo ". \${HOME}/AppData/Local/miniconda3/etc/profile.d/conda.sh" >> ~/.bashrc
|
|
152
|
+
```
|
|
153
|
+
This will add a new line to your `.bashrc` file that will execute `conda.sh` each time that you open the bash terminal. To check if the command worked, you can open your `.bashrc` file:
|
|
154
|
+
```bash
|
|
155
|
+
notepad ~/.bashrc
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### Step 2 - Create a virtual environment and install CoolProp
|
|
159
|
+
Open a new Git Bash terminal and type the following command to create a new virtual environment named `coolprop_env`:
|
|
160
|
+
```shell
|
|
161
|
+
conda create --name coolprop_env python=3.8
|
|
162
|
+
```
|
|
163
|
+
Now that the environment is created, you can activate it. Just use the following command:
|
|
164
|
+
```shell
|
|
165
|
+
conda activate coolprop_env
|
|
166
|
+
```
|
|
167
|
+
Finally, type the following command to install CoolProp:
|
|
168
|
+
```shell
|
|
169
|
+
conda install CoolProp --channel conda-forge
|
|
170
|
+
```
|
|
171
|
+
That's it! Note that it was necessary to tell Miniconda that it should look for Coolprop in the `conda-forge` channel.
|
|
172
|
+
|
|
173
|
+
#### Step 3 - Interface MATLAB and Coolprop
|
|
174
|
+
Open MATLAB (or close and open it if it was already open) and type the following command to let MATLAB know where is the Python executable (python.exe) of the virtual environment that you have just created:
|
|
175
|
+
```matlab
|
|
176
|
+
pyversion(fullfile(char(java.lang.System.getProperty('user.home')), '\AppData\Local\miniconda3\envs\coolprop_env\python.exe'))
|
|
177
|
+
```
|
|
178
|
+
This command will find the Python executable of the `coolprop_env` environment installed in your home directory.
|
|
179
|
+
|
|
180
|
+
Good! You have installed CoolProp and interfaced it with MATLAB. Let's do a simple test to check if the installation was successful. We are going to use CoolProp to compute the saturation temperature of water at atmospheric pressure. Just type the following command in MATLAB:
|
|
181
|
+
```matlab
|
|
182
|
+
py.CoolProp.CoolProp.PropsSI('T','P',101325,'Q',0,'Water')
|
|
183
|
+
```
|
|
184
|
+
If this does not throw and error and returns 373.1243 K, the installation was successful.
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
The code in this repository is licensed under the terms of the MIT license. See the [license file](LICENSE.md) for more information.
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
## Contact information
|
|
192
|
+
The code in this repository was developed by Roberto Agromayor at the Department of Civil and Mechanical Engineering of DTU. Drop an email to roagr@dtu.dk if you have questions about the code or you have a bug to report!
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
## Installation advanced
|
|
198
|
+
If you are using [Conda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/windows.html), you can use the following [Bash](https://gitforwindows.org/) command to create a new virtual environment with all the dependencies required to run the code in this repository:
|
|
199
|
+
``` bash
|
|
200
|
+
conda env create --file environment.yaml
|
|
201
|
+
```
|
|
202
|
+
This will create the `barotropic_env` virtual environment and install all the packages in the specified in the YAML file.
|
|
203
|
+
|
|
204
|
+
To activate the virtual environment use:
|
|
205
|
+
``` bash
|
|
206
|
+
conda activate barotropic_env
|
|
207
|
+
```
|
|
208
|
+
If you need to install additional packages you can use the following command:
|
|
209
|
+
``` bash
|
|
210
|
+
conda install <name of the package>
|
|
211
|
+
```
|
|
212
|
+
You can also install new packages by adding their names to the `environment.yaml` file and updating the environment (using `--prune` removes any dependencies that are no longer required):
|
|
213
|
+
``` bash
|
|
214
|
+
conda env update --file environment.yaml --prune
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Barotropic Model
|
|
2
|
+
|
|
3
|
+
[Documentation hosted here](https://turbo-sim.github.io/barotropy/)
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
This repository contains functions to generate a barotropic model for fluid properties. A barotropic model is a simplified mathematical representation that assumes the fluid's properties are only a function of pressure. This is simplification can be useful to model flows in which the fluid approximatelly follows a known thermodynamic process, such as an isentropic process within a turbine or compressor
|
|
7
|
+
|
|
8
|
+
>Note that using a barotropic model in the context of a CFD simulation does not imply that the flow is frictionless since the momentum equations can have dissipation terms due to viscous friction. Instead, the implication of using the barotropic model is that the variation of fluid properties caused by viscous dissipation (i.e., entropy generation and heating) is ignored.
|
|
9
|
+
|
|
10
|
+
The script `barotropic_model.m` evaluates the properties of the fluid (e.g., density, viscosity, heat capacity, conductivity) along a line of constant entropy using the CoolProp library. Once computed, the fluid properties are automatically fitted with piece-wise polynomials and exported as [Fluent Expressions](https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v232/en/flu_ug/flu_ug_expressions_intro.html) to be used in conjuction with Fluent's pressure-based solver.
|
|
11
|
+
|
|
12
|
+
The fluid properties between the saturation line and the spinodal line can be computed according to phase-equilibrium or by extrapolation the Helmholtz-energy equation of state into the metastable region. Check the [documentation](./documentation/thermodynamic_properties.md) for more information about extrapolating the equation of state beyond the saturation line and its limitations.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Getting started
|
|
16
|
+
|
|
17
|
+
The installation instructions ar edetailed in the next section. The script below contains a minimum working example to get started with the code:
|
|
18
|
+
|
|
19
|
+
``` matlab
|
|
20
|
+
%% Minimum working example showcasing the barotropic model
|
|
21
|
+
% Clear the workspace
|
|
22
|
+
clear all %#ok
|
|
23
|
+
close all
|
|
24
|
+
clc
|
|
25
|
+
|
|
26
|
+
% Add path to utility functions
|
|
27
|
+
addpath(genpath("dependencies"))
|
|
28
|
+
|
|
29
|
+
% Set plot options
|
|
30
|
+
save_figures = false;
|
|
31
|
+
set_plot_options()
|
|
32
|
+
|
|
33
|
+
% Define the fluid name and create the fluid object
|
|
34
|
+
fluid_name = 'CO2';
|
|
35
|
+
fluid = FluidCoolProp_2Phase('HEOS', fluid_name);
|
|
36
|
+
|
|
37
|
+
% Define the inlet state
|
|
38
|
+
T_in = 300; % Kelvin degrees
|
|
39
|
+
p_in = 90e5; % Pascals
|
|
40
|
+
|
|
41
|
+
% Define the order of the polynomials
|
|
42
|
+
polynomial_order = 6;
|
|
43
|
+
|
|
44
|
+
% Extrapolate equation of state between the saturation and spinodal lines
|
|
45
|
+
include_metastable = true;
|
|
46
|
+
|
|
47
|
+
% Compute properties along isentrope
|
|
48
|
+
isentrope_segments = create_barotropic_model(T_in, p_in, fluid, ...
|
|
49
|
+
include_metastable=include_metastable, ...
|
|
50
|
+
polynomial_order=polynomial_order, ...
|
|
51
|
+
properties={'rhomass'});
|
|
52
|
+
|
|
53
|
+
% Plot barotropic process in p-s diagram
|
|
54
|
+
plot_barotropic_process_ps(fluid, isentrope_segments, ...
|
|
55
|
+
save_figures=save_figures, ...
|
|
56
|
+
plot_spinodal_line=true, ...
|
|
57
|
+
spinodal_line_method='robust', ...
|
|
58
|
+
plot_quality_isolines=true, ...
|
|
59
|
+
quality_labels=true, ...
|
|
60
|
+
show_in_legend=false)
|
|
61
|
+
|
|
62
|
+
% Plot barotropic model fitting
|
|
63
|
+
plot_barotropic_polynomials(fluid, isentrope_segments, save_figures=save_figures)
|
|
64
|
+
|
|
65
|
+
% Export fitted polynomials
|
|
66
|
+
export_fluent_expressions(fluid, isentrope_segments)
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Executing this script will evaluate the density of carbon dioxide along the isentrope passing through the thermodynamic state defined by $T=300$ K and $p=90$ bar. If we set `include_metastable=true`, the code will extrapolate the equation of state between the saturation and spinodal lines. Therefore, the isentrope line will be divided in 3 segments:
|
|
71
|
+
1. Single-phase region
|
|
72
|
+
2. Metastable region
|
|
73
|
+
3. Two-phase region
|
|
74
|
+
|
|
75
|
+
In addition, the script will fit a polynomial of degree 4 to each of the isentrope segments and will plot the piece-wise polynomials and the fitting error:
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
Finally, the code will generate the following Fluent Expression that can be directly copy-pasted into the [Fluent Expression Manager](https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v232/en/flu_ug/flu_ug_expressions_create_and_use.html):
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
Fluent expressions of CO2 properties along an isentrope
|
|
84
|
+
Creation datetime: 14-Aug-2023 15:24:58
|
|
85
|
+
|
|
86
|
+
rhomass_barotropic_model_CO2
|
|
87
|
+
IF(AbsolutePressure>=5.179643e+05 [Pa],
|
|
88
|
+
IF(AbsolutePressure>=4.189928e+06 [Pa],
|
|
89
|
+
IF(AbsolutePressure>=5.936887e+06 [Pa],
|
|
90
|
+
+6.381823e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
91
|
+
(+2.748104e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
92
|
+
(-2.408267e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
93
|
+
(+1.217994e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
94
|
+
(-2.491639e+01)))),
|
|
95
|
+
-1.123298e+03 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
96
|
+
(+1.004366e+04 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
97
|
+
(-2.056259e+04 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
98
|
+
(+1.890792e+04 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
99
|
+
(-6.534217e+03))))),
|
|
100
|
+
+1.298915e+00 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
101
|
+
(+4.120057e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
102
|
+
(+3.715987e+02 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
103
|
+
(+7.977732e+01 + (AbsolutePressure/7.377300e+06 [Pa])*
|
|
104
|
+
(+3.169611e+02))))),
|
|
105
|
+
3.209318e+01*exp((AbsolutePressure - 5.179643e+05 [Pa])/7.377300e+06 [Pa])) * 1 [kg/m^3]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Note the following aspects of the Fluent expression:
|
|
109
|
+
- The absolute pressure is normalized by the critical pressure to improve the [conditioning of the polynomial fitting](https://www.mathworks.com/help/matlab/ref/polyfit.html).
|
|
110
|
+
- The polynomials are represented in [Horner's form](https://en.wikipedia.org/wiki/Horner%27s_method) to reduce the computational cost and improve the numerical stability of the model.
|
|
111
|
+
- The expression uses an exponential function to extend the properties below the triple pressure. This is necessary to ensure that the barotropic model can handle negative pressures that might take place before the Fluent solver converges to a physically meaningful solution.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
## Installation
|
|
115
|
+
In order to use the code you need a MATLAB installation. Also, make sure that the `barotropic_model.m` script includes a code-line to add the folder [`dependencies`](./dependencies) to the MATLAB path:
|
|
116
|
+
``` matlab
|
|
117
|
+
addpath(genpath("dependencies"))
|
|
118
|
+
```
|
|
119
|
+
In addition, you need to install the CoolProp fluid property library and interface it with MATLAB through Python. Check the step-by-step instructions below to learn how to interface MATLAB with CoolProp in a Windows operating system. The installation for Linux or Mac operating systems would be similar.
|
|
120
|
+
#### Step 1 - Download and install Miniconda
|
|
121
|
+
[Download the installer](https://docs.conda.io/projects/conda/en/latest/user-guide/install/windows.html) and follow the instructions until the installation is completed.
|
|
122
|
+
|
|
123
|
+
In order to use the Conda from from the [Git Bash](https://gitforwindows.org/) teminal, you have to initialize it in your terminal session. The easiest way to achieve this in a permanent way is to modify your `.bashrc` file to initialize conda each time that bash is started. Open your bash terminal and type the following command:
|
|
124
|
+
``` bash
|
|
125
|
+
echo ". \${HOME}/AppData/Local/miniconda3/etc/profile.d/conda.sh" >> ~/.bashrc
|
|
126
|
+
```
|
|
127
|
+
This will add a new line to your `.bashrc` file that will execute `conda.sh` each time that you open the bash terminal. To check if the command worked, you can open your `.bashrc` file:
|
|
128
|
+
```bash
|
|
129
|
+
notepad ~/.bashrc
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### Step 2 - Create a virtual environment and install CoolProp
|
|
133
|
+
Open a new Git Bash terminal and type the following command to create a new virtual environment named `coolprop_env`:
|
|
134
|
+
```shell
|
|
135
|
+
conda create --name coolprop_env python=3.8
|
|
136
|
+
```
|
|
137
|
+
Now that the environment is created, you can activate it. Just use the following command:
|
|
138
|
+
```shell
|
|
139
|
+
conda activate coolprop_env
|
|
140
|
+
```
|
|
141
|
+
Finally, type the following command to install CoolProp:
|
|
142
|
+
```shell
|
|
143
|
+
conda install CoolProp --channel conda-forge
|
|
144
|
+
```
|
|
145
|
+
That's it! Note that it was necessary to tell Miniconda that it should look for Coolprop in the `conda-forge` channel.
|
|
146
|
+
|
|
147
|
+
#### Step 3 - Interface MATLAB and Coolprop
|
|
148
|
+
Open MATLAB (or close and open it if it was already open) and type the following command to let MATLAB know where is the Python executable (python.exe) of the virtual environment that you have just created:
|
|
149
|
+
```matlab
|
|
150
|
+
pyversion(fullfile(char(java.lang.System.getProperty('user.home')), '\AppData\Local\miniconda3\envs\coolprop_env\python.exe'))
|
|
151
|
+
```
|
|
152
|
+
This command will find the Python executable of the `coolprop_env` environment installed in your home directory.
|
|
153
|
+
|
|
154
|
+
Good! You have installed CoolProp and interfaced it with MATLAB. Let's do a simple test to check if the installation was successful. We are going to use CoolProp to compute the saturation temperature of water at atmospheric pressure. Just type the following command in MATLAB:
|
|
155
|
+
```matlab
|
|
156
|
+
py.CoolProp.CoolProp.PropsSI('T','P',101325,'Q',0,'Water')
|
|
157
|
+
```
|
|
158
|
+
If this does not throw and error and returns 373.1243 K, the installation was successful.
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
The code in this repository is licensed under the terms of the MIT license. See the [license file](LICENSE.md) for more information.
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
## Contact information
|
|
166
|
+
The code in this repository was developed by Roberto Agromayor at the Department of Civil and Mechanical Engineering of DTU. Drop an email to roagr@dtu.dk if you have questions about the code or you have a bug to report!
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
## Installation advanced
|
|
172
|
+
If you are using [Conda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/windows.html), you can use the following [Bash](https://gitforwindows.org/) command to create a new virtual environment with all the dependencies required to run the code in this repository:
|
|
173
|
+
``` bash
|
|
174
|
+
conda env create --file environment.yaml
|
|
175
|
+
```
|
|
176
|
+
This will create the `barotropic_env` virtual environment and install all the packages in the specified in the YAML file.
|
|
177
|
+
|
|
178
|
+
To activate the virtual environment use:
|
|
179
|
+
``` bash
|
|
180
|
+
conda activate barotropic_env
|
|
181
|
+
```
|
|
182
|
+
If you need to install additional packages you can use the following command:
|
|
183
|
+
``` bash
|
|
184
|
+
conda install <name of the package>
|
|
185
|
+
```
|
|
186
|
+
You can also install new packages by adding their names to the `environment.yaml` file and updating the environment (using `--prune` removes any dependencies that are no longer required):
|
|
187
|
+
``` bash
|
|
188
|
+
conda env update --file environment.yaml --prune
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Highlight exception messages
|
|
2
|
+
# https://stackoverflow.com/questions/25109105/how-to-colorize-the-output-of-python-errors-in-the-gnome-terminal/52797444#52797444
|
|
3
|
+
try:
|
|
4
|
+
import IPython.core.ultratb
|
|
5
|
+
except ImportError:
|
|
6
|
+
# No IPython. Use default exception printing.
|
|
7
|
+
pass
|
|
8
|
+
else:
|
|
9
|
+
import sys
|
|
10
|
+
sys.excepthook = IPython.core.ultratb.ColorTB()
|
|
11
|
+
|
|
12
|
+
# Import subpackages
|
|
13
|
+
from .fluent_automation import *
|
|
14
|
+
from .fluid_properties import *
|
|
15
|
+
from .barotropic_model import *
|
|
16
|
+
|
|
17
|
+
# Import submodules
|
|
18
|
+
from .math import *
|
|
19
|
+
from .plot_options import *
|
|
20
|
+
from .sCO2_utilities import *
|
|
21
|
+
from .utilities import *
|
|
22
|
+
|
|
23
|
+
# Package info
|
|
24
|
+
__version__ = "0.0.2"
|
|
25
|
+
PACKAGE_NAME = "barotropy"
|
|
26
|
+
URL_GITHUB = "https://github.com/turbo-sim/barotropy"
|
|
27
|
+
URL_DOCS = "https://turbo-sim.github.io/barotropy/"
|
|
28
|
+
URL_DTU = "https://thermalpower.dtu.dk/"
|
|
29
|
+
BREAKLINE = 80 * "-"
|
|
30
|
+
|
|
31
|
+
def print_banner():
|
|
32
|
+
"""Prints a banner."""
|
|
33
|
+
banner = """
|
|
34
|
+
____ __
|
|
35
|
+
/ __ )____ __________ / /__________ ____ __ __
|
|
36
|
+
/ __ / __ `/ ___/ __ \/ __/ ___/ __ \/ __ \/ / / /
|
|
37
|
+
/ /_/ / /_/ / / / /_/ / /_/ / / /_/ / /_/ / /_/ /
|
|
38
|
+
/_____/\__,_/_/ \____/\__/_/ \____/ .___/\__, /
|
|
39
|
+
/_/ /____/
|
|
40
|
+
"""
|
|
41
|
+
# banner = """
|
|
42
|
+
# ____ ___ ____ ____ __________ ____ ______ __
|
|
43
|
+
# / __ )/ | / __ \/ __ \/_ __/ __ \/ __ \/ __ \ \/ /
|
|
44
|
+
# / __ / /| | / /_/ / / / / / / / /_/ / / / / /_/ /\ /
|
|
45
|
+
# / /_/ / ___ |/ _, _/ /_/ / / / / _, _/ /_/ / ____/ / /
|
|
46
|
+
# /_____/_/ |_/_/ |_|\____/ /_/ /_/ |_|\____/_/ /_/
|
|
47
|
+
|
|
48
|
+
# """
|
|
49
|
+
print(BREAKLINE)
|
|
50
|
+
print(banner)
|
|
51
|
+
print(BREAKLINE)
|
|
52
|
+
# https://manytools.org/hacker-tools/ascii-banner/
|
|
53
|
+
# Style: Sland
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def print_package_info():
|
|
57
|
+
"""Prints package information with predefined values."""
|
|
58
|
+
|
|
59
|
+
info = f""" Version: {__version__}
|
|
60
|
+
Repository: {URL_GITHUB}
|
|
61
|
+
Documentation: {URL_DOCS}"""
|
|
62
|
+
print_banner()
|
|
63
|
+
print(info)
|
|
64
|
+
print(BREAKLINE)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|