Hi I am having trouble with imposing boundary conditions on a 2 dimensional discretization problem in fortran. My discretization grid is a 2 dimensional square that goes from -L to L in x,y directions.
I want to impose the boundary condition such that, on the boundary line at x=L , the value of the function is specified. I also want to specify the boundary condition at the boundary line y=L. Then do the same for x,y=-L.
A basic attempt at the correct syntax is below. I am wondering if this syntax is correct and/or the quickest way at doing what I am doing. I assume there is a way to do it without do loops also using the colon notation just not sure how.
My syntax may be incorrect as I am unsure how to properly use the u(:) notation, or what the : really is doing for me. Thanks!
integer :: i,j
integer, parameter :: nx=60, ny=60
real, parameter :: h=0.1 !step size
real, dimension(-nx:nx,-ny:ny) :: u
real :: L
L=h*nx
do i = -nx, nx
x = real(i)*h
u(:,ny) = cos(atan(L/x)) ! is this correct?
u(:,-ny) = cos(atan((-L)/x))
end do
do j = -ny, ny
y = real(j)*h
u(nx, :) = cos(atan(y/L))
u(-nx, :) = cos(atan(y/(-L)))
end do