"Fossies" - the Fresh Open Source Software Archive

Member "petsc-3.12.3/src/ts/adapt/impls/cfl/adaptcfl.c" (2 Jul 2018, 2399 Bytes) of package /linux/misc/petsc-3.12.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "adaptcfl.c" see the Fossies "Dox" file reference documentation.

    1 #include <petsc/private/tsimpl.h> /*I "petscts.h" I*/
    2 
    3 static PetscErrorCode TSAdaptChoose_CFL(TSAdapt adapt,TS ts,PetscReal h,PetscInt *next_sc,PetscReal *next_h,PetscBool *accept,PetscReal *wlte,PetscReal *wltea,PetscReal *wlter)
    4 {
    5   PetscErrorCode  ierr;
    6   PetscReal       hcfl,cfltimestep,ccfl;
    7   PetscInt        ncandidates;
    8   const PetscReal *ccflarray;
    9 
   10   PetscFunctionBegin;
   11   ierr = TSGetCFLTime(ts,&cfltimestep);CHKERRQ(ierr);
   12   ierr = TSAdaptCandidatesGet(adapt,&ncandidates,NULL,NULL,&ccflarray,NULL);CHKERRQ(ierr);
   13   ccfl = (ncandidates > 0) ? ccflarray[0] : 1.0;
   14 
   15   if (!adapt->always_accept) SETERRQ(PetscObjectComm((PetscObject)adapt),PETSC_ERR_SUP,"Step rejection not implemented. The CFL implementation is incomplete/unusable");
   16 
   17   /* Determine whether the step is accepted of rejected */
   18   *accept = PETSC_TRUE;
   19   if (h > cfltimestep * ccfl) {
   20     if (adapt->always_accept) {
   21       ierr = PetscInfo3(adapt,"Step length %g with scheme of CFL coefficient %g did not satisfy user-provided CFL constraint %g, proceeding anyway\n",(double)h,(double)ccfl,(double)cfltimestep);CHKERRQ(ierr);
   22     } else {
   23       ierr = PetscInfo3(adapt,"Step length %g with scheme of CFL coefficient %g did not satisfy user-provided CFL constraint %g, step REJECTED\n",(double)h,(double)ccfl,(double)cfltimestep);CHKERRQ(ierr);
   24       *accept  = PETSC_FALSE;
   25     }
   26   }
   27 
   28   /* The optimal new step based purely on CFL constraint for this step. */
   29   hcfl = adapt->safety * cfltimestep * ccfl;
   30   if (hcfl < adapt->dt_min) {
   31     ierr = PetscInfo4(adapt,"Cannot satisfy CFL constraint %g (with %g safety) at minimum time step %g with method coefficient %g, proceding anyway\n",(double)cfltimestep,(double)adapt->safety,(double)adapt->dt_min,(double)ccfl);CHKERRQ(ierr);
   32   }
   33 
   34   *next_sc = 0;
   35   *next_h  = PetscClipInterval(hcfl,adapt->dt_min,adapt->dt_max);
   36   *wlte    = -1;   /* Weighted local truncation error was not evaluated */
   37   *wltea   = -1;   /* Weighted absolute local truncation error was not evaluated */
   38   *wlter   = -1;   /* Weighted relative local truncation error was not evaluated */
   39   PetscFunctionReturn(0);
   40 }
   41 
   42 /*MC
   43    TSADAPTCFL - CFL adaptive controller for time stepping
   44 
   45    Level: intermediate
   46 
   47 .seealso: TS, TSAdapt, TSGetAdapt()
   48 M*/
   49 PETSC_EXTERN PetscErrorCode TSAdaptCreate_CFL(TSAdapt adapt)
   50 {
   51   PetscFunctionBegin;
   52   adapt->ops->choose = TSAdaptChoose_CFL;
   53   PetscFunctionReturn(0);
   54 }