[SOLVED] What technologie to use for a simulation?


I have several Problems.

I want/ have to build a simulation. In which the flight bahvior of different discgolf discs should be simulated. These discs can have different shapes and properties like, thickness, weight, curvature etc and their flight path will change based on those values.
Unfortunately I do not really know what technologies/crates to use...

I need the following things:

  • A way to render the simulation. The different meshes of the discs, an environment to make it look nicer on the eyes and some UI stuff. I already looked into the Amethyst engine but that but quite overkill, although all features I need are available... (also I am concerned about performance)
  • Calculating... I think nalgebra is the way to go here.

Since I am also not sure how to actually simulate the flight, those decisions are hard to make. Which leads me to my second problem: how? I already thought about that problem but I feel stuck. What I learned to far is that in game engines or the like, drag is calculated by estimating the drag coeficient. But I would like to really simulate the real flight path. So I thought maybe a fluid simulation is the way to go. Calculating the air and discs moving in it.

You may see that I am struggeling to ultimately decide on which way to go, I hope you have some helpfull thoughts about that.

Thank you in advance

Computational Fluid Dynamics is probably not the route you want to go for performant simulation. OpenFOAM is a popular open source CFD code, if you're interested to see what that entails. Generally CFD is a very detailed and computationally expensive process which is better used to experimentally determine properties like drag coefficients, which can then be used in a simpler physics engine. The closest CFD is getting to real-time performance is the Lattice Boltzmann Method used on supercomputer GPU arrays.

It sounds like you want a rigid-body kinematic motion solver. nphysics is probably what you're after on that front. It works with nalgebra.

1 Like

If you think about it, a simulation is just a game which doesn't accept input from the user, so a game engine would provide a lot of the tools you'll need.

For the high-level architecture I'd check out something called Entity-Component-System. This is where you create a bunch of objects (entities) and attach properties to them (components), then you run a bunch of logic (systems) which will implement various parts of the simulation (collision, deformation, equations of motion, etc.).

It's a good architecture for managing your simulation's data and lets you incrementally add new mechanisms and physics... For example, say you want to introduce a system for deformation of a disk due to the difference in forces along hits length. You'd code up deformation independent of the rest of the simulation, then integrating it in is just a case of schedule the deformation system to run after unit volume pressures and velocities are calculated.

How accurate do you want your simulations to be? You can get pretty far by rolling your own simulation using newton's equations of motion and simplifications like the drag equation, and evaluating it in discrete time steps. Otherwise if you want to do more accurate simulations I'd reach for a proper simulation package like OpenFOAM or Ansys.

Yeah, that is why i looked into Amethyst. I finished the Pong-Tutorial and played around with it. I also thought about nphysics like @PFaas mentioned, but I think I need i rather accurate simulation because the discs vary in in small details (see here for more detail in disc types). That is why IMO nphysics is not accurate enough for that.

If that's the case I'd go for a professional simulation package instead of rolling my own.

Unless this is purely for educational purposes, of course. If that's the case then have at it!

If you are wanting to write your own simulation, here are some links which may provide inspiration or useful crates:

1 Like

I'm not sure I follow on what might be lacking from nphysics. For any object you can set:

  • Mass
  • Center of gravity
  • Moments of inertia
  • 6DOF motion (speeds + rotations)
  • External forces to apply

That is everything that actually applies to the accurate calculation of motion of a body. More detailed geometries can be handled by layering geometry on top of that in a separate system like ncollide and/or the rendering engine. The detailed calculation of external (aerodynamic) forces is where your real challenge lies.

Yea, I kinda make it on my own. Thank you for the links.

That is the problem since the overall form and weight of all discs is the same.

You have asked and then answered your own question there.

1 Like

Nphysics allows you to apply your own forces. That's not it lacking accuracy. That's just the nature of forces; they are highly dependent on the body and the fluid(s) it's in.

There's no reasonable way to expect there to be a pre-existing library that covers the entire spectrum from generic shaped body in a custom environment -> aerodynamic forces -> kinematic motions. Saying the kinematic motion portion of that lacks accuracy because it doesn't include the prior two steps is throwing out a hammer for it not being an entire toolbox worth of tools.

I'm not sure I said that.

I'm sure Nphysics is great at what it is designed to do, rigid-body simulation with contacts.

My feeling is that when dealing with a large object traveling through air those rigid bodies are a) The large object, b) billions of air molecules. How is Nphysics going to perform in the face of billions of objects?

You rightly point out that one could just model the large object as an Nphysics object and then apply forces to it as if from those billions of air molecules. But that just moves the problem of simulating the action of the air to code you are going to have to create and run outside of Nphysics. It is the hard part of the problem.

That's the purpose of CFD and why I brought it up first - it can be used as simulated wind tunnel testing to calculate simple lift and drag coefficients, rotational drag and moments, etc. taking into account the nuanced shapes of each disc. The results from that are then empirically derived functions of speed, angles, rotation, etc. to produce aerodynamic forces. That leaves the millions of particles/volumes to the high-performance computing realm to be run once per case, and let the simulation function on empirical and simple formulas.


Ah, OK, sounds cool. If one has access to machines capable of doing that empirical derivation.