Skip to content

potential_energy analysis function limited to built-in potential types #44

@jrdegreeff

Description

@jrdegreeff

function potential_energy(coordinates, simulation::NBodySimulation)
e_potential = 0
system = simulation.system
n = length(system.bodies)
if :lennard_jones keys(system.potentials)
p = system.potentials[:lennard_jones]
(ms, indxs) = obtain_data_for_lennard_jones_interaction(system)
e_potential += lennard_jones_potential(p, indxs, coordinates, simulation.boundary_conditions)
end
if :electrostatic keys(system.potentials)
p = system.potentials[:electrostatic]
(qs, ms, indxs, exclude) = obtain_data_for_electrostatic_interaction(simulation.system)
e_potential += electrostatic_potential(p, indxs, exclude, qs, coordinates, simulation.boundary_conditions)
end
e_potential
end

The current implementation for calculating the potential energy of the system is hardcoded to only recognize a couple of built-in potential functions. NBS supports adding custom potentials for the simulation, but they can't be included in analysis of the energies afterwards. Could this be extended to custom potentials through dynamic dispatch?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions