Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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
41 changes: 41 additions & 0 deletions src/amuse/community/petar/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
# """
Expand Down Expand Up @@ -573,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",
(
Expand Down Expand Up @@ -614,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
Expand Down