Changeset 2654 in lmdz_wrf
- Timestamp:
- Jul 2, 2019, 2:08:48 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/module_scientific.f90
r2641 r2654 19 19 ! crossingpoints_polys: Subroutine to provide the crossing points between two polygons 20 20 ! curl2D_1o: Subroutine to compute the first order curl of a 2D vectorial field 21 ! curl2D_c1o: Subroutine to compute the first order centered curl of a 2D vectorial field 21 22 ! distanceRK: Function to provide the distance between two points 22 23 ! divergence2D_1o: Subroutine to compute the first order divergence of a 2D vectorial field 24 ! divergence2D_c1o: Subroutine to compute the first order centered divergence of a 2D vectorial field 23 25 ! FindMinimumR_K*: Function returns the location of the minimum in the section between Start and End. 24 26 ! fill3DI_2Dvec: Subroutine to fill a 3D integer matrix from a series of indices from a 2D matrix 25 27 ! fill3DR_2Dvec: Subroutine to fill a 3D float matrix from a series of indices from a 2D matrix 26 28 ! gradient2D_1o: Subroutine to compute the first order gradient of a 2D field 29 ! gradient2D_c1o: Subroutine to compute the first order centered gradient of a 2D field 27 30 ! grid_within_polygon: Subroutine to determine which grid cells from a matrix lay inside a polygon 28 31 ! grid_spacepercen: Subroutine to compute the space-percentages of a series of grid cells (B) which lay inside another … … 40 43 ! intersection_2Dlines: Subroutine to provide the intersection point between two lines on the plane using Cramer's method 41 44 ! join_polygon: Subroutine to join two polygons 45 ! lap2D_1o: Subroutine to compute the first order laplacian of a 2D vectorial field 46 ! lap2D_c1o: Subroutine to compute the first order centered laplacian of a 2D vectorial field 42 47 ! look_clockwise_borders: Subroutine to look clock-wise for a next point within a collection of borders 43 48 ! (limits of a region) … … 7607 7612 SUBROUTINE gradient2D_1o(dx, dy, var, dsx, dsy, grad) 7608 7613 ! Subroutine to compute the first order gradient of a 2D field 7614 ! FROM: From: https://en.wikipedia.org/wiki/Finite_difference_coefficient 7609 7615 7610 7616 IMPLICIT NONE … … 7625 7631 fname = 'gradient2D_1o' 7626 7632 7627 grad = zeroRK 7633 grad = fillval64 7634 7635 DO i=1, dx-1 7636 DO j=1, dy-1 7637 grad(i,j,:) = (/ (var(i+1,j)-var(i,j))/dsx(i,j), (var(i,j+1)-var(i,j))/dsy(i,j) /) 7638 END DO 7639 END DO 7640 7641 END SUBROUTINE gradient2D_1o 7642 7643 SUBROUTINE gradient2D_c1o(dx, dy, var, dsx, dsy, grad) 7644 ! Subroutine to compute the first order centerd gradient of a 2D field 7645 7646 IMPLICIT NONE 7647 7648 INTEGER, INTENT(in) :: dx, dy 7649 REAL(r_k), DIMENSION(dx,dy), INTENT(in) :: var, dsx, dsy 7650 REAL(r_k), DIMENSION(dx,dy,2), INTENT(out) :: grad 7651 7652 ! Local 7653 INTEGER :: i, j 7654 REAL(r_k) :: d1x, d1y 7655 7656 !!!!!!! Variables 7657 ! dx, dy: shape of the 2D field 7658 ! var: variable 7659 ! dsx, dsy: matrices of distances betweeen grid points along each axis 7660 ! grad: gradient 7661 7662 fname = 'gradient2D_c1o' 7663 7664 grad = fillval64 7628 7665 7629 7666 DO i=2, dx-1 7630 7667 DO j=2, dy-1 7631 grad(i,j,:) = (/ (var(i+1,j)-var(i,j))/dsx(i,j), (var(i,j+1)-var(i,j))/dsy(i,j) /) 7668 d1x = 0.5*(var(i+1,j)-0.5*var(i-1,j))/dsx(i,j) 7669 d1y = 0.5*(var(i,j+1)-0.5*var(i,j-1))/dsy(i,j) 7670 grad(i,j,:) = (/ d1x, d1y /) 7632 7671 END DO 7633 7672 END DO 7634 7673 7635 END SUBROUTINE gradient2D_ 1o7674 END SUBROUTINE gradient2D_c1o 7636 7675 7637 7676 SUBROUTINE divergence2D_1o(dx, dy, dsx, dsy, xvar, yvar, diver) … … 7655 7694 fname = 'divergence2D_1o' 7656 7695 7657 diver = zeroRK 7696 diver = fillval64 7697 7698 DO i=1, dx-1 7699 DO j=1, dy-1 7700 diver(i,j) = (xvar(i+1,j)-xvar(i,j))/dsx(i,j) + (yvar(i,j+1)-yvar(i,j))/dsy(i,j) 7701 END DO 7702 END DO 7703 7704 END SUBROUTINE divergence2D_1o 7705 7706 SUBROUTINE divergence2D_c1o(dx, dy, dsx, dsy, xvar, yvar, diver) 7707 ! Subroutine to compute the first order centerd divergence of a 2D vectorial field 7708 7709 IMPLICIT NONE 7710 7711 INTEGER, INTENT(in) :: dx, dy 7712 REAL(r_k), DIMENSION(dx,dy), INTENT(in) :: xvar, yvar, dsx, dsy 7713 REAL(r_k), DIMENSION(dx,dy), INTENT(out) :: diver 7714 7715 ! Local 7716 INTEGER :: i, j 7717 REAL(r_k) :: d1x, d1y 7718 7719 !!!!!!! Variables 7720 ! dx, dy: shape of the 2D field 7721 ! xvar, yvar: x-y components of vectorial variable 7722 ! dsx, dsy: matrices of distances betweeen grid points along each axis 7723 ! diver: divergence 7724 7725 fname = 'divergence2D_c1o' 7726 7727 diver = fillval64 7658 7728 7659 7729 DO i=2, dx-1 7660 7730 DO j=2, dy-1 7661 diver(i,j) = (xvar(i+1,j)-xvar(i,j))/dsx(i,j) + (yvar(i,j+1)-yvar(i,j))/dsy(i,j) 7731 d1x = 0.5*(xvar(i+1,j)-0.5*xvar(i-1,j))/dsx(i,j) 7732 d1y = 0.5*(yvar(i,j+1)-0.5*yvar(i,j-1))/dsy(i,j) 7733 diver(i,j) = d1x + d1y 7662 7734 END DO 7663 7735 END DO 7664 7736 7665 END SUBROUTINE divergence2D_ 1o7737 END SUBROUTINE divergence2D_c1o 7666 7738 7667 7739 SUBROUTINE curl2D_1o(dx, dy, dsx, dsy, xvar, yvar, curl) … … 7685 7757 fname = 'curl2D_1o' 7686 7758 7687 curl = zeroRK7759 curl = fillval64 7688 7760 7689 7761 DO i=1, dx-1 … … 7695 7767 END SUBROUTINE curl2D_1o 7696 7768 7769 SUBROUTINE curl2D_c1o(dx, dy, dsx, dsy, xvar, yvar, curl) 7770 ! Subroutine to compute the first order centered curl of a 2D vectorial field 7771 7772 IMPLICIT NONE 7773 7774 INTEGER, INTENT(in) :: dx, dy 7775 REAL(r_k), DIMENSION(dx,dy), INTENT(in) :: xvar, yvar, dsx, dsy 7776 REAL(r_k), DIMENSION(dx,dy), INTENT(out) :: curl 7777 7778 ! Local 7779 INTEGER :: i, j 7780 REAL(r_k) :: d1x, d1y 7781 7782 !!!!!!! Variables 7783 ! dx, dy: shape of the 2D field 7784 ! xvar, yvar: x-y components of vectorial variable 7785 ! dsx, dsy: matrices of distances betweeen grid points along each axis 7786 ! curl: curl 7787 7788 fname = 'curl2D_c1o' 7789 7790 curl = fillval64 7791 7792 DO i=1, dx-1 7793 DO j=1, dy-1 7794 d1x = 0.5*(yvar(i+1,j)-0.5*yvar(i-1,j))/dsx(i,j) 7795 d1y = 0.5*(xvar(i,j+1)-0.5*xvar(i,j-1))/dsy(i,j) 7796 curl(i,j) = d1x - d1y 7797 END DO 7798 END DO 7799 7800 END SUBROUTINE curl2D_c1o 7801 7802 SUBROUTINE lap2D_1o(dx, dy, dsx, dsy, var, lap) 7803 ! Subroutine to compute the first order laplacian of a 2D vectorial field 7804 7805 IMPLICIT NONE 7806 7807 INTEGER, INTENT(in) :: dx, dy 7808 REAL(r_k), DIMENSION(dx,dy), INTENT(in) :: var, dsx, dsy 7809 REAL(r_k), DIMENSION(dx,dy), INTENT(out) :: lap 7810 7811 ! Local 7812 INTEGER :: i, j 7813 REAL(r_k) :: d2x, d2y 7814 7815 !!!!!!! Variables 7816 ! dx, dy: shape of the 2D field 7817 ! xvar, yvar: x-y components of vectorial variable 7818 ! dsx, dsy: matrices of distances betweeen grid points along each axis 7819 ! lap: laplacian 7820 7821 fname = 'curl2D_1o' 7822 7823 lap = fillval64 7824 7825 DO i=1, dx-2 7826 DO j=1, dy-2 7827 d2x = (1.*var(i,j)-2.*var(i+1,j)+1.*var(i+2,j))/(dsx(i,j)**2) 7828 d2y = (1.*var(i,j)-2.*var(i,j+1)+1.*var(i,j+2))/(dsy(i,j)**2) 7829 lap(i,j) = d2x+d2y 7830 END DO 7831 END DO 7832 7833 END SUBROUTINE lap2D_1o 7834 7835 7836 SUBROUTINE lap2D_c1o(dx, dy, dsx, dsy, var, lap) 7837 ! Subroutine to compute the first order centered laplacian of a 2D vectorial field 7838 7839 IMPLICIT NONE 7840 7841 INTEGER, INTENT(in) :: dx, dy 7842 REAL(r_k), DIMENSION(dx,dy), INTENT(in) :: var, dsx, dsy 7843 REAL(r_k), DIMENSION(dx,dy), INTENT(out) :: lap 7844 7845 ! Local 7846 INTEGER :: i, j 7847 REAL(r_k) :: d2x, d2y 7848 7849 !!!!!!! Variables 7850 ! dx, dy: shape of the 2D field 7851 ! xvar, yvar: x-y components of vectorial variable 7852 ! dsx, dsy: matrices of distances betweeen grid points along each axis 7853 ! lap: laplacian 7854 7855 fname = 'curl2D_c1o' 7856 7857 lap = fillval64 7858 7859 DO i=2, dx-1 7860 DO j=2, dy-1 7861 d2x = (1.*var(i-1,j)-2.*var(i,j)+1.*var(i+1,j))/(dsx(i,j)**2) 7862 d2y = (1.*var(i,j-1)-2.*var(i,j)+1.*var(i,j+1))/(dsy(i,j)**2) 7863 lap(i,j) = d2x+d2y 7864 END DO 7865 END DO 7866 7867 END SUBROUTINE lap2D_c1o 7868 7697 7869 END MODULE module_scientific
Note: See TracChangeset
for help on using the changeset viewer.