Skip to content

Commit

Permalink
P to dynes/cm2. Python install
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed May 30, 2024
1 parent 6346e45 commit 74335f9
Show file tree
Hide file tree
Showing 10 changed files with 795 additions and 8 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ jobs:
compiler: gcc
version: 11

- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: 3.9

- name: Install dependencies
run: |
sudo apt-get install valgrind
Expand All @@ -32,4 +37,11 @@ jobs:
- name: test
working-directory: ${{github.workspace}}/build
run: |
valgrind --error-exitcode=1 --leak-check=full ./test/test_equilibrate
valgrind --error-exitcode=1 --leak-check=full ./test/test_equilibrate
- name: build python
run: python -m pip install . -v

- name: test python
working-directory: ${{github.workspace}}/test
run: python test_equilibrate.py
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION "3.14")

project(EQUILIBRATE LANGUAGES Fortran C VERSION "0.1.0")
project(EQUILIBRATE LANGUAGES Fortran C VERSION "0.1.1")

set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/modules")
include(cmake/CPM.cmake)
Expand Down
675 changes: 675 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Equilibrate

`Equilibrate` is a chemical equilibrium solver which is based on [EasyChem](https://gitlab.com/EliseLei/easychem), which itself is a clone of the NASA CEA tool (described in [Gordon and McBride 1994](https://ntrs.nasa.gov/api/citations/19950013764/downloads/19950013764.pdf)).





2 changes: 1 addition & 1 deletion equilibrate/cython/_equilibrate.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ cdef class ChemEquiAnalysis:
Parameters
----------
P : double
Pressure in bars
Pressure in dynes/cm^2
T : double
Temperature in Kelvin
molfracs_atoms : ndarray[double,ndim=1], optional
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build-system]
requires = ["setuptools>=42", "wheel", "scikit-build", "cmake>=3.12", "ninja", "numpy", "cython"]
33 changes: 33 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from skbuild import setup
from os import path

this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()

with open("CMakeLists.txt",'r') as fil:
lines = fil.readlines()
for line in lines:
if line.startswith("project(EQUILIBRATE"):
version = line.split('"')[1]
break

setup(
name="equilibrate",
packages=['equilibrate'],
python_requires='>=3.6',
version=version,
license="GNU General Public License v3.0",
install_requires=['numpy'],
author='Nicholas Wogan',
author_email = '[email protected]',
description = "A chemical equilibrium solver.",
long_description=long_description,
long_description_content_type='text/markdown',
url = "https://github.com/Nicholaswogan/Equilibrate",
cmake_args=['-DCMAKE_BUILD_TYPE=Release',\
'-DBUILD_PYTHON_EQUILIBRATE=ON',\
'-DBUILD_EXECUTABLES=OFF']
)


6 changes: 4 additions & 2 deletions src/equilibrate.f90
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function create_ChemEquiAnalysis(thermopath, atoms, species, err) result(cea)
!> `err` is allocated with an error message.
function solve(self, P, T, molfracs_atoms, molfracs_species, err) result(converged)
class(ChemEquiAnalysis), intent(inout) :: self
real(dp), intent(in) :: P !! Pressure in bars
real(dp), intent(in) :: P !! Pressure in dynes/cm^2
real(dp), intent(in) :: T !! Temperature in Kelvin
!> Atom mole fractions in the same order and length as self%atoms_names.
real(dp), optional, intent(in) :: molfracs_atoms(:)
Expand All @@ -173,9 +173,11 @@ function solve(self, P, T, molfracs_atoms, molfracs_species, err) result(converg
logical :: converged

real(dp), allocatable :: molfracs_atoms_(:)
real(dp) :: P_bars
integer :: i, j, jj

converged = .false.
P_bars = P/1.0e6_dp

if (present(molfracs_atoms) .and. present(molfracs_species)) then
err = 'Both "molfracs_atoms" and "molfracs_species" are inputs, but only one is allowed.'
Expand Down Expand Up @@ -224,7 +226,7 @@ function solve(self, P, T, molfracs_atoms, molfracs_species, err) result(converg
mass_tol=self%mass_tol, &
molfracs_reactants=self%molfracs_species, &
massfracs_reactants=self%massfracs_species, &
temp=T, press=P, &
temp=T, press=P_bars, &
nabla_ad=self%nabla_ad, gamma2=self%gamma2, MMW=self%MMW, rho=self%rho, c_pe=self%c_pe)
if (self%dat%error) then
err = trim(self%dat%err_msg)
Expand Down
6 changes: 3 additions & 3 deletions test/test_equilibrate.f90
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ subroutine test()
stop 1
endif

converged = cea%solve(1.0_dp, 1000.0_dp, molfracs_atoms=X, err=err)
converged = cea%solve(1.0e6_dp, 1000.0_dp, molfracs_atoms=X, err=err)
if (allocated(err)) then
print*,err
stop 1
endif
if (.not.converged) stop 1

converged = cea2%solve(1.0_dp, 1000.0_dp, molfracs_atoms=X, err=err)
converged = cea2%solve(1.0e6_dp, 1000.0_dp, molfracs_atoms=X, err=err)
if (allocated(err)) then
print*,err
stop 1
Expand All @@ -294,7 +294,7 @@ subroutine test()
endif
enddo

converged = cea%solve(1.0_dp, 1000.0_dp, molfracs_species=cea%molfracs_species, err=err)
converged = cea%solve(1.0e6_dp, 1000.0_dp, molfracs_species=cea%molfracs_species, err=err)
if (allocated(err)) then
print*,err
stop 1
Expand Down
55 changes: 55 additions & 0 deletions test/test_equilibrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import numpy as np
from equilibrate import ChemEquiAnalysis

def main():
atoms = [
'H ',
'He',
'C ',
'N ',
'O ',
'Na',
'Mg',
'Al',
'Si',
'P ',
'S ',
'Cl',
'K ',
'Ca',
'Ti',
'V ',
'Fe',
'Ni'
]
X = np.array([
9.207539305000000e-01,
7.836886940000000e-02,
2.478241000000000e-04,
6.225060569498810e-05,
4.509658000000000e-04,
1.600086943532050e-06,
3.665587420553620e-05,
2.595000000000000e-06,
2.979500000000000e-05,
2.366702019976680e-07,
1.213790073460400e-05,
2.911679584995890e-07,
9.866056119256769e-08,
2.014390114292550e-06,
8.206228043663590e-08,
7.836886940899920e-09,
2.911679584995890e-05,
1.528071168062810e-06
])

#
cea = ChemEquiAnalysis('thermo_easy_chem_simp_own.yaml', atoms=atoms)
converged = cea.solve(1.0e6, 1000.0, molfracs_atoms=X)

# Check the solution
ind = cea.species_names.index('H2')
assert np.isclose(cea.molfracs_species[ind],8.531731613887943e-01,rtol=1e-4)

if __name__ == '__main__':
main()

0 comments on commit 74335f9

Please sign in to comment.