10000 Adjacent phase by jtgasparik · Pull Request #32 · open-atmos/camp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adjacent phase #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 94 additions & 1 deletion src/aero_reps/aero_rep_single_particle.F90
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module camp_aero_rep_single_particle

public :: aero_rep_single_particle_t, &
aero_rep_update_data_single_particle_number_t, &
ordered_layer_ids
ordered_layer_ids, index_pair_t

!> Single particle aerosol representation
!!
Expand Down Expand Up @@ -142,10 +142,17 @@ module camp_aero_rep_single_particle
procedure :: num_phases
!> Returns the number of state variables for a layer and phase
procedure :: phase_state_size
!> Returns index_pair_t type with phase_ids of adjacent phases
procedure :: adjacent_phases
!> Finalize the aerosol representation
final :: finalize, finalize_array
end type aero_rep_single_particle_t

type :: index_pair_t
integer :: first_ = -9999
integer :: second_ = -9999
end type index_pair_t

! Constructor for aero_rep_single_particle_t
interface aero_rep_single_particle_t
procedure :: constructor
Expand Down Expand Up @@ -784,6 +791,92 @@ integer function phase_state_size(this, layer, phase)

end function phase_state_size

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!> Determine is specified phase(s) exist in adjacent layers. Returns array
!! of phase_ids for adjacent phases first and second.

function adjacent_phases(this, phase_name_first, &
phase_name_second) result(index_pairs)

!> Aerosol representation data
class(aero_rep_single_particle_t), intent(in) :: this
character(len=*), intent(in) :: phase_name_first
character(len=*), intent(in) :: phase_name_second
type(index_pair_t), allocatable :: temp_index_pairs(:), index_pairs(:)

integer(kind=i_kind), allocatable :: layer_first(:)
integer(kind=i_kind), allocatable :: layer_second(:)
integer(kind=i_kind), allocatable :: phase_id_first_(:)
integer(kind=i_kind), allocatable :: phase_id_second_(:)
integer(kind=i_kind) :: i_layer, i_phase, i_instance, j_phase

allocate(layer_first(NUM_LAYERS_))
allocate(layer_second(NUM_LAYERS_))
allocate(phase_id_first_(NUM_LAYERS_))
allocate(phase_id_second_(NUM_LAYERS_))
layer_first = -9999
layer_second = -9999
phase_id_first_ = -9999
phase_id_second_ = -9999

! Loop over layers and phases to determine where each input phase exists
i_instance = 1
do i_layer = 1, NUM_LAYERS_
do i_phase = 1, NUM_PHASES_(i_layer)
if (phase_name_first .eq. phase_name_second) then
if (this%aero_phase(i_instance)%val%name() .eq. phase_name_first) then
layer_first(i_layer) = PHASE_MODEL_DATA_ID_(i_layer, i_phase)
phase_id_first_(i_layer) = i_instance
end if
else
if (this%aero_phase(i_instance)%val%name() .eq. phase_name_first) then
layer_first(i_layer) = PHASE_MODEL_DATA_ID_(i_layer, i_phase)
phase_id_first_(i_layer) = i_instance
else if (this%aero_phase(i_instance)%val%name() .eq. phase_name_second) then
layer_second(i_layer) = PHASE_MODEL_DATA_ID_(i_layer, i_phase)
phase_id_second_(i_layer) = i_instance
end if
end if
i_instance = i_instance + 1
end do
end do

! Find out where the pairs exist and assign to temp_index_pairs
allocate(temp_index_pairs(i_instance))
i_instance = 1
do i_layer = 1, NUM_LAYERS_-1
do i_phase = 1, NUM_PHASES_(i_layer)
do j_phase = 1, NUM_PHASES_(i_layer+1)
if (phase_name_first .eq. phase_name_second) then
if (layer_first(i_layer) .eq. PHASE_MODEL_DATA_ID_(i_layer,i_phase) .and. &
layer_first(i_layer+1) .eq. PHASE_MODEL_DATA_ID_(i_layer+1,j_phase)) then
temp_index_pairs(i_instance)%first_ = phase_id_first_(i_layer)
temp_index_pairs(i_instance)%second_ = phase_id_first_(i_layer+1)
i_instance = i_instance + 1
end if
else
if (layer_first(i_layer) .eq. PHASE_MODEL_DATA_ID_(i_layer, i_phase) .and. &
layer_second(i_layer+1) .eq. PHASE_MODEL_DATA_ID_(i_layer+1, j_phase)) then
temp_index_pairs(i_instance)%first_ = phase_id_first_(i_layer)
temp_index_pairs(i_instance)%second_ = phase_id_second_(i_layer+1)
i_instance = i_instance + 1
else if (layer_second(i_layer) .eq. PHASE_MODEL_DATA_ID_(i_layer, i_phase) .and. &
layer_first(i_layer+1) .eq. PHASE_MODEL_DATA_ID_(i_layer+1, j_phase)) then
temp_index_pairs(i_instance)%first_ = phase_id_second_(i_layer)
temp_index_pairs(i_instance)%second_ = phase_id_first_(i_layer+1)
i_instance = i_instance + 1
end if
end if
end do
end do
end do

allocate(index_pairs(i_instance-1))
index_pairs(:)%first_ = temp_index_pairs(1:i_instance-1)%first_
index_pairs(:)%second_ = temp_index_pairs(1:i_instance-1)%second_

end function adjacent_phases
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

!> Finalize the aerosol representation
Expand Down
Loading
0