subroutine mesh(l ,h ,n ,m ,eps ,xp ,deltaxp ,xf ,yp ,deltayp ,yf) implicit none real ,…
- User
subroutine mesh(l ,h ,n ,m ,eps ,xp ,deltaxp ,xf ,yp ,deltayp ,yf) implicit none real , intent (in) :: l ,h ,eps integer , intent (in) :: n,m double precision ,dimension (n) ,intent (in out) :: xp double precision ,dimension (n) ,intent (in out) :: deltaxp,xf double precision ,dimension (m) ,intent (in out) :: yp double precision ,dimension (m) ,intent (in out) :: deltayp,yf real :: deltax1 ,deltay1 ,epsn ,epsm integer ::i,j
!****** deltax1=l/3.0/((eps**(n/3-1)-1)/(eps-1)) xp(1)=0 xp(2)=deltax1/2 do i=3,n/3 deltax1=deltax1*eps xp(i)=xp(i-1)+deltax1 end do
deltay1=h/3.0/((eps**(m/3-1)-1)/(eps-1)) yp(1)=0 yp(2)=deltay1/2 do j=3,m/3 deltay1=deltay1eps yp(j)=yp(j-1)+deltay1 end do !***** deltax1=(l/3.0)/(n/3) xp(n/3+1)=l/3.0+deltax1/2 do i=n/3+2,2*n/3 xp(i)=xp(i-1)+deltax1 end do
deltay1=(h/3.0)/(m/3) yp(m/3+1)=h/3.0+deltay1/2 do j=m/3+2,2m/3 yp(j)=yp(j-1)+deltay1 end do !***** epsn=1./1.001 deltax1=l/3.0/((epsn**(n/3-1)-1)/(epsn-1)) xp(2n/3+1)=2l/3.0+deltax1/2 do i=2n/3+2,n-1 deltax1=deltax1epsn xp(i)=xp(i-1)+deltax1 end do xp(n)=l
epsm=1./1.001 deltay1=h/3.0/((epsm**(m/3-1)-1)/(epsm-1)) yp(2m/3+1)=2h/3.0+deltay1/2 do j=2m/3+2,m-1 deltay1=deltay1epsm yp(j)=yp(j-1)+deltay1 end do yp(m)=l
!****** xf(1)=0.0 xf(2)=0.0 do i=3,n-1 xf(i)=(xp(i-1)+xp(i))/2.0 end do xf(n)=l
yf(1)=0.0 yf(2)=0.0 do j=3,m-1 yf(j)=(yp(j-1)+yp(j))/2.0 end do yf(m)=h !****** deltaxp(1)=0.0 do i=2,n deltaxp(i)= xp(i)-xp(i-1) end do
deltayp(1)=0.0 do j=2,m deltayp(j)= yp(j)-yp(j-1) end do end subroutine mesh
explain the code line by line and tell the details about all parameter that used in this fortran subroutine.
- Assistant
- User
exlpain line 7-8 with their formula.
- Assistant
Lines 7-8 in the code calculate the initial x-spacing, denoted as "deltax1", and set the first two x-coordinates, "xp(1)" and "xp(2)".
The formula used to calculate "deltax1" is:
deltax1 = l / 3.0 / ((eps**(n/3-1) - 1) / (eps - 1))
Explanation of the formula:
- "l" represents the length of the domain in the x-axis direction.
- "eps" is the refinement factor, which controls the rate of refinement towards the boundaries.
- "n" is the desired number of divisions along the x-axis.
- The formula inside the parentheses calculates the sum of a geometric series with a common ratio of "eps" and a total number of terms equal to "n/3 - 1". The formula for the sum of a geometric series is (a * (r^n - 1)) / (r - 1), where "a" is the first term and "r" is the common ratio.
- Finally, the formula divides the length of the domain by 3.0 and by the result of the geometric series calculation to obtain the initial x-spacing.
Once "deltax1" is calculated, it is assigned to "xp(1)" and "xp(2)" for the first two x-coordinates of the mesh. The subsequent x-coordinates (xp(i)) from 3 to n/3 are calculated by multiplying "deltax1" by the refinement factor (eps) and incrementing the previous x-coordinate.