Commits

Lisandro Dalcin committed 81bfb26

Fix many demos to build with scalar-type=complex

Comments (0)

Files changed (10)

demo/AdaptiveL2Projection.c

   ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
   ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);
 
+  PetscScalar scalar[2];
+  ierr  = IGAFormScalar(iga,x,2,&scalar[0],Error,NULL);CHKERRQ(ierr);
   PetscReal errors[2];
-  ierr  = IGAFormScalar(iga,x,2,&errors[0],Error,NULL);CHKERRQ(ierr);
-  errors[0] = PetscSqrtReal(PetscRealPart(errors[0]));
-  errors[1] = PetscSqrtReal(PetscRealPart(errors[1]));
+  errors[0] = PetscSqrtReal(PetscRealPart(scalar[0]));
+  errors[1] = PetscSqrtReal(PetscRealPart(scalar[1]));
   *error = errors[0]/errors[1];
 
   ierr = KSPDestroy(&ksp);CHKERRQ(ierr);

demo/BoundaryIntegral.c

   error = PetscSqrtReal(PetscRealPart(error));
 
   if (print_error) {ierr = PetscPrintf(PETSC_COMM_WORLD,"L2 error = %G\n",error);CHKERRQ(ierr);}
-  if (check_error) {if (error>1e-4) SETERRQ1(PETSC_COMM_WORLD,1,"L2 error=%G\n",error);}
+  if (check_error) {if (PetscRealPart(error)>1e-4) SETERRQ1(PETSC_COMM_WORLD,1,"L2 error=%G\n",error);}
   if (draw&&dim<3) {ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);}
 
   ierr = KSPDestroy(&ksp);CHKERRQ(ierr);

demo/CahnHilliard3D.c

   PetscReal theta,cbar,alpha;
   PetscReal L0,lambda,tau;
   Vec X0,E;
-  PetscScalar energy[3],time[3];
+  PetscReal energy[3],time[3];
 } AppCtx;
 
 #undef  __FUNCT__
   AppCtx *user = (AppCtx *)mctx;
   if (!user->E) PetscFunctionReturn(0);
 
-  PetscScalar dt;
+  PetscReal dt;
   ierr = TSGetTimeStep(ts,&dt);CHKERRQ(ierr);
   PetscPrintf(PETSC_COMM_WORLD,"%.6e %.6e %.16e\n",t,dt,user->energy[0]);
   
 
   ierr = TSGetTimeStep(ts,&dt);CHKERRQ(ierr);
   th->time[0]=t-dt;
-  ierr = IGAFormScalar(th->iga,X,1,&th->energy[0],Stats,ctx);CHKERRQ(ierr);
+  PetscScalar energy;
+  ierr = IGAFormScalar(th->iga,X,1,&energy,Stats,ctx);CHKERRQ(ierr);
+  th->energy[0] = PetscRealPart(energy);
 
   if (!th->E){
     th->energy[1] = 1.01*th->energy[0];
     th->time[2] = -2.0*dt;
   }
 
-  PetscScalar scale_min = 0.5;
-  PetscScalar scale_max = 1.5;
-  PetscScalar    dt_min = 1.0e-15;
-  PetscScalar    dt_max = 1.0e+10;
-  PetscScalar      rtol = 1.0e-3;
-  PetscScalar      atol = 1.0e-3;
-  PetscScalar       rho = 0.9;
+  PetscReal scale_min = 0.5;
+  PetscReal scale_max = 1.5;
+  PetscReal    dt_min = 1.0e-15;
+  PetscReal    dt_max = 1.0e+10;
+  PetscReal      rtol = 1.0e-3;
+  PetscReal      atol = 1.0e-3;
+  PetscReal       rho = 0.9;
   //PetscScalar       dE2 = EstimateSecondDerivative(*th);
   
   /* If the SNES fails, reject the step and reduce the step by the
   error = PetscSqrtReal(PetscRealPart(error));
 
   if (print_error) {ierr = PetscPrintf(PETSC_COMM_WORLD,"L2 error = %G\n",error);CHKERRQ(ierr);}
-  if (check_error) {if (error>1e-4) SETERRQ1(PETSC_COMM_WORLD,1,"L2 error=%G\n",error);}
+  if (check_error) {if (PetscRealPart(error)>1e-4) SETERRQ1(PETSC_COMM_WORLD,1,"L2 error=%G\n",error);}
   if (draw&&dim<3) {ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);}
   if (save)        {ierr = IGAWrite(iga,"LaplaceGeometry.dat");CHKERRQ(ierr);}
   if (save)        {ierr = IGAWriteVec(iga,x,"LaplaceSolution.dat");CHKERRQ(ierr);}

demo/NavierStokesKorteweg2D.c

   PetscFunctionBegin;
   AppCtx *user = (AppCtx *)mctx;
 
-  PetscScalar energy = 0.;
-  ierr = IGAFormScalar(user->iga,U,1,&energy,Energy,mctx);CHKERRQ(ierr);
+  PetscScalar scalar = 0.;
+  ierr = IGAFormScalar(user->iga,U,1,&scalar,Energy,mctx);CHKERRQ(ierr);
+  PetscReal energy = PetscRealPart(scalar);
 
   PetscReal dt;
   TSGetTimeStep(ts,&dt);
   error = PetscSqrtReal(PetscRealPart(error));
 
   if (print_error) {ierr = PetscPrintf(PETSC_COMM_WORLD,"Error=%G\n",error);CHKERRQ(ierr);}
-  if (check_error) {if (error>1e-4) SETERRQ1(PETSC_COMM_WORLD,1,"Error=%G\n",error);}
+  if (check_error) {if (PetscRealPart(error)>1e-4) SETERRQ1(PETSC_COMM_WORLD,1,"Error=%G\n",error);}
   if (draw&&dim<3) {ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);}
 
   ierr = KSPDestroy(&ksp);CHKERRQ(ierr);

demo/PhaseFieldCrystal2D.c

   PetscFunctionBegin;
   AppCtx *user = (AppCtx *)mctx;
 
-  PetscScalar stats[1] = {0};
-  ierr = IGAFormScalar(user->iga,U,1,&stats[0],Stats,mctx);CHKERRQ(ierr);
+  PetscScalar scalar = 0.0;
+  ierr = IGAFormScalar(user->iga,U,1,&scalar,Stats,mctx);CHKERRQ(ierr);
+  PetscReal stats = PetscRealPart(scalar);
 
-  PetscScalar dt;
+  PetscReal dt;
   TSGetTimeStep(ts,&dt);
-  PetscPrintf(PETSC_COMM_WORLD,"%.6e %.6e %.16e\n",t,dt,stats[0]);
+  PetscPrintf(PETSC_COMM_WORLD,"%.6e %.6e %.16e\n",t,dt,stats);
 
-  if(stats[0] > user->Sprev[0]) PetscPrintf(PETSC_COMM_WORLD,"WARNING: free energy increased!\n");
-  user->Sprev[0] = stats[0];
+  if(stats > user->Sprev[0]) PetscPrintf(PETSC_COMM_WORLD,"WARNING: free energy increased!\n");
+  user->Sprev[0] = stats;
 
   PetscFunctionReturn(0);
 }
 #define SQ(A) ((A)*(A))
 
 typedef struct {
-  PetscScalar m,lambda,kappa,NGr;
-  PetscScalar S0,Sin,d0,penalty;
-  PetscBool   phase_field;
+  PetscReal m,lambda,kappa,NGr;
+  PetscReal S0,Sin,d0,penalty;
+  PetscBool phase_field;
 } AppCtx;
 
 #undef  __FUNCT__
   PetscReal x[dim];
   IGAPointFormPoint(p,x);
 
-  PetscScalar f = user->S0;
-  PetscScalar d = x[dim-1];
+  PetscReal f = user->S0;
+  PetscReal d = x[dim-1];
   if(d < user->d0) f += SQ(1.-SQ(d/user->d0))*(user->Sin-user->S0);
 
   const PetscReal *N = (typeof(N)) p->shape[0];
   IGAPointFormHess (p,U,&S2[0][0]);
   for(i=0;i<dim;i++) delS += S2[i][i];
 
-  S = PetscMax(1000*PETSC_MACHINE_EPSILON,S);
+  S = PetscMax(1000*PETSC_MACHINE_EPSILON,PetscRealPart(S));
 
   const PetscReal  *N0            = (typeof(N0)) p->shape[0];
   const PetscReal (*N1)[dim]      = (typeof(N1)) p->shape[1];

demo/ShallowWater.c

   PetscReal viscosity;
 } AppCtx;
 
-PetscReal Tau(PetscReal dt, PetscScalar u0, PetscScalar u1, PetscInt nen, const PetscScalar (*N1)[2])
+PetscReal Tau(PetscReal dt, PetscScalar u0, PetscScalar u1, PetscInt nen, const PetscReal (*N1)[2])
 {
   PetscInt a,i;
   PetscScalar u[2] = {0};
     Rhu = Na * res[1];
     Rhv = Na * res[2];
 
-    PetscScalar W0[3];
+    PetscReal W0[3];
     W0[0] = 0; 
     W0[1] = (-u*u+g*h) * Na_x + (-u*v)     * Na_y; 
     W0[2] = (-u*v)     * Na_x + (-v*v+g*h) * Na_y; 
 
-    PetscScalar W1[3];
+    PetscReal W1[3];
     W1[0] = (1)   * Na_x; 
     W1[1] = (2*u) * Na_x + (v) * Na_y; 
     W1[2] = (v)   * Na_x; 
 
-    PetscScalar W2[3];
+    PetscReal W2[3];
     W2[0] =                (1) * Na_y; 
     W2[1] =                (u) * Na_y;
     W2[2] = (u) * Na_x + (2*v) * Na_y; 

demo/TwoPhaseTwoComponent.c

 
 typedef struct {
   IGA         iga;
-  PetscScalar rholw,porosity,Pr,n,Slr,Sgr,H,Mh,T,mul,mug,Mw,Dlh,k;
+  PetscReal rholw,porosity,Pr,n,Slr,Sgr,H,Mh,T,mul,mug,Mw,Dlh,k;
 } AppCtx;
 
 typedef struct {
-  PetscScalar Pl,rholh;
+  PetscReal Pl,rholh;
 } Field;
 
 PetscReal SEC_PER_YEAR = 365.0*24.0*3600.0;
   PetscScalar Pc_t  = rholh_t/(H*Mh)-Pl_t;
   PetscScalar Sle   = 1;
   PetscScalar Sle_t = 0;
-  if(rholh/H/Mh-Pl > 0.0) {
+  if(PetscRealPart(rholh/H/Mh-Pl) > 0.0) {
     Sle   = pow(pow((Pc/Pr),n)+1.,-m);
     Sle_t = -m*n/Pr*pow(pow((Pc/Pr),n)+1.,-m-1.)*pow(Pc/Pr,n-1.)*Pc_t;
   }
   }
   
   // Pl,Pg,Sg computed at left middle  
-  PetscScalar point[2] = {0,10};
+  PetscReal   point[2] = {0,10};
   PetscScalar sol[2];
   ierr = IGAInterpolate(iga,U,point,sol,NULL);CHKERRQ(ierr);
   PetscScalar Pl,Pg,Sg;
   Pg = sol[1]/(user->Mh*user->H);
   PetscScalar Pc  = Pg-Pl;
   PetscScalar Sle = 1;
-  if(Pc > 0.0) {
+  if(PetscRealPart(Pc) > 0.0) {
     Sle   = pow(pow((Pc/user->Pr),user->n)+1.,-1.+1./user->n);
   }
   Sg = 1.-((1.-user->Slr-user->Sgr)*Sle+user->Slr);
   Pg = sol[1]/(user->Mh*user->H);
   Pc  = Pg-Pl;
   Sle = 1;
-  if(Pc > 0.0) {
+  if(PetscRealPart(Pc) > 0.0) {
     Sle   = pow(pow((Pc/user->Pr),user->n)+1.,-1.+1./user->n);
   }
   Sg = 1.-((1.-user->Slr-user->Sgr)*Sle+user->Slr);