├── .gitignore ├── GPUConfig.h ├── GPUHeader.h ├── GPUMass_s.cu ├── GPUMoment_s.cu ├── GPUOpen_BD.cu ├── GPUOutput.cu ├── GPUall_grids.cu ├── GPUcomcot.cu ├── LICENSE ├── Makefile ├── README.md ├── all_grids.f90 ├── boundaries.f90 ├── comcot.ctl ├── comcot.f90 ├── debug_option.h ├── deform.f90 ├── dispersion.f90 ├── fault_multi.ctl ├── hotstart.f90 ├── initialization.f90 ├── landslide.ctl ├── landslide.f90 ├── mass.f90 ├── moment.f90 ├── output.f90 ├── plot_dat.py ├── ts_location.dat ├── ts_name.dat ├── type_module.f90 └── wavemaker.f90 /.gitignore: -------------------------------------------------------------------------------- 1 | # object files 2 | comcot 3 | GPUcomcot.o 4 | GPUMass_s.o 5 | GPUMoment_s.o 6 | GPUOpen_BD.o 7 | GPUOutput.o 8 | nvobj.o 9 | type_module.o 10 | comcot.o 11 | initialization.o 12 | output.o 13 | deform.o 14 | mass.o 15 | moment.o 16 | boundaries.o 17 | all_grids.o 18 | hotstart.o 19 | landslide.o 20 | wavemaker.o 21 | dispersion.o 22 | bci_params.mod 23 | fault_params.mod 24 | landslide_params.mod 25 | layer_params.mod 26 | wave_params.mod 27 | # data files & temporary files 28 | SIMULATION_INFO.TXT 29 | arrival_*.dat 30 | z_[0-9][0-9]_*.dat 31 | M1Layer*.txt 32 | [fhijmnvz]max_layer*.dat 33 | layer*.dat 34 | ini_surface.dat 35 | ts_record*.dat 36 | zmin_layer*.dat 37 | deform_seg[0-9][0-9][0-9].dat 38 | *_[0-9][0-9]_*.dat 39 | time.dat 40 | *.xyz 41 | *.swp 42 | *.png 43 | .metadata/* 44 | RemoteSystemsTempFiles/* 45 | -------------------------------------------------------------------------------- /GPUConfig.h: -------------------------------------------------------------------------------- 1 | #ifndef GPUCONF_H 2 | #define GPUCONF_H 3 | 4 | #define SM_CONFG 5 | #define LOAD_PER_SM 2 6 | #define NUMSTREAM 4 7 | extern cudaStream_t EXECstream[NUMSTREAM]; 8 | 9 | #define MOMT_KERNEL_CONFG 10 | #define BLOCKX 16 // ==> along column axis 11 | #define EXECX 15 // BLOCKX-1 12 | #define BLOCKY 16 // ==> along row axis 13 | #define EXECY 15// BLOCKY-1 14 | 15 | extern dim3 DimBlockMomt; 16 | extern dim3 DimGridMomt; 17 | 18 | #define BLOCKX_MOMT 512 19 | extern dim3 DimBlockMomt_MN; 20 | extern dim3 DimGridMomt_MN; 21 | 22 | #define BLOCKX_MASS 64 23 | extern dim3 DimBlockMass; 24 | extern dim3 DimGridMass; 25 | 26 | #define BLOCKX_JNZ 64 27 | #define DEBUG_DEPTH 32 28 | #define LOOPDEPTH DEBUG_DEPTH 29 | 30 | #define BLOCKX_OPENBD 64 31 | extern dim3 DimBlockOpenBD; 32 | extern dim3 DimGridOpenBD_LR; 33 | extern dim3 DimGridOpenBD_TB; 34 | 35 | #define MAXAMP_BLOCK 512 36 | extern size_t GridMaxAmp; 37 | 38 | #define BLOCKX_JNQ 128 39 | 40 | #endif /* GPUCONF_H */ 41 | -------------------------------------------------------------------------------- /GPUHeader.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "debug_option.h" 3 | #include "cuda.h" 4 | #include 5 | 6 | //#define DEBUG 7 | #ifdef DEBUG 8 | #ifndef DEBUG_FUNC 9 | #define DEBUG_FUNC 10 | #define ERROR 1.0e-4 11 | #define CHKR 720 12 | #define CHKC 304 13 | #define CHKSI 10 14 | extern float* tmpout; 15 | #endif 16 | #endif 17 | 18 | #ifndef CONSTS 19 | #define CONSTS 20 | #define GX 1.0e-5 21 | #define EPS 1.0e-10 22 | #define TWLVTH 0.0833333333333333333 23 | #define GRAV 9.807 24 | #endif 25 | 26 | 27 | #ifndef CUDA_CHK 28 | #define CUDA_CHK 29 | #define cudaCHK(FUN) ({\ 30 | if ((FUN) != cudaSuccess) {\ 31 | printf("%s in %s at line %d\n",cudaGetErrorString(cudaGetLastError()), __FILE__,__LINE__);\ 32 | exit(EXIT_FAILURE);\ 33 | }\ 34 | }) 35 | #define cudaERROR(err) ({\ 36 | if (err != cudaSuccess) {\ 37 | printf("error code: %d\n", err);\ 38 | printf("%s in %s at line %d\n",cudaGetErrorString(err), __FILE__,__LINE__);\ 39 | exit(EXIT_FAILURE);\ 40 | }\ 41 | }) 42 | #endif 43 | 44 | #ifndef CUDA_KERNEL 45 | #define CUDA_KERNEL 46 | #define ID(row,col) (col)*size_dev[0] + row 47 | #define ID2E(row,col,dim) size_dev[2]*(dim) + ID(row,col) 48 | #define ID_MATRIX(row,col,row_size) ((col)*(row_size) + (row)) 49 | #endif 50 | 51 | #define MAX_LAYERS 20 52 | struct GPU_Layer { 53 | int lid; 54 | int plid; 55 | int lvl; 56 | int rel_size; 57 | int rel_time; 58 | int corner[4]; 59 | float *Zdat_hst, *MNdat_hst; 60 | float *Zout_hst, *MNout_hst; 61 | float *R24_hst, *R35_hst, *H_hst; 62 | float *R_MASS_hst; 63 | float *Zmax_hst; 64 | float *yflux; 65 | float *xflux; 66 | uint32_t l_size[4]; 67 | float grx; 68 | float gry; 69 | 70 | dim3 DimGridJnz; 71 | dim3 DimBlockJnz; 72 | dim3 DimGridMomt_MN; 73 | dim3 DimGridMomt; 74 | dim3 DimGridMass; 75 | dim3 DimGridOpenBD_LR; 76 | dim3 DimGridOpenBD_TB; 77 | dim3 DimGrid_JNQV; 78 | dim3 DimGrid_JNQH; 79 | size_t GridMaxAmp; 80 | struct GPU_Layer *child; 81 | struct GPU_Layer *sibling; 82 | }; 83 | extern struct GPU_Layer Layer_struct[MAX_LAYERS]; 84 | 85 | extern struct GPU_Layer *Root_Grid; 86 | 87 | static inline struct GPU_Layer* ldlayer(int lid){ 88 | if (lid >= MAX_LAYERS || lid < 0) { 89 | printf("invalid layer id %d\n", lid); 90 | return NULL; 91 | } 92 | return Layer_struct + lid; 93 | } 94 | 95 | extern "C" void mass_launch_(const float* Z_f, float* Z_f_complete, const float *H_f, const int *lid); 96 | extern "C" void momt_launch_(float*,float*,float*, const int*); 97 | extern "C" void cuda_update_layer_(int *lid); 98 | 99 | #ifndef CUDA_GLOB_VAR 100 | extern __constant__ __device__ uint32_t all_size_dev[MAX_LAYERS][4]; 101 | extern uint32_t all_size[MAX_LAYERS][4]; // mirror of all_size_dev 102 | extern cudaDeviceProp dev_prop; 103 | #endif 104 | 105 | #ifdef RELDIFF 106 | static inline bool assert_diff(float base, float eval) { 107 | if (base == 0.0f) { 108 | if (eval != 0.0f) 109 | return true; 110 | else 111 | return false; 112 | } 113 | 114 | if (fabs((eval - base) / base) >= DIFFRATE) 115 | return true; 116 | else 117 | return false; 118 | } 119 | #else 120 | static inline bool assert_diff(float base, float eval) { 121 | if (fabs(eval - base) >= TOLERANCE) 122 | return true; 123 | else 124 | return false; 125 | } 126 | #endif /* RELDIFF */ 127 | 128 | #define CMP_VAR(cmpp, varp, row, col, str,...) { \ 129 | for (size_t j = 0; j < col; j++) { \ 130 | for (size_t i = 0; i < row; i++) { \ 131 | size_t id = j*(row) + i; \ 132 | double diff = fabs((cmpp)[id] - (varp)[id]); \ 133 | if (assert_diff((cmpp)[id], (varp)[id])) { \ 134 | printf(str, __VA_ARGS__); \ 135 | printf("(i,j)=(%zu,%zu), %f %f, diff=%lf ", \ 136 | i, j, (cmpp)[id], (varp)[id], diff); \ 137 | printf("%x, %x\n", *(unsigned int*)((cmpp) + id),\ 138 | *(unsigned int*)((varp) + id)); \ 139 | } \ 140 | } \ 141 | } \ 142 | } 143 | 144 | static inline bool ispow2(unsigned int val) { 145 | // returns true if val is power of 2 146 | return !(val & (val - 1)); 147 | } 148 | 149 | -------------------------------------------------------------------------------- /GPUMass_s.cu: -------------------------------------------------------------------------------- 1 | #include "GPUHeader.h" 2 | #include "GPUConfig.h" 3 | #include "debug_option.h" 4 | 5 | __global__ void mass_kernel(struct GPU_Layer); 6 | 7 | 8 | 9 | extern "C" void mass_launch_(const float* Z_f, float* Z_f_complete, const float *H_f, const int *lid){ 10 | cudaError_t err; 11 | clock_t st, fi; 12 | struct GPU_Layer *L = ldlayer(*lid); 13 | 14 | st = clock(); 15 | mass_kernel <<< L->DimGridMass, DimBlockMass >>> (*L); 16 | cudaDeviceSynchronize(); 17 | err = cudaGetLastError(); 18 | cudaERROR(err); 19 | fi = clock(); 20 | 21 | #ifdef DEBUG_CORE 22 | float *z_cmp; 23 | printf("TIME SPENT ON GPU (MASS) %f\n",(float)(fi-st)/CLOCKS_PER_SEC); 24 | z_cmp = (float*) malloc(L->l_size[3]); 25 | cudaCHK( cudaMemcpy(z_cmp, L->Zout_hst, L->l_size[3], cudaMemcpyDeviceToHost) ); 26 | for (size_t id = 0; id < L->l_size[2]; id++) { 27 | if (assert_diff(z_cmp[id], Z_f_complete[id])) { 28 | printf("(mass, layerid=%d) i = %d, %f, %f, diff=%f\n", 29 | *lid, 30 | id, 31 | z_cmp[id], Z_f_complete[id], 32 | fabs(z_cmp[id] - Z_f_complete[id])); 33 | } 34 | } 35 | free(z_cmp); 36 | #endif /* DEBUG_CORE */ 37 | } 38 | 39 | __global__ void mass_kernel(struct GPU_Layer L){ 40 | /*+-->+-->+---->| 41 | +-->+-->+---->| 42 | +-->+-->+---->| 43 | +-->+-->+---->| 44 | */ 45 | 46 | const float* __restrict__ Z = L.Zdat_hst; 47 | const float* __restrict__ MN = L.MNdat_hst; 48 | const float* __restrict__ R_MASS = L.R_MASS_hst; 49 | const float* __restrict__ H = L.H_hst; 50 | const uint32_t __restrict__ *size_dev = all_size_dev[L.lid]; 51 | float* __restrict__ Z_out_dev = L.Zout_hst; 52 | 53 | //designed for architectures whose warpsize=32 54 | uint32_t row = blockIdx.x*31*(blockDim.x>>5) + 31*(threadIdx.x>>5) + threadIdx.x%32; 55 | uint32_t col = blockIdx.y*(size_dev[1]/gridDim.y); 56 | uint32_t col_end, row_end; 57 | float h,z; 58 | float m, m_suf; 59 | float n, n_prev; 60 | float ztmp; 61 | float r1, r11; 62 | float r6, r6_prev; 63 | 64 | if (L.lid == 1) { 65 | col_end = (blockIdx.y == gridDim.y-1)? 66 | size_dev[1] - 1:(blockIdx.y+1)*(size_dev[1]/gridDim.y)+1; 67 | row_end = size_dev[0]-1; 68 | } else { 69 | col_end = (blockIdx.y == gridDim.y-1)? 70 | size_dev[1]:(blockIdx.y+1)*(size_dev[1]/gridDim.y)+1; 71 | row_end = size_dev[0]; 72 | } 73 | 74 | n_prev = MN[ID2E(row,col,1)]; 75 | r6_prev = R_MASS[col*4+1]; 76 | 77 | for (uint32_t i = col+1; i < col_end; i++) { 78 | if (threadIdx.x%32 == 0) { 79 | r1 = R_MASS[i*4]; 80 | r6 = R_MASS[i*4+1]; 81 | r11 = R_MASS[i*4+2]; 82 | } 83 | __syncwarp(); 84 | r1 = __shfl_sync(0xFFFFFFFF,r1,0); 85 | r6 = __shfl_sync(0xFFFFFFFF,r6,0); 86 | r11 = __shfl_sync(0xFFFFFFFF,r11,0); 87 | m = MN[ID(row,i)]; 88 | h = H[ID(row,i)]; 89 | z = Z[ID(row,i)]; 90 | n = MN[ID2E(row,i,1)]; 91 | m_suf = __shfl_up_sync(0xFFFFFFFF,m,1); 92 | if (threadIdx.x%32 != 0 && row < row_end) { 93 | ztmp = z - r1*(m-m_suf) - r11*(n*r6-n_prev*r6_prev); 94 | if (ztmp + h <= EPS) ztmp = -h; 95 | if (h <= GX || (ztmp < EPS && -ztmp < EPS) ) ztmp = 0.0; 96 | Z_out_dev[ID(row,i)] = ztmp; 97 | 98 | r6_prev = r6; 99 | n_prev = n; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /GPUMoment_s.cu: -------------------------------------------------------------------------------- 1 | #include "GPUHeader.h" 2 | #include "GPUConfig.h" 3 | #include "debug_option.h" 4 | 5 | __global__ void momts_kernel(const float* __restrict__,const float* __restrict__, 6 | const float* __restrict__,const float* __restrict__,const float* __restrict__); 7 | __global__ void momt_kernelM(struct GPU_Layer L); 8 | __global__ void momt_kernelN(struct GPU_Layer L); 9 | 10 | extern "C" void momt_launch_(float *M_f, float *N_f, float *Z_f, const int *lid) { 11 | float* tmp; 12 | clock_t st, fi; 13 | cudaError_t err; 14 | struct GPU_Layer *L = ldlayer(*lid); 15 | 16 | st = clock(); 17 | momt_kernelM <<< L->DimGridMomt_MN, DimBlockMomt_MN, 0, EXECstream[0] >>> (*L); 18 | momt_kernelN <<< L->DimGridMomt_MN, DimBlockMomt_MN, 0, EXECstream[1] >>> (*L); 19 | cudaDeviceSynchronize(); 20 | err = cudaGetLastError(); 21 | cudaERROR(err); 22 | fi = clock(); 23 | 24 | #ifdef DEBUG_CORE 25 | float *mn_cmp; 26 | printf("TIME SPENT ON GPU (MOMT->%d) %f\n",(float)(fi-st)/CLOCKS_PER_SEC, L->lid); 27 | 28 | mn_cmp = (float*) malloc(2*L->l_size[3]); 29 | cudaCHK( cudaMemcpy( 30 | mn_cmp, L->MNout_hst, 2*L->l_size[3], cudaMemcpyDeviceToHost) ); 31 | 32 | CMP_VAR(mn_cmp, M_f, L->l_size[0], L->l_size[1], "(momt-m, layer-id=%d)", L->lid); 33 | CMP_VAR(mn_cmp+L->l_size[2], N_f, L->l_size[0], L->l_size[1], "(momt-n, layer-id=%d)", L->lid); 34 | 35 | // for (size_t id = 0; id < L->l_size[2]; id++) { 36 | // if (fabs(mn_cmp[id] - M_f[id]) >= TOLERANCE) { 37 | // printf("(momt-m, layerid=%d) i = %d, %f, %f, diff=%f\n", 38 | // *lid, 39 | // id, 40 | // mn_cmp[id], M_f[id], 41 | // fabs(mn_cmp[id] - M_f[id])); 42 | // } 43 | // } 44 | // for (size_t id = 0; id < L->l_size[2]; id++) { 45 | // if (fabs(mn_cmp[id + L->l_size[2]] - N_f[id]) >= TOLERANCE) { 46 | // printf("(momt-n, layerid=%d) i = %d, %f, %f, diff=%f\n", 47 | // *lid, 48 | // id, 49 | // mn_cmp[id + L->l_size[2]], N_f[id], 50 | // fabs(mn_cmp[id + L->l_size[2]] - N_f[id])); 51 | // } 52 | // } 53 | free(mn_cmp); 54 | #endif /* DEBUG_CORE */ 55 | 56 | } 57 | 58 | __global__ void momt_kernelM(const struct GPU_Layer L) 59 | { 60 | const float* __restrict__ Z = L.Zout_hst; 61 | const float* __restrict__ MN = L.MNdat_hst; 62 | const float* __restrict__ R2 = L.R24_hst; 63 | const float* __restrict__ R3 = L.R35_hst; 64 | const float* __restrict__ H = L.H_hst; 65 | float* __restrict__ MN_out_dev = L.MNout_hst; 66 | const uint32_t __restrict__ *size_dev = all_size_dev[L.lid]; 67 | 68 | 69 | uint32_t row = blockIdx.x*31*(blockDim.x>>5) + 31*(threadIdx.x>>5) + threadIdx.x%32; 70 | uint32_t col = blockIdx.y*(size_dev[1]/gridDim.y); 71 | uint32_t col_end = (blockIdx.y == gridDim.y-1)? size_dev[1]:(blockIdx.y+1)*(size_dev[1]/gridDim.y)+1; 72 | 73 | // memory operands ==================================== 74 | float n_prev, n; // prev-->stored for next loop 75 | float n_ip1jm1_prev, n_ip1;// n shuffle 76 | //Z 77 | float z; //independant load 78 | float z_ip1; //Z shuffle 79 | //H 80 | float h; //independant load 81 | float h_ip1; //H shuffle 82 | 83 | float m, r2; //independant loads 84 | float r3; //boardcast 85 | //===================================================== 86 | // computation operands =============================== 87 | float tot_n; 88 | float xm; 89 | //===================================================== 90 | 91 | // we can simply return since there is no `im1` 92 | if (row == 0 && L.lid != 1) 93 | return; 94 | 95 | if (row < size_dev[0]) { //lower bound of threads 96 | n_prev = MN[ID2E(row,col,1)]; 97 | n_ip1jm1_prev = __shfl_down_sync(0xFFFFFFFF, n_prev,1); 98 | if (col != 0 || L.lid != 1) col+= 1; // not start at left boundary (consider jm1 at j == 0) 99 | for (uint32_t j = col; j < col_end; j++) { //grid striding 100 | // if (threadIdx.x%32 == 31) { 101 | // r3 = R3[j]; 102 | // } 103 | // __syncwarp(); 104 | // r3 = __shfl_sync(0xFFFFFFFF,r3,31); 105 | r3 = R3[j]; 106 | n = MN[ID2E(row,j,1)]; 107 | h = H[ID(row,j)]; 108 | z = Z[ID(row,j)]; 109 | // __syncwarp(); 110 | 111 | n_ip1 = __shfl_down_sync(0xFFFFFFFF, n,1); 112 | z_ip1 = __shfl_down_sync(0xFFFFFFFF, z,1); 113 | h_ip1 = __shfl_down_sync(0xFFFFFFFF, h,1); 114 | 115 | if (threadIdx.x%32 != 31 && row < size_dev[0]-1) { //lower bound of lanes & computation 116 | if (h > GX && h_ip1 > GX) { 117 | m = MN[ID(row,j)]; 118 | r2 = R2[ID(row,j)]; 119 | 120 | tot_n = n + n_ip1 + n_prev + n_ip1jm1_prev; 121 | xm = m - r2*(z_ip1 - z) + r3*tot_n; 122 | if (xm < EPS && xm > -EPS) xm = 0.0f; 123 | MN_out_dev[ID(row,j)] = xm; 124 | 125 | }else{ 126 | MN_out_dev[ID(row,j)] = 0.0f; 127 | } 128 | // if (row == 1495 && L.lid == 2 && j == 50) { 129 | // printf("[%d,%d]===============================[row,j][%d,%d]\n",threadIdx.x,blockIdx.x,row,j ); 130 | // printf("%e\t%e\t%e\t%e\t%e\t%e\n",r2,r3,n,n_ip1,n_prev,n_ip1jm1_prev); 131 | // printf("%e\t%e\t%e\n",m,z_ip1,z); 132 | // } 133 | 134 | } 135 | n_prev = n; 136 | n_ip1jm1_prev = n_ip1; 137 | } 138 | } 139 | } 140 | 141 | 142 | 143 | __global__ void momt_kernelN(const struct GPU_Layer L) 144 | { 145 | const float* __restrict__ Z = L.Zout_hst; 146 | const float* __restrict__ MN = L.MNdat_hst; 147 | const float* __restrict__ R4 = L.R24_hst + L.l_size[2]; 148 | const float* __restrict__ R5 = L.R35_hst + L.l_size[1]; 149 | const float* __restrict__ H = L.H_hst; 150 | float* __restrict__ MN_out_dev = L.MNout_hst; 151 | const uint32_t __restrict__ *size_dev = all_size_dev[L.lid]; 152 | 153 | 154 | uint32_t row = blockIdx.x*31*(blockDim.x>>5) + 31*(threadIdx.x>>5) + threadIdx.x%32; 155 | uint32_t col = blockIdx.y*(size_dev[1]/gridDim.y); 156 | uint32_t col_end = (blockIdx.y == gridDim.y-1)? size_dev[1]-1:(blockIdx.y+1)*(size_dev[1]/gridDim.y)+1; 157 | 158 | // memory operands ==================================== 'prev' variable should be kept in registers 159 | float m_im1, m_im1jp1_prev; // m shuffle & prev-->stored for next loop 160 | float m, m_jp1_prev; // independant loas + prevload 161 | //Z 162 | float z, z_jp1_prev; //independant load + prevload 163 | //H 164 | float h, h_jp1_prev; //independant load + prevload 165 | 166 | float n, r4; //independant loads 167 | float r5; //boardcast 168 | //===================================================== 169 | // computation operands =============================== 170 | float tot_m; 171 | float xn; 172 | //===================================================== 173 | bool write = true; 174 | 175 | if (L.lid != 1 && row == 0) 176 | write = false; 177 | 178 | if (L.lid != 1 && col == 0) 179 | col = 1; 180 | 181 | if (row < size_dev[0]) { //lower bound of threads; 182 | m_jp1_prev = MN[ID(row,col_end)]; 183 | m_im1jp1_prev = __shfl_up_sync(0xFFFFFFFF, m_jp1_prev,1); 184 | 185 | z_jp1_prev = Z[ID(row,col_end)]; 186 | h_jp1_prev = H[ID(row,col_end)]; 187 | // !! bug fixed: note that comparison of unsigned expression >= 0 is always true 188 | for (int j = (int)col_end-1; j >= (int)col; j--) { //grid striding 189 | // if (threadIdx.x%32 == 0) { 190 | // r5 = R5[j]; 191 | // } 192 | // __syncwarp(); 193 | // r5 = __shfl_sync(0xFFFFFFFF,r5,0); 194 | r5 = R5[j]; 195 | m = MN[ID(row,j)]; 196 | h = H[ID(row,j)]; 197 | m_im1 = __shfl_up_sync(0xFFFFFFFF,m,1); 198 | 199 | // if (L.lid != 1 && (row == 0 || j == 0)) { 200 | // write = false; 201 | // } 202 | 203 | if (threadIdx.x%32 != 0 || row == 0) { //upper bound of lanes 204 | r4 = R4[ID(row,j)]; 205 | z = Z[ID(row,j)]; 206 | n = MN[ID2E(row,j,1)]; 207 | if (h > GX && h_jp1_prev > GX) { 208 | if (row != 0) tot_m = m_im1 + m_im1jp1_prev + m + m_jp1_prev; 209 | else tot_m = 2.0*(m + m_jp1_prev); // upper bound of the computation 210 | xn = n - r4*(z_jp1_prev -z) - r5*tot_m; 211 | 212 | // if (row == 449 && j == 782) { 213 | // printf("[%d,%d]===============================[row,j][%d,%d]\n",threadIdx.x,blockIdx.x,row,j ); 214 | // printf("%e\t%e\t%e\t%e\t%e\t%e\n",r4, r5, m, m_jp1_prev, m_im1jp1_prev, m_im1); 215 | // printf("%e\t%e\t%e\n",n,z_jp1_prev,z); 216 | // } 217 | 218 | if (xn < EPS && xn > -EPS) xn = 0.0f; 219 | if (write) 220 | MN_out_dev[ID2E(row,j,1)] = xn; 221 | }else{ 222 | if (write) 223 | MN_out_dev[ID2E(row,j,1)] = 0.0f; 224 | } 225 | m_jp1_prev = m; 226 | m_im1jp1_prev = m_im1; 227 | z_jp1_prev = z; 228 | h_jp1_prev = h; 229 | } 230 | } 231 | } 232 | 233 | 234 | 235 | } 236 | -------------------------------------------------------------------------------- /GPUOpen_BD.cu: -------------------------------------------------------------------------------- 1 | #include "GPUHeader.h" 2 | #include "GPUConfig.h" 3 | 4 | typedef enum bd_side{ 5 | LEFT, 6 | RIGHT, 7 | TOP, 8 | BOTTOM, 9 | } bdside; 10 | 11 | __global__ void openbd_kernel(struct GPU_Layer, bdside); 12 | 13 | extern "C" void openbd_launch_(float *Z_f_complete) { 14 | /* Only for outest layer, assume its layerid = 0 */ 15 | struct GPU_Layer *L = ldlayer(1); 16 | 17 | cudaError_t err; 18 | openbd_kernel<<< L->DimGridOpenBD_LR, DimBlockOpenBD, 0, EXECstream[0] >>>(*L, LEFT);// MN has been changed (:,:,1) <--> (:,:,2) 19 | openbd_kernel<<< L->DimGridOpenBD_LR, DimBlockOpenBD, 0, EXECstream[1] >>>(*L, RIGHT);// so use M(:,:,1) directly 20 | openbd_kernel<<< L->DimGridOpenBD_TB, DimBlockOpenBD, 0, EXECstream[2] >>>(*L, TOP); 21 | openbd_kernel<<< L->DimGridOpenBD_TB, DimBlockOpenBD, 0, EXECstream[3] >>>(*L, BOTTOM); 22 | cudaDeviceSynchronize(); 23 | err = cudaGetLastError(); 24 | cudaERROR(err); 25 | 26 | 27 | #ifdef DEBUG 28 | printf("printing information for debugging\n" ); 29 | cudaCHK( cudaMemcpy(tmpout, Zout_hst, l_size[3], cudaMemcpyDeviceToHost) ); 30 | for (size_t i = 0; i < l_size[2]; i++) { 31 | if (abs(tmpout[i] - Z_f_complete[i]) > ERROR) { 32 | printf("Z[%d,%d] Z_cu:%e Z_f:%e %e\n", i%l_size[0], i/l_size[0] , tmpout[i], Z_f_complete[i], tmpout[i] - Z_f_complete[i]); 33 | } 34 | } 35 | #endif /* DEBUG */ 36 | 37 | } 38 | 39 | 40 | __global__ void openbd_kernel(struct GPU_Layer L, bdside BOUNDARY) { 41 | 42 | const float* __restrict__ MN = L.MNdat_hst; 43 | const float* __restrict__ H = L.H_hst; 44 | float* __restrict__ Z_out_dev = L.Zout_hst; 45 | const uint32_t __restrict__ *size_dev = all_size_dev[L.lid]; 46 | 47 | #define UB 99.0 48 | float ztmp=0.0, h, m, n, cc; 49 | uint32_t row=0, col=0; 50 | switch (BOUNDARY) { 51 | case RIGHT: 52 | col = (size_dev[1]-1)*size_dev[0]; 53 | row = blockIdx.x*31*(blockDim.x>>5) + 31*(threadIdx.x>>5) + threadIdx.x%32; 54 | if (row < size_dev[0]-1) { 55 | h = H[row+col]; 56 | m = MN[row+col];// must not load in the following if block, or 1st lane would get 0 57 | float m_suf = __shfl_up_sync(0xFFFFFFFF,m,1);// must not shuffle in the following if block, or 1st lane would get 0 58 | n = MN[row+col-size_dev[0]+size_dev[2]]; 59 | cc = 1/sqrtf(GRAV*h); 60 | if (threadIdx.x % 32 != 0) { 61 | if (h > GX) { 62 | float uh_2 = 0.25*(m+m_suf)*(m+m_suf); 63 | ztmp = sqrtf(n*n + uh_2)*cc; 64 | if (n < 0.0) ztmp *= -1; 65 | if (ztmp > UB || ztmp < -UB) ztmp = 0.0; 66 | }// else {ztmp=0.0;} 67 | Z_out_dev[row+col] = ztmp; 68 | } 69 | else if (row == 0) { // --| 70 | if (h > GX) { 71 | ztmp = sqrtf(m*m + n*n)*cc; 72 | if (m > 0 || n < 0) ztmp *= -1; 73 | if (ztmp > UB || ztmp < -UB) ztmp = 0.0; 74 | } 75 | Z_out_dev[col] = ztmp; 76 | } 77 | } 78 | break; 79 | case LEFT: 80 | row = blockIdx.x*31*(blockDim.x>>5) + 31*(threadIdx.x>>5) + threadIdx.x%32; 81 | if (row < size_dev[0]-1) { 82 | h = H[row]; 83 | m = MN[row]; 84 | float m_suf = __shfl_up_sync(0xFFFFFFFF,m,1); 85 | n = MN[row+size_dev[2]]; 86 | cc = 1/sqrtf(GRAV*h); 87 | if (threadIdx.x % 32 != 0) { 88 | if (h > GX) { 89 | float uh_2 = 0.25*(m+m_suf)*(m+m_suf); 90 | ztmp = sqrtf(n*n + uh_2)*cc; 91 | if (n > 0.0) ztmp *= -1; 92 | if (ztmp > UB || ztmp < -UB) ztmp = 0.0; 93 | }// else {ztmp=0.0;} 94 | Z_out_dev[row] = ztmp; 95 | } 96 | else if (row == 0) {// |-- 97 | if (h > GX) { 98 | ztmp = sqrtf(m*m + n*n)*cc; 99 | if (m > 0 || n < 0) ztmp *= -1; 100 | if (ztmp > UB || ztmp < -UB) ztmp = 0.0; 101 | } 102 | Z_out_dev[col] = ztmp; 103 | } 104 | } 105 | break; 106 | case TOP: // should use texture 107 | col = blockIdx.x*31*(blockDim.x>>5) + 31*(threadIdx.x>>5) + threadIdx.x%32; 108 | if (col < size_dev[1]-1 && col > 0) { 109 | col *= size_dev[0]; 110 | h = H[col]; 111 | n = MN[col+size_dev[2]]; 112 | float n_suf = __shfl_up_sync(0xFFFFFFFF,n,1); 113 | if (threadIdx.x%32 != 0) { 114 | if (h > GX) { 115 | m = MN[col]; 116 | cc = 1/sqrtf(GRAV*h); 117 | float uh_2 = 0.25*(n+n_suf)*(n+n_suf); 118 | 119 | ztmp = sqrtf(uh_2 + m*m)*cc; 120 | if (m > 0.0) ztmp *= -1; 121 | if (ztmp > UB || ztmp < -UB) ztmp = 0.0; 122 | } 123 | Z_out_dev[col] = ztmp; 124 | } 125 | } 126 | break; 127 | case BOTTOM: 128 | row = size_dev[0]-1; 129 | col = blockIdx.x*31*(blockDim.x>>5) + 31*(threadIdx.x>>5) + threadIdx.x%32; 130 | 131 | if (col < size_dev[1]-1 && col > 0) { //bottom body 132 | col *= size_dev[0]; 133 | h = H[col+row]; 134 | n = MN[col+row+size_dev[2]]; 135 | float n_suf = __shfl_up_sync(0xFFFFFFFF,n,1); 136 | if (threadIdx.x%32 != 0) { 137 | if (h > GX) { 138 | m = MN[col+row-1]; 139 | cc = 1/sqrtf(GRAV*h); 140 | float uh_2 = 0.25*(n+n_suf)*(n+n_suf); 141 | 142 | ztmp = sqrtf(uh_2 + m*m)*cc; 143 | if (m < 0.0) ztmp *= -1; 144 | if (ztmp > UB || ztmp < -UB) ztmp = 0.0; 145 | } 146 | Z_out_dev[col+row] = ztmp; 147 | } 148 | }else if (col == 0 || col == size_dev[1]-1){ // bottom boundary 149 | uint32_t id = row+col*size_dev[0]; 150 | h = H[id]; 151 | if (h > GX) { 152 | cc = 1/sqrtf(GRAV*h); 153 | m = MN[id-1]; 154 | if (col == 0) { // |__ 155 | n = MN[row+size_dev[2]]; 156 | ztmp = sqrtf(m*m + n*n); 157 | ztmp *= cc; 158 | if (m < 0.0 || n > 0.0) ztmp *= -1; 159 | if (ztmp > UB || ztmp < -UB) ztmp = 0.0; 160 | }else{ // __| 161 | n = MN[row + (col-1)*size_dev[0] + size_dev[2]]; 162 | ztmp = sqrtf(m*m + n*n); 163 | ztmp *= cc; 164 | if (m < 0.0 || n < 0.0) ztmp *= -1; 165 | if (ztmp > UB || ztmp < -UB) ztmp = 0.0; 166 | } 167 | } 168 | Z_out_dev[id] = ztmp; 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /GPUOutput.cu: -------------------------------------------------------------------------------- 1 | #include "GPUHeader.h" 2 | #include "GPUConfig.h" 3 | 4 | extern "C" void maxamp_launch_(const int *); 5 | __global__ void maximum_recorder_kernel(float *, const float * __restrict__ , const uint32_t); 6 | extern "C" void cuda_getz_(float *, int *); 7 | extern "C" void cuda_getmn_(float *,float *, int *); 8 | extern "C" void cuda_getzmax_(float *, int *); 9 | 10 | 11 | extern "C" void maxamp_launch_(const int *lid){ 12 | clock_t st, fi; 13 | cudaError_t err; 14 | struct GPU_Layer *L = ldlayer(*lid); 15 | 16 | st = clock(); 17 | maximum_recorder_kernel <<< L->GridMaxAmp, MAXAMP_BLOCK >>> (L->Zmax_hst, L->Zout_hst, L->l_size[2]); 18 | cudaDeviceSynchronize(); 19 | err = cudaGetLastError(); 20 | cudaERROR(err); 21 | fi = clock(); 22 | 23 | #ifdef DEBUG 24 | printf("GPU MAX_AMP\n" ); 25 | printf("TIME SPENT ON GPU %f\n",(float)(fi-st)/CLOCKS_PER_SEC); 26 | #endif 27 | } 28 | 29 | extern "C" void gcomcot_get_z_(int *lid, float *l1, float *l2, 30 | float *l3, float *l4, 31 | int *i, int *j) 32 | { 33 | struct GPU_Layer *L = ldlayer(*lid); 34 | float tmp[2]; 35 | cudaCHK( cudaMemcpy(tmp, L->Zout_hst + L->l_size[0] * (*j - 1) + (*i - 1), 36 | 2 * sizeof(float), cudaMemcpyDeviceToHost) ); 37 | *l1 = tmp[0]; 38 | *l2 = tmp[1]; 39 | cudaCHK( cudaMemcpy(tmp, L->Zout_hst + L->l_size[0] * (*j) + (*i - 1), 40 | 2 * sizeof(float), cudaMemcpyDeviceToHost) ); 41 | *l3 = tmp[0]; 42 | *l4 = tmp[1]; 43 | return; 44 | } 45 | 46 | __global__ void maximum_recorder_kernel(float *max_array, const float* __restrict__ array, const uint32_t array_size){ 47 | uint32_t id=blockIdx.x*blockDim.x + threadIdx.x; 48 | if (id < array_size) { 49 | float current_max_value = max_array[id]; 50 | if (current_max_value >= array[id]) return; 51 | else max_array[id] = array[id]; 52 | } 53 | } 54 | 55 | extern "C" void cuda_getz1_(float *Z_f, int *lid) { 56 | struct GPU_Layer *L = ldlayer(*lid); 57 | cudaCHK( cudaMemcpy(Z_f, L->Zdat_hst, L->l_size[3], cudaMemcpyDeviceToHost) ); 58 | } 59 | 60 | extern "C" void cuda_setz1_(float *Z_f, int *lid) { 61 | struct GPU_Layer *L = ldlayer(*lid); 62 | cudaCHK( cudaMemcpy(L->Zdat_hst, Z_f, L->l_size[3], cudaMemcpyHostToDevice) ); 63 | } 64 | 65 | extern "C" void cuda_getz_(float *Z_f, int *lid) { 66 | struct GPU_Layer *L = ldlayer(*lid); 67 | cudaCHK( cudaMemcpy(Z_f, L->Zout_hst, L->l_size[3], cudaMemcpyDeviceToHost) ); 68 | } 69 | 70 | extern "C" void cuda_setz_(float *Z_f, int *lid) { 71 | struct GPU_Layer *L = ldlayer(*lid); 72 | cudaCHK( cudaMemcpy(L->Zout_hst, Z_f, L->l_size[3], cudaMemcpyHostToDevice) ); 73 | } 74 | 75 | extern "C" void cuda_getmn1_(float *M_f, float *N_f, int *lid) { 76 | struct GPU_Layer *L = ldlayer(*lid); 77 | cudaCHK( cudaMemcpy(M_f, L->MNdat_hst, L->l_size[3], cudaMemcpyDeviceToHost) ); 78 | cudaCHK( cudaMemcpy(N_f, L->MNdat_hst+L->l_size[2], L->l_size[3], cudaMemcpyDeviceToHost) ); 79 | } 80 | 81 | extern "C" void cuda_setmn1_(float *M_f, float *N_f, int *lid) { 82 | struct GPU_Layer *L = ldlayer(*lid); 83 | cudaCHK( cudaMemcpy(L->MNdat_hst, M_f, L->l_size[3], cudaMemcpyHostToDevice) ); 84 | cudaCHK( cudaMemcpy(L->MNdat_hst+L->l_size[2], N_f, L->l_size[3], cudaMemcpyHostToDevice) ); 85 | } 86 | 87 | extern "C" void cuda_getmn_(float *M_f, float *N_f, int *lid) { 88 | struct GPU_Layer *L = ldlayer(*lid); 89 | cudaCHK( cudaMemcpy(M_f, L->MNout_hst, L->l_size[3], cudaMemcpyDeviceToHost) ); 90 | cudaCHK( cudaMemcpy(N_f, L->MNout_hst+L->l_size[2], L->l_size[3], cudaMemcpyDeviceToHost) ); 91 | } 92 | 93 | extern "C" void cuda_setmn_(float *M_f, float *N_f, int *lid) { 94 | struct GPU_Layer *L = ldlayer(*lid); 95 | cudaCHK( cudaMemcpy(L->MNout_hst, M_f, L->l_size[3], cudaMemcpyHostToDevice) ); 96 | cudaCHK( cudaMemcpy(L->MNout_hst+L->l_size[2], N_f, L->l_size[3], cudaMemcpyHostToDevice) ); 97 | } 98 | 99 | extern "C" void cuda_getzmax_(float *Zmax_f, int *lid) { 100 | struct GPU_Layer *L = ldlayer(*lid); 101 | cudaCHK( cudaMemcpy(Zmax_f, L->Zmax_hst, L->l_size[3], cudaMemcpyDeviceToHost) ); 102 | } 103 | 104 | // void cuda_getmnmax_(float *Mmax_f, float *Nmax_f) { 105 | // cudaCHK( cudaMemcpy(Mmax_f, MNmax_hst, l_size[3], cudaMemcpyDeviceToHost) ); 106 | // cudaCHK( cudaMemcpy(Nmax_f, MNmax_hst+l_size[2], l_size[3], cudaMemcpyDeviceToHost) ); 107 | // } 108 | -------------------------------------------------------------------------------- /GPUall_grids.cu: -------------------------------------------------------------------------------- 1 | #include "GPUHeader.h" 2 | #include "GPUConfig.h" 3 | #include "debug_option.h" 4 | 5 | void show_grid(struct GPU_Layer *L) 6 | { 7 | printf("lid = %d\n", L->lid ); 8 | printf("parent = %d\n", L->plid ); 9 | printf("level = %d\n", L->lvl); 10 | printf("size = %d x %d\n", L->l_size[0], L->l_size[1]); 11 | } 12 | 13 | extern "C" void for_alll_grids_rcsv(void(*__do)(struct GPU_Layer *), struct GPU_Layer *l) 14 | { 15 | if (!l) { 16 | return; 17 | } 18 | 19 | __do(l); 20 | for_alll_grids_rcsv(__do, l->child); 21 | for_alll_grids_rcsv(__do, l->sibling); 22 | 23 | return; 24 | } 25 | 26 | extern "C" void gcomcot_show_grids_() 27 | { 28 | for_alll_grids_rcsv(show_grid, Root_Grid); 29 | return; 30 | } 31 | 32 | // nx row 33 | // ny col 34 | __global__ void edgeinterp_vert(const float* __restrict__ outer, int stride, 35 | struct GPU_Layer innerL) 36 | { 37 | const uint32_t __restrict__ *size_dev = all_size_dev[innerL.lid]; 38 | int inner_row = 0; 39 | // int row_r = size_dev[0] - 1; 40 | int col = threadIdx.x%32 + 30*(threadIdx.x>>5) + blockIdx.x*30*(blockDim.x>>5) - 1; 41 | int col_end = innerL.corner[3]; 42 | const int ir = innerL.rel_size; 43 | 44 | int inner_col = col*ir + 1; 45 | 46 | col += innerL.corner[2] - 1; 47 | 48 | float flux; 49 | double flux_s, flux_e, c1, c2, nn; 50 | 51 | nn = 2.0 * (double) ir; 52 | 53 | flux = outer[col*stride + innerL.corner[0] - 1 - 1]; 54 | flux_e = (double) __shfl_down_sync(0xFFFFFFFF, flux, 1); 55 | flux_s = (double) __shfl_up_sync(0xFFFFFFFF, flux, 1); 56 | flux_e = 0.5*(flux_e + (double) flux); 57 | flux_s = 0.5*(flux_s + (double) flux); 58 | 59 | if (threadIdx.x%32 == 0 || threadIdx.x%32 == 31) { 60 | return; 61 | } 62 | 63 | if (col < col_end) { 64 | c1 = (flux_e-flux_s)/nn; 65 | c2 = -c1 + flux_s; 66 | 67 | for (size_t i = 0; i < ir; i++) { 68 | innerL.MNdat_hst[ID(inner_row, inner_col)] = 2.0*((float)(i+1))*c1 + c2; 69 | if (innerL.H_hst[ID(inner_row, inner_col)] + innerL.Zdat_hst[ID(inner_row, inner_col)] <= GX) 70 | innerL.MNdat_hst[ID(inner_row, inner_col)] = 0.0; 71 | inner_col++; 72 | } 73 | 74 | } 75 | } 76 | 77 | __device__ float newq_vert(struct GPU_Layer outerL, struct GPU_Layer innerL, 78 | int row, int col, int t, int side) 79 | { 80 | const uint32_t* __restrict__ size_dev = all_size_dev[outerL.lid]; 81 | float c1, c2; 82 | float n, n_ip1, n_jm1, n_ip1_jm1, tot_n; 83 | float m, xm; 84 | float z, z_ip1, h, h_ip1; 85 | float r2, r3; 86 | float yflux = 0.0f; 87 | 88 | c1 = ((float) t - 1.0f)/((float) innerL.rel_time); 89 | c2 = 1.0 - c1; 90 | 91 | h = outerL.H_hst[ID(row, col)]; 92 | h_ip1 = outerL.H_hst[ID(row + 1, col)]; 93 | z = outerL.Zout_hst[ID(row, col)]; 94 | z_ip1 = outerL.Zout_hst[ID(row + 1, col)]; 95 | 96 | if (t == 2) { 97 | n = outerL.MNdat_hst[ID2E(row, col, 1)]; 98 | n_ip1 = outerL.MNdat_hst[ID2E(row + 1, col, 1)]; 99 | n_jm1 = __shfl_up_sync(0xFFFFFFFF, n, 1); 100 | n_ip1_jm1 = __shfl_up_sync(0xFFFFFFFF, n_ip1, 1); 101 | if (threadIdx.x%32 == 0) { // first lane cannot get jm1 via shfl_up 102 | n_jm1 = outerL.MNdat_hst[ID2E(row, col - 1, 1)]; 103 | n_ip1_jm1 = outerL.MNdat_hst[ID2E(row + 1, col - 1, 1)]; 104 | } 105 | } 106 | 107 | if (col < innerL.corner[2] - 2 || col > innerL.corner[3] ) 108 | return 0; 109 | 110 | if (h + z > GX && h_ip1 + z_ip1 > GX) { 111 | m = outerL.MNdat_hst[ID2E(row, col, 0)]; 112 | if (t == 2) { 113 | r2 = outerL.R24_hst[ID(row, col)]; 114 | r3 = outerL.R35_hst[col]; 115 | 116 | tot_n = n + n_ip1 + n_jm1 + n_ip1_jm1; 117 | xm = m - r2*(z_ip1 - z) + r3*tot_n; 118 | if (fabs(xm) < EPS) 119 | xm = 0.0f; 120 | 121 | outerL.yflux[col + outerL.l_size[1]*side] = xm; 122 | if (col == 1411 && side == 0) { 123 | printf("%d, %d, %e, %e, %d, %d\n", outerL.lid, innerL.lid, xm, tot_n, threadIdx.x, blockIdx.x); 124 | } 125 | } 126 | yflux = c1*outerL.yflux[col + outerL.l_size[1]*side] + c2*m; 127 | } 128 | 129 | return yflux; 130 | } 131 | 132 | __device__ float newq_hori(struct GPU_Layer outerL, struct GPU_Layer innerL, 133 | int row, int col, int t, int side) 134 | { 135 | const uint32_t* __restrict__ size_dev = all_size_dev[outerL.lid]; 136 | float c1, c2; 137 | float m, m_im1, m_jp1, m_im1_jp1, tot_m; 138 | float n, xn; 139 | float z, z_jp1, h, h_jp1; 140 | float r4, r5; 141 | float xflux = 0.0f; 142 | 143 | c1 = ((float) t - 1.0f)/((float) innerL.rel_time); 144 | c2 = 1.0 - c1; 145 | 146 | h = outerL.H_hst[ID(row, col)]; 147 | h_jp1 = outerL.H_hst[ID(row, col + 1)]; 148 | z = outerL.Zout_hst[ID(row, col)]; 149 | z_jp1 = outerL.Zout_hst[ID(row, col + 1)]; 150 | 151 | if (t == 2) { 152 | m = outerL.MNdat_hst[ID(row, col)]; 153 | m_jp1 = outerL.MNdat_hst[ID(row, col + 1)]; 154 | m_im1 = __shfl_up_sync(0xFFFFFFFF, m, 1); 155 | m_im1_jp1 = __shfl_up_sync(0xFFFFFFFF, m_jp1, 1); 156 | if (threadIdx.x%32 == 0) { 157 | m_im1 = outerL.MNdat_hst[ID(row - 1, col)]; 158 | m_im1_jp1 = outerL.MNdat_hst[ID(row - 1, col + 1)]; 159 | } 160 | } 161 | 162 | if (row < innerL.corner[0] - 2 || row > innerL.corner[1]) 163 | return 0; 164 | 165 | if (h + z > GX && h_jp1 + z_jp1 > GX) { 166 | n = outerL.MNdat_hst[ID2E(row, col, 1)]; 167 | if (t == 2) { 168 | r4 = outerL.R24_hst[ID2E(row, col, 1)]; 169 | r5 = outerL.R35_hst[col + size_dev[1]]; 170 | 171 | tot_m = m_im1 + m_im1_jp1 + m + m_jp1; 172 | xn = n - r4*(z_jp1 - z) - r5*tot_m; 173 | if (fabs(xn) < EPS) 174 | xn = 0.0f; 175 | 176 | outerL.xflux[row + outerL.l_size[0]*side] = xn; 177 | } 178 | xflux = c1*outerL.xflux[row + outerL.l_size[0]*side] + c2*n; 179 | } 180 | 181 | return xflux; 182 | } 183 | 184 | __global__ void edgeinterp_vert2(struct GPU_Layer innerL, struct GPU_Layer outerL, int T) 185 | { 186 | const uint32_t* __restrict__ size_dev = all_size_dev[innerL.lid]; 187 | const int outer_row[2] = {innerL.corner[0] - 1 - 1, 188 | innerL.corner[1] - 1}; 189 | const int inner_row[2] = {0, size_dev[0]-1}; 190 | const int colid = threadIdx.x%32 + 30*(threadIdx.x>>5) + blockIdx.x*30*(blockDim.x>>5) - 1; 191 | int col = colid; 192 | int col_end = innerL.corner[3]; 193 | const int ir = innerL.rel_size; 194 | 195 | col += innerL.corner[2] - 1; 196 | 197 | float flux; 198 | float flux_s, flux_e, c1[2], c2[2], nn; 199 | 200 | nn = 2.0 * (float) ir; 201 | 202 | #pragma unroll 2 203 | for (size_t i = 0; i < 2; i++) { 204 | if (T == 1) { 205 | flux = outerL.MNdat_hst[outer_row[i] + col*outerL.l_size[0]]; 206 | } 207 | else { 208 | flux = newq_vert(outerL, innerL, outer_row[i], col, T, i); 209 | __syncwarp(); 210 | } 211 | flux_e = __shfl_down_sync(0xFFFFFFFF, flux, 1); 212 | flux_s = __shfl_up_sync(0xFFFFFFFF, flux, 1); 213 | flux_e = 0.5*(flux_e + flux); 214 | flux_s = 0.5*(flux_s + flux); 215 | c1[i] = (flux_e-flux_s)/nn; 216 | c2[i] = -c1[i] + flux_s; 217 | // if (colid == 59 || colid == 89 || colid == 209 || colid == 269 || colid == 29) { 218 | // printf("row = %d col = %d colid = %d, threadIdx.x=%d, fluxes=%f, %f, %f\n", 219 | // outer_row[i], col, colid, threadIdx.x, flux, flux_s, flux_e); 220 | // } 221 | } 222 | 223 | // The first and last lanes cannot get flux via shfl_up/down_sync 224 | if (threadIdx.x%32 == 0 || threadIdx.x%32 == 31) { 225 | return; 226 | } 227 | 228 | if (col < col_end) { 229 | #pragma unroll 2 230 | for (size_t i = 0; i < 2; i++) { 231 | int inner_col = colid*ir + 1; 232 | for (size_t j = 0; j < ir; j++) { 233 | innerL.MNdat_hst[ID(inner_row[i], inner_col)] = 234 | 2.0*((float)(j+1))*c1[i] + c2[i]; 235 | if (innerL.H_hst[ID(inner_row[i], inner_col)] + 236 | innerL.Zdat_hst[ID(inner_row[i], inner_col)] <= GX) 237 | innerL.MNdat_hst[ID(inner_row[i], inner_col)] = 0.0; 238 | inner_col++; 239 | } 240 | } 241 | } 242 | } 243 | 244 | __global__ void edgeinterp_hori2(struct GPU_Layer innerL, struct GPU_Layer outerL, int T) 245 | { 246 | const uint32_t* __restrict__ size_dev = all_size_dev[innerL.lid]; 247 | const int outer_col[2] = {(innerL.corner[2] - 1 - 1), 248 | (innerL.corner[3] - 1)}; 249 | const int inner_col[2] = {0, size_dev[1]-1}; 250 | const int rowid = threadIdx.x%32 + 30*(threadIdx.x>>5) + blockIdx.x*30*(blockDim.x>>5) - 1; 251 | int row = rowid; 252 | int row_end = innerL.corner[1]; 253 | const int ir = innerL.rel_size; 254 | 255 | row += innerL.corner[0] - 1; 256 | 257 | float flux; 258 | float flux_s, flux_e, c1[2], c2[2], nn; 259 | 260 | nn = 2.0 * (float) ir; 261 | 262 | #pragma unroll 2 263 | for (size_t i = 0; i < 2; i++) { 264 | if (T == 1) { 265 | flux = outerL.MNdat_hst[outerL.l_size[2] + outer_col[i]*outerL.l_size[0] + row]; 266 | } 267 | else { 268 | flux = newq_hori(outerL, innerL, row, outer_col[i], T, i); 269 | __syncwarp(); 270 | } 271 | flux_e = __shfl_down_sync(0xFFFFFFFF, flux, 1); 272 | flux_s = __shfl_up_sync(0xFFFFFFFF, flux, 1); 273 | flux_e = 0.5*(flux_e + flux); 274 | flux_s = 0.5*(flux_s + flux); 275 | c1[i] = (flux_e-flux_s)/nn; 276 | c2[i] = -c1[i] + flux_s; 277 | } 278 | 279 | if (threadIdx.x%32 == 0 || threadIdx.x%32 == 31) { 280 | return; 281 | } 282 | 283 | if (row < row_end) { 284 | #pragma unroll 2 285 | for (size_t i = 0; i < 2; i++) { 286 | int inner_row = rowid*ir + 1; 287 | for (size_t j = 0; j < ir; j++) { 288 | innerL.MNdat_hst[ID2E(inner_row, inner_col[i], 1)] = 289 | 2.0*((float)(j+1))*c1[i] + c2[i]; 290 | if (innerL.H_hst[ID(inner_row, inner_col[i])] + 291 | innerL.Zdat_hst[ID(inner_row, inner_col[i])] <= GX) 292 | innerL.MNdat_hst[ID2E(inner_row, inner_col[i], 1)] = 0.0; 293 | inner_row++; 294 | } 295 | } 296 | } 297 | } 298 | 299 | extern "C" void edgeinterp_dbglaunch_(float *mO, float *nO, int *idO, 300 | float *mA, float *nA, int *idA, int *t, 301 | float *yflux, float *xflux) 302 | { 303 | clock_t st, fi; 304 | struct GPU_Layer *lO = ldlayer(*idO); 305 | struct GPU_Layer *lA = ldlayer(*idA); 306 | float *mn_cmp, *yflux_cmp, *xflux_cmp; 307 | cudaError_t err; 308 | 309 | st = clock(); 310 | // edgeinterp_vert <<< lA->DimGrid_JNQ, BLOCKX_JNQ >>> 311 | // (lO->MNdat_hst + lA->corner[0] - 1 - 1, lO->l_size[0], *lA); 312 | edgeinterp_vert2 <<< lA->DimGrid_JNQV, BLOCKX_JNQ, 0, EXECstream[0] >>> 313 | (*lA, *lO, *t); 314 | 315 | edgeinterp_hori2 <<< lA->DimGrid_JNQH, BLOCKX_JNQ, 0, EXECstream[1] >>> 316 | (*lA, *lO, *t); 317 | 318 | cudaDeviceSynchronize(); 319 | err = cudaGetLastError(); 320 | cudaERROR(err); 321 | fi = clock(); 322 | printf("TIME SPENT ON GPU (EDGE_INTERP->%d) %f\n",(float)(fi-st)/CLOCKS_PER_SEC, lA->lid); 323 | 324 | mn_cmp = (float*) malloc(2*lA->l_size[3]); 325 | xflux_cmp = (float*) malloc(2*lO->l_size[0]*sizeof(float)); 326 | yflux_cmp = (float*) malloc(2*lO->l_size[1]*sizeof(float)); 327 | cudaCHK( cudaMemcpy(mn_cmp, lA->MNdat_hst, 2*lA->l_size[3], cudaMemcpyDeviceToHost) ); 328 | cudaCHK( cudaMemcpy(yflux_cmp, lO->yflux, 2*lO->l_size[1]*sizeof(float), cudaMemcpyDeviceToHost) ); 329 | cudaCHK( cudaMemcpy(xflux_cmp, lO->xflux, 2*lO->l_size[0]*sizeof(float), cudaMemcpyDeviceToHost) ); 330 | 331 | printf("==============lO:%d, lA:%d =============\n", lO->lid, lA->lid); 332 | if (*t == 2) { 333 | for (size_t i = lA->corner[2]-1; i <= lA->corner[3]; i++) { 334 | int id = i; 335 | if (assert_diff(yflux_cmp[id], yflux[id])) { 336 | printf("(left-flux) i = %d, %f, %f, diff=%f\n", i, yflux_cmp[id], yflux[id], fabs(yflux_cmp[id] - yflux[id])); 337 | } 338 | } 339 | 340 | for (size_t i = lA->corner[2]-1; i <= lA->corner[3]; i++) { 341 | int id = i + lO->l_size[1]; 342 | if (assert_diff(yflux_cmp[id], yflux[id])) { 343 | printf("(right-flux) i = %d, %f, %f, diff=%f\n", i, yflux_cmp[id], yflux[id], fabs(yflux_cmp[id] - yflux[id])); 344 | } 345 | } 346 | 347 | for (size_t i = lA->corner[0]-1; i < lA->corner[1]; i++) { 348 | int id = i; 349 | if (assert_diff(xflux_cmp[id], xflux[id])) { 350 | printf("(bottom-flux) i = %d, %f, %f, diff=%f\n", i, xflux_cmp[id], xflux[id], fabs(xflux_cmp[id] - xflux[id])); 351 | } 352 | } 353 | 354 | for (size_t i = lA->corner[0]-1; i <= lA->corner[1]; i++) { 355 | int id = i + lO->l_size[0]; 356 | if (assert_diff(xflux_cmp[id], xflux[id])) { 357 | printf("(top-flux) i = %d, %f, %f, diff=%f\n", i, xflux_cmp[id], xflux[id], fabs(xflux_cmp[id] - xflux[id])); 358 | } 359 | } 360 | } 361 | 362 | for (size_t i = 0; i < lA->l_size[1]; i++) { 363 | int id = i*lA->l_size[0] + 0; 364 | if (assert_diff(mn_cmp[id], mA[id])) { 365 | printf("(left) i = %d, %f, %f, diff=%f\n", i, mn_cmp[id], mA[id], fabs(mn_cmp[id] - mA[id])); 366 | } 367 | } 368 | for (size_t i = 0; i < lA->l_size[1]; i++) { 369 | int id = i*lA->l_size[0] + lA->l_size[0] - 1; 370 | if (assert_diff(mn_cmp[id], mA[id]) ) { 371 | printf("(right) i = %d, %f, %f, diff=%f\n", i, mn_cmp[id], mA[id], fabs(mn_cmp[id] - mA[id])); 372 | } 373 | } 374 | 375 | for (size_t i = 0; i < lA->l_size[0]; i++) { 376 | int id = i; 377 | if (assert_diff(mn_cmp[id + lA->l_size[2]], nA[id])) { 378 | printf("(bottom) i = %d, %f, %f, diff=%f\n", i, mn_cmp[id + lA->l_size[2]], 379 | nA[id], fabs(mn_cmp[id + lA->l_size[2]] - nA[id])); 380 | } 381 | } 382 | 383 | for (size_t i = 0; i < lA->l_size[0]; i++) { 384 | int id = i + lA->l_size[0]*(lA->l_size[1] - 1); 385 | if (assert_diff(mn_cmp[id + lA->l_size[2]], nA[id])) { 386 | printf("(top) i = %d, %f, %f, diff=%f\n", i, mn_cmp[id + lA->l_size[2]], 387 | nA[id], fabs(mn_cmp[id + lA->l_size[2]] - nA[id])); 388 | } 389 | } 390 | 391 | free(mn_cmp); 392 | free(yflux_cmp); 393 | free(xflux_cmp); 394 | } 395 | 396 | void jnq(struct GPU_Layer *lO, struct GPU_Layer *lA) 397 | { 398 | clock_t st, fi; 399 | cudaError_t err; 400 | 401 | st = clock(); 402 | // edgeinterp_vert <<< lA->DimGrid_JNQ, BLOCKX_JNQ >>> 403 | // (lO->MNdat_hst + lA->corner[0] - 1 - 1, lO->l_size[0], *lA); 404 | edgeinterp_vert2 <<< lA->DimGrid_JNQV, BLOCKX_JNQ, 0, EXECstream[0] >>> 405 | (*lA, *lO, 1); 406 | 407 | edgeinterp_hori2 <<< lA->DimGrid_JNQH, BLOCKX_JNQ, 0, EXECstream[1] >>> 408 | (*lA, *lO, 1); 409 | 410 | cudaDeviceSynchronize(); 411 | err = cudaGetLastError(); 412 | cudaERROR(err); 413 | fi = clock(); 414 | return; 415 | } 416 | 417 | 418 | void newq(struct GPU_Layer *lO, struct GPU_Layer *lA, int step) 419 | { 420 | clock_t st, fi; 421 | cudaError_t err; 422 | 423 | st = clock(); 424 | // edgeinterp_vert <<< lA->DimGrid_JNQ, BLOCKX_JNQ >>> 425 | // (lO->MNdat_hst + lA->corner[0] - 1 - 1, lO->l_size[0], *lA); 426 | edgeinterp_vert2 <<< lA->DimGrid_JNQV, BLOCKX_JNQ, 0, EXECstream[0] >>> 427 | (*lA, *lO, step); 428 | 429 | edgeinterp_hori2 <<< lA->DimGrid_JNQH, BLOCKX_JNQ, 0, EXECstream[1] >>> 430 | (*lA, *lO, step); 431 | 432 | cudaDeviceSynchronize(); 433 | err = cudaGetLastError(); 434 | cudaERROR(err); 435 | fi = clock(); 436 | return; 437 | } 438 | 439 | __global__ void jnz_kernel_deprecated(float * __restrict__ Z_out, int stride, 440 | float * __restrict__ Z_in, int nr, int nc, 441 | int rel_size, int thread_xbound) 442 | { 443 | __shared__ float col_reduct[32]; 444 | int row, col, col_end; 445 | float row_reduct, final_val; 446 | 447 | // row = threadIdx.x + blockIdx.x*(32/rel_size*rel_size) ; 448 | row = threadIdx.x + blockIdx.x*thread_xbound; 449 | col = threadIdx.y + blockIdx.y*10*rel_size; 450 | col_end = col + 10 < nc ? col + 10 : nc; 451 | 452 | for (size_t i = 0, j = col; j < col_end; i++, j++) { 453 | if (row < nr) { 454 | row_reduct = Z_in[j*nr + row]; 455 | } 456 | if (rel_size == 2) { 457 | row_reduct += __shfl_down_sync(0xFFFFFFFF, row_reduct, 1); 458 | if (threadIdx.x & 0x1 == 0) { // x%2 == 0 459 | col_reduct[threadIdx.y*16 + threadIdx.x/2] = row_reduct; 460 | } 461 | __syncthreads(); 462 | if (threadIdx.x & 0x1 == 0 && threadIdx.y == 0) { 463 | final_val = row_reduct; 464 | final_val += col_reduct[threadIdx.x/2 + 16]; 465 | Z_out[stride*i + threadIdx.x/2] = final_val/4.0f; 466 | } 467 | } 468 | if (rel_size == 4) { 469 | row_reduct += __shfl_down_sync(0xFFFFFFFF, row_reduct, 2); 470 | row_reduct += __shfl_down_sync(0xFFFFFFFF, row_reduct, 1); 471 | if (threadIdx.x & 0x3 == 0) { // x%4 == 0 472 | /* code */ 473 | } 474 | } 475 | if (rel_size == 8) { 476 | row_reduct += __shfl_down_sync(0xFFFFFFFF, row_reduct, 4); 477 | row_reduct += __shfl_down_sync(0xFFFFFFFF, row_reduct, 2); 478 | row_reduct += __shfl_down_sync(0xFFFFFFFF, row_reduct, 1); 479 | if (threadIdx.x & 0x7 == 0) { // x%8 == 0 480 | 481 | } 482 | } 483 | } 484 | } 485 | 486 | #define WRP_ALL_MASK 0xffffffff 487 | template 488 | __global__ void jnz_wrap_based_kernel(const struct GPU_Layer LO, 489 | const struct GPU_Layer LA, 490 | const int reltime) 491 | { 492 | const float half = relsize * relsize / 2.0; 493 | float* __restrict__ ZO = LO.Zout_hst; 494 | const float* __restrict__ ZA1 = LA.Zdat_hst; 495 | const float* __restrict__ ZA2 = LA.Zout_hst; 496 | const float* __restrict__ HA = LA.H_hst; 497 | int row, col, row_end, col_end; 498 | int dest_row, dest_col; 499 | const int nr_row_lo = LO.l_size[0]; 500 | const int nr_row_la = LA.l_size[0]; 501 | const int offset_i = LA.corner[0] - 1; // translate to C's zero-based index 502 | const int offset_j = LA.corner[2] - 1; 503 | bool writer; 504 | float z, h; 505 | int cnt; 506 | float res; 507 | float reduct_z; 508 | int reduct_cnt; 509 | 510 | row = threadIdx.x + blockIdx.x * blockDim.x + 1; 511 | col = blockIdx.y * LOOPDEPTH + 1; // threadIdx.y is always 0 512 | row_end = LA.l_size[0]; 513 | col_end = (blockIdx.y == gridDim.y - 1) ? LA.l_size[1]: 514 | col + LOOPDEPTH; 515 | if (row >= row_end) 516 | return; 517 | 518 | dest_row = offset_i + (threadIdx.x + blockIdx.x * blockDim.x) / relsize; 519 | dest_col = offset_j + (blockIdx.y * LOOPDEPTH) / relsize; 520 | writer = threadIdx.x % relsize == 0; 521 | 522 | while (col < col_end) { 523 | int c = col; 524 | reduct_z = 0; 525 | reduct_cnt = 0; 526 | for (; c < col + relsize; c++) { 527 | z = ZA2[ID_MATRIX(row, c, nr_row_la)]; 528 | h = HA[ID_MATRIX(row, c, nr_row_la)]; 529 | if (z + h <= GX) { 530 | z = 0; 531 | cnt = 0; 532 | } else { 533 | if (reltime % 2 == 0) 534 | z = (z + ZA1[ID_MATRIX(row, c, nr_row_la)]) / 2.0; 535 | cnt = 1; 536 | } 537 | /* 538 | if (dest_row == 391 && dest_col == 1299) { 539 | printf("z = %e, h = %e, row = %d, col = %d, cnt = %d, tidx = %d, bidy = %d\n", 540 | z, h, row, c, cnt, threadIdx.x, blockIdx.y); 541 | } 542 | */ 543 | // reduction starts 544 | __syncwarp(); 545 | if (relsize == 32) { 546 | z += __shfl_down_sync(WRP_ALL_MASK, z, 16); 547 | cnt += __shfl_down_sync(WRP_ALL_MASK, cnt, 16); 548 | } 549 | if (relsize >= 16) { 550 | z += __shfl_down_sync(WRP_ALL_MASK, z, 8); 551 | cnt += __shfl_down_sync(WRP_ALL_MASK, cnt, 8); 552 | } 553 | if (relsize >= 8) { 554 | z += __shfl_down_sync(WRP_ALL_MASK, z, 4); 555 | cnt += __shfl_down_sync(WRP_ALL_MASK, cnt, 4); 556 | } 557 | if (relsize >= 4) { 558 | z += __shfl_down_sync(WRP_ALL_MASK, z, 2); 559 | cnt += __shfl_down_sync(WRP_ALL_MASK, cnt, 2); 560 | } 561 | if (relsize >= 2) { 562 | z += __shfl_down_sync(WRP_ALL_MASK, z, 1); 563 | cnt += __shfl_down_sync(WRP_ALL_MASK, cnt, 1); 564 | } 565 | reduct_z += z; 566 | reduct_cnt += cnt; 567 | } 568 | // write back 569 | if (writer) { 570 | /* 571 | if (dest_row == 391 && dest_col == 1299) { 572 | printf("reducted_z = %e, reducted_cnt = %d, %d/%d, %d/%d\n", 573 | reduct_z, reduct_cnt, 574 | threadIdx.x, blockIdx.x, threadIdx.y, blockIdx.y); 575 | } 576 | */ 577 | res = (reduct_cnt > half) ? (reduct_z / (float) reduct_cnt) : 0.0; 578 | ZO[ID_MATRIX(dest_row, dest_col, nr_row_lo)] = res; 579 | dest_col++; 580 | } 581 | col = c; // c would be 582 | } 583 | 584 | return; 585 | } 586 | 587 | void jnz(struct GPU_Layer *L_p, struct GPU_Layer *L_c) 588 | { 589 | clock_t st, fi; 590 | cudaError_t err; 591 | 592 | st = clock(); 593 | switch (L_c->rel_size) { 594 | case 2: 595 | jnz_wrap_based_kernel<2> <<< L_c->DimGridJnz, L_c->DimBlockJnz >>> 596 | (*L_p, *L_c, L_c->rel_time); 597 | break; 598 | case 4: 599 | jnz_wrap_based_kernel<4> <<< L_c->DimGridJnz, L_c->DimBlockJnz >>> 600 | (*L_p, *L_c, L_c->rel_time); 601 | break; 602 | case 8: 603 | jnz_wrap_based_kernel<8> <<< L_c->DimGridJnz, L_c->DimBlockJnz >>> 604 | (*L_p, *L_c, L_c->rel_time); 605 | break; 606 | case 16: 607 | jnz_wrap_based_kernel<16> <<< L_c->DimGridJnz, L_c->DimBlockJnz >>> 608 | (*L_p, *L_c, L_c->rel_time); 609 | break; 610 | case 32: 611 | jnz_wrap_based_kernel<32> <<< L_c->DimGridJnz, L_c->DimBlockJnz >>> 612 | (*L_p, *L_c, L_c->rel_time); 613 | break; 614 | } 615 | cudaDeviceSynchronize(); 616 | err = cudaGetLastError(); 617 | cudaERROR(err); 618 | fi = clock(); 619 | 620 | #ifdef DEBUG_CORE 621 | printf("TIME SPENT ON GPU (JNZ) %f\n",(float)(fi-st)/CLOCKS_PER_SEC); 622 | #endif /* DEBUG_CORE */ 623 | return; 624 | } 625 | 626 | extern "C" void jnz_dbglaunch_(float *Z_f, int *outid, int *inid) { 627 | GPU_Layer *parent = ldlayer(*outid); 628 | GPU_Layer *child = ldlayer(*inid); 629 | float *z_cmp = (float*) malloc(parent->l_size[3]); 630 | float *z_ori = (float*) malloc(child->l_size[3]); 631 | 632 | jnz(parent, child); 633 | cudaCHK( cudaMemcpy(z_cmp, parent->Zout_hst, parent->l_size[3], cudaMemcpyDeviceToHost) ); 634 | cudaCHK( cudaMemcpy(z_ori, child->Zout_hst, child->l_size[3], cudaMemcpyDeviceToHost) ); 635 | printf("child corner %d %d %d %d\n", 636 | child->corner[0], child->corner[1], child->corner[2], child->corner[3]); 637 | CMP_VAR(z_cmp, Z_f, 638 | parent->l_size[0], parent->l_size[1], 639 | "JNZ, layerid=%d", child->lid); 640 | 641 | free(z_ori); 642 | free(z_cmp); 643 | } 644 | 645 | void update(struct GPU_Layer *L) 646 | { 647 | 648 | // maybe we could place cudaDeviceSynchronize() before some kernel launch 649 | // so that we can run C/Fortran code simutaneously with cuda code 650 | cuda_update_layer_(&L->lid); 651 | 652 | return; 653 | } 654 | 655 | void subgrid_solver_rcsv(struct GPU_Layer *current) 656 | { 657 | struct GPU_Layer *parent, *sibling, *child; 658 | const int *id = ¤t->lid; 659 | 660 | int halfway = 0; 661 | 662 | if (!current) { 663 | return; 664 | } 665 | 666 | if (current->plid == -1) { 667 | return; 668 | } 669 | parent = ldlayer(current->plid); 670 | 671 | sibling = current->sibling; 672 | child = current->child; 673 | 674 | halfway = (current->rel_time/2) + 1; 675 | for (size_t i = 1; i <= current->rel_time; i++) { 676 | if (i == 1) { 677 | jnq(parent, current); 678 | } 679 | else { 680 | newq(parent, current, i); 681 | } 682 | 683 | mass_launch_(NULL , NULL, NULL, id); 684 | 685 | subgrid_solver_rcsv(current->child); 686 | 687 | momt_launch_(NULL, NULL, NULL, id); 688 | 689 | if (i == halfway) { 690 | jnz(parent, current); 691 | } 692 | 693 | update(current); 694 | } 695 | 696 | subgrid_solver_rcsv(sibling); 697 | 698 | return; 699 | } 700 | 701 | extern "C" void all_grid_launch_(void) 702 | { 703 | // All subgrids start from 2. 1 is the Root_Grid. 704 | return subgrid_solver_rcsv(ldlayer(2)); 705 | } 706 | 707 | -------------------------------------------------------------------------------- /GPUcomcot.cu: -------------------------------------------------------------------------------- 1 | #include "GPUHeader.h" 2 | #include "GPUConfig.h" 3 | 4 | // global variables----------------------------- 5 | struct GPU_Layer *Root_Grid; 6 | struct GPU_Layer Layer_struct[MAX_LAYERS]; 7 | uint32_t all_size[MAX_LAYERS][4]; 8 | __constant__ __device__ uint32_t all_size_dev[MAX_LAYERS][4]; 9 | 10 | cudaStream_t EXECstream[NUMSTREAM]; 11 | dim3 DimBlockMomt_MN(BLOCKX_MOMT,1,1); 12 | dim3 DimGridMomt_MN(0,1,1); 13 | dim3 DimBlockMomt(BLOCKX,BLOCKY,2); 14 | dim3 DimGridMomt(0,0,1); 15 | dim3 DimBlockMass(BLOCKX_MASS,1,1); 16 | dim3 DimGridMass(1,1,1); 17 | dim3 DimBlockOpenBD(BLOCKX_OPENBD,1,1); 18 | dim3 DimGridOpenBD_LR(0,1,1); 19 | dim3 DimGridOpenBD_TB(0,1,1); 20 | size_t GridMaxAmp; 21 | 22 | cudaDeviceProp dev_prop; 23 | #ifdef DEBUG 24 | float *tmpout; 25 | #endif 26 | //---------------------------------------------- 27 | extern "C" void cuda_update_layer_(int *); 28 | void cudaMalloc2E(void**, void*, void*, size_t); 29 | #ifdef DEBUG 30 | __host__ __device__ void prt_mat(float*, size_t, size_t); 31 | __global__ void GPUmemtest(void); 32 | __global__ void CHECK_VAR(void); 33 | extern "C" void cmpvar_(const float *, int *); 34 | #endif 35 | 36 | extern "C" void cuda_alloc_layer(struct GPU_Layer *L, float *R1_f, float *R2_f, 37 | float *R3_f, float *R4_f, float *R5_f, float *R6_f, 38 | float *R11_f, float *H_f, float *Z_f, int *row, int *col){ 39 | 40 | //float *R24_hst, *R35_hst, *H_hst; 41 | float *R3, *R5; 42 | float *R_MASS; 43 | 44 | L->l_size[0] = *row; 45 | L->l_size[1] = *col; 46 | L->l_size[2] = (*row)*(*col); 47 | L->l_size[3] = (*row)*(*col)*sizeof(float); 48 | // allocate variables 49 | // const === R2 R4 H === 50 | cudaCHK( cudaMalloc(&L->H_hst, L->l_size[3]) ); 51 | 52 | cudaMalloc2E((void**)&L->R24_hst, R2_f, R4_f, L->l_size[3]); 53 | //cudaCHK( cudaMemcpyToSymbol(R24_dev, &R24_hst, sizeof(float*)) ); 54 | // const variables R3 R5, R1 R6 R11 55 | size_t R_size = sizeof(float)*L->l_size[1]; 56 | //R1 = (float*) malloc(R_size); 57 | R3 = (float*) malloc(R_size); 58 | R5 = (float*) malloc(R_size); 59 | //R11 =(float*) malloc(R_size); 60 | R_MASS = (float*) malloc(4*R_size); 61 | 62 | for (size_t i = 0; i < L->l_size[1]; i++) { 63 | R3[i] = R3_f[i*L->l_size[0]]; 64 | R5[i] = R5_f[i*L->l_size[0]]; 65 | R_MASS[4*i] = R1_f[i*L->l_size[0]]; 66 | R_MASS[4*i+1] = R6_f[i]; 67 | R_MASS[4*i+2] = R11_f[i*L->l_size[0]]; 68 | } 69 | 70 | cudaCHK( cudaMalloc(&L->R_MASS_hst, 4*R_size) ); 71 | cudaCHK( cudaMemcpy(L->R_MASS_hst, R_MASS, 4*R_size, cudaMemcpyHostToDevice) ); 72 | 73 | cudaMalloc2E((void**)&L->R35_hst, R3, R5, R_size); 74 | 75 | // output variables === M N Z === 76 | cudaCHK( cudaMalloc(&L->Zdat_hst, L->l_size[3]) ); 77 | cudaCHK( cudaMalloc(&L->Zmax_hst, L->l_size[3]) ); 78 | cudaCHK( cudaMemcpy(L->Zdat_hst, Z_f, L->l_size[3], cudaMemcpyHostToDevice) ); 79 | cudaCHK( cudaMemcpy(L->Zmax_hst, Z_f, L->l_size[3], cudaMemcpyHostToDevice) ); 80 | cudaCHK( cudaMalloc(&L->Zout_hst, L->l_size[3]) ); 81 | 82 | cudaMalloc2E((void**)&L->MNdat_hst, NULL, NULL, L->l_size[3]); 83 | cudaMalloc2E((void**)&L->MNout_hst, NULL, NULL, L->l_size[3]); 84 | cudaCHK( cudaMalloc(&L->xflux, 2*L->l_size[0]*sizeof(float)) ); 85 | cudaCHK( cudaMemset(L->xflux, 0, 2*L->l_size[0]*sizeof(float)) ); 86 | cudaCHK( cudaMalloc(&L->yflux, 2*L->l_size[1]*sizeof(float)) ); 87 | cudaCHK( cudaMemset(L->yflux, 0, 2*L->l_size[1]*sizeof(float)) ); 88 | 89 | // copy data into variables 90 | // const variables === H, size === 91 | cudaCHK( cudaMemcpy(L->H_hst, H_f, L->l_size[3], cudaMemcpyHostToDevice) ); 92 | 93 | int *ptr; 94 | memcpy(all_size[L->lid], L->l_size, 4*sizeof(uint32_t)); 95 | cudaCHK( cudaMalloc(&ptr, sizeof(all_size)) ); 96 | cudaCHK( cudaMemcpy(ptr, all_size, sizeof(all_size), cudaMemcpyHostToDevice) ); 97 | cudaCHK( cudaMemcpyToSymbol(all_size_dev, ptr, sizeof(all_size)) ); 98 | cudaCHK( cudaFree(ptr) ); 99 | 100 | // kernel configurations 101 | L->DimGridMomt_MN = dim3((L->l_size[0]-1)/(31*(BLOCKX_MOMT>>5)) + 1, LOAD_PER_SM*(uint32_t)dev_prop.multiProcessorCount, 1); 102 | L->DimGridMomt = dim3((L->l_size[0]-1)/EXECY + 1, (L->l_size[1]-1)/EXECX + 1, 1); 103 | L->DimGridMass = dim3((L->l_size[0]-1)/(31*(BLOCKX_MASS>>5)) + 1, LOAD_PER_SM*(uint32_t)dev_prop.multiProcessorCount, 1); 104 | L->DimGridOpenBD_LR = dim3((L->l_size[0]-1)/(31*(BLOCKX_OPENBD>>5)) + 1, 1, 1); 105 | L->DimGridOpenBD_TB = dim3((L->l_size[1]-1)/(31*(BLOCKX_OPENBD>>5)) + 1, 1, 1); 106 | L->GridMaxAmp = (L->l_size[2]-1)/MAXAMP_BLOCK + 1; 107 | if (L->lid != 1) { 108 | if (L->rel_size > 32 || (!ispow2(L->rel_size)) && L->rel_size > 1) { 109 | printf("Error, JNZ kernel only supports grid size ratio of 2,4,8,16,32, input is %d\n", L->rel_size); 110 | exit(EXIT_FAILURE); 111 | } 112 | // the last row and col are not used 113 | L->DimBlockJnz = dim3(BLOCKX_JNZ, 1 ,1); 114 | L->DimGridJnz = dim3((L->l_size[0] - 1 - 1)/(BLOCKX_JNZ) + 1, (L->l_size[1] - 1 - 1) / LOOPDEPTH + 1, 1); 115 | } 116 | // if (L->lid != 1) { 117 | // if (L->rel_size < 2 || L->rel_size > 32 ) { 118 | // printf("Error, Invalid rel_size=%d for layer_%d\n", 119 | // L->rel_size, L->lid); 120 | // exit(EXIT_FAILURE); 121 | // } 122 | // if (L->rel_size < 8) { 123 | // printf("Warning, inefficient rel_size=%d for layer_%d\n", 124 | // L->rel_size, L->lid); 125 | // } 126 | // L->DimBlockJnz = dim3(L->rel_size, L->rel_size, 1); 127 | // L->DimGridJnz = dim3(((L->l_size[0] - 1) / L->rel_size) + 1, 128 | // ((L->l_size[1] - 1) / L->rel_size) + 1, 1); 129 | // } 130 | if (L->lid != 1) { 131 | L->DimGrid_JNQV = dim3((L->corner[3] - L->corner[2])/(30*BLOCKX_JNQ>>5) + 1, 1, 1); 132 | L->DimGrid_JNQH = dim3((L->corner[1] - L->corner[0])/(30*BLOCKX_JNQ>>5) + 1, 1, 1); 133 | } 134 | 135 | #ifdef DEBUG 136 | tmpout = (float*) malloc(2*l_size[3]); 137 | #endif 138 | 139 | free(R_MASS); 140 | free(R3); 141 | free(R5); 142 | } 143 | 144 | extern "C" void cuda_update_layer_(int *lid) { 145 | struct GPU_Layer *L = ldlayer(*lid); 146 | float *tmp; 147 | // similar to function change 148 | tmp = L->MNout_hst; 149 | L->MNout_hst = L->MNdat_hst; 150 | L->MNdat_hst = tmp; 151 | 152 | tmp = L->Zout_hst; 153 | L->Zout_hst = L->Zdat_hst; 154 | L->Zdat_hst = tmp; 155 | } 156 | 157 | void Ltree_insert_sibling(struct GPU_Layer **insert, struct GPU_Layer *l) 158 | { 159 | 160 | while (*insert) { 161 | insert = &((*insert)->sibling); 162 | } 163 | 164 | *insert = l; 165 | return; 166 | } 167 | 168 | void gcomcot_insert_grid(struct GPU_Layer *l) 169 | { 170 | struct GPU_Layer *parent; 171 | 172 | if (l->plid == -1) { 173 | Root_Grid = l; 174 | return; 175 | } 176 | else if (!Root_Grid) { 177 | printf("Error, Root grid is not initialized\n"); 178 | exit(EXIT_FAILURE); 179 | } 180 | 181 | parent = ldlayer(l->plid); 182 | if (parent->child) { 183 | Ltree_insert_sibling(&parent->child->sibling, l); 184 | } 185 | else { 186 | parent->child = l; 187 | } 188 | 189 | return; 190 | } 191 | 192 | extern "C" void gcomcot_init_gpu_(void) 193 | { 194 | cudaCHK( cudaGetDeviceProperties(&dev_prop, 0) ); 195 | printf("GPU INFORMATIONS: %s\n", dev_prop.name); 196 | printf("-->Compute Capabilities [Major.Miner]: %d.%d\n", dev_prop.major, dev_prop.minor); 197 | printf("-->Clock Rate: %d\n", dev_prop.clockRate); 198 | printf("-->Streaming Multi-Processor Count: %d\n", dev_prop.multiProcessorCount); 199 | printf("-->Shared Memory size per SM %d\n", dev_prop.sharedMemPerBlock); 200 | printf("-->Total Constant Memory size: %d\n", dev_prop.totalConstMem ); 201 | printf("-->Maximum Grid Size: %dx%dx%d\n", dev_prop.maxGridSize[0],dev_prop.maxGridSize[1],dev_prop.maxGridSize[2]); 202 | printf("-->Warp Size: %d\n", dev_prop.warpSize); 203 | 204 | //streams 205 | for (size_t i = 0; i < NUMSTREAM; i++) { 206 | cudaCHK( cudaStreamCreate(EXECstream+i) ); 207 | } 208 | 209 | Root_Grid = NULL; 210 | 211 | } 212 | 213 | 214 | extern "C" void gcomcot_init_layer_(int *layerid, int *parent, int *level, 215 | int *rel_size, int *rel_time, 216 | int *corners, float *grx, float *gry, 217 | float *R1_f, float *R2_f, 218 | float *R3_f, float *R4_f, float *R5_f, 219 | float *R6_f, float *R11_f, float *H_f, 220 | float *Z_f, int *row, int *col) 221 | { 222 | struct GPU_Layer *L = ldlayer(*layerid); 223 | 224 | if (*layerid < 0) { 225 | printf("ERROR: invalid layerid\n"); 226 | exit(-1); 227 | } 228 | if (*layerid >= MAX_LAYERS) { 229 | printf("ERROR: number of layer exceed MAX_LAYERS\n"); 230 | exit(-1); 231 | } 232 | printf("Initializing layer id %d\n", *layerid); 233 | 234 | L->lid = *layerid; 235 | L->plid = *parent; 236 | L->lvl = *level; 237 | L->child = NULL; 238 | L->sibling = NULL; 239 | L->rel_size = *rel_size; 240 | L->rel_time = *rel_time; 241 | L->grx = *grx; 242 | L->gry = *gry; 243 | memcpy(L->corner, corners, 4*sizeof(int)); 244 | 245 | gcomcot_insert_grid(L); 246 | 247 | cuda_alloc_layer(L, R1_f, R2_f, R3_f, R4_f, R5_f, 248 | R6_f, R11_f, H_f, Z_f, row, col); 249 | 250 | return; 251 | } 252 | 253 | extern "C" void cuda_shutdown_(void){ 254 | // Free Device Memory 255 | // Unbind Texture Memory 256 | } 257 | 258 | 259 | void cudaMalloc2E(void** cu_hst, void* e1, void* e2, size_t size){ 260 | cudaCHK( cudaMalloc(cu_hst, 2*size) ); 261 | if (!e1) { 262 | cudaCHK( cudaMemset(*cu_hst, 0, size) ); 263 | } 264 | else{ 265 | cudaCHK( cudaMemcpy(*cu_hst, e1, size, cudaMemcpyHostToDevice) ); 266 | } 267 | if (!e2) { 268 | cudaCHK( cudaMemset((void*)((char*)*cu_hst+size), 0, size) ); 269 | }else{ 270 | cudaCHK( cudaMemcpy((void*)((char*)*cu_hst+size), e2, size, cudaMemcpyHostToDevice) ); 271 | } 272 | } 273 | 274 | #ifdef DEBUG 275 | __global__ void CHECK_VAR(){ 276 | for (size_t i = 0; i < size_dev[0]; i++) { 277 | printf("%e\t",Z_out_dev[i]); 278 | } 279 | printf("\n" ); 280 | } 281 | extern "C" void cmpvar_(const float *var_f, int *Case){ 282 | if (*Case == 0) { 283 | printf("copying data\n"); 284 | for (size_t i = 0; i < l_size[2]; i++) { 285 | tmpout[i] = var_f[i]; 286 | } 287 | return; 288 | }else{ 289 | printf("comparing data\n" ); 290 | for (size_t i = 0; i < l_size[2]; i++) { 291 | if (abs(tmpout[i] - var_f[i]) > ERROR) { 292 | printf("VAR[%d,%d] VAR_cu:%e VAR_f:%e %e\n", i%l_size[0], i/l_size[0] , tmpout[i], var_f[i], tmpout[i] - var_f[i]); 293 | } 294 | } 295 | } 296 | } 297 | 298 | 299 | __host__ __device__ void prt_mat(float *mat, size_t row, size_t col){ 300 | printf("Matrix[%d:%d][%d:%d]\n", CHKR,CHKR+CHKSI, CHKC,CHKC+CHKSI); 301 | for (size_t i = CHKR; i < CHKR+CHKSI; i++) { 302 | for (size_t j = CHKC; j < CHKC+CHKSI; j++) { 303 | printf("%8.6e\t", mat[j*row + i]); 304 | } 305 | printf("\n"); 306 | } 307 | } 308 | #endif /* DEBUG */ 309 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Makefile: GPU-Cornell Multigrid Coupled Tsunami (GPUCOMCOT) Model # 3 | # LAST REVISED: TAO CHIU MARCH 2018 # 4 | ##################################################################### 5 | 6 | ### Plese specify your fortran, cuda compiler and GPU's compute capabilities ##### 7 | FC = gfortran -g -cpp 8 | FC_FLAGS = -O2 9 | 10 | 11 | NVCC = nvcc -g 12 | NVFLAGS = 13 | NVCC_OPT = -arch=sm_61 -lineinfo 14 | NVLIB = -L/usr/local/cuda-9.2/lib64 15 | ################################################################################## 16 | 17 | 18 | NV_OBJECTS = GPUcomcot.o\ 19 | GPUall_grids.o\ 20 | GPUMass_s.o\ 21 | GPUMoment_s.o\ 22 | GPUOpen_BD.o\ 23 | GPUOutput.o 24 | 25 | NV_DEVOBJ = nvobj.o 26 | 27 | 28 | F90_MOD = type_module.o 29 | F90_OBJECTS = comcot.o initialization.o output.o\ 30 | deform.o mass.o moment.o\ 31 | boundaries.o all_grids.o hotstart.o\ 32 | landslide.o wavemaker.o dispersion.o 33 | 34 | 35 | 36 | .PHONY: cleandat cleanall cleanf90 cleancu clean 37 | comcot: $(F90_OBJECTS) $(NV_OBJECTS) $(NV_DEVOBJ) 38 | $(FC) -lstdc++ $(FC_FLAGS) $(F90_OBJECTS) $(F90_MOD) $(NVLIB) -lcudart $(NV_OBJECTS) $(NV_DEVOBJ) -o comcot 39 | 40 | cleandat: 41 | for file in *.[dt][ax]t ; do\ 42 | if [[ "$$file" = z_[0-9][0-9]_*.dat ]] ||\ 43 | [[ "$$file" = arrival_*.dat ]] ||\ 44 | [[ "$$file" = M1Layer*.txt ]] ||\ 45 | [[ "$$file" = [fhijmnvz]max_layer*.dat ]] ||\ 46 | [[ "$$file" = layer*.dat ]] ||\ 47 | [[ "$$file" = ts_record*.dat ]] ||\ 48 | [[ "$$file" = zmin_layer*.dat ]] ||\ 49 | [[ "$$file" = deform_seg[0-9][0-9][0-9].dat ]] ||\ 50 | [[ "$$file" = *_[0-9][0-9]_*.dat ]]; then\ 51 | $(RM) "$$file" ;\ 52 | fi;\ 53 | done 54 | cleanf90: 55 | rm comcot $(F90_OBJECTS) $(F90_MOD) 56 | cleancu: 57 | rm $(NV_OBJECTS) $(NV_DEVOBJ) 58 | clean: 59 | make cleanf90 60 | make cleancu 61 | cleanall: 62 | make clean 63 | make cleandat 64 | 65 | ########################## RULES FOR CUDA C ########################### 66 | $(NV_DEVOBJ): $(NV_OBJECTS) 67 | $(NVCC) $(NVCC_OPT) --device-link $(NV_OBJECTS) -o $(NV_DEVOBJ) 68 | $(NV_OBJECTS) $(NV_DEVOBJ): GPUConfig.h GPUHeader.h 69 | GPUcomcot.o: GPUcomcot.cu 70 | $(NVCC) -c -rdc=true $(NVCC_OPT) $(NVFLAGS) GPUcomcot.cu 71 | 72 | GPUMass_s.o: GPUMass_s.cu 73 | $(NVCC) -c -rdc=true $(NVCC_OPT) $(NVFLAGS) GPUMass_s.cu 74 | 75 | GPUMoment_s.o: GPUMoment_s.cu 76 | $(NVCC) -c -rdc=true $(NVCC_OPT) $(NVFLAGS) GPUMoment_s.cu 77 | 78 | GPUOpen_BD.o: GPUOpen_BD.cu 79 | $(NVCC) -c -rdc=true $(NVCC_OPT) $(NVFLAGS) GPUOpen_BD.cu 80 | 81 | GPUOutput.o: GPUOutput.cu 82 | $(NVCC) -c -rdc=true $(NVCC_OPT) $(NVFLAGS) GPUOutput.cu 83 | 84 | GPUall_grids.o: GPUall_grids.cu 85 | $(NVCC) -c -rdc=true $(NVCC_OPT) $(NVFLAGS) GPUall_grids.cu 86 | 87 | ####################################################################### 88 | 89 | ################# RULES FOR FORTRAN ################# 90 | $(F90_MOD): type_module.f90 91 | $(FC) -c $(FC_FLAGS) type_module.f90 92 | $(F90_OBJECTS): $(F90_MOD) 93 | comcot.o: comcot.f90 94 | $(FC) -c $(FC_FLAGS) comcot.f90 95 | 96 | initialization.o: initialization.f90 97 | $(FC) -c $(FC_FLAGS) initialization.f90 98 | 99 | output.o: output.f90 100 | $(FC) -c $(FC_FLAGS) output.f90 101 | 102 | deform.o: deform.f90 103 | $(FC) -c $(FC_FLAGS) deform.f90 104 | 105 | mass.o: mass.f90 106 | $(FC) -c $(FC_FLAGS) mass.f90 107 | 108 | moment.o: moment.f90 109 | $(FC) -c $(FC_FLAGS) moment.f90 110 | 111 | boundaries.o: boundaries.f90 112 | $(FC) -c $(FC_FLAGS) boundaries.f90 113 | 114 | all_grids.o: all_grids.f90 115 | $(FC) -c $(FC_FLAGS) all_grids.f90 116 | 117 | hotstart.o: hotstart.f90 118 | $(FC) -c $(FC_FLAGS) hotstart.f90 119 | 120 | landslide.o: landslide.f90 121 | $(FC) -c $(FC_FLAGS) landslide.f90 122 | 123 | wavemaker.o: wavemaker.f90 124 | $(FC) -c $(FC_FLAGS) wavemaker.f90 125 | 126 | dispersion.o: dispersion.f90 127 | $(FC) -c $(FC_FLAGS) dispersion.f90 128 | #################################################### 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GPU-comcot 2 | This is a program that transfer the computational component on the outermost layer of COMCOT to Nvidia GPU. Currently, the speed up achieved by parallelized code on GTX-1060 comparing to serial one on AMD-FX8150 is nearly 200X. The code is still under development to fulfill the full functionality of the original model. 3 | # Acknowledgements 4 | GPU version of COMCOT was developed by Tao, Chiu at Tsunami reseach group, IHOS, NCU and protected under GPL v3.0. The goal of this work is to librate, coporate ideas with the community and accelerate the development of a high-throughput tsunami warning system at relatively low cost. Original COMCOT version can be found at [here](http://223.4.213.26/archive/tsunami/cornell/comcot_down.htm). 5 | -------------------------------------------------------------------------------- /boundaries.f90: -------------------------------------------------------------------------------- 1 | !*!---------------------------------------------------------------------- 2 | !* SUBROUTINE BC_SETUP (LO,BCI_INFO,WAVE_INFO,BC_TYPE) 3 | !*!.....SET UP VERTICAL WALL BOUNDARY 4 | !*!---------------------------------------------------------------------- 5 | !* USE LAYER_PARAMS 6 | !* USE WAVE_PARAMS 7 | !* USE BCI_PARAMS 8 | !* TYPE (BCI) :: BCI_INFO 9 | !* TYPE (LAYER) :: LO 10 | !* TYPE (WAVE) :: WAVE_INFO 11 | !* INTEGER BC_TYPE 12 | !* 13 | !* IF (BC_TYPE.EQ.0) CALL OPEN (LO) 14 | !* IF (BC_TYPE.EQ.1) CALL SPONGE_LAYER (LO) 15 | !* IF (BC_TYPE.EQ.2) CALL BC_WALL (LO,WAVE_INFO) 16 | !*! IF (BC_TYPE.EQ.3) CALL BC_INPUT (LO,BCI_INFO,TIME) 17 | !* 18 | !* RETURN 19 | !* END 20 | 21 | !---------------------------------------------------------------------- 22 | SUBROUTINE OPEN (LO) 23 | !.....DEPLOY OPEN BOUNDARY CONDITION (ONLY FOR OUTEST LAYER) 24 | !---------------------------------------------------------------------- 25 | USE LAYER_PARAMS 26 | TYPE (LAYER) :: LO 27 | LOGICAL IFIRST,JFIRST,IEND,JEND 28 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 29 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 30 | DATA UB/99.0/ 31 | ! 32 | I_S = 1 33 | J_S = 1 34 | I_E = LO%NX 35 | J_E = LO%NY 36 | IFIRST = I_S .EQ. 1 37 | JFIRST = J_S .EQ. 1 38 | IEND = I_E .EQ. LO%NX 39 | JEND = J_E .EQ. LO%NY 40 | ! 41 | IF ( JFIRST ) THEN 42 | J = 1 43 | DO I=2,LO%NX-1 44 | IF (LO%H(I,J) .GT. GX) THEN 45 | CC = SQRT(GRAV*LO%H(I,J)) 46 | UH = 0.5*(LO%M(I,J,2)+LO%M(I-1,J,2)) 47 | UU = SQRT(UH**2+LO%N(I,J,2)**2) 48 | ZZ = UU/CC 49 | ARG = LO%N(I,J,2) 50 | IF (ARG .GT. ZERO) THEN 51 | ZZ = -ZZ 52 | ENDIF 53 | ! IF (ABS(ZZ) .LE. EPS) ZZ = 0.0 54 | IF (ABS(ZZ) .GT. UB) ZZ=0.0 55 | LO%Z(I,J,2) = ZZ 56 | ELSE 57 | LO%Z(I,J,2) = ZERO 58 | ENDIF 59 | ! if ( i .EQ. 715 ) then 60 | ! WRITE(*,*) "Fortran--------------------->dbdb" 61 | ! WRITE(*,*) LO%H(I,1), LO%M(I,1,2), LO%N(I,1,2), 1/CC 62 | ! WRITE(*,*) LO%M(I-1,1,2), ZZ 63 | ! end if 64 | END DO 65 | ENDIF 66 | ! 67 | IF ( JEND ) THEN 68 | J = LO%NY 69 | DO I=2,LO%NX-1 70 | IF (LO%H(I,J) .GT. GX) THEN 71 | CC = SQRT(GRAV*LO%H(I,J)) 72 | UH = 0.5*(LO%M(I,J,2)+LO%M(I-1,J,2)) 73 | UU = SQRT(UH**2+LO%N(I,J-1,2)**2) 74 | ZZ = UU/CC 75 | ARG = LO%N(I,J-1,2) 76 | IF (ARG .LT. ZERO) THEN 77 | ZZ = -ZZ 78 | ENDIF 79 | ! IF (ABS(ZZ) .LE. EPS) ZZ = 0.0 80 | IF (ABS(ZZ) .GT. UB) ZZ=0.0 81 | LO%Z(I,J,2) = ZZ 82 | ELSE 83 | LO%Z(I,J,2) = ZERO 84 | ENDIF 85 | END DO 86 | ENDIF 87 | ! 88 | IF ( IFIRST ) THEN 89 | I = 1 90 | DO J=2,LO%NY-1 91 | IF (LO%H(I,J) .GT. GX) THEN 92 | CC = SQRT(GRAV*LO%H(I,J)) 93 | IF (LO%H(I,J-1) .GT. GX) THEN 94 | UH = 0.5*(LO%N(I,J,2)+LO%N(I,J-1,2)) 95 | ELSE 96 | UH = LO%N(I,J,2) 97 | ENDIF 98 | UU = SQRT(UH**2+LO%M(I,J,2)**2) 99 | ZZ = UU/CC 100 | ARG = LO%M(I,J,2) 101 | IF (ARG .GT. ZERO) THEN 102 | ZZ = -ZZ 103 | ENDIF 104 | ! IF (ABS(ZZ) .LE. EPS) ZZ = 0.0 105 | IF (ABS(ZZ) .GT. UB) ZZ=0.0 106 | LO%Z(I,J,2) = ZZ 107 | ELSE 108 | LO%Z(I,J,2) = ZERO 109 | ENDIF 110 | END DO 111 | ENDIF 112 | ! 113 | IF ( IEND ) THEN 114 | I = LO%NX 115 | DO J=2,LO%NY-1 116 | IF (LO%H(I,J) .GT. GX) THEN 117 | CC = SQRT(GRAV*LO%H(I,J)) 118 | UH = 0.5*(LO%N(I,J,2)+LO%N(I,J-1,2)) 119 | UU = SQRT(UH**2+LO%M(I-1,J,2)**2) 120 | ZZ = UU/CC 121 | ARG = LO%M(I-1,J,2) 122 | IF (ARG .LT. ZERO) THEN 123 | ZZ = -ZZ 124 | ENDIF 125 | ! IF (ABS(ZZ) .LE. EPS) ZZ = 0.0 126 | IF (ABS(ZZ) .GT. UB) ZZ=0.0 127 | LO%Z(I,J,2) = ZZ 128 | ELSE 129 | LO%Z(I,J,2) = ZERO 130 | ENDIF 131 | END DO 132 | ENDIF 133 | ! 134 | IF ( IFIRST .AND. JFIRST ) THEN 135 | IF (LO%H(1,1) .GT. GX) THEN 136 | QX = LO%M(1,1,2) 137 | QY = LO%N(1,1,2) 138 | CC = SQRT(GRAV*LO%H(1,1)) 139 | UH = SQRT(QX**2+QY**2) 140 | ZZ = UH/CC 141 | IF (QX .GT. ZERO .OR. QY.GT.ZERO) ZZ = -ZZ 142 | ! IF (ABS(ZZ) .LE. EPS) ZZ = 0.0 143 | IF (ABS(ZZ) .GT. UB) ZZ=0.0 144 | LO%Z(1,1,2) = ZZ 145 | ELSE 146 | LO%Z(1,1,2) = ZERO 147 | ENDIF 148 | ENDIF 149 | ! 150 | IF ( IEND .AND. JFIRST ) THEN 151 | IF (LO%H(LO%NX,1) .GT. GX) THEN 152 | QX = LO%M(LO%NX-1,1,2) 153 | QY = LO%N(LO%NX,1,2) 154 | CC = SQRT(GRAV*LO%H(LO%NX,1)) 155 | UH = SQRT(QX**2+QY**2) 156 | ZZ = UH/CC 157 | IF (QX .LT. ZERO .OR. QY.GT.ZERO) ZZ = -ZZ 158 | ! IF (ABS(ZZ) .LE. EPS) ZZ = 0.0 159 | IF (ABS(ZZ) .GT. UB) ZZ=0.0 160 | LO%Z(LO%NX,1,2) = ZZ 161 | ELSE 162 | LO%Z(LO%NX,1,2) = ZERO 163 | ENDIF 164 | ENDIF 165 | ! 166 | IF ( IFIRST .AND. JEND ) THEN 167 | IF (LO%H(1,LO%NY) .GT. GX) THEN 168 | QX = LO%M(1,LO%NY,2) 169 | QY = LO%N(1,LO%NY-1,2) 170 | CC = SQRT(GRAV*LO%H(1,LO%NY)) 171 | UH = SQRT(QX**2+QY**2) 172 | ZZ = UH/CC 173 | IF (QX .GT. ZERO .OR. QY.LT.ZERO) ZZ = -ZZ 174 | ! IF (ABS(ZZ) .LE. EPS) ZZ = 0.0 175 | IF (ABS(ZZ) .GT. UB) ZZ = 0.0 176 | LO%Z(1,LO%NY,2) = ZZ 177 | ELSE 178 | LO%Z(1,LO%NY,2) = ZERO 179 | ENDIF 180 | ENDIF 181 | ! 182 | IF ( IEND .AND. JEND ) THEN 183 | IF (LO%H(LO%NX,LO%NY) .GT. GX) THEN 184 | QX = LO%M(LO%NX-1,LO%NY,2) 185 | QY = LO%N(LO%NX,LO%NY-1,2) 186 | CC = SQRT(GRAV*LO%H(LO%NX,LO%NY)) 187 | UH = SQRT(QX**2+QY**2) 188 | ZZ = UH/CC 189 | IF (QX.LT.ZERO .OR. QY.LT.ZERO) ZZ = -ZZ 190 | ! IF (ABS(ZZ) .LE. EPS) ZZ = 0.0 191 | LO%Z(LO%NX,LO%NY,2) = ZZ 192 | ! LO%Z(LO%NX,LO%NY,2)=0.5*(LO%Z(LO%NX-1,LO%NY,2) & 193 | ! + LO%Z(LO%NX,LO%NY-1,2)) 194 | IF (ABS(LO%Z(LO%NX,LO%NY,2)) .GT. UB) & 195 | LO%Z(LO%NX,LO%NY,2)=0.0 196 | ELSE 197 | LO%Z(LO%NX,LO%NY,2) = ZERO 198 | ENDIF 199 | ENDIF 200 | ! 201 | RETURN 202 | END 203 | 204 | 205 | !---------------------------------------------------------------------- 206 | SUBROUTINE SPONGE_LAYER (LO) 207 | !DESCRIPTION: 208 | ! #. DETERMINE COEFFICIENT ALPHA SO AS TO IMPROVE NUMERICAL DISPERSION 209 | ! REF: WEI AND KIRBY (1995) AND KIRBY ET AL (1998); 210 | ! #, USED TOGETHER WITH RADIATION/OPEN BOUNDARY CONDITION; 211 | !NOTES: 212 | ! #. CREATED ON ??? ?? 2007 (XIAOMING WANG, CORNELL UNIVERSITY) 213 | ! #. UPDATED ON FEB 25 2009 (XIAOMING WANG, GNS) 214 | !---------------------------------------------------------------------- 215 | USE LAYER_PARAMS 216 | TYPE (LAYER) :: LO 217 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 218 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 219 | 220 | DO I = 1,LO%NX 221 | IP1 = I+1 222 | IM1 = I-1 223 | IF (IP1.GE.LO%NX) IP1 = LO%NX 224 | IF (IM1.LE.1) IM1 = 1 225 | DO J = 1,LO%NY 226 | JP1 = J+1 227 | JM1 = J-1 228 | IF (JP1.GE.LO%NY) JP1 = LO%NY 229 | IF (JM1.LE.1) JM1 = 1 230 | IF ( LO%SPONGE_COEFX(I,J).GT.ZERO .OR. & 231 | LO%SPONGE_COEFY(I,J).GT.ZERO ) THEN 232 | CX = LO%SPONGE_COEFX(I,J) 233 | CY = LO%SPONGE_COEFY(I,J) 234 | ! CXY = SQRT(CX**2+CY**2) 235 | !* LO%M(I,J,2) = LO%M(I,J,2) + CX*LO%DT & 236 | !* *0.5*(LO%M(I,J,1)+LO%M(I,J,2)) 237 | !* LO%N(I,J,2) = LO%N(I,J,2) + CY*LO%DT & 238 | !* *0.5*(LO%N(I,J,1)+LO%N(I,J,2)) 239 | LO%M(I,J,2) = LO%M(I,J,2) + CX*LO%DT*LO%M(I,J,1) 240 | LO%N(I,J,2) = LO%N(I,J,2) + CY*LO%DT*LO%N(I,J,1) 241 | ENDIF 242 | ENDDO 243 | ENDDO 244 | 245 | RETURN 246 | END 247 | 248 | 249 | !---------------------------------------------------------------------- 250 | SUBROUTINE SPONGE_COEF (LO) 251 | !DESCRIPTION: 252 | ! DETERMINE COEFFICIENT ALPHA SO AS TO IMPROVE NUMERICAL DISPERSION 253 | !.....REF: WEI AND KIRBY (1995) AND KIRBY ET AL (1998) 254 | !NOTES: 255 | ! #. CREATED ON ??? ?? 2007 (XIAOMING WANG, CORNELL UNIVERSITY) 256 | ! #. UPDATED ON FEB 25 2009 (XIAOMING WANG, GNS) 257 | !---------------------------------------------------------------------- 258 | USE LAYER_PARAMS 259 | ! USE WAVE_PARAMS 260 | ! USE FAULT_PARAMS 261 | TYPE (LAYER) :: LO 262 | ! TYPE (WAVE) :: WAVE_INFO 263 | ! TYPE (FAULT) :: FAULT_INFO 264 | REAL DX, DY, DT, G, R_MAX, RX, RY, X_REL, R, WIDTH,H_MEAN 265 | REAL COEFX(LO%NX,LO%NY),COEFY(LO%NX,LO%NY) 266 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 267 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 268 | 269 | DX = LO%DX 270 | DY = LO%DY 271 | DT = LO%DT 272 | !WIDTH OF SPONGE LAYER IS 1.5 TIMES THE CHARACTERISTIC WAVE LENGTH 273 | 274 | !TYPICAL WATER LENGTH, USED TO DETERMINE CHARACTERSTIC WAVE NUMBER 275 | CALL H_CALC(LO,H_MEAN,H_MAX) 276 | 277 | DEPTH = H_MEAN 278 | 279 | IF (DEPTH.LE.GX) DEPTH = GX 280 | 281 | !DETERMINE CHARACTERISTIC WAVE LENGTH 282 | WAVELENGTH = 20.0*DEPTH 283 | WIDTH = 2.0*WAVELENGTH 284 | 285 | !PARAMETERS USED BY KIRBY ET AL (1998) 286 | ALPHA_C = 10.0; 287 | ALPHA_MU = ZERO; 288 | M = 2.0; 289 | T = WAVELENGTH/SQRT(GRAV*DEPTH) 290 | OMEGA = 2.0*PI/T 291 | 292 | !.....IF LAYER01 ADOPTS SPHERICAL COORD, 293 | ! CONVERT WIDTH (IN METERS) TO ARC MINUTES 294 | IF (LO%LAYCORD .EQ. 0) THEN 295 | SPONGE_WIDTH = WIDTH/R_EARTH*180.0/PI 296 | ELSE 297 | SPONGE_WIDTH = WIDTH 298 | ENDIF 299 | 300 | R_MAX = WIDTH !MAXIMUM DISTANCE FOR DAMPING 301 | 302 | XS = LO%X(1) + SPONGE_WIDTH 303 | YS = LO%Y(1) + SPONGE_WIDTH 304 | XE = LO%X(LO%NX) - SPONGE_WIDTH 305 | YE = LO%Y(LO%NY) - SPONGE_WIDTH 306 | 307 | COEFX = ZERO 308 | COEFY = ZERO 309 | DO I = 1,LO%NX 310 | DO J = 1,LO%NY 311 | X0 = LO%X(I) 312 | Y0 = LO%Y(J) 313 | IF (X0 .LE. XS) THEN 314 | RX = -(X0 - XS) 315 | ELSEIF (X0 .GE. XE) THEN 316 | RX = X0 - XE 317 | ELSE 318 | RX = ZERO 319 | ENDIF 320 | IF (Y0 .LE. YS) THEN 321 | RY = -(Y0 - YS) 322 | ELSEIF (Y0 .GE. YE) THEN 323 | RY = Y0 - YE 324 | ELSE 325 | RY = ZERO 326 | ENDIF 327 | R = SQRT(RX**2+RY**2) 328 | X_REL = RX 329 | Y_REL = RY 330 | IF (X_REL .LE. ZERO) X_REL = ZERO 331 | IF (Y_REL .LE. ZERO) Y_REL = ZERO 332 | IF (X_REL .GE. R_MAX) X_REL = R_MAX 333 | IF (Y_REL .GE. R_MAX) Y_REL = R_MAX 334 | 335 | COEFX(I,J) = ALPHA_C*OMEGA*(EXP((X_REL/R_MAX)**M)-1.0) & 336 | /(EXP(1.0)-1.0) 337 | COEFY(I,J) = ALPHA_C*OMEGA*(EXP((Y_REL/R_MAX)**M)-1.0) & 338 | /(EXP(1.0)-1.0) 339 | IF (COEFX(I,J).LE.EPS) COEFX(I,J) = 0.0 340 | IF (COEFY(I,J).LE.EPS) COEFY(I,J) = 0.0 341 | ENDDO 342 | ENDDO 343 | LO%SPONGE_COEFX = COEFX 344 | LO%SPONGE_COEFY = COEFY 345 | 346 | RETURN 347 | END 348 | 349 | 350 | !---------------------------------------------------------------------- 351 | SUBROUTINE H_CALC (LO,H_MEAN,H_MAX) 352 | !DESCRIPTION: 353 | ! DETERMINE COEFFICIENT ALPHA SO AS TO IMPROVE NUMERICAL DISPERSION 354 | !.....REF: WEI AND KIRBY (1995) AND KIRBY ET AL (1998) 355 | !NOTES: 356 | ! #. CREATED ON ??? ?? 2007 (XIAOMING WANG, CORNELL UNIVERSITY) 357 | ! #. UPDATED ON FEB 25 2009 (XIAOMING WANG, GNS) 358 | !---------------------------------------------------------------------- 359 | USE LAYER_PARAMS 360 | TYPE (LAYER) :: LO 361 | REAL DX, DY, DT, G, R_MAX, RX, RY, X_REL, R, WIDTH 362 | REAL H_MEAN,H_SUM 363 | INTEGER K 364 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 365 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 366 | 367 | K = 0 368 | H_MEAN = ZERO 369 | H_SUM = ZERO 370 | H_MAX = ZERO 371 | 372 | DO I = 1,LO%NX 373 | DO J = 1,LO%NY 374 | IF (LO%H(I,J) .GT. GX) THEN 375 | H_SUM = H_SUM + LO%H(I,J) 376 | IF (H_MAX.LT.LO%H(I,J)) H_MAX = LO%H(I,J) 377 | K = K+1 378 | ENDIF 379 | ENDDO 380 | ENDDO 381 | IF (K.GT.0) H_MEAN = H_SUM/K 382 | ! WRITE(*,*) H_MEAN 383 | 384 | RETURN 385 | END 386 | 387 | !---------------------------------------------------------------------- 388 | SUBROUTINE BC_WALL (LO,WAVE_INFO) 389 | !.....SET UP VERTICAL WALL BOUNDARY 390 | !Incident direction( 1:top,2:bt,3:lf,4:rt,5:ob ) 391 | !---------------------------------------------------------------------- 392 | USE LAYER_PARAMS 393 | USE WAVE_PARAMS 394 | TYPE (LAYER) :: LO 395 | TYPE (WAVE) :: WAVE_INFO 396 | IF (LO%INI_SWITCH.EQ.2 ) THEN 397 | IF (WAVE_INFO%INCIDENT.EQ.1) THEN 398 | LO%H(1:2,:) = -999.0 399 | LO%H(:,1:2) = -999.0 400 | LO%H(LO%NX-1:LO%NX,:) = -999.0 401 | !* LO%H(:,LO%NY-1:LO%NY) = -999.0 402 | ENDIF 403 | IF (WAVE_INFO%INCIDENT.EQ.2) THEN 404 | LO%H(1:2,:) = -999.0 405 | !* LO%H(:,1:2) = -999.0 406 | LO%H(LO%NX-1:LO%NX,:) = -999.0 407 | LO%H(:,LO%NY-1:LO%NY) = -999.0 408 | ENDIF 409 | IF (WAVE_INFO%INCIDENT.EQ.3) THEN 410 | !* LO%H(1:2,:) = -999.0 411 | LO%H(:,1:2) = -999.0 412 | LO%H(LO%NX-1:LO%NX,:) = -999.0 413 | LO%H(:,LO%NY-1:LO%NY) = -999.0 414 | ENDIF 415 | IF (WAVE_INFO%INCIDENT.EQ.4) THEN 416 | LO%H(1:2,:) = -999.0 417 | LO%H(:,1:2) = -999.0 418 | !* LO%H(LO%NX-1:LO%NX,:) = -999.0 419 | LO%H(:,LO%NY-1:LO%NY) = -999.0 420 | ENDIF 421 | ELSE 422 | LO%H(1:2,:) = -999.0 423 | LO%H(:,1:2) = -999.0 424 | LO%H(LO%NX-1:LO%NX,:) = -999.0 425 | LO%H(:,LO%NY-1:LO%NY) = -999.0 426 | ENDIF 427 | RETURN 428 | END 429 | 430 | !---------------------------------------------------------------------- 431 | SUBROUTINE READ_FACTS (BCI_INFO,LO,SWITCH) 432 | !.....READ FACTS INPUT FILES AS INPUT BOUNDARY CONDITIONS 433 | ! SWITCH: 434 | ! 0-SURFACE ELEVATION DATA, ####H.ASC 435 | ! 1-HORIZONTAL VELOCITY DATA, ####U.ASC 436 | ! 2-VERTICAL VELOCITY DATA, ####V.ASC 437 | !.....CREATED ON NOV 11 2008 (XIAOMING WANG, GNS) 438 | ! LAST REVISE: NOV.27, 2008 (XIAOMING WANG, GNS) 439 | !---------------------------------------------------------------------- 440 | USE LAYER_PARAMS 441 | USE BCI_PARAMS 442 | TYPE (LAYER) :: LO 443 | TYPE (BCI) :: BCI_INFO 444 | INTEGER NX,NY,NT 445 | INTEGER BC_TYPE,POS,SWITCH,STAT 446 | REAL H(LO%NX,LO%NY) 447 | REAL,ALLOCATABLE :: SNAPSHOT(:,:,:) 448 | CHARACTER(LEN=120) INE,LINE1,LINE2,LINE3 449 | CHARACTER(LEN=120) DUMP,TMP,FNAME 450 | CHARACTER(LEN=18) TEXT 451 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 452 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 453 | 454 | ! WRITE(*,*) BCI_INFO%FNAMEH 455 | ! WRITE(*,*) BCI_INFO%FNAMEU 456 | ! WRITE(*,*) BCI_INFO%FNAMEV 457 | FNAME = '' 458 | IF (SWITCH.EQ.0) FNAME = BCI_INFO%FNAMEH 459 | IF (SWITCH.EQ.1) FNAME = BCI_INFO%FNAMEU 460 | IF (SWITCH.EQ.2) FNAME = BCI_INFO%FNAMEV 461 | WRITE (*,*) FNAME 462 | ! 463 | !...../////// READ H,U,V DATA FROM FACTS OUTPUT //////////// 464 | OPEN(UNIT=1,FILE=FNAME,STATUS='OLD',IOSTAT=STAT,FORM='FORMATTED') 465 | IF (STAT /=0) THEN 466 | PRINT *,"ERROR:: CAN'T OPEN FACTS DATA",FNAME,"; EXITING." 467 | STOP 468 | END IF 469 | POS = 0 470 | DO WHILE (POS.LE.0) 471 | READ (1,*) DUMP 472 | ! WRITE (*,*) DUMP 473 | POS = INDEX(DUMP,'GEOMETRY') 474 | DUMP = '' 475 | ! PAUSE 476 | ENDDO 477 | READ (1,*) TEXT,NX,NY,NT 478 | WRITE(*,*) NX,NY,NT 479 | ALLOCATE(SNAPSHOT(NX,NY,NT)) 480 | SNAPSHOT = ZERO 481 | 482 | IF (SWITCH.EQ.0) THEN 483 | ALLOCATE(BCI_INFO%X(NX)) 484 | ALLOCATE(BCI_INFO%Y(NY)) 485 | ALLOCATE(BCI_INFO%T(NT)) 486 | ALLOCATE(BCI_INFO%SNAPSHOT(NX,NY,NT)) 487 | ALLOCATE(BCI_INFO%SNAPSHOTU(NX,NY,NT)) 488 | ALLOCATE(BCI_INFO%SNAPSHOTV(NX,NY,NT)) 489 | ALLOCATE(BCI_INFO%Z_VERT(LO%NY,NT,2)) 490 | ALLOCATE(BCI_INFO%U_VERT(LO%NY,NT,2)) 491 | ALLOCATE(BCI_INFO%V_VERT(LO%NY,NT,2)) 492 | ALLOCATE(BCI_INFO%Z_HORI(LO%NX,NT,2)) 493 | ALLOCATE(BCI_INFO%U_HORI(LO%NX,NT,2)) 494 | ALLOCATE(BCI_INFO%V_HORI(LO%NX,NT,2)) 495 | END IF 496 | 497 | READ (1,*) DUMP 498 | READ (1,*) DUMP 499 | READ (1,*) DUMP 500 | READ (1,*) (BCI_INFO%X(I),I=1,NX) 501 | READ (1,*) DUMP 502 | READ (1,*) (BCI_INFO%Y(I),I=1,NY) 503 | READ (1,*) DUMP 504 | READ (1,*) (BCI_INFO%T(I),I=1,NT) 505 | READ (1,*) DUMP 506 | 507 | DO K = 1,NT 508 | DO J = 1,NY 509 | READ (1,*) (SNAPSHOT(I,J,K),I=1,NX) 510 | ENDDO 511 | ENDDO 512 | 513 | CLOSE(1) 514 | 515 | IF (SWITCH.EQ.0) THEN 516 | BCI_INFO%NX = NX 517 | BCI_INFO%NY = NY 518 | BCI_INFO%NT = NT 519 | BCI_INFO%DURATION = BCI_INFO%T(NT)-BCI_INFO%T(1) 520 | !* BCI_INFO%T(:) = BCI_INFO%T(:)-BCI_INFO%T(1) 521 | ENDIF 522 | !.....CONVERT UNITS FROM CM OR CM/S TO M OR M/S 523 | IF (SWITCH.EQ.0) BCI_INFO%SNAPSHOT = SNAPSHOT/100.0 524 | IF (SWITCH.EQ.1) BCI_INFO%SNAPSHOTU = SNAPSHOT/100.0 525 | IF (SWITCH.EQ.2) BCI_INFO%SNAPSHOTV = SNAPSHOT/100.0 526 | 527 | ! WRITE(*,*) NX,NY,NT 528 | 529 | DEALLOCATE(SNAPSHOT,STAT = ISTAT) 530 | 531 | RETURN 532 | END 533 | 534 | 535 | !---------------------------------------------------------------------- 536 | SUBROUTINE BC_INPUT (BI,LO,TIME) 537 | !...................................................................... 538 | !DESCRIPTION: 539 | ! #. MAP THE BOUNDARY CONDITION FROM FACTS TO COMPUTATIONAL GRIDS; 540 | !NOTES: 541 | ! #. CREATED ON NOV 11 2008 (XIAOMING WANG, GNS) 542 | ! #. LAST REVISE: NOV.24, 2008 (XIAOMING WANG, GNS) 543 | ! #. UPDATED ON MAR 10 2009 (XIAOMING WANG, GNS) 544 | !---------------------------------------------------------------------- 545 | USE LAYER_PARAMS 546 | USE BCI_PARAMS 547 | TYPE (LAYER) :: LO 548 | TYPE (BCI) :: BI 549 | REAL T(BI%NT),TMPX(LO%NX),TMPY(LO%NY) 550 | REAL TIME,C1,C2 551 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 552 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 553 | T(:) = BI%T(:) 554 | 555 | !.....OBTAIN SURFACE ELEVATION AT T = TIME FROM FACTS DATA 556 | KT = 1 557 | DO K = 1,BI%NT-1 558 | IF (TIME-0.5*LO%DT.GE.BI%T(K) .AND. & 559 | TIME-0.5*LO%DT.LT.BI%T(K+1)) KT = K 560 | ENDDO 561 | C1 = (TIME-0.5*LO%DT-BI%T(KT))/(BI%T(KT+1)-BI%T(KT)) 562 | C2 = 1.0 - C1 563 | 564 | DO I = 1,LO%NX 565 | LO%Z(I,1,2) = C1*BI%Z_HORI(I,KT+1,1) + C2*BI%Z_HORI(I,KT,1) 566 | LO%Z(I,LO%NY,2) = C1*BI%Z_HORI(I,KT+1,2) + C2*BI%Z_HORI(I,KT,2) 567 | ! DZDT = (BI%Z_HORI(I,KT+1,1)-BI%Z_HORI(I,KT,1))/(T(KT+1)-T(KT)) 568 | ! LO%Z(I,1,2) = LO%Z(I,1,2) + LO%DT*DZDT 569 | ! DZDT = (BI%Z_HORI(I,KT+1,2)-BI%Z_HORI(I,KT,2))/(T(KT+1)-T(KT)) 570 | ! LO%Z(I,LO%NY,2) = LO%Z(I,LO%NY,2) + LO%DT*DZDT 571 | ENDDO 572 | DO J = 1,LO%NY 573 | LO%Z(1,J,2) = C1*BI%Z_VERT(J,KT+1,1) + C2*BI%Z_VERT(J,KT,1) 574 | LO%Z(LO%NX,J,2) = C1*BI%Z_VERT(J,KT+1,2) + C2*BI%Z_VERT(J,KT,2) 575 | ! DZDT = (BI%Z_VERT(J,KT+1,1)-BI%Z_VERT(J,KT,1))/(T(KT+1)-T(KT)) 576 | ! LO%Z(1,J,2) = LO%Z(1,J,2) + LO%DT*DZDT 577 | ! DZDT = (BI%Z_VERT(J,KT+1,2)-BI%Z_VERT(J,KT,2))/(T(KT+1)-T(KT)) 578 | ! LO%Z(LO%NX,J,2) = LO%Z(LO%NX,J,2) + LO%DT*DZDT 579 | ENDDO 580 | 581 | !.....OBTAIN VOLUME FLUX AT T = TIME 582 | KT = 1 583 | DO K = 1,BI%NT-1 584 | IF (TIME.GE.BI%T(K) .AND. TIME.LT.BI%T(K+1)) KT = K 585 | ENDDO 586 | C1 = (TIME-BI%T(KT))/(BI%T(KT+1)-BI%T(KT)) 587 | C2 = 1.0 - C1 588 | 589 | DO I = 1,LO%NX 590 | LO%M(I,1,2) = C1*BI%U_HORI(I,KT+1,1) + C2*BI%U_HORI(I,KT,1) 591 | LO%M(I,LO%NY,2) = C1*BI%U_HORI(I,KT+1,2) + C2*BI%U_HORI(I,KT,2) 592 | ! DPDT = (BI%U_HORI(I,KT+1,1)-BI%U_HORI(I,KT,1))/(T(KT+1)-T(KT)) 593 | ! LO%M(I,1,1) = LO%M(I,1,1) + LO%DT*DPDT 594 | ! DPDT = (BI%U_HORI(I,KT+1,2)-BI%U_HORI(I,KT,2))/(T(KT+1)-T(KT)) 595 | ! LO%M(I,LO%NY,1) = LO%M(I,LO%NY,1) + LO%DT*DPDT 596 | ENDDO 597 | DO J = 1,LO%NY 598 | LO%M(1,J,2) = C1*BI%U_VERT(J,KT+1,1) + C2*BI%U_VERT(J,KT,1) 599 | LO%M(LO%NX-1,J,2) = C1*BI%U_VERT(J,KT+1,2) + C2*BI%U_VERT(J,KT,2) 600 | ! DPDT = (BI%U_VERT(J,KT+1,1)-BI%U_VERT(J,KT,1))/(T(KT+1)-T(KT)) 601 | ! LO%M(1,J,1) = LO%M(1,J,1) + LO%DT*DPDT 602 | ! DPDT = (BI%U_VERT(J,KT+1,2)-BI%U_VERT(J,KT,2))/(T(KT+1)-T(KT)) 603 | ! LO%M(LO%NX-1,J,1) = LO%M(LO%NX-1,J,1) + LO%DT*DPDT 604 | ENDDO 605 | DO I = 1,LO%NX 606 | LO%N(I,1,2) = C1*BI%V_HORI(I,KT+1,1) + C2*BI%V_HORI(I,KT,1) 607 | LO%N(I,LO%NY-1,2) = C1*BI%V_HORI(I,KT+1,2) + C2*BI%V_HORI(I,KT,2) 608 | ! DQDT = (BI%V_HORI(I,KT+1,1)-BI%V_HORI(I,KT,1))/(T(KT+1)-T(KT)) 609 | ! LO%N(I,1,1) = LO%N(I,1,1) + LO%DT*DQDT 610 | ! DQDT = (BI%V_HORI(I,KT+1,2)-BI%V_HORI(I,KT,2))/(T(KT+1)-T(KT)) 611 | ! LO%N(I,LO%NY-1,1) = LO%N(I,LO%NY-1,1) + LO%DT*DQDT 612 | ENDDO 613 | DO J = 1,LO%NY 614 | LO%N(1,J,2) = C1*BI%V_VERT(J,KT+1,1) + C2*BI%V_VERT(J,KT,1) 615 | LO%N(LO%NX,J,2) = C1*BI%V_VERT(J,KT+1,2) + C2*BI%V_VERT(J,KT,2) 616 | ! DQDT = (BI%V_VERT(J,KT+1,1)-BI%V_VERT(J,KT,1))/(T(KT+1)-T(KT)) 617 | ! LO%N(1,J,1) = LO%N(1,J,1) + LO%DT*DQDT 618 | ! DQDT = (BI%V_VERT(J,KT+1,2)-BI%V_VERT(J,KT,2))/(T(KT+1)-T(KT)) 619 | ! LO%N(LO%NX,J,1) = LO%N(LO%NX,J,1) + LO%DT*DQDT 620 | ENDDO 621 | 622 | RETURN 623 | END 624 | -------------------------------------------------------------------------------- /comcot.ctl: -------------------------------------------------------------------------------- 1 | ################################################# 2 | # # 3 | # Control file for COMCOT program (v1.7) # 4 | # Sample # 5 | ################################################# 6 | #--+-----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 7 | #===============================================:=============================== 8 | # General Parameters for Simulation : Value Field | 9 | #===============================================:=============================== 10 | #Job Description: NZ30sec bathymetry, Spherical Coordinates for code testing 11 | Total run time (Wall clock, seconds) : 86400.0 12 | Time interval to Save Data ( unit: sec ) : 1800.0 13 | Output Zmax & TS (0-Max Z;1-Timeseries;2-Both) : 2 14 | Start Type (0-Cold start; 1-Hot start) : 0 15 | Resuming Time If hot start (Seconds) : 100000000000000.00 16 | Specify Min WaterDepth offshore (meter) : 10.00 17 | Initial Cond. (0:FLT,1:File,2:WM,3:LS,4:FLT+LS): 0 18 | Specify BC (0-Open;1-Sponge;2-Wall;3-FACTS) : 0 19 | Specify Input Z filename (for BC=3, FACTS) : mw94_n22_nz_ha.xyt 20 | Specify Input U filename (for BC=3, FACTS) : mw94_n22_nz_ua.xyt 21 | Specify Input V filename (for BC=3, FACTS) : mw94_n22_nz_va.xyt 22 | 23 | #===============================================:=============================== 24 | # Parameters for Fault Model (Segment 01) :Values | 25 | #===============================================:=============================== 26 | No. of FLT Planes (With fault_multi.ctl if >1) : 1 27 | Fault Rupture Time (seconds) : 0.0 28 | Faulting Option (0: Model; 1- Data;) : 9 29 | Focal Depth (meter): 20.0 30 | Length of source area (meter): 548.479219e3 31 | Width of source area (meter): 182.826406e3 32 | Dislocation of fault plate (meter): 16.343058 33 | Strike direction (theta) (degree): 203.0 34 | Dip angle (delta) (degree): 10.0 35 | Slip angle (lambda) (degree): 88.0 36 | Origin of Comp. Domain (Layer 01) (Lat, degree): 0.0 37 | Origin of Comp. Domain (Layer 01) (Lon, degree): 110.0 38 | Epicenter Location: Latitude (degree): 37.520 39 | Epicenter Location: Longitude (degree): 143.050 40 | File Name of Deformation Data : fault12.xyz 41 | Data Format Option (0-COMCOT; 1-MOST; 2-XYZ) : 2 42 | 43 | #===============================================:=============================== 44 | # Parameters for Wave Maker :Values | 45 | #===============================================:=============================== 46 | Wave type ( 1:Solit, 2:given, 3:focusing ) : 1 47 | FileName of Customized Input (for Type=2) : fse.dat 48 | Incident direction( 1:top,2:bt,3:lf,4:rt,5:ob ): 2 49 | Characteristic Wave Amplitude (meter) : 0.500 50 | Typical Water depth (meter) : 2000.000 51 | 52 | #===============================================:=============================== 53 | # Parameters for Submarine LS/Transient Motion :ValUes | 54 | #===============================================:=============================== 55 | X Coord. of Left/West Edge of Landlide Area : 177.00 56 | X Coord. of Right/East Edge of Landlide Area : 179.00 57 | Y Coord. of Bottom/South Edge of Landlide Area : -41.00 58 | Y Coord. of Top/North Edge of Landlide Area : -39.00 59 | File Name of landslide Data : landslide_test.dat 60 | Data Format Option (0-Old; 1-XYT; 2-Function) : 2 61 | 62 | #===============================================:=============================== 63 | # Configurations for all grids :Values | 64 | #===============================================:=============================== 65 | # Parameters for 1st-level grid -- layer 01 :Values | 66 | #===============================================:=============================== 67 | Run This Layer ? (0:Yes, 1:No ): 0 68 | Coordinate System (0:spherical, 1:cartesian): 0 69 | Governing Equations (0:linear, 1:nonlinear): 0 70 | Grid Size (dx, sph:minute, cart:meter) : 4.0 71 | Time step ( second ): 2.0 72 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 1 73 | Manning's Roughness Coef. (For fric.option=0) : 0.013 74 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 0 75 | X_start : 105.0 76 | X_end : 300.0 77 | Y_Start : -56.0 78 | Y_end : 63.0 79 | File Name of Bathymetry Data :../etopo_halk2.xyz 80 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 81 | Grid Identification Number : 01 82 | Grid Level : 1 83 | Parent Grid's ID Number : -1 84 | 85 | #===============================================:=============================== 86 | # Parameters for Sub-level grid -- layer 02 :Values | 87 | #===============================================:=============================== 88 | Run This Layer ? (0:Yes, 1:No ): 0 89 | Coordinate (0:spherical, 1:cartesian): 0 90 | Governing Eqn. (0:linear, 1:nonlinear): 0 91 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 1 92 | Manning's Roughness Coef. (For fric.option=0) : 0.013 93 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 0 94 | GridSize Ratio of Parent layer to current layer: 4 95 | X_start : 125.0 96 | X_end : 150.0 97 | Y_start : 30.0 98 | Y_end : 50.0 99 | FileName of Water depth data :../etopo_halk2.xyz 100 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 101 | Grid Identification Number : 02 102 | Grid Level : 2 103 | Parent Grid's ID Number : 01 104 | 105 | #===============================================:=============================== 106 | # Parameters for Sub-level grid -- layer 03 :Values | 107 | #===============================================:=============================== 108 | Run This Layer ? (0:Yes, 1:No ): 0 109 | Coordinate (0:spherical, 1:cartesian): 0 110 | Governing Eqn. (0:linear, 1:nonlinear): 0 111 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 1 112 | Manning's Roughness Coef. (For fric.option=0) : 0.013 113 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 114 | GridSize Ratio of Parent layer to current layer: 8 115 | X_start : 119.9 116 | X_end : 122.1 117 | Y_start : 21.8 118 | Y_end : 25.4 119 | FileName of Water depth data :../etopo_halk2.xyz 120 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 121 | Grid Identification Number : 03 122 | Grid Level : 3 123 | Parent Grid's ID Number : 01 124 | 125 | #===============================================:=============================== 126 | # Parameters for Sub-level grid -- layer 04 :Values | 127 | #===============================================:=============================== 128 | Run This Layer ? (0:Yes, 1:No ): 0 129 | Coordinate (0:spherical, 1:cartesian): 0 130 | Governing Eqn. (0:linear, 1:nonlinear): 0 131 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 1 132 | Manning's Roughness Coef. (For fric.option=0) : 0.013 133 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 134 | GridSize Ratio of Parent layer to current layer: 16 135 | X_start : 143.0 136 | X_end : 144.0 137 | Y_start : 37.0 138 | Y_end : 38.0 139 | FileName of Water depth data :../etopo_halk2.xyz 140 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 141 | Grid Identification Number : 04 142 | Grid Level : 3 143 | Parent Grid's ID Number : 01 144 | 145 | #===============================================:=============================== 146 | # Parameters for Sub-level grid -- layer 05 :Values | 147 | #===============================================:=============================== 148 | Run This Layer ? (0:Yes, 1:No ): 0 149 | Coordinate (0:spherical, 1:cartesian): 0 150 | Governing Eqn. (0:linear, 1:nonlinear): 0 151 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 1 152 | Manning's Roughness Coef. (For fric.option=0) : 0.013 153 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 154 | GridSize Ratio of Parent layer to current layer: 4 155 | X_start : 120.3092711496687 156 | X_end : 120.723621321133 157 | Y_start : 22.1896412622199 158 | Y_end : 22.53257020096585 159 | FileName of Water depth data :../etopo_halk2.xyz 160 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 161 | Grid Identification Number : 05 162 | Grid Level : 3 163 | Parent Grid's ID Number : 03 164 | 165 | #===============================================:=============================== 166 | # Parameters for Sub-level grid -- layer 06 :Values | 167 | #===============================================:=============================== 168 | Run This Layer ? (0:Yes, 1:No ): 0 169 | Coordinate (0:spherical, 1:cartesian): 0 170 | Governing Eqn. (0:linear, 1:nonlinear): 0 171 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 0 172 | Manning's Roughness Coef. (For fric.option=0) : 0.013 173 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 174 | GridSize Ratio of Parent layer to current layer: 16 175 | X_start : 120.0036509071348 176 | X_end : 120.5120381818606 177 | Y_start : 22.42373978748143 178 | Y_end : 24.24865827343963 179 | FileName of Water depth data :../etopo_halk2.xyz 180 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 181 | Grid Identification Number : 06 182 | Grid Level : 3 183 | Parent Grid's ID Number : 03 184 | 185 | #===============================================:=============================== 186 | # Parameters for Sub-level grid -- layer 07 :Values | 187 | #===============================================:=============================== 188 | Run This Layer ? (0:Yes, 1:No ): 0 189 | Coordinate (0:spherical, 1:cartesian): 0 190 | Governing Eqn. (0:linear, 1:nonlinear): 0 191 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 0 192 | Manning's Roughness Coef. (For fric.option=0) : 0.013 193 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 194 | GridSize Ratio of Parent layer to current layer: 16 195 | X_start : 120.4562042092812 196 | X_end : 120.9175729323763 197 | Y_start : 24.15490301533408 198 | Y_end : 24.80244805853942 199 | FileName of Water depth data :../etopo_halk2.xyz 200 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 201 | Grid Identification Number : 07 202 | Grid Level : 3 203 | Parent Grid's ID Number : 03 204 | 205 | #===============================================:=============================== 206 | # Parameters for Sub-level grid -- layer 08 :Values | 207 | #===============================================:=============================== 208 | Run This Layer ? (0:Yes, 1:No ): 0 209 | Coordinate (0:spherical, 1:cartesian): 0 210 | Governing Eqn. (0:linear, 1:nonlinear): 0 211 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 0 212 | Manning's Roughness Coef. (For fric.option=0) : 0.013 213 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 214 | GridSize Ratio of Parent layer to current layer: 16 215 | X_start : 120.808842317314 216 | X_end : 121.3231069967601 217 | Y_start : 24.69987279481362 218 | Y_end : 25.19808824930069 219 | FileName of Water depth data :../etopo_halk2.xyz 220 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 221 | Grid Identification Number : 08 222 | Grid Level : 3 223 | Parent Grid's ID Number : 03 224 | 225 | #===============================================:=============================== 226 | # Parameters for Sub-level grid -- layer 09 :Values | 227 | #===============================================:=============================== 228 | Run This Layer ? (0:Yes, 1:No ): 1 229 | Coordinate (0:spherical, 1:cartesian): 0 230 | Governing Eqn. (0:linear, 1:nonlinear): 1 231 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 0 232 | Manning's Roughness Coef. (For fric.option=0) : 0.013 233 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 234 | GridSize Ratio of Parent layer to current layer: 16 235 | X_start : 121.2320085958588 236 | X_end : 122.0460161131184 237 | Y_start : 24.96080357036498 238 | Y_end : 25.3508512831777 239 | FileName of Water depth data : 4_6.xyz 240 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 241 | Grid Identification Number : 09 242 | Grid Level : 3 243 | Parent Grid's ID Number : 02 244 | 245 | #===============================================:=============================== 246 | # Parameters for Sub-level grid -- layer 10 :Values | 247 | #===============================================:=============================== 248 | Run This Layer ? (0:Yes, 1:No ): 1 249 | Coordinate (0:spherical, 1:cartesian): 0 250 | Governing Eqn. (0:linear, 1:nonlinear): 1 251 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 0 252 | Manning's Roughness Coef. (For fric.option=0) : 0.013 253 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 254 | GridSize Ratio of Parent layer to current layer: 16 255 | X_start : 121.7227643425554 256 | X_end : 122.0489548154786 257 | Y_start : 24.22894457248688 258 | Y_end : 25.0404101584892 259 | FileName of Water depth data : 4_7.xyz 260 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 261 | Grid Identification Number : 10 262 | Grid Level : 3 263 | Parent Grid's ID Number : 02 264 | 265 | #===============================================:=============================== 266 | # Parameters for Sub-level grid -- layer 11 :Values | 267 | #===============================================:=============================== 268 | Run This Layer ? (0:Yes, 1:No ): 1 269 | Coordinate (0:spherical, 1:cartesian): 0 270 | Governing Eqn. (0:linear, 1:nonlinear): 1 271 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 0 272 | Manning's Roughness Coef. (For fric.option=0) : 0.013 273 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 274 | GridSize Ratio of Parent layer to current layer: 16 275 | X_start : 121.3906957787801 276 | X_end : 121.8079853387364 277 | Y_start : 23.41747516260113 278 | Y_end : 24.38422152963531 279 | FileName of Water depth data : 4_8.xyz 280 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 281 | Grid Identification Number : 11 282 | Grid Level : 3 283 | Parent Grid's ID Number : 02 284 | 285 | #===============================================:=============================== 286 | # Parameters for Sub-level grid -- layer 12 :Values | 287 | #===============================================:=============================== 288 | Run This Layer ? (0:Yes, 1:No ): 1 289 | Coordinate (0:spherical, 1:cartesian): 0 290 | Governing Eqn. (0:linear, 1:nonlinear): 1 291 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 0 292 | Manning's Roughness Coef. (For fric.option=0) : 0.013 293 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 294 | GridSize Ratio of Parent layer to current layer: 16 295 | X_start : 121.1203399645682 296 | X_end : 121.4906102867619 297 | Y_start : 22.74369554382476 298 | Y_end : 23.51418785598371 299 | FileName of Water depth data : 4_9.xyz 300 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 301 | Grid Identification Number : 12 302 | Grid Level : 3 303 | Parent Grid's ID Number : 02 304 | 305 | #===============================================:=============================== 306 | # Parameters for Sub-level grid -- layer 13 :Values | 307 | #===============================================:=============================== 308 | Run This Layer ? (0:Yes, 1:No ): 1 309 | Coordinate (0:spherical, 1:cartesian): 0 310 | Governing Eqn. (0:linear, 1:nonlinear): 1 311 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 0 312 | Manning's Roughness Coef. (For fric.option=0) : 0.013 313 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 314 | GridSize Ratio of Parent layer to current layer: 16 315 | X_start : 120.808842317314 316 | X_end : 121.2084996631093 317 | Y_start : 22.14603554034114 318 | Y_end : 22.78475484366331 319 | FileName of Water depth data : 4_10.xyz 320 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 321 | Grid Identification Number : 13 322 | Grid Level : 3 323 | Parent Grid's ID Number : 02 324 | 325 | #===============================================:=============================== 326 | # Parameters for Sub-level grid -- layer 14 :Values | 327 | #===============================================:=============================== 328 | Run This Layer ? (0:Yes, 1:No ): 1 329 | Coordinate (0:spherical, 1:cartesian): 0 330 | Governing Eqn. (0:linear, 1:nonlinear): 1 331 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 0 332 | Manning's Roughness Coef. (For fric.option=0) : 0.013 333 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 334 | GridSize Ratio of Parent layer to current layer: 16 335 | X_start : 120.808842317314 336 | X_end : 121.2084996631093 337 | Y_start : 22.14603554034114 338 | Y_end : 22.78475484366331 339 | FileName of Water depth data : 4_10.xyz 340 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 341 | Grid Identification Number : 14 342 | Grid Level : 3 343 | Parent Grid's ID Number : 02 344 | 345 | #===============================================:=============================== 346 | # Parameters for Sub-level grid -- layer 15 :Values | 347 | #===============================================:=============================== 348 | Run This Layer ? (0:Yes, 1:No ): 1 349 | Coordinate (0:spherical, 1:cartesian): 0 350 | Governing Eqn. (0:linear, 1:nonlinear): 1 351 | Bottom Friction Switch? (0:Yes,1:No,2:var. n ) : 0 352 | Manning's Roughness Coef. (For fric.option=0) : 0.013 353 | Layer Ouput Option? (0:Z+Hu+Hv;1:Z Only;2:NONE): 1 354 | GridSize Ratio of Parent layer to current layer: 16 355 | X_start : 120.808842317314 356 | X_end : 121.2084996631093 357 | Y_start : 22.14603554034114 358 | Y_end : 22.78475484366331 359 | FileName of Water depth data : 4_10.xyz 360 | Data Format Option (0-OLD;1-MOST;2-XYZ;3-ETOPO): 3 361 | Grid Identification Number : 15 362 | Grid Level : 3 363 | Parent Grid's ID Number : 02 364 | -------------------------------------------------------------------------------- /debug_option.h: -------------------------------------------------------------------------------- 1 | #ifndef DBG_OPT 2 | #define DBG_OPT 3 | 4 | /* #define DEBUG_ALL_GRID */ 5 | /* #define DEBUG_CORE */ 6 | 7 | /* #define RELDIFF */ 8 | 9 | #ifdef RELDIFF 10 | #define DIFFRATE 0.001 11 | #else 12 | #define TOLERANCE 1.0e-4 13 | #endif /* RELDIFF */ 14 | 15 | #ifdef DEBUG_CORE 16 | #define DEBUG_CORE_MASS 17 | #define DEBUG_CORE_MOMT 18 | #define DEBUG_CORE_JNQ 19 | /* #define DEBUG_CORE_JNZ */ 20 | #endif /* DEBUG_CORE */ 21 | 22 | #endif /* !DBG_OPT */ 23 | -------------------------------------------------------------------------------- /hotstart.f90: -------------------------------------------------------------------------------- 1 | 2 | !---------------------------------------------------------------------- 3 | SUBROUTINE HOT_START (LO,LA,START_TYPE,START_STEP) 4 | ! HOT START FUNCTION 5 | ! START_TYPE: 6 | ! = 0: SAVE RESUMING SNAPSHOTS 7 | ! = 1: LOAD RESUMING DATA FROM ONLY FIRST-LEVEL GRIDS (LAYER1) 8 | ! = 2: LOAD RESUMING DATA FROM ALL GRIDS 9 | !---------------------------------------------------------------------- 10 | USE LAYER_PARAMS 11 | TYPE (LAYER) :: LO 12 | TYPE (LAYER), DIMENSION(NUM_GRID) :: LA 13 | INTEGER :: START_TYPE,START_STEP,SWITCH 14 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 15 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 16 | 17 | CALL HOTSTART_DATA (LO,START_TYPE,START_STEP) 18 | IF (START_TYPE .NE. 1) THEN 19 | DO I = 1,NUM_GRID 20 | IF (LA(I)%LAYSWITCH .EQ. 0) CALL HOTSTART_DATA (LA(I), & 21 | START_TYPE,START_STEP) 22 | ENDDO 23 | ENDIF 24 | 25 | RETURN 26 | END 27 | 28 | 29 | !---------------------------------------------------------------------- 30 | SUBROUTINE HOTSTART_DATA (LO,START_TYPE,START_STEP) 31 | !---------------------------------------------------------------------- 32 | USE LAYER_PARAMS 33 | TYPE (LAYER) :: LO 34 | INTEGER :: START_TYPE,START_STEP,SWITCH 35 | INTEGER IOSTAT 36 | CHARACTER(LEN=20) FNAME1,FNAME2,FNAME3,FNAME4 37 | CHARACTER(LEN=20) FNAME5,FNAME6 38 | CHARACTER(LEN=20) FNAME10,FNAME11 39 | 40 | LAYID = LO%ID 41 | IF ( LAYID .EQ. 1) THEN 42 | IS = 1 43 | IE = LO%NX 44 | JS = 1 45 | JE = LO%NY 46 | ELSE 47 | IS = 2 48 | JS = 2 49 | IE = LO%NX 50 | JE = LO%NY 51 | ENDIF 52 | 53 | WRITE (FNAME1,4) LAYID,START_STEP 54 | 4 FORMAT('z1_',I2.2,'_',I6.6,'.dat') 55 | WRITE (FNAME2,5) LAYID,START_STEP 56 | 5 FORMAT('Z2_',I2.2,'_',I6.6,'.dat') 57 | WRITE (FNAME3,6) LAYID,START_STEP 58 | 6 FORMAT('m1_',I2.2,'_',I6.6,'.dat') 59 | WRITE (FNAME4,7) LAYID,START_STEP 60 | 7 FORMAT('m2_',I2.2,'_',I6.6,'.dat') 61 | WRITE (FNAME5,8) LAYID,START_STEP 62 | 8 FORMAT('n1_',I2.2,'_',I6.6,'.dat') 63 | WRITE (FNAME6,9) LAYID,START_STEP 64 | 9 FORMAT('n2_',I2.2,'_',I6.6,'.dat') 65 | WRITE (FNAME10,10) LAYID,START_STEP 66 | 10 FORMAT('zmax1_',I2.2,'_',I6.6,'.dat') 67 | WRITE (FNAME11,11) LAYID,START_STEP 68 | 11 FORMAT('zmin1_',I2.2,'_',I6.6,'.dat') 69 | ! ----- OUTPUT DATA FOR FUTURE HOT START ----------- 70 | !! OUTPUT WATER SURFACE DISPLACEMENT DATA Z 71 | IF (START_TYPE .EQ. 0) THEN 72 | OPEN (25,FILE=FNAME1,STATUS='UNKNOWN') 73 | DO J = JS,JE 74 | WRITE (25,'(10F12.5)') (LO%Z(I,J,1),I=IS,IE) 75 | ENDDO 76 | CLOSE (25) 77 | !! OUTPUT FLUX DATA IN X DIRECTION 78 | OPEN (25,FILE=FNAME3,STATUS='UNKNOWN') 79 | DO J = JS,JE 80 | WRITE (25,'(10F12.5)') (LO%M(I,J,1),I=IS,IE) 81 | ENDDO 82 | CLOSE (25) 83 | !! OUTPUT FLUX DATA IN Y DIRECTION 84 | OPEN (25,FILE=FNAME5,STATUS='UNKNOWN') 85 | DO J = JS,JE 86 | WRITE (25,'(10F12.5)') (LO%N(I,J,1),I=IS,IE) 87 | ENDDO 88 | CLOSE (25) 89 | !! OUTPUT MAXIMUM SURFACE ELEVATION DATA 90 | OPEN (25,FILE=FNAME10,STATUS='UNKNOWN') 91 | DO J = JS,JE 92 | WRITE (25,'(10F12.5)') (LO%Z_MAX(I,J),I=IS,IE) 93 | ENDDO 94 | CLOSE (25) 95 | !! OUTPUT MAXIMUM SURFACE DEPRESSION DATA 96 | OPEN (25,FILE=FNAME11,STATUS='UNKNOWN') 97 | DO J = JS,JE 98 | WRITE (25,'(10F12.5)') (LO%Z_MIN(I,J),I=IS,IE) 99 | ENDDO 100 | CLOSE (25) 101 | ELSE 102 | !------- LOAD DATA FOR HOT START ------------------------------------ 103 | !! LOAD WATER SURFACE DISPLACEMENT DATA FOR HOT START 104 | OPEN (UNIT=25,FILE=FNAME1,STATUS='OLD',IOSTAT=ISTAT, & 105 | FORM='FORMATTED') 106 | IF (ISTAT /= 0) THEN 107 | PRINT *,"WARNING:: HOTSTART CAN'T OPEN Z FILE; USE ZEROS INSTEAD." 108 | LO%Z(:,:,1) = 0.0 109 | ELSE 110 | DO J = JS,JE 111 | READ (25,'(10F12.5)') (LO%Z(I,J,1),I=IS,IE) 112 | ENDDO 113 | ENDIF 114 | CLOSE (25) 115 | !! LOAD VOLUME FLUX DATA IN X DIRECTION FOR HOT START 116 | OPEN (UNIT=25,FILE=FNAME3,STATUS='OLD',IOSTAT=ISTAT, & 117 | FORM='FORMATTED') 118 | IF (ISTAT /= 0) THEN 119 | PRINT *,"WARNING:: HOTSTART CAN'T OPEN P FILE; USE ZEROS INSTEAD." 120 | LO%M(:,:,1) = 0.0 121 | ELSE 122 | DO J = JS,JE 123 | READ (25,'(10F12.5)') (LO%M(I,J,1),I=IS,IE) 124 | ENDDO 125 | ENDIF 126 | CLOSE (25) 127 | !! LOAD VOLUME FLUX DATA IN Y DIRECTION FOR HOT START 128 | OPEN (UNIT=25,FILE=FNAME5,STATUS='OLD',IOSTAT=ISTAT, & 129 | FORM='FORMATTED') 130 | IF (ISTAT /= 0) THEN 131 | PRINT *,"WARNING:: HOTSTART CAN'T OPEN Q FILE; USE ZEROS INSTEAD." 132 | LO%N(:,:,1) = 0.0 133 | ELSE 134 | DO J = JS,JE 135 | READ (25,'(10F12.5)') (LO%N(I,J,1),I=IS,IE) 136 | ENDDO 137 | ENDIF 138 | CLOSE (25) 139 | !! LOAD MAXIMUM SURFACE ELEVATION DATA FOR HOT START 140 | OPEN (UNIT=25,FILE=FNAME10,STATUS='OLD',IOSTAT=ISTAT, & 141 | FORM='FORMATTED') 142 | IF (ISTAT /= 0) THEN 143 | PRINT *,"WARNING:: HOTSTART CAN'T OPEN ZMAX FILE; USE ZEROS INSTEAD." 144 | LO%Z_MAX(:,:) = 0.0 145 | ELSE 146 | DO J = JS,JE 147 | READ (25,'(10F12.5)') (LO%Z_MAX(I,J),I=IS,IE) 148 | ENDDO 149 | ENDIF 150 | CLOSE (25) 151 | !! LOAD MAXIMUM SURFACE DEPRESSION DATA FOR HOT START 152 | OPEN (UNIT=25,FILE=FNAME11,STATUS='OLD',IOSTAT=ISTAT, & 153 | FORM='FORMATTED') 154 | IF (ISTAT /= 0) THEN 155 | PRINT *,"WARNING:: HOTSTART CAN'T OPEN ZMIN FILE; USE ZEROS INSTEAD." 156 | LO%Z_MIN(:,:) = 0.0 157 | ELSE 158 | DO J = JS,JE 159 | READ (25,'(10F12.5)') (LO%Z_MIN(I,J),I=IS,IE) 160 | ENDDO 161 | ENDIF 162 | CLOSE (25) 163 | ENDIF 164 | 165 | RETURN 166 | END 167 | -------------------------------------------------------------------------------- /landslide.ctl: -------------------------------------------------------------------------------- 1 | ################################################# 2 | # # 3 | # Control file for COMCOT program (v1.7) # 4 | # For Land Slide Configuration # 5 | ################################################# 6 | #--+-----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 7 | #===============================================:=============================== 8 | # Parameters for Landslide Function: Watts et al (2003) | 9 | #===============================================:=============================== 10 | 11 | #===============================================:=============================== 12 | # Parameters for Land Slide Function :Values | 13 | #===============================================:=============================== 14 | Land Slide Starting Time (seconds) : 0.0 15 | Land Slide Ending Time (seconds) : 600.0 16 | X Coord of Starting Location (Center of Mass) : 178.50 17 | Y Coord of Starting Location (Center of Mass) : -40.50 18 | X Coord of Stopping Location (Center of Mass) : 178.00 19 | Y Coord of Stopping Location (Center of Mass) : -40.00 20 | Typical Slope Angle along sliding path (degree): 8.0 21 | Length of Sliding Volume (in meters along Path): 5000.0 22 | Width of Sliding Volume (in meters cross Path) : 10000.000 23 | Typical Thickness of Slide Volume (in meters) : 20.0 24 | -------------------------------------------------------------------------------- /landslide.f90: -------------------------------------------------------------------------------- 1 | 2 | !---------------------------------------------------------------------- 3 | SUBROUTINE LAND_SLIDE (LO,LANDSLIDE_INFO,T) 4 | !DESCRIPTION: 5 | ! #. CALCULATE TIME-VARIATION OF WATER DEPTH 6 | ! ********* USE LANDSLIDE MODEL ************** 7 | !NOTES: 8 | ! #. CREATED ON ??? ??, (XIAOMING WANG, CORNELL UNIVERSITY) 9 | ! #. UPDATED ON SEP17 2006 (XIAOMING WANG) 10 | ! #. UPDATED ON NOV.27 2008 (XIAOMING WANG, GNS) 11 | !---------------------------------------------------------------------- 12 | USE LAYER_PARAMS 13 | USE LANDSLIDE_PARAMS 14 | TYPE (LAYER) :: LO 15 | TYPE (LANDSLIDE) :: LANDSLIDE_INFO 16 | INTEGER :: NX, NY, NUM,IS,IE,JS,JE 17 | REAL HS1(LANDSLIDE_INFO%NX,LANDSLIDE_INFO%NY) 18 | REAL HS2(LANDSLIDE_INFO%NX,LANDSLIDE_INFO%NY) 19 | REAL UPLIFT(LANDSLIDE_INFO%NX,LANDSLIDE_INFO%NY) 20 | REAL TIME_SEQUENCE(LANDSLIDE_INFO%NT) 21 | REAL T 22 | CHARACTER(LEN=30) FNAME 23 | 24 | HS1 = 0.0 25 | HS2 = 0.0 26 | UPLIFT = 0.0 27 | TIME_SEQUENCE = 0.0 28 | 29 | IS = LANDSLIDE_INFO%CORNERS(1) 30 | IE = LANDSLIDE_INFO%CORNERS(2) 31 | JS = LANDSLIDE_INFO%CORNERS(3) 32 | JE = LANDSLIDE_INFO%CORNERS(4) 33 | 34 | IF (LANDSLIDE_INFO%OPTION .LE. 1) THEN 35 | TIME_SEQUENCE = LANDSLIDE_INFO%T 36 | 37 | ! DETERMINE THE POSITION OF CURRENT TIME IN THE TIME SEQUENCE 38 | K = 1 39 | DO I=1,LANDSLIDE_INFO%NT-1 40 | IF (T.GE.TIME_SEQUENCE(I) .AND. & 41 | T.LT.TIME_SEQUENCE(I+1)) THEN 42 | K = I 43 | ENDIF 44 | ENDDO 45 | 46 | IF (TIME_SEQUENCE(LANDSLIDE_INFO%NT)-T .LE. 0.000001) & 47 | K = LANDSLIDE_INFO%NT-1 48 | 49 | DT = TIME_SEQUENCE(K+1) - TIME_SEQUENCE(K) 50 | HS1(:,:) = LANDSLIDE_INFO%SNAPSHOT(:,:,K) 51 | HS2(:,:) = LANDSLIDE_INFO%SNAPSHOT(:,:,K+1) 52 | !.....DEFORMATION AT T IS INTERPOLATED FROM HS1 AND HS2 53 | DO I=1,LANDSLIDE_INFO%NX 54 | DO J=1,LANDSLIDE_INFO%NY 55 | UPLIFT(I,J) = HS1(I,J)+(HS2(I,J)-HS1(I,J))/DT & 56 | *(T-TIME_SEQUENCE(K)) 57 | ENDDO 58 | ENDDO 59 | 60 | LO%HT(IS:IE,JS:JE,2) = LO%H(IS:IE,JS:JE) - UPLIFT(:,:) 61 | ! LO%H2(IS:IE,JS:JE) = UPLIFT(:,:) 62 | ELSEIF (LANDSLIDE_INFO%OPTION .EQ. 2) THEN 63 | CALL LANDSLIDE_FUNCTION (LO,LANDSLIDE_INFO,T) 64 | LO%HT(IS:IE,JS:JE,2) = LO%H(IS:IE,JS:JE) & 65 | - LANDSLIDE_INFO%SNAPSHOT(:,:,3) 66 | ENDIF 67 | 68 | 69 | RETURN 70 | END 71 | 72 | 73 | !---------------------------------------------------------------------- 74 | SUBROUTINE READ_LANDSLIDE (LO,LANDSLIDE_INFO) 75 | !.....READ SNAPSHOTS OF LANDSLIDE DATA 76 | ! ONLY USED WHEN WAVE TYPE OPTION IS 2. 77 | !.....LAST REVISE: NOV.24 2008 (XIAOMING WANG) 78 | !---------------------------------------------------------------------- 79 | USE LAYER_PARAMS 80 | USE LANDSLIDE_PARAMS 81 | TYPE (LANDSLIDE) :: LANDSLIDE_INFO 82 | TYPE (LAYER) :: LO 83 | REAL, ALLOCATABLE:: SNAPSHOT(:,:,:),X(:),Y(:),T(:) 84 | INTEGER COUNT,NX,NY,NT 85 | INTEGER :: RSTAT 86 | REAL LATIN,LONIN,XS,YS,XE,YE,XT,YT,X0,Y0 87 | CHARACTER(LEN=80) FNAME 88 | RSTAT = 0 89 | DO K = 1,LO%NX-1 90 | IF (LANDSLIDE_INFO%X_START.GT.LO%X(K) .AND. & 91 | LANDSLIDE_INFO%X_START.LE.LO%X(K+1)) THEN 92 | LANDSLIDE_INFO%CORNERS(1) = K+1 93 | ENDIF 94 | IF (LANDSLIDE_INFO%X_END.GE.LO%X(K) .AND. & 95 | LANDSLIDE_INFO%X_END.LT.LO%X(K+1)) THEN 96 | LANDSLIDE_INFO%CORNERS(2) = K 97 | ENDIF 98 | ENDDO 99 | 100 | DO K = 1,LO%NY-1 101 | IF (LANDSLIDE_INFO%Y_START.GT.LO%Y(K) .AND. & 102 | LANDSLIDE_INFO%Y_START.LE.LO%Y(K+1)) THEN 103 | LANDSLIDE_INFO%CORNERS(3) = K+1 104 | ENDIF 105 | IF (LANDSLIDE_INFO%Y_END.GE.LO%Y(K) .AND. & 106 | LANDSLIDE_INFO%Y_END.LT.LO%Y(K+1)) THEN 107 | LANDSLIDE_INFO%CORNERS(4) = K 108 | ENDIF 109 | ENDDO 110 | !.....CALCULATE DIMENSION OF LANDSLIDE REGION 111 | LANDSLIDE_INFO%NX = LANDSLIDE_INFO%CORNERS(2) & 112 | - LANDSLIDE_INFO%CORNERS(1) + 1 113 | LANDSLIDE_INFO%NY = LANDSLIDE_INFO%CORNERS(4) & 114 | - LANDSLIDE_INFO%CORNERS(3) + 1 115 | 116 | !USE THE OLD COMCOT DATA FORMAT: NOT SUGGESTED 117 | IF (LANDSLIDE_INFO%OPTION .EQ. 0) THEN 118 | 119 | OPEN(UNIT=20,FILE='bottom_motion_time.dat',STATUS='OLD', & 120 | IOSTAT=ISTAT) 121 | IF (ISTAT /=0) THEN 122 | PRINT *,"ERROR:: CAN'T OPEN BOTTOM_MOTION_TIME.DAT; EXITING." 123 | STOP 124 | ENDIF 125 | COUNT = -1 126 | DO WHILE (RSTAT == 0) 127 | COUNT = COUNT + 1 128 | READ (20,*,IOSTAT=RSTAT) TEMP 129 | END DO 130 | LANDSLIDE_INFO%NT = COUNT 131 | ! CLOSE(20) 132 | ALLOCATE(LANDSLIDE_INFO%T(COUNT)) 133 | ALLOCATE(LANDSLIDE_INFO%SNAPSHOT(LANDSLIDE_INFO%NX, & 134 | LANDSLIDE_INFO%NY,COUNT)) 135 | ALLOCATE(SNAPSHOT(LANDSLIDE_INFO%NX,LANDSLIDE_INFO%NY, & 136 | COUNT)) 137 | LANDSLIDE_INFO%T = 0.0 138 | LANDSLIDE_INFO%SNAPSHOT = 0.0 139 | SNAPSHOT = 0.0 140 | ! !OBTAIN TIME SEQUENCE 141 | REWIND(20) 142 | ! OPEN(UNIT=20,FILE='bottom_motion_time.dat',STATUS='OLD', & 143 | ! IOSTAT=ISTAT) 144 | DO I=1,LANDSLIDE_INFO%NT 145 | READ (20,*) LANDSLIDE_INFO%T(I) 146 | ENDDO 147 | CLOSE(20) 148 | LANDSLIDE_INFO%DURATION = & 149 | LANDSLIDE_INFO%T(LANDSLIDE_INFO%NT) & 150 | - LANDSLIDE_INFO%T(1) 151 | 152 | !..... READ SEAFLOOR DEFORMATION DATA FROM SEQUENTIAL SNAPSHOTS 153 | DO K = 1,COUNT 154 | WRITE (FNAME,1) K 155 | 1 FORMAT('bottom_motion_',I6.6,'.dat') 156 | OPEN (25,FILE=FNAME,STATUS='OLD',IOSTAT=ISTAT) 157 | IF (ISTAT /=0) THEN 158 | PRINT *,"ERROR:: CAN'T OPEN LANDSLIDE FILE; EXITING." 159 | STOP 160 | ENDIF 161 | DO J = 1,LANDSLIDE_INFO%NY 162 | DO I = 1,LANDSLIDE_INFO%NX 163 | READ (25,*) SNAPSHOT(I,J,K) 164 | ENDDO 165 | ENDDO 166 | !* WRITE (*,*) FNAME 167 | CLOSE (25) 168 | LANDSLIDE_INFO%SNAPSHOT = SNAPSHOT 169 | ENDDO 170 | ENDIF 171 | !LANDSLIDE SNAPSHOTS ADOPT XYT DATA FORMAT 172 | IF (LANDSLIDE_INFO%OPTION .EQ. 1) THEN 173 | OPEN(UNIT=20,FILE=LANDSLIDE_INFO%FILENAME,STATUS='OLD', & 174 | IOSTAT=ISTAT) 175 | IF (ISTAT /=0) THEN 176 | PRINT *,"ERROR:: CAN'T OPEN LANDSLIDE FILE; EXITING." 177 | STOP 178 | ENDIF 179 | READ (20,*) NX,NY,NT 180 | 181 | ALLOCATE(X(NX)) 182 | ALLOCATE(Y(NY)) 183 | ALLOCATE(T(NT)) 184 | ALLOCATE(SNAPSHOT(NX,NY,NT)) 185 | X = 0.0 186 | Y = 0.0 187 | T = 0.0 188 | SNAPSHOT = 0.0 189 | 190 | DO I = 1,NX 191 | READ(20,*) X(I) 192 | ENDDO 193 | DO J = 1,NY 194 | READ(20,*) Y(J) 195 | ENDDO 196 | DO K = 1,NT 197 | READ(20,*) T(K) 198 | ENDDO 199 | DO K = 1,NT 200 | DO J = 1,NY 201 | DO I = 1,NX 202 | READ(20,*) SNAPSHOT(I,J,K) 203 | ENDDO 204 | ENDDO 205 | ENDDO 206 | CLOSE(20) 207 | 208 | ALLOCATE(LANDSLIDE_INFO%T(NT)) 209 | LANDSLIDE_INFO%T = 0.0 210 | 211 | LANDSLIDE_INFO%NT = NT 212 | LANDSLIDE_INFO%T = T 213 | LANDSLIDE_INFO%DURATION = T(NT)-T(1) 214 | 215 | IS = LANDSLIDE_INFO%CORNERS(1) 216 | IE = LANDSLIDE_INFO%CORNERS(2) 217 | JS = LANDSLIDE_INFO%CORNERS(3) 218 | JE = LANDSLIDE_INFO%CORNERS(4) 219 | 220 | ALLOCATE(LANDSLIDE_INFO%SNAPSHOT(LANDSLIDE_INFO%NX, & 221 | LANDSLIDE_INFO%NY,NT)) 222 | LANDSLIDE_INFO%SNAPSHOT = 0.0 223 | 224 | DO K = 1,NT 225 | CALL GRID_INTERP (LANDSLIDE_INFO%SNAPSHOT(:,:,K), & 226 | LO%X(IS:IE),LO%Y(JS:JE), & 227 | LANDSLIDE_INFO%NX,LANDSLIDE_INFO%NY, & 228 | SNAPSHOT(:,:,K),X,Y,NX,NY) 229 | !* LANDSLIDE_INFO%SNAPSHOT(:,:,K) = & 230 | !* - LANDSLIDE_INFO%SNAPSHOT(:,:,K) + LO%H(IS:IE,JS:JE) 231 | ENDDO 232 | ENDIF 233 | ! WRITE(*,*) NX,NT,NT 234 | ! WRITE(*,*) X(1),Y(1),T(1),SNAPSHOT(1,1,NT),SNAPSHOT(1,NY,NT), & 235 | ! SNAPSHOT(NX,1,NT),SNAPSHOT(NX,NY,NT) 236 | ! WRITE(*,*) LANDSLIDE_INFO%SNAPSHOT(1,LANDSLIDE_INFO%NY,NT) 237 | 238 | !USE PROFILE FUNCTION TO GENEATE SNAPSHOTS OF LANDSLIDE PROFILE 239 | !NOTE: LANDSLIDE_INFO%SNAPSHOT IS USED TO STORE COORDINATES 240 | IF (LANDSLIDE_INFO%OPTION .EQ. 2) THEN 241 | CALL GET_LANDSLIDE_PARAMETERS (LO,LANDSLIDE_INFO) 242 | NX = LANDSLIDE_INFO%NX 243 | NY = LANDSLIDE_INFO%NY 244 | NT = LANDSLIDE_INFO%NT 245 | XS = LANDSLIDE_INFO%XS 246 | YS = LANDSLIDE_INFO%YS 247 | XE = LANDSLIDE_INFO%XE 248 | YE = LANDSLIDE_INFO%YE 249 | 250 | ALLOCATE(SNAPSHOT(NX,NY,2)) 251 | ALLOCATE(LANDSLIDE_INFO%SNAPSHOT(NX,NY,3)) 252 | SNAPSHOT = 0.0 253 | LANDSLIDE_INFO%SNAPSHOT = 0.0 254 | 255 | !COORDINATE CONVERSION (IF SPHERICAL COORD. IS ADOPTED)AND ROTATION 256 | IS = LANDSLIDE_INFO%CORNERS(1) 257 | IE = LANDSLIDE_INFO%CORNERS(2) 258 | JS = LANDSLIDE_INFO%CORNERS(3) 259 | JE = LANDSLIDE_INFO%CORNERS(4) 260 | IF (LO%LAYCORD .EQ. 1) THEN 261 | X0 = LANDSLIDE_INFO%XS 262 | Y0 = LANDSLIDE_INFO%YS 263 | !ROTATE COORDINATES TO ALIGN WITH SLIDING PATH 264 | LANDSLIDE_INFO%DISTANCE = SQRT((XE-XS)**2+(YE-YS)**2) 265 | SN = (YE-YS)/LANDSLIDE_INFO%DISTANCE 266 | CS = (XE-XS)/LANDSLIDE_INFO%DISTANCE 267 | DO I = 1,NX 268 | DO J = 1,NY 269 | XT = LO%X(I+IS-1) - X0 270 | YT = LO%Y(J+JS-1) - Y0 271 | XR = XT*CS + YT*SN 272 | YR = -XT*SN + YT*CS 273 | LANDSLIDE_INFO%SNAPSHOT(I,J,1) = XR 274 | LANDSLIDE_INFO%SNAPSHOT(I,J,2) = YR 275 | LANDSLIDE_INFO%SNAPSHOT(I,J,3) = 0.0 276 | ENDDO 277 | ENDDO 278 | !* CALL LANDSLIDE_FUNCTION (LO,LANDSLIDE_INFO,0.0) 279 | ELSEIF (LO%LAYCORD .EQ. 0) THEN 280 | X0 = LANDSLIDE_INFO%XS 281 | Y0 = LANDSLIDE_INFO%YS 282 | LONIN = LANDSLIDE_INFO%XS 283 | LATIN = LANDSLIDE_INFO%YS 284 | !CONVERTING SPHERICAL COORDINATES TO CARTESIAN COORDINATES 285 | CALL STEREO_PROJECTION (XS,YS,LONIN,LATIN,X0,Y0) 286 | LONIN = LANDSLIDE_INFO%XE 287 | LATIN = LANDSLIDE_INFO%YE 288 | !CONVERTING SPHERICAL COORDINATES TO CARTESIAN COORDINATES 289 | CALL STEREO_PROJECTION (XE,YE,LONIN,LATIN,X0,Y0) 290 | LANDSLIDE_INFO%DISTANCE = SQRT((XE-XS)**2+(YE-YS)**2) 291 | SN = (YE-YS)/LANDSLIDE_INFO%DISTANCE 292 | CS = (XE-XS)/LANDSLIDE_INFO%DISTANCE 293 | DO I = 1,NX 294 | DO J = 1,NY 295 | LONIN = LO%X(I+IS-1) 296 | LATIN = LO%Y(J+JS-1) 297 | !CONVERTING SPHERICAL COORDINATES TO CARTESIAN COORDINATES 298 | CALL STEREO_PROJECTION (XT,YT,LONIN,LATIN,X0,Y0) 299 | !ROTATING COORDINATES TO ALIGN WITH SLIDING PATH 300 | XR = XT*CS + YT*SN 301 | YR = -XT*SN + YT*CS 302 | LANDSLIDE_INFO%SNAPSHOT(I,J,1) = XR 303 | LANDSLIDE_INFO%SNAPSHOT(I,J,2) = YR 304 | LANDSLIDE_INFO%SNAPSHOT(I,J,3) = 0.0 305 | ENDDO 306 | ENDDO 307 | !* CALL LANDSLIDE_FUNCTION (LO,LANDSLIDE_INFO,T) 308 | ENDIF 309 | ENDIF 310 | 311 | DEALLOCATE(SNAPSHOT,X,Y,T,STAT=ISTAT) 312 | 313 | RETURN 314 | END 315 | 316 | !---------------------------------------------------------------------- 317 | SUBROUTINE LANDSLIDE_FUNCTION (LO,LS,TIME) 318 | !DESCRIPTION: 319 | ! #. GENERATE LANDSLIDE FROM FUNCTION; 320 | ! #. WATER DEPTH VARIATION IS DETERMINED FROM WATTS ET AL (2003); 321 | !REFERENCE: 322 | ! #. WATTS ET AL (2003), NATURAL HAZARDS AND EARTH SYSTEM SCIENCES, 323 | ! (2003) 3:391-402 324 | !NOTES: 325 | ! #. CREATED ON FEB06 2009 (XIAOMING WANG, GNS) 326 | ! #. UPDATED ON ?? 327 | !---------------------------------------------------------------------- 328 | USE LAYER_PARAMS 329 | USE LANDSLIDE_PARAMS 330 | TYPE (LAYER) :: LO 331 | TYPE (LANDSLIDE) :: LS 332 | INTEGER :: NX, NY, IS,IE,JS,JE 333 | REAL TIME,T,T0,S0,A0,UT,B,SN 334 | REAL X,Y,Z,C,ZE,ZD 335 | REAL D,D_LIMIT 336 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 337 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 338 | 339 | UPLIFT = 0.0 340 | 341 | THETA = LS%SLOPE*RAD_DEG 342 | SN = SIN(THETA) 343 | A = LS%A 344 | B = LS%B 345 | C = LS%THICKNESS 346 | 347 | T = TIME - LS%T(1) 348 | IF (T .LE. 0.0) T = 0.0 349 | A0 = 0.30*GRAV*SN 350 | UT = 1.16*SQRT(A*GRAV*SN) 351 | S0 = UT**2/A0 352 | T0 = UT/A0 353 | S = S0*LOG(COSH(T/T0)) 354 | 355 | D = S*COS(THETA) 356 | D_LIMIT = LS%DISTANCE 357 | 358 | IF (T.GE.LS%T(1) .AND. T.LE.LS%T(LS%NT) & 359 | .AND. D.LE.D_LIMIT) THEN 360 | DO I = 1,LS%NX 361 | DO J = 1,LS%NY 362 | X = LS%SNAPSHOT(I,J,1) 363 | Y = LS%SNAPSHOT(I,J,2) 364 | CALL SLIDEPROFILE_ELLIPSOID (ZE,X-S,Y,A,B,C) 365 | CALL SLIDEPROFILE_ELLIPSOID (ZD,X,Y,A,B,C) 366 | LS%SNAPSHOT(I,J,3) = ZE - ZD 367 | ENDDO 368 | ENDDO 369 | ENDIF 370 | 371 | RETURN 372 | END 373 | 374 | !---------------------------------------------------------------------- 375 | SUBROUTINE SLIDEPROFILE_ELLIPSOID (Z,X,Y,A,B,C) 376 | !DESCRIPTION: 377 | ! #. SLIDE PROFILE: ELLIPOID; 378 | !NOTES: 379 | ! #. CREATED ON FEB13 2009 (XIAOMING WANG, GNS) 380 | ! #. UPDATED ON ?? 381 | !---------------------------------------------------------------------- 382 | REAL X,Y,Z,A,B,C 383 | 384 | TMP = 1.0-(X/A)**2-(Y/B)**2 385 | IF (TMP .GE. 0.0) THEN 386 | Z = C*SQRT(TMP) 387 | ELSE 388 | Z = 0.0 389 | ENDIF 390 | 391 | 392 | RETURN 393 | END 394 | -------------------------------------------------------------------------------- /mass.f90: -------------------------------------------------------------------------------- 1 | #include "debug_option.h" 2 | !---------------------------------------------------------------------- 3 | SUBROUTINE MASS (LO) 4 | ! ....SOLVE CONTINUITY EQUATION 5 | ! OPTION: 6 | ! 0 - LINEAR SWE WITHOUT DISPERSION ADJUSTMENT 7 | ! 1 - NONLINEAR SWE WITHOUT DISPERSION ADJUSTMENT 8 | ! 2 - LINEAR SWE WITH DISPERSION ADJUSTMENT 9 | ! 3 - NONLINEAR SWE WITH DISPERSION ADJUSTMENT 10 | !---------------------------------------------------------------------- 11 | USE LAYER_PARAMS 12 | TYPE (LAYER) :: LO 13 | 14 | #ifdef DEBUG_CORE 15 | CALL SET_ALL(LO) 16 | #endif 17 | 18 | !.....FOR SPHERICAL COORDINATES 19 | IF (LO%LAYCORD .EQ. 0) THEN 20 | SELECT CASE (LO%LAYGOV) 21 | CASE (0) 22 | CALL MASS_S (LO) 23 | CASE (1) 24 | CALL CONMASS_S (LO) 25 | CASE (2) 26 | CALL MASS_S_D (LO) 27 | CASE (3) 28 | CALL MASS_S_D (LO) 29 | CASE (9) 30 | CALL CONMASS_S (LO) 31 | CASE DEFAULT 32 | CALL MASS_S (LO) 33 | END SELECT 34 | !.....FOR CARTESIAN COORDINATES 35 | ELSE 36 | SELECT CASE (LO%LAYGOV) 37 | CASE (0) 38 | CALL MASS_C (LO) 39 | CASE (1) 40 | CALL CONMASS (LO) 41 | CASE (2) 42 | CALL MASS_C_D (LO) 43 | CASE (3) 44 | CALL MASS_C_D (LO) 45 | CASE (5) 46 | CALL CONMASS (LO) 47 | CASE (9) 48 | CALL CONMASS (LO) 49 | CASE DEFAULT 50 | CALL MASS_C (LO) 51 | END SELECT 52 | ENDIF 53 | 54 | #ifdef DEBUG_CORE 55 | CALL MASS_LAUNCH(LO%Z(:,:,1),LO%Z(:,:,2),LO%H(:,:), LO%ID) 56 | #endif 57 | RETURN 58 | END 59 | 60 | !---------------------------------------------------------------------- 61 | SUBROUTINE MASS_S (L) 62 | ! ....SOLVE CONTINUITY EQUATION UNDER SPHERICAL COORD. 63 | !---------------------------------------------------------------------- 64 | USE LAYER_PARAMS 65 | TYPE (LAYER) :: L 66 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 67 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 68 | DATA UB/99.0/ 69 | ! 70 | IS = 2 71 | JS = 2 72 | IF (L%ID .EQ. 1) THEN 73 | IE = L%NX-1 !FOR OUTEST LAYER 74 | JE = L%NY-1 75 | ELSE 76 | IE = L%NX !FOR INNER LAYER 77 | JE = L%NY 78 | END IF 79 | DO J=JS,JE 80 | JM1 = J-1 81 | DO I=IS,IE 82 | IF (L%H(I,J) .GT. GX) THEN 83 | ZZ = L%Z(I,J,1)-L%R1(I,J)*(L%M(I,J,1)-L%M(I-1,J,1)) & 84 | -L%R11(I,J)*(L%N(I,J,1)*L%R6(J) & 85 | -L%N(I,JM1,1)*L%R6(JM1)) 86 | IF (L%INI_SWITCH.EQ.3 .OR. L%INI_SWITCH.EQ.4) & 87 | ZZ = ZZ-(L%HT(I,J,2)-L%HT(I,J,1)) 88 | IF (ABS(ZZ) .LT. EPS) ZZ = ZERO 89 | !* IF (ABS(ZZ) .GT. UB) ZZ=SIGN(UB,ZZ) 90 | !DEPRESSION CANNOT BE LESS THAN BOTTOM ELEVATION 91 | IF ( (ZZ+L%H(I,J)) .LE. EPS ) ZZ = -L%H(I,J) 92 | L%Z(I,J,2) = ZZ 93 | ELSE 94 | L%Z(I,J,2) = 0.0 95 | ENDIF 96 | END DO 97 | END DO 98 | 99 | RETURN 100 | END 101 | 102 | !---------------------------------------------------------------------- 103 | SUBROUTINE MASS_C (L) 104 | ! ....SOLVE CONTINUITY EQUATION (LINEAR) IN CARTESIAN COORD. 105 | ! LAYID = 1, OUTEST LAYER 106 | ! OTHERWISE, INNER LAYER 107 | ! 108 | ! NOTES: ADD SUPPORT FOR DX\=DY (FOR HIGH-LATITUDE, 05/04/2007) 109 | ! RX = L%R 110 | ! RY = L%DT/L%DY 111 | !---------------------------------------------------------------------- 112 | USE LAYER_PARAMS 113 | TYPE (LAYER) :: L 114 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 115 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 116 | DATA UB/99.0/ 117 | 118 | RX = L%RX 119 | RY = L%RY 120 | ! 121 | IS = 2 122 | JS = 2 123 | IF (L%ID .EQ. 1) THEN !OUTTEST LAYER 124 | IE = L%NX -1 125 | JE = L%NY -1 126 | ELSE ! INNER LAYER 127 | IE = L%NX 128 | JE = L%NY 129 | ENDIF 130 | 131 | IF (L%DIM.EQ.1) THEN 132 | L%N(:,:,:) = 0.0 133 | JS = NINT(L%NY/2.0) 134 | JE = NINT(L%NY/2.0) 135 | ENDIF 136 | 137 | DO J=JS,JE 138 | DO I=IS,IE 139 | IF (L%H(I,J) .GT. GX) THEN 140 | ZZ = L%Z(I,J,1) - RX*(L%M(I,J,1)-L%M(I-1,J,1)) & 141 | - RY*(L%N(I,J,1)-L%N(I,J-1,1)) 142 | IF (L%INI_SWITCH.EQ.3 .OR. L%INI_SWITCH.EQ.4) & 143 | ZZ = ZZ-(L%HT(I,J,2)-L%HT(I,J,1)) 144 | IF (ABS(ZZ) .LT. EPS) ZZ = ZERO 145 | !DEPRESSION CANNOT BE LESS THAN BOTTOM ELEVATION 146 | !* IF (ABS(ZZ) .GT. UB) ZZ=SIGN(UB,ZZ) 147 | IF ( (ZZ+L%H(I,J)) .LE. EPS ) ZZ = -L%H(I,J) 148 | L%Z(I,J,2) = ZZ 149 | ELSE 150 | L%Z(I,J,2) = 0.0 151 | ENDIF 152 | IF (L%DIM.EQ.1) L%Z(I,:,2) = L%Z(I,J,2) 153 | END DO 154 | END DO 155 | 156 | RETURN 157 | END 158 | 159 | 160 | 161 | !---------------------------------------------------------------------- 162 | SUBROUTINE CONMASS (L) 163 | !.....SOVLE CONTINUITY EQUATION (NONLINEAR) IN CARTESIAN COORD. 164 | ! LAYID = 1, OUTEST LAYER 165 | ! OTHERWISE, INNER LAYER 166 | !.....DD TOTAL WATER DEPTH 167 | !---------------------------------------------------------------------- 168 | USE LAYER_PARAMS 169 | ! USE DFLIB 170 | TYPE (LAYER) :: L 171 | REAL FM 172 | ! INTEGER ERR, ERR_TABLE(L%NX,L%NY) 173 | ! INTEGER(2) STATUS 174 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 175 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 176 | 177 | RX = L%RX 178 | RY = L%RY 179 | 180 | IF ( L%ID .EQ. 1 ) THEN !OUTTEST LAYER !20 181 | IS = 2 182 | JS = 2 183 | IE = L%NX -1 184 | JE = L%NY -1 185 | ELSE 186 | IS = 2 187 | JS = 2 188 | IE = L%NX 189 | JE = L%NY 190 | ENDIF 191 | 192 | IF (L%DIM .EQ. 1) THEN 193 | L%N(:,:,:) = 0.0 194 | JS = NINT(L%NY/2.0) 195 | JE = NINT(L%NY/2.0) 196 | ENDIF 197 | 198 | !* L%DZ = 0.0 199 | DO J = JS, JE 200 | DO I = IS, IE 201 | IF (L%H(I,J) .GT. ELMAX) THEN 202 | ZZZ = L%Z(I,J,1) - RX*(L%M(I,J,1)-L%M(I-1,J,1)) & 203 | - RY*(L%N(I,J,1)-L%N(I,J-1,1)) 204 | IF (L%INI_SWITCH.EQ.3 .OR. L%INI_SWITCH.EQ.4) & 205 | ZZZ = ZZZ-(L%HT(I,J,2)-L%HT(I,J,1)) 206 | IF (ABS(ZZZ) .LT. EPS) ZZZ = 0.0 207 | DD = ZZZ + L%H(I,J) 208 | IF (DD .GE. GX) THEN 209 | L%DZ(I,J,2) = DD 210 | L%Z(I,J,2) = ZZZ 211 | ELSE 212 | L%DZ(I,J,2) = 0.0 213 | L%Z(I,J,2) = -L%H(I,J) 214 | ENDIF 215 | ELSE 216 | L%DZ(I,J,2) = 0.0 217 | L%Z(I,J,2) = -L%H(I,J) 218 | ENDIF 219 | IF (L%DIM.EQ.1) L%Z(I,:,2) = L%Z(I,JS,2) 220 | ENDDO 221 | ENDDO 222 | 223 | RETURN 224 | END 225 | 226 | !---------------------------------------------------------------------- 227 | SUBROUTINE CONMASS_S (L) 228 | !.....SOVLE CONTINUITY EQUATION (NONLINEAR) IN SPHERICAL COORD. 229 | ! LAYID = 1, OUTEST LAYER 230 | ! OTHERWISE, INNER LAYER 231 | !.....DD TOTAL WATER DEPTH 232 | !---------------------------------------------------------------------- 233 | USE LAYER_PARAMS 234 | ! USE DFLIB 235 | TYPE (LAYER) :: L 236 | REAL FM 237 | ! INTEGER ERR, ERR_TABLE(L%NX,L%NY) 238 | ! INTEGER(2) STATUS 239 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 240 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 241 | 242 | IS = 2 243 | JS = 2 244 | IF (L%ID .EQ. 1) THEN 245 | IE = L%NX-1 !FOR OUTEST LAYER 246 | JE = L%NY-1 247 | ELSE 248 | IE = L%NX !FOR INNER LAYER 249 | JE = L%NY 250 | END IF 251 | DO J=JS,JE 252 | JM1 = J-1 253 | DO I=IS,IE 254 | IF (L%H(I,J) .GE. ELMAX) THEN 255 | ZZ = L%Z(I,J,1)-L%R1(I,J)*(L%M(I,J,1)-L%M(I-1,J,1)) & 256 | - L%R11(I,J)*(L%N(I,J,1)*L%R6(J)-L%N(I,JM1,1) & 257 | * L%R6(JM1)) 258 | IF (L%INI_SWITCH.EQ.3 .OR. L%INI_SWITCH.EQ.4) & 259 | ZZ = ZZ-(L%HT(I,J,2)-L%HT(I,J,1)) 260 | IF (ABS(ZZ) .LT. EPS) ZZ = ZERO 261 | DD = ZZ + L%H(I,J) 262 | IF (DD .GE. GX) THEN 263 | L%DZ(I,J,2) = DD 264 | L%Z(I,J,2) = ZZ 265 | ELSE 266 | L%DZ(I,J,2) = 0.0 267 | L%Z(I,J,2) = - L%H(I,J) 268 | ENDIF 269 | ELSE 270 | L%DZ(I,J,2) = 0.0 271 | L%Z(I,J,2) = - L%H(I,J) 272 | ENDIF 273 | END DO 274 | END DO 275 | 276 | RETURN 277 | END 278 | 279 | -------------------------------------------------------------------------------- /plot_dat.py: -------------------------------------------------------------------------------- 1 | from mpl_toolkits.basemap import Basemap 2 | from sys import argv 3 | from time import sleep 4 | import matplotlib.pyplot as plt 5 | import matplotlib as mpl 6 | import numpy as npy 7 | import struct 8 | from os import listdir 9 | class COMCOTdat(object): 10 | """COMCOTdat 11 | Import comcot data from .dat files 12 | 13 | """ 14 | def __init__(self, BASE_DIR, Layer=1,busywaitmode=False): 15 | super(COMCOTdat, self).__init__() 16 | self._layer = Layer 17 | if BASE_DIR[-1] != '/': 18 | BASE_DIR+='/' 19 | self._basedir = BASE_DIR 20 | # check files 21 | mapfiles = ["layer%02d_x.dat" % Layer, 22 | "layer%02d_y.dat" % Layer, 23 | "layer%02d.dat" % Layer] 24 | while busywaitmode: 25 | lsfiles = listdir(BASE_DIR) 26 | nrfile = 0 27 | for tmpfname in mapfiles: 28 | if tmpfname in lsfiles: 29 | nrfile += 1 30 | if nrfile == 3: 31 | break 32 | elif nrfile == 0: 33 | sleep(3) 34 | sleep(3) #BUG temporary solution to race condition on file being wrtten by comcot and read by python at the same time 35 | #FUTURE 36 | # import data 37 | self._x = self.ReadFile(BASE_DIR+ "layer%02d_x.dat" % Layer) 38 | self._y = self.ReadFile(BASE_DIR+ "layer%02d_y.dat" % Layer) 39 | self._dim = [len(self._y), len(self._x)] 40 | self._z = self.ReadFile(BASE_DIR+ "layer%02d.dat" % Layer, dim = True) 41 | #self._zmax = self.ReadFile(BASE_DIR+ "zmax_layer%02d.dat" % Layer, dim = True) 42 | self._etaname = [i for i in listdir(BASE_DIR) if i[:4]=='z_%02d' % Layer] 43 | self._etaname.sort() 44 | self._eta = {} 45 | for timestrig in self._etaname: 46 | self.Read_eta(timestrig) 47 | # self._arri = self.ReadFile(BASE_DIR+ "arrival_layer%02d.dat" % Layer,dim = True) 48 | 49 | [self._xx, self._yy] = npy.meshgrid(self._x,self._y) 50 | 51 | 52 | def Read_eta(self, filename): 53 | minute = int(filename[5:-4]) 54 | masked = npy.ma.masked_where(self._z < 0, self.ReadFile(filename, dim=True, binary=True)) 55 | self._eta.update({minute:masked}) 56 | 57 | def ReadFile(self,filename,dim=False , binary=False): 58 | print("Reading File %s" % filename) 59 | try: # read from file 60 | if binary: 61 | with open(filename,'rb') as FILE: 62 | size = self.dim[0]*self.dim[1] 63 | data = struct.unpack('f'*size, FILE.read(4*size)) 64 | if dim: 65 | return npy.reshape(data,self.dim) 66 | else: 67 | return data 68 | else: 69 | with open(filename,'r') as FILE: 70 | text = FILE.read() 71 | #parse to list 72 | data = [float(value) for value in text.split()] 73 | if dim: 74 | return npy.reshape(data,self.dim) 75 | else: 76 | return data 77 | except FileNotFoundError as e: 78 | print("Error, File < %s > Not Found" % e.filename) 79 | raise 80 | 81 | def Update_eta(self): 82 | tmpfilename = [i for i in listdir(self._basedir) if i[:4]=='z_%02d' % self._layer] 83 | for tmp in tmpfilename: 84 | if tmp not in self._etaname: 85 | self.Read_eta(tmp) 86 | self._etaname.append(tmp) 87 | 88 | @property 89 | def dim(self): 90 | return self._dim 91 | @property 92 | def XGRID(self): 93 | return self._xx 94 | @property 95 | def YGRID(self): 96 | return self._yy 97 | 98 | @property 99 | def ZMAX(self): 100 | return self._zmax 101 | @property 102 | def ARRIVAL(self): 103 | return self._arri 104 | @property 105 | def ETA(self): 106 | return self._eta 107 | 108 | class COMCOTGlobalmap(COMCOTdat): 109 | def __init__(self, BASE_DIR, Layer=1, timestep=2, busywaitmode=True): 110 | super(COMCOTGlobalmap, self).__init__(BASE_DIR, Layer=1, busywaitmode=busywaitmode) 111 | self._cmax = 0.5#npy.max(self.ETA[0])/2 112 | self._step2timecoef = 1.0/(60.0/timestep) 113 | done = [] 114 | if busywaitmode: 115 | while True: 116 | self.Update_eta() 117 | num = 0 118 | for step in self.ETA: 119 | if step not in done: 120 | self.save_eta(step) 121 | done.append(step) 122 | num+=1 123 | if num == 0: 124 | print("No new eta files (z_[layer]_[step].dat) found, sleep") 125 | sleep(3) 126 | else: 127 | for step in self.ETA: 128 | self.save_eta(step) 129 | done.append(step) 130 | 131 | def save_eta(self, step): 132 | self.Eta_Map(step) 133 | plt.savefig("plot_z_01_%05d.png" %step) 134 | plt.close() 135 | 136 | def Eta_Map(self, step): 137 | print('processing %dth step plot' % step) 138 | m = self.Global_MAP() 139 | pc = m.pcolormesh(self.XGRID, self.YGRID, self.ETA[step], cmap='RdBu_r', vmin=-self._cmax, vmax=self._cmax) 140 | m.colorbar(pc, location="right") 141 | t = float(step)*self._step2timecoef 142 | plt.title("Tsunami Wave Propagation at Time = %5.3f min" % t) 143 | 144 | def Global_MAP(self): 145 | fig = plt.figure(figsize=(18,12)) 146 | fig.add_axes([0.05,0.05,0.9,0.9]) 147 | ax = plt.gca() 148 | m = Basemap(projection='cyl',llcrnrlat=0.0,urcrnrlat=self.YGRID[-1,0],\ 149 | llcrnrlon=self.XGRID[0,0],urcrnrlon=255,resolution='i', ellps="WGS84", ax=ax) 150 | # h = 5000. 151 | # m = Basemap(projection='nsper',lon_0=139,lat_0=35, 152 | # satellite_height=h*1000.,resolution='l', ax=ax) 153 | m.drawcoastlines() 154 | m.fillcontinents(color='coral', lake_color='aqua') 155 | m.drawmapboundary(fill_color='aqua') 156 | # draw parallels and meridians. 157 | m.drawparallels(npy.arange(-90.,91.,20.),labels=[1,0,0,0]) 158 | m.drawmeridians(npy.arange(-180.,181.,15.),labels=[0,0,0,1]) 159 | return m 160 | 161 | if __name__ == '__main__': 162 | plt.switch_backend('agg') # no display mode 163 | test = COMCOTGlobalmap(argv[1]) 164 | -------------------------------------------------------------------------------- /ts_location.dat: -------------------------------------------------------------------------------- 1 | 121.745830 25.162500 2 | 121.504170 25.287500 3 | 121.404170 25.179167 4 | 121.387500 25.162500 5 | 121.237500 25.120834 6 | 120.912500 24.854167 7 | 120.762500 24.645834 8 | 120.512500 24.295834 9 | 120.162500 23.787500 10 | 120.137500 23.620833 11 | 119.628000 23.545833 12 | 120.120830 23.470833 13 | 120.137500 23.437500 14 | 120.079160 23.212500 15 | 120.154160 22.962500 16 | 120.204160 22.820833 17 | 120.262500 22.595833 18 | 120.437500 22.462500 19 | 120.387500 22.362500 20 | 120.704160 21.987500 21 | 120.754160 21.945833 22 | 121.920830 25.095834 23 | 121.937500 25.054167 24 | 121.954170 25.029167 25 | 121.845830 24.862500 26 | 121.879 24.5875 27 | 121.770830 24.295834 28 | 121.620830 23.970834 29 | 121.512500 23.495833 30 | 121.379170 23.087500 31 | 121.195830 22.787500 32 | 121.462500 22.662500 33 | 120.904170 22.337500 34 | 121.495830 22.062500 35 | 122.079170 25.637500 36 | 121.920830 25.095834 37 | 121.920830 25.095834 38 | 121.404170 25.220834 39 | 120.004160 23.095833 40 | 142.041659 39.371422 -------------------------------------------------------------------------------- /ts_name.dat: -------------------------------------------------------------------------------- 1 | Keelung 2 | Linshanbi 3 | Danshui 4 | Taipei_Port 5 | Zhuwei 6 | Hsinchu 7 | Waipu 8 | Taichung_Port 9 | Mailiao 10 | Boziliao 11 | Penghu 12 | Wengang 13 | Dongshi 14 | Jiangjun 15 | Anping 16 | Yong-an 17 | Kaohsiung 18 | Donggang 19 | Xiao_Liuqiu 20 | Xunguangzui 21 | Houbihu 22 | Longdong 23 | Yanliao 24 | Fulong 25 | Wushi 26 | Su-ao 27 | Heping_Port 28 | Hualien 29 | Shiti 30 | Chenggong 31 | Fugang 32 | Ludao 33 | Dawu 34 | Lanyu 35 | Pengjiayu 36 | Longdong_Buoy 37 | Longdong 38 | Danshui_Estuary 39 | Qigu_Buoy 40 | Iwate_Ken -------------------------------------------------------------------------------- /type_module.f90: -------------------------------------------------------------------------------- 1 | 2 | !////////////////////////////////////////////////////////////////////// 3 | ! PARAMETER DEFINITION FOR GRID 4 | !////////////////////////////////////////////////////////////////////// 5 | MODULE LAYER_PARAMS 6 | TYPE LAYER 7 | INTEGER :: ID ! IDENTIFICATION NUMBER OF A GRID LAYER 8 | INTEGER :: PARENT ! ID OF ITS FATHER GRID 9 | INTEGER :: LEVEL ! GRID LEVEL 10 | CHARACTER(120) :: NAME ! FOR FUTURE USE 11 | CHARACTER(120) :: DEPTH_NAME ! FILENAME OF WATERDEPTH DATA 12 | 13 | INTEGER :: FS ! OPTION: CONTROLLING FORMAT OF INPUT DATA FILE 14 | INTEGER*4 :: NX, NY ! DIMENSION OF GRIDS IN X AND Y DIRECTIONS 15 | REAL, DIMENSION(:,:),POINTER :: DEFORM ! SEAFLOOR DEFORMATION IF FAULT MODEL IS IMPLEMENTED 16 | REAL, DIMENSION(:,:,:),POINTER :: Z ! FREE SURFACE ELEVATION 17 | REAL, DIMENSION(:,:,:),POINTER :: M ! VOLUME FLUX IN X 18 | REAL, DIMENSION(:,:,:),POINTER :: N ! VOLUME FLUX IN Y 19 | REAL, DIMENSION(:,:),POINTER :: H ! STILL WATER DEPTH AT T = 0.0 20 | REAL, DIMENSION(:,:,:),POINTER :: HT ! TRANSIENT WATER DEPTH AT T = N*DT AND T = (N+1)*DT 21 | REAL, DIMENSION(:,:),POINTER :: HP ! STILL WATER DEPTH AT DISCHARGE POINT P (I+1/2,J) 22 | REAL, DIMENSION(:,:),POINTER :: HQ ! STILL WATER DEPTH AT DISCHARGE POINT Q (I,J+1/2) 23 | REAL, DIMENSION(:,:,:),POINTER :: DH ! BEING USED FOR SEDIMENT TRANSPORT 24 | REAL, DIMENSION(:,:,:),POINTER :: DZ ! TOTAL WATER DEPTH, FOR MOVING BOUNDARY 25 | REAL, DIMENSION(:,:),POINTER :: R1 ! R0 TO R6 : COEFFICIENTS FOR SPHERICAL COORD 26 | REAL, DIMENSION(:,:),POINTER :: R2 27 | REAL, DIMENSION(:,:),POINTER :: R3 28 | REAL, DIMENSION(:,:),POINTER :: R4 29 | REAL, DIMENSION(:,:),POINTER :: R5 30 | REAL, DIMENSION(:),POINTER :: R6 31 | REAL, DIMENSION(:,:),POINTER :: R0 ! R0 : COEFFICIENTS FOR SPHERICAL COORD 32 | REAL, DIMENSION(:,:),POINTER :: R11 ! R21: COEFFICIENTS FOR SPHERICAL COORD 33 | REAL, DIMENSION(:,:),POINTER :: R21 ! R21: COEFFICIENTS FOR SPHERICAL COORD 34 | REAL, DIMENSION(:,:),POINTER :: R22 ! R21: COEFFICIENTS FOR SPHERICAL COORD 35 | REAL, DIMENSION(:,:),POINTER :: XFLUX ! INTERNAL USE, VOLUME FLUX AT CONNECTING INTERFACE, FOR FLUX INTERPOLATION THROUGH NESTING INTERFACE 36 | REAL, DIMENSION(:,:),POINTER :: YFLUX ! INTERNAL USE, VOLUME FLUX AT CONNECTING INTERFACE, FOR FLUX INTERPOLATION THROUGH NESTING INTERFACE 37 | ! REAL, ALLOCATABLE :: XFLUX(:,:) 38 | ! REAL, ALLOCATABLE :: YFLUX(:,:) 39 | REAL, DIMENSION(:),POINTER :: X ! X COORDINATE OF GRIDS 40 | REAL, DIMENSION(:),POINTER :: Y ! Y COORDINATE OF GRIDS 41 | REAL, DIMENSION(:),POINTER :: XT ! X COORDINATE OF GRIDS (TEMP) 42 | REAL, DIMENSION(:),POINTER :: YT ! Y COORDINATE OF GRIDS (TEMP) 43 | REAL :: DX ! GRID SIZE IN X DIRECTION 44 | REAL :: DY ! GRID SIZE IN Y DIRECTION 45 | REAL, DIMENSION(:),POINTER :: DEL_X ! VARIABLE GRID SIZE IN X DIRECTION 46 | REAL, DIMENSION(:),POINTER :: DEL_Y ! VARIABLE GRID SIZE IN Y DIRECTION 47 | REAL :: DT ! TIME STEP 48 | REAL :: RX ! R=DT/DX 49 | REAL :: RY ! R=DT/DY 50 | REAL :: GRX ! GR=GRAV*DT/DX 51 | REAL :: GRY ! GR=GRAV*DT/DY 52 | INTEGER :: INI_SWITCH ! SWITCH FOR INITIAL CONDITION 53 | INTEGER :: BC_TYPE ! BOUNDARY CONDITION (FOR LAYER01 ONLY) 54 | INTEGER :: DIM ! DIMENSION: 1 -- ONE-DIMENSIONAL; 2 -- TWO-DIMENSIONAL 55 | INTEGER :: LINCHK ! FOR INTERNAL PURPOSE, 0 - WITHOUT CONVECTION TERMS; 1- WITH CONVECTION TERMS 56 | INTEGER :: MODSCM ! FOR INTERNAL PURPOSE, 0 - WITH MODIFIED SCHEME; 1 - WITHOUT MODIFIED SCHEME 57 | !VARIABLES RELATED TO BOTTOM FRICTION 58 | INTEGER :: FRIC_SWITCH ! 0-USE MANNING'S FORMULA,CONST. COEF;1-NO FRICTION; 2-VARIABLE COEF; 3-SEDIMENT TRANS 59 | REAL :: FRIC_COEF ! MANNING'S ROUGHNESS COEFFICIENT 60 | REAL, DIMENSION(:,:),POINTER :: FRIC_VCOEF ! VARIABLE MANNING'S ROUGHNESS COEF. 61 | !VARIABLES RELATED TO NUMERICAL DISPERSION 62 | INTEGER,DIMENSION(:,:),POINTER :: MASK 63 | REAL, DIMENSION(:,:),POINTER :: ALPHA ! VARIABLE FOR IMPROVEMENT OF NUMERICAL DISPERSION 64 | REAL, DIMENSION(:,:),POINTER :: A1X 65 | REAL, DIMENSION(:,:),POINTER :: A2X 66 | REAL, DIMENSION(:,:),POINTER :: A1Y 67 | REAL, DIMENSION(:,:),POINTER :: A2Y 68 | REAL, DIMENSION(:,:,:),POINTER :: CF 69 | REAL, DIMENSION(:,:,:),POINTER :: CB 70 | REAL, DIMENSION(:,:),POINTER :: M0 ! VOLUME FLUX IN X AT T=N-1 71 | REAL, DIMENSION(:,:),POINTER :: N0 ! VOLUME FLUX IN Y AT T=N-1 72 | REAL, DIMENSION(:,:),POINTER :: SPONGE_COEFX !COEFICIENTS USED FOR SPONGE LAYER IMPLEMENTATION 73 | REAL, DIMENSION(:,:),POINTER :: SPONGE_COEFY !COEFICIENTS USED FOR SPONGE LAYER IMPLEMENTATION 74 | REAL, DIMENSION(:,:),POINTER :: Z_MAX ! MAXIMUM WATER SURFACE ELEVATION 75 | REAL, DIMENSION(:,:),POINTER :: Z_MIN ! MAXIMUM WATER SURFACE DEPRESSION 76 | REAL :: SOUTH_LAT !F ! LATTITUDE OF SOUTH BOUNDARY (NOTE: SOUTH EDGE OF BOTTOM GRID CELLS !!!) 77 | INTEGER :: LAYCORD ! COORDINATE, 0-SPHERI, 1-CART 78 | INTEGER :: LAYGOV ! GOVERNING EQ. 0-LINEAR, 1-NONLINEAR 79 | INTEGER :: LAYSWITCH ! SWITCH TO TURN ON/OFF CURRENT GRID 80 | INTEGER :: FLUXSWITCH ! FLUX OUTPUT SWITCH: 0-OUTPUT FLUX, 1-NO FLUX OUTPUT 81 | INTEGER :: SEDI_SWITCH ! SEDIMENT TRANSPORT: 0-ENABLE, 1-DISABLE 82 | INTEGER :: REL_SIZE ! GRID SIZE RATIO OF PARENT GRID TO CHILD GRID 83 | INTEGER :: REL_TIME ! TIME STEP RATIO OF PARENT GRID TO CHILD GRID 84 | INTEGER :: NUM_CHILD ! # OF CHILDREN GRIDS 85 | INTEGER, DIMENSION(4) :: CORNERS ! INDICE OF CURRENT GRID'S FOUR CORNER IN ITS PARENT GRID 86 | ! CORNESR(1)=XS;CORNERS(2)=XE;CORNERS(3)=YS;CORNERS(4)=YE 87 | REAL :: X_START ! X COORDINATE OF THE LOWER-LEFT CORNER GRID 88 | REAL :: Y_START ! Y COORDINATE OF THE LOWER-LEFT CORNER GRID 89 | REAL :: X_END ! X COORDINATE OF THE UPPER-RIGHT CORNER GRID 90 | REAL :: Y_END ! Y COORDINATE OF THE UPPER-RIGHT CORNER GRID 91 | 92 | REAL :: XO ! X COORDINATE OF THE LOWER-LEFT CORNER GRID IN DEGREES 93 | REAL :: YO ! Y COORDINATE OF THE LOWER-LEFT CORNER GRID IN DEGREES 94 | 95 | REAL H_LIMIT ! WATER DEPTH LIMIT, LOWER THAN THIS VALUE WILL BE TREATED AS LAND 96 | REAL TIDE_LEVEL ! TIDAL CORRECTION TO THE MEAN SEA LEVEL (HIGH TIDE > 0; LOW TIDE < 0) 97 | LOGICAL UPZ ! ONLY .TRUE. WHEN CARTESIAN GRID IS NESTED IN SPHERICAL GRIDS 98 | INTEGER :: SC_OPTION ! OPTION SWITCH TO SELECT COUPLING METHOD BETWEEN SPHERICAL AND CARTESIAN 99 | INTEGER, DIMENSION(:,:,:),POINTER :: POS ! USED WHEN CARTESIAN GRID IS NESTED IN SPHERICAL GRIDS 100 | REAL, DIMENSION(:,:,:), POINTER :: CXY ! USED WHEN CARTESIAN GRID IS NESTED IN SPHERICAL GRIDS 101 | 102 | END TYPE LAYER 103 | END MODULE LAYER_PARAMS 104 | 105 | !////////////////////////////////////////////////////////////////////// 106 | ! PARAMETER DEFINITION MODULE FOR WAVE MAKER 107 | !////////////////////////////////////////////////////////////////////// 108 | MODULE WAVE_PARAMS 109 | TYPE WAVE 110 | INTEGER :: MK_TYPE ! WAVE TYPE (0:SINE, 1: SOLITARY, 2:GIVEN FORM, 3:FOCUSING SOLITARYWAVE) 111 | INTEGER :: INCIDENT ! INCIDENT DIRECTION(1:TOP,2:B,3:LF,4:RT,5:OBLIQUE) 112 | INTEGER :: MK_BC ! B.C. AFTER SENDING WAVE IN (1:SOLID, 0:OPEN) 113 | REAL :: WK_END ! TIME TO CHANGE BOUNDARY SENDING WAVE IN, (SEC) 114 | REAL :: W ! WAVE ANGULAR FREQUENCY 115 | REAL :: AMP ! CHARACTERISTIC WAVE HEIGHT (METER) 116 | REAL :: DEPTH ! CHARACTERISTIC WATER DEPTH (METER) 117 | REAL :: POINT(2) ! FOCUS FOR FOCUSING WAVE (POINT(1)=X0, POINT(2)=Y0) 118 | REAL :: ANG ! ANGLE FOR OBLIQUE WAVE (IN DEGREES) 119 | CHARACTER(120) :: FORM_NAME ! FILENAME OF TIMEHISTORY INPUT FILE, FOR FUTURE USE 120 | INTEGER :: FORM_LEN ! NUMBER OF ENTRIES (LINES) IN A GIVEN TIMEHISTORY INPUT FILE 121 | REAL, DIMENSION(:),POINTER :: T ! TIME FOR A GIVEN TIME HISTORY INPUT 122 | REAL, DIMENSION(:),POINTER :: FSE ! FREE SURFACE ELEVATION FOR A GIVEN TIME HISTORY INPUT 123 | END TYPE WAVE 124 | END MODULE WAVE_PARAMS 125 | 126 | !////////////////////////////////////////////////////////////////////// 127 | ! PARAMETER MODULE FOR FAULT MODEL 128 | !////////////////////////////////////////////////////////////////////// 129 | MODULE FAULT_PARAMS 130 | TYPE FAULT 131 | REAL :: HH ! FOCAL DEPTH, MEASURED FROM MEAN EARTH SURFACE TO THE TOP EDGE OF FAULT PLANE 132 | REAL :: L ! LENGTH OF THE FAULT PLANE 133 | REAL :: W ! WIDTH OF THE FAULT PLANE 134 | REAL :: D ! DISLOCATION 135 | REAL :: TH ! (=THETA) STRIKE DIRECTION 136 | REAL :: DL ! (=DELTA) DIP ANGLE 137 | REAL :: RD ! (=LAMDA) SLIP ANGLE 138 | REAL :: YO ! ORIGIN OF COMPUTATIONAL DOMAIN (LATITUDE IN DEGREES) 139 | REAL :: XO ! ORIGIN OF COMPUTATIONAL DOMAIN (LONGITUDE IN DEGREES) 140 | REAL :: Y0 ! EPICENTER (LATITUDE) 141 | REAL :: X0 ! EPICENTER (LONGITUDE) 142 | REAL :: T0 ! TIME WHEN THE RUTPURE STARTS 143 | INTEGER :: SWITCH ! DEFORMATION CALCULATION SWITCH: 0 - FAULT MODEL; 1 - DATAFILE 144 | INTEGER :: NUM_FLT ! TOTAL NUMBER OF FAULT PLANES 145 | INTEGER :: FS ! OPTION: CONTROLLING INPUT DATA FORMAT 146 | CHARACTER(120) :: DEFORM_NAME ! FILENAME OF DEFORMATION DATA 147 | END TYPE FAULT 148 | END MODULE FAULT_PARAMS 149 | 150 | !////////////////////////////////////////////////////////////////////// 151 | ! PARAMETER MODULE FOR SUBMARINE LAND SLIDE MODEL 152 | !////////////////////////////////////////////////////////////////////// 153 | MODULE LANDSLIDE_PARAMS 154 | TYPE LANDSLIDE 155 | INTEGER :: NX ! TOTAL X GRIDS OF LANDSLIDE REGION IN LAYER 1 156 | INTEGER :: NY ! TOTAL Y GRIDS OF LANDSLIDE REGION IN LAYER 1 157 | INTEGER, DIMENSION(4) :: CORNERS ! INDICES OF LANDSLIDE REGION IN LAYER 1 158 | REAL :: X_START 159 | REAL :: Y_START 160 | REAL :: X_END 161 | REAL :: Y_END 162 | REAL :: XS ! X COORD.OF STARTING LOCATION OF LANDSLIDE 163 | REAL :: YS ! Y COORD.OF STARTING LOCATION OF LANDSLIDE 164 | REAL :: XE ! X COORD.OF ENDING LOCATION OF LANDSLIDE 165 | REAL :: YE ! Y COORD.OF ENDING LOCATION OF LANDSLIDE 166 | REAL :: DISTANCE ! DISTANCE OF LANDSLIDE MOTION 167 | REAL :: SLOPE ! EFFECTIVE SLOPE OF LANDSLIDE PATH 168 | REAL :: A ! SEMI-MAJOR AXIS 169 | REAL :: B ! SEMI-MINOR AXIS 170 | REAL :: THICKNESS ! THICKNESS OF SLIDING VOLUME 171 | REAL, DIMENSION(:,:,:), POINTER :: SNAPSHOT ! SNAPSHOTS OF TRANSIENT WATER DEPTH DUE TO LANDSLIDE 172 | INTEGER :: NT ! TOTAL # OF SNAPSHOTS OF LANDSLIDE DATA 173 | REAL :: DURATION ! TOTAL DURATION OF LANDSLIDE 174 | REAL, DIMENSION(:),POINTER :: T ! TIME SEQUENCE CORRESPONDS TO WATERDEPTH SNAPSHOTS 175 | INTEGER :: OPTION ! OPTION: CONTROLLING INPUT DATA 176 | CHARACTER(120) :: FILENAME ! FILENAME OF INPUT DATA 177 | END TYPE LANDSLIDE 178 | END MODULE LANDSLIDE_PARAMS 179 | !////////////////////////////////////////////////////////////////////// 180 | ! PARAMETER MODULE FOR INPUT BOUNDARY CONDITION (FACTS) 181 | !////////////////////////////////////////////////////////////////////// 182 | MODULE BCI_PARAMS 183 | TYPE BCI 184 | INTEGER :: NX ! 185 | INTEGER :: NY ! 186 | INTEGER :: NT ! 187 | REAL :: DURATION ! 188 | REAL, DIMENSION(:),POINTER :: X 189 | REAL, DIMENSION(:),POINTER :: Y 190 | REAL, DIMENSION(:),POINTER :: T ! 191 | REAL, DIMENSION(:,:,:),POINTER :: Z_VERT ! 192 | REAL, DIMENSION(:,:,:),POINTER :: Z_HORI ! 193 | REAL, DIMENSION(:,:,:),POINTER :: U_VERT ! 194 | REAL, DIMENSION(:,:,:),POINTER :: U_HORI ! 195 | REAL, DIMENSION(:,:,:),POINTER :: V_VERT ! 196 | REAL, DIMENSION(:,:,:),POINTER :: V_HORI ! 197 | REAL, DIMENSION(:,:,:),POINTER :: SNAPSHOT 198 | REAL, DIMENSION(:,:,:),POINTER :: SNAPSHOTU 199 | REAL, DIMENSION(:,:,:),POINTER :: SNAPSHOTV 200 | INTEGER :: FS ! 201 | CHARACTER(120) :: FNAMEH ! 202 | CHARACTER(120) :: FNAMEU ! 203 | CHARACTER(120) :: FNAMEV ! 204 | END TYPE BCI 205 | END MODULE BCI_PARAMS 206 | -------------------------------------------------------------------------------- /wavemaker.f90: -------------------------------------------------------------------------------- 1 | 2 | !---------------------------------------------------------------------- 3 | SUBROUTINE WAVE_MAKER (TIME,LO,WV) 4 | !.....SEND IN INCIDENT WAVES THROUGH A BOUNDARY 5 | !.....CREATED BY XIAOMING WANG (MAR 15, 2004) 6 | ! UPDATED BY XIAOMING WANG (SEP 17 2006) 7 | !---------------------------------------------------------------------- 8 | USE LAYER_PARAMS 9 | USE WAVE_PARAMS 10 | ! IMPLICIT NONE 11 | TYPE (LAYER) :: LO 12 | TYPE (WAVE) :: WV 13 | REAL ETA,FLUX,TIME,X,DX,SOUTH_LAT,DX_RAD,DD,CC,TIME_LAG,T 14 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 15 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 16 | DATA OSIXTY/0.016666666667/, BIG/-999./ 17 | DATA RAD/0.01745329252/ 18 | ! DATA RR/6.37E6/ ! RADIUS OF EARTH 19 | ! DATA PI/3.14159265358979/ 20 | 21 | 22 | IF (LO%LAYCORD .EQ. 0) THEN 23 | SOUTH_LAT = LO%SOUTH_LAT*RAD_DEG 24 | DX_RAD = LO%DX*RAD_MIN 25 | DX = R_EARTH*COS(SOUTH_LAT)*DX_RAD !CONVERT RAD TO METERS 26 | ELSE 27 | DX = LO%DX 28 | ENDIF 29 | CC = SQRT(GRAV*(WV%DEPTH+WV%AMP)) 30 | 31 | IF (WV%MK_TYPE .EQ. 5) THEN 32 | ! TIME = TIME-19*LO%DT 33 | DO I = 1,LO%NX 34 | X = I*LO%DX - 50.0 35 | IF (X.LE.0.0) THEN 36 | CALL SOLIT (LO,ETA,FLUX,X,TIME-LO%DT,WV) 37 | DO J = 1,LO%NY 38 | LO%Z(I,J,1) = ETA 39 | LO%M(I,J,1) = FLUX 40 | ENDDO 41 | CALL SOLIT (LO,ETA,FLUX,X,TIME,WV) 42 | DO J = 1,LO%NY 43 | LO%Z(I,J,2) = ETA 44 | LO%M(I,J,2) = FLUX 45 | ENDDO 46 | ENDIF 47 | ENDDO 48 | ENDIF 49 | 50 | X = 0.0 51 | ! CALL SOLIT (ETA,FLUX,X,TIME,WV) 52 | IF (WV%MK_TYPE .LE. 2) THEN ! FOR SOLITARY OR TIMEHISTORY INPUT 53 | CALL SOLIT (LO,ETA,FLUX,X,TIME,WV) 54 | SELECT CASE (WV%INCIDENT) 55 | CASE (1) !FROM TOP BOUNDARY 56 | DO I = 1,LO%NX 57 | LO%Z(I,LO%NY,2) = ETA !+LO%Z(I,LO%NY,1) 58 | LO%N(I,LO%NY,2) = -FLUX !+LO%N(I,LO%NY,1) 59 | ENDDO 60 | CASE (2) !FROM BOTTOM BOUNDARY 61 | DO I = 1,LO%NX 62 | LO%Z(I,1,2) = ETA !+LO%Z(I,1,1) 63 | LO%N(I,1,2) = FLUX !+LO%N(I,1,1) 64 | ENDDO 65 | CASE (3) !FROM LEFT BOUNDARY 66 | DO J = 1,LO%NY 67 | LO%Z(1,J,2) = ETA !+LO%Z(1,J,1) 68 | LO%M(1,J,2) = FLUX !+LO%M(1,J,1) 69 | ENDDO 70 | CASE (4) !FROM RIGHT BOUNDARY 71 | DO J = 1,LO%NY 72 | LO%Z(LO%NX,J,2) = ETA !+LO%Z(LO%NX,J,1) 73 | LO%M(LO%NX,J,2) = -FLUX !+LO%M(LO%NX,J,1) 74 | ENDDO 75 | CASE (5) !OBLIQUE INCIDENT WAVE 76 | !PROPAGATE TO UPPER-RIGHT 77 | IF (WV%ANG.GE.0.0 .AND. WV%ANG.LT.90.0) THEN 78 | ANG = WV%ANG*RAD_DEG 79 | SN = SIN(ANG) 80 | CS = COS(ANG) 81 | DO J=1,LO%NY 82 | DIS = DBLE(J-1)*DX*CS 83 | TIME_LAG = DIS/CC 84 | T = TIME - TIME_LAG 85 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 86 | LO%Z(1,J,2) = ETA 87 | LO%M(1,J,2) = FLUX*SN 88 | LO%N(1,J,2) = FLUX*CS 89 | ENDDO 90 | DO I=1,LO%NX 91 | DIS = DBLE(I-1)*DX*SN 92 | TIME_LAG = DIS/CC 93 | T = TIME - TIME_LAG 94 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 95 | LO%Z(I,1,2) = ETA 96 | LO%M(I,1,2) = FLUX*SN 97 | LO%N(I,1,2) = FLUX*CS 98 | ENDDO 99 | ENDIF 100 | !PROPAGATE TO LOWER-RIGHT 101 | IF (WV%ANG.GE.90.0 .AND. WV%ANG.LT.180.0) THEN 102 | ANG = (180.0-WV%ANG)*RAD_DEG 103 | CS = COS(ANG) 104 | SN = SIN(ANG) 105 | DO J=1,LO%NY 106 | DIS = DBLE(LO%NY-J)*DX*CS 107 | TIME_LAG = DIS/CC 108 | T = TIME - TIME_LAG 109 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 110 | LO%Z(1,J,2) = ETA 111 | LO%M(1,J,2) = FLUX*SN 112 | LO%N(1,J,2) = -FLUX*CS 113 | ENDDO 114 | DO I=1,LO%NX 115 | DIS = DBLE(I-1)*DX*SN 116 | TIME_LAG = DIS/CC 117 | T = TIME - TIME_LAG 118 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 119 | LO%Z(I,LO%NY,2) = ETA 120 | LO%M(I,LO%NY,2) = FLUX*SN 121 | LO%N(I,LO%NY,2) = -FLUX*CS 122 | ENDDO 123 | ENDIF 124 | !PROPAGATE TO LOWER-LEFT 125 | IF (WV%ANG.GE.180.0 .AND. WV%ANG.LT.270.0) THEN 126 | ANG = (270.0-WV%ANG)*RAD_DEG 127 | CS = COS(ANG) 128 | SN = SIN(ANG) 129 | DO J=1,LO%NY 130 | DIS = DBLE(LO%NY-J)*DX*SN 131 | TIME_LAG = DIS/CC 132 | T = TIME - TIME_LAG 133 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 134 | LO%Z(LO%NX,J,2) = ETA 135 | LO%M(LO%NX,J,2) = -FLUX*CS 136 | LO%N(LO%NX,J,2) = -FLUX*SN 137 | ENDDO 138 | DO I=1,LO%NX 139 | DIS = DBLE(LO%NX-I)*DX*CS 140 | TIME_LAG = DIS/CC 141 | T = TIME - TIME_LAG 142 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 143 | LO%Z(I,LO%NY,2) = ETA 144 | LO%M(I,LO%NY,2) = -FLUX*CS 145 | LO%N(I,LO%NY,2) = -FLUX*SN 146 | ENDDO 147 | ENDIF 148 | !PROPAGATE TO UPPER-LEFT 149 | IF (WV%ANG.GE.270.0 .AND. WV%ANG.LT.360.0) THEN 150 | ANG = (360.0-WV%ANG)*RAD_DEG 151 | CS = COS(ANG) 152 | SN = SIN(ANG) 153 | DO J=1,LO%NY 154 | DIS = DBLE(J-1)*DX*CS 155 | TIME_LAG = DIS/CC 156 | T = TIME - TIME_LAG 157 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 158 | LO%Z(LO%NX,J,2) = ETA 159 | LO%M(LO%NX,J,2) = -FLUX*SN 160 | LO%N(LO%NX,J,2) = FLUX*CS 161 | ENDDO 162 | DO I=1,LO%NX 163 | DIS = DBLE(LO%NX-I)*DX*SN 164 | TIME_LAG = DIS/CC 165 | T = TIME - TIME_LAG 166 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 167 | LO%Z(I,1,2) = ETA 168 | LO%M(I,1,2) = -FLUX*SN 169 | LO%N(I,1,2) = FLUX*CS 170 | ENDDO 171 | ENDIF 172 | END SELECT 173 | ENDIF 174 | IF (WV%MK_TYPE .EQ. 3) THEN ! FOCUSING SOLITARY WAVE 175 | SELECT CASE (WV%INCIDENT) 176 | CASE (1) !WAVE FROM TOP BOUNARY 177 | !* D0 = DBLE(LO%NY-1)*DX-WV%POINT(2) 178 | D0 = LO%Y(LO%NY)-WV%POINT(2) 179 | DO I = 1,LO%NX 180 | DIS_VERT = D0 181 | !* DIS_HORI = DBLE(I-1)*DX-WV%POINT(1) 182 | DIS_HORI = LO%X(I)-WV%POINT(1) 183 | DD = SQRT(DIS_VERT**2+DIS_HORI**2)-D0 184 | CC = SQRT(GRAV*(WV%DEPTH+WV%AMP)) 185 | TIME_LAG = DD/CC 186 | T = TIME + TIME_LAG 187 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 188 | LO%Z(I,LO%NY,2) = ETA !+LO%Z(1,J,1) 189 | LO%N(I,LO%NY,2) = -FLUX*DIS_VERT/(DD+D0) !+LO%M(1,J,1) 190 | LO%M(I,LO%NY,2) = -FLUX*DIS_HORI/(DD+D0) 191 | ENDDO 192 | CASE (2) ! WAVE FROM BOTTOM BOUNDARY 193 | D0 = WV%POINT(2)-LO%Y(1) 194 | DO I = 1,LO%NX 195 | DIS_VERT = D0 196 | !* DIS_HORI = DBLE(I-1)*DX-WV%POINT(1) 197 | DIS_HORI = LO%X(I)-WV%POINT(1) 198 | DD = SQRT(DIS_HORI**2+DIS_VERT**2)-D0 199 | !CC = SQRT(9.807*(WV%DEPTH+WV%AMP)) 200 | TIME_LAG = DD/CC 201 | T = TIME + TIME_LAG 202 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 203 | LO%Z(I,1,2) = ETA !+LO%Z(1,J,1) 204 | LO%N(I,1,2) = FLUX*DIS_VERT/(DD+D0) !+LO%M(1,J,1) 205 | LO%M(I,1,2) = -FLUX*DIS_HORI/(DD+D0) 206 | ENDDO 207 | CASE (3) !WAVE FROM LEFT BOUNDARY 208 | !* D0 = WV%POINT(1) 209 | D0 = WV%POINT(1) - LO%X(1) 210 | DO J = 1,LO%NY 211 | DIS_HORI = D0 212 | !* DIS_VERT = DBLE(J-1)*DX-WV%POINT(2) 213 | DIS_VERT = LO%Y(J)-WV%POINT(2) 214 | DD = SQRT(DIS_VERT**2+DIS_HORI**2)-D0 215 | !CC = SQRT(9.807*(WV%DEPTH+WV%AMP)) 216 | TIME_LAG = DD/CC 217 | T = TIME + TIME_LAG 218 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 219 | LO%Z(1,J,2) = ETA !+LO%Z(1,J,1) 220 | LO%M(1,J,2) = FLUX*DIS_HORI/(DD+D0) !+LO%M(1,J,1) 221 | LO%N(1,J,2) = -FLUX*DIS_VERT/(DD+D0) 222 | ENDDO 223 | CASE (4) !WAVE FROM RIGHT BOUNDARY 224 | !* D0 = DBLE(LO%NX-1)*DX-WV%POINT(1) 225 | D0 = LO%X(LO%NX)-WV%POINT(1) 226 | DO J = 1,LO%NY 227 | DIS_HORI = D0 228 | !* DIS_VERT = DBLE(J-1)*DX-WV%POINT(2) 229 | DIS_VERT = LO%Y(J)-WV%POINT(2) 230 | DD = SQRT(DIS_VERT**2+DIS_HORI**2)-D0 231 | !CC = SQRT(9.807*(WV%DEPTH+WV%AMP)) 232 | TIME_LAG = DD/CC 233 | T = TIME + TIME_LAG 234 | CALL SOLIT(LO,ETA,FLUX,X,T,WV) 235 | LO%Z(LO%NX,J,2) = ETA !+LO%Z(1,J,1) 236 | LO%M(LO%NX,J,2) = -FLUX*DIS_HORI/(DD+D0) !+LO%M(1,J,1) 237 | LO%N(LO%NX,J,2) = -FLUX*DIS_VERT/(DD+D0) 238 | ENDDO 239 | END SELECT 240 | ENDIF 241 | ! WAVE MAKER STOP WORKING ON LAND 242 | DO J=1,LO%NY 243 | IF (LO%H(1,J) .LE. 0.0) THEN 244 | LO%Z(1,J,2) = 0.0 245 | LO%M(1,J,2) = 0.0 246 | LO%N(1,J,2) = 0.0 247 | ENDIF 248 | IF (LO%H(LO%NX,J) .LE. 0.0) THEN 249 | LO%Z(LO%NX,J,2) = 0.0 250 | LO%M(LO%NX,J,2) = 0.0 251 | LO%N(LO%NX,J,2) = 0.0 252 | ENDIF 253 | ENDDO 254 | DO I=1,LO%NX 255 | IF (LO%H(I,1) .LE. 0.0) THEN 256 | LO%Z(I,1,2) = 0.0 257 | LO%M(I,1,2) = 0.0 258 | LO%N(I,1,2) = 0.0 259 | ENDIF 260 | IF (LO%H(I,LO%NY) .LE. 0.0) THEN 261 | LO%Z(I,LO%NY,2) = 0.0 262 | LO%M(I,LO%NY,2) = 0.0 263 | LO%N(I,LO%NY,2) = 0.0 264 | ENDIF 265 | ENDDO 266 | 267 | RETURN 268 | END 269 | 270 | !---------------------------------------------------------------------- 271 | SUBROUTINE SOLIT (LO,ETA,FLUX,X,TIME,WAVE_INFO) 272 | ! CREATED ON SEP 17, 2006 (XIAOMING WANG) 273 | ! ADDITIONAL PASSING PARAMETER, LO, IS ADDED ON MAR 18 2008 274 | !---------------------------------------------------------------------- 275 | USE LAYER_PARAMS 276 | USE WAVE_PARAMS 277 | TYPE (LAYER):: LO 278 | TYPE (WAVE) :: WAVE_INFO 279 | REAL ETA, FLUX, TIME, X 280 | REAL TIMELAG,THI,CE,WAVEPERI,WLENGTH 281 | COMMON /CONS/ ELMAX,GRAV,PI,R_EARTH,GX,EPS,ZERO,ONE,NUM_GRID, & 282 | NUM_FLT,V_LIMIT,RAD_DEG,RAD_MIN 283 | 284 | ! PI = 3.14159265358979 285 | G = GRAV 286 | IF (LO%LAYCORD .EQ. 0) THEN 287 | DX = LO%DX*RAD_MIN*R_EARTH 288 | ELSE 289 | DX = LO%DX 290 | ENDIF 291 | DT = LO%DT 292 | 293 | IF (WAVE_INFO%MK_TYPE.EQ.0) THEN 294 | A0 = WAVE_INFO%AMP 295 | C0 = SQRT(GRAV*(WAVE_INFO%AMP+WAVE_INFO%DEPTH)) 296 | PERI = 1.30 297 | WLENGTH = C0*PERI 298 | WNUM = 2.*PI/WLENGTH 299 | OMIGA = 2.*PI/PERI 300 | 301 | ETA = A0*COS(WNUM*X-OMIGA*TIME+PI/2.0) 302 | ETAP = A0*COS(WNUM*(X+LO%DX/2.)-OMIGA*(TIME+DT/2.0)+PI/2.0) 303 | ! CE = SQRT(9.807*(WAVE_INFO%DEPTH+ETA)) 304 | FLUX = ETAP*C0 305 | ENDIF 306 | 307 | IF (WAVE_INFO%MK_TYPE.EQ.5) THEN 308 | A0 = WAVE_INFO%AMP 309 | C0 = SQRT(GRAV*(WAVE_INFO%AMP+WAVE_INFO%DEPTH)) 310 | PERI = 1.30 311 | WLENGTH = C0*PERI 312 | WNUM = 2.0*PI/WLENGTH 313 | OMIGA = 2.0*PI/PERI 314 | 315 | ETA = A0*COS(WNUM*X-OMIGA*TIME+PI/2.0) 316 | ETAP = A0*COS(WNUM*(X+LO%DX/2.)-OMIGA*(TIME+DT/2.0)+PI/2.0) 317 | ! CE = SQRT(9.807*(WAVE_INFO%DEPTH+ETA)) 318 | FLUX = ETAP*C0 319 | ENDIF 320 | 321 | IF (WAVE_INFO%MK_TYPE.EQ.1 .OR. WAVE_INFO%MK_TYPE.EQ.3) THEN 322 | THI = SQRT(3.0*WAVE_INFO%AMP/(4.0*WAVE_INFO%DEPTH**3)) 323 | CE = SQRT(GRAV*(WAVE_INFO%DEPTH+WAVE_INFO%AMP)) 324 | WAVEPERI = 2.0/(THI*CE)*(3.8+WAVE_INFO%AMP/WAVE_INFO%DEPTH) 325 | WLENGTH = 2.0*2.12*WAVE_INFO%DEPTH & 326 | /SQRT(WAVE_INFO%AMP/WAVE_INFO%DEPTH) 327 | TIMELAG = 0.6 * WAVEPERI 328 | ETA = WAVE_INFO%AMP/COSH(SQRT(3.0/4.0*WAVE_INFO%AMP & 329 | /WAVE_INFO%DEPTH**3)*CE*(TIMELAG-TIME))**2 330 | ! PRINT *,ETA 331 | FLUX = ETA*CE !/(ETA+WAVE_INFO%DEPTH) 332 | ELSEIF (WAVE_INFO%MK_TYPE.EQ.2) THEN 333 | DO I=1,WAVE_INFO%FORM_LEN-1 334 | IF (TIME.LT.WAVE_INFO%T(1)) THEN 335 | ETA = 0.0 336 | FLUX = 0.0 337 | ELSEIF (TIME.GE.WAVE_INFO%T(I) .AND. & 338 | TIME.LT.WAVE_INFO%T(I+1)) THEN 339 | ETA=(WAVE_INFO%FSE(I+1)-WAVE_INFO%FSE(I)) & 340 | /(WAVE_INFO%T(I+1) - WAVE_INFO%T(I)) & 341 | *(TIME-WAVE_INFO%T(I))+WAVE_INFO%FSE(I) 342 | CE = SQRT(GRAV*(WAVE_INFO%DEPTH+ETA)) 343 | FLUX = ETA*CE !/(ETA+WAVE_INFO%DEPTH) 344 | ELSEIF (TIME.GE.WAVE_INFO%T(WAVE_INFO%FORM_LEN)) THEN 345 | ETA = 0.0 346 | FLUX = 0.0 347 | ENDIF 348 | ENDDO 349 | ENDIF 350 | 351 | RETURN 352 | END 353 | 354 | !---------------------------------------------------------------------- 355 | SUBROUTINE READ_WAVE (WAVE_INFO) 356 | !.....CUSTOMIZED INPUT WAVE PROFILE 357 | ! ONLY USED WHEN WAVE TYPE OPTION IS 2. 358 | !---------------------------------------------------------------------- 359 | USE WAVE_PARAMS 360 | TYPE (WAVE) :: WAVE_INFO 361 | REAL H_MAX,SOUTH_LAT,DX,CR 362 | REAL TEMP1,TEMP2 363 | INTEGER COUNT 364 | CHARACTER(LEN=80) FNAME 365 | INTEGER :: RSTAT 366 | RSTAT = 0 367 | TEMP1 = 0.0 368 | TEMP2 = 0.0 369 | IF (WAVE_INFO%MK_TYPE==2) THEN 370 | OPEN(UNIT=20,FILE=WAVE_INFO%FORM_NAME,STATUS='OLD',IOSTAT=ISTAT) 371 | IF (ISTAT /=0) THEN 372 | PRINT *,"ERROR:: CAN'T OPEN TIME HISTORY DATA; EXITING." 373 | STOP 374 | END IF 375 | COUNT = -1 376 | DO WHILE (RSTAT == 0) 377 | COUNT = COUNT + 1 378 | READ (20,*,IOSTAT=RSTAT) TEMP1,TEMP2 379 | ENDDO 380 | !* CLOSE(20) 381 | WAVE_INFO%FORM_LEN = COUNT 382 | ALLOCATE(WAVE_INFO%T(WAVE_INFO%FORM_LEN)) 383 | ALLOCATE(WAVE_INFO%FSE(WAVE_INFO%FORM_LEN)) 384 | WAVE_INFO%T = 0.0 385 | WAVE_INFO%FSE = 0.0 386 | REWIND(20) 387 | !* OPEN(UNIT=20,FILE=WAVE_INFO%FORM_NAME,STATUS='OLD',IOSTAT=ISTAT) 388 | DO I=1,WAVE_INFO%FORM_LEN 389 | READ(20,*) WAVE_INFO%T(I),WAVE_INFO%FSE(I) 390 | ENDDO 391 | CLOSE(20) 392 | ENDIF 393 | IF (WAVE_INFO%INCIDENT.EQ.5) THEN ! FOR OBLIQUE WAVE 394 | WRITE (*,*) ' YOU ARE USING OBLIQUE INCIDENT WAVE. INCIDENT ANGLE IS MEASURED' 395 | WRITE (*,*) ' CLOCKWISE FROM THE NORTH (UPWARD), RANGING 0.0 TO 360.' 396 | WRITE (*,*) ' PLEASE INPUT INCDIENT ANGLE (IN DEGREES):' 397 | READ *, WAVE_INFO%ANG 398 | ENDIF 399 | IF (WAVE_INFO%MK_TYPE.EQ.3) THEN ! FOR FOCUSING INCIDENT WAVE 400 | WRITE (*,*) ' YOU ARE USING FOCUSING INCIDENT WAVE. THE FOCUS IS WHERE' 401 | WRITE (*,*) ' THE INCIDENT WAVE FROM A BOUNDARY CONVERGES.' 402 | WRITE (*,*) ' PLEASE INPUT X COORD. OF THE FOCUS (IN METERS):' 403 | READ *, WAVE_INFO%POINT(1) 404 | WRITE (*,*) ' PLEASE INPUT Y COORD. OF THE FOCUS (IN METERS):' 405 | READ *, WAVE_INFO%POINT(2) 406 | ENDIF 407 | 408 | 409 | RETURN 410 | END 411 | --------------------------------------------------------------------------------