Skip to content

Commit

Permalink
ENH: Update fortran modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanSkocic committed Jun 25, 2024
1 parent cf5be6a commit 53c3873
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 216 deletions.
17 changes: 3 additions & 14 deletions include/ecx.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,29 @@
extern char* ecx_get_version(void);


/* ---------------------------------------------------------------------------------------------- */
ADD_IMPORT extern const double ecx_core_PI;
ADD_IMPORT extern const double ecx_core_T_K;
void ecx_core_nm2eV(double *lambda, double *E, size_t n);
void ecx_core_kTe(double *U, double *kTE, size_t n);
/* ---------------------------------------------------------------------------------------------- */


/* ---------------------------------------------------------------------------------------------- */
extern double ecx_kinetics_capi_nernst(double E0, int z,
extern double ecx_kinetics_nernst(double E0, int z,
double *aox, double *vox, size_t nox,
double *ared, double *vred, size_t nred,
double T);

extern void ecx_kinetics_capi_sbv(double *U, double OCV, double j0,
extern void ecx_kinetics_sbv(double *U, double OCV, double j0,
double aa, double ac, double za, double zc,
double A, double T, double *i, size_t n);

extern void ecx_kinetics_capi_bv(double *U, double OCV, double j0, double jdla, double jdlc,
extern void ecx_kinetics_bv(double *U, double OCV, double j0, double jdla, double jdlc,
double aa, double ac, double za, double zc,
double A, double T, double *i, size_t n);
/* ---------------------------------------------------------------------------------------------- */


/* ---------------------------------------------------------------------------------------------- */
extern void ecx_capi_zr(double *w, double R, size_t n, ecx_cdouble *Z);
extern void ecx_capi_zc(double *w, double C, size_t n, ecx_cdouble *Z);
extern void ecx_capi_zl(double *w, double L, size_t n, ecx_cdouble *Z);
extern void ecx_capi_zcpe(double *w, double Q, double a, size_t n, ecx_cdouble *Z);
extern void ecx_capi_zw(double *w, double s, size_t n, ecx_cdouble *Z);
extern void ecx_eis_z(double *p, double *w, ecx_cdouble *z,
char e, size_t k, size_t n,
int *errstat, char *(*errmsg));
/* ---------------------------------------------------------------------------------------------- */

#endif

Expand Down
54 changes: 0 additions & 54 deletions py/src/pyecx/ecx.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/capi.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module capi
use capi__version
use capi__eis
use capi__kinetics

use capi__core
end module
35 changes: 35 additions & 0 deletions src/capi_core.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module capi__core
use iso_c_binding, only: c_double, c_size_t
use ecx__core, only: nm2eV, kTe
implicit none

contains

pure subroutine capi_nm2eV(lambda, E, n)bind(C, name="ecx_core_nm2eV")
!! Convert wavelength to energy

integer(c_size_t), intent(in), value :: n
!! Size of lambda and E.
real(c_double), intent(in) :: lambda(n)
!! Wavelength in nm.
real(c_double), intent(out) :: E(n)
!! Energy in eV.
E = nm2eV(lambda)

end subroutine

pure subroutine capi_kTe(T, kTe_, n)bind(C, name="ecx_core_kTe")
!! Compute the thermal voltage.

integer(c_size_t), intent(in), value :: n
!! Size of T and kTe.
real(c_double), intent(in) :: T(n)
!! Temperature in °C.
real(c_double), intent(out) :: kTe_(n)
!! Thermal voltage in V.

kTe_ = kTe(T)

end subroutine

end module
15 changes: 14 additions & 1 deletion src/capi_eis.f90
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
module capi__eis
!! EIS: CAPI.
use iso_c_binding, only: c_size_t, &
c_int, &
c_double, &
c_double_complex, &
c_char, &
c_ptr, &
c_null_char, &
c_loc
use ecx__eis
implicit none

character(len=:), allocatable, target :: errmsg_c

contains

subroutine capi_z(p, w, zout, e, k, n, errstat, errmsg)bind(C, name="ecx_eis_z")
!! Compute the complex impedance for the given element.
implicit none

integer(c_size_t), intent(in), value :: n
!! Size of w
integer(c_size_t), intent(in), value :: k
Expand Down
18 changes: 9 additions & 9 deletions src/capi_kinetics.f90
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module capi__kinetics
!! Kinetics: C API.
use stdlib_kinds, only, dp, int32
use stdlib_kinds, only: dp, int32
use iso_c_binding
use ecx__kinetics
use ecx__kinetics, only: bv, sbv, nernst
implicit none
private

contains

pure function capi_nernst(E0, z, aox, vox, nox, ared, vred, nred, T)result(E)bind(C)
pure function capi_nernst(E0, z, aox, vox, nox, ared, vred, nred, T)result(E)bind(C, name="ecx_kinetics_nernst")
!! Compute the Nernst electrochemical potential in V.
implicit none
real(c_double), intent(in), value :: E0
Expand All @@ -30,11 +30,11 @@ pure function capi_nernst(E0, z, aox, vox, nox, ared, vred, nred, T)result(E)bin
real(c_double), intent(in), value :: T
!! Temperature in °C.
real(c_double) :: E
E = ecx_kinetics_nernst(E0, z, aox, vox, ared, vred, T)
E = nernst(E0, z, aox, vox, ared, vred, T)

end function

pure subroutine capi_sbv(U, OCV, j0, aa, ac, za, zc, A, T, I, n)bind(c)
pure subroutine capi_sbv(U, OCV, j0, aa, ac, za, zc, A, T, I, n)bind(c, name="ecx_kinetics_sbv")
!! Compute Butler Volmer equation without mass transport.
! arguments
integer(c_size_t), intent(in), value :: n
Expand All @@ -60,11 +60,11 @@ pure subroutine capi_sbv(U, OCV, j0, aa, ac, za, zc, A, T, I, n)bind(c)
real(c_double), intent(out) :: I(n)
!! Current in A.

I = ecx_kinetics_sbv(U, OCV, j0, aa, ac, za, zc, A, T)
I = sbv(U, OCV, j0, aa, ac, za, zc, A, T)

end subroutine

pure subroutine capi_bv(U, OCV, j0, jdla, jdlc, aa, ac, za, zc, A, T, I, n)bind(c)
pure subroutine capi_bv(U, OCV, j0, jdla, jdlc, aa, ac, za, zc, A, T, I, n)bind(c, name="ecx_kinetics_bv")
!! Compute Butler Volmer equation without mass transport.
! arguments
integer(c_size_t), intent(in), value :: n
Expand All @@ -75,9 +75,9 @@ pure subroutine capi_bv(U, OCV, j0, jdla, jdlc, aa, ac, za, zc, A, T, I, n)bind(
!! Potential in volts.
real(c_double), intent(in), value :: j0
!! Exchange current density in A.cm-2
real(4), intent(in), value :: jdla
real(c_double), intent(in), value :: jdla
!! Anodic diffusion limiting current density in A.cm-2.
real(4), intent(in), value :: jdlc
real(c_double), intent(in), value :: jdlc
!! Cathodic diffusion limiting current density in A.cm-2.
real(c_double), intent(in), value :: aa
!! Anodic transfert coefficient.
Expand Down
32 changes: 4 additions & 28 deletions src/ecx_core.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module ecx__core
implicit none
private

real(dp), parameter :: PI = 4.0d0*datan(1.0d0) !! PI
real(dp), parameter :: T_K=273.15d0 !! 0°C in Kelvin.
real(dp), parameter :: PI = 4.0_dp*datan(1.0_dp) !! PI
real(dp), parameter :: T_K=273.15_dp !! 0°C in Kelvin.
real(dp), parameter :: kB_eV = BOLTZMANN_CONSTANT_IN_EV_K%value
real(dp), parameter :: h_eV = PLANCK_CONSTANT_IN_EV_HZ%value
real(dp), parameter :: c = SPEED_OF_LIGHT_IN_VACUUM%value
Expand Down Expand Up @@ -113,18 +113,6 @@ pure elemental function nm2eV(lambda)result(E)
E = h_eV * c / (lambda*1.0d-9)
end function

pure subroutine capi_nm2eV(lambda, E, n)bind(C, name="ecx_core_nm2eV")
!! Convert wavelength to energy
implicit none
integer(c_size_t), intent(in), value :: n
!! Size of lambda and E.
real(c_double), intent(in) :: lambda(n)
!! Wavelength in nm.
real(c_double), intent(out) :: E(n)
!! Energy in eV.
E = nm2eV(lambda)

end subroutine

pure elemental function eV2nm(E)result(lambda)
!! Convert wavelength to energy
Expand All @@ -144,7 +132,7 @@ pure elemental function deg2rad(theta)result(phase)
!! Angle in degrees.
real(dp) :: phase
!! Angle in rad.
phase = theta * PI / 180.0d0
phase = theta * PI / 180.0_dp
end

pure elemental function rad2deg(phase)result(theta)
Expand All @@ -154,7 +142,7 @@ pure elemental function rad2deg(phase)result(theta)
!! Angle in rad.
real(dp) :: theta
!! Angle in degrees.
theta = phase * 180.0d0 / PI
theta = phase * 180.0_dp / PI
end

pure elemental function kTe(T)result(r)
Expand All @@ -168,17 +156,5 @@ pure elemental function kTe(T)result(r)
r = (T+T_K) * kB_eV
end function

pure subroutine capi_kTe(T, kTe_, n)bind(C, name="ecx_core_kTe")
!! Compute the thermal voltage.
integer(c_size_t), intent(in), value :: n
!! Size of T and kTe.
real(c_double), intent(in) :: T(n)
!! Temperature in °C.
real(c_double), intent(out) :: kTe_(n)
!! Thermal voltage in V.

kTe_ = kTe(T)

end subroutine

end module
Loading

0 comments on commit 53c3873

Please sign in to comment.