Skip to content
Snippets Groups Projects
MatData.h 5.64 KiB
Newer Older
  • Learn to ignore specific revisions
  • Radim Vavřík's avatar
    Radim Vavřík committed
    // MatData.h
    #pragma once
    #include "pugixml.hpp"
    #include "Logger.h"
    #include "Station.h"
    #include "Channel.h"
    #include "Options.h"
    #include <ctime>
    namespace math1d_cl
    {
    
    	typedef std::vector<std::pair<time_t ,std::vector<double>>> precipitationsVector;
    	///
    	/// Main class of Math1D model that contains whole data structure and methods to run computation of model.
    	///
    	class MatData
    	{
    	public:
    		//MatData(); ///< Constructor
    
    		///
    		/// Constructor. Param fileName is filename/path to XML file with schematization modifications.
    		///
    		MatData(std::string fileName);
    
    		///
    		/// Copy constructor
    		///
    		MatData(const MatData& origin);
    
    		///
    		/// Starts model computation
    		///
    		int runRR();
    
    		///
    		/// Computes RR model
    		///
    		void rainfallRunoffModel();
    
    		///
    		/// Returns date and time in format dd.mm.yyyy hh:mm
    		///
    		std::string printDateTime(const time_t& dateTime);
    
    		// Getters & Setters
    		std::vector<std::shared_ptr<Station>>& getSourceStations();
    		void setSourceStations(const std::vector<std::shared_ptr<Station>>& sourceStations);
    		std::vector<std::shared_ptr<Station>>& getRiverStations();
    		void setRiverStations(const std::vector<std::shared_ptr<Station>>& riverStations);
    		const int& getBasinId();
    		void setBasinId(const int& basinId);
    		std::vector<std::shared_ptr<Station>>& getWeatherStations();
    		void setWeatherStations(const std::vector<std::shared_ptr<Station>>& weatherStations);
    		std::vector<std::shared_ptr<Channel>>& getChannels();
    		void setChannels(const std::vector<std::shared_ptr<Channel>>& channels);
    		std::vector<std::shared_ptr<Subbasin>>& getSubbasins();
    		void setSubbasins(const std::vector<std::shared_ptr<Subbasin>>& subbasins);
    		precipitationsVector getPrecipitations();
    		void setPrecipitations(const precipitationsVector precipitations);
    		Options& getOptions();
    		void setOptions(Options options);
    		
    		// Getters for model results
    		std::vector<std::vector<double>> getMeasuredHydrographsQ();
    		std::vector<std::shared_ptr<Station>>& getMeasureStations();
    		
    		// Search getters
    		std::shared_ptr<Channel> getChannelById(int id);
    		std::shared_ptr<Subbasin> getSubbasinById(int id);
    						
    		///
    		/// Loads input data from CSV files and schematization from XML file.
    		///
    		void collectMatDataCsv();
    
    		///
    		/// Check Flood Warning levels exceeding (SPA) in simulated discharge volumes
    		//
    		int checkFWL();
    
    	private:
    		///
    		/// Implementation of SCS-CN Method
    		///
    		void scsMethod(std::vector<double>& q, size_t& index);
    
    		
    
    
    		///
    		/// Sets default options of model
    		///
    		void setOptions();
    
    		///
    		/// Converts integer to string
    		///
    		std::string intToString(const int& number);
    
    		///
    		/// Loads measured discharge volumes and creates 2d vector of values
    		///
    		void loadSchematization();
    
    		///
    		/// Loads stations data from XML and creates stations object
    		///
    		void loadStationsFromXml(std::vector<std::shared_ptr<Station>>& stations, pugi::xml_node& xml_stations);
    
    		///
    		/// Loads channels data from XML and creates channels object
    		///
    		void loadChannelsFromXml(std::vector<std::shared_ptr<Channel>>& channels, pugi::xml_node& xml_channels);
    
    		///
    		/// Loads subbasins data from XML and creates subbasins object
    		///
    		void loadSubbasinsFromXml(std::vector<std::shared_ptr<Subbasin>>& subbasins, pugi::xml_node& xml_subbasins);
    
    		///
    		/// Loads measured discharge volumes and creates 2d vector of values
    		///
    		void loadMeasuredDischargeVolumesFromCsv();
    
    		///
    		/// Loads precipitations and creates 2d vector of time and values
    		///
    		void loadPrecipitationsFromCsv();
    
    		///
    		/// Compute measured Hydrographs
    		///
    		void getMeasuredHydrographs();
    
    		///
    		/// Finds station by given id in collection of Stations
    		///
    		std::shared_ptr<Station> findStation(std::vector<std::shared_ptr<Station>>&, int& id);
    
    		///
    		/// Converts Q to H
    		///
    		std::vector<double> qToH(std::vector<double>& q, std::shared_ptr<Channel> channel, int& rectangleProfile);
    
    		///
    		/// Computes velocity
    		///
    		double velocity(std::shared_ptr<Channel> channel);
    
    		///
    		/// Fitting (Calibration in matlab code) sets alpha and beta to params passed by reference.
    		///
    		void fit(double& alpha, double& beta, std::vector<double>& x, std::vector<double>& y, std::vector<double>& wage);
    
    		///
    		/// Saves results as CSV files
    		///
    		void collectRRResultCsv();
    
    		///
    		/// Clear results
    		///
    		void clearResults();
    
    		/// Members
    		std::vector<std::shared_ptr<Station>> m_sourceStations;
    		std::vector<std::shared_ptr<Station>> m_riverStations;
    		int m_basinId;
    		std::vector<std::shared_ptr<Station>> m_weatherStations;	///< Contains only Id, Name, Code, Location in MatData.mat
    		std::vector<std::shared_ptr<Station>> m_measureStations;
    		//std::vector<int> m_measureStations;
    		std::vector<std::shared_ptr<Channel>> m_channels;
    		std::vector<std::shared_ptr<Subbasin>> m_subbasins;
    		std::vector<std::vector<double>> m_measuredDischargeVolumes;
    		precipitationsVector m_precipitations;
    		std::vector<std::vector<double>> m_measuredHydrographsQ;
    
    		Options m_options;
    		std::string m_configFilePath;
    		std::string m_matDataXmlFilePath;
    		std::string m_measuredDischargeVolumesCsvFilePath;
    		std::string m_precipitationsCsvFilePath;
    		std::string m_qCsvFilePath;
    		std::string m_hCsvFilePath;
    		std::string m_vCsvFilePath;
    		int m_nTimeSteps;
    		int m_minuteStep;
    		std::vector<int> m_precStationIds;
    		std::vector<int> m_mdvStationIds;
    		//std::vector<int> m_times;
    		//bool m_checkModifications;
    		//pugi::xml_parse_result m_schemaConfig;
    		bool m_simulationDone = false;
    	};
    }