this post was submitted on 17 Nov 2025
39 points (97.6% liked)

Ask Science

13565 readers
17 users here now

Ask a science question, get a science answer.


Community Rules


Rule 1: Be respectful and inclusive.Treat others with respect, and maintain a positive atmosphere.


Rule 2: No harassment, hate speech, bigotry, or trolling.Avoid any form of harassment, hate speech, bigotry, or offensive behavior.


Rule 3: Engage in constructive discussions.Contribute to meaningful and constructive discussions that enhance scientific understanding.


Rule 4: No AI-generated answers.Strictly prohibit the use of AI-generated answers. Providing answers generated by AI systems is not allowed and may result in a ban.


Rule 5: Follow guidelines and moderators' instructions.Adhere to community guidelines and comply with instructions given by moderators.


Rule 6: Use appropriate language and tone.Communicate using suitable language and maintain a professional and respectful tone.


Rule 7: Report violations.Report any violations of the community rules to the moderators for appropriate action.


Rule 8: Foster a continuous learning environment.Encourage a continuous learning environment where members can share knowledge and engage in scientific discussions.


Rule 9: Source required for answers.Provide credible sources for answers. Failure to include a source may result in the removal of the answer to ensure information reliability.


By adhering to these rules, we create a welcoming and informative environment where science-related questions receive accurate and credible answers. Thank you for your cooperation in making the Ask Science community a valuable resource for scientific knowledge.

We retain the discretion to modify the rules as we deem necessary.


founded 2 years ago
MODERATORS
 

I’m currently learning Python, but in the meantime I still want to try a simple simulation of my ideas. I just need a program that lets me create particles and forces with whatever properties and interactions I want that I can then simulate. For example, I might make a particle that attracts certain particles and repels others according to some equation. I already tried asking in softwareoptions, by the way

top 9 comments
sorted by: hot top controversial new old
[–] potatoguy@lemmy.eco.br 16 points 2 days ago

Oh yeah, someone finally asked something about my field.

So, maybe COMSOL is what you're looking for, but if you want the cool, smooth and amazing stuff of the pros:

Time to learn numerical calculus, like verlet integration, maybe some calculus for turning potential fields into force (maybe some forward differentiation with dual numbers, just like sympy does hahaha, you can use that too). If it's a hairy equation, that takes some hypergeometric, bessel, etc, scipy has all the special equations.

I think verlet + sympy for turning the potential fields into the force fields at the particle spots will do amazing, if you don't want paper ready simulations. Like, pos[n, 3], v[n, 3], a[n, 3] (maybe some torque if you want) would be almost all you need.

For visualization, matplotlib has a lot of stuff, you can make animations and videos.

If you want to simulate the fields itself, you can use finite differences or finite element methods.

If you need a lot of performance, I recommend learning Julia or the GODLY Fortran 2008 (fprettify, fortls, gfortran will help to build a modern Fortran program that you can call from python using cdll and ctypes with the ieee c libs for fortran).

[–] Danitos@reddthat.com 4 points 2 days ago

For advanced stuff, you have Geant4. Fully open source software developed by the CERN and collaborators. It has a steep learning curve, but the feeling of simulating advanced physics (and somewhat underestading them) is amazing.

[–] HootinNHollerin@lemmy.dbzer0.com 4 points 2 days ago* (last edited 2 days ago) (1 children)

At a past job a physicist on my team used a free code that was developed at CERN for radiation simulations. Can’t recall what it was called but look into open stuff they’ve developed

[–] Danitos@reddthat.com 3 points 2 days ago (1 children)

Yes that sounds familiar

[–] nooneescapesthelaw@mander.xyz 2 points 2 days ago (1 children)

Could you elaborate on what you want to make? If it's lots of particles (thousands) then look into DEM software like ansys rocky or LIGGGHTS

[–] fourhazzy@lemmy.world 1 points 1 day ago

I basically just want to use some point particles that I already have equations for interaction for. They're kind of like the elemental particles of our universe, just with different properties. I'd also want to have more general forces like, for example, an equivalent to gravity. What I want to do is just start a "universe" with these particles and forces and some starting conditions and see what emerges.

[–] Gust@piefed.social 2 points 2 days ago

A lot of people already mentioned it but geant4 is the gold standard for that kind of simulation. It could also be worth looking into pythia if you're interested in simulating high energy events with geant4

[–] potatoguy@lemmy.eco.br 2 points 2 days ago* (last edited 2 days ago)

Edit: Corrected the integration

This is a simulation I made for a ball falling (the principles can be used everywhere):

import numpy as np
import matplotlib.pyplot as plt


def calc_acceleration(pos, v):
    return np.array([0, 0, -9.8])


def integrate(pos, v, a_old, delta_t):
    pos_new = pos + v * delta_t + 0.5 * a_old * delta_t * delta_t

    a_new = calc_acceleration(pos_new, v)

    v_new = v + 0.5 * (a_old + a_new) * delta_t

    if pos_new[2] < 0.0:
        v_new[2] = -v_new[2]

    return pos_new, v_new, a_new


# Constants
delta_t = 0.01
t_max = 10

# Time evolution
times: np.ndarray = np.arange(0, t_max, delta_t)

# Initial state
v = np.array([15.0, -3.0, 15.0])
pos = np.array([0.0, 0.0, 7.0])
positions = np.zeros([times.size, 3])
a_old = calc_acceleration(pos, v)

# Simulating
for i in range(times.size):
    pos, v, a_old = integrate(pos, v, a_old, delta_t)
    positions[i, :] = pos

# Plotting
fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.scatter(positions[:, 0], positions[:, 1], positions[:, 2])
plt.show()

Very simple, you can see a ball falling and getting up again from that starting point, so you just see at least some starting point on how to do this stuff, the basics are not that difficult. But every simulation is like this, just more complicated hahaha.