From 8a8e81933885ee691b3c5393ffd5de53959af066 Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Mon, 29 Apr 2024 13:30:28 -0400 Subject: [PATCH 1/5] Add binary detection function and required flag --- src/amuse/community/petar/Makefile | 3 ++- src/amuse/community/petar/interface.cc | 11 ++++++++++ src/amuse/community/petar/interface.py | 29 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/amuse/community/petar/Makefile b/src/amuse/community/petar/Makefile index 44445b8d3c..dff0a5f53a 100644 --- a/src/amuse/community/petar/Makefile +++ b/src/amuse/community/petar/Makefile @@ -26,13 +26,14 @@ CXXFLAGS += -D MPICH_IGNORE_CXX_SEEKC CXXFLAGS += -D SOFT_PERT -D AR_TTL -D AR_SLOWDOWN_TREE -D AR_SLOWDOWN_TIMESCALE -D CLUSTER_VELOCITY CXXFLAGS += -D USE_QUAD CXXFLAGS += -D STELLAR_EVOLUTION +CXXFLAGS += -D ADJUST_GROUP_PRINT CXXFLAGS += -D PROFILE CXXFLAGS += -D HARD_CHECK_ENERGY CXXFLAGS += -D TIDAL_TENSOR_3RD # debug -#CXXFLAGS += -D PETAR_DEBUG -D AR_DEBUG -D AR_DEBUG_DUMP -D AR_WARN -D HARD_DEBUG -D HARD_DUMP -D CLUSTER_DEBUG -D ARTIFICIAL_PARTICLE_DEBUG +CXXFLAGS += -D PETAR_DEBUG -D AR_DEBUG -D AR_DEBUG_DUMP -D AR_WARN -D HARD_DEBUG -D HARD_DUMP -D CLUSTER_DEBUG -D ARTIFICIAL_PARTICLE_DEBUG CXXFLAGS += -D INTERFACE_DEBUG_PRINT CXXFLAGS += -D INTERFACE_DEBUG diff --git a/src/amuse/community/petar/interface.cc b/src/amuse/community/petar/interface.cc index 2c1ed6796a..b221c05ab0 100644 --- a/src/amuse/community/petar/interface.cc +++ b/src/amuse/community/petar/interface.cc @@ -106,6 +106,7 @@ extern "C" { ptr->input_parameters.update_changeover_flag = true; ptr->input_parameters.update_rsearch_flag = true; ptr->initialParameters(); + ptr->hard_manager.h4_manager.adjust_group_write_flag = true; ptr->initial_step_flag = false; // set stopping condtions support @@ -389,6 +390,15 @@ extern "C" { return 0; } + int get_binary_companion(int index_of_the_particle, int * binary_companion){ + reconstruct_particle_list(); + int index = ptr->getParticleAdrFromID(index_of_the_particle); + FPSoft* p = &(ptr->system_soft[index]); + //*binary_companion = ptr->getParticleIDFromAdr(p->getBinaryPairID()); + *binary_companion = p->getBinaryPairID(); + return 0; + } + int get_position(int index_of_the_particle, double * x, double * y, double * z) { reconstruct_particle_list(); @@ -737,6 +747,7 @@ extern "C" { if (!ptr->read_data_flag) return -1; ptr->input_parameters.n_glb.value = ptr->stat.n_real_glb; ptr->initialParameters(); + ptr->hard_manager.h4_manager.adjust_group_write_flag = true; ptr->initialStep(); ptr->reconstructIdAdrMap(); particle_list_change_flag = false; diff --git a/src/amuse/community/petar/interface.py b/src/amuse/community/petar/interface.py index 977cb7e3cd..40d4028fac 100644 --- a/src/amuse/community/petar/interface.py +++ b/src/amuse/community/petar/interface.py @@ -83,6 +83,35 @@ def set_theta(): """ return function + @legacy_function + def get_binary_companion(): + """ + Get the binary state of a particle + """ + function = LegacyFunctionSpecification() + function.addParameter( + 'index_of_the_particle', dtype='int32', direction=function.IN, + description=( + "Index of the particle to get the state from. This index must " + "have been returned by an earlier call to :meth:`new_particle`" + ) + ) + function.addParameter( + 'binary_companion', dtype='int32', direction=function.OUT, + description="The companion star, if the star is in a binary" + ) + function.result_type = 'int32' + function.can_handle_array = True + function.result_doc = """ + 0 - OK + current value was retrieved + -1 - ERROR + particle could not be found + -2 - ERROR + not yet implemented + """ + return function + #@legacy_function #def get_gravitational_constant(): # """ From c695c798569a9f6addf4de1d7dc6ed771c09d14b Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Fri, 3 May 2024 13:22:11 -0400 Subject: [PATCH 2/5] make "binary_companion" available as a particle attribute --- src/amuse/community/petar/interface.cc | 6 +++--- src/amuse/community/petar/interface.h | 2 ++ src/amuse/community/petar/interface.py | 12 ++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/amuse/community/petar/interface.cc b/src/amuse/community/petar/interface.cc index b221c05ab0..cada513a17 100644 --- a/src/amuse/community/petar/interface.cc +++ b/src/amuse/community/petar/interface.cc @@ -49,7 +49,7 @@ extern "C" { // set print flag to rank 0 ptr->input_parameters.print_flag = (ptr->my_rank==0) ? true: false; // set writing flag to false - ptr->input_parameters.write_style.value = 0; + ptr->input_parameters.write_style.value = 3; // default input int flag= ptr->readParameters(argc,argv); @@ -392,10 +392,10 @@ extern "C" { int get_binary_companion(int index_of_the_particle, int * binary_companion){ reconstruct_particle_list(); - int index = ptr->getParticleAdrFromID(index_of_the_particle); + int index = 1 + ptr->getParticleAdrFromID(index_of_the_particle); FPSoft* p = &(ptr->system_soft[index]); //*binary_companion = ptr->getParticleIDFromAdr(p->getBinaryPairID()); - *binary_companion = p->getBinaryPairID(); + *binary_companion = p->getBinaryPairID() - 1; return 0; } diff --git a/src/amuse/community/petar/interface.h b/src/amuse/community/petar/interface.h index d7e8890e04..95714d220c 100644 --- a/src/amuse/community/petar/interface.h +++ b/src/amuse/community/petar/interface.h @@ -31,6 +31,8 @@ int get_radius(int index_of_the_particle, double * radius); int set_radius(int index_of_the_particle, double radius); +int get_binary_companion(int index_of_the_particle, int * binary_companion); + int get_position(int index_of_the_particle, double * x, double * y, double * z); int set_position(int index_of_the_particle, double x, double y, double z); diff --git a/src/amuse/community/petar/interface.py b/src/amuse/community/petar/interface.py index 40d4028fac..8299966e35 100644 --- a/src/amuse/community/petar/interface.py +++ b/src/amuse/community/petar/interface.py @@ -602,6 +602,17 @@ def define_methods(self, handler): ) ) + handler.add_method( + "get_binary_companion", + ( + handler.NO_UNIT, + ), + ( + handler.NO_UNIT, + handler.ERROR_CODE, + ) + ) + handler.add_method( "set_tree_step", ( @@ -643,6 +654,7 @@ def define_methods(self, handler): def define_particle_sets(self, handler): GravitationalDynamics.define_particle_sets(self, handler) self.stopping_conditions.define_particle_set(handler) + handler.add_getter('particles', 'get_binary_companion') PetarInterface = petarInterface From 2aecdca1564a6c8f97335c3445b37ad2fedbda52 Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Fri, 3 May 2024 19:36:38 +0200 Subject: [PATCH 3/5] Update Makefile --- src/amuse/community/petar/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/amuse/community/petar/Makefile b/src/amuse/community/petar/Makefile index dff0a5f53a..7547ea51d6 100644 --- a/src/amuse/community/petar/Makefile +++ b/src/amuse/community/petar/Makefile @@ -33,7 +33,7 @@ CXXFLAGS += -D HARD_CHECK_ENERGY CXXFLAGS += -D TIDAL_TENSOR_3RD # debug -CXXFLAGS += -D PETAR_DEBUG -D AR_DEBUG -D AR_DEBUG_DUMP -D AR_WARN -D HARD_DEBUG -D HARD_DUMP -D CLUSTER_DEBUG -D ARTIFICIAL_PARTICLE_DEBUG +# CXXFLAGS += -D PETAR_DEBUG -D AR_DEBUG -D AR_DEBUG_DUMP -D AR_WARN -D HARD_DEBUG -D HARD_DUMP -D CLUSTER_DEBUG -D ARTIFICIAL_PARTICLE_DEBUG CXXFLAGS += -D INTERFACE_DEBUG_PRINT CXXFLAGS += -D INTERFACE_DEBUG From a727fcdea2c4138e12a08765a86c4dee4c3b294c Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Fri, 3 May 2024 19:37:00 +0200 Subject: [PATCH 4/5] Update Makefile --- src/amuse/community/petar/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/amuse/community/petar/Makefile b/src/amuse/community/petar/Makefile index 7547ea51d6..ce9e666bda 100644 --- a/src/amuse/community/petar/Makefile +++ b/src/amuse/community/petar/Makefile @@ -33,7 +33,7 @@ CXXFLAGS += -D HARD_CHECK_ENERGY CXXFLAGS += -D TIDAL_TENSOR_3RD # debug -# CXXFLAGS += -D PETAR_DEBUG -D AR_DEBUG -D AR_DEBUG_DUMP -D AR_WARN -D HARD_DEBUG -D HARD_DUMP -D CLUSTER_DEBUG -D ARTIFICIAL_PARTICLE_DEBUG +#CXXFLAGS += -D PETAR_DEBUG -D AR_DEBUG -D AR_DEBUG_DUMP -D AR_WARN -D HARD_DEBUG -D HARD_DUMP -D CLUSTER_DEBUG -D ARTIFICIAL_PARTICLE_DEBUG CXXFLAGS += -D INTERFACE_DEBUG_PRINT CXXFLAGS += -D INTERFACE_DEBUG From cef5575be97b6dbd51181c6001507b8d81ad4977 Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Fri, 3 May 2024 14:20:30 -0400 Subject: [PATCH 5/5] simplify interface with remote_function --- src/amuse/community/petar/interface.py | 37 +++++++------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/amuse/community/petar/interface.py b/src/amuse/community/petar/interface.py index 8299966e35..6a71b7fe20 100644 --- a/src/amuse/community/petar/interface.py +++ b/src/amuse/community/petar/interface.py @@ -1,4 +1,9 @@ -from amuse.rfi.core import legacy_function, LegacyFunctionSpecification +""" +Interface for PeTar +""" +from amuse.rfi.core import ( + legacy_function, LegacyFunctionSpecification, remote_function +) from amuse.community import ( CodeInterface, LiteratureReferencesMixIn, @@ -83,34 +88,12 @@ def set_theta(): """ return function - @legacy_function - def get_binary_companion(): + @remote_function(can_handle_array=True) + def get_binary_companion(index_of_the_particle='i'): """ - Get the binary state of a particle + Returns the binary companion of a particle, or -1 if no such companion exists """ - function = LegacyFunctionSpecification() - function.addParameter( - 'index_of_the_particle', dtype='int32', direction=function.IN, - description=( - "Index of the particle to get the state from. This index must " - "have been returned by an earlier call to :meth:`new_particle`" - ) - ) - function.addParameter( - 'binary_companion', dtype='int32', direction=function.OUT, - description="The companion star, if the star is in a binary" - ) - function.result_type = 'int32' - function.can_handle_array = True - function.result_doc = """ - 0 - OK - current value was retrieved - -1 - ERROR - particle could not be found - -2 - ERROR - not yet implemented - """ - return function + returns (binary_companion='i') #@legacy_function #def get_gravitational_constant():