Beispiel #1
0
static PetscErrorCode TSSetFromOptions_Alpha(TS ts)
{
  TS_Alpha *th = (TS_Alpha*)ts->data;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  ierr = PetscOptionsHead("Alpha ODE solver options");CHKERRQ(ierr);
  {
    PetscBool flag, adapt = PETSC_FALSE;
    PetscReal radius = 1.0;
    ierr = PetscOptionsReal("-ts_alpha_radius","spectral radius","TSAlphaSetRadius",radius,&radius,&flag);CHKERRQ(ierr);
    if (flag) { ierr = TSAlphaSetRadius(ts,radius);CHKERRQ(ierr); }
    ierr = PetscOptionsReal("-ts_alpha_alpha_m","algoritmic parameter alpha_m","TSAlphaSetParams",th->Alpha_m,&th->Alpha_m,PETSC_NULL);CHKERRQ(ierr);
    ierr = PetscOptionsReal("-ts_alpha_alpha_f","algoritmic parameter alpha_f","TSAlphaSetParams",th->Alpha_f,&th->Alpha_f,PETSC_NULL);CHKERRQ(ierr);
    ierr = PetscOptionsReal("-ts_alpha_gamma","algoritmic parameter gamma","TSAlphaSetParams",th->Gamma,&th->Gamma,PETSC_NULL);CHKERRQ(ierr);
    ierr = TSAlphaSetParams(ts,th->Alpha_m,th->Alpha_f,th->Gamma);CHKERRQ(ierr);

    ierr = PetscOptionsBool("-ts_alpha_adapt","default time step adaptativity","TSAlphaSetAdapt",adapt,&adapt,&flag);CHKERRQ(ierr);
    if (flag) { ierr = TSAlphaSetAdapt(ts,adapt?TSAlphaAdaptDefault:PETSC_NULL,PETSC_NULL);CHKERRQ(ierr); }
    ierr = PetscOptionsReal("-ts_alpha_adapt_rtol","relative tolerance for dt adaptativity","",th->rtol,&th->rtol,PETSC_NULL);CHKERRQ(ierr);
    ierr = PetscOptionsReal("-ts_alpha_adapt_atol","absolute tolerance for dt adaptativity","",th->atol,&th->atol,PETSC_NULL);CHKERRQ(ierr);
    ierr = PetscOptionsReal("-ts_alpha_adapt_min","minimum dt scale","",th->scale_min,&th->scale_min,PETSC_NULL);CHKERRQ(ierr);
    ierr = PetscOptionsReal("-ts_alpha_adapt_max","maximum dt scale","",th->scale_max,&th->scale_max,PETSC_NULL);CHKERRQ(ierr);
    ierr = PetscOptionsReal("-ts_alpha_adapt_dt_min","minimum dt","",th->dt_min,&th->dt_min,PETSC_NULL);CHKERRQ(ierr);
    ierr = PetscOptionsReal("-ts_alpha_adapt_dt_max","maximum dt","",th->dt_max,&th->dt_max,PETSC_NULL);CHKERRQ(ierr);
    ierr = SNESSetFromOptions(ts->snes);CHKERRQ(ierr);
  }
  ierr = PetscOptionsTail();CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
Beispiel #2
0
PETSC_EXTERN void PETSC_STDCALL  tsalphasetradius_(TS ts,PetscReal *radius, int *__ierr ){
*__ierr = TSAlphaSetRadius(
	(TS)PetscToPointer((ts) ),*radius);
}
Beispiel #3
0
int main(int argc, char *argv[]) {
  PetscErrorCode  ierr;
  PetscMPIInt     rank;
  AppCtx          user;
  PetscInt        p=2,N=64,C=1;
  PetscInt ng = p+2; /* integration in each direction */
  PetscInt Nx,Ny;
  Vec            U; /* solution vector */
  Mat            J;
  TS             ts;
  PetscInt steps;
  PetscReal ftime;

  /* This code solve the dimensionless form of the isothermal
     Navier-Stokes-Korteweg equations as presented in:

     Gomez, Hughes, Nogueira, Calo
     Isogeometric analysis of the isothermal Navier-Stokes-Korteweg equations
     CMAME, 2010

     Equation/section numbers reflect this publication.
 */

  // Petsc Initialization rite of passage
  ierr = PetscInitialize(&argc,&argv,0,help);CHKERRQ(ierr);
  ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank);CHKERRQ(ierr);

  // Define simulation specific parameters
  user.L0 = 1.0; // length scale
  user.C1x = 0.75; user.C1y = 0.50; // bubble centers
  user.C2x = 0.25; user.C2y = 0.50;
  user.C3x = 0.40; user.C3y = 0.75;
  user.R1 = 0.10;  user.R2 = 0.15;  user.R3 = 0.08; // bubble radii

  user.alpha = 2.0; // (Eq. 41)
  user.theta = 0.85; // temperature parameter (just before section 5.1)

  // Set discretization options
  ierr = PetscOptionsBegin(PETSC_COMM_WORLD, "", "NavierStokesKorteweg Options", "IGA");CHKERRQ(ierr);
  ierr = PetscOptionsInt("-p", "polynomial order", __FILE__, p, &p, PETSC_NULL);CHKERRQ(ierr);
  ierr = PetscOptionsInt("-C", "global continuity order", __FILE__, C, &C, PETSC_NULL);CHKERRQ(ierr);
  ierr = PetscOptionsInt("-N", "number of elements (along one dimension)", __FILE__, N, &N, PETSC_NULL);CHKERRQ(ierr);
  ierr = PetscOptionsEnd();CHKERRQ(ierr);

  // Compute simulation parameters
  user.h = user.L0/N; // characteristic length scale of mesh (Eq. 43, simplified for uniform elements)
  user.Ca = user.h/user.L0; // capillarity number (Eq. 38)
  user.Re = user.alpha/user.Ca; // Reynolds number (Eq. 39)

  // Test C < p
  if(p <= C){
    SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE, "Discretization inconsistent: polynomial order must be greater than degree of continuity");
  }

  Nx=Ny=N;

  // Initialize B-spline space
  ierr = DMCreate(PETSC_COMM_WORLD,&user.iga);CHKERRQ(ierr);
  ierr = DMSetType(user.iga, DMIGA);CHKERRQ(ierr);
  ierr = DMIGAInitializeUniform2d(user.iga,PETSC_FALSE,2,3,
                                  p,Nx,C,0.0,1.0,PETSC_TRUE,ng,
                                  p,Ny,C,0.0,1.0,PETSC_TRUE,ng);CHKERRQ(ierr);

  ierr = DMCreateGlobalVector(user.iga,&U);CHKERRQ(ierr);
  ierr = FormInitialCondition(&user,U);CHKERRQ(ierr);
  ierr = DMIGASetFieldName(user.iga, 0, "density");CHKERRQ(ierr);
  ierr = DMIGASetFieldName(user.iga, 1, "velocity-u");CHKERRQ(ierr);
  ierr = DMIGASetFieldName(user.iga, 2, "velocity-v");CHKERRQ(ierr);

  ierr = DMCreateMatrix(user.iga, MATAIJ, &J);CHKERRQ(ierr);

  ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRQ(ierr);
  ierr = TSSetType(ts,TSALPHA);CHKERRQ(ierr);
  ierr = TSAlphaSetRadius(ts,0.5);CHKERRQ(ierr);
  ierr = TSSetDM(ts,user.iga);CHKERRQ(ierr);
  ierr = TSSetSolution(ts,U);CHKERRQ(ierr);
  ierr = TSSetProblemType(ts,TS_NONLINEAR);CHKERRQ(ierr);
  ierr = TSSetIFunction(ts,PETSC_NULL,FormResidual,&user);CHKERRQ(ierr);
  ierr = TSSetIJacobian(ts,J,J,FormTangent,&user);CHKERRQ(ierr);
  ierr = TSSetDuration(ts,1000000,1000.0);CHKERRQ(ierr);
  ierr = TSSetInitialTimeStep(ts,0.0,0.001);CHKERRQ(ierr);
  ierr = TSAlphaSetAdapt(ts,TSAlphaAdaptDefault,PETSC_NULL);CHKERRQ(ierr);
  ierr = TSMonitorSet(ts,OutputMonitor,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
  ierr = TSSetFromOptions(ts);CHKERRQ(ierr);

  ierr = TSSolve(ts,U,&ftime);CHKERRQ(ierr);
  ierr = TSGetTimeStepNumber(ts,&steps);CHKERRQ(ierr);

  // Cleanup
  ierr = TSDestroy(&ts);CHKERRQ(ierr);
  ierr = DMDestroy(&user.iga);CHKERRQ(ierr);
  ierr = PetscFinalize();

  return 0;
}