!! Computes the Salt fluxes caused by gravity drainage.
!!
!!
!!
!!
!! @author Philipp Griewank
!!
!!
!! COPYRIGHT
!!
!! This file is part of SAMSIM.
!!
!! SAMSIM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
!!
!! SAMSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
!!
!! You should have received a copy of the GNU General Public License along with SAMSIM. If not, see <http://www.gnu.org/licenses/>.
!!
!
!!
!!
!! @par Revision History
!! Injected with life by Philipp Griewank, IMPRS (<2010-08-27>)
!!
!!
MODULEmo_grav_drain
USEmo_parameters
USEmo_thermo_functions,ONLY:func_S_br
USEmo_mass
IMPLICITNONE
PUBLIC::fl_grav_drain,fl_grav_drain_simple
CONTAINS
!>
!! Calculates fluxes caused by gravity drainage.
!!
!! If the Rayleigh number of a layer is higher then the critical value, brine leaves the layer by a theoretical brine channel.
!! The discharged brine flows downward through all layers directly into the underlying ocean.
!! To preserve mass the same amount of water flows upwards through all lower layers.
!! In contrast to the downward flux the upward flux is assumed to be in thermal equilibrium thus moving salt and heat to each layer.
!! The upward flux is a standard upwind advection.
!! The downward flux of a layer over the timestep is = x*(Ray-Ray_crit)*dt*thick.
!! _____________________________________
!! | ->__|__<-
!! |______________| v |__________________
!! | ^ ->| |<- ^
!! |______________| |__________________
!! | ^ ^ ->|||||<- ^ ^
!! |______________|vvv|__________________
!! ^ ^ ^ ^ ^ ^
!! This superb ascii art is supposed to show how the assumed fluxes flow downward through a brine channel and upwards through the layer.
!! x and r are passed on to enable easy optimization.
!! The effect of the upward moving brine is calculated in mass_transfer.
!!
!! IMPORTANT: The height assumptions are special. The bottom of the ice edge is assumed to be at psi_s(N_active)/psi_s_min *thick_0
!!
!! The first approach assumed that brine drainage occurred between two layers but performed poorly.
!!
!! If grav_heat_flag is set to 2 the amount of heat transported out of the ice will be compensated in the lowest layer
!!
!! @par Revision History
!! created by Philipp Griewank, IMPRS (2010-08-27) \n
!! Completely revised to assume brine channels by Philipp Griewank , IMPRS (2010-11-05) \n
!! Mass_transfer is used to advect H and S by Philipp Griewank, IMPRS (2010-11-05) \n
!! Added condition S_br(k)>S_br(k+1) by Philipp Griewank. IMPRS (2011-04-29) \n
!! Added harmonic mean for permeability by Philipp Griewank (2014-01-05)
!! The module mo_grotz contains the most important subroutine grotz (Named after GRiewank nOTZ).
!! Mo_grotz is called by SAMSIM.f90.
!! Subroutine grotz contains the time loop, as well as the initialization, and calls all other branches of the model.
!! This model was developed from scratch by Philipp Griewank during and after his PhD at Max Planck Institute of Meteorology from 2010-2014.
!! The code is intended to be understandable and most subroutines, modules, functions, parameters, and global variables have doxygen compatible descriptions.
!! In addition to the doxygen generated description, some python plotscripts are available to plot model output.
!!
!!
!!
!!
!! @author Philipp Griewank
!!
!!
!! COPYRIGHT
!!
!! This file is part of SAMSIM.
!!
!! SAMSIM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
!!
!! SAMSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
!!
!! You should have received a copy of the GNU General Public License along with SAMSIM. If not, see <http://www.gnu.org/licenses/>.
!
!!
!!
!!
!! @par Revision History
!! Started by Philipp Griewank 2012-08-28
!!
MODULEmo_grotz
CONTAINS
!>
!!
!! Main subroutine of SAMSIM, a 1D thermodynamic seaice model.
!! A semi-adaptive grid is used which is managed by mo_layer_dynamics.
!!
!! The basic rundown of the time loop is:
!! 1. Calculate the current ice/snow state and forcing, as well as gravity drainage and flooding
!! 2. Apply all the fluxes, recalculate ice state
!! 3. Flushing and layer dynamics
!!
!! Here is the full rundown of what happens in mo_grotz:
!!
!! - Initialization: all fields are initialized for the given config.json file, and the output is formatted
!! - Input and Forcing read in.
!! TIME LOOP BEGINS:
!! - Calculate the total ice properties, total freshwater, thermal resistivity, energy, bulk salinity
!! - Determine snow and rain rates
!! - Calculate snow thermodynamics
!! - Calculate inner ice thermodynamic fluxes
!! - Calculate brine flux from expulsion
!! - Raw output written out if debug_flag is set to 2
!! - Standard output written
!! - Flooding parametrized
!! - Lowest layer mixing with underlying water
!! - Gravity drainage parametrized
!! - Calcuating and applying the heat fluxes
!! - After heatfluxes are applied new liquidus thermal equilibrium is calculated
!! - Flushing is parametrized
!! - Chemistry advection calculated
!! - Layer Dynamics
!! TIME LOOP ENDS
!! -Final output, files closed, and fields deallocated
!!
!!
!! IMPORTANT:
!! To get the correct freshwater amount make sure the freshwater is calculated using a salinity value to compare against.
!!
!!
!! Common errors leading to termination are: too small timestep, bad programming
!!
!! @par Revision History
!! Basic thermodynamics and layer_dynamics for fixed boundaries seem stable, backup made. by griewank (2010-08-10) \n
!! Add some more outputs, changed routine names and arguments with respect to newly introduces flags by Niels Fuchs, MPIMET (2017-03-01) \n
!! Added a bit of description with the run down of what happends by Philipp Griewank, Uni K (2018-08-08)
SUBROUTINEgrotz()
USEmo_parameters
USEmo_thermo_functions
USEmo_data
USEmo_init
USEmo_layer_dynamics
USEmo_mass
USEmo_grav_drain
USEmo_output
USEmo_flush
USEmo_flood
USEmo_snow
USEmo_functions
USEmo_heat_fluxes
IMPLICITNONE
CHARACTER*12000::description!< String to describes simulation which is output into dat_settings
!Bastard variables, are used for various dirty deeds
INTEGER::jj
REAL(wp)::temp,temp2,temp4,temp5,temp_2017_H,temp_2017_m!when a real is needed !< Niels, 2017 add: temp_2017_m