⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fdtd_3d_bloch_pml.cpp

📁 利用c++语言写的三维FDTD
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			
			return 1;
		}
		
		switch (load_2D_long(Ind_F, n_Ind_F, 3, Inp_D->path_name_foll_field_points))
		{
			case 0:
					#ifdef USE_MPI //WIN
						cout << "process " << myrank << " : - Ind_F loaded successfull" << endl;
					#else //IBM AIX
						cout << "Ind_F loaded successfull" << endl;
					#endif
					break;
			case 1:
					#ifdef USE_MPI //WIN
						cout << "process " << myrank << " : - Faild to open the Ind_F file" << endl;
						MPI_Finalize();
					#else //IBM AIX
						cout << "Faild to open the Ind_F file" << endl;
					#endif
					
					return 2;
			case 2:
					#ifdef USE_MPI //WIN
						cout << "process " << myrank << " : - Wrong Ind_F file content" << endl;
						MPI_Finalize();
					#else //IBM AIX
						cout << "Wrong Ind_F file content" << endl;
					#endif
					
					return 3;
			default:
					#ifdef USE_MPI //WIN
						cout << "process " << myrank << " : - Wrong dimensions Ind_F" << endl;
						MPI_Finalize();
					#else //IBM AIX
						cout << "Wrong dimensions Ind_F" << endl;
					#endif
					
					return 4;
		}
	}
	else //if there are no external Followed field points specified
	{
		n_Ind_F = 60;
		Ind_F = Init_Matrix_2D<long >(n_Ind_F,3);
		if(!Ind_F)
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Memory allocation problem - Ind_F" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Memory allocation problem - Ind_F" << endl;
			#endif
			
			return 1;
		}

		long step_x = (nx-n_PML_x_1-n_PML_x_2-20)/19;
		for (i = 0; i<20; i++)
		{
			Ind_F[i][0] = n_PML_x_1 + n_TS + 1 + i*step_x; Ind_F[i][1] = ny/2; Ind_F[i][2] = nz/2;
		}
		long step_y = (ny-n_PML_y_1-n_PML_y_2-20)/19;
		for (i = 20; i<40; i++)
		{
			Ind_F[i][0] = nx/2; Ind_F[i][1] = n_PML_y_1 + n_TS + 1 + (i-20)*step_y; Ind_F[i][2] = nz/2;
		}
		long step_z = (nz-n_PML_z_1-n_PML_z_2-20)/19;
		for (i = 40; i<60; i++)
		{
			Ind_F[i][0] = nx/2; Ind_F[i][1] = ny/2; Ind_F[i][2] = n_PML_z_1 + n_TS + 1 + (i-40)*step_z;
		}
	}
		
	//Save Ind_F
	long x1 = 0, y1 = 0, y2 = 3, it = 0;
	#ifdef USE_MPI
		if (myrank == 0)
		{
			strcpy(file_name,Path_Data);
			strcat(file_name,"/Ind_Foll");
			if ( save_2D_long(Ind_F,x1,n_Ind_F,y1,y2,it,file_name) )
			{
				cout << "process " << myrank << " : - Error saving Ind_F" << endl;
				MPI_Finalize();
				return 2;
			}
		}
	#else
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Ind_Foll");
		if ( save_2D_long(Ind_F,x1,n_Ind_F,y1,y2,it,file_name) )
		{
			cout << "Error saving Ind_F" << endl;
			return 2;
		}
	#endif

	FDTD_3D_compl.Init_Followed(Ind_F, n_Ind_F, num_iter);
	
    /////////////////////////////////////////////////////////////////////////////
	//Save the followed data
	/////////////////////////////////////////////////////////////////////////////
	double **hx_foll_re = NULL, **hy_foll_re = NULL, **hz_foll_re = NULL;
	double **ex_foll_re = NULL, **ey_foll_re = NULL, **ez_foll_re = NULL; 
	double **hx_foll_im = NULL, **hy_foll_im = NULL, **hz_foll_im = NULL;
	double **ex_foll_im = NULL, **ey_foll_im = NULL, **ez_foll_im = NULL; 

	FDTD_3D_compl.Get_Data_Followed(hx_foll_re, hy_foll_re, hz_foll_re, 
							        ex_foll_re, ey_foll_re, ez_foll_re,
	                                hx_foll_im, hy_foll_im, hz_foll_im, 
							        ex_foll_im, ey_foll_im, ez_foll_im);

	
	char buffer[512];

	/////////////////////////////////////////////////////////////////////////////
	//start of the main FDTD loop
	/////////////////////////////////////////////////////////////////////////////
	long cont;	
	#ifdef USE_MPI
		cont = myrank;
		#ifndef run_enviroment //IBM AIX
			sprintf(Path, "%s/%i", Inp_D->Path_Load_Workspace_Data, myrank);
			FDTD_3D_compl.Init_Mesure_Ellapsed_Time(time_start, Inp_D->limit_time, myrank,
										            Inp_D->load_workspace_data, Path, Path_Data);
		#endif
	#else
		for (cont = 0; cont < n_kxkykz; cont++) //run serially
		{
	#endif
		FDTD_3D_compl.Reset_Field_Comp();

		//sets a point in the kx ky space
		FDTD_3D_compl.Init_KxORa_KyORb_KzORc(Kx_Ky_Kz[cont][0],Kx_Ky_Kz[cont][1],Kx_Ky_Kz[cont][2]);
			
		/////////////////////////////////////////////////////////////////////////////
		//start of the main FDTD loop
		/////////////////////////////////////////////////////////////////////////////
		cout << "point: " << cont <<  "   kx = " << Kx_Ky_Kz[cont][0] << 
	    "   ky = " << Kx_Ky_Kz[cont][1] << "   kz = " << Kx_Ky_Kz[cont][2] << endl;

		long iter = FDTD_3D_compl.fdtd_marching(num_iter); //returns the number of FDTD steps

		/////////////////////////////////////////////////////////////////////////////
		//end of the main FDTD loop
		/////////////////////////////////////////////////////////////////////////////
		
		sprintf(buffer, "_%i", cont);

		//hx_foll_re
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Hx_foll_re");
		strcat(file_name,buffer);
		if ( save_2D(hx_foll_re,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving hx_foll_re" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving hx_foll_re" << endl;
			#endif
			return 2;
		}
			

		//hy_foll_re
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Hy_foll_re");
		strcat(file_name,buffer);
		if ( save_2D(hy_foll_re,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving hy_foll_re" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving hy_foll_re" << endl;
			#endif
			return 2;
		}

		//hz_foll_re
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Hz_foll_re");
		strcat(file_name,buffer);
		if ( save_2D(hz_foll_re,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving hz_foll_re" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving hz_foll_re" << endl;
			#endif
			return 2;
		}

		//ex_foll_re
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Ex_foll_re");
		strcat(file_name,buffer);
		if ( save_2D(ex_foll_re,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving ex_foll_re" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving ex_foll_re" << endl;
			#endif
			return 2;
		}

		//ey_foll_re
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Ey_foll_re");
		strcat(file_name,buffer);
		if ( save_2D(ey_foll_re,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving ey_foll_re" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving ey_foll_re" << endl;
			#endif
			return 2;
		}

		//ez_foll_re
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Ez_foll_re");
		strcat(file_name,buffer);
		if ( save_2D(ez_foll_re,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving ez_foll_re" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving ez_foll_re" << endl;
			#endif
			return 2;
		}

		//hx_foll_im
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Hx_foll_im");
		strcat(file_name,buffer);
		if ( save_2D(hx_foll_im,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving hx_foll_im" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving hx_foll_im" << endl;
			#endif
			return 2;
		}

		//hy_foll_im
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Hy_foll_im");
		strcat(file_name,buffer);
		if ( save_2D(hy_foll_im,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving hy_foll_im" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving hy_foll_im" << endl;
			#endif
			return 2;
		}

		//hz_foll_im
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Hz_foll_im");
		strcat(file_name,buffer);
		if ( save_2D(hz_foll_im,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving hz_foll_im" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving hz_foll_im" << endl;
			#endif
			return 2;
		}

		//ex_foll_im
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Ex_foll_im");
		strcat(file_name,buffer);
		if ( save_2D(ex_foll_im,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving ex_foll_im" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving ex_foll_im" << endl;
			#endif
			return 2;
		}

		//ey_foll_im
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Ey_foll_im");
		strcat(file_name,buffer);
		if ( save_2D(ey_foll_im,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving ey_foll_im" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving ey_foll_im" << endl;
			#endif
			return 2;
		}

		//ez_foll_im
		strcpy(file_name,Path_Data);
		strcat(file_name,"/Ez_foll_im");
		strcat(file_name,buffer);
		if ( save_2D(ez_foll_im,x1,n_Ind_F,y1,num_iter,iter,file_name) )
		{
			#ifdef USE_MPI //WIN
				cout << "process " << myrank << " : - Error saving ez_foll_im" << endl;
				MPI_Finalize();
			#else //IBM AIX
				cout << "Error saving ez_foll_im" << endl;
			#endif
			return 2;
		}

	#ifndef USE_MPI
		}
	#endif
	/////////////////////////////////////////////////////////////////////////////
	//end of the main FDTD loop
	/////////////////////////////////////////////////////////////////////////////

	/////////////////////////////////////////////////////////////////////////////
	//Free the allocated memory
	/////////////////////////////////////////////////////////////////////////////
	
	//Free the memory allocated in the main program
	if (Path)
	{
		free(Path);
		Path = NULL;
	}
	if (Path_Data)
	{
		free(Path_Data);
		Path_Data = NULL;
	}
	if (file_name)
	{
		free(file_name);
		file_name = NULL;
	}
	if (Ind_F)
			Ind_F = Free_Matrix_2D<long>(Ind_F);
	if (Materials)
			Materials = Free_Matrix_2D<double>(Materials);
	if (Index)
			Index = Free_Matrix_3D<long>(Index,nx);
	if (Param_Source)
		    Param_Source = Free_Matrix_2D<double>(Param_Source);
	
	if (jel_TS_planes)
	{
		free(jel_TS_planes);
		jel_TS_planes = NULL;
	}
	
	//the elapsed time
	#ifdef run_enviroment //WIN
		finish = clock();
		duration = (double)(finish - start) / CLOCKS_PER_SEC;
		cout<< "duration: " << duration << " seconds" <<endl;
		cout << "success " << endl;
	#else //IBM AIX
		gettimeofday(&tv, &tz);
		time_end = (double) tv.tv_sec + (double) tv.tv_usec / 1000000.0;
		cout << myrank << " : Ellapsed time = " << time_end-time_start << endl;
	#endif

	#ifdef USE_MPI //IBM AIX
		MPI_Finalize();                            //finish MPI
	#endif

	cout << "success" << endl;

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -