Skip to content
Draft
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
49 changes: 46 additions & 3 deletions compass/landice/iceshelf_melt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
from netCDF4 import Dataset
from netCDF4 import Dataset, chartostring


def calc_mean_TF(geometry_file, forcing_file):
def calc_mean_TF(geometry_file, forcing_file, start_year=None,
end_year=None):
"""
Function to calculate mean thermal forcing across all floating ice in a
domain.
Expand All @@ -14,14 +15,27 @@ def calc_mean_TF(geometry_file, forcing_file):

forcing_file : str
name of file containing MALI ocean forcing information

start_year : int, optional
First year (inclusive) of the period over which the 3D thermal
forcing is time-averaged before interpolation to the ice draft.
Years are read from ``xtime`` in ``forcing_file``. If neither
``start_year`` nor ``end_year`` is given, the first time slice is
used.

end_year : int, optional
Last year (inclusive) of the averaging period
"""

rhoi = 910.0
rhosw = 1028.0

ff = Dataset(forcing_file, 'r')
zOcean = ff.variables['ismip6shelfMelt_zOcean'][:]
TFocean = ff.variables['ismip6shelfMelt_3dThermalForcing'][0, :, :]
time_indices = _get_time_indices(ff, forcing_file, start_year, end_year)
TFocean = np.ma.mean(
ff.variables['ismip6shelfMelt_3dThermalForcing'][time_indices, :, :],
axis=0)

f = Dataset(geometry_file, 'r')
thickness = f.variables['thickness'][0, :]
Expand Down Expand Up @@ -49,3 +63,32 @@ def calc_mean_TF(geometry_file, forcing_file):
ff.close()

return meanTF, iceshelf_area


def _get_time_indices(ff, forcing_file, start_year, end_year):
"""
Get the time indices in the forcing file to average over
"""
if start_year is None and end_year is None:
return [0]
if start_year is None or end_year is None:
raise ValueError('Both start_year and end_year must be given to '
'average thermal forcing over a period.')
if start_year > end_year:
raise ValueError(f'start_year ({start_year}) is after end_year '
f'({end_year}).')
if 'xtime' not in ff.variables:
raise ValueError(f'{forcing_file} has no xtime variable, so a '
f'calibration year range cannot be used.')

xtime = ff.variables['xtime'][:]
if xtime.ndim > 1:
xtime = chartostring(xtime)
years = np.array([int(str(time).strip()[0:4]) for time in xtime])
time_indices = np.nonzero((years >= start_year) &
(years <= end_year))[0]
if len(time_indices) == 0:
raise ValueError(f'No time slices in {forcing_file} fall between '
f'{start_year} and {end_year}. Available years: '
f'{years.min()}-{years.max()}.')
return time_indices
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ SMB_file_path = /global/cfs/cdirs/fanssie/MALI_projects/Amery_UQ/Amery_4to20km_f
# converting target melt flux to deltaT.
iceshelf_area_obs = 60654.e6

# Optional year range (inclusive) over which thermal forcing in TF_file_path
# is time-averaged when converting meltflux to deltaT. Years are read from
# xtime. Runs still use the full time-varying TF_file_path. If both are
# omitted, the first time slice of TF_file_path is used.
# calibration_start_year = 1995
# calibration_end_year = 2014

# Parameter definitions are listed in this section in sampling order.
# Use the prefix "nl." for float parameters that map to namelist options.
# Each parameter must define "<name> = min, max".
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
%YAML 1.1
---
ANONYMOUS:
Problem:
Depth Integrated Model: true
LandIce Field Norm:
sliding_velocity_basalside:
Regularization Type: Given Value
Regularization Value: 1.0e-4
LandIce BCs:
BC 0:
Cubature Degree: 8
Basal Friction Coefficient:
Type: Power Law
Power Exponent: 0.2
Mu Type: Field
Effective Pressure Type: Constant
Effective Pressure: 1.0
# Zero Effective Pressure On Floating Ice At Nodes: true
Zero Beta On Floating Ice: true

# Discretization Description
Discretization:
#Exodus Output File Name: albany_output.exo

Piro:
# Nonlinear Solver Information
NOX:
Nonlinear Solver: Line Search Based
Line Search:
Full Step:
Full Step: 1.0e+00
Method: Backtrack
Solver Options:
Status Test Check Type: Minimal
Status Tests:
Test Type: Combo
Combo Type: OR
Number of Tests: 2
Test 0:
Test Type: NormF
Norm Type: Two Norm
Scale Type: Scaled
Tolerance: 1.0e-05
Test 1:
Test Type: MaxIters
Maximum Iterations: 50
Printing:
Output Precision: 3
Output Processor: 0
Output Information:
Error: true
Warning: true
Outer Iteration: true
Parameters: false
Details: false
Linear Solver Details: false
Stepper Iteration: true
Stepper Details: true
Stepper Parameters: true

Direction:
Method: Newton
Newton:
Forcing Term Method: Constant
Rescue Bad Newton Solve: true
Linear Solver:
Write Linear System: false
Tolerance: 1.0e-8

Stratimikos Linear Solver:
Stratimikos:

# Linear Solver Information
Linear Solver Type: Belos
Linear Solver Types:
Belos:
Solver Type: Block GMRES
Solver Types:
Block GMRES:
Output Frequency: 20
Output Style: 1
Verbosity: 33
Maximum Iterations: 200
Block Size: 1
Num Blocks: 200
Flexible Gmres: false
VerboseObject:
Output File: none
Verbosity Level: low

# Preconditioner Information
Preconditioner Type: MueLu
Preconditioner Types:

Ifpack2:
Overlap: 1
Prec Type: ILUT

MueLu:
Matrix:
PDE equations: 2
Factories:
myLineDetectionFact:
factory: LineDetectionFactory
'linedetection: orientation': coordinates
mySemiCoarsenPFact1:
factory: SemiCoarsenPFactory
'semicoarsen: coarsen rate': 14
UncoupledAggregationFact2:
factory: UncoupledAggregationFactory
'aggregation: ordering': graph
'aggregation: max selected neighbors': 0
'aggregation: min agg size': 3
'aggregation: phase3 avoid singletons': true
MyCoarseMap2:
factory: CoarseMapFactory
Aggregates: UncoupledAggregationFact2
myTentativePFact2:
'tentative: calculate qr': true
factory: TentativePFactory
Aggregates: UncoupledAggregationFact2
CoarseMap: MyCoarseMap2
mySaPFact2:
'sa: eigenvalue estimate num iterations': 10
'sa: damping factor': 1.33333e+00
factory: SaPFactory
P: myTentativePFact2
myTransferCoordinatesFact:
factory: CoordinatesTransferFactory
CoarseMap: MyCoarseMap2
Aggregates: UncoupledAggregationFact2
myTogglePFact:
factory: TogglePFactory
'semicoarsen: number of levels': 2
TransferFactories:
P1: mySemiCoarsenPFact1
P2: mySaPFact2
Ptent1: mySemiCoarsenPFact1
Ptent2: myTentativePFact2
Nullspace1: mySemiCoarsenPFact1
Nullspace2: myTentativePFact2
myRestrictorFact:
factory: TransPFactory
P: myTogglePFact
myToggleTransferCoordinatesFact:
factory: ToggleCoordinatesTransferFactory
Chosen P: myTogglePFact
TransferFactories:
Coordinates1: mySemiCoarsenPFact1
Coordinates2: myTransferCoordinatesFact
myRAPFact:
factory: RAPFactory
P: myTogglePFact
R: myRestrictorFact
TransferFactories:
For Coordinates: myToggleTransferCoordinatesFact
myRepartitionHeuristicFact:
factory: RepartitionHeuristicFactory
A: myRAPFact
'repartition: min rows per proc': 3000
'repartition: max imbalance': 1.327e+00
'repartition: start level': 1
myZoltanInterface:
factory: ZoltanInterface
A: myRAPFact
Coordinates: myToggleTransferCoordinatesFact
number of partitions: myRepartitionHeuristicFact
myRepartitionFact:
factory: RepartitionFactory
A: myRAPFact
Partition: myZoltanInterface
'repartition: remap parts': true
number of partitions: myRepartitionHeuristicFact
myRebalanceProlongatorFact:
factory: RebalanceTransferFactory
type: Interpolation
P: myTogglePFact
Coordinates: myToggleTransferCoordinatesFact
Nullspace: myTogglePFact
myRebalanceRestrictionFact:
factory: RebalanceTransferFactory
type: Restriction
R: myRestrictorFact
myRebalanceAFact:
factory: RebalanceAcFactory
A: myRAPFact
TransferFactories: { }
mySmoother1:
factory: TrilinosSmoother
type: LINESMOOTHING_BANDEDRELAXATION
'smoother: pre or post': both
ParameterList:
'relaxation: type': Gauss-Seidel
'relaxation: sweeps': 1
'relaxation: damping factor': 1.0
mySmoother3:
factory: TrilinosSmoother
type: RELAXATION
'smoother: pre or post': both
ParameterList:
'relaxation: type': Gauss-Seidel
'relaxation: sweeps': 1
'relaxation: damping factor': 1.0
mySmoother4:
factory: TrilinosSmoother
type: RELAXATION
'smoother: pre or post': pre
ParameterList:
'relaxation: type': Gauss-Seidel
'relaxation: sweeps': 4
'relaxation: damping factor': 1.0
Hierarchy:
max levels: 7
'coarse: max size': 2000
verbosity: None
Finest:
Smoother: mySmoother1
CoarseSolver: mySmoother4
P: myRebalanceProlongatorFact
Nullspace: myRebalanceProlongatorFact
CoarseNumZLayers: myLineDetectionFact
LineDetection_Layers: myLineDetectionFact
LineDetection_VertLineIds: myLineDetectionFact
A: myRebalanceAFact
Coordinates: myRebalanceProlongatorFact
Importer: myRepartitionFact
All:
startLevel: 1
Smoother: mySmoother4
CoarseSolver: mySmoother4
P: myRebalanceProlongatorFact
Nullspace: myRebalanceProlongatorFact
CoarseNumZLayers: myLineDetectionFact
LineDetection_Layers: myLineDetectionFact
LineDetection_VertLineIds: myLineDetectionFact
A: myRebalanceAFact
Coordinates: myRebalanceProlongatorFact
Importer: myRepartitionFact
Loading
Loading