Self-consistent electrical charging of insulating layers and metal-insulator-semiconductor structures