BISICLES AMR ice sheet model  0.9
JFNKSolver.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _JFNKSOLVER_H_
12 #define _JFNKSOLVER_H_
13 
14 
15 #include "IceVelocitySolver.H"
16 #include "NonlinearViscousTensor.H"
17 #include "AMRMultiGrid.H"
18 #include "MultilevelIceVelOp.H"
19 #include "ViscousTensorOp.H"
20 #ifdef CH_USE_PETSC
21 #include "PetscAMRSolver.H"
22 #endif
23 
24 #include "NamespaceHeader.H"
25 
26 
28 
29 
30 class JFNKSolver;
31 
43 class LinearizedVTOp : public LinearOp<Vector<LevelData<FArrayBox>*> >
44 {
45  friend class JFNKSolver;
46 #ifdef CH_USE_PETSC
47  friend class PetscAMRSolver;
48 #endif
49 
50  NonlinearViscousTensor* m_u; // current state
51  NonlinearViscousTensor* m_uPerturbed; // perturbed state
52 
53  Vector<LevelData<FArrayBox>*> m_fu; // current value of f(u)
54  Vector<LevelData<FArrayBox>*> m_uplushv; // current value of u + v
55 
56  //constant perturbation coefficient h
57  Real m_h;
58  //parameters that appear in the adaptive calculation of h
59  Real m_err, m_umin; bool m_hAdaptive;
60  //compute a perturbation coefficient h given a direction a_v
61  Real finiteh(const Vector<LevelData<FArrayBox>*>& a_v);
62 
63 
64  // m_mlOp provides the multigrid precondioner
65  // and is used to evaluate f(u)
66  MultilevelIceVelOp m_mlOp;
67 
68  //m_perturbedMlOp is used to evaluate f(u + h*v)
69  MultilevelIceVelOp m_perturbedMlOp;
70 
72  static int m_bottom_solver_type;
73 
75  static int m_MG_solver_depth;
76 
77  Vector<DisjointBoxLayout> m_grids;
78  Vector<int> m_refRatio;
79  Vector<ProblemDomain> m_domains;
80  Vector<RealVect> m_dxs;
81  int m_lBase;
82 
83  LinearizationMode m_mode;
84 
85  //options related to writing out the residual
86  bool m_writeResiduals;
87  static int m_residualID;
88 
89  void writeResidual
90  (const Vector<LevelData<FArrayBox> *>& a_u,
91  const Vector<LevelData<FArrayBox> *>& a_residual);
92 
93 public:
94 
95  NonlinearViscousTensor& current() const {return *m_u;}
96 
97  virtual ~LinearizedVTOp()
98  {
99 
100  if (m_uPerturbed != NULL)
101  {
102  delete m_uPerturbed;
103  m_uPerturbed = NULL;
104  }
105 
106  for (int lev = 0; lev < m_fu.size(); ++lev)
107  {
108  if (m_fu[lev] != NULL)
109  delete m_fu[lev];
110  }
111  for (int lev = 0; lev < m_uplushv.size(); ++lev)
112  {
113  if (m_uplushv[lev] != NULL)
114  delete m_uplushv[lev];
115  }
116  }
117  LinearizedVTOp(NonlinearViscousTensor* a_currentState ,
118  Vector<LevelData<FArrayBox>*>& a_u,
119  Real a_h, Real m_err, Real m_umin, bool m_hAdaptive,
120  Vector<DisjointBoxLayout>& a_grids,
121  Vector<int>& a_refRatio,
122  Vector<ProblemDomain>& a_domains,
123  Vector<RealVect>& a_dxs,
124  int a_lBase,
125  int a_numMGSmooth,
126  int a_numMGIter,
127  LinearizationMode a_mode
128  );
129 
130  // set the current solution u (so that J * v \approx (f(u+hv)-f(u))/h
131  virtual void setU(Vector<LevelData<FArrayBox>*>& a_u);
132 
133  // a_lhs = (f(u+ h * (a_v) ) -f(u))/ h (in JFNK mode)
134  // or L[u](a_v) (in Picard mode)
135  virtual void applyOp(Vector<LevelData<FArrayBox>*>& a_lhs,
136  const Vector<LevelData<FArrayBox>*>& a_v,
137  bool a_homogeneous = false);
138 
139  // a_lhs = (f(u+ h * (a_v) )-f(u))/h - a_rhs (in JFNK mode)
140  // or L[u](a_v) (in Picard mode)
141  virtual void residual(Vector<LevelData<FArrayBox>*>& a_lhs,
142  const Vector<LevelData<FArrayBox>*>& a_v,
143  const Vector<LevelData<FArrayBox>*>& a_rhs,
144  bool a_homogeneous = false);
145 
146  virtual void outerResidual(Vector<LevelData<FArrayBox>*>& a_lhs,
147  const Vector<LevelData<FArrayBox>*>& a_u,
148  const Vector<LevelData<FArrayBox>*>& a_rhs,
149  bool a_homogeneous = false);
150 
151 
152  virtual void outerLHS(Vector<LevelData<FArrayBox>*>& a_lhs,
153  const Vector<LevelData<FArrayBox>*>& a_u,
154  bool a_homogeneous = false)
155  {
156 
157  m_mlOp.applyOp(a_lhs, a_u, a_homogeneous);
158  }
159 
160 
161 
162  //the rest of LinearOp can be palmed off on m_mlOp.
163  virtual void preCond(Vector<LevelData<FArrayBox>*>& a_cor,
164  const Vector<LevelData<FArrayBox>*>& a_residual);
165 
166 
167  virtual void create(Vector<LevelData<FArrayBox>*>& a_lhs,
168  const Vector<LevelData<FArrayBox>*>& a_rhs)
169  {
170  m_mlOp.create(a_lhs , a_rhs);
171  }
172 
173  virtual void clear(Vector<LevelData<FArrayBox>*>& a_lhs)
174  {
175  m_mlOp.clear(a_lhs);
176  }
177 
178  // helpful function which clears memory allocated by create
179  virtual void clearStorage(Vector<LevelData<FArrayBox> * >& a_lhs)
180  {
181  for (int lev=0; lev<a_lhs.size(); lev++)
182  {
183  if (a_lhs[lev] != NULL)
184  {
185  delete a_lhs[lev];
186  a_lhs[lev] = NULL;
187  }
188  }
189  }
190 
191  virtual void assign(Vector<LevelData<FArrayBox>*>& a_lhs,
192  const Vector<LevelData<FArrayBox>*>& a_rhs)
193  {
194  m_mlOp.assign(a_lhs, a_rhs);
195  }
196 
197 
198  virtual Real dotProduct(const Vector<LevelData<FArrayBox>*>& a_1,
199  const Vector<LevelData<FArrayBox>*>& a_2)
200  {
201  return m_mlOp.dotProduct(a_1,a_2);
202  }
203 
204  virtual void incr(Vector<LevelData<FArrayBox>*>& a_lhs,
205  const Vector<LevelData<FArrayBox>*>& a_x,
206  Real a_scale)
207  {
208  m_mlOp.incr(a_lhs, a_x, a_scale);
209  }
210 
211 
212  virtual void axby(Vector<LevelData<FArrayBox>*>& a_lhs,
213  const Vector<LevelData<FArrayBox>*>& a_x,
214  const Vector<LevelData<FArrayBox>*>& a_y,
215  Real a_a,
216  Real a_b)
217  {
218  m_mlOp.axby(a_lhs, a_x, a_y, a_a, a_b);
219  }
220 
221  virtual void scale(Vector<LevelData<FArrayBox>*>& a_lhs,
222  const Real& a_scale)
223  {
224  m_mlOp.scale(a_lhs , a_scale);
225  }
226 
227  virtual Real norm(const Vector<LevelData<FArrayBox>*>& a_rhs,
228  int a_ord)
229  {
230  return m_mlOp.norm(a_rhs, a_ord);
231  }
232 
233  virtual void setToZero(Vector<LevelData<FArrayBox>*>& a_lhs)
234  {
235  m_mlOp.setToZero(a_lhs);
236  }
237 
238 
239 };
240 
241 
243 
275 {
276 
277 public:
279  {
280 
281  public:
282 
283  enum LinearSolverType {Relax,BiCGStab,GMRES,CG,petsc};
284 
285  ~Configuration();
286 
287  Configuration();
288 
289  void parse(const char* a_prefix = "JFNKSolver");
290 
296  Real m_absTol;
298  Real m_relTol;
332  Real m_h;
334  Real m_err;
336  Real m_umin;
342 
362  Real m_muMin;
364  Real m_muMax;
365  //dont solve, just evaluate the residual
367  // scale factor, f: solve for f*u internally - still return u
368  Real m_scale;
369  // artificial drag that applies everywhere
370  /* if used, need to ensure that
371  (m_artificial_drag * |u|)^m_artifical_drag_power << rho * g * h * grad(s) ~ 10^4
372  when |u| ~ 10^4
373  */
374  Real m_artificialDragCoef, m_artificialDragPower;
375 
376  };
377 
378 private:
379 
380  Configuration m_config;
381 
382 public:
384  void parseConfiguration(const char* a_prefix)
385  {
386  m_config.parse(a_prefix);
387  }
388 
391  {
392  return m_config;
393  }
394 
397  {
398  return m_config;
399  }
400 
401 private:
402 
403  Vector<ProblemDomain> m_domains;
404 
405  Vector<DisjointBoxLayout> m_grids;
406 
407  Vector<RealVect> m_dxs;
408 
409  Vector<int> m_refRatios;
410 
411  ConstitutiveRelation* m_constRelPtr;
412 
413  BasalFrictionRelation* m_basalFrictionRelPtr;
414 
415  IceThicknessIBC* m_bcPtr;
416 
417 
418 
419 #ifdef CH_USE_PETSC
420  // petsc solvers are more expensive to set up, so keep one around
421  PetscAMRSolver *m_petscSolver;
422 #endif
423 
424  LinearSolver<Vector<LevelData<FArrayBox>* > >* newLinearSolver(LinearizedVTOp& a_op,
425  LinearizationMode a_mode);
426 
429  Real lineSearch(Vector<LevelData<FArrayBox>* >& a_u,
430  Vector<LevelData<FArrayBox>* >& a_residual,
431  const Vector<LevelData<FArrayBox>* >& a_rhs,
432  const Vector<LevelData<FArrayBox>* >& a_du,
433  LinearizedVTOp& a_op,
434  NonlinearViscousTensor& a_nvt,
435  Real a_minW,
436  bool a_resetOnFail);
437 
439  void linearSolve(LinearizedVTOp& a_op,
440  Vector<LevelData<FArrayBox>* >& a_u,
441  const Vector<LevelData<FArrayBox>* >& a_rhs,
442  LinearizationMode a_mode);
443 
444 
445  void eliminateFastIce(Vector<LevelData<FArrayBox>* >& a_velocity,
446  Vector<LevelData<FArrayBox>* >& a_calvedIce,
447  Vector<LevelData<FArrayBox>* >& a_addedIce,
448  Vector<LevelData<FArrayBox>* >& a_removedIce,
449  Vector<LevelData<FArrayBox>* >& a_rhs,
450  Vector<RefCountedPtr<LevelSigmaCS > >& a_coordSys,
451  IceNonlinearViscousTensor& a_current);
452 
453 
454  Real m_convergenceMetric;
455 
456 
457 public:
458  virtual ~JFNKSolver() {
459  #ifdef CH_USE_PETSC
460  if (m_petscSolver) delete m_petscSolver;
461 #endif
462  }
463 
464  JFNKSolver()
465 #ifdef CH_USE_PETSC
466  : m_petscSolver(NULL)
467 #endif
468  {
469 
470  }
471 
472 
473  virtual void define(const ProblemDomain& a_coarseDomain,
474  ConstitutiveRelation* a_constRel,
475  BasalFrictionRelation* a_basalFrictionRel,
476  const Vector<DisjointBoxLayout>& a_vectGrids,
477  const Vector<int>& a_vectRefRatio,
478  const RealVect& a_dxCrse,
479  IceThicknessIBC* a_bc,
480  int a_numLevels);
481 
482 
483  //IceVelocitySolver non-linear solve
484  virtual int solve(Vector<LevelData<FArrayBox>* >& a_horizontalVel,
485  Vector<LevelData<FArrayBox>* >& a_calvedIce,
486  Vector<LevelData<FArrayBox>* >& a_addedIce,
487  Vector<LevelData<FArrayBox>* >& a_removedIce,
488  Real& a_initialResidualNorm, Real& a_finalResidualNorm,
489  const Real a_convergenceMetric,
490  const Vector<LevelData<FArrayBox>* >& a_rhs,
491  const Vector<LevelData<FArrayBox>* >& a_C,
492  const Vector<LevelData<FArrayBox>* >& a_C0,
493  const Vector<LevelData<FArrayBox>* >& a_A,
494  const Vector<LevelData<FArrayBox>* >& a_muCoef,
495  Vector<RefCountedPtr<LevelSigmaCS > >& a_coordSys,
496  Real a_time,
497  int a_lbase, int a_maxLevel) ;
498 
500 
509  virtual int solve(Vector<LevelData<FArrayBox>* >& a_horizontalVel,
510  Vector<LevelData<FArrayBox>* >& a_calvedIce,
511  Vector<LevelData<FArrayBox>* >& a_addedIce,
512  Vector<LevelData<FArrayBox>* >& a_removedIce,
513  Real& a_initialResidualNorm, Real& a_finalResidualNorm,
514  const Real a_convergenceMetric,
515  const bool a_linear,
516  const Vector<LevelData<FArrayBox>* >& a_rhs,
517  const Vector<LevelData<FArrayBox>* >& a_C,
518  const Vector<LevelData<FArrayBox>* >& a_C0,
519  const Vector<LevelData<FArrayBox>* >& a_A,
520  const Vector<LevelData<FArrayBox>* >& a_muCoef,
521  Vector<RefCountedPtr<LevelSigmaCS > >& a_coordSys,
522  Real a_time,
523  int a_lbase, int a_maxLevel);
524 
525 
526 private:
527 
528 
529 
530  void imposeMaxAbs(Vector<LevelData<FArrayBox>*>& a_u,
531  Real a_limit);
532 
533 };
534 
535 
536 
537 
538 
539 
540 
541 #include "NamespaceFooter.H"
542 #endif
Real m_err
parameters that appears in the adaptive calculation of h
Definition: JFNKSolver.H:334
Real m_relTol
relative tolerance for convergence test;
Definition: JFNKSolver.H:298
virtual void scale(Vector< LevelData< FArrayBox > *> &a_lhs, const Real &a_scale)
Definition: JFNKSolver.H:221
Real m_eliminateRemoteIceTol
how thin is thin ice?
Definition: JFNKSolver.H:358
Implement NonlinearViscousTensor for typical (velocity-depenendent) ice rheology. ...
Definition: NonlinearViscousTensor.H:105
int m_maxRelaxIter
maximum number of Relax iterations
Definition: JFNKSolver.H:314
virtual ~LinearizedVTOp()
Definition: JFNKSolver.H:97
Real m_vtopRelaxTol
relax tolerance for viscous tensor op
Definition: JFNKSolver.H:324
Real m_scale
Definition: JFNKSolver.H:368
bool m_writeResiduals
write out residual data frequently: useful for working out why solves fail
Definition: JFNKSolver.H:350
Real m_RelaxRelTol
Relax solver relative tolerance.
Definition: JFNKSolver.H:312
int m_vtopRelaxMinIter
minimum number of smnooths in viscous tensor op mg relax
Definition: JFNKSolver.H:326
virtual void setU(Vector< LevelData< FArrayBox > *> &a_u)
Definition: JFNKSolver.cpp:146
virtual Real norm(const Vector< LevelData< FArrayBox > *> &a_rhs, int a_ord)
Definition: JFNKSolver.H:227
Abstract class to manage the nonlinear solve for the ice-sheet momentum.
Definition: IceVelocitySolver.H:32
Real m_artificialDragPower
Definition: JFNKSolver.H:374
virtual void clearStorage(Vector< LevelData< FArrayBox > * > &a_lhs)
Definition: JFNKSolver.H:179
Abstract class around the englacial constitutive relations for ice.
Definition: ConstitutiveRelation.H:34
virtual ~JFNKSolver()
Definition: JFNKSolver.H:458
Real m_muMax
largest effective viscosity in ice-covered regions
Definition: JFNKSolver.H:364
bool m_hAdaptive
Use adaptive calculation of h?
Definition: JFNKSolver.H:338
Jacobian-Free Newton Krylov (JFNK) solver for the nonlinear ice-sheet/shelf momentum equations...
Definition: JFNKSolver.H:274
int m_maxGMRESIter
maximum number of GMRES iterations
Definition: JFNKSolver.H:310
LinearizedVTOp(NonlinearViscousTensor *a_currentState, Vector< LevelData< FArrayBox > *> &a_u, Real a_h, Real m_err, Real m_umin, bool m_hAdaptive, Vector< DisjointBoxLayout > &a_grids, Vector< int > &a_refRatio, Vector< ProblemDomain > &a_domains, Vector< RealVect > &a_dxs, int a_lBase, int a_numMGSmooth, int a_numMGIter, LinearizationMode a_mode)
Definition: JFNKSolver.cpp:54
int m_normType
type of norm to test convergence against
Definition: JFNKSolver.H:318
virtual void applyOp(Vector< LevelData< FArrayBox > *> &a_lhs, const Vector< LevelData< FArrayBox > *> &a_v, bool a_homogeneous=false)
Definition: JFNKSolver.cpp:184
Real m_BiCGStabRelTol
BiCGstab solver relative tolerance.
Definition: JFNKSolver.H:300
friend class JFNKSolver
Definition: JFNKSolver.H:45
Real m_vtopSafety
safety number for viscous tensor op
Definition: JFNKSolver.H:322
Physical/domain initial and boundary conditions for ice-sheet problems.
Definition: IceThicknessIBC.H:84
virtual void create(Vector< LevelData< FArrayBox > *> &a_lhs, const Vector< LevelData< FArrayBox > *> &a_rhs)
Definition: JFNKSolver.H:167
const Configuration & configuration()
allow read access to configuration entries
Definition: JFNKSolver.H:390
Real m_absTol
absolute tolerance for convergence test;
Definition: JFNKSolver.H:296
virtual void residual(Vector< LevelData< FArrayBox > *> &a_lhs, const Vector< LevelData< FArrayBox > *> &a_v, const Vector< LevelData< FArrayBox > *> &a_rhs, bool a_homogeneous=false)
Definition: JFNKSolver.cpp:127
Definition: JFNKSolver.H:43
void parse(const char *a_prefix="JFNKSolver")
Definition: JFNKSolver.cpp:358
Definition: JFNKSolver.H:27
void parseConfiguration(const char *a_prefix)
allows the usual configuration ("JFNKSolver.*") to be over-ridden
Definition: JFNKSolver.H:384
virtual void assign(Vector< LevelData< FArrayBox > *> &a_lhs, const Vector< LevelData< FArrayBox > *> &a_rhs)
Definition: JFNKSolver.H:191
Real m_muMin
smallest effective viscosity in ice-covered regions
Definition: JFNKSolver.H:362
virtual void axby(Vector< LevelData< FArrayBox > *> &a_lhs, const Vector< LevelData< FArrayBox > *> &a_x, const Vector< LevelData< FArrayBox > *> &a_y, Real a_a, Real a_b)
Definition: JFNKSolver.H:212
int m_numMGSmooth
(maximum) number of smooths in mg relax
Definition: JFNKSolver.H:328
NonlinearViscousTensor & current() const
Definition: JFNKSolver.H:95
bool m_eliminateFastIceEdgeOnly
throw away fast ice only ice/no ice boundaries
Definition: JFNKSolver.H:356
Definition: JFNKSolver.H:283
Real m_switchRate
rate at which to switch from Picard to JFNK mode
Definition: JFNKSolver.H:340
virtual Real dotProduct(const Vector< LevelData< FArrayBox > *> &a_1, const Vector< LevelData< FArrayBox > *> &a_2)
Definition: JFNKSolver.H:198
Definition: PetscAMRSolver.H:26
int m_verbosity
verbosity
Definition: JFNKSolver.H:320
Definition: JFNKSolver.H:27
Real m_eliminateFastIceSpeed
how fast is fast?
Definition: JFNKSolver.H:354
virtual void outerResidual(Vector< LevelData< FArrayBox > *> &a_lhs, const Vector< LevelData< FArrayBox > *> &a_u, const Vector< LevelData< FArrayBox > *> &a_rhs, bool a_homogeneous=false)
Definition: JFNKSolver.cpp:111
int eliminateFastIce(Vector< RefCountedPtr< LevelSigmaCS > > &a_coordSys, Vector< LevelData< FArrayBox > * > &a_vel, Vector< LevelData< FArrayBox > * > &a_calvedIce, Vector< LevelData< FArrayBox > * > &a_addedIce, Vector< LevelData< FArrayBox > * > &a_removedIce, const Vector< DisjointBoxLayout > &a_grids, const Vector< ProblemDomain > &a_domain, const Vector< int > &a_refRatio, Real a_crseDx, int a_finestLevel, int a_maxIter, Real a_thinIceTol, Real a_fastIceTol, bool a_edgeOnly, int a_verbosity=0)
Identify regions of fast ice and eliminate them. return the total number of cells eliminated...
Definition: IceUtility.cpp:776
LinearizationMode
Definition: JFNKSolver.H:27
Definition: JFNKSolver.H:27
Virtual base class for basal friction relations.
Definition: BasalFrictionRelation.H:27
bool m_eliminateFastIce
throw away fast ice at the end of each iteration?
Definition: JFNKSolver.H:352
Real m_eliminateRemoteIceMaxIter
limit the number of iterations in eliminate remote ice
Definition: JFNKSolver.H:360
virtual void setToZero(Vector< LevelData< FArrayBox > *> &a_lhs)
Definition: JFNKSolver.H:233
Definition: NonlinearViscousTensor.H:33
Real m_GMRESRelTol
GMRES solver relative tolerance.
Definition: JFNKSolver.H:308
Real m_RelaxHang
hang parameter for RelaxSolver;
Definition: JFNKSolver.H:316
int m_maxIter
maximum number of Newton steps;
Definition: JFNKSolver.H:294
LinearSolverType m_linearSolverType
type of linear solver
Definition: JFNKSolver.H:292
virtual void outerLHS(Vector< LevelData< FArrayBox > *> &a_lhs, const Vector< LevelData< FArrayBox > *> &a_u, bool a_homogeneous=false)
Definition: JFNKSolver.H:152
Real m_h
size of finite differenc
Definition: JFNKSolver.H:332
bool m_residualOnly
Definition: JFNKSolver.H:366
Definition: JFNKSolver.H:278
Real m_minStepFactor
smallest acceptable factor to try when reducing the newton step length
Definition: JFNKSolver.H:348
Real m_CGRelTol
CG solver relative tolerance.
Definition: JFNKSolver.H:304
Definition: MultilevelIceVelOp.H:38
virtual void clear(Vector< LevelData< FArrayBox > *> &a_lhs)
Definition: JFNKSolver.H:173
Configuration & get_evil_configuration()
allow write access to configuration entries
Definition: JFNKSolver.H:396
virtual void incr(Vector< LevelData< FArrayBox > *> &a_lhs, const Vector< LevelData< FArrayBox > *> &a_x, Real a_scale)
Definition: JFNKSolver.H:204
int m_numMGIter
number of MG v-cycles per BiCGStab iteration
Definition: JFNKSolver.H:330
LinearSolverType
Definition: JFNKSolver.H:283
virtual void preCond(Vector< LevelData< FArrayBox > *> &a_cor, const Vector< LevelData< FArrayBox > *> &a_residual)
Definition: JFNKSolver.cpp:283
int m_maxCGIter
maximum number of CG iterations
Definition: JFNKSolver.H:306
int m_maxBiCGStabIter
maximum number of BiCGStab iterations
Definition: JFNKSolver.H:302
int m_minPicardIter
minumum number of Picard Iterations before switching to JFNK
Definition: JFNKSolver.H:346
Real m_umin
parameter that appears in the adaptive calculation of h
Definition: JFNKSolver.H:336