Ejemplo n.º 1
0
PetscErrorCode SolveH(MPI_Comm comm, KSP ksp, Mat H, Vec rhs, Vec sol)
{
  /*-----------------KSP Solving------------------*/   
  PetscErrorCode ierr;
  PetscLogDouble t1,t2,tpast;
  ierr = Ptime(&t1);CHKERRQ(ierr);

  if (itsH>(maxit-5)){
    ierr = KSPSetOperators(ksp,H,H);CHKERRQ(ierr);}
  else{
    ierr = KSPSetReusePreconditioner(ksp,PETSC_TRUE);CHKERRQ(ierr);}

   ierr = KSPSolve(ksp,rhs,sol);CHKERRQ(ierr);
   ierr = KSPGetIterationNumber(ksp,&itsH);CHKERRQ(ierr);

   // if GMRES is stopped due to maxit, then redo it with sparse direct solve;
   if(itsH>(maxit-2))
     {
	ierr = KSPSetOperators(ksp,H,H);CHKERRQ(ierr);
	ierr = KSPSolve(ksp,rhs,sol);CHKERRQ(ierr);
	ierr = KSPGetIterationNumber(ksp,&itsH);CHKERRQ(ierr);
     }

  //Print kspsolving information
  double norm;
  Vec xdiff;
  ierr=VecDuplicate(sol,&xdiff);CHKERRQ(ierr);
  ierr = MatMult(H,sol, xdiff);CHKERRQ(ierr);
  ierr = VecAXPY(xdiff,-1.0,rhs);CHKERRQ(ierr);
  ierr = VecNorm(xdiff,NORM_INFINITY,&norm);CHKERRQ(ierr);
  ierr = PetscPrintf(PETSC_COMM_WORLD,"==> Helmholtz filter solution: norm of error %g, Kryolv Iterations %d----\n ",norm,itsH);CHKERRQ(ierr);    

  ierr = Ptime(&t2);CHKERRQ(ierr);
  tpast = t2 - t1;

  int rank;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  if(rank==0) PetscPrintf(PETSC_COMM_SELF,"==> Helmholtz filter solution: the runing time is %f s \n",tpast);
  /*--------------Finish KSP Solving---------------*/ 

  VecDestroy(&xdiff);
  PetscFunctionReturn(0);
}
Ejemplo n.º 2
0
//
//Turn LED ON*************************************************************
//
int LEDon(){
//Turns LED on

//Open LED file
LEDfile = fopen("/sys/class/gpio/gpio49/value","w");

//Set LED variable to on
LED = 1;

//Write to LED file
fprintf(LEDfile, "%d", LED);

//Close LED file
fclose(LEDfile);

//Call Ptime to print the time
Ptime();

return 0;	
}
Ejemplo n.º 3
0
//
//Toggle LED
//
int TLED(){
//Toggle LED
LEDfile = fopen("/sys/class/gpio/gpio49/value","r");
fscanf(LEDfile, "%d", &LED);
//Close file
fclose(LEDfile);

//if LED is on, turn off
if(LED == 1){
	LEDoff();
}
//else turn LED on
else{
	LEDon();
}

//Call Ptime to print the time
Ptime();

return 0;
}