Is it grammatically correct to omit the second "the" in the sentence
The viscosity and the density of water characterize its speed.
and write instead
The viscosity and density of water characterize its speed?
Is it grammatically correct to omit the second "the" in the sentence
The viscosity and the density of water characterize its speed.
and write instead
The viscosity and density of water characterize its speed?
Repeating the article can avoid ambiguity when adjectives get involved. "The black dog and cat" might mean "The black dog and the black cat" or "The black dog and the cat [of any colour]." "The black dog and the cat" clearly associates "black" only with the dog.
No, not really. In your example, "the viscosity and density of water" is perfectly okay, and it means the same as "the viscosity of water and the density of water", but a "the" has not been omitted, nor has "of water" been omitted. Instead, a conjoined noun, "viscosity and density", has been used as the head noun of the noun phrase. There is only one noun phrase there, consequently, there is only one "the". But "[[the viscosity of water] and [the density of water]]" has two noun phrases, and consequently there are two "the"s -- one for each noun phrase.
Words that are not present aren't necessarily "omitted".
If you want to test whether there are actually two noun phrases present, perhaps you could tell by trying to associate different nonrestrictive relative clauses with each noun phrase.