fortran nnn

Download Fortran Nnn

Post on 30-Oct-2014

41 views

Category:

Documents

5 download

Embed Size (px)

TRANSCRIPT

Source File : Wave.F

Two Dimensional Wave Equation with inflow in x and periodic in y. 10 time frames of a circle moving up from the lower left corner and exit to the right boundary. | Input File |Note : Portions of Code that colored Red are essential for used with PseudoPack.

List of Routines

2D Wave Equation Main Program o #include "pseudopack.h" o Storage Allocation o Specify Leading Dimension o Setup Derived Data Type in x o Setup Differentiatial Operator in x o Setup Smoothing Operator in x o Setup Derived Data Type in y o Setup Differentiatial Operator in y o Setup Smoothing Operator in y Input Initial Conditions Time Step

Runge Kutta Scheme o Solution Smoothing call Flux o Differentiation call Boundary Conditions Graphic OutputBack to the Top |

! |

!-----! Demonstration Program for the use of PseudoPack. ! ! 2-D Scalar Wave Equation ! ! Chebyshev/Fourier Implementation ! ! 1: U_t+a*U_x+b*U_y=0 ! 2: U_t+y*U_x-x*U_y=0 ! ! ! Initial Condition : U(x,y,0) = Smoothed Gaussian ! Boundary Condition : Periodic in y direction ! Inflow/Outflow in x direction ! !-----c-----c Must include this include statement for used with Macros in pseudopack.h c-----#include "pseudopack.h" ! !============================================================ ! MODULE Initial_Parameter Integer :: Flux_Choice

REALTYPE :: Speed_x, Speed_y REALTYPE :: C_x, C_y, Radius_Ratio, Gaussian_Order REALTYPE :: Left_x, Right_x, Bottom_y, Top_y END MODULE Initial_Parameter ! !============================================================ ! Program Wave_2D USE PseudoPack USE Initial_Parameter implicit NONE

integer, parameter :: N_Frame = 10 Integer :: Index_x, Method_x, Point_Type_x, Max_Diff_x, Algorithm_x, Symmetry_x, N_x, BlockSize_x, Map_x, Manual_x, Map_F_x, Filter_Choice_D_x, Mode_CutOff_D_x, Smooth_1_D_x, Smooth_2_D_x, Filter_Choice_S_x, Mode_CutOff_S_x REALTYPE :: alpha_x, Angle_x, Omega_D_x, Order_D_x, Omega_S_x, Order_S_x Integer :: Index_y, Method_y, Point_Type_y, Max_Diff_y, Algorithm_y, Symmetry_y, N_y, BlockSize_y, Map_y, Manual_y, Map_F_y, Filter_Choice_D_y, Mode_CutOff_D_y, Smooth_1_D_y, Smooth_2_D_y, Filter_Choice_S_y, Mode_CutOff_S_y REALTYPE :: alpha_y, Angle_y, Omega_D_y, Order_D_y, Omega_S_y, Order_S_y Integer Integer logical REALTYPE REALTYPE, ! | Back REALTYPE, REALTYPE, TYPE TYPE TYPE TYPE TYPE :: :: :: :: N, M, LDY, M_D, M_S Step, N_Time_Step, N_Inc, Status BlowUp Time, Final_Time, dt, CFL & & & & & & & & & & & &

dimension(:,:), ALLOCATABLE :: u to the Top | dimension(:) , ALLOCATABLE :: x, y dimension(:) , ALLOCATABLE :: D_x, D_y, S_x, S_y :: :: :: :: :: Property Grid_Index Domain Mapping Filtering_D, Filtering_S

(PS_Property ) (PS_Grid_Index) (PS_Domain ) (PS_Mapping ) (PS_Filtering )

!-------------------------------------------------------------! First Executable Statement start here..... !-------------------------------------------------------------!-----! Input Data !-----call Input (7) N = N_x-1 M = N_y-1 Allocate (x(0:N), y(0:M), u(0:N,0:M)) ! | Back to the Top | !-----! Specify the leading dimension of the data array !-----LDY = SIZE(u, DIM=1)

!-----! Setup in x direction !-----call PS_Setup ( , Index=Index_x, Method=Method_x, & Algorithm=Algorithm_x, & Grid_Index=Grid_Index , N=N_x, M=N_y, LDY=LDY, & Mapping=Mapping , Map=Map_x) (Filtering_D , Filter_Choice_D_x) (Filtering_S , Filter_Choice_S_x) Property=Property

call PS_Setup_Filtering call PS_Setup_Filtering

call PS_Get_Operator_Size ('D', N_x, M_D, Property) Allocate (D_x(M_D)) call PS_Setup_Operator (N_x, D_x, x, Property, Grid_Index, & Mapping=Mapping, Filtering=Filtering_D)

call PS_Get_Operator_Size ('S', N_x, M_S, Filtering_S, Property) Allocate (S_x(M_S)) call PS_Setup_Operator (N_x, S_x, Property, Grid_Index, Filtering_S) !-----! Setup in y direction !-----call PS_Setup ( , Index=Index_y, Method=Method_y, Algorithm=Algorithm_y, Grid_Index=Grid_Index , N=N_y, M=N_x, LDY=LDY, Domain=Domain , x0=Bottom_y, x1=Top_y, Map_F=Map_F_y, Mapping=Mapping , Map=Map_y) (Filtering_D , Filter_Choice_D_y) (Filtering_S , Filter_Choice_S_y) Property=Property & & & & &

call PS_Setup_Filtering call PS_Setup_Filtering

call PS_Get_Operator_Size ('D', N_y, M_D, Property) Allocate (D_y(M_D)) call PS_Setup_Operator (N_y, D_y, y, Property, Grid_Index, Domain, Filtering=Filtering_D) call PS_Get_Operator_Size ('S', N_y, M_S, Filtering_S, Property) Allocate (S_y(M_S)) call PS_Setup_Operator (N_y, S_y, Property, Grid_Index, Filtering_S) !-----! Finished Setup !-----call Echo_Code_Information !-----! Compute Initial Condition !-----call Initial_Conditions (N, M, x, y, u, LDY) !------

&

! Compute Time Step dt !-----call Time_Step (N, M, x, y, u, LDY, CFL, dt) !-----! Output Initial Condition !-----OPEN OPEN OPEN OPEN (UNIT=10, (UNIT=11, (UNIT=12, (UNIT=13, FILE='wave_Movie.dat', FILE='wave.dat' , FILE='wave_Movie.m' , FILE='wave.m' , STATUS="UNKNOWN") STATUS="UNKNOWN") STATUS="UNKNOWN") STATUS="UNKNOWN") ; ; ; ; REWIND REWIND REWIND REWIND (10) (11) (12) (13)

Status = 0 call TecPlot call Matlab Status = 1

(N, M, Step, Time, x, y, u, LDY, Status, 10) (N, M, Step, Time, x, y, u, LDY, Status, 12)

N_Time_Step = INT(Final_Time/dt) N_Inc = MAX(N_Time_Step/(N_Frame-2),1) call Echo_Time_Step_Information !-----! Start the Runge Kutta Time Stepping !-----Step = 0 Time = 0 100 continue

Step = Step + 1 Time = Time + dt call RK_TVD (N, M, Time, dt, x, y, u, LDY, D_x, D_y, S_x, S_y) if (Step/N_Inc*N_Inc == Step) then write (6,*) 'The Current Step, Time is ',Step, Time call TecPlot call Matlab endif (N, M, Step, Time, x, y, u, LDY, Status, 10) (N, M, Step, Time, x, y, u, LDY, Status, 12) TWO ! Do not fool around with this variable

BlowUp = MAXVAL(ABS(u)) >

if (BlowUp) then Final_Time = Time write (6,*) write (6,*) '--------------------------------------------------' write (6,*) 'Stopped! Unstable Numerical Solution ....' write (6,*) '--------------------------------------------------' write (6,*) endif if (Time < Final_Time) goto 100

!-----! Output Data !-----call TecPlot call Matlab Status = 0 call TecPlot call Matlab

(N, M, Step, Time, x, y, u, LDY, Status, 10) (N, M, Step, Time, x, y, u, LDY, Status, 12) (N, M, Step, Time, x, y, u, LDY, Status, 11) (N, M, Step, Time, x, y, u, LDY, Status, 13)

call Echo_Final_Message CONTAINS ! | Back to the Top | Subroutine Input (LID) integer :: LID, IOS

OPEN (UNIT=LID, FILE='Wave.input', STATUS='OLD', IOSTAT=IOS) call PS_Input (Index_x, Method_x, Point_Type_x, Max_Diff_x, Algorithm_x, Symmetry_x, N_x, BlockSize_x, Left_x, Right_x, Map_F_x, Map_x, Manual_x, alpha_x, Angle_x, Filter_Choice_D_x, Mode_CutOff_D_x, Omega_D_x, Order_D_x, Smooth_1_D_x, Smooth_2_D_x, Filter_Choice_S_x, Mode_CutOff_S_x, Omega_S_x, Order_S_x, LID) call PS_Input (Index_y, Method_y, Point_Type_y, Max_Diff_y, Algorithm_y, Symmetry_y, N_y, BlockSize_y, Bottom_y, Top_y, Map_F_y, Map_y, Manual_y, alpha_y, Angle_y, Filter_Choice_D_y, Mode_CutOff_D_y, Omega_D_y, Order_D_y, Smooth_1_D_y, Smooth_2_D_y, Filter_Choice_S_y, Mode_CutOff_S_y, Omega_S_y, Order_S_y, LID) read read read read read read read read read read (LID,'(//)') (LID,*) Final_Time (LID,*) CFL (LID,'(//)') (LID,*) Flux_Choice (LID,*) (LID,*) Speed_x, Speed_y (LID,*) C_x, C_y (LID,*) Radius_Ratio (LID,*) Gaussian_Order & & & & & & & & & & & & & & & & & &

CLOSE (LID) if (Flux_Choice == 1) then

Speed_x = ONE ; Speed_y = ONE endif END Subroutine Input ! ================================================================== Subroutine Echo_Code_Information write (6,*) write (6,*) '--------------------------------------------------' write (6,*) if (OPERATOR_METHOD(D_x) == 0) & write (6,*) 'Method in x is Fourier' if (OPERATOR_METHOD(D_x) == 1) & write (6,*) 'Method in x is Chebyshev' if (OPERATOR_METHOD(D_x) == 2) & write (6,*) 'Method in x is Legendre ' if (OPERATOR_POINT_TYPE(D_x) == 1) & write (6,*) 'Point_type in x is Gauss-Lobatto' if (OPERATOR_POINT_TYPE(D_x) == 2) & write (6,*) 'Point_type in x is Gauss_Radau' if (OPERATOR_POINT_TYPE(D_x) == 3) & write (6,*) 'Point_type in x is Gauss' if (OPERATOR_ALGORITHM(D_x) == 0) & write (6,*) 'Algorithm in x is MXM' if (OPERATOR_ALGORITHM(D_x) == 1) & write (6,*) 'Algorithm in x is EOD' if (OPERATOR_ALGORITHM(D_x) == 2) & write (6,*) 'Algorithm in x is Transform' if (OPERATOR_METHOD(D_y) == 0) & write (6,*) 'Method in y is Fourier' if (OPERATOR_METHOD(D_y) == 1) & write (6,*) 'Method in y is Chebyshev' if (OPERATOR_METHOD(D_y) == 2) & write (6,*) 'Method in y is Legendre ' if (OPERATOR_POINT_TYPE(D_y) == 1) & write (6,*) 'Point_type in y is Gauss-Lobatto' if (OPERATOR_POINT_TYPE(D_y) == 2) & write (6,*) 'Point_type in y is Gauss_Radau' if (OPERATOR_POINT_TYPE(D_y) == 3) & write (6,*) 'Point_type in y is Gauss' if (OPERATOR_ALGORITHM(D_y) == 0) & write (6,*) 'Algorithm in y is MXM' if (OPERATOR_ALGORITHM(D_y) == 1) & write (6,*) 'Algorithm in y is EOD' if (OPERATOR_ALGORITHM(D_y) == 2) & write (6,*) 'Algorithm in y is Transform' write (6,*) write (6,*) '--------------------------------------------------' write (6,*) END Subroutine Echo_Code_Information ! ================================================================== Subroutine Echo_Time_Step_Information

write write write write write write write write write write write write

(6,*) (6,*) (6,*) (6,*) (6,*) (6,*) (6,*) (6,*) (6,*) (6,*) (6,*) (6,*)

'--------------------------------------------------' ' Time Step is ',dt ' Final Time is ',Final_Time 'Total Number of Time Step is ',int(Final_Time/dt) 'Frame Increment Time Step is ',N_Inc ' Number of Frame

Recommended

View more >