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

Work to enable interfaces with different-than-standard index lengths #1080

Draft
wants to merge 4 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
23 changes: 23 additions & 0 deletions src/amuse/community/interface/gd/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from amuse.support.interface import InCodeComponentImplementation
from amuse.units import nbody_system
from amuse.units import generic_unit_converter
from amuse.community.interface import common

from amuse.rfi.core import legacy_function
from amuse.rfi.core import LegacyFunctionSpecification

from .gravitational_dynamics import (
GravitationalDynamicsInterface,
GravitationalDynamicsDocumentation,
GravitationalDynamics,
)
from .gravity_field import (
SinglePointGravityFieldInterface,
GravityFieldInterface,
GravityFieldCode,
)
from .gravitational_dynamics_64 import (
GravitationalDynamics64Interface,
GravitationalDynamics64Documentation,
GravitationalDynamics64,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
Stellar Dynamics Interface Definition
"""

from amuse.support.interface import InCodeComponentImplementation
from amuse.units import nbody_system
from amuse.units import generic_unit_converter
from amuse.community.interface import common

from amuse.rfi.core import legacy_function
Expand Down Expand Up @@ -1132,104 +1130,6 @@ def get_index_of_next_particle():
return function


class GravityFieldInterface:
"""
Codes implementing the gravity field interface provide functions to
calculate the force and potential energy fields at any point.
"""

@legacy_function
def get_gravity_at_point():
"""
Get the gravitational acceleration at the given points. To calculate
the force on bodies at those points, multiply with the mass of the
bodies
"""
function = LegacyFunctionSpecification()
for x in ["eps", "x", "y", "z"]:
function.addParameter(
x, dtype="float64", direction=function.IN, unit=nbody_system.length
)
for x in ["ax", "ay", "az"]:
function.addParameter(
x,
dtype="float64",
direction=function.OUT,
unit=nbody_system.acceleration,
)
function.addParameter("npoints", dtype="i", direction=function.LENGTH)
function.result_type = "int32"
function.must_handle_array = True
return function

@legacy_function
def get_potential_at_point():
"""
Determine the gravitational potential on any given point
"""
function = LegacyFunctionSpecification()
for x in ["eps", "x", "y", "z"]:
function.addParameter(
x, dtype="float64", direction=function.IN, unit=nbody_system.length
)
for x in ["phi"]:
function.addParameter(
x, dtype="float64", direction=function.OUT, unit=nbody_system.potential
)
function.addParameter("npoints", dtype="i", direction=function.LENGTH)
function.result_type = "int32"
function.must_handle_array = True
return function


class SinglePointGravityFieldInterface:
"""
Codes implementing the gravity field interface provide functions to
calculate the force and potential energy fields at any point.
"""

@legacy_function
def get_gravity_at_point():
"""
Get the gravitational acceleration at the given points. To calculate
the force on bodies at those points, multiply with the mass of the
bodies
"""
function = LegacyFunctionSpecification()
for x in ["eps", "x", "y", "z"]:
function.addParameter(
x, dtype="float64", direction=function.IN, unit=nbody_system.length
)
for x in ["ax", "ay", "az"]:
function.addParameter(
x,
dtype="float64",
direction=function.OUT,
unit=nbody_system.acceleration,
)
function.result_type = "int32"
function.can_handle_array = True
return function

@legacy_function
def get_potential_at_point():
"""
Determine the gravitational potential on any given point
"""
function = LegacyFunctionSpecification()
for x in ["eps", "x", "y", "z"]:
function.addParameter(
x, dtype="float64", direction=function.IN, unit=nbody_system.length
)
for x in ["phi"]:
function.addParameter(
x, dtype="float64", direction=function.OUT, unit=nbody_system.potential
)
function.result_type = "int32"
function.can_handle_array = True
return function


class GravitationalDynamicsDocumentation:

def __get__(self, instance, owner):
Expand Down Expand Up @@ -1610,10 +1510,3 @@ def reset(self):

def get_total_energy(self):
return self.get_potential_energy() + self.get_kinetic_energy()


class GravityFieldCode:

def define_state(self, handler):
handler.add_method("RUN", "get_gravity_at_point")
handler.add_method("RUN", "get_potential_at_point")
Loading
Loading