From b5b14045560a92f5ee034b2f8dd49324d1a6fd65 Mon Sep 17 00:00:00 2001 From: Nick Wagner Date: Thu, 15 Feb 2024 14:37:49 -0600 Subject: [PATCH 1/5] Update Using RadialSolver.md Updated documentation of radial_solver for degree stability. --- Documentation/Using RadialSolver.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/Using RadialSolver.md b/Documentation/Using RadialSolver.md index 4fe2bbc3..cdcc1bf5 100644 --- a/Documentation/Using RadialSolver.md +++ b/Documentation/Using RadialSolver.md @@ -66,7 +66,7 @@ radial_solver_solution = radial_solver( # Harmonic degree used. # Note that the stability of the solution gets worse with higher-l. You may need to increase the relative tolerance # or use simpler layer assumptions to get a successful solution. - # It particularly starts to break down for l > 10. + # It particularly starts to break down for l > 10 but stable solutions exist up to l=40. solve_for = None, # What to solve for (type: tuple[str, ...]) From d8697f800c8fdec8d8bb45db1e81475e380db33a Mon Sep 17 00:00:00 2001 From: "Joe P. Renaud" Date: Thu, 15 Feb 2024 16:42:53 -0500 Subject: [PATCH 2/5] DOCS: Updated documentation, change log, and version. --- CHANGES.md | 5 +++++ Documentation/Using RadialSolver.md | 2 ++ pyproject.toml | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ae028fdb..435dadb6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,11 @@ * Other Major Changes * Remove support for the older non-cythonized `radial_solver` module. +### Version 0.5.2 (2024-NN) + +Documentation +* Improved RadialSolver documentation. + ### Version 0.5.1 (2024-02-14) * Removed Python 3.8 support due to issues with building SciPy. diff --git a/Documentation/Using RadialSolver.md b/Documentation/Using RadialSolver.md index cdcc1bf5..8c117afc 100644 --- a/Documentation/Using RadialSolver.md +++ b/Documentation/Using RadialSolver.md @@ -67,6 +67,8 @@ radial_solver_solution = radial_solver( # Note that the stability of the solution gets worse with higher-l. You may need to increase the relative tolerance # or use simpler layer assumptions to get a successful solution. # It particularly starts to break down for l > 10 but stable solutions exist up to l=40. + # For higher degrees, it is recommended to start integration higher in the planet. I.,e. above the + # core-mantle-boundary (if applicable). solve_for = None, # What to solve for (type: tuple[str, ...]) diff --git a/pyproject.toml b/pyproject.toml index a6c7b3e6..9c8e18de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name='TidalPy' -version = '0.5.1' +version = '0.5.2.a0' description='Tidal Dynamics and Thermal-Orbital Evolution Software Suite Implemented in Cython and Python' authors= [ {name = 'Joe P. Renaud', email = 'TidalPy@gmail.com'} From b87742244d69cdd14430d302a53476144a253fa8 Mon Sep 17 00:00:00 2001 From: Jrenaud-Desk Date: Thu, 22 Feb 2024 14:04:49 -0500 Subject: [PATCH 3/5] FIX: Added exception when user provides incorrect number of layers to radial solver --- CHANGES.md | 3 +++ README.md | 2 +- TidalPy/RadialSolver/solver.pyx | 11 +++++++++++ pyproject.toml | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 435dadb6..3c1331f4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,9 @@ Documentation * Improved RadialSolver documentation. +Fixes: +* Added error message to `RadialSolver.radial_solver` if length of provided assumption tuples is not the same. + ### Version 0.5.1 (2024-02-14) * Removed Python 3.8 support due to issues with building SciPy. diff --git a/README.md b/README.md index 02a92e86..4e653be7 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ --- -TidalPy Version 0.5.1 Alpha +TidalPy Version 0.5.1 Alpha **Tidal Dynamics and Thermal-Orbital Evolution Software Suite Implemented in Cython and Python** diff --git a/TidalPy/RadialSolver/solver.pyx b/TidalPy/RadialSolver/solver.pyx index b3ceeec9..bdcfeaaa 100644 --- a/TidalPy/RadialSolver/solver.pyx +++ b/TidalPy/RadialSolver/solver.pyx @@ -1184,6 +1184,17 @@ def radial_solver( # Unpack inefficient user-provided tuples into bool arrays and pass by pointer cdef size_t num_layers num_layers = len(layer_types) + + # Check that number of assumptions match. + if len(is_static_by_layer) != num_layers: + raise AttributeError('Number of `is_static_by_layer` must match number of `layer_types`.') + if len(is_incompressible_by_layer) != num_layers: + raise AttributeError('Number of `is_incompressible_by_layer` must match number of `layer_types`.') + if len(upper_radius_by_layer) != num_layers: + raise AttributeError('Number of `upper_radius_by_layer` must match number of `layer_types`.') + + # Build array of assumptions + # OPT: Perhaps set a maximum number of layers then we can put these on the stack rather than heap allocating them. cdef int* layer_assumptions_ptr = allocate_mem( 3 * num_layers * sizeof(int), 'layer_assumptions_ptr (radial_solver; init)' diff --git a/pyproject.toml b/pyproject.toml index 9c8e18de..bfe73003 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name='TidalPy' -version = '0.5.2.a0' +version = '0.5.2.a1' description='Tidal Dynamics and Thermal-Orbital Evolution Software Suite Implemented in Cython and Python' authors= [ {name = 'Joe P. Renaud', email = 'TidalPy@gmail.com'} From d9fe40205013a8d266ddb32d9daad5d2a25cbd64 Mon Sep 17 00:00:00 2001 From: Jrenaud-Desk Date: Thu, 22 Feb 2024 16:10:10 -0500 Subject: [PATCH 4/5] FIX: disallowed non C-continguous arrays --- CHANGES.md | 4 +++- Documentation/Rheology.md | 3 +++ Documentation/Using RadialSolver.md | 3 +++ TidalPy/RadialSolver/derivatives/odes.pyx | 2 +- TidalPy/RadialSolver/love.pyx | 8 +++---- TidalPy/RadialSolver/solver.pyx | 10 ++++----- TidalPy/rheology/base.pyx | 10 ++++----- .../utilities/dimensions/nondimensional.pyx | 22 +++++++++---------- pyproject.toml | 2 +- 9 files changed, 36 insertions(+), 28 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3c1331f4..d3734b78 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,10 +7,12 @@ ### Version 0.5.2 (2024-NN) Documentation -* Improved RadialSolver documentation. +* Improved RadialSolver documentation regarding higher degree-l. +* Added info about issues that can arise from using non C-continguous arrays in cythonized functions. Fixes: * Added error message to `RadialSolver.radial_solver` if length of provided assumption tuples is not the same. +* Fixed issue where non C-continguous arrays were allowed in cythonized functions that required them. ### Version 0.5.1 (2024-02-14) * Removed Python 3.8 support due to issues with building SciPy. diff --git a/Documentation/Rheology.md b/Documentation/Rheology.md index 0a2df617..c1f1112e 100644 --- a/Documentation/Rheology.md +++ b/Documentation/Rheology.md @@ -50,6 +50,9 @@ print(complex_shear) TidalPy provides helper methods to efficiently parse over arrays. These functions use multithreading when possible to quickly calculate results over large arrays. +Note that all arrays must be [C-contiguous](https://stackoverflow.com/questions/26998223/what-is-the-difference-between-contiguous-and-non-contiguous-arrays). +If you suspect that an array may not be C-contiguous you can use the numpy function `arr = np.ascontiguousarray(arr)` to ensure that they are before being passed to the rheology methods. + ```python from TidalPy.models import Andrade diff --git a/Documentation/Using RadialSolver.md b/Documentation/Using RadialSolver.md index 8c117afc..519eb7d8 100644 --- a/Documentation/Using RadialSolver.md +++ b/Documentation/Using RadialSolver.md @@ -14,6 +14,9 @@ To learn more about this method please review the literature cited in the refere ## `TidalPy.RadialSolver.radial_solver` Function The `radial_solver` function, contained in the `TidalPy.RadialSolver` module can be used with the following arguments. +Note that all arrays must be [C-contiguous](https://stackoverflow.com/questions/26998223/what-is-the-difference-between-contiguous-and-non-contiguous-arrays). +If you suspect that an array may not be C-contiguous you can use the numpy function `arr = np.ascontiguousarray(arr)` to ensure that they are before being passed to the rheology methods. + ```python from TidalPy.RadialSolver import radial_solver radial_solver_solution = radial_solver( diff --git a/TidalPy/RadialSolver/derivatives/odes.pyx b/TidalPy/RadialSolver/derivatives/odes.pyx index ec417046..30bad94e 100644 --- a/TidalPy/RadialSolver/derivatives/odes.pyx +++ b/TidalPy/RadialSolver/derivatives/odes.pyx @@ -752,7 +752,7 @@ cdef RadialSolverBase cf_build_solver( cdef RadialSolverBase solver # Convert the y0 pointer to a memoryview in order to work with CyRK's CySolver __init__ - cdef double[:] y0_view = y0_ptr + cdef double[::1] y0_view = y0_ptr if (layer_type == 0): # Solid layer diff --git a/TidalPy/RadialSolver/love.pyx b/TidalPy/RadialSolver/love.pyx index 47085def..ffca2762 100644 --- a/TidalPy/RadialSolver/love.pyx +++ b/TidalPy/RadialSolver/love.pyx @@ -30,8 +30,8 @@ cdef void find_love_cf( def find_love( - double complex[:] complex_love_numbers_view, - double complex[:] surface_solutions_view, + double complex[::1] complex_love_numbers_view, + double complex[::1] surface_solutions_view, double surface_gravity ): """ @@ -39,9 +39,9 @@ def find_love( Parameters ---------- - complex_love_numbers_view : double complex[:], array, output + complex_love_numbers_view : double complex[::1], array, output Array to store complex Love numbers. There must be space for 3 double complex numbers. - surface_solutions_view : double complex[:], array, input + surface_solutions_view : double complex[::1], array, input Array of radial solutions (y_i) values at the surface of a planet. surface_gravity : double, input Acceleration due to gravity at the planet's surface [m s-2]. diff --git a/TidalPy/RadialSolver/solver.pyx b/TidalPy/RadialSolver/solver.pyx index bdcfeaaa..69707069 100644 --- a/TidalPy/RadialSolver/solver.pyx +++ b/TidalPy/RadialSolver/solver.pyx @@ -1045,11 +1045,11 @@ cdef RadialSolverSolution cf_radial_solver( def radial_solver( - double[:] radius_array, - double[:] density_array, - double[:] gravity_array, - double[:] bulk_modulus_array, - double complex[:] complex_shear_modulus_array, + double[::1] radius_array, + double[::1] density_array, + double[::1] gravity_array, + double[::1] bulk_modulus_array, + double complex[::1] complex_shear_modulus_array, double frequency, double planet_bulk_density, tuple layer_types, diff --git a/TidalPy/rheology/base.pyx b/TidalPy/rheology/base.pyx index d1fc8f9c..8a5d8e65 100644 --- a/TidalPy/rheology/base.pyx +++ b/TidalPy/rheology/base.pyx @@ -93,10 +93,10 @@ cdef class RheologyModelBase(TidalPyBaseExtensionClass): def vectorize_frequency( self, - double[:] frequency_view, + double[::1] frequency_view, double modulus, double viscosity, - double complex[:] output_view, + double complex[::1] output_view, ): cdef Py_ssize_t n, n2 @@ -111,9 +111,9 @@ cdef class RheologyModelBase(TidalPyBaseExtensionClass): def vectorize_modulus_viscosity( self, double frequency, - double[:] modulus_view, - double[:] viscosity_view, - double complex[:] output_view, + double[::1] modulus_view, + double[::1] viscosity_view, + double complex[::1] output_view, ): cdef Py_ssize_t n, n2, n3 diff --git a/TidalPy/utilities/dimensions/nondimensional.pyx b/TidalPy/utilities/dimensions/nondimensional.pyx index 00b87da2..6a72459c 100644 --- a/TidalPy/utilities/dimensions/nondimensional.pyx +++ b/TidalPy/utilities/dimensions/nondimensional.pyx @@ -151,11 +151,11 @@ def non_dimensionalize_physicals( double frequency, double mean_radius, double bulk_density, - double[:] radius_array_view, - double[:] density_array_view, - double[:] gravity_array_view, - double[:] bulk_array_view, - double_numeric[:] shear_array_view, + double[::1] radius_array_view, + double[::1] density_array_view, + double[::1] gravity_array_view, + double[::1] bulk_array_view, + double_numeric[::1] shear_array_view, ): cdef size_t num_radius = radius_array_view.size @@ -174,11 +174,11 @@ def redimensionalize_physicals( double frequency, double mean_radius, double bulk_density, - double[:] radius_array_view, - double[:] density_array_view, - double[:] gravity_array_view, - double[:] bulk_array_view, - double_numeric[:] shear_array_view, + double[::1] radius_array_view, + double[::1] density_array_view, + double[::1] gravity_array_view, + double[::1] bulk_array_view, + double_numeric[::1] shear_array_view, ): cdef size_t num_radius = radius_array_view.size @@ -201,7 +201,7 @@ def redimensionalize_radial_functions( Parameters ---------- - radial_function_ptr : complex128* + radial_function_view : double complex[:, ::1] Non-dimensionalized radial solutions as a function of radius. mean_radius : float64 Mean radius of the planet, used in scaling [m] diff --git a/pyproject.toml b/pyproject.toml index bfe73003..233d10a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name='TidalPy' -version = '0.5.2.a1' +version = '0.5.2.a2' description='Tidal Dynamics and Thermal-Orbital Evolution Software Suite Implemented in Cython and Python' authors= [ {name = 'Joe P. Renaud', email = 'TidalPy@gmail.com'} From 013f1f640ee772497b122ca3a2e96acf89e58ed9 Mon Sep 17 00:00:00 2001 From: Jrenaud-Desk Date: Thu, 22 Feb 2024 16:39:50 -0500 Subject: [PATCH 5/5] MAINT: Updated change log and version --- CHANGES.md | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d3734b78..9ec327f4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ * Other Major Changes * Remove support for the older non-cythonized `radial_solver` module. -### Version 0.5.2 (2024-NN) +### Version 0.5.2 (2024-02-22) Documentation * Improved RadialSolver documentation regarding higher degree-l. diff --git a/pyproject.toml b/pyproject.toml index 233d10a0..ec5ea3ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name='TidalPy' -version = '0.5.2.a2' +version = '0.5.2' description='Tidal Dynamics and Thermal-Orbital Evolution Software Suite Implemented in Cython and Python' authors= [ {name = 'Joe P. Renaud', email = 'TidalPy@gmail.com'}