Skip to content

Commit b2e9b2a

Browse files
authored
Merge pull request #8 from open-atmos/develop-debug-SIMPOL
Update unique names function to have is_at_surface flag
2 parents c7d5074 + eb8ace3 commit b2e9b2a

File tree

5 files changed

+62
-31
lines changed

5 files changed

+62
-31
lines changed

src/aero_rep_data.F90

+8-5
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ end function get_size
276276
!> Get a list of unique names for each element on the
277277
!! \c camp_camp_state::camp_state_t::state_var array for this aerosol
278278
!! representation.
279-
function unique_names(this, phase_name, tracer_type, spec_name)
279+
function unique_names(this, phase_name, tracer_type, spec_name, &
280+
phase_is_at_surface)
280281
use camp_util, only : string_t, i_kind
281282
import :: aero_rep_data_t
282283

@@ -290,6 +291,8 @@ function unique_names(this, phase_name, tracer_type, spec_name)
290291
integer(kind=i_kind), optional, intent(in) :: tracer_type
291292
!> Aerosol-phase species name
292293
character(len=*), optional, intent(in) :: spec_name
294+
!> Indicates if aerosol phase is at the surface of particle
295+
logical, optional, intent(in) :: phase_is_at_surface
293296

294297
end function unique_names
295298

@@ -342,7 +345,7 @@ end function spec_name
342345
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
343346

344347
!> Get the number of instances of a specified aerosol phase
345-
function num_phase_instances(this, phase_name, num_is_at_surface)
348+
function num_phase_instances(this, phase_name, is_at_surface)
346349
use camp_util, only : i_kind
347350
import :: aero_rep_data_t
348351

@@ -353,7 +356,7 @@ function num_phase_instances(this, phase_name, num_is_at_surface)
353356
!> Aerosol phase name
354357
character(len=*), intent(in) :: phase_name
355358
!> Indicates if aerosol phase is at the surface of particle
356-
logical, intent(in), optional :: num_is_at_surface
359+
logical, intent(in), optional :: is_at_surface
357360

358361
end function num_phase_instances
359362

@@ -511,10 +514,10 @@ function phase_ids(this, phase_name, is_at_surface)
511514
if (present(is_at_surface)) then
512515
if (is_at_surface) then
513516
num_instances = this%num_phase_instances(phase_name, &
514-
num_is_at_surface = .true.)
517+
is_at_surface = .true.)
515518
else
516519
num_instances = this%num_phase_instances(phase_name, &
517-
num_is_at_surface = .false.)
520+
is_at_surface = .false.)
518521
end if
519522
else
520523
num_instances = this%num_phase_instances(phase_name)

src/aero_reps/aero_rep_modal_binned_mass.F90

+24-8
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,8 @@ end function get_size
734734
!!
735735
!! ... and for modes are:
736736
!! - "mode name.phase name.species name"
737-
function unique_names(this, phase_name, tracer_type, spec_name)
737+
function unique_names(this, phase_name, tracer_type, spec_name, &
738+
phase_is_at_surface)
738739

739740
!> List of unique names
740741
type(string_t), allocatable :: unique_names(:)
@@ -746,6 +747,8 @@ function unique_names(this, phase_name, tracer_type, spec_name)
746747
integer(kind=i_kind), optional, intent(in) :: tracer_type
747748
!> Aerosol-phase species name
748749
character(len=*), optional, intent(in) :: spec_name
750+
!> Aerosol-phase species is at surface
751+
logical, optional, intent(in) :: phase_is_at_surface
749752

750753
integer(kind=i_kind) :: num_spec, i_spec, j_spec, i_phase, j_phase, &
751754
i_section, i_bin
@@ -764,6 +767,12 @@ function unique_names(this, phase_name, tracer_type, spec_name)
764767
if (phase_name.ne.curr_phase_name) cycle
765768
end if
766769

770+
! Filter by phase is at surface
771+
if (present(phase_is_at_surface)) then
772+
if (phase_is_at_surface .neqv. &
773+
this%aero_phase_is_at_surface(i_phase)) cycle
774+
end if
775+
767776
! Filter by spec name and/or tracer type
768777
if (present(spec_name).or.present(tracer_type)) then
769778
spec_names = this%aero_phase(i_phase)%val%get_species_names()
@@ -810,6 +819,15 @@ function unique_names(this, phase_name, tracer_type, spec_name)
810819
end if
811820
end if
812821

822+
! Filter by phase is at surface
823+
if (present(phase_is_at_surface)) then
824+
if (phase_is_at_surface .neqv. &
825+
this%aero_phase_is_at_surface(i_phase)) then
826+
i_phase = i_phase + NUM_BINS_(i_section)
827+
cycle
828+
end if
829+
end if
830+
813831
! Get the species names in this phase
814832
spec_names = this%aero_phase(i_phase)%val%get_species_names()
815833

@@ -941,7 +959,7 @@ end function spec_name
941959
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
942960

943961
!> Get the number of instances of a specified aerosol phase.
944-
function num_phase_instances(this, phase_name, num_is_at_surface)
962+
function num_phase_instances(this, phase_name, is_at_surface)
945963

946964
!> Number of instances of the aerosol phase
947965
integer(kind=i_kind) :: num_phase_instances
@@ -950,21 +968,20 @@ function num_phase_instances(this, phase_name, num_is_at_surface)
950968
!> Aerosol phase name
951969
character(len=*), intent(in) :: phase_name
952970
!> Indicates if aerosol phase is at the surface of particle
953-
logical, intent(in), optional :: num_is_at_surface
971+
logical, intent(in), optional :: is_at_surface
954972

955973
integer(kind=i_kind) :: i_phase
956974

957-
if (present(num_is_at_surface)) then
958-
if (num_is_at_surface) then
959-
num_phase_instances = 0
975+
num_phase_instances = 0
976+
if (present(is_at_surface)) then
977+
if (is_at_surface) then
960978
do i_phase = 1, size(this%aero_phase)
961979
if (this%aero_phase(i_phase)%val%name().eq.phase_name .and. &
962980
this%aero_phase_is_at_surface(i_phase)) then
963981
num_phase_instances = num_phase_instances + 1
964982
end if
965983
end do
966984
else
967-
num_phase_instances = 0
968985
do i_phase = 1, size(this%aero_phase)
969986
if (this%aero_phase(i_phase)%val%name().eq.phase_name .and. &
970987
.not. this%aero_phase_is_at_surface(i_phase)) then
@@ -975,7 +992,6 @@ function num_phase_instances(this, phase_name, num_is_at_surface)
975992
end do
976993
end if
977994
else
978-
num_phase_instances = 0
979995
do i_phase = 1, size(this%aero_phase)
980996
if (this%aero_phase(i_phase)%val%name().eq.phase_name) then
981997
num_phase_instances = num_phase_instances + 1

src/aero_reps/aero_rep_single_particle.F90

+20-11
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,8 @@ end function per_particle_size
487487
!! For a single particle representation, the unique names will be a 'P'
488488
!! followed by the computational particle number, a '.', the phase name,
489489
!! another '.', and the species name.
490-
function unique_names(this, phase_name, tracer_type, spec_name)
490+
function unique_names(this, phase_name, tracer_type, spec_name, &
491+
phase_is_at_surface)
491492

492493
use camp_util, only : integer_to_string
493494
!> List of unique names
@@ -500,6 +501,8 @@ function unique_names(this, phase_name, tracer_type, spec_name)
500501
integer(kind=i_kind), optional, intent(in) :: tracer_type
501502
!> Aerosol-phase species name
502503
character(len=*), optional, intent(in) :: spec_name
504+
!> Indicates if aerosol phase is at the surface of particle
505+
logical, optional, intent(in) :: phase_is_at_surface
503506

504507
integer :: i_particle, i_layer, i_phase, i_spec, j_spec
505508
integer :: num_spec, curr_tracer_type
@@ -520,6 +523,10 @@ function unique_names(this, phase_name, tracer_type, spec_name)
520523
if (present(phase_name)) then
521524
if(phase_name .ne. this%aero_phase(i_phase)%val%name()) cycle
522525
end if
526+
if (present(phase_is_at_surface)) then
527+
if (phase_is_at_surface .neqv. &
528+
this%aero_phase_is_at_surface(i_phase)) cycle
529+
end if
523530
if (present(spec_name) .or. present(tracer_type)) then
524531
spec_names = this%aero_phase(i_phase)%val%get_species_names()
525532
do j_spec = 1, size(spec_names)
@@ -549,6 +556,10 @@ function unique_names(this, phase_name, tracer_type, spec_name)
549556
if (present(phase_name)) then
550557
if(phase_name .ne. this%aero_phase(i_phase)%val%name()) cycle
551558
end if
559+
if (present(phase_is_at_surface)) then
560+
if (phase_is_at_surface .neqv. &
561+
this%aero_phase_is_at_surface(i_phase)) cycle
562+
end if
552563
spec_names = this%aero_phase(i_phase)%val%get_species_names()
553564
do j_spec = 1, this%aero_phase(i_phase)%val%size()
554565
if (present(spec_name)) then
@@ -641,27 +652,25 @@ end function spec_name
641652
!! particle representation with layers, a phase can exist in multiple layers
642653
!! in one particle.
643654
integer(kind=i_kind) function num_phase_instances(this, phase_name, &
644-
num_is_at_surface)
655+
is_at_surface)
645656

646657
!> Aerosol representation data
647658
class(aero_rep_single_particle_t), intent(in) :: this
648659
!> Aerosol phase name
649660
character(len=*), intent(in) :: phase_name
650661
!> Indicates if aerosol phase is at the surface of particle
651-
logical, intent(in), optional :: num_is_at_surface
662+
logical, intent(in), optional :: is_at_surface
652663

653664
integer(kind=i_kind) :: i_phase, i_layer, phase_index
654665

655-
656666
num_phase_instances = 0
657-
phase_index = 0
658-
if (present(num_is_at_surface)) then
659-
if (num_is_at_surface) then
667+
if (present(is_at_surface)) then
668+
if (is_at_surface) then
660669
do i_layer = 1, NUM_LAYERS_
661670
do i_phase = LAYER_PHASE_START_(i_layer), LAYER_PHASE_END_(i_layer)
662671
if (this%aero_phase(i_phase)%val%name() .eq. phase_name .and. &
663672
this%aero_phase_is_at_surface(i_phase)) then
664-
phase_index = phase_index + 1
673+
num_phase_instances = num_phase_instances + 1
665674
end if
666675
end do
667676
end do
@@ -670,7 +679,7 @@ integer(kind=i_kind) function num_phase_instances(this, phase_name, &
670679
do i_phase = LAYER_PHASE_START_(i_layer), LAYER_PHASE_END_(i_layer)
671680
if (this%aero_phase(i_phase)%val%name() .eq. phase_name .and. &
672681
.not. this%aero_phase_is_at_surface(i_phase)) then
673-
phase_index = phase_index + 1
682+
num_phase_instances = num_phase_instances + 1
674683
end if
675684
end do
676685
end do
@@ -679,12 +688,12 @@ integer(kind=i_kind) function num_phase_instances(this, phase_name, &
679688
do i_layer = 1, NUM_LAYERS_
680689
do i_phase = LAYER_PHASE_START_(i_layer), LAYER_PHASE_END_(i_layer)
681690
if (this%aero_phase(i_phase)%val%name() .eq. phase_name) then
682-
phase_index = phase_index + 1
691+
num_phase_instances = num_phase_instances + 1
683692
end if
684693
end do
685694
end do
686695
end if
687-
num_phase_instances = phase_index * MAX_PARTICLES_
696+
num_phase_instances = num_phase_instances * MAX_PARTICLES_
688697

689698
end function num_phase_instances
690699

src/rxns/rxn_SIMPOL_phase_transfer.F90

+6-3
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ subroutine initialize(this, chem_spec_data, aero_rep, n_cells)
246246
! Get the unique names in this aerosol representation for the
247247
! partitioning species
248248
unique_spec_names = aero_rep(i_aero_rep)%val%unique_names( &
249-
phase_name = phase_name, spec_name = aero_spec_name)
249+
phase_name = phase_name, spec_name = aero_spec_name, &
250+
phase_is_at_surface = .true.)
250251

251252
! Skip aerosol representations that do not contain this phase
252253
if (.not.allocated(unique_spec_names)) cycle
@@ -308,12 +309,14 @@ subroutine initialize(this, chem_spec_data, aero_rep, n_cells)
308309
! Get the unique names in this aerosol representation for the
309310
! partitioning species
310311
unique_spec_names = aero_rep(i_aero_rep)%val%unique_names( &
311-
phase_name = phase_name, spec_name = aero_spec_name)
312+
phase_name = phase_name, spec_name = aero_spec_name, &
313+
phase_is_at_surface = .true.)
312314

313315
! Find the corresponding activity coefficients, if specified
314316
if (has_act_coeff) then
315317
unique_act_names = aero_rep(i_aero_rep)%val%unique_names( &
316-
phase_name = phase_name, spec_name = act_name)
318+
phase_name = phase_name, spec_name = act_name, &
319+
phase_is_at_surface = .true.)
317320
call assert_msg(236251734, size(unique_act_names).eq. &
318321
size(unique_spec_names), &
319322
"Mismatch of SIMPOL species and activity coeffs"// &

test/unit_aero_rep_data/test_aero_rep_single_particle.F90

+4-4
Original file line numberDiff line numberDiff line change
@@ -215,19 +215,19 @@ subroutine test_config_read()
215215
max_part = aero_rep%maximum_computational_particles()
216216
jam_phase_instance = 0
217217
!check value
218-
print *, "jam_instances ", aero_rep%num_phase_instances(phase_name_test, num_is_at_surface = .false.)
218+
print *, "jam_instances ", aero_rep%num_phase_instances(phase_name_test, is_at_surface = .false.)
219219
call assert(417730478, 3 .eq. max_part)
220220
call assert(493602373, jam_phase_instance .eq. aero_rep%num_phase_instances(phase_name_test, &
221-
num_is_at_surface = .true.))
221+
is_at_surface = .true.))
222222

223223
phase_name_test = "bread"
224224
num_bread = 1
225225
bread_phase_instance = num_bread * max_part
226226
!check value
227227
print *, bread_phase_instance
228-
print *, "bread_instqnces ", aero_rep%num_phase_instances(phase_name_test, num_is_at_surface = .true.)
228+
print *, "bread_instqnces ", aero_rep%num_phase_instances(phase_name_test, is_at_surface = .true.)
229229
call assert(734138496, bread_phase_instance .eq. aero_rep%num_phase_instances(phase_name_test, &
230-
num_is_at_surface = .true.))
230+
is_at_surface = .true.))
231231

232232
class default
233233
call die_msg(519535557, rep_name)

0 commit comments

Comments
 (0)