From cefafa7f9f53276e31689c29d843723ab5ea803a Mon Sep 17 00:00:00 2001 From: murphyqm Date: Wed, 14 Jul 2021 16:11:01 +0100 Subject: [PATCH 1/3] Adding units to docstrings --- pytesimal/analysis.py | 65 ++++++++++++++++++++++--------------- pytesimal/core_function.py | 26 +++++++-------- pytesimal/load_plot_save.py | 50 +++++++++++++++------------- 3 files changed, 80 insertions(+), 61 deletions(-) diff --git a/pytesimal/analysis.py b/pytesimal/analysis.py index a1f05b2..dba7da9 100644 --- a/pytesimal/analysis.py +++ b/pytesimal/analysis.py @@ -29,24 +29,24 @@ def core_freezing( Parameters ---------- coretemp : numpy.ndarray - Array of temperatures in the core + Array of temperatures in the core, in Kelvin. max_time : float - Length of time the model runs for, in seconds + Length of time the model runs for, in seconds. times : numpy.ndarray Array from 0 to the max time +0.5* the timestep, with a spacing equal - to the timestep + to the timestep. latent : list List of total latent heat extracted since core began freezing, at each - timestep + timestep. temp_core_melting : float - Melting point of core material (in K) + Melting point of core material, in Kelvin. timestep : float, default 1e11 Discretisation timestep in seconds. Returns ------- - core_frozen: boolean array where temperature <= 1200 - times_frozen: array of indices of times where the temp <= 1200 + core_frozen: boolean array where temperature <= 1200 K + times_frozen: array of indices of times where the temp <= 1200 K time_core_frozen: when the core starts to freeze, in seconds fully_frozen: when the core finished freezing, in seconds @@ -91,12 +91,12 @@ def cooling_rate_cloudyzone_diameter(d): Parameters ---------- d : float - Cloudy zone particle size in nm + Cloudy zone particle size in nm. Returns ------- cz_rate : float - The cooling rate in K/Myr + The cooling rate in K/Myr. """ m = 7620000 # constant @@ -114,12 +114,12 @@ def cooling_rate_tetra_width(tw): Parameters ---------- tw : float - Tetrataenite bandwidth in nm + Tetrataenite bandwidth in nm. Returns ------- t_rate : float - The cooling rate in K/Myr + The cooling rate in K/Myr. """ k = 14540000 # constant @@ -128,9 +128,21 @@ def cooling_rate_tetra_width(tw): def cooling_rate_to_seconds(cooling_rate): - """Convert cooling rates to seconds.""" + """Convert cooling rates to seconds. + + Parameters + ---------- + cooling_rate : float + The cooling rate in K/Myr. + + Returns + ------- + new_cooling_rate : float + The cooling rate in K/s. + + """ myr = 3.1556926e13 - new_cooling_rate = cooling_rate / myr # /1000000/365/24/60/60 # fix to myr + new_cooling_rate = cooling_rate / myr return new_cooling_rate @@ -156,37 +168,38 @@ def meteorite_depth_and_timing( Parameters ---------- CR : float - cooling rate of meteorite + cooling rate of meteorite, in K/s. temperatures : numpy.ndarray - Array of mantle temperatures + Array of mantle temperatures, in Kelvin. dT_by_dt : numpy.ndarray - Array of mantle cooling rates + Array of mantle cooling rates, in K/dt. radii : numpy.ndarray - Mantle radii spaced by `dr` + Mantle radii spaced by `dr`, in m. r_planet : float - Planetesimal radius, in m + Planetesimal radius, in m. core_size_factor : float, <1 - Radius of the core, expressed as a fraction of `r_planet` + Radius of the core, expressed as a fraction of `r_planet`. time_core_frozen : float - The time the core begins to freeze + The time the core begins to freeze, in dt. fully_frozen : float - The time the core is fully frozen + The time the core is fully frozen, in dt. dr : float, default 1000.0 - Radial step for numerical discretisation + Radial step for numerical discretisation, in m. Returns ------- depth : float - Depth of genesis of meteorite + Depth of genesis of meteorite, in km. string : string Relative timing of tetrataenite formation and core crystallisation, in a string format time_core_frozen : float - The time the core begins to freeze + The time the core begins to freeze, in dt. Time_of_Crossing : float - When the meteorite cools through tetrataenite formation temperature + When the meteorite cools through tetrataenite formation temperature, in + dt. Critical_Radius : float - Depth of meteorite genesis given as radius value + Depth of meteorite genesis given as radius value, in m. """ # Define two empty lists diff --git a/pytesimal/core_function.py b/pytesimal/core_function.py index 7d39808..fc06e61 100644 --- a/pytesimal/core_function.py +++ b/pytesimal/core_function.py @@ -34,26 +34,26 @@ class IsothermalEutecticCore: Attributes ---------- initial_temperature : float - Initial uniform temperature of the core + Initial uniform temperature of the core, in K. melting_temperature : float - Temperature at which core crystallisation initiates + Temperature at which core crystallisation initiates, in K. outer_r : float - Outer core radius + Outer core radius, in m. inner_r : float Inner core radius, not used by this simple implementation of the core (set to zero), but included so that more complex core models can be - coupled to the mantle discretisation function + coupled to the mantle discretisation function. rho : float - Core density + Core density, kg m^-3. cp : float - Core heat capacity + Core heat capacity, J kg^-1 K^-1. core_latent_heat : float Latent heat of crystallisation of the core, used to calculate time for - core to solidify fully + core to solidify fully, J kg^-1. lat : float, optional Tracks latent heat of core, always initially zero in current implementation but included for forward compatibility with a coupled - model where core has already cooled by some degree + model where core has already cooled by some degree, in J kg^-1. """ @@ -112,9 +112,9 @@ def extract_heat(self, power, timestep): Parameters ---------- power : float - Heat extracted across the CMB in Watts + Heat extracted across the CMB in Watts. timestep : float - The time over which the heat is extracted (in s) + The time over which the heat is extracted (in s). """ volume_of_core = (4.0 / 3.0) * np.pi * self.radius ** 3 @@ -139,7 +139,7 @@ def temperature_array_1D(self): Returns ------- temp_array : numpy.ndarray - Time series of `boundary_temperature` + Time series of `boundary_temperature`, in K. """ temp_array = np.asarray(self.templist) @@ -152,12 +152,12 @@ def temperature_array_2D(self, coretemp_array): Parameters ---------- coretemp_array : numpy.ndarray - Array of zeros to be filled wth core temperature history + Array of zeros to be filled wth core temperature history. Returns ------- coretemp_array : numpy.ndarray - Array of core temperature history + Array of core temperature history, in K. """ for i in range(1, len(self.templist[1:])): diff --git a/pytesimal/load_plot_save.py b/pytesimal/load_plot_save.py index 69e5af4..f573c8d 100644 --- a/pytesimal/load_plot_save.py +++ b/pytesimal/load_plot_save.py @@ -178,9 +178,9 @@ def save_params_and_results( Absolute path to directory where file is to be saved. Existence of the directory can be checked with the `check_folder_exists()` function. timestep : float - The timestep used in numerical method. + The timestep used in numerical method, in s. r_planet : float - The radius of the planet in m + The radius of the planet in m. core_size_factor : float The core size as a fraction of the total planet radius. reg_fraction : float @@ -188,29 +188,29 @@ def save_params_and_results( max_time : float The total run-time of the model, in millions of years (Myr). temp_core_melting : float - The melting temperature of the core. + The melting temperature of the core, in K. mantle_heat_cap_value: float - The heat capacity of mantle material. + The heat capacity of mantle material, in J kg^-1 K^-1. mantle_density_value : float - The density of mantle material. + The density of mantle material, in kg m^-3. mantle_conductivity_value : float - The conductivity of the mantle. + The conductivity of the mantle, in W m^-1 K^-1. core_cp : float - The heat capacity of the core. + The heat capacity of the core, in J kg^-1 K^-1. core_density : float - The density of the core. + The density of the core, in kg m^-3. temp_init : float, list, numpy array - The initial temperature of the body. + The initial temperature of the body, in K. temp_surface : float - The surface temperature of the planet. + The surface temperature of the planet, in K. core_temp_init : float - The initial temperature of the core + The initial temperature of the core, in K. core_latent_heat : float - The latent heat of crystallisation of the core. + The latent heat of crystallisation of the core, in J kg^-1. kappa_reg : float - The regolith constant diffusivity + The regolith constant diffusivity, m^2 s^-1. dr : float - The radial step used in the numerical model. + The radial step used in the numerical model, in m. cond_constant : str Flag of `y` or `n` to specify if mantle conductivity is constant. density_constant : str @@ -291,16 +291,16 @@ def save_result_arrays( Absolute path to directory where file is to be saved. Existence of the directory can be checked with the `check_folder_exists()` function. mantle_temperature_array : numpy.ndarray - Temperatures in the mantle for all radii through time. + Temperatures in the mantle for all radii through time, in K. core_temperature_array : numpy.ndarray - Temperatures in the core through time. + Temperatures in the core through time, in K. mantle_cooling_rates : numpy.ndarray - Cooling rates in the mantle for all radii through time. + Cooling rates in the mantle for all radii through time, in K/dt. core_cooling_rates : numpy.ndarray - Cooling rates in the core through time. + Cooling rates in the core through time, in K/dt. latent: list, optional List of latent heat values for the core; needed to - calculate timing of core crystallisation. + calculate timing of core crystallisation, in J kg^-1. Returns ------- @@ -329,8 +329,8 @@ def read_datafile(filepath): with np.load(filepath) as data: temperatures = data["temperatures"] # mantle temperatures in K coretemp = data["coretemp"] # core temperatures in K - dT_by_dt = data["dT_by_dt"] # mantle cooling rates in K/1E11 s - dT_by_dt_core = data["dT_by_dt_core"] # core cooling rates in K/1E11 s + dT_by_dt = data["dT_by_dt"] # mantle cooling rates in K/dt + dT_by_dt_core = data["dT_by_dt_core"] # core cooling rates in K/dt return temperatures, coretemp, dT_by_dt, dT_by_dt_core @@ -360,6 +360,13 @@ def get_million_years_formatters(timestep, maxtime): Creates two matplotlib formatters, one to go from timesteps to myrs and one to go from cooling rate per timestep to cooling rate per million years. + + Parameters + ---------- + timestep : float + Numerical timestep, in s. + maxtime: float + Total time for model run, in s. """ myr = 3.1556926e13 # seconds in a million years @@ -411,7 +418,6 @@ def plot_temperature_history( """ million_years, _, myr = get_million_years_formatters(timestep, maxtime) - # What if only ax or fig are set? Only need fig for cbar really... if (fig is None) and (ax is None): fig, ax = plt.subplots(figsize=(fig_w, fig_h)) From c78a4998b29b8457153b2430c49e82cf08404aa7 Mon Sep 17 00:00:00 2001 From: murphyqm Date: Thu, 15 Jul 2021 11:01:48 +0100 Subject: [PATCH 2/3] Additions to documentation --- pytesimal/load_plot_save.py | 120 +++++++++++++++++++++++++++-- pytesimal/mantle_properties.py | 12 +-- pytesimal/numerical_methods.py | 137 ++++++++++++++++++++------------- 3 files changed, 203 insertions(+), 66 deletions(-) diff --git a/pytesimal/load_plot_save.py b/pytesimal/load_plot_save.py index f573c8d..1883349 100644 --- a/pytesimal/load_plot_save.py +++ b/pytesimal/load_plot_save.py @@ -46,7 +46,25 @@ def check_folder_exists(folder): def make_default_param_file(filepath="example_params.txt"): - """Save an example parameter json file with default parameters.""" + """ + Save an example parameter json file with default parameters. + + Save a dictionary of default parameters as a human-readable json txt file. + This example file can then be used as an input file as-is, or can be edited + in order to modify the model set up. References for the example values can + be found in Murphy Quinlan et al. (2021). + + Murphy Quinlan, M., Walker, A. M., Davies, C. J., Mound, J. E., Müller, T., + & Harvey, J. (2021). The conductive cooling of planetesimals with + temperature-dependent properties. Journal of Geophysical Research: Planets, + 126, e2020JE006726. https://doi.org/10.1029/2020JE006726 + + Parameters + ---------- + filepath : str, optional + Absolute or relative path to save the json parameter file to. + + """ default_variables = { "run_ID": "example_default", "folder": "example_default", @@ -77,7 +95,63 @@ def make_default_param_file(filepath="example_params.txt"): def load_params_from_file(filepath="example_params.txt"): - """Load parameters from a json file and return variable values.""" + """ + Load parameters from a json file and return variable values. + + Parameters + ---------- + filepath : str + Absolute or relative path to load the json parameter file from. + + Returns + ------- + run_ID : str + Identifier for the specific model run. + folder : str + Absolute path to directory where file is to be saved. Existence of + the directory can be checked with the `check_folder_exists()` function. + timestep : float + The timestep used in numerical method, in s. + r_planet : float + The radius of the planet in m. + core_size_factor : float + The core size as a fraction of the total planet radius. + reg_fraction : float + The regolith thickness as a fraction of the total planet radius. + max_time : float + The total run-time of the model, in millions of years (Myr). + temp_core_melting : float + The melting temperature of the core, in K. + mantle_heat_cap_value: float + The heat capacity of mantle material, in J kg^-1 K^-1. + mantle_density_value : float + The density of mantle material, in kg m^-3. + mantle_conductivity_value : float + The conductivity of the mantle, in W m^-1 K^-1. + core_cp : float + The heat capacity of the core, in J kg^-1 K^-1. + core_density : float + The density of the core, in kg m^-3. + temp_init : float, list, numpy array + The initial temperature of the body, in K. + temp_surface : float + The surface temperature of the planet, in K. + core_temp_init : float + The initial temperature of the core, in K. + core_latent_heat : float + The latent heat of crystallisation of the core, in J kg^-1. + kappa_reg : float + The regolith constant diffusivity, m^2 s^-1. + dr : float + The radial step used in the numerical model, in m. + cond_constant : str + Flag of `y` or `n` to specify if mantle conductivity is constant. + density_constant : str + Flag of `y` or `n` to specify if mantle density is constant. + heat_cap_constant : str + Flag of `y` or `n` to specify if mantle heat capacity is constant. + + """ with open(filepath) as json_file: data = json.load(json_file) run_ID = data["run_ID"] @@ -325,6 +399,22 @@ def read_datafile(filepath): Reads the content of the numpy 'npz' data file representing a model run and returns arrays of the mantle temperature, core temperature, and cooling rates of the mantle and core. + + Parameters + ---------- + filepath : str + Location of .npz data file, including file name and npz suffix. + + Returns + ------- + temperatures : numpy.ndarray + Array filled with mantle temperatures, in K. + coretemp : numpy.ndarray + Array filled with core temperatures, in K. + dT_by_dt : numpy.ndarray + Array filled with mantle cooling rates, in K/dt. + dT_by_dt_core : numpy.ndarray + Array filled with core cooling rates, in K/dt. """ with np.load(filepath) as data: temperatures = data["temperatures"] # mantle temperatures in K @@ -343,6 +433,24 @@ def read_datafile_with_latent(filepath): a model run and returns arrays of the mantle temperature, core temperature, cooling rates of the mantle and core, and the number of timesteps the core was crystallising for. + + Parameters + ---------- + filepath : str + Location of .npz data file, including file name and npz suffix. + + Returns + ------- + temperatures : numpy.ndarray + Array filled with mantle temperatures, in K. + coretemp : numpy.ndarray + Array filled with core temperatures, in K. + dT_by_dt : numpy.ndarray + Array filled with mantle cooling rates, in K/dt. + dT_by_dt_core : numpy.ndarray + Array filled with core cooling rates, in K/dt. + latent_array : numpy.ndarray + Array filled with latent heat of the core, as it crystallises, J kg^-1. """ with np.load(filepath) as data: temperatures = data["temperatures"] # mantle temperatures in K @@ -376,8 +484,8 @@ def million_years(x, pos): This gets called for each tick value in the plot with the x coordinate and a position (which may be None) and returns a string to be used as - the value to be plotted on the axis of the graph. This retuns a time - in millions of years, rounded to look nice + the value to be plotted on the axis of the graph. This returns a time + in millions of years, rounded to look nice. """ value = (x * timestep) / myr value_rounded = round(value, -2) @@ -547,7 +655,7 @@ def two_in_one( Return a heat map of depth vs time; colormap shows variation in temp. Change save="n" to save="y" when function is called to produce a png - image named after the data filename + image named after the data filename. """ fig, axs = plt.subplots(2, 1, figsize=(fig_w, fig_h), sharey=True) @@ -611,7 +719,7 @@ def two_in_one( fig_w = args.fig_width fig_h = args.fig_height - # Read data and make grap + # Read data and make graph temperatures, coretemp, dT_by_dt, dT_by_dt_core = read_datafile( args.datafile ) diff --git a/pytesimal/mantle_properties.py b/pytesimal/mantle_properties.py index eac7572..b19e8b0 100755 --- a/pytesimal/mantle_properties.py +++ b/pytesimal/mantle_properties.py @@ -35,11 +35,11 @@ class MantleProperties: Attributes ---------- rho : float, default 3341.0 - The density of the mantle material (constant) + The density of the mantle material (constant), in kg m^-3. cp : float, default 819.0 - The heat capacity of mantle material (constant) + The heat capacity of mantle material (constant), in J kg^-1 K^-1. k : float, default 3.0 - The conductivity of mantle material (constant) + The conductivity of mantle material (constant), in W m^-1 K^-1. """ def __init__(self, rho=3341.0, cp=819.0, k=3.0): @@ -193,11 +193,11 @@ def set_up_mantle_properties( Default `'y'` results in constant heat capacity, while any other string produces variable heat capacity. mantle_density : float, default 3341.0 - Constant value for mantle density + Constant value for mantle density, in kg m^-3. mantle_heat_capacity : float, default 819.0 - Constant value for mantle heat capacity + Constant value for mantle heat capacity, in J kg^-1 K^-1. mantle_conductivity : float - Constant value for mantle conductivity + Constant value for mantle conductivity, in W m^-1 K^-1. Returns ------- diff --git a/pytesimal/numerical_methods.py b/pytesimal/numerical_methods.py index 36fb6da..2b4dadc 100755 --- a/pytesimal/numerical_methods.py +++ b/pytesimal/numerical_methods.py @@ -24,15 +24,16 @@ def calculate_diffusivity(conductivity, heat_capacity, density): Parameters ---------- conductivity : float - Thermal conductivity of the material + Thermal conductivity of the material, in W m^-1 K^-1. heat_capacity : float - Heat capacity of the material + Heat capacity of the material, in J kg^-1 K^-1. density : float - Density of the material + Density of the material, in kg m^-3. Returns ------- diffusivity : float + The calculated diffusivity, in m^2 s^-1. """ diffusivity = conductivity / (density * heat_capacity) @@ -52,11 +53,11 @@ def check_stability(max_diffusivity, timestep, dr): ---------- max_diffusivity : float The highest diffusivity of the system to impose the most restrictive - conditions + conditions, , in m^2 s^-1. timestep : float - The timestep used for the numerical scheme + The timestep used for the numerical scheme, in s. dr : float - The radial step used for the numerical scheme + The radial step used for the numerical scheme, in m. Returns ------- @@ -81,16 +82,16 @@ def surface_dirichlet_bc(temperatures, temp_surface, i): Parameters ---------- temperatures : numpy.ndarray - Numpy array of mantle temperatures to apply condition to + Numpy array of mantle temperatures to apply condition to, in K. temp_surface : float - The temperature at the surface boundary + The temperature at the surface boundary, in K. i : int - Index along time axis where condition is to be set + Index along time axis where condition is to be set. Returns ------- temperatures : numpy.ndarray - Temperature array with condition applied + Temperature array with condition applied, in K. """ temperatures[-1, i] = temp_surface @@ -104,16 +105,16 @@ def cmb_dirichlet_bc(temperatures, core_boundary_temperature, i): Parameters ---------- temperatures : numpy.ndarray - Numpy array of mantle temperatures to apply condition to + Numpy array of mantle temperatures to apply condition to, in K. core_boundary_temperature : float - The temperature at the core mantle boundary + The temperature at the core mantle boundary, in K. i : int - Index along time axis where condition is to be set + Index along time axis where condition is to be set. Returns ------- temperatures : numpy.ndarray - Temperature array with condition applied + Temperature array with condition applied, in K. """ temperatures[0, i] = core_boundary_temperature return temperatures @@ -133,17 +134,18 @@ def cmb_neumann_bc(temperatures, core_boundary_temperature, i): Parameters ---------- temperatures : numpy.ndarray - Numpy array of mantle temperatures to apply condition to + Numpy array of mantle temperatures to apply condition to, in K. core_boundary_temperature : float The temperature at the core mantle boundary; this is not used by this - boundary condition but inclusion allows functions to be easily swapped + boundary condition but inclusion allows functions to be easily swapped. + In K. i : int - Index along time axis where condition is to be set + Index along time axis where condition is to be set. Returns ------- temperatures : numpy.ndarray - Temperature array with condition applied + Temperature array with condition applied, in K. """ temperatures[0, i] = ( 4.0 * (temperatures[1, i]) - temperatures[2, i] @@ -159,11 +161,11 @@ class EnergyExtractedAcrossCMB: Attributes ---------- outer_r : float - Core radius + Core radius, in m. timestep : float - Time over which heat is extracted + Time over which heat is extracted, in s. radius_step : float - Radial step for numerical discretisation + Radial step for numerical discretisation, in m. """ def __init__(self, outer_r, timestep, radius_step): @@ -239,25 +241,26 @@ def discretisation( ---------- core_values : core object An object that represents the state of the layer inside the current - layer (normally a metalic core). The object must provide one method + layer (normally a metallic core). The object must provide one method and two attributes. The method extract_heat(power, timestep) is called on each timestep and represents the amount of heat that is lost from - the the inner layer to the presnet layer (power, in W) over an amount - of time (timestep, in s). The attribute temperature gives the temperature - at the top of the inner layer and this is used (after calling extract_heat) - as input to the basal boundary condition calculation. The attribute latent - reports any latent heat released by freezing and this is not explicity used - in the evaluation of mantle temperatures. + the the inner layer to the present layer (power, in W) over an amount + of time (timestep, in s). The attribute temperature gives the + temperature at the top of the inner layer and this is used (after + calling extract_heat) as input to the basal boundary condition + calculation. The attribute latent reports any latent heat released by + freezing and this is not explicitly used in the evaluation of mantle + temperatures. latent : list Empty list (unless coupling two models) of latent heat extracted from - the core + the core. temp_init : float, numpy.ndarray - The initial temperature (in K) of the mantle with float implying initial - homogeneous temperature distribution + The initial temperature (in K) of the mantle with float implying + initial homogeneous temperature distribution. core_temp_init : float, numpy.ndarray Initial temperature of the core; current core object is isothermal so only accepts float but more complex core models could track the - temperature distribution in the core + temperature distribution in the core. In K. top_mantle_bc : callable Calleable function that defines the boundary condition at the planetesimal surface. The calling signature is @@ -270,46 +273,72 @@ def discretisation( bottom_mantle_bc : callable Calleable function that defines the boundary condition at the base of the planetesimal mantle. The calling signature is - bottom_mantle_bc(temperatures, core_boundary_temperature, timestep_index) - where temperatures is the temperatures array to be updated with the - boundary condition, core_boundary_temperature is the temperature (that - may be involved in the calculation) and timestep_index is the column - index of the current timestep. The function must return an updated - temperatures array. See cmb_neumann_bc for an example. + bottom_mantle_bc(temperatures, core_boundary_temperature, + timestep_index) where temperatures is the temperatures array to be + updated with the boundary condition, core_boundary_temperature is the + temperature (that may be involved in the calculation) and + timestep_index is the column index of the current timestep. The + function must return an updated temperatures array. See cmb_neumann_bc + for an example. temp_surface : float - Temperature at the surface of the planetesimal + Temperature at the surface of the planetesimal, in K. temperatures : numpy.ndarray - Numpy array to fill with mantle temperatures + Numpy array to fill with mantle temperatures in K. dr : float - Radial step for numerical discretisation + Radial step for numerical discretisation, in m. coretemp_array : numpy.ndarray Numpy array to fill with core temperatures timestep : float - Timestep for numerical discretisation in s + Timestep for numerical discretisation, in s. r_core : float - Radius of the core in m + Radius of the core in m. radii : numpy.ndarray - Numpy array of radii values in the mantle, with spacing defined by `dr` + Numpy array of radii values in the mantle, with spacing defined by + `dr`, in m. times : numpy.ndarray Numpy array of time values in s, up to the maximum time, with spacing - controlled by `timestep` + controlled by `timestep`, in s. where_regolith : numpy.ndarray - Boolean array recording presence of regolith + Boolean array recording presence of regolith. kappa_reg : float - Constant diffusivity of the regolith - cond : function, method - Function or method that defines the mantle conductivity - heatcap : function, method - Function or method that defines the mantle heat capacity - dens : function, method - Function or method that defines the mantle density + Constant diffusivity of the regolith, in m^2 s^-1. + cond : callable + Callable function or method that defines the mantle conductivity. The + calling signature is cond.getk(temperatures[radial_index, + timestep_index]), where temperatures is the temperatures array, + radial_index is the row index of the radius, and timestep_index is the + column index of the timestep, that define the value in temperatures at + which conductivity should be evaluated. The function must return a + value for conductivity in in W m^-1 K^-1. + heatcap : callable + Callable function or method that defines the mantle heat capacity. The + calling signature is heatcap.getcp(temperatures[radial_index, + timestep_index]), where temperatures is the temperatures array, + radial_index is the row index of the radius, and timestep_index is the + column index of the timestep, that define the value in temperatures at + which heat capacity should be evaluated. The function must return a + value for heat capacity in J kg^-1 K^-1. + dens : callable + Callable function or method that defines the mantle density. The + calling signature is dens.getrho(temperatures[radial_index, + timestep_index]), where temperatures is the temperatures array, + radial_index is the row index of the radius, and timestep_index is the + column index of the timestep, that define the value in temperatures at + which heat capacity should be evaluated. The function must return a + value for density in kg m^-3. non_lin_term : str, default `'y'` Flag to switch off the non-linear term when temperature-dependent - conductivity is being used + conductivity is being used. Returns ------- + temperatures : numpy.ndarray + Array filled with mantle temperatures, in K. + coretemp : numpy.ndarray + Array filled with core temperatures, in K. + latent : list + List of latent heat values during core crystallisation, in J kg^-1. """ From cccd66d308a3df941eab3639a513dbc986254691 Mon Sep 17 00:00:00 2001 From: murphyqm Date: Thu, 15 Jul 2021 11:31:19 +0100 Subject: [PATCH 3/3] Adding to documentation --- pytesimal/numerical_methods.py | 16 ++++++---------- pytesimal/quick_workflow.py | 7 +++++++ pytesimal/setup_functions.py | 16 ++++++++-------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/pytesimal/numerical_methods.py b/pytesimal/numerical_methods.py index 2b4dadc..6418f00 100755 --- a/pytesimal/numerical_methods.py +++ b/pytesimal/numerical_methods.py @@ -211,16 +211,12 @@ def discretisation( core_temp_init, top_mantle_bc, bottom_mantle_bc, - # temp_core_melting, temp_surface, temperatures, dr, coretemp_array, timestep, - # core_density, - # core_cp, r_core, - # core_latent_heat, radii, times, where_regolith, @@ -304,24 +300,24 @@ def discretisation( Constant diffusivity of the regolith, in m^2 s^-1. cond : callable Callable function or method that defines the mantle conductivity. The - calling signature is cond.getk(temperatures[radial_index, - timestep_index]), where temperatures is the temperatures array, + calling signature is `cond.getk(temperatures[radial_index, + timestep_index])`, where temperatures is the temperatures array, radial_index is the row index of the radius, and timestep_index is the column index of the timestep, that define the value in temperatures at which conductivity should be evaluated. The function must return a value for conductivity in in W m^-1 K^-1. heatcap : callable Callable function or method that defines the mantle heat capacity. The - calling signature is heatcap.getcp(temperatures[radial_index, - timestep_index]), where temperatures is the temperatures array, + calling signature is `heatcap.getcp(temperatures[radial_index, + timestep_index])`, where temperatures is the temperatures array, radial_index is the row index of the radius, and timestep_index is the column index of the timestep, that define the value in temperatures at which heat capacity should be evaluated. The function must return a value for heat capacity in J kg^-1 K^-1. dens : callable Callable function or method that defines the mantle density. The - calling signature is dens.getrho(temperatures[radial_index, - timestep_index]), where temperatures is the temperatures array, + calling signature is `dens.getrho(temperatures[radial_index, + timestep_index])`, where temperatures is the temperatures array, radial_index is the row index of the radius, and timestep_index is the column index of the timestep, that define the value in temperatures at which heat capacity should be evaluated. The function must return a diff --git a/pytesimal/quick_workflow.py b/pytesimal/quick_workflow.py index eb35dc7..0496ed5 100644 --- a/pytesimal/quick_workflow.py +++ b/pytesimal/quick_workflow.py @@ -40,6 +40,13 @@ def workflow( Results files will be saved under the `filename` with `_results` and the appropriate file extension appended. + The json (.txt) file contains a list of parameter names and values, while + the array file (.npz) contains four different arrays: + `mantle_temperature_array` - an array of mantle temperatures in K, + `core_temperature_array` - an array of core temperatures in K, + `mantle_cooling_rates` - an array of mantle cooling rates in K/dt, + `core_cooling_rates` - an array of core cooling rates in K/dt. + Parameters ---------- filename : str diff --git a/pytesimal/setup_functions.py b/pytesimal/setup_functions.py index efa1d11..62655a8 100644 --- a/pytesimal/setup_functions.py +++ b/pytesimal/setup_functions.py @@ -24,22 +24,22 @@ def set_up( Parameters ---------- timestep : float, default 1e11 - A timestep for the numerical discretisation + A timestep for the numerical discretisation, in s r_planet : float, default 250000.0 - The radius of the planetesimal in m + The radius of the planetesimal, in m core_size_factor : float, < 1.0, default 0.5 The core radius expressed as a fraction of `r_planet` reg_fraction : float, <1.0, default 0.032 The core thickness expressed as a fraction of `r_planet` max_time : float, default 400.0 - Total time for model to run, in millions of years + Total time for model to run, in millions of years (Myr) dr : float, default 1000.0 - Radial step for the numerical discretisation + Radial step for the numerical discretisation, in m Returns ------- r_core : float, - Radius of the core in m + Radius of the core, in m radii : numpy.ndarray Numpy array of radius values in m for the mantle, with spacing defined by `dr` @@ -51,12 +51,12 @@ def set_up( where_regolith : numpy.ndarray Boolean array with location of regolith times : numpy.ndarray - Numpy array starting at 0 and going to 400 myr, with timestep + Numpy array starting at 0 and going to 400 Myr, with timestep controlling the spacing mantle_temperature_array : numpy.ndarray - Numpy array of zeros to be filled with mantle temperatures + Numpy array of zeros to be filled with mantle temperatures in K core_temperature_array : numpy.ndarray - Numpy array of zeros to be filled with core temperatures + Numpy array of zeros to be filled with core temperatures in K """ # Set up list of timesteps