Example #1
0
void LBInitializeBC(
                    Lattice *    lattice,
                    Problem *    problem,
                    ProblemData *problem_data)
{
  /*------------------------------------------------------------*
  * Local variables
  *------------------------------------------------------------*/

  /* Lattice variables */
  Grid  *grid = (lattice->grid);
  Vector *pressure = (lattice->pressure);
  Vector *perm = (lattice->perm);
  CharVector *cellType = (lattice->cellType);
  double time = (lattice->t);

  /* Structures */
  BCPressureData *bc_pressure_data = ProblemDataBCPressureData(problem_data);
  TimeCycleData   *time_cycle_data;
  SubgridArray   *subgrids = GridSubgrids(grid);
  GrGeomSolid    *gr_domain;

  /* Patch variables */
  double       ***values;
  double         *patch_values = NULL;
  int            *fdir;

  /* Grid parameters */
  Subgrid   *subgrid;
  int nx, ny, nz;
  int ix, iy, iz;
  int nx_v, ny_v, nz_v;

  /* Indices and counters */
  int num_patches;
  int num_phases;
  int ipatch, is, i, j, k, ival;
  int cycle_number, interval_number;
  int r;

  /* Physical variables and coefficients */
  Subvector *sub_p;
  double    *pp;
  Subvector *sub_perm;
  double    *permp;
  Subcharvector *sub_cellType;
  char      *cellTypep;
  double rho_g;

  /* Communications */
  VectorUpdateCommHandle *handle;

  /*--------------------------
   *  Initializations
   *--------------------------*/
  rho_g = ProblemGravity(problem) * RHO;
  num_patches = BCPressureDataNumPatches(bc_pressure_data);
  gr_domain = ProblemDataGrDomain(problem_data);
  num_phases = BCPressureDataNumPhases(bc_pressure_data);
  if (num_patches > 0)
  {
    time_cycle_data = BCPressureDataTimeCycleData(bc_pressure_data);
    values = ctalloc(double **, num_patches);

    for (ipatch = 0; ipatch < num_patches; ipatch++)
    {
      values[ipatch] = ctalloc(double *, SubgridArraySize(subgrids));

      cycle_number = BCPressureDataCycleNumber(bc_pressure_data, ipatch);
      interval_number = TimeCycleDataComputeIntervalNumber(problem, time,
                                                           time_cycle_data, cycle_number);

      switch (BCPressureDataType(bc_pressure_data, ipatch))
      {
        case 0:
        {
          BCPressureType0 *bc_pressure_type0;

          GeomSolid       *ref_solid;

          double z, dz2;
          double         **elevations;
          int ref_patch, iel;

          bc_pressure_type0 = (BCPressureType0*)BCPressureDataIntervalValue(
                                                                            bc_pressure_data, ipatch, interval_number);
          ref_solid = ProblemDataSolid(problem_data,
                                       BCPressureType0RefSolid(bc_pressure_type0));
          ref_patch = BCPressureType0RefPatch(bc_pressure_type0);

          /* Calculate elevations at (x,y) points on reference patch. */
          elevations = CalcElevations(ref_solid, ref_patch, subgrids, problem_data);

          ForSubgridI(is, subgrids)
          {
            /* subgrid = GridSubgrid(grid, is); */
            subgrid = SubgridArraySubgrid(subgrids, is);
            sub_p = VectorSubvector(pressure, is);
            sub_perm = VectorSubvector(perm, is);
            sub_cellType = CharVectorSubcharvector(cellType, is);

            nx = SubgridNX(subgrid);
            ny = SubgridNY(subgrid);
            nz = SubgridNZ(subgrid);

            ix = SubgridIX(subgrid);
            iy = SubgridIY(subgrid);
            iz = SubgridIZ(subgrid);

            /* RDF: assume resolution is the same in all 3 directions */
            r = SubgridRX(subgrid);

            pp = SubvectorData(sub_p);
            permp = SubvectorData(sub_perm);
            cellTypep = SubcharvectorData(sub_cellType);

            nx_v = SubvectorNX(sub_p);
            ny_v = SubvectorNY(sub_p);
            nz_v = SubvectorNZ(sub_p);

            values[ipatch][is] = patch_values;

            dz2 = RealSpaceDZ(0) / 2.0;

            GrGeomPatchLoop(i, j, k, fdir, gr_domain, ipatch,
                            r, ix, iy, iz, nx, ny, nz,
            {
              ival = SubvectorEltIndex(sub_p, i, j, k);
              iel = (i - ix) + (j - iy) * nx;
              z = RealSpaceZ(k, 0) + fdir[2] * dz2;

              pp[ival] = BCPressureType0Value(bc_pressure_type0)
                         - rho_g * (z - elevations[is][iel]);

              cellTypep[ival] = 0;
            });

            tfree(elevations[is]);
          }       /* End subgrid loop */

          tfree(elevations);
          break;
        }

        case 1:
        {
          BCPressureType1 *bc_pressure_type1;
          int num_points;
          double x, y, z, dx2, dy2, dz2;
          double unitx, unity, line_min, line_length, xy, slope;
          int ip;

          bc_pressure_type1 = (BCPressureType1*)BCPressureDataIntervalValue(bc_pressure_data, ipatch, interval_number);

          ForSubgridI(is, subgrids)
          {
            /* subgrid = GridSubgrid(grid, is); */
            subgrid = SubgridArraySubgrid(subgrids, is);
            sub_p = VectorSubvector(pressure, is);
            sub_perm = VectorSubvector(perm, is);
            sub_cellType = CharVectorSubcharvector(cellType, is);

            nx = SubgridNX(subgrid);
            ny = SubgridNY(subgrid);
            nz = SubgridNZ(subgrid);

            ix = SubgridIX(subgrid);
            iy = SubgridIY(subgrid);
            iz = SubgridIZ(subgrid);

            /* RDF: assume resolution is the same in all 3 directions */
            r = SubgridRX(subgrid);

            pp = SubvectorData(sub_p);
            permp = SubvectorData(sub_perm);
            cellTypep = SubcharvectorData(sub_cellType);

            nx_v = SubvectorNX(sub_p);
            ny_v = SubvectorNY(sub_p);
            nz_v = SubvectorNZ(sub_p);

            values[ipatch][is] = patch_values;

            dx2 = RealSpaceDX(0) / 2.0;
            dy2 = RealSpaceDY(0) / 2.0;
            dz2 = RealSpaceDZ(0) / 2.0;

            /* compute unit direction vector for piecewise linear line */
            unitx = BCPressureType1XUpper(bc_pressure_type1) - BCPressureType1XLower(bc_pressure_type1);
            unity = BCPressureType1YUpper(bc_pressure_type1) - BCPressureType1YLower(bc_pressure_type1);
            line_length = sqrt(unitx * unitx + unity * unity);
            unitx /= line_length;
            unity /= line_length;
            line_min = BCPressureType1XLower(bc_pressure_type1) * unitx
                       + BCPressureType1YLower(bc_pressure_type1) * unity;

            GrGeomPatchLoop(i, j, k, fdir, gr_domain, ipatch,
                            r, ix, iy, iz, nx, ny, nz,
            {
              ival = SubvectorEltIndex(sub_p, i, j, k);

              x = RealSpaceX(i, 0) + fdir[0] * dx2;
              y = RealSpaceY(j, 0) + fdir[1] * dy2;
              z = RealSpaceZ(k, 0) + fdir[2] * dz2;

              /* project center of BC face onto piecewise line */
              xy = (x * unitx + y * unity - line_min) / line_length;

              /* find two neighboring points */
              ip = 1;
              /* Kludge; this needs to be fixed. */
              num_points = 2;
              for (; ip < (num_points - 1); ip++)
              {
                if (xy < BCPressureType1Point(bc_pressure_type1, ip))
                  break;
              }

              /* compute the slope */
              slope = ((BCPressureType1Value(bc_pressure_type1, ip) - BCPressureType1Value(bc_pressure_type1, (ip - 1)))
                       / (BCPressureType1Point(bc_pressure_type1, ip) - BCPressureType1Point(bc_pressure_type1, (ip - 1))));

              pp[ival] = BCPressureType1Value(bc_pressure_type1, ip - 1)
                         + slope * (xy - BCPressureType1Point(
                                                              bc_pressure_type1, ip - 1))
                         - rho_g * z;

              cellTypep[ival] = 0;
            });
          }      /* End subgrid loop */
void FreeBCPressureData(
   BCPressureData *bc_pressure_data)
{
   int            i, cycle_number, interval_division, interval_number;

   TimeCycleData *time_cycle_data;

   if ( bc_pressure_data )
   {
      time_cycle_data = BCPressureDataTimeCycleData(bc_pressure_data);

      if (BCPressureDataNumPatches(bc_pressure_data) > 0)
      {
         if (BCPressureDataValues(bc_pressure_data))
         {
            for(i = 0; i < BCPressureDataNumPatches(bc_pressure_data); i++)
            {
               if (BCPressureDataIntervalValues(bc_pressure_data,i))
               {
                  cycle_number = BCPressureDataCycleNumber(bc_pressure_data,i);
                  interval_division = TimeCycleDataIntervalDivision(
					 time_cycle_data, cycle_number);
                  for(interval_number = 0; 
		      interval_number < interval_division; 
		      interval_number++)
                  {
                     switch(BCPressureDataType(bc_pressure_data,i))
                     {
                     case 0:
                     {
                        BCPressureType0 *bc_pressure_type0;

                        bc_pressure_type0 = (BCPressureType0 *)BCPressureDataIntervalValue(
                                           bc_pressure_data,i,interval_number);
                        if (BCPressureType0ValueAtInterfaces(
                            bc_pressure_type0))
                        {
                           tfree(BCPressureType0ValueAtInterfaces(
                                                           bc_pressure_type0));
                        }
                        break;
                     }
                     case 1:
                     {
                        BCPressureType1 *bc_pressure_type1;

                        bc_pressure_type1 = (BCPressureType1 *)BCPressureDataIntervalValue(
                                           bc_pressure_data,i,interval_number);
                        if (BCPressureType1Points(bc_pressure_type1))
                        {
                           tfree(BCPressureType1Points(bc_pressure_type1));
                        }
                        if (BCPressureType1Values(bc_pressure_type1))
                        {
                           tfree(BCPressureType1Values(bc_pressure_type1));
                        }
                        if (BCPressureType1ValueAtInterfaces(
                                                            bc_pressure_type1))
                        {
                           tfree(BCPressureType1ValueAtInterfaces(
                                                           bc_pressure_type1));
                        }
                        break;
                     }
                     case 2:
                     {
                        BCPressureType2 *bc_pressure_type2;

                        bc_pressure_type2 = (BCPressureType2 *)BCPressureDataIntervalValue(
                                           bc_pressure_data,i,interval_number);

                        break;
                     }
                     case 3:
                     {
                        BCPressureType3 *bc_pressure_type3;

                        bc_pressure_type3 = (BCPressureType3 *)BCPressureDataIntervalValue(
                                           bc_pressure_data,i,interval_number);

                        break;
                     }
                     case 4:
                     {
                        BCPressureType4 *bc_pressure_type4;

                        bc_pressure_type4 = (BCPressureType4 *)BCPressureDataIntervalValue(
                                           bc_pressure_data,i,interval_number);
                        if (BCPressureType4FileName(bc_pressure_type4))
                        {
                           tfree(BCPressureType4FileName(bc_pressure_type4));
                        }
                        break;
                     }
                     case 5:
                     {
                        BCPressureType5 *bc_pressure_type5;

                        bc_pressure_type5 = (BCPressureType5 *)BCPressureDataIntervalValue(
                                           bc_pressure_data,i,interval_number);
                        if (BCPressureType5FileName(bc_pressure_type5))
                        {
                           tfree(BCPressureType5FileName(bc_pressure_type5));
                        }
                        break;
                     }
                     }
                     if (BCPressureDataIntervalValue(bc_pressure_data,i,
						     interval_number))
                     {
                        tfree(BCPressureDataIntervalValue(bc_pressure_data,i,
							  interval_number));
                     }
                  }
                  tfree(BCPressureDataIntervalValues(bc_pressure_data,i));
               }
            }
            tfree(BCPressureDataValues(bc_pressure_data));
         }
         if (BCPressureDataBCTypes(bc_pressure_data))
         {
            tfree(BCPressureDataBCTypes(bc_pressure_data));
         }
         if (BCPressureDataPatchIndexes(bc_pressure_data))
         {
            tfree(BCPressureDataPatchIndexes(bc_pressure_data));
         }
         if (BCPressureDataCycleNumbers(bc_pressure_data))
         {
            tfree(BCPressureDataCycleNumbers(bc_pressure_data));
         }
         if (BCPressureDataTypes(bc_pressure_data))
         {
            tfree(BCPressureDataTypes(bc_pressure_data));
         }
      }

      FreeTimeCycleData(time_cycle_data);

      tfree(bc_pressure_data);
   }
}
void     SelectTimeStep(

double      *dt,          /* Time step size */
char        *dt_info,     /* Character flag indicating what requirement 
			     chose the time step */
double       time,
Problem     *problem,
ProblemData *problem_data)
{
   PFModule      *this_module   = ThisPFModule;
   PublicXtra    *public_xtra   = (PublicXtra *)PFModulePublicXtra(this_module);

   Type0         *dummy0;
   Type1         *dummy1;

   double         well_dt, bc_dt;

   switch((public_xtra -> type))
   {
   
   case 0:
   {
      double constant;

      dummy0 = (Type0 *)(public_xtra -> data);

      constant = (dummy0 -> step);
      
      (*dt) = constant;

      break;
   }     /* End case 0 */

   case 1:
   {
      double initial_step;
      double factor;
      double max_step;
      double min_step;

      dummy1 = (Type1 *)(public_xtra -> data);

      initial_step = (dummy1 -> initial_step);
      factor = (dummy1 -> factor);
      max_step = (dummy1 -> max_step);
      min_step = (dummy1 -> min_step);

      if ((*dt) == 0.0)
      {
	 (*dt) = initial_step;
      }
      else
      {
	 (*dt) = (*dt)*factor;
	 if ((*dt) < min_step) (*dt) = min_step;
	 if ((*dt) > max_step) (*dt) = max_step;
      }

      break;
   }     /* End case 1 */

   }     /* End switch */

   /*-----------------------------------------------------------------
    * Get delta t's for all wells and boundary conditions.
    *-----------------------------------------------------------------*/

   well_dt = TimeCycleDataComputeNextTransition(problem, time,
                WellDataTimeCycleData(ProblemDataWellData(problem_data)));

   bc_dt = TimeCycleDataComputeNextTransition(problem, time,
	 BCPressureDataTimeCycleData(ProblemDataBCPressureData(problem_data)));

   /*-----------------------------------------------------------------
    * Compute the new dt value based on time stepping criterion imposed
    * by the user or on system parameter changes.  Indicate what 
    * determined the value of `dt'.
    *-----------------------------------------------------------------*/

   if ( well_dt <= 0.0 ) well_dt = (*dt);
   if ( bc_dt   <= 0.0 ) bc_dt   = (*dt);
      
   if ((*dt) > well_dt)
   {
      (*dt) = well_dt;
      (*dt_info) = 'w';
   }
   else if ((*dt) > bc_dt)
   {
      (*dt) = bc_dt;
      (*dt_info) = 'b';
   }
   else
   {
      (*dt_info) = 'p';
   }


}