Space charges in nanostructured solar cells: CuInS2 thin films and CdSe quantum dots