Non-traditional use of KiCad for water treatment system design and simulation

I would have posted this as a reply to " Schematics for other purpose than PCB and simulation" but that thread has been closed. I’m working on using KiCad to help design and simulate the plumbing system in my home.

I’m renovating my home and am adding whole house reverse osmosis and am replacing my gas water heater with an indirect (i.e. heat exchanger based) water heating system as well as hot water recirculation to get “instant on” hot water. I looked at several PI&D design software packages but really didn’t find something I that was low cost/free, seemed easy to use, and supported hydraulic simulation of my design. So I’ve ventured down the path of using KiCad to capture my design and linking it to a surprisingly good (and free) hydraulic system simulator developed by the, wait for it…, U.S. Environmental Protection Agency, called “EPANet”.

EPANet was developed to support municipal and regional water distribution systems but seems to work quite well for home water distribution networks as well. Things like pressure boosting pumps, cisterns, filters, piping systems, mixing valves, etc., pressure drops due to flow rate and elevation changes can all be modeled. Both static (analogous to “DC” simulations in Spice) and dynamic (i.e. valves turning on and off) behavior can be simulated. The piping models are non-linear (i.e. they work for both laminar and turbulent flow) and the simulations are fast.

What I’ve done so far with this is to create a few dozen Kicad symbols for the types of components I use (e.g. valves, storage tanks, filters, pressure booster pumps, PEX piping, etc.) as well as some sensors (e.g. pressure and temperature, TDS (total dissolved solids)). and begun capturing my design. I use hierarchical sheets quite a lot mainly to keep each page of the drawing from getting too busy, but also because I have some functions, like re-mixing source water in different proportions with the RO output so it’s suitable for drinking vs. laundry, etc.

While EPANet has a GUI based editor, it’s very primitive. However, it has some nice features that KiCad lacks (like showing simulation results (e.g. static water pressure) in the network) as the simulation proceeds. Its “netlist” is 100% text based, so it should be able to be generated from KiCad. But, it requires a flat netlist so I’m looking at the KIPE toolkit in case it can help.

There are many things left to do to implement what I have in mind. I’m still tweaking/adding symbols just to capture the design. The design itself is still evolving. I’m a complete NOOB at generating KiCad netlists, much less the “netlist” that EPANet wants. All sorts of new parameters need to be added to the symbols just to tell EPANet what it needs to know to simulate properly. I haven’t run into any showstoppers yet, but I’m sure I’ll find some stuff requiring workarounds. I seem to recall that assigning instance specific parameter values for hierarchical sheets that get “passed into” the sheet when flattening the design is a limitation that KiCad hasn’t addressed yet. This comes up a lot when running pipes of various sizes, types, and lengths.

I’m happy to post a picture of my design so far, but I don’t know how to attach something like that to this post, much less stuff like the symbols I’ve created :disappointed:

3 Likes

Drag picture file on your post when editing it.

Interesting, @Perry

You’re not the first to abuse Kicad this way. Not only did I use Kicad to draw a wiring layout for my tractor, but I also used Kicad for a plumbing layout of our place. :grinning:

My plumbing layout is very basic. Different colored (not to exact scale) graphic lines for piping and named circles and rectangles for various pieces of equipment.
eg: three different pressure controlled demand pumps: (house, stock & garden), all the isolating taps, one way valves, reverse osmosis system and its feed-in system, rainwater tanks, water bore, solar/wood heater hot water system with its recirculating system, etc, etc.

I’ve never attempted any sort of simulation: if the water exits the taps the way and with the pressure I’m happy with, it’ll do.

A tip: RO water tastes strange because it has no flavor, it is like drinking distilled water. I found just allowing it to mix with roof collected rain water gives it a little taste because of the bird poop, dust and rotting leaves.
All those people on town water get their water flavor from the city dam dirt and fish poop. :slightly_smiling_face:

I also have (dim) interest into this direction. I’ve seen KiCad being (ab)used for things like electrical cabinet layout to hydraulic and pneumatic circuits. There is more specialized software for this (Such as for example QElectroTech) but if you only do such diagrams occasionally then using the software you already know is an advantage.

There is a library on github for hydraulic symbols, but unfortunately it mostly has “exotic” symbols. I collected some info about ISO1219 and then I sort of got lost somewhere between an overwhelming amount of possible symbols (especially for valves and their actuation methods) and paywalls.

This forum places some restrictions on new users for spam mitigation, but you have already reached the “basic” trust level and can upload attachments or post images. For more about the working of this forum software, see:

I already have learned that “KiCad Abuse” might have been a better title for this thread:-)

Below is a snippet of my top level PI&D diagram. There are lots of “standards” for PI&D drawings and variations on symbols. Some things, like valves, are very similar across tools… Notations for naming/tagging of sensors seem pretty consistent. I’ve collected a lot of examples and tend to follow the ANSI/ISA S5.1 and ISO 14617-6 standards for symbol shapes.

Note that I do not yet model piping properly in this diagram. Pipes are just “wires”. This makes it something of a hybrid of (bad) PFD and single line PI&D. For now, I’m concerned mostly with valve, tank, and pump interconnect to get the basic design down, evaluating different valve setting combinations for different operating modes, evaluate fail-safe modes, and prove I can isolate key components for maintenance/repair. For example, if the RO filter croaks I need to be able to bypass it for replacement. Or, if the pressure booster dies that valve arrangement allows switching automatically to using the municipal water supply once the pressure tank is empty. OR, most importantly, if I get run over by a bus that my wife can hit the Big Red Button to turn all the fancy stuff off and revert to the way things worked for centuries.

Proving the design can handle the many desired operating and fault modes (E.g. pump dies, pressure tank leaks, town water is shut off, a pipe/valve breaks and I want to prevent a flood, filter needs replacement, sterilize mode for DHW recirc (legionella prevention), blah, blah) is actually quite complicated. I’m experimenting with using Prolog to simulate the network functionally and formally prove that I have the system detects these conditions and operates properly. Overkill? Maybe so. But I’m retired and this is what I want to do. So there:-) Then again, this mini expert system looks like it might actually make the final SCADA control software easier to implement reliably.

If I could attach attributes to wires (and wire segments) in EESchema than I could make the design above into a real PI&D without the diagram changing too much. Since EESchema dosen’t support this, I’ll need to add actual symbols for pipe segments and fittings like Tees, and just use “wires” to show how they are joined. This is no too bad. Many RF/uWave design tools work the same way.

One level above PI&D diagrams are Process Flow Diagrams (PFD), which I currently maintain in Powerpoint slides since I want these to be a basis for building the Human Machine Interface (HMI) that will have the glitzy animated dashboards to monitor and control the system. There is design software out there to integrate all of this (PI&D, PFD, HMI, SCADA, PLC programming, etc.), even one that looks like it might be free for personal use, but their learnin curve is steep.

This is my noob PFD so far…

water_treatment_overview.pdf (380.8 KB)

I took a quick look at QElectroTech. The price is right but my quick scan couldn’t find any support for PI&D. The documentation seemed to try to be much more friendly to newcomers than many I’ve seen, but they used so many unusual terms (e.g. “folio”, “element”, “schema”) for concepts that have conventional names in most tools it felt like I’d need to spend too much effort on learning its idisyncracies before getting to the core design work.

I had the same impression as you re: the hydraulic library on github. Creating symbols is a real PIA so I follow almost any lead to avoid reinventing that wheel. But the best I’ve been able to do is collect .jpeg examples from “real” tools and then re-enter them for KiCad.

Thanks for the pointer to the netiquette rules. They make good sense.

KiCad PCB can be used to check several arrangements of furniture in the apartment. I used Protel to check if everything fits. Since I use KiCad I had no such need, but if needed I suppose I would define footprints with 3D furniture models.
There are probably better programs for this but learning UI for one use…

I see little squares on the wires of your “Pressure Booster”:

image

… and this means that KiCad does not recognize the connection. KiCad has a limitation that connections between pins and wires are difficult to make for off-grid items. This is not much of an issue as long as you adhere to the KLC (KiCad Library Convention) (Mostly, put all pins on a 100mil grid), and use a 50mil grid for wiring (Because of resistors / capacitors, which have a 50mil offset for their pins).

Another small thing, I noticed your wires are a bit thin and out of proportion with your schematic symbols. It’s just visual and not a big issue, but you can adjust this in KiCad with: Schematic Editor / File / Schematic Setup / Project / Net Classes

I’ve seen KiCad being (ab)used for things like electrical cabinet layout to hydraulic and pneumatic circuits.

This seems like normal schematic capture to me.

Good catch. The “In” pin was 10mils off. The end of the wire intended for the “Out” pin was too long. And, I hadn’t marked the “Ctl” pins a N/C yet.

One of the many things I’ve found out the hard way is how cumbersome it is to draw a symbol. I find myself turning off snap-to-grid to get graphics to look like I want, and then forget to turn it back on when placing pins. Also, the symbols themselves do seem pretty fat compared to the wires, as you pointed out. As I proceed I’m sure I’ll have more of the best practices paged-in from the KiCad Library Convention document, and probably end up redoing the entire library at some point to make it “right”.

Of course, I spell pride with a “?” so if someone more versed in this also wants to dive in then the water’s fine. That would include creating a netlister, suggestions on how the kinds of parameters needed to make the simulation happy/accurate, etc. It was a bit of an eye opener for me, as an EE, to see just how complicated the model parameters for “simple” things like pipes and valves become when you want to get accurate enough. If I were an ME instead then I probably wouldn’t have been so surprised.

True enough. The beauty of it is that so much can get done on simple home-scale projects with a tool that’s definitely not designed for hydraulic engineering. The libraries and simulation models are clearly different. Other differences are related to the design flow and the kinds of polymorphisms that hydraulics guys take for granted as table stakes when creating/evaluating designs. The $$$$ built for purpose tools treat PFDs, PI&D, PLD programming, cable harness wiring and test, enclosure design and placement, and control system engineering as integrated facets of the effort, much like KiCad tries to integrate schematic capture and PCB layout. For the basic things I want in a home project scale, KiCad seems to get me a long way.

KiCad V8 has “Grid Overrides”, which can be used to set different grids for different items (pins, graphics, texts) You can also temporarily ignore the grid by depressing the [Ctrl] key. There are lots of little things in KiCad that can make you more productive, but it takes some time to find and learn such things.

*Edit: [Shift][Ctrl]. Duh, silly me! (Noticed it while reading jmk’s post).

Somehow I missed that gem when reading the V8 Release Notes. Thanks :grinning:

The grid is off when the Ctrl key is held down.

My work flow tends to be to keep a grid for everything, but I have a bucket load of grids to choose from in every Editor and use a Hotkey for “Edit Grids” then select the appropriate for the job.

Default line width for symbols can be changed in Preferences > Symbol Editor > Editing Options.

Duplicate, Mirror and Rotate are really useful for creating symbols.
eg. your Pressure Booster drawing. Draw one line in the circle from control to out; then Duplicate, Move, Mirror and Move again to get a symetrical line to go from Out to the top of the circle.
Very handy, also, for things like the arcs on your pressure tank (get one right and Duplicate then Mirror) and the arrows on your gauges (draw half the arrow then Duplicate, Mirror and Rotate for the other half).

That is the only reason I went to the trouble of drawing the “map of the plumbing”. It only took me 15 years to get around to this creation. :rofl:

I’ve seen KiCad being (ab)used for things like electrical cabinet layout

About this. We have been ‘abusing’ Eagle CAD for this. So logically I made a small demo with a PLC and 3 IO blocks in KiCad.

As is now, It is extremely rudimentary. I would need to make good footprint and good symbol libraries along with style sheets.

afbeelding

I think that Kicad could actually be a viable replacement.We are ofcourse going over to Eplan which is for this task by far superior in every way (with user friendlyness as exception).

I like the hiearchy in the schematic editor. In Eagle we don’t have a nice route sheet. The hierarchy helps with navigating in the schematic.

I can already imagine that you can use busses and or wires to hierarchial sheets to ‘highlight’ the power nets and such.

The board editor can be used with extra footprints for things like cable ducts, DIN rails and a physical cabinet to design the actual cabinet. There are ways to export the drill files which we would need

And 3D is just nice to have.

So despite it ain’t perfect, I do see some potential in this kind of abuse :smiley:

:tumbler_glass:

Bas

You may want to take a look at scilab. Scilab is a free near MATLAB clone. It is not as compatible with MATLAB as Octave, but it comes with something like MATLAB’s Simulink, called Xcos (I don’t know how to pronounce it). Xcos is a full-featured controls and signal-processing toolkit with a very sophisticated gui. It may be possible to use the symbols you are making with Xcos, but Xcos comes with a rich gamut of symbols already. With Xcos, you can set up your system graphically and then run analog or digital simulations using scilab’s computational prowess, much like you would do with MATLAB’s Simulink.

There is also https://openmodelica.org/

I think they also offer a decent alternative for “abusive” schematics (and “simulation”?) that can cover these non-traditional cases.

Abusing KiCad is more fun though :slight_smile:

The water where I live is insanely hard, hence the RO. Some I’ve talked to swear by drinking/cooking with RO water, but I buy the argument that it’s actually less healthy because the mineral content is too low. Hence, two instances of remix with the Town water. One instance for cooking/drinking, seasoned to taste, and one for DHW (just enough to prevent corrosion).

TBH, until I stumbled on the EPANet software I had no plans to try simulation. But, the price was right and when I saw its models worked for 1/4" pipes as well as 12’ pipes and could deal with pumps, valves, tanks, even temperature and chemical concentration gradients (think remineralization and DHW recirculation), it tickled my funny bone too much.

I love Scilab. Xcos is pretty nice as well, but since I worked for Keysight I and used our EDA products (Advanced Design System) frequently, I tended to use what I already knew. I haven’t looked, but I suspect that a lot of modeling work would be needed to get XCos models to the level of maturity of the EPANet models. Perhaps I’m mistaken and should take another look.

On the other hand, I do want to simulate the complete control loops for stuff like preheating/post-cooling water for the RO filter, remineralization system, etc. which have both hydraulic and electronic/SW components on the loop. This is just what the Xcos folks had in mind. But then I’d need to generate Xcos “netlists” as well as the hydraulic models. It’s really a question of what’s the easiest path, since I’m lazy.

What I’d like is a decent co-simulation environment. ADS can do this, but since I retired my license expired:-(

1 Like

I know there’s some DNA sharing between Xcos and Modelica. How good are their hydraulic models?

1 Like