How do you replenish the materials used by nanites when they're doing something?
Alternative thought, you don't.
The nanites are the materials.
At least when it comes to producing something - either a finished product, or the materials for a later finished product. This wouldn't work when you want to do something other than manufacture, but I'm struggling to think of uses for nanites that isn't in some way 'eat things' and/or 'make things'.
Replenishing materials becomes a non-issue as this answer is the answer to the question of how do you manufacture nanites in the first place?
I can think of two plausible nanite life-cycles. The end result is largely the same, but the order of things is swapped around slightly.
- You feed your nanites, much like you feed biological cells. They grow large and flabby.
- The nanites undergo binary cell fission.
- You encourage half of your nanites to attach themselves onto the surface of the thing being built.
- The nanites, using the same internal machinery used to initially build themselves, start unbuilding themselves and attaching those molecules to what's being built.
- Split your nanites into two groups.
Feed both so they're large and flabby.
2.1. Encourage one group to attach themselves onto the surface of the thing being built. It's obvious what happens here.
2.2. Let the other group undergo binary cell fission.
Feeding, and manufacture are both going to produce waste. Needless to say that they'll be both messy eaters and inefficient builders. The above life-cycles have the advantage of being able to separate apart the two processes. This allows us to supply the nanites with resources without interfering with the work they'll do, and tailor clean up measures accordingly.
But it comes at the cost of having to manage them. And this is a control problem.
Controlling large numbers of very small things is going to be imprecise. You won't be able to select a single nanite and direct it to a specific location. You'll be relying on swarm behaviour. Splitting nanites into groups is the easier task; if you can instruct them to form a large blob, then mechanical separation is the order of the day.
If nanites naturally like being somewhat close to each other, then they will form a blob, but you can't control the location of the blob.
Avoidance of light is a good way to direct them around as it works in liquid (caveat:transparent liquids) and with cleverly placed orthogonal lights can work in 3D and make paths to guide them.
The hard part is telling the little blighters when it's time to turn themselves into stuff. This is hard for two reasons; the thing you're building something might be something like a computer CPU that has lots of specific and precisely placed elements, and you don't want your nanites to incorrectly start building too early.
The signal to build, and what to build into needs to be very salient.
Nanites won't have access to their x, y, z coordinates. So take inspiration from biology and use combinations chemical signals. Emit a chemical from one end of your product, and another from the far end. Give the nanites a sense of smell. The ratio of one chemical to the other can infer position, and hence what the nanite should turn into. This has the added benefit of no-smells-equals-no-construction.
Now, dealing with the waste. The waste, obviously, is the left-over parts of the nanites that weren't used.
Wastes come in two types: soluble, and non-soluble. Soluble wastes will disperse throughout your liquid. If these wastes can be consumed by the nanites, then you're golden as they'll filter out and recycle them.
Soluble wastes are a problem to the health of your nanites as they'll likely change the pH levels of the liquid. They'll react with the nanite food, the nanites themselves, or both.
Non-soluble wastes will effect the turbidity of the liquid - which may influence your ability to control the nanites. Turbid water is treated two ways; mechanically, through filtration, and chemically through reagents. Both of these could be harmful to nanites. A work-around would be to heard all the nanites to another tank/vat/etc, and process the waste separately. Always having one operating vat, and one vat being cleaned.
Using @Magnanimancer's idea of having another variety of nanite that cleans the water is a nice idea. It allows you to have a mechanical process in-situ that doesn't harm the other nanites. Suppose you have a nanite that can sense two things; the presense of other nanites, and the turbidity of the water.
If there are few nanites around; feed and multiply.
If there are many; don't.
If there's junk floating in the water, grab hold of it, don't let go, and sink to the bottom of the vat.