I’m working on creating a web application to simulate piping systems, where you can place pipes precisely and track the fluid flow theoretically (using thermodynamic calculations), including pressure losses, etc. However, as I started coding this feature, I wondered if there’s an existing architecture that could handle elements like branches, separations, bends, elevations, descents, and so on.
So far, I’ve come up with this structure to represent my pipes:
pipe = {
from: {
position: [0.25, 1.25, 0],
connected: false
},
to: {
position: [5, 1.25, 0],
connected: false
},
id: 2164514,
stage: -4
};
But I feel like this setup could quickly become overly complex.
Do you have any suggestions or ideas for an architecture that would be more suitable for this type of simulation?
What I’ve tried so far is creating a structure where each pipe has a from and to position, along with an ID and other details. I hoped this would be a flexible way to represent different pipe segments and their connections, allowing for easy modifications and extensions to handle things like branches, bends, and other features.
However, I’m finding that this approach might quickly get overly complicated, especially when dealing with more complex networks involving separations, multiple branches, or different elevations. I was expecting the structure to be scalable, but it seems like it could become difficult to manage and maintain as the system grows.
hichem moumni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
An Object Orientated approach would work, where Pipes are defined as classes/objects. You can define the properties you need in a pipe, such as it’s length, diameter, etc.
You can then define logic, probably a couple of types of logic: logic to help manage how pipes can be assembled, and another for performing the simulations.
I would focus on the logic you need to perform first, and use this to guide your class/object design; I would worry about data structures (for persisting the data) later.
Are you familiar with Design Patterns? If not, you may find one or several that help you in aspects of your project. I’m not thinking of a specific one for you right now, but some of the structural and behavioral pattern may be of use to you at some point.
A way to test your object and logic design is to come up with a list of functional scenarios, and use each of them to “test” your design – at the initial stages your first tests might be on a whiteboard – to see if an idea is then worth prototyping in code.
Have you built a web application before? How long do you think this system will be in operation for and who will maintain it? (I’m wondering how much engineering and architecture to put into this, like is this for a personal hobby project or a ‘serious’ professional product?).
One random thought – if you are trying to simulate behavior, maybe focus on using relative values rather than absolute ones e.g. variables like pipe length rather that start/end coordinates; as it’s easier to add pipe lengths together than workout distances between coordinates.