Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get information about binaries in PeTar #1052

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions src/amuse/community/petar/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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
Expand Down
13 changes: 12 additions & 1 deletion src/amuse/community/petar/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = 1 + ptr->getParticleAdrFromID(index_of_the_particle);
FPSoft* p = &(ptr->system_soft[index]);
//*binary_companion = ptr->getParticleIDFromAdr(p->getBinaryPairID());
*binary_companion = p->getBinaryPairID() - 1;
return 0;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs to work with multiple workers, similar to other getters.

int get_position(int index_of_the_particle,
double * x, double * y, double * z) {
reconstruct_particle_list();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/amuse/community/petar/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 25 additions & 1 deletion src/amuse/community/petar/interface.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -83,6 +88,13 @@ def set_theta():
"""
return function

@remote_function(can_handle_array=True)
def get_binary_companion(index_of_the_particle='i'):
"""
Returns the binary companion of a particle, or -1 if no such companion exists
"""
returns (binary_companion='i')

#@legacy_function
#def get_gravitational_constant():
# """
Expand Down Expand Up @@ -573,6 +585,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",
(
Expand Down Expand Up @@ -614,6 +637,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
Expand Down
Loading