//--------------------------------------------------------- bool CFlow_Parallel::Calculate(void) { for(int y=0; y<Get_NY() && Set_Progress(y); y+=m_Step) { #pragma omp parallel for for(int x=0; x<Get_NX(); x+=m_Step) { Init_Cell(x, y); } } return( Set_Flow() ); }
//--------------------------------------------------------- bool CDiffuse_Pollution_Risk::Set_Flow(void) { Process_Set_Text(_TL("initialization")); CSG_Grid *pWeight = Parameters("WEIGHT")->asGrid (); double Weight = Parameters("WEIGHT")->asDouble(); CSG_Grid *pRain = Parameters("RAIN" )->asGrid (); double Rain = Parameters("RAIN" )->asDouble(); m_FlowDir.Create(*Get_System(), SG_DATATYPE_Char); m_RainAcc.Create(*Get_System()); m_TWI .Create(*Get_System()); for(sLong n=0; n<Get_NCells() && Set_Progress_NCells(n); n++) { int x, y; if( !m_pDEM->Get_Sorted(n, x, y, true) || (pRain && pRain->is_NoData(x, y)) || !Set_Flow(x, y, pRain ? pRain->asDouble(x, y) : Rain) ) { m_FlowDir .Set_NoData(x, y); m_RainAcc .Set_NoData(x, y); m_TWI .Set_NoData(x, y); m_pRisk_Point->Set_NoData(x, y); } else { double s, a; m_pDEM->Get_Gradient(x, y, s, a); s = tan(s); // tangens of slope a = (fabs(sin(a)) + fabs(cos(a))) * Get_Cellsize(); // flow width double SCA = m_RainAcc.asDouble(x, y) / a; // rain * specific catchment area m_TWI.Set_Value(x, y, log(SCA / (s < M_ALMOST_ZERO ? M_ALMOST_ZERO : s))); if( pWeight && pWeight->is_NoData(x, y) ) { m_pRisk_Point->Set_NoData(x, y); } else { m_pRisk_Point->Set_Value(x, y, SCA * s * (pWeight ? pWeight->asDouble(x, y) : Weight)); // Point Scale Risk Calculation according to Milledge et al. 2012 } } } return( true ); }
//--------------------------------------------------------- bool CDiffuse_Pollution_Risk::On_Execute(void) { //----------------------------------------------------- m_pDEM = Parameters("DEM" )->asGrid(); m_pDelivery = Parameters("DELIVERY" )->asGrid(); m_pRisk_Point = Parameters("RISK_POINT" )->asGrid(); m_pRisk_Diffuse = Parameters("RISK_DIFFUSE")->asGrid(); m_bSingle = Parameters("METHOD" )->asInt() == 0; DataObject_Set_Colors(m_pDelivery , 11, SG_COLORS_RED_GREY_GREEN, true); DataObject_Set_Colors(m_pRisk_Point , 11, SG_COLORS_RED_GREY_GREEN, true); DataObject_Set_Colors(m_pRisk_Diffuse, 11, SG_COLORS_RED_GREY_GREEN, true); //----------------------------------------------------- bool bResult = false; if( !Set_Flow() ) { Error_Set(_TL("initialization failed")); } else if( !Set_Delivery_Index() ) { Error_Set(_TL("delivery index calculation failed")); } else if( !Get_Risk_Diffuse() ) { Error_Set(_TL("diffuse pollution risk calculation failed")); } else { bResult = true; } //----------------------------------------------------- m_FlowDir.Destroy(); m_RainAcc.Destroy(); m_TWI .Destroy(); return( bResult ); }
//--------------------------------------------------------- bool CFlow_Parallel::Calculate(int x, int y) { Init_Cell(x, y); return( Set_Flow() ); }