Mechanism of linear and nonlinear optical effects of KDP and urea crystals