|
@@ -91,4 +91,114 @@ Geometry::load(fstream& file,bool init) {
|
|
|
if(init) Z[i]=new double[nZ[i]];
|
|
|
file.read((char*)Z[i],nZ[i]*sizeof(double));
|
|
|
}
|
|
|
+ //Comoute dhsoil and dhbot
|
|
|
+ dhsoil[0]=(hsoil[1]-hsoil[0])/dX;
|
|
|
+ dhbot[0]=(hbot[1]-hbot[0])/dX;
|
|
|
+
|
|
|
+ for(size_t i=1;i<nX-1;++i){
|
|
|
+ dhsoil[i]=(hsoil[i+1]-hsoil[i-1])/(2*dX);
|
|
|
+ dhbot[i]=(hbot[i+1]-hbot[i-1])/(2*dX);
|
|
|
+ }
|
|
|
+ dhsoil[nX-1]=(hsoil[nX-1]-hsoil[nX-2])/dX;
|
|
|
+ dhbot[nX-1]=(hbot[nX-1]-hbot[nX-2])/dX;
|
|
|
+ cout<<"Done"<<endl;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+pair<list<Basin*>::iterator,list<Basin*>::iterator>
|
|
|
+Geometry::find_basins(const Summit& s,list<Basin*>& basins){
|
|
|
+ list<Basin*>::iterator it_left;
|
|
|
+ list<Basin*>::iterator it_right;
|
|
|
+ for(list<Basin*>::iterator it=basins.begin();it!=basins.end();++it){
|
|
|
+ Basin* b=*it;
|
|
|
+ if(b->xleft==s.ix){
|
|
|
+ cout<<"Right found"<<endl;
|
|
|
+ it_right=it;
|
|
|
+ }
|
|
|
+ if(b->xright==s.ix){
|
|
|
+ cout<<"Left found"<<endl;
|
|
|
+ it_left=it;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pair<list<Basin*>::iterator,list<Basin*>::iterator>(it_left,it_right);
|
|
|
+}
|
|
|
+
|
|
|
+void Geometry::compute_basins(){
|
|
|
+ //Find local min point of hsoil
|
|
|
+ vector<size_t> v_min;
|
|
|
+ if(hsoil[0]<hsoil[1]) v_min.push_back(0);
|
|
|
+ for(size_t ix=1;ix<nX-1;++ix){
|
|
|
+ double h=hsoil[ix];
|
|
|
+ if(hsoil[ix-1]>h and h<hsoil[ix+1]) v_min.push_back(ix);
|
|
|
+ }
|
|
|
+ if(hsoil[nX-2]>hsoil[nX-1]) v_min.push_back(nX-1);
|
|
|
+ size_t nb=v_min.size();
|
|
|
+
|
|
|
+ //Primitive Basins
|
|
|
+ vector<Summit> summits;
|
|
|
+ list<Basin*> basins_to_merge;
|
|
|
+
|
|
|
+ for(size_t ib=0;ib<nb;++ib){
|
|
|
+ Basin* b=new Basin;
|
|
|
+ size_t xb=v_min[ib];
|
|
|
+ //Find left bound
|
|
|
+ b->xbottom=xb;
|
|
|
+ if(xb==0){
|
|
|
+ b->xleft=xb;
|
|
|
+ b->position=BorderLeft;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ size_t ix=xb;
|
|
|
+ while(ix>0 and hsoil[ix-1]>hsoil[ix]) --ix;
|
|
|
+ b->xleft=ix;
|
|
|
+ if(ix==0) b->position=BorderLeft;
|
|
|
+ if(ix>0) summits.emplace_back(ix,hsoil[ix]);
|
|
|
+ }
|
|
|
+ //Find right bound
|
|
|
+ if(xb==nX-1){
|
|
|
+ b->xright=xb;
|
|
|
+ b->position=BorderRight;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ size_t ix=xb;
|
|
|
+ while(ix<nX and hsoil[ix+1]>hsoil[ix]) ++ix;
|
|
|
+ if(ix==nX-1)b->position=BorderRight;
|
|
|
+ b->xright=ix;
|
|
|
+ }
|
|
|
+ b->hleft=hsoil[b->xleft];
|
|
|
+ b->hright=hsoil[b->xright];
|
|
|
+
|
|
|
+ b->compute_leak_direction();
|
|
|
+
|
|
|
+ // Set hmin
|
|
|
+ b->hmin=hsoil[xb];
|
|
|
+
|
|
|
+ basins_to_merge.push_back(b);
|
|
|
+ }
|
|
|
+ //Determine meta basins`
|
|
|
+ sort(summits.begin(),summits.end());
|
|
|
+ for(auto it=summits.begin();it!=summits.end();++it){
|
|
|
+ Summit& s=*it;
|
|
|
+ auto res=find_basins(s,basins_to_merge);
|
|
|
+ list<Basin*>::iterator it_left=res.first;
|
|
|
+ list<Basin*>::iterator it_right=res.second;
|
|
|
+ Basin* b_left=*it_left;
|
|
|
+ Basin* b_right=*it_right;
|
|
|
+
|
|
|
+ basins_to_merge.erase(it_left);
|
|
|
+ basins_to_merge.erase(it_right);
|
|
|
+ Basin* b=new Basin(b_left,b_right);
|
|
|
+ basins_to_merge.push_back(b);
|
|
|
+ }
|
|
|
+ root_basin=basins_to_merge.front();
|
|
|
+ root_basin->display();
|
|
|
+
|
|
|
+ // Compute Runoff directions
|
|
|
+ runoff_directions=new Direction[nX];
|
|
|
+ for(size_t ix=1;ix<nX-1;++ix){
|
|
|
+ double dh=(hsoil[ix+1]-hsoil[ix-1])/(2*dX);
|
|
|
+ if(abs(dh)<max_slope_both_side_runoff) runoff_directions[ix]=Both;
|
|
|
+ else runoff_directions[ix]=(dh>0)?Left:Right;
|
|
|
+ cout<<ix<<" "<<dh<<" "<<runoff_directions[ix]<<endl;
|
|
|
+ }
|
|
|
}
|