Water Hammer Calculation

How can I calculate the water hammer in ramified drinkable water conveyances?  

How can the knocking noise in water pipes, when the water is suddenly shut off, be prevented while installing the pipes?

What can be done if the problem occurs after installation?