Esempio n. 1
0
//Execute module
int SOL_WB::Execute()
{	
	CheckInputData();

	if(m_subbasinList == NULL)
	{
		m_subbasinSelectedCount = 1;
		m_subbasinSelected = new float[1];
		m_subbasinSelected[0] = 0;
		getSubbasinList(m_nCells, m_subbasin, m_subbasinSelectedCount, m_subbasinSelected);
		delete m_subbasinSelected;
	}

	return 0;
}
Esempio n. 2
0
int ReservoirMethod::Execute()
{
	// check the data
	if (!CheckInputData()) 
		return -1;
	
	//read subbasin information
	if(m_subbasinList.size() == 0) 
		getSubbasinList();

	//initial results
	if(m_D_Revap == NULL) 
		m_D_Revap = new float[m_nCells];

	int nLen = m_subbasinList.size() + 1;

	if(m_T_RG == NULL) 
	{
		m_T_RG = new float[nLen];
		m_T_QG = new float[nLen];
		m_petSubbasin = new float[nLen];
		m_gwStore = new float[nLen];
	}

	//if(m_T_GWWB == NULL && m_subbasinSelectedCount > 0 && m_subbasinSelected != NULL) 
	//{
	//	m_T_GWWB = new float*[m_subbasinSelectedCount];
	//	for(int i=0; i<m_subbasinSelectedCount; i++) 
	//		m_T_GWWB[i] = new float[6];
	//}
	//cout << "nSubbasins:\t" << m_nSubbasins << endl;
	for(int i = 0; i < m_nSubbasins; i++)
	{
		int subbasinID = i+1;
		subbasin *sub = m_subbasinList[i];
		//cout << "subbasin ID: " << subbasinID << "\t" << sub << endl;

		float gwBank = 0.0f;
		if(m_VgroundwaterFromBankStorage != NULL)//at the first time step m_VgroundwaterFromBankStorage is null 
			gwBank = m_VgroundwaterFromBankStorage[subbasinID];

		sub->setInputs(m_D_PET, m_D_EI, m_D_ED, m_D_ES, m_perc, gwBank);	//caculate
		m_T_RG[subbasinID] = sub->getRG();				//get rg of specific subbasin
		m_T_QG[subbasinID] = sub->getQG();				//get qg of specific subbasin
		m_petSubbasin[subbasinID] = sub->getPET();
		m_gwStore[subbasinID] = sub->getGW();
	}
	
	m_T_RG[0] = subbasin::subbasin2basin("RG", &m_subbasinList);  // get rg of entire watershed
	m_T_QG[0] = subbasin::subbasin2basin("QG", &m_subbasinList);  // get qg of entire watershed
	m_petSubbasin[0] = subbasin::subbasin2basin("PET", &m_subbasinList);
	m_gwStore[0] = subbasin::subbasin2basin("GW", &m_subbasinList);

	//get D_Revap
	for(int i = 0; i < m_nSubbasins; i++)
	{
		subbasin* sub = m_subbasinList[i];
		if(!(sub->getIsRevapChanged())) //if the revap is the same with last time step, do not set its value to m_D_Revap.
			continue; 

		int* cells = sub->getCells();
		int nCells = sub->getCellCount();
		int index = 0;
		for(int i = 0; i < nCells; i++)
		{
			index = cells[i];
			float depth2 = m_rootDepth[index] - m_upSoilDepth;
			m_soilMoisture[index][m_nSoilLayers-1] += sub->getEG()/depth2;
		}
	}

	return 0;
}