Skip to content

Commit

Permalink
Merge pull request #126 from n-claes/refactor/background
Browse files Browse the repository at this point in the history
Refactor background equilibrium into dedicated functions
  • Loading branch information
n-claes authored Mar 29, 2023
2 parents b6c38ef + 14259c0 commit 8cff13b
Show file tree
Hide file tree
Showing 78 changed files with 3,322 additions and 3,568 deletions.
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ set (sources
settings/mod_units.f08
mod_physical_constants.f08
utils/mod_get_indices.f08
utils/mod_function_utils.f08
background/mod_background.f08
background/fields/mod_bg_density.f08
background/fields/mod_bg_temperature.f08
background/fields/mod_bg_velocity.f08
background/fields/mod_bg_magnetic.f08
matrices/datastructure/mod_matrix_node.f08
matrices/datastructure/mod_matrix_row.f08
matrices/datastructure/mod_matrix_structure.f08
Expand Down
32 changes: 32 additions & 0 deletions src/background/fields/mod_bg_density.f08
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module mod_bg_density
use mod_global_variables, only: dp
implicit none

private

type, public :: bg_density_t
procedure(real(dp)), pointer, nopass :: rho0
procedure(real(dp)), pointer, nopass :: drho0
contains
procedure :: delete
end type bg_density_t

public :: new_bg_density

contains

function new_bg_density(default_func) result(bg_density)
procedure(real(dp)) :: default_func
type(bg_density_t) :: bg_density
bg_density%rho0 => default_func
bg_density%drho0 => default_func
end function new_bg_density


pure subroutine delete(this)
class(bg_density_t), intent(inout) :: this
nullify(this%rho0)
nullify(this%drho0)
end subroutine delete

end module mod_bg_density
63 changes: 63 additions & 0 deletions src/background/fields/mod_bg_magnetic.f08
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module mod_bg_magnetic
use mod_global_variables, only: dp
implicit none

private

type, public :: bg_magnetic_t
procedure(real(dp)), pointer, nopass :: B01
procedure(real(dp)), pointer, nopass :: B02
procedure(real(dp)), pointer, nopass :: dB02
procedure(real(dp)), pointer, nopass :: ddB02
procedure(real(dp)), pointer, nopass :: B03
procedure(real(dp)), pointer, nopass :: dB03
procedure(real(dp)), pointer, nopass :: ddB03
contains
procedure, public :: get_B0
procedure, public :: get_dB0
procedure, public :: delete
end type bg_magnetic_t

public :: new_bg_magnetic

contains

function new_bg_magnetic(default_func) result(bg_magnetic)
procedure(real(dp)) :: default_func
type(bg_magnetic_t) :: bg_magnetic
bg_magnetic%B01 => default_func
bg_magnetic%B02 => default_func
bg_magnetic%dB02 => default_func
bg_magnetic%ddB02 => default_func
bg_magnetic%B03 => default_func
bg_magnetic%dB03 => default_func
bg_magnetic%ddB03 => default_func
end function new_bg_magnetic


impure elemental real(dp) function get_B0(this, x)
class(bg_magnetic_t), intent(in) :: this
real(dp), intent(in) :: x
get_B0 = sqrt(this%B01(x)**2 + this%B02(x)**2 + this%B03(x)**2)
end function get_B0


impure elemental real(dp) function get_dB0(this, x)
class(bg_magnetic_t), intent(in) :: this
real(dp), intent(in) :: x
get_dB0 = (this%B02(x) * this%dB02(x) + this%B03(x) * this%dB03(x)) / this%get_B0(x)
end function get_dB0


pure subroutine delete(this)
class(bg_magnetic_t), intent(inout) :: this
nullify(this%B01)
nullify(this%B02)
nullify(this%dB02)
nullify(this%ddB02)
nullify(this%B03)
nullify(this%dB03)
nullify(this%ddB03)
end subroutine delete

end module mod_bg_magnetic
35 changes: 35 additions & 0 deletions src/background/fields/mod_bg_temperature.f08
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module mod_bg_temperature
use mod_global_variables, only: dp
implicit none

private

type, public :: bg_temperature_t
procedure(real(dp)), pointer, nopass :: T0
procedure(real(dp)), pointer, nopass :: dT0
procedure(real(dp)), pointer, nopass :: ddT0
contains
procedure :: delete
end type bg_temperature_t

public :: new_bg_temperature

contains

function new_bg_temperature(default_func) result(bg_temperature)
procedure(real(dp)) :: default_func
type(bg_temperature_t) :: bg_temperature
bg_temperature%T0 => default_func
bg_temperature%dT0 => default_func
bg_temperature%ddT0 => default_func
end function new_bg_temperature


pure subroutine delete(this)
class(bg_temperature_t), intent(inout) :: this
nullify(this%T0)
nullify(this%dT0)
nullify(this%ddT0)
end subroutine delete

end module mod_bg_temperature
61 changes: 61 additions & 0 deletions src/background/fields/mod_bg_velocity.f08
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module mod_bg_velocity
use mod_global_variables, only: dp
implicit none

private

type, public :: bg_velocity_t
procedure(real(dp)), pointer, nopass :: v01
procedure(real(dp)), pointer, nopass :: dv01
procedure(real(dp)), pointer, nopass :: ddv01
procedure(real(dp)), pointer, nopass :: v02
procedure(real(dp)), pointer, nopass :: dv02
procedure(real(dp)), pointer, nopass :: ddv02
procedure(real(dp)), pointer, nopass :: v03
procedure(real(dp)), pointer, nopass :: dv03
procedure(real(dp)), pointer, nopass :: ddv03
contains
procedure, public :: get_v0
procedure, public :: delete
end type bg_velocity_t

public :: new_bg_velocity

contains

function new_bg_velocity(default_func) result(bg_velocity)
procedure(real(dp)) :: default_func
type(bg_velocity_t) :: bg_velocity
bg_velocity%v01 => default_func
bg_velocity%dv01 => default_func
bg_velocity%ddv01 => default_func
bg_velocity%v02 => default_func
bg_velocity%dv02 => default_func
bg_velocity%ddv02 => default_func
bg_velocity%v03 => default_func
bg_velocity%dv03 => default_func
bg_velocity%ddv03 => default_func
end function new_bg_velocity


real(dp) function get_v0(this, x)
class(bg_velocity_t), intent(in) :: this
real(dp), intent(in) :: x
get_v0 = sqrt(this%v01(x)**2 + this%v02(x)**2 + this%v03(x)**2)
end function get_v0


pure subroutine delete(this)
class(bg_velocity_t), intent(inout) :: this
nullify(this%v01)
nullify(this%dv01)
nullify(this%ddv01)
nullify(this%v02)
nullify(this%dv02)
nullify(this%ddv02)
nullify(this%v03)
nullify(this%dv03)
nullify(this%ddv03)
end subroutine delete

end module mod_bg_velocity
142 changes: 142 additions & 0 deletions src/background/mod_background.f08
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
module mod_background
use mod_global_variables, only: dp
use mod_function_utils, only: zero_func
use mod_bg_density, only: bg_density_t, new_bg_density
use mod_bg_velocity, only: bg_velocity_t, new_bg_velocity
use mod_bg_temperature, only: bg_temperature_t, new_bg_temperature
use mod_bg_magnetic, only: bg_magnetic_t, new_bg_magnetic
implicit none

private

type, public :: background_t
type(bg_density_t) :: density
type(bg_velocity_t) :: velocity
type(bg_temperature_t) :: temperature
type(bg_magnetic_t) :: magnetic

contains

procedure :: set_density_funcs
procedure :: set_velocity_1_funcs
procedure :: set_velocity_2_funcs
procedure :: set_velocity_3_funcs
procedure :: set_temperature_funcs
procedure :: set_magnetic_1_funcs
procedure :: set_magnetic_2_funcs
procedure :: set_magnetic_3_funcs
procedure :: delete
end type background_t

public :: new_background

contains

function new_background() result(background)
type(background_t) :: background

background%density = new_bg_density(default_func=zero_func)
background%velocity = new_bg_velocity(default_func=zero_func)
background%temperature = new_bg_temperature(default_func=zero_func)
background%magnetic = new_bg_magnetic(default_func=zero_func)
end function new_background

subroutine set_density_funcs(this, rho0_func, drho0_func)
class(background_t), intent(inout) :: this
procedure(real(dp)) :: rho0_func
procedure(real(dp)), optional :: drho0_func

this%density%rho0 => rho0_func
if (present(drho0_func)) this%density%drho0 => drho0_func
end subroutine set_density_funcs


subroutine set_velocity_1_funcs(this, v01_func, dv01_func, ddv01_func)
class(background_t), intent(inout) :: this
procedure(real(dp)) :: v01_func
procedure(real(dp)), optional :: dv01_func
procedure(real(dp)), optional :: ddv01_func

this%velocity%v01 => v01_func
if (present(dv01_func)) this%velocity%dv01 => dv01_func
if (present(ddv01_func)) this%velocity%ddv01 => ddv01_func
end subroutine set_velocity_1_funcs


subroutine set_velocity_2_funcs(this, v02_func, dv02_func, ddv02_func)
class(background_t), intent(inout) :: this
procedure(real(dp)) :: v02_func
procedure(real(dp)), optional :: dv02_func
procedure(real(dp)), optional :: ddv02_func

this%velocity%v02 => v02_func
if (present(dv02_func)) this%velocity%dv02 => dv02_func
if (present(ddv02_func)) this%velocity%ddv02 => ddv02_func
end subroutine set_velocity_2_funcs


subroutine set_velocity_3_funcs(this, v03_func, dv03_func, ddv03_func)
class(background_t), intent(inout) :: this
procedure(real(dp)) :: v03_func
procedure(real(dp)), optional :: dv03_func
procedure(real(dp)), optional :: ddv03_func

this%velocity%v03 => v03_func
if (present(dv03_func)) this%velocity%dv03 => dv03_func
if (present(ddv03_func)) this%velocity%ddv03 => ddv03_func
end subroutine set_velocity_3_funcs


subroutine set_temperature_funcs(this, T0_func, dT0_func, ddT0_func)
class(background_t), intent(inout) :: this
procedure(real(dp)) :: T0_func
procedure(real(dp)), optional :: dT0_func
procedure(real(dp)), optional :: ddT0_func

this%temperature%T0 => T0_func
if (present(dT0_func)) this%temperature%dT0 => dT0_func
if (present(ddT0_func)) this%temperature%ddT0 => ddT0_func
end subroutine set_temperature_funcs


subroutine set_magnetic_1_funcs(this, B01_func)
class(background_t), intent(inout) :: this
procedure(real(dp)) :: B01_func

this%magnetic%B01 => B01_func
end subroutine set_magnetic_1_funcs


subroutine set_magnetic_2_funcs(this, B02_func, dB02_func, ddB02_func)
class(background_t), intent(inout) :: this
procedure(real(dp)) :: B02_func
procedure(real(dp)), optional :: dB02_func
procedure(real(dp)), optional :: ddB02_func

this%magnetic%B02 => B02_func
if (present(dB02_func)) this%magnetic%dB02 => dB02_func
if (present(ddB02_func)) this%magnetic%ddB02 => ddB02_func
end subroutine set_magnetic_2_funcs


subroutine set_magnetic_3_funcs(this, B03_func, dB03_func, ddB03_func)
class(background_t), intent(inout) :: this
procedure(real(dp)) :: B03_func
procedure(real(dp)), optional :: dB03_func
procedure(real(dp)), optional :: ddB03_func

this%magnetic%B03 => B03_func
if (present(dB03_func)) this%magnetic%dB03 => dB03_func
if (present(ddB03_func)) this%magnetic%ddB03 => ddB03_func
end subroutine set_magnetic_3_funcs


pure subroutine delete(this)
class(background_t), intent(inout) :: this
call this%density%delete()
call this%temperature%delete()
call this%magnetic%delete()
call this%velocity%delete()
end subroutine delete

end module mod_background
Loading

0 comments on commit 8cff13b

Please sign in to comment.