Exemple #1
0
void phi_flux( struct domain * theDomain , double dt ){

   struct cell ** theCells = theDomain->theCells;
   int Nr = theDomain->Nr;
   int Nz = theDomain->Nz;
   int * Np = theDomain->Np;
   double * r_jph = theDomain->r_jph;
   double * z_kph = theDomain->z_kph;
   int i,j,k;
   plm_phi( theDomain );
   for( j=0 ; j<Nr ; ++j ){
      for( k=0 ; k<Nz ; ++k ){
         int jk = j+Nr*k;
         for( i=0 ; i<Np[jk] ; ++i ){
            int ip = (i+1)%Np[jk];
            struct cell * cp = theCells[jk];
            double phi = cp[i].piph;
            double xp[3] = {r_jph[j]  ,phi,z_kph[k]  };
            double xm[3] = {r_jph[j-1],phi,z_kph[k-1]};
            double r = get_moment_arm(xp,xm);
            double dA = get_dA(xp,xm,0); 
            double x[3] = {r, phi, 0.5*(z_kph[k-1]+z_kph[k])};
            riemann_phi( &(cp[i]) , &(cp[ip]) , x , dA*dt );
         }
      }
   }

}
Exemple #2
0
void calc_prim( struct domain * theDomain ){

   struct cell ** theCells = theDomain->theCells;
   int Nr = theDomain->Nr;
   int Nz = theDomain->Nz;
   int * Np = theDomain->Np;
   double * r_jph = theDomain->r_jph;
   double * z_kph = theDomain->z_kph;

   int i,j,k;
   for( j=0 ; j<Nr ; ++j ){
      double rm = r_jph[j-1];
      double rp = r_jph[j];
      for( k=0 ; k<Nz ; ++k ){
         int jk = j+Nr*k;
         for( i=0 ; i<Np[jk] ; ++i ){
            struct cell * c = &(theCells[jk][i]);
            double phip = c->piph;
            double phim = phip-c->dphi;
            double xp[3] = {rp,phip,z_kph[k]  };
            double xm[3] = {rm,phim,z_kph[k-1]};
            double r = get_moment_arm( xp , xm );
            double dV = get_dV( xp , xm );
            double x[3] = {r, 0.5*(phim+phip), 0.5*(z_kph[k]+z_kph[k-1])};
            cons2prim( c->cons , c->prim , x , dV );
         }
      }
   }
}
Exemple #3
0
void setupCells( struct domain * theDomain ){

   int restart_flag = theDomain->theParList.restart_flag;
   if( restart_flag ) restart( theDomain );

   calc_dp( theDomain );

   int i,j,k;
   struct cell ** theCells = theDomain->theCells;
   int Nr = theDomain->Nr;
   int Nz = theDomain->Nz;
   int * Np = theDomain->Np;
   int Npl = theDomain->Npl;
   double * r_jph = theDomain->r_jph;
   double * z_kph = theDomain->z_kph;
   int atmos = theDomain->theParList.include_atmos;

   for( j=0 ; j<Nr ; ++j ){
      for( k=0 ; k<Nz ; ++k ){
         int jk = j+Nr*k;
         for( i=0 ; i<Np[jk] ; ++i ){
            struct cell * c = &(theCells[jk][i]);
            double phip = c->piph;
            double phim = phip-c->dphi;
            c->wiph = 0.0; 
            double xp[3] = {r_jph[j  ],phip,z_kph[k  ]};
            double xm[3] = {r_jph[j-1],phim,z_kph[k-1]};
            double r = get_moment_arm( xp , xm );
            double dV = get_dV( xp , xm );
            double phi = c->piph-.5*c->dphi;
            double x[3] = { r , phi , .5*(z_kph[k]+z_kph[k-1])};
            if( !restart_flag ) initial( c->prim , x );
            subtract_omega( c->prim ); 
            if( atmos ){
               int p;
               for( p=0 ; p<Npl ; ++p ){
                  double gam = theDomain->theParList.Adiabatic_Index;
                  adjust_gas( theDomain->thePlanets+p , x , c->prim , gam );
               }
            }
            prim2cons( c->prim , c->cons , x , dV );
            cons2prim( c->cons , c->prim , x , dV );
         }    
      }    
   }

   set_wcell( theDomain );

}
Exemple #4
0
void output( struct domain * theDomain , char * filestart ){

   struct cell * theCells = theDomain->theCells;
   int Nr = theDomain->Nr;
   int Ng = theDomain->Ng;
   int rank = theDomain->rank;
   int size = theDomain->size;

   char filename[256];
   sprintf(filename,"%s.dat",filestart);

   if( rank==0 ){
      FILE * pFile = fopen( filename , "w" );
      fprintf(pFile,"#r           dr           Density      Pressure     Velocity     X            Alpha\n");
      fclose(pFile);
   }
   MPI_Barrier( MPI_COMM_WORLD );

   int i_min = 0;
   int i_max = Nr;

   if( rank != 0      ) i_min = Ng;
   if( rank != size-1 ) i_max = Nr-Ng;

   int rk;
   for( rk=0 ; rk<size ; ++rk ){
      if( rank==rk ){
         FILE * pFile = fopen( filename , "a" );
         int i,q;
         for( i=i_min ; i<i_max ; ++i ){
            struct cell * c = theCells+i;
            double rp = c->riph;
            double dr = c->dr; 
            double rm = rp-dr;
            double r  = get_moment_arm( rp , rm );
            fprintf(pFile,"%e %e ",r,dr);
            for( q=0 ; q<NUM_Q ; ++q ){
               fprintf(pFile,"%e ",c->prim[q]);
            }
            fprintf(pFile,"%e ",c->miph);
            fprintf(pFile,"\n");
         }
         fclose( pFile );
      }
      MPI_Barrier( MPI_COMM_WORLD );
   }

}
Exemple #5
0
void B_faces_to_cells( struct domain * theDomain , int type ){

   if( NUM_Q > BZZ ){
      struct cell ** theCells = theDomain->theCells;
      struct face * theFaces_1 = theDomain->theFaces_1;
      struct face * theFaces_2 = theDomain->theFaces_2;
   
      int Nr = theDomain->Nr;
      int Nz = theDomain->Nz;
      int * Np = theDomain->Np;
      double * r_jph = theDomain->r_jph;
      double * z_kph = theDomain->z_kph;

      int Nf = theDomain->fIndex_r[theDomain->N_ftracks_r];  
 
      int i,j,k;

      for( j=0 ; j<Nr ; ++j ){
         for( k=0 ; k<Nz ; ++k ){
            int jk = j+Nr*k;
            for( i=0 ; i<Np[jk] ; ++i ){
               struct cell * c = &(theCells[jk][i]);
               c->tempDoub = 0.0;
               if( type==0 ){
                  c->prim[BRR] = 0.0;
                  c->prim[BPP] = 0.0;
                  if( NUM_FACES==5 ) c->prim[BZZ] = 0.0;
               }else{
                  c->cons[BRR] = 0.0;
                  c->cons[BPP] = 0.0;
                  if( NUM_FACES==5 ) c->cons[BZZ] = 0.0;
               }
            }
         }
      }   

      int n;
      for( n=0 ; n<Nf ; ++n ){
         struct face * f = theFaces_1 + n;
         struct cell * cL = f->L;
         struct cell * cR = f->R;
         double Phi;
         if( f->LRtype==0 ){
            Phi = cL->Phi[2];
         }else{
            Phi = cR->Phi[1];
         }
         cL->tempDoub += f->dA;
         cR->tempDoub += f->dA;

         if( type==0 ){
            cL->prim[BRR] += Phi;
            cR->prim[BRR] += Phi;
         }else{
            cL->cons[BRR] += Phi;
            cR->cons[BRR] += Phi;
         }
      }

      for( j=0 ; j<Nr ; ++j ){
         for( k=0 ; k<Nz ; ++k ){
            int jk = j+Nr*k;
            for( i=0 ; i<Np[jk] ; ++i ){
               int im = i-1;
               if( im==-1 ) im = Np[jk]-1;

               struct cell * c = &(theCells[jk][i]);
               struct cell * cm = &(theCells[jk][im]);

               double xp[3] = { r_jph[j]   , c->piph  , z_kph[k]   };
               double xm[3] = { r_jph[j-1] , cm->piph , z_kph[k-1] };
               double r = get_moment_arm( xp , xm );
               double dA = get_dA( xp , xm , 0 );
               double dV = get_dV( xp , xm );

               if( type==0 ){
                  c->prim[BRR] /= c->tempDoub;
                  c->prim[BPP] = .5*(c->Phi[0]+cm->Phi[0])/dA;
               }else{
                  c->cons[BRR] *= dV/r/c->tempDoub;
                  c->cons[BPP] = .5*(c->Phi[0]+cm->Phi[0])*dV/dA/r;
               }
            }
         }
      }

      if( NUM_FACES == 5 && Nz>1 ){
         for( j=0 ; j<Nr ; ++j ){
            for( k=0 ; k<Nz ; ++k ){
               int jk = j+Nr*k;
               for( i=0 ; i<Np[jk] ; ++i ){
                  theCells[jk][i].tempDoub = 0.0;
               }
            }
         }
         int Nfz = theDomain->fIndex_z[theDomain->N_ftracks_z];  
         for( n=0 ; n<Nfz ; ++n ){
            struct face * f = theFaces_2 + n;
            struct cell * cL = f->L;
            struct cell * cR = f->R;
            double Phi;
            if( f->LRtype==0 ){
               Phi = cL->Phi[4];
            }else{
               Phi = cR->Phi[3];
            }
            cL->tempDoub += f->dA;
            cR->tempDoub += f->dA;

            if( type==0 ){
               cL->prim[BZZ] += Phi;
               cR->prim[BZZ] += Phi;
            }else{
               cL->cons[BZZ] += Phi;
               cR->cons[BZZ] += Phi;
            }
         }

         for( j=0 ; j<Nr ; ++j ){
            for( k=0 ; k<Nz ; ++k ){
               int jk = j+Nr*k;
               for( i=0 ; i<Np[jk] ; ++i ){
                  int im = i-1; 
                  if( im==-1 ) im = Np[jk]-1;

                  struct cell * c = &(theCells[jk][i]);
                  struct cell * cm = &(theCells[jk][im]);

                  double xp[3] = { r_jph[j]   , c->piph  , z_kph[k]   };   
                  double xm[3] = { r_jph[j-1] , cm->piph , z_kph[k-1] };
                  double dV = get_dV( xp , xm );

                  if( type==0 ){
                     c->prim[BZZ] /= c->tempDoub;
                  }else{
                     c->cons[BZZ] *= dV/c->tempDoub;
                  }    
               }    
            }    
         }  
      }
   }
}
Exemple #6
0
void set_B_fields( struct domain * theDomain ){

   int i,j,k;
   struct cell ** theCells = theDomain->theCells;
   int Nr = theDomain->Nr;
   int Nz = theDomain->Nz;
   int * Np = theDomain->Np;
   double * r_jph = theDomain->r_jph;
   double * z_kph = theDomain->z_kph;

   for( j=0 ; j<Nr ; ++j ){
      for( k=0 ; k<Nz ; ++k ){
         int jk = j+Nr*k;
         for( i=0 ; i<Np[jk] ; ++i ){
            struct cell * c = &(theCells[jk][i]);
            double phip = c->piph;
            double phim = phip-c->dphi;
            double xp[3] = { r_jph[j]   , phip , z_kph[k]   };
            double xm[3] = { r_jph[j-1] , phim , z_kph[k-1] };
            double r = get_moment_arm( xp , xm );
            double x[3] = { r , phip , .5*(z_kph[k]+z_kph[k-1])};
            double prim[NUM_Q];
            initial( prim , x ); 
            double dA = get_dA( xp , xm , 0 );
            double Phi = 0.0;
            if( NUM_Q > BPP ) Phi = prim[BPP]*dA;
            c->Phi[0] = Phi;
         }    
      }    
   }

   int NRZ1 = theDomain->N_ftracks_r;
   setup_faces( theDomain , 1 ); 

   int n;
   for( n=0 ; n<theDomain->fIndex_r[NRZ1] ; ++n ){
      struct face * f = theDomain->theFaces_1 + n;
      double prim[NUM_Q];
      initial( prim , f->cm );
      double Phi = 0.0;
      if( NUM_Q > BRR ) Phi = prim[BRR]*f->dA;
      if( f->LRtype == 0 ){
         f->L->Phi[2] = Phi;
      }else{
         f->R->Phi[1] = Phi;
      }
   }

   if( NUM_FACES==5 && theDomain->Nz > 1 ){
      int NRZ2 = theDomain->N_ftracks_z;
      setup_faces( theDomain , 2 );
      for( n=0 ; n<theDomain->fIndex_z[NRZ2] ; ++n ){
         struct face * f = theDomain->theFaces_2 + n; 
         double prim[NUM_Q];
         initial( prim , f->cm );
         double Phi = 0.0; 
         if( NUM_Q > BZZ ) Phi = prim[BZZ]*f->dA;

         if( f->LRtype == 0 ){ 
            f->L->Phi[4] = Phi; 
         }else{
            f->R->Phi[3] = Phi; 
         }    
      }
   }

   B_faces_to_cells( theDomain , 0 );
   B_faces_to_cells( theDomain , 1 );
 
   free( theDomain->theFaces_1 );
   if( theDomain->theFaces_2 ) free( theDomain->theFaces_2 );

}
Exemple #7
0
void boundary_trans( struct domain * theDomain , int dim ){

   struct cell ** theCells = theDomain->theCells;

   int Nr = theDomain->Nr;
   int Nz = theDomain->Nz;
   int * Np = theDomain->Np;
   int Ng = theDomain->Ng;
   double * r_jph = theDomain->r_jph;
   double * z_kph = theDomain->z_kph;
   int * dim_rank = theDomain->dim_rank;
   int * dim_size = theDomain->dim_size;

   if( dim==1 && dim_rank[0] == dim_size[0]-1 ){
      int j;
      for( j=Nr-1 ; j>Nr-1-Ng ; --j ){
         int i,k;
         for( k=0 ; k<Nz ; ++k ){
            int jk = j+Nr*k;
            for( i=0 ; i<Np[jk] ; ++i ){
               struct cell * c = &(theCells[jk][i]);
               double phi = c->piph - .5*c->dphi;
               double x[3] = { .5*(r_jph[j]+r_jph[j-1]) , phi , .5*(z_kph[k]+z_kph[k-1]) };
               initial( c->prim , x );
            }
         }
      }
   }

   if( dim==2 && dim_rank[1] == 0 ){
      int i,j,k;
      for( k=0 ; k<Ng ; ++k ){
         for( j=0 ; j<Nr ; ++j ){
            int jk = j+Nr*k;
            for( i=0 ; i<Np[jk] ; ++i ){
               struct cell * c = &(theCells[jk][i]);
               double phi = c->piph - .5*c->dphi;
               double xp[3] = { r_jph[j]   , c->piph            , z_kph[k]   };
               double xm[3] = { r_jph[j-1] , c->piph-.5*c->dphi , z_kph[k-1] };
               double r = get_moment_arm( xp , xm );
               double x[3] = { r , phi , .5*(z_kph[k]+z_kph[k-1]) };
               //double x[3] = { .5*(r_jph[j]+r_jph[j-1]) , phi , .5*(z_kph[k]+z_kph[k-1]) };
               initial( c->prim , x ); 
            }    
         }    
      } 
   }
   if( dim==2 && dim_rank[1] == dim_size[1]-1 ){ 
      int i,j,k;
      for( k=Nz-1 ; k>Nz-1-Ng ; --k ){
         for( j=0 ; j<Nr ; ++j ){
            int jk = j+Nr*k;
            for( i=0 ; i<Np[jk] ; ++i ){
               struct cell * c = &(theCells[jk][i]);
               double phi = c->piph - .5*c->dphi;
               double xp[3] = { r_jph[j]   , c->piph            , z_kph[k]   };
               double xm[3] = { r_jph[j-1] , c->piph-.5*c->dphi , z_kph[k-1] };
               double r = get_moment_arm( xp , xm );
               double x[3] = { r , phi , .5*(z_kph[k]+z_kph[k-1]) };
               //double x[3] = { .5*(r_jph[j]+r_jph[j-1]) , phi , .5*(z_kph[k]+z_kph[k-1]) };
               initial( c->prim , x );
            }
         }
      }
   }

}
Exemple #8
0
void set_wcell( struct domain * theDomain ){
   struct cell ** theCells = theDomain->theCells;
   int mesh_motion = theDomain->theParList.Mesh_Motion;
   int Nr = theDomain->Nr;
   int Nz = theDomain->Nz;
   int * Np = theDomain->Np;
   double * r_jph = theDomain->r_jph;
   double * z_kph = theDomain->z_kph;

   int i,j,k;
   for( j=0 ; j<Nr ; ++j ){
      for( k=0 ; k<Nz ; ++k ){
         int jk = j+Nr*k;
         double rm = r_jph[j-1];
         double rp = r_jph[j];
         double zm = z_kph[k-1];
         double zp = z_kph[k];
         for( i=0 ; i<Np[jk] ; ++i ){
            struct cell * cL = &(theCells[jk][i ]);  
            double w = 0.0;
            if( mesh_motion ){
               int ip = (i+1)%Np[jk];
               double phip = cL->piph;
               double phim = phip-cL->dphi;
               double xp[3] = {rp,phip,zp};
               double xm[3] = {rm,phim,zm};
               double r = get_moment_arm( xp , xm );
               double x[3] = {r, 0.5*(phim+phip), 0.5*(zm+zp)};
               double wL = get_omega( cL->prim , x );

               struct cell * cR = &(theCells[jk][ip]);
               phip = cR->piph;
               phim = phip-cR->dphi;
               xp[1] = phip;
               xm[1] = phim;
               r = get_moment_arm( xp , xm );
               x[0] = r;
               x[1] = 0.5*(phim+phip);
               double wR = get_omega( cR->prim , x );

               w = .5*(wL + wR); 
            }
            cL->wiph = w;
         }
      }    
   }
   if( mesh_motion == 3 ){
      for( j=0 ; j<Nr ; ++j ){
         for( k=0 ; k<Nz ; ++k ){
            int jk = j+Nr*k;
            double w = 0.0;
            for( i=0 ; i<Np[jk] ; ++i ){
               w += theCells[jk][i].wiph; 
            }    
            w /= (double)Np[jk];
            for( i=0 ; i<Np[jk] ; ++i ){
               theCells[jk][i].wiph = w; 
            }    
         }    
      } 
   }
   if( mesh_motion == 4 ){
      for( j=0 ; j<Nr ; ++j ){
         double r = .5*(r_jph[j]+r_jph[j-1]);
         for( k=0 ; k<Nz ; ++k ){
            int jk = j+Nr*k;
            for( i=0 ; i<Np[jk] ; ++i ){
               theCells[jk][i].wiph = r*mesh_om(r); 
            }    
         }    
      } 
   }

}
Exemple #9
0
void AMRsweep( struct domain * theDomain , struct cell ** swptr , int jk ){

   double * r_jph = theDomain->r_jph;
   double * z_kph = theDomain->z_kph;
   int Nr = theDomain->Nr;
   int * Np = theDomain->Np;
   int j = jk%Nr;
   int k = jk/Nr;

   double MaxShort = theDomain->theParList.MaxShort;
   double MaxLong  = theDomain->theParList.MaxLong;

   struct cell * sweep = *swptr;
   double L,S;
   int iL=0;
   int iS=0;
   longandshort( theDomain , &L , &S , &iL , &iS , sweep , j , k );
   //printf("Long = %e, Short = %e\n",L,S);

   if( S>MaxShort ){
      int iSp = (iS+1)%Np[jk];

      //Possibly shift iS backwards by 1
      int iSm = iS-1;
      if( iSm == -1 ) iSm = Np[jk]-1;
      double dpL = sweep[iSm].dphi;
      double dpR = sweep[iSp].dphi;
      if( dpL < dpR ){
         --iS;
         --iSm;
         --iSp;
         if( iS  == -1 ) iS  = Np[jk]-1;
         if( iSm == -1 ) iSm = Np[jk]-1;
         if( iSp == -1 ) iSp = Np[jk]-1;
      }

      //Remove Zone at iS+1
      sweep[iS].dphi  += sweep[iSp].dphi;
      sweep[iS].piph   = sweep[iSp].piph;
      int q;
      for( q=0 ; q<NUM_Q ; ++q ){
         sweep[iS].cons[q]   += sweep[iSp].cons[q];
         sweep[iS].RKcons[q] += sweep[iSp].RKcons[q];
      }
      double phip = sweep[iS].piph;
      double phim = phip - sweep[iS].dphi;
      double xp[3] = {r_jph[j]  ,phip,z_kph[k]  };
      double xm[3] = {r_jph[j-1],phim,z_kph[k-1]};
      double r  = get_moment_arm( xp , xm );
      double dV = get_dV( xp , xm );
      double x[3] = {r, 0.5*(phim+phip), 0.5*(z_kph[k-1]+z_kph[k])};
      cons2prim( sweep[iS].cons , sweep[iS].prim , x , dV );
      //Shift Memory
      int blocksize = Np[jk]-iSp-1;
      if( iSp != Np[jk]-1 ) memmove( sweep+iSp , sweep+iSp+1 , blocksize*sizeof(struct cell) );
      Np[jk] -= 1;
      *swptr = (struct cell *) realloc( sweep , Np[jk]*sizeof(struct cell) );
      sweep = *swptr;
      if( iS < iL ) iL--;

   }

   if( L>MaxLong ){
      Np[jk] += 1;
      *swptr = (struct cell *) realloc( sweep , Np[jk]*sizeof(struct cell) );
      sweep = *swptr;
      int blocksize = Np[jk]-iL-1;
      memmove( sweep+iL+1 , sweep+iL , blocksize*sizeof(struct cell) );

      double dphi = sweep[iL].dphi;
      double phip = sweep[iL].piph;
      double phim = phip - dphi;
      double phi0 = .5*(phip+phim);

      sweep[iL].piph   = phi0;
      sweep[iL].dphi   = .5*dphi;
      sweep[iL+1].dphi = .5*dphi;

      int q;
      for( q=0 ; q<NUM_Q ; ++q ){
         sweep[iL].cons[q]     *= .5;
         sweep[iL].RKcons[q]   *= .5;
         sweep[iL+1].cons[q]   *= .5;
         sweep[iL+1].RKcons[q] *= .5;
      }

      double xp[3] = {r_jph[j]  ,phi0,z_kph[k]  };
      double xm[3] = {r_jph[j-1],phim,z_kph[k-1]};
      double dV = get_dV( xp , xm );
      double r  = get_moment_arm( xp , xm );
      double x[3] = {r, 0.5*(xp[1]+xm[1]), 0.5*(xp[2]+xm[2])};
      cons2prim( sweep[iL].cons , sweep[iL].prim , x , dV );

      xp[1] = phip;
      xm[1] = phi0;
      dV = get_dV( xp , xm );
      r  = get_moment_arm( xp , xm );
      x[0] = r;
      x[1] = 0.5*(xp[1]+xm[1]);
      cons2prim( sweep[iL+1].cons , sweep[iL+1].prim , x , dV );

   }
}