1!
2!     CalculiX - A 3-dimensional finite element program
3!              Copyright (C) 1998-2021 Guido Dhondt
4!
5!     This program is free software; you can redistribute it and/or
6!     modify it under the terms of the GNU General Public License as
7!     published by the Free Software Foundation(version 2);
8!
9!
10!     This program is distributed in the hope that it will be useful,
11!     but WITHOUT ANY WARRANTY; without even the implied warranty of
12!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13!     GNU General Public License for more details.
14!
15!     You should have received a copy of the GNU General Public License
16!     along with this program; if not, write to the Free Software
17!     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18!
19      subroutine hcrit(xflow,rho,b,theta,dg,sqrts0,hk)
20!
21!     determine the critical depth
22!
23      implicit none
24!
25      real*8 xflow,rho,b,dg,sqrts0,hk,theta,tth,c1,xflow2,
26     &  A,dBBdh,dAdh,BB,dhk
27!
28      hk=((xflow/(rho*b))**2/(dg*sqrts0))**(1.d0/3.d0)
29!
30      if(dabs(theta).lt.1.d-10) return
31!
32!     critical depth for trapezoid, non-rectangular cross section
33!
34      tth=dtan(theta)
35      c1=rho*rho*dg*sqrts0
36      xflow2=xflow*xflow
37!
38      do
39         A=hk*(b+hk*tth)
40         dBBdh=2.d0*tth
41         dAdh=b+hk*dBBdh
42         BB=dAdh
43         dhk=(xflow2*BB-c1*A**3)/(xflow2*dBBdh-3.d0*c1*A*A*dAdh)
44         if(dabs(dhk)/dhk.lt.1.d-3) exit
45         hk=hk-dhk
46      enddo
47!
48      return
49      end
50
51
52