Esempio n. 1
0
Real INSChorinPredictor::computeQpResidual()
{
  // Vector object for test function
  RealVectorValue test;
  test(_component) = _test[_i][_qp];

  // Tensor object for test function gradient
  RealTensorValue grad_test;
  for (unsigned k=0; k<3; ++k)
    grad_test(_component, k) = _grad_test[_i][_qp](k);

  // Decide what velocity vector, gradient to use:
  RealVectorValue U;
  RealTensorValue grad_U;

  switch (_predictor_enum)
  {
  case OLD:
  {
    U = RealVectorValue(_u_vel_old[_qp], _v_vel_old[_qp], _w_vel_old[_qp]);
    grad_U = RealTensorValue(_grad_u_vel_old[_qp], _grad_v_vel_old[_qp], _grad_w_vel_old[_qp]);
    break;
  }
  case NEW:
  {
    U = RealVectorValue(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
    grad_U = RealTensorValue(_grad_u_vel[_qp], _grad_v_vel[_qp], _grad_w_vel[_qp]);
    break;
  }
  case STAR:
  {
    // Note: Donea and Huerta's book says you are supposed to use "star" velocity to make Chorin implicit, not U^{n+1}.
    U = RealVectorValue(_u_vel_star[_qp], _v_vel_star[_qp], _w_vel_star[_qp]);
    grad_U = RealTensorValue(_grad_u_vel_star[_qp], _grad_v_vel_star[_qp], _grad_w_vel_star[_qp]);
    break;
  }
  default:
    mooseError("Unrecognized Chorin predictor type requested.");
  }


  //
  // Compute the different parts
  //

  // Note: _u is the component'th entry of "u_star" in Chorin's method.
  RealVectorValue U_old(_u_vel_old[_qp], _v_vel_old[_qp], _w_vel_old[_qp]);
  Real symmetric_part = (_u[_qp] - U_old(_component)) * _test[_i][_qp];

  // Convective part.  Remember to multiply by _dt!
  Real convective_part = _dt * (grad_U * U) * test;

  // Viscous part - we are using the Laplacian form here for simplicity.
  // Remember to multiply by _dt!
  Real viscous_part = _dt * (_mu/_rho) * grad_U.contract(grad_test);

  return symmetric_part + convective_part + viscous_part;
}
Esempio n. 2
0
//\begin{>>PPP_2d_Jacobi_1d_Part.tex}{\subsubsection{runBenchmark}}
void PPP_2d_Jacobi_1d_Part::
runBenchmark(  )
//================================================================
// /Description:  Executes the benchmarking code the specified
//  number of times and stores the times in the array.
//
// /Return Values: None.
//
// /Errors:
//   None.
//
// /Author:  BJM
// /Date:  24 August 2000
//\end{PPP_2d_Jacobi_1d_Part.tex}
//================================================================
{
  double theTime,theStartTime,theEndTime;
  
  int theNumProcs = 1;
  int thisProcNum = 0;

// MPI_Comm_size(MPI_COMM_WORLD, &theNumProcs);
// MPI_Comm_rank(MPI_COMM_WORLD, &thisProcNum);
 
  Partitioning_Type Partitioning(Range(0,theNumProcs-1));
  Partitioning.SpecifyInternalGhostBoundaryWidths(1,1);
  Partitioning.SpecifyDecompositionAxes(1);

  int theArraySideLength = sqrt( mUnknownsPerProc * theNumProcs );

  printf ("theArraySideLength = %d \n",theArraySideLength);
  
  doubleArray U_old(theArraySideLength,theArraySideLength,Partitioning);
  U_old = 0.0;

  Index I (1,theArraySideLength-2);
  Index J (1,theArraySideLength-2);
  int i;

// printf ("Warming up ... \n");
  for(i=0;i< mNumberOfWarmupIterations;i++)
  {
    U_old(I,J) =
      (U_old(I+1,J+1) + U_old(I+1,J) + U_old(I+1,J-1) + U_old(I,J+1) +
       U_old(I,J-1) + U_old(I-1,J+1) + U_old(I-1,J) + U_old(I-1,J-1)) / 8.0;
  }
  
  // Now time the problem
// printf ("Running timing loop ... \n");
  for (i=0; i < mNumberOfTimingIterations; i++)
  {
//  printf ("Running timing loop iteration %d \n",i);
    theStartTime = Communication_Manager::Wall_Clock_Time();
//    theStartTime = clock();
    U_old(I,J) =
      (U_old(I+1,J+1) + U_old(I+1,J) + U_old(I+1,J-1) + U_old(I,J+1) +
       U_old(I,J-1) + U_old(I-1,J+1) + U_old(I-1,J) + U_old(I-1,J-1)) / 8.0;
    theEndTime = Communication_Manager::Wall_Clock_Time();
//    theEndTime = clock();
    theTime = theEndTime - theStartTime;
    
    mTimes[0][i] = theTime;
    printf("time= %f\n",theTime);
    
  }//end of loop over timed iterations
}
void VideoFluids::trackVelocity(Matrix& Zn1,Matrix& Zn,Matrix& U,Matrix& V)
{
	Matrix Zx(height,width),Zy(height,width),ZZx(height,width),ZZy(height,width),Zt(height,width),ZZt(height,width),ZZtx(height,width),ZZty(height,width);
	Matrix Au1(height,width),Au2(height,width),Av1(height,width),Av2(height,width);
	Matrix Z2x(height,width),Z2y(height,width),Z2(height,width);
	Matrix Cu(height,width),Cv(height,width);
	Matrix tmp(height,width),tmp1(height,width);
	Matrix U_old(height,width),V_old(height,width),Ux(height,width),Uy(height,width),Vx(height,width),Vy(height,width),Uax(height,width),Uay(height,width),Vax(height,width),Vay(height,width),Uxy(height,width),Vxy(height,width);
	Matrix Coe(height,width);

	Zt = Zn;
	Zt -= Zn1;
	DotMul(Zn,Zt,ZZt);
	Zn.output("Zn.txt");
	Zn1.output("Zn1.txt");
	Zt.output("Zt.txt");
	Partial(ZZt,ZZtx,AXIS_X);
	Partial(ZZt,ZZty,AXIS_Y);
	Partial(Zn,Zx,AXIS_X);
	Partial(Zn,Zy,AXIS_Y);
	DotMul(Zn,Zx,ZZx);
	DotMul(Zn,Zy,ZZy);
	DotMul(Zx,Zx,Au1);
	Partial(ZZx,tmp,AXIS_X);
	Au1-=tmp;
	DotMul(Zn,Zn,tmp);
	Au1+=tmp;
	Au1+=2*alpha*alpha;
	DotMul(Zx,Zy,Au2);
	Partial(ZZy,tmp,AXIS_X);
	Au2-=tmp;
	DotMul(Zx,Zy,Av1);
	Partial(ZZx,tmp,AXIS_Y);
	Av1-=tmp;
	DotMul(Zy,Zy,Av2);
	Partial(ZZy,tmp,AXIS_Y);
	Av2-=tmp;
	DotMul(Zn,Zn,tmp);
	Av2+=tmp;
	Av2+=2*alpha*alpha;
	DotMul(Zn,Zn,Z2);
	Partial(Z2,Z2x,AXIS_X);
	Partial(Z2,Z2y,AXIS_Y);
	for (int i = 0;i<height;i++)
		for (int j = 0;j<width;j++)
			Coe[i][j] = 1.0/(Au1[i][j]*Av2[i][j]-Au2[i][j]*Av1[i][j]);

	U = 0.0;
	V = 0.0;
	for (int iter_time = 0;iter_time<iterationTime;iter_time++)
	{
		V_old = V;
		U_old = U;
		Partial(U,Ux,AXIS_X);
		Partial(U,Uy,AXIS_Y);
		Partial(V,Vx,AXIS_X);
		Partial(V,Vy,AXIS_Y);
		Partial(Vx,Vxy,AXIS_Y);
		Partial(Ux,Uxy,AXIS_Y);
		Average(U,Uax,AXIS_X);
		Average(U,Uay,AXIS_Y);
		Average(V,Vax,AXIS_X);
		Average(V,Vay,AXIS_Y);
		DotMul(Z2x,Ux,Cu);
		DotMul(ZZy,Vx,tmp);
		Cu += tmp;
		tmp = ZZx*-1;
		tmp+=Z2x;
		DotMul(tmp,Vy,tmp1);
		Cu+=tmp1;
		tmp = Z2;
		tmp+=alpha*alpha;
		DotMul(tmp,Uax,tmp1);
		Cu+=tmp1;
		tmp1=Uay;
		tmp1*=alpha*alpha;
		Cu+=tmp1;
		DotMul(Z2,Vxy,tmp1);
		Cu+=tmp1;
		DotMul(Zx,Zt,tmp);
		Cu-=tmp;
		Cu+=ZZtx;


		DotMul(Z2y,Vy,Cv);
		DotMul(ZZx,Uy,tmp);
		Cv += tmp;
		tmp = ZZy;
		tmp*=-1;
		tmp+=Z2y;
		DotMul(tmp,Ux,tmp1);
		Cv+=tmp1;
		tmp = Z2;
		tmp+=alpha*alpha;
		DotMul(tmp,Vay,tmp1);
		Cv+=tmp1;
		tmp1=Vax;
		tmp1*=alpha*alpha;
		Cv+=tmp1;
		DotMul(Z2,Uxy,tmp1);
		Cv+=tmp1;
		DotMul(Zy,Zt,tmp);
		Cv-=tmp;
		Cv+=ZZty;
		for (int i = 0;i<height;i++)
			for (int j = 0;j<width;j++)
			{
				U[i][j] = Coe[i][j]*(Av2[i][j]*Cu[i][j]-Au2[i][j]*Cv[i][j]);
				V[i][j] = Coe[i][j]*(-Av1[i][j]*Cu[i][j]+Au1[i][j]*Cv[i][j]);
			}	
		for (int i = 0;i<height;i++)
		{
			U[i][0] = U[i][1];
			U[i][width-1] = U[i][width-2];
			V[i][0] = V[i][1];
			V[i][width-1] =V[i][width-2];
		}
		for (int i = 0;i<width;i++)
		{
			U[0][i] = U[1][i];
			U[height-1][i] = U[height-2][i];
			V[0][i] = V[1][i];
			V[height-1][i] =V[height-2][i];
		}
		FILE* fp;
// 		Au1.output("Au1.txt");
// 		Au2.output("Au2.txt");
// 		Av1.output("Av1.txt");
// 		Av2.output("Av2.txt");
// 		Cu.output("Cu.txt");
// 		Cv.output("Cv.txt");
		float d1 = Difference(U,U_old);
		float d2 = Difference(V,V_old);
// 		U.output("U.txt");
// 		U_old.output("U_old.txt");
// 		V.output("V.txt");
		cout<<d1<<' '<<d2<<endl;
		if (d1<iterationTorlerance && d2<iterationTorlerance)
			break;
	}
	U.output("U.txt");
	
		cv::Mat showV(height,width,CV_8UC3);
		float lowv=10000000,lowu=10000000,highu=-10000000,highv=-1000000;
		for(int j=0;j<height;j++){
			for(int k=0;k<width;k++){
				if(U[j][k]>highu)
					highu=U[j][k];
				if(U[j][k]<lowu)
					lowu=U[j][k];
				if(V[j][k]>highv)
					highv=V[j][k];
				if(V[j][k]<lowv)
					lowv=V[j][k];
			}
		}
		for(int j=0;j<height;j++){
			for(int k=0;k<width;k++){
				//printf("%d %d\n",j,k);
				//if(sfs_list[i][j][k]<low)
				//	showH.at<uchar>(j,k)=0;
				//else
				float u=(U[j][k]-lowu)/(highu-lowu);
				float v=(V[j][k]-lowv)/(highv-lowv);
				if(u>0.5)
					showV.at<cv::Vec3b>(j,k)[2]=255;
				else
					showV.at<cv::Vec3b>(j,k)[2]=255*u;
				if(v>0.5){
					showV.at<cv::Vec3b>(j,k)[0]=255;
					showV.at<cv::Vec3b>(j,k)[1]=255*(1-v);
				}
				else{
					showV.at<cv::Vec3b>(j,k)[1]=255;
					showV.at<cv::Vec3b>(j,k)[0]=255*v;
				}
			}
		}
		cv::imwrite("testV.bmp",showV);
		printf("show you");
		

}