Skip to content

Commit

Permalink
introduced rate scale factor (rdt_) instead of divisor (dt) because m…
Browse files Browse the repository at this point in the history
…ultiplication is faster than division
  • Loading branch information
jornbr committed Mar 12, 2020
1 parent 6d1befd commit ee2c908
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 8 additions & 8 deletions include/fabm.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,17 @@
#define _ADD_HORIZONTAL_(variable,value) cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%horizontal_sum_index) = cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%horizontal_sum_index) + (value)

! For BGC models: Expressions for setting space-dependent FABM variables defined on the full spatial domain.
#define _SET_ODE_(variable,value) cache%write _INDEX_SLICE_PLUS_1_(variable%sms%sum_index) = cache%write _INDEX_SLICE_PLUS_1_(variable%sms%sum_index) + (value)/self%dt
#define _SET_BOTTOM_ODE_(variable,value) cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%bottom_sms%horizontal_sum_index) = cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%bottom_sms%horizontal_sum_index) + (value)/self%dt
#define _SET_SURFACE_ODE_(variable,value) cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%surface_sms%horizontal_sum_index) = cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%surface_sms%horizontal_sum_index) + (value)/self%dt
#define _SET_BOTTOM_EXCHANGE_(variable,value) cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%bottom_flux%horizontal_sum_index) = cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%bottom_flux%horizontal_sum_index) + (value)/self%dt
#define _SET_SURFACE_EXCHANGE_(variable,value) cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%surface_flux%horizontal_sum_index) = cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%surface_flux%horizontal_sum_index) + (value)/self%dt
#define _SET_DD_(variable1,variable2,value) dd _INDEX_SLICE_PLUS_2_(variable1%state_index,variable2%state_index) = dd _INDEX_SLICE_PLUS_2_(variable1%state_index,variable2%state_index) + (value)/self%dt
#define _SET_PP_(variable1,variable2,value) pp _INDEX_SLICE_PLUS_2_(variable1%state_index,variable2%state_index) = pp _INDEX_SLICE_PLUS_2_(variable1%state_index,variable2%state_index) + (value)/self%dt
#define _SET_ODE_(variable,value) cache%write _INDEX_SLICE_PLUS_1_(variable%sms%sum_index) = cache%write _INDEX_SLICE_PLUS_1_(variable%sms%sum_index) + (value)*self%rdt_
#define _SET_BOTTOM_ODE_(variable,value) cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%bottom_sms%horizontal_sum_index) = cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%bottom_sms%horizontal_sum_index) + (value)*self%rdt_
#define _SET_SURFACE_ODE_(variable,value) cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%surface_sms%horizontal_sum_index) = cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%surface_sms%horizontal_sum_index) + (value)*self%rdt_
#define _SET_BOTTOM_EXCHANGE_(variable,value) cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%bottom_flux%horizontal_sum_index) = cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%bottom_flux%horizontal_sum_index) + (value)*self%rdt_
#define _SET_SURFACE_EXCHANGE_(variable,value) cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%surface_flux%horizontal_sum_index) = cache%write_hz _INDEX_HORIZONTAL_SLICE_PLUS_1_(variable%surface_flux%horizontal_sum_index) + (value)*self%rdt_
#define _SET_DD_(variable1,variable2,value) dd _INDEX_SLICE_PLUS_2_(variable1%state_index,variable2%state_index) = dd _INDEX_SLICE_PLUS_2_(variable1%state_index,variable2%state_index) + (value)*self%rdt_
#define _SET_PP_(variable1,variable2,value) pp _INDEX_SLICE_PLUS_2_(variable1%state_index,variable2%state_index) = pp _INDEX_SLICE_PLUS_2_(variable1%state_index,variable2%state_index) + (value)*self%rdt_
#define _SET_EXTINCTION_(value) _ADD_(self%extinction_id,value)
#define _SCALE_DRAG_(value) drag _INDEX_HORIZONTAL_SLICE_ = drag _INDEX_HORIZONTAL_SLICE_ * (value)
#define _SET_ALBEDO_(value) albedo _INDEX_HORIZONTAL_SLICE_ = albedo _INDEX_HORIZONTAL_SLICE_ + (value)
#define _SET_VERTICAL_MOVEMENT_(variable,value) cache%write _INDEX_SLICE_PLUS_1_(variable%movement%sum_index) = cache%write _INDEX_SLICE_PLUS_1_(variable%movement%sum_index) + value/self%dt
#define _SET_VERTICAL_MOVEMENT_(variable,value) cache%write _INDEX_SLICE_PLUS_1_(variable%movement%sum_index) = cache%write _INDEX_SLICE_PLUS_1_(variable%movement%sum_index) + value*self%rdt_
#define _INVALIDATE_STATE_ cache%valid = .false.
#define _REPAIR_STATE_ cache%repair

Expand Down
8 changes: 5 additions & 3 deletions src/fabm_types.F90
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ module fabm_types
type (type_coupling_task_list) :: coupling_task_list

real(rk) :: dt = 1.0_rk
real(rk) :: rdt_ = 1.0_rk

logical :: check_conservation = .false.

Expand Down Expand Up @@ -904,6 +905,7 @@ recursive subroutine add_child(self, model, name, long_name, configunit)
call self%couplings%add_child(model%couplings, trim(model%name))
call self%children%append(model)
call model%initialize(configunit)
model%rdt_ = 1._rk / model%dt

if (model%implements(source_get_light_extinction)) then
call model%add_interior_variable('light_extinction', 'm-1', &
Expand Down Expand Up @@ -1529,12 +1531,12 @@ subroutine register_movement(self, link, movement_id, vertical_movement)
type (type_aggregate_variable_id), intent(inout), target :: movement_id
real(rk), intent(in), optional :: vertical_movement

real(rk) :: vertical_movement_
type (type_link),pointer :: link2
real(rk) :: vertical_movement_
type (type_link), pointer :: link2

vertical_movement_ = 0
if (present(vertical_movement)) vertical_movement_ = vertical_movement
if (.not.associated(movement_id%link)) call self%add_interior_variable(trim(link%name) // '_w', &
if (.not. associated(movement_id%link)) call self%add_interior_variable(trim(link%name) // '_w', &
'm/s', trim(link%target%long_name) // ' vertical velocity', &
vertical_movement_, output=output_none, write_index=movement_id%sum_index, link=movement_id%link, source=source_constant)
if (self%implements(source_get_vertical_movement)) then
Expand Down

0 comments on commit ee2c908

Please sign in to comment.