From 922b01e7860c93e640c48cce0b70e8ec80815ad0 Mon Sep 17 00:00:00 2001 From: Charles Gannon Date: Sat, 31 Aug 2024 11:14:13 -0700 Subject: [PATCH 1/5] fix: spheroidRadiusPowerLaw fix: spheroidRadiusPowerLawConstructorInternal not being called fix: typo in power law formula radius fomula fix: changed to more reasonable default value for parameter "beta" (originally, forgot to convert unit) --- ....operators.empirical.spheroid_radius_power_law.F90 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/nodes.operators.empirical.spheroid_radius_power_law.F90 b/source/nodes.operators.empirical.spheroid_radius_power_law.F90 index 991f5a3630..bb9a1faa5e 100644 --- a/source/nodes.operators.empirical.spheroid_radius_power_law.F90 +++ b/source/nodes.operators.empirical.spheroid_radius_power_law.F90 @@ -28,7 +28,7 @@ A node operator that implements an an empirical power law relationship between spheroid stellar radius and stellar mass. - + !!] type, extends(nodeOperatorClass) :: nodeOperatorspheroidRadiusPowerLaw @@ -86,10 +86,14 @@ function spheroidRadiusPowerLawConstructorParameters(parameters) result(self) beta parameters Coefficient $\beta$ in the power law fit. - 1.19d-6 + 1.19d-9 \cite[][table J1: Parameter $b$, for early type galaxies and re-scaled from half light radius to Hernquist radius \protect\citep{hernquist_analytical_1990}---Note: there was a typo in the originally provided value, see \protect\cite{shen_erratum_2007} for the corrected value]{shen_size_2003} !!] + self=spheroidRadiusPowerLawConstructorInternal(alpha, beta) + !![ + + !!] end function spheroidRadiusPowerLawConstructorParameters function spheroidRadiusPowerLawConstructorInternal(alpha, beta) result(self) @@ -102,7 +106,6 @@ function spheroidRadiusPowerLawConstructorInternal(alpha, beta) result(self) !![ !!] - return end function spheroidRadiusPowerLawConstructorInternal @@ -120,7 +123,7 @@ subroutine spheroidRadiusPowerLawUpdate(self, node) if (.not.node%isOnMainBranch()) return spheroid => node %spheroid () radiusStellar = +self %beta & - & +spheroid%massStellar()**self%alpha + & *spheroid%massStellar()**self%alpha call spheroid%radiusSet(radiusStellar) return end subroutine spheroidRadiusPowerLawUpdate From 8caebcb8fa96332fbb1be362b06928506ecf1043 Mon Sep 17 00:00:00 2001 From: Charles Gannon Date: Sat, 31 Aug 2024 11:20:33 -0700 Subject: [PATCH 2/5] feat: added tests for spheroidRadiusPowerLaw node Operator --- .../parameters/test-spheroid-power-law.xml | 168 ++++++++++++++++++ testSuite/test-spheroid-power-law.py | 58 ++++++ 2 files changed, 226 insertions(+) create mode 100644 testSuite/parameters/test-spheroid-power-law.xml create mode 100755 testSuite/test-spheroid-power-law.py diff --git a/testSuite/parameters/test-spheroid-power-law.xml b/testSuite/parameters/test-spheroid-power-law.xml new file mode 100644 index 0000000000..337acd0772 --- /dev/null +++ b/testSuite/parameters/test-spheroid-power-law.xml @@ -0,0 +1,168 @@ + + + + 2 + 0.9.4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/testSuite/test-spheroid-power-law.py b/testSuite/test-spheroid-power-law.py new file mode 100755 index 0000000000..12e51d689f --- /dev/null +++ b/testSuite/test-spheroid-power-law.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +import subprocess +import os +import sys +import h5py +import numpy as np +import xml.etree.ElementTree as ET + +# Check UniverseMachine results. +# Charles Gannon (26-August-2024) +path_in_param = os.path.abspath(f"parameters/test-spheroid-power-law.xml" ) +path_out_dir = os.path.abspath(f"outputs/test-spheroid-power-law" ) +path_out_log = os.path.abspath(f"outputs/test-spheroid-power-law/test-spheroid-power-law.log" ) +path_out_hdf = os.path.abspath(f"outputs/test-spheroid-power-law/test-spheroid-power-law.hdf5" ) + +status = subprocess.run(f"mkdir -p {path_out_dir}",shell=True) + +# Run the model and check for completion +print("Running model...") + +log = open(path_out_log,"w") +status = subprocess.run(f"cd ..; ./Galacticus.exe {path_in_param}",stdout=log,stderr=log,shell=True) +log.close() + +print("...done ("+str(status)+")") + +if status.returncode != 0: + print("FAILED: model run:") + subprocess.run(f"cat {path_out_log}",shell=True) + sys.exit() +print("Checking for errors...") +status = subprocess.run(f"grep -q -i -e fatal -e aborted -e \"Galacticus experienced an error in the GSL library\" {path_out_log}",shell=True) +print("...done ("+str(status)+")") +if status.returncode == 0: + print("FAILED: model run (errors):") + subprocess.run(f"cat {path_out_log}",shell=True) + sys.exit() +print("SUCCESS: model run") + +# Open the model and extract the recycled fraction. +model = h5py.File(path_out_hdf,'r') +massStellar = model["Outputs/Output1/nodeData/spheroidMassStellar" ][:] +radiusStellar = model["Outputs/Output1/nodeData/spheroidRadius" ] +isIsolated = model["Outputs/Output1/nodeData/nodeIsIsolated" ][:].astype(bool) + +massStellarHost, radiusStellarHost = massStellar[isIsolated], radiusStellar[isIsolated] + +alpha = 0.56 +beta = 1.19E-9 + +radiusStellarHostPython = ( + +beta + *massStellarHost**alpha + ) +if np.allclose(np.log10(radiusStellarHost), np.log10(radiusStellarHostPython), rtol=1e-6): + print(f"SUCCESS: results do agree" ) +else: + print(f"FAILED: results do not agree") From ea631cbe486a85f67c13bcfc742af1a608d107ed Mon Sep 17 00:00:00 2001 From: Charles Gannon Date: Sat, 31 Aug 2024 14:41:53 -0700 Subject: [PATCH 3/5] fix: formatting --- testSuite/parameters/test-spheroid-power-law.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testSuite/parameters/test-spheroid-power-law.xml b/testSuite/parameters/test-spheroid-power-law.xml index 337acd0772..bcda1e4880 100644 --- a/testSuite/parameters/test-spheroid-power-law.xml +++ b/testSuite/parameters/test-spheroid-power-law.xml @@ -159,10 +159,10 @@ - - - - + + + + From c07aa19f1253a78616cd6f0c52334498db11987d Mon Sep 17 00:00:00 2001 From: Charles Gannon Date: Sat, 31 Aug 2024 16:32:28 -0700 Subject: [PATCH 4/5] fix: formatting --- ...rs.empirical.spheroid_radius_power_law.F90 | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source/nodes.operators.empirical.spheroid_radius_power_law.F90 b/source/nodes.operators.empirical.spheroid_radius_power_law.F90 index bb9a1faa5e..8d8f1b2e91 100644 --- a/source/nodes.operators.empirical.spheroid_radius_power_law.F90 +++ b/source/nodes.operators.empirical.spheroid_radius_power_law.F90 @@ -25,13 +25,13 @@ !!} !![ - + A node operator that implements an an empirical power law relationship between spheroid stellar radius and stellar mass. !!] - type, extends(nodeOperatorClass) :: nodeOperatorspheroidRadiusPowerLaw + type, extends(nodeOperatorClass) :: nodeOperatorSpheroidRadiusPowerLaw !!{ Implements a power law prescription for the stellar mass--stellar radius relation of spheroids. Specificially: \begin{equation} @@ -52,15 +52,15 @@ procedure :: nodeInitialize => spheroidRadiusPowerLawNodeInitialize procedure :: differentialEvolutionSolveAnalytics => spheroidRadiusPowerLawSolveAnalytics procedure :: nodesMerge => spheroidRadiusPowerLawNodesMerge - end type nodeOperatorspheroidRadiusPowerLaw + end type nodeOperatorSpheroidRadiusPowerLaw - interface nodeOperatorspheroidRadiusPowerLaw + interface nodeOperatorSpheroidRadiusPowerLaw !!{ Constructors for the {\normalfont \ttfamily spheroidRadiusPowerLaw} node operator class. !!} module procedure spheroidRadiusPowerLawConstructorParameters module procedure spheroidRadiusPowerLawConstructorInternal - end interface nodeOperatorspheroidRadiusPowerLaw + end interface nodeOperatorSpheroidRadiusPowerLaw contains @@ -70,7 +70,7 @@ function spheroidRadiusPowerLawConstructorParameters(parameters) result(self) !!} use :: Input_Parameters, only : inputParameters implicit none - type (nodeOperatorspheroidRadiusPowerLaw) :: self + type (nodeOperatorSpheroidRadiusPowerLaw) :: self type (inputParameters ), intent(inout) :: parameters double precision :: alpha , beta @@ -101,7 +101,7 @@ function spheroidRadiusPowerLawConstructorInternal(alpha, beta) result(self) Internal constructor for the {\normalfont \ttfamily spheroidRadiusPowerLaw} node operator class. !!} implicit none - type (nodeOperatorspheroidRadiusPowerLaw) :: self + type (nodeOperatorSpheroidRadiusPowerLaw) :: self double precision , intent(in) :: alpha, beta !![ @@ -115,7 +115,7 @@ subroutine spheroidRadiusPowerLawUpdate(self, node) !!} use :: Galacticus_Nodes, only : nodeComponentSpheroid implicit none - class (nodeOperatorspheroidRadiusPowerLaw), intent(inout) :: self + class (nodeOperatorSpheroidRadiusPowerLaw), intent(inout) :: self type (treeNode ), intent(inout) :: node class (nodeComponentSpheroid ), pointer :: spheroid double precision :: radiusStellar @@ -134,7 +134,7 @@ subroutine spheroidRadiusPowerLawNodeInitialize(self,node) !!} use :: Galacticus_Nodes, only : nodeComponentSpheroid implicit none - class(nodeOperatorspheroidRadiusPowerLaw), intent(inout), target :: self + class(nodeOperatorSpheroidRadiusPowerLaw), intent(inout), target :: self type (treeNode ), intent(inout), target :: node class (nodeComponentSpheroid ), pointer :: spheroid @@ -150,7 +150,7 @@ subroutine spheroidRadiusPowerLawSolveAnalytics(self,node,time) Set the radius of the spheroid. !!} implicit none - class (nodeOperatorspheroidRadiusPowerLaw), intent(inout) :: self + class (nodeOperatorSpheroidRadiusPowerLaw), intent(inout) :: self type (treeNode ), intent(inout) :: node double precision , intent(in ) :: time !$GLC attributes unused :: time @@ -164,7 +164,7 @@ subroutine spheroidRadiusPowerLawNodesMerge(self,node) Update the radius of the spheroid after a merger. !!} implicit none - class(nodeOperatorspheroidRadiusPowerLaw), intent(inout) :: self + class(nodeOperatorSpheroidRadiusPowerLaw), intent(inout) :: self type (treeNode ), intent(inout) :: node call self%update(node) From 6815728bc9c67964b3e8ecc02f19c5a80cee971a Mon Sep 17 00:00:00 2001 From: Charles Gannon Date: Sat, 31 Aug 2024 16:48:05 -0700 Subject: [PATCH 5/5] fix: comment in tests --- testSuite/test-spheroid-power-law.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testSuite/test-spheroid-power-law.py b/testSuite/test-spheroid-power-law.py index 12e51d689f..166aca40b2 100755 --- a/testSuite/test-spheroid-power-law.py +++ b/testSuite/test-spheroid-power-law.py @@ -6,8 +6,8 @@ import numpy as np import xml.etree.ElementTree as ET -# Check UniverseMachine results. -# Charles Gannon (26-August-2024) +# Test spheroidRadiusPowerLaw nodeOperator. +# Charles Gannon (31-August-2024) path_in_param = os.path.abspath(f"parameters/test-spheroid-power-law.xml" ) path_out_dir = os.path.abspath(f"outputs/test-spheroid-power-law" ) path_out_log = os.path.abspath(f"outputs/test-spheroid-power-law/test-spheroid-power-law.log" )