Source code: C++ Solar Irradiation and Daily Light Integral Classes 🛠

Example

The following example generates a map of DLI by latitude for the solar radiation received at the ground as if there were no atmosphere. Atmosphere and weather affect the actual DLI received, the above class, currently, can also calculate the DLI with a first order estimation of attenuation.


******************************************* DLI by latitude and year day ***********************************************


		
	/*************/
	/* Calculate the dli on the min/max solar radiation days. */
	std::cout << "****************************************************************************************************************************************" << std::endl;
	std::cout << "******************************************* DLI by latitude and year day **************************************************************" << std::endl;
	std::cout << "****************************************************************************************************************************************" << std::endl;
	do
	{
		Daily_Light dli;
		zoned_sun_time location;
		sun sun_element_newyork;
		std::list<std::tuple<double, double, double>> rad_map;
		
		int day_stride = 3;
		std::cout << "LAT     1" <<  std::string((round(365 / day_stride) - 10) / 2, ' ') << "day" <<  std::string((round(365 / day_stride) - 1) / 2, ' ') << "365   Total(yr)" << std::endl;
		
		for (int calc_latitude = 84; calc_latitude >= -84; calc_latitude -= 2)
		{
			double total_irrad = 0.0;
			
			for (int day = 0; day < 365; day++)
			{
				/* Find the solar noons and the incident radiation max/mins throughout the year. */
				/* Find solar noon for today. */
				location = date::make_zoned("UTC", date::local_days{ date::January / 01 / 2018 } + std::chrono::hours(0) + date::days(day));
				sun_element_newyork.set("UTC", calc_latitude, -73.935242, location);
			
				/* Determine radiation. */
				double distance = dli.calculate_dli(location, &sun_element_newyork, false);
			
				/* Save this information. */
				rad_map.push_back(std::tuple<double, double, double>((double)day, distance, calc_latitude));
			}
		
			/* Plot the chart */

			for (std::tuple<double, double, double> element : rad_map)
			{
				int day = std::get<0>(element);
				double distance = std::get<1>(element);
				double calc_latitude = std::get<2>(element);
				
				if (day == 0) std::cout << boost::format("%-5.1f")  % calc_latitude << " : ";
				
				total_irrad += distance;
				
				if ((day % day_stride == 0))
				{

					if ((distance) >= (40))
					{
						std::cout << BG_RED << " " << FG_DEFAULT << BG_DEFAULT;
					}	
					else if ((distance) >= (35))
					{
						std::cout << BG_MAGENTA << " " << FG_DEFAULT << BG_DEFAULT;
					}
					else if ((distance) >= (30))
					{
						std::cout << BG_ORANGE << " " << FG_DEFAULT << BG_DEFAULT;
					}
					else if ((distance) >= (25))
					{
						std::cout << BG_YELLOW << " " << FG_DEFAULT << BG_DEFAULT;
					}
					else if ((distance) >= (20))
					{
						std::cout << BG_LIGHT_YELLOW  << " " << FG_DEFAULT << BG_DEFAULT;
					}
					else if ((distance) >= (15))
					{
						std::cout << BG_LIGHT_GREEN  << " " << FG_DEFAULT << BG_DEFAULT;
					}
					else if ((distance) >= (10))
					{
						std::cout << BG_GREEN << " " << FG_DEFAULT << BG_DEFAULT;
					}
					else if ((distance) >= (5))
					{
						std::cout << BG_CYAN << " " << FG_DEFAULT << BG_DEFAULT;
					}
					else if ((distance) >= (3))
					{
						std::cout << BG_LIGHT_BLUE  << " " << FG_DEFAULT << BG_DEFAULT;
					}
					else if ((distance) >= (2))
					{
						std::cout << BG_BLUE << " " << FG_DEFAULT << BG_DEFAULT;
					}
					else if ((distance) >= (0))
					{
						std::cout << BG_LIGHT_BLACK << " " << FG_DEFAULT << BG_DEFAULT;
					}
					else
					{
						std::cout << BG_DARK_GRAY << " " << FG_DEFAULT << BG_DEFAULT;
					}
				}    
			} 
			std::cout << " : " << total_irrad << std::endl;
			rad_map.clear();
			
		} /* end calc_longitude */

		std::cout << "Legend:" << std::endl;	
		std::cout << "MJ/m^2 day :" << FG_RED << "* >40 \t" << FG_MAGENTA << "* >35 \t" << FG_ORANGE << "* >30 \t" << FG_YELLOW << "* >25 \t" << FG_LIGHT_YELLOW << "* >20 \t" << FG_DEFAULT << BG_DEFAULT << std::endl;
		std::cout << "MJ/m^2 day :" << FG_LIGHT_GREEN << "* >15 \t" << FG_GREEN << "* >10 \t" << FG_CYAN << "* >5 \t" << FG_LIGHT_BLUE << "* >3 \t" << FG_LIGHT_BLACK << "* >=0 \t" << FG_DEFAULT << BG_DEFAULT << std::endl;
		std::cout << std::endl;	
	} while (0) ;

Produces the following:

CC BY-SA 4.0

4 Likes