DUNE PDELab (2.7)

pdelab.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3#ifndef DUNE_PDELAB_BOILERPLATE_PDELAB_HH
4#define DUNE_PDELAB_BOILERPLATE_PDELAB_HH
5
16// first of all we include a lot of dune grids and pdelab files
17#include <array>
18#include <iostream>
19#include <memory>
20
21#include <dune/common/parallel/mpihelper.hh> // include mpi helper class
27
28#include <dune/geometry/type.hh>
30
31#include <dune/grid/onedgrid.hh>
33#include <dune/grid/yaspgrid.hh>
34#if HAVE_UG
35#include <dune/grid/uggrid.hh>
36#endif
37#if HAVE_ALBERTA
38#include<dune/grid/albertagrid.hh>
39#include <dune/grid/albertagrid/dgfparser.hh>
40#endif
41#if HAVE_UG
42#include<dune/grid/uggrid.hh>
43#endif
44#if HAVE_DUNE_ALUGRID
45#include<dune/alugrid/grid.hh>
46#include <dune/alugrid/dgf.hh>
47#endif
49#include <dune/grid/io/file/gmshreader.hh>
50
51#include <dune/istl/bvector.hh>
53#include <dune/istl/solvers.hh>
54#include <dune/istl/solvercategory.hh>
56#include <dune/istl/io.hh>
57
59#include <dune/pdelab/common/function.hh>
60#include <dune/pdelab/common/functionutilities.hh>
61#include <dune/pdelab/common/vtkexport.hh>
62#include <dune/pdelab/backend/istl.hh>
63#include <dune/pdelab/constraints/conforming.hh>
64#include <dune/pdelab/constraints/hangingnode.hh>
65#include <dune/pdelab/constraints/p0.hh>
66#include <dune/pdelab/constraints/p0ghost.hh>
67#include <dune/pdelab/constraints/common/constraints.hh>
68#include <dune/pdelab/gridfunctionspace/gridfunctionspace.hh>
69#include <dune/pdelab/gridfunctionspace/gridfunctionspaceutilities.hh>
70#include <dune/pdelab/gridfunctionspace/interpolate.hh>
71#include <dune/pdelab/gridoperator/gridoperator.hh>
72#include <dune/pdelab/gridoperator/onestep.hh>
73#include <dune/pdelab/stationary/linearproblem.hh>
74#include <dune/pdelab/finiteelementmap/pkfem.hh>
75#include <dune/pdelab/finiteelementmap/p0fem.hh>
76#include <dune/pdelab/finiteelementmap/opbfem.hh>
77#include <dune/pdelab/finiteelementmap/qkfem.hh>
78#include <dune/pdelab/finiteelementmap/qkdg.hh>
79#include <dune/pdelab/adaptivity/adaptivity.hh>
80#include <dune/pdelab/instationary/onestep.hh>
81#include <dune/pdelab/common/instationaryfilenamehelper.hh>
82#include <dune/pdelab/newton/newton.hh>
83
84namespace Dune {
85 namespace PDELab {
86
87 // make grids
88 template<typename T>
89 class StructuredGrid
90 {
91 public:
92 // export types
93 typedef T Grid;
94 typedef typename T::ctype ctype;
95 static const int dim = T::dimension;
96 static const int dimworld = T::dimensionworld;
97
98 // constructors
99 StructuredGrid (Dune::GeometryType::BasicType meshtype, unsigned int cells)
100 {
101 FieldVector<ctype,dimworld> lowerLeft(0.0);
102 FieldVector<ctype,dimworld> upperRight(1.0);
103 std::array<unsigned int,dim> elements; elements.fill(cells);
104
105 StructuredGridFactory<T> factory;
106
107 if (meshtype==Dune::GeometryType::cube)
108 gridp = factory.createCubeGrid(lowerLeft,upperRight,elements);
109 else if (meshtype==Dune::GeometryType::simplex)
110 gridp = factory.createSimplexGrid(lowerLeft,upperRight,elements);
111 else
112 {
113 DUNE_THROW(GridError, className<StructuredGrid>()
114 << "::StructuredGrid(): grid type must be simplex or cube ");
115 }
116 }
117
118
119 StructuredGrid (Dune::GeometryType::BasicType meshtype,
120 std::array<double,dimworld> lower_left, std::array<double,dimworld> upper_right,
121 std::array<unsigned int,dim> cells)
122 {
123 FieldVector<ctype,dimworld> lowerLeft;
124 FieldVector<ctype,dimworld> upperRight;
125 std::array<unsigned int,dim> elements;
126
127 // copy data to correct types for StructuredGridFactory
128 for (size_t i=0; i<dimworld; i++)
129 {
130 lowerLeft[i] = lower_left[i];
131 upperRight[i] = upper_right[i];
132 }
133 for (size_t i=0; i<dim; i++)
134 {
135 elements[i] = cells[i];
136 }
137
138 StructuredGridFactory<T> factory;
139
140 if (meshtype==Dune::GeometryType::cube)
141 gridp = factory.createCubeGrid(lowerLeft,upperRight,elements);
142 else if (meshtype==Dune::GeometryType::simplex)
143 gridp = factory.createSimplexGrid(lowerLeft,upperRight,elements);
144 else
145 {
146 DUNE_THROW(GridError, className<StructuredGrid>()
147 << "::StructuredGrid(): grid type must be simplex or cube ");
148 }
149 }
150
151 // return shared pointer
152 std::shared_ptr<T> getSharedPtr ()
153 {
154 return gridp;
155 }
156
157 // return grid reference
158 T& getGrid ()
159 {
160 return *gridp;
161 }
162
163 // return grid reference const version
164 const T& getGrid () const
165 {
166 return *gridp;
167 }
168
169 T& operator*()
170 {
171 return *gridp;
172 }
173
174 T* operator->()
175 {
176 return gridp.operator->();
177 }
178
179 const T& operator*() const
180 {
181 return *gridp;
182 }
183
184 const T* operator->() const
185 {
186 return gridp.operator->();
187 }
188
189
190 private:
191 std::shared_ptr<T> gridp; // hold a shared pointer to a grid
192 };
193
194 // specialization for yaspgrid; treats paralle case right
195 template<int dim>
196 class StructuredGrid<YaspGrid<dim> >
197 {
198 public:
199
200 // export types
201 typedef YaspGrid<dim> Grid;
202 typedef typename Grid::ctype ctype;
203 static const int dimworld = Grid::dimensionworld;
204
205 // simple constructor for the unit cube
206 StructuredGrid (Dune::GeometryType::BasicType meshtype, unsigned int cells, int overlap=1)
207 {
208 // check element type
209 if (meshtype!=Dune::GeometryType::cube)
210 std::cout << "StructuredGrid(): element type " << meshtype << " is ignored" << std::endl;
211
212 // copy data to correct types for YaspGrid
214 std::array<int,dimworld> N(Dune::filledArray<dimworld, int>(cells));
215 std::bitset<dimworld> B(false);
216
217 // instantiate the grid
218 gridp = std::shared_ptr<Grid>(new Grid(L,N,B,overlap,Dune::MPIHelper::getCollectiveCommunication()));
219 }
220
221 // constructor with sizes given
222 StructuredGrid (Dune::GeometryType::BasicType meshtype,
223 std::array<double,dimworld> lower_left, std::array<double,dimworld> upper_right,
224 std::array<unsigned int,dim> cells, int overlap=1)
225 {
226 // check that lower right corner is the origin
227 for(int d = 0; d < dimworld; ++d)
228 if(std::abs(lower_left[d]) > std::abs(upper_right[d])*1e-10)
229 DUNE_THROW(GridError, className<StructuredGrid>()
230 << "::createCubeGrid(): The lower coordinates "
231 "must be at the origin for YaspGrid.");
232
233 // check element type
234 if (meshtype!=Dune::GeometryType::cube)
235 std::cout << "StructuredGrid(): element type " << meshtype << " is ignored" << std::endl;
236
237 // copy data to correct types for YaspGrid
239 std::array<int,dimworld> N;
240 std::bitset<dimworld> B(false);
241 for (size_t i=0; i<dimworld; i++)
242 {
243 L[i] = upper_right[i];
244 N[i] = cells[i];
245 }
246
247 // instantiate the grid
248 gridp = std::shared_ptr<Grid>(new Grid(L,N,B,overlap,Dune::MPIHelper::getCollectiveCommunication()));
249 }
250
251 // constructor with periodicity argument
252 StructuredGrid (Dune::GeometryType::BasicType meshtype,
253 std::array<double,dimworld> lower_left, std::array<double,dimworld> upper_right,
254 std::array<unsigned int,dim> cells, std::array<bool,dim> periodic, int overlap=1)
255 {
256 // check that lower right corner is the origin
257 for(int d = 0; d < dimworld; ++d)
258 if(std::abs(lower_left[d]) > std::abs(upper_right[d])*1e-10)
259 DUNE_THROW(GridError, className<StructuredGrid>()
260 << "::createCubeGrid(): The lower coordinates "
261 "must be at the origin for YaspGrid.");
262
263 // check element type
264 if (meshtype!=Dune::GeometryType::cube)
265 std::cout << "StructuredGrid(): element type " << meshtype << " is ignored" << std::endl;
266
267 // copy data to correct types for YaspGrid
269 std::array<int,dimworld> N;
270 std::bitset<dimworld> B(false);
271 for (size_t i=0; i<dimworld; i++)
272 {
273 L[i] = upper_right[i];
274 N[i] = cells[i];
275 B[i] = periodic[i];
276 }
277
278 // instantiate the grid
279 gridp = std::shared_ptr<Grid>(new Grid(L,N,B,overlap,Dune::MPIHelper::getCollectiveCommunication()));
280 }
281
282 // return shared pointer
283 std::shared_ptr<Grid> getSharedPtr ()
284 {
285 return gridp;
286 }
287
288 // return grid reference
289 Grid& getGrid ()
290 {
291 return *gridp;
292 }
293
294 // return grid reference const version
295 const Grid& getGrid () const
296 {
297 return *gridp;
298 }
299
300 Grid& operator*()
301 {
302 return *gridp;
303 }
304
305 Grid* operator->()
306 {
307 return gridp.operator->();
308 }
309
310 const Grid& operator*() const
311 {
312 return *gridp;
313 }
314
315 const Grid* operator->() const
316 {
317 return gridp.operator->();
318 }
319
320 private:
321 std::shared_ptr<Grid> gridp; // hold a shared pointer to a grid
322 };
323
324 // unstructured grid read from gmsh file
325 template<typename T>
326 class UnstructuredGrid
327 {
328 public:
329 // export types
330 typedef T Grid;
331 typedef typename T::ctype ctype;
332 static const int dim = T::dimension;
333 static const int dimworld = T::dimensionworld;
334
335 // constructors
336 UnstructuredGrid (std::string filename, bool verbose = true, bool insert_boundary_segments=true)
337 {
338 Dune::GridFactory<T> factory;
339 Dune::GmshReader<T>::read(factory,filename,verbose,insert_boundary_segments);
340 gridp = std::shared_ptr<T>(factory.createGrid());
341 }
342
343 // return shared pointer
344 std::shared_ptr<T> getSharedPtr ()
345 {
346 return gridp;
347 }
348
349 // return grid reference
350 T& getGrid ()
351 {
352 return *gridp;
353 }
354
355 // return grid reference const version
356 const T& getGrid () const
357 {
358 return *gridp;
359 }
360
361 T& operator*()
362 {
363 return *gridp;
364 }
365
366 T* operator->()
367 {
368 return gridp.operator->();
369 }
370
371 const T& operator*() const
372 {
373 return *gridp;
374 }
375
376 const T* operator->() const
377 {
378 return gridp.operator->();
379 }
380
381 private:
382 std::shared_ptr<T> gridp; // hold a shared pointer to a grid
383 };
384
385
386 //============================================================================
387 // Continuous Lagrange Finite Element Space
388 //============================================================================
389
390 // finite element map base template
391 template<typename GV, typename C, typename R, unsigned int degree, unsigned int dim, Dune::GeometryType::BasicType gt>
392 class CGFEMBase
393 {};
394
395 template<typename GV, typename C, typename R, unsigned int degree, unsigned int dim>
396 class CGFEMBase<GV,C,R,degree,dim,Dune::GeometryType::simplex>
397 {
398 public:
399 typedef PkLocalFiniteElementMap<GV,C,R,degree> FEM;
400
401 CGFEMBase (const GV& gridview)
402 {
403 femp = std::shared_ptr<FEM>(new FEM(gridview));
404 }
405
406 FEM& getFEM() {return *femp;}
407 const FEM& getFEM() const {return *femp;}
408
409 private:
410 std::shared_ptr<FEM> femp;
411 };
412
413 template<typename GV, typename C, typename R, unsigned int degree, unsigned int dim>
414 class CGFEMBase<GV,C,R,degree,dim,Dune::GeometryType::cube>
415 {
416 public:
417 typedef QkLocalFiniteElementMap<GV,C,R,degree> FEM;
418
419 CGFEMBase (const GV& gridview)
420 {
421 femp = std::shared_ptr<FEM>(new FEM(gridview));
422 }
423
424 FEM& getFEM() {return *femp;}
425 const FEM& getFEM() const {return *femp;}
426
427 private:
428 std::shared_ptr<FEM> femp;
429 };
430
431 //============================================================================
432
433 // define enumeration type that differentiate conforming and nonconforming meshes
434 enum MeshType {
437 };
438
439 // constraints base template
440 template<typename Grid, unsigned int degree, Dune::GeometryType::BasicType gt, MeshType mt, SolverCategory::Category st, typename BCType, typename GV = typename Grid::LeafGridView>
441 class CGCONBase
442 {};
443
444 template<typename Grid, typename BCType, typename GV>
445 class CGCONBase<Grid,1,Dune::GeometryType::simplex,MeshType::nonconforming,SolverCategory::sequential,BCType,GV>
446 {
447 public:
448 typedef HangingNodesDirichletConstraints<Grid,HangingNodesConstraintsAssemblers::SimplexGridP1Assembler,BCType> CON;
449
450 CGCONBase (Grid& grid, const BCType& bctype, const GV& gv)
451 {
452 conp = std::shared_ptr<CON>(new CON(grid,true,bctype));
453 }
454
455 CGCONBase (Grid& grid, const BCType& bctype)
456 {
457 conp = std::shared_ptr<CON>(new CON(grid,true,bctype));
458 }
459
460 template<typename GFS>
461 void postGFSHook (const GFS& gfs) {}
462 CON& getCON() {return *conp;}
463 const CON& getCON() const {return *conp;}
464 template<typename GFS, typename DOF>
465 void make_consistent (const GFS& gfs, DOF& x) const {}
466 private:
467 std::shared_ptr<CON> conp;
468 };
469
470 template<typename Grid, typename BCType, typename GV>
471 class CGCONBase<Grid,1,Dune::GeometryType::cube,MeshType::nonconforming,SolverCategory::sequential,BCType,GV>
472 {
473 public:
474 typedef HangingNodesDirichletConstraints<Grid,HangingNodesConstraintsAssemblers::CubeGridQ1Assembler,BCType> CON;
475
476 CGCONBase (Grid& grid, const BCType& bctype, const GV& gv)
477 {
478 conp = std::shared_ptr<CON>(new CON(grid,true,bctype));
479 }
480
481 CGCONBase (Grid& grid, const BCType& bctype)
482 {
483 conp = std::shared_ptr<CON>(new CON(grid,true,bctype));
484 }
485
486 template<typename GFS>
487 void postGFSHook (const GFS& gfs) {}
488 CON& getCON() {return *conp;}
489 const CON& getCON() const {return *conp;}
490 template<typename GFS, typename DOF>
491 void make_consistent (const GFS& gfs, DOF& x) const {}
492 private:
493 std::shared_ptr<CON> conp;
494 };
495
496 template<typename Grid, unsigned int degree, Dune::GeometryType::BasicType gt,typename BCType, typename GV>
497 class CGCONBase<Grid,degree,gt,MeshType::conforming,SolverCategory::sequential,BCType,GV>
498 {
499 public:
500 typedef ConformingDirichletConstraints CON;
501
502 CGCONBase (Grid& grid, const BCType& bctype, const GV& gv)
503 {
504 conp = std::shared_ptr<CON>(new CON());
505 }
506
507 CGCONBase (Grid& grid, const BCType& bctype)
508 {
509 conp = std::shared_ptr<CON>(new CON());
510 }
511
512 template<typename GFS>
513 void postGFSHook (const GFS& gfs) {}
514 CON& getCON() {return *conp;}
515 const CON& getCON() const {return *conp;}
516 template<typename GFS, typename DOF>
517 void make_consistent (const GFS& gfs, DOF& x) const {}
518 private:
519 std::shared_ptr<CON> conp;
520 };
521
522 template<typename Grid, unsigned int degree, Dune::GeometryType::BasicType gt,typename BCType, typename GV>
523 class CGCONBase<Grid,degree,gt,MeshType::conforming,SolverCategory::overlapping,BCType,GV>
524 {
525 public:
526 typedef OverlappingConformingDirichletConstraints CON;
527
528 CGCONBase (Grid& grid, const BCType& bctype, const GV& gv)
529 {
530 conp = std::shared_ptr<CON>(new CON());
531 }
532
533 CGCONBase (Grid& grid, const BCType& bctype)
534 {
535 conp = std::shared_ptr<CON>(new CON());
536 }
537
538 template<typename GFS>
539 void postGFSHook (const GFS& gfs) {}
540 CON& getCON() {return *conp;}
541 const CON& getCON() const {return *conp;}
542 template<typename GFS, typename DOF>
543 void make_consistent (const GFS& gfs, DOF& x) const
544 {
545 // make vector consistent; this is needed for all overlapping solvers
546 ISTL::ParallelHelper<GFS> helper(gfs);
547 helper.maskForeignDOFs(Backend::native(x));
548 Dune::PDELab::AddDataHandle<GFS,DOF> adddh(gfs,x);
549 if (gfs.gridView().comm().size()>1)
550 gfs.gridView().communicate(adddh,Dune::InteriorBorder_All_Interface,Dune::ForwardCommunication);
551 }
552 private:
553 std::shared_ptr<CON> conp;
554 };
555
556 template<typename Grid, unsigned int degree, Dune::GeometryType::BasicType gt,typename BCType, typename GV>
557 class CGCONBase<Grid,degree,gt,MeshType::conforming,SolverCategory::nonoverlapping,BCType,GV>
558 {
559 public:
561 CGCONBase (Grid& grid, const BCType& bctype)
562 {
563 conp = std::shared_ptr<CON>(new CON);
564 }
565
566 template<typename GFS>
567 CON& getCON() {return *conp;}
568 const CON& getCON() const {return *conp;}
569 template<typename GFS, typename DOF>
570 void make_consistent (const GFS& gfs, DOF& x) const {}
571 private:
572 std::shared_ptr<CON> conp;
573 };
574
575
576 // continuous Lagrange finite elements
577 template<typename T, typename N, unsigned int degree, typename BCType,
579 typename VBET=ISTL::VectorBackend<> >
580 class CGSpace {
581 public:
582
583 // export types
584 typedef T Grid;
585 typedef typename T::LeafGridView GV;
586 typedef typename T::ctype ctype;
587 static const int dim = T::dimension;
588 static const int dimworld = T::dimensionworld;
589
590 typedef CGFEMBase<GV,ctype,N,degree,dim,gt> FEMB;
591 typedef CGCONBase<Grid,degree,gt,mt,st,BCType> CONB;
592
593 typedef typename FEMB::FEM FEM;
594 typedef typename CONB::CON CON;
595
596 typedef VBET VBE;
597 typedef GridFunctionSpace<GV,FEM,CON,VBE> GFS;
598
599 typedef N NT;
600 using DOF = Backend::Vector<GFS,N>;
602 typedef typename GFS::template ConstraintsContainer<N>::Type CC;
603 typedef VTKGridFunctionAdapter<DGF> VTKF;
604
605 // constructor making the grid function space an all that is needed
606 CGSpace (Grid& grid, const BCType& bctype)
607 : gv(grid.leafGridView()), femb(gv), conb(grid,bctype)
608 {
609 gfsp = std::shared_ptr<GFS>(new GFS(gv,femb.getFEM(),conb.getCON()));
610 gfsp->name("cgspace");
611 // initialize ordering
612 gfsp->update();
613 conb.postGFSHook(*gfsp);
614 ccp = std::shared_ptr<CC>(new CC());
615 }
616
617 FEM& getFEM()
618 {
619 return femb.getFEM();
620 }
621
622 const FEM& getFEM() const
623 {
624 return femb.getFEM();
625 }
626
627 // return gfs reference
628 GFS& getGFS ()
629 {
630 return *gfsp;
631 }
632
633 // return gfs reference const version
634 const GFS& getGFS () const
635 {
636 return *gfsp;
637 }
638
639 // return gfs reference
640 CC& getCC ()
641 {
642 return *ccp;
643 }
644
645 // return gfs reference const version
646 const CC& getCC () const
647 {
648 return *ccp;
649 }
650
651 void assembleConstraints (const BCType& bctype)
652 {
653 ccp->clear();
654 constraints(bctype,*gfsp,*ccp);
655 }
656
657 void clearConstraints ()
658 {
659 ccp->clear();
660 }
661
662 void setConstrainedDOFS (DOF& x, NT nt) const
663 {
664 set_constrained_dofs(*ccp,nt,x);
665 conb.make_consistent(*gfsp,x);
666 }
667
668 void setNonConstrainedDOFS (DOF& x, NT nt) const
669 {
670 set_nonconstrained_dofs(*ccp,nt,x);
671 conb.make_consistent(*gfsp,x);
672 }
673
674 void copyConstrainedDOFS (const DOF& xin, DOF& xout) const
675 {
676 copy_constrained_dofs(*ccp,xin,xout);
677 conb.make_consistent(*gfsp,xout);
678 }
679
680 void copyNonConstrainedDOFS (const DOF& xin, DOF& xout) const
681 {
682 copy_nonconstrained_dofs(*ccp,xin,xout);
683 conb.make_consistent(*gfsp,xout);
684 }
685
686 private:
687 GV gv; // need this object here because FEM and GFS store a const reference !!
688 FEMB femb;
689 CONB conb;
690 std::shared_ptr<GFS> gfsp;
691 std::shared_ptr<CC> ccp;
692 };
693
694 // template specialization for nonoverlapping case
695 template<typename T, typename N, unsigned int degree, typename BCType,
697 typename VBET>
698 class CGSpace<T, N, degree, BCType, gt, mt, SolverCategory::nonoverlapping, VBET> {
699 public:
700
701 // export types
702 typedef T Grid;
703 typedef typename T::LeafGridView GV;
704 typedef typename T::ctype ctype;
705 typedef typename Dune::PDELab::NonOverlappingEntitySet<GV> ES;
706 static const int dim = T::dimension;
707 static const int dimworld = T::dimensionworld;
708
709 typedef CGFEMBase<ES,ctype,N,degree,dim,gt> FEMB;
710 typedef CGCONBase<Grid,degree,gt,mt,SolverCategory::nonoverlapping,BCType> CONB;
711
712 typedef typename FEMB::FEM FEM;
713 typedef typename CONB::CON CON;
714
715 typedef VBET VBE;
716 typedef GridFunctionSpace<ES,FEM,CON,VBE> GFS;
717
718 typedef N NT;
719 using DOF = Backend::Vector<GFS,N>;
721 typedef typename GFS::template ConstraintsContainer<N>::Type CC;
722 typedef VTKGridFunctionAdapter<DGF> VTKF;
723
724 // constructor making the grid function space an all that is needed
725 CGSpace (Grid& grid, const BCType& bctype)
726 : gv(grid.leafGridView()), es(gv), femb(es), conb(grid,bctype)
727 {
728 gfsp = std::shared_ptr<GFS>(new GFS(es,femb.getFEM(),conb.getCON()));
729 gfsp->name("cgspace");
730 // initialize ordering
731 gfsp->update();
732 // conb.postGFSHook(*gfsp);
733 ccp = std::shared_ptr<CC>(new CC());
734 }
735
736 FEM& getFEM()
737 {
738 return femb.getFEM();
739 }
740
741 const FEM& getFEM() const
742 {
743 return femb.getFEM();
744 }
745
746 // return gfs reference
747 GFS& getGFS ()
748 {
749 return *gfsp;
750 }
751
752 // return gfs reference const version
753 const GFS& getGFS () const
754 {
755 return *gfsp;
756 }
757
758 // return gfs reference
759 CC& getCC ()
760 {
761 return *ccp;
762 }
763
764 // return gfs reference const version
765 const CC& getCC () const
766 {
767 return *ccp;
768 }
769
770 void assembleConstraints (const BCType& bctype)
771 {
772 ccp->clear();
773 constraints(bctype,*gfsp,*ccp);
774 }
775
776 void clearConstraints ()
777 {
778 ccp->clear();
779 }
780
781 void setConstrainedDOFS (DOF& x, NT nt) const
782 {
783 set_constrained_dofs(*ccp,nt,x);
784 conb.make_consistent(*gfsp,x);
785 }
786
787 void setNonConstrainedDOFS (DOF& x, NT nt) const
788 {
789 set_nonconstrained_dofs(*ccp,nt,x);
790 conb.make_consistent(*gfsp,x);
791 }
792
793 void copyConstrainedDOFS (const DOF& xin, DOF& xout) const
794 {
795 copy_constrained_dofs(*ccp,xin,xout);
796 conb.make_consistent(*gfsp,xout);
797 }
798
799 void copyNonConstrainedDOFS (const DOF& xin, DOF& xout) const
800 {
801 copy_nonconstrained_dofs(*ccp,xin,xout);
802 conb.make_consistent(*gfsp,xout);
803 }
804
805 private:
806 GV gv; // need this object here because FEM and GFS store a const reference !!
807 ES es;
808 FEMB femb;
809 CONB conb;
810 std::shared_ptr<GFS> gfsp;
811 std::shared_ptr<CC> ccp;
812 };
813
814
815
816 //============================================================================
817 // Discontinuous Finite Element Space
818 //============================================================================
819
820 // constraints base template
821 template<SolverCategory::Category st>
822 class DGCONBase
823 {};
824
825 template<>
826 class DGCONBase<SolverCategory::sequential>
827 {
828 public:
829 typedef NoConstraints CON;
830 DGCONBase ()
831 {
832 conp = std::shared_ptr<CON>(new CON());
833 }
834 CON& getCON() {return *conp;}
835 const CON& getCON() const {return *conp;}
836 template<typename GFS, typename DOF>
837 void make_consistent (const GFS& gfs, DOF& x) const {}
838 private:
839 std::shared_ptr<CON> conp;
840 };
841
842 template<>
843 class DGCONBase<SolverCategory::nonoverlapping>
844 {
845 public:
846 typedef P0ParallelGhostConstraints CON;
847 DGCONBase ()
848 {
849 conp = std::shared_ptr<CON>(new CON());
850 }
851 CON& getCON() {return *conp;}
852 const CON& getCON() const {return *conp;}
853 template<typename GFS, typename DOF>
854 void make_consistent (const GFS& gfs, DOF& x) const {}
855 private:
856 std::shared_ptr<CON> conp;
857 };
858
859 template<>
860 class DGCONBase<SolverCategory::overlapping>
861 {
862 public:
863 typedef P0ParallelConstraints CON;
864 DGCONBase ()
865 {
866 conp = std::shared_ptr<CON>(new CON());
867 }
868 CON& getCON() {return *conp;}
869 const CON& getCON() const {return *conp;}
870 template<typename GFS, typename DOF>
871 void make_consistent (const GFS& gfs, DOF& x) const
872 {
873 // make vector consistent; this is needed for all overlapping solvers
874 ISTL::ParallelHelper<GFS> helper(gfs);
875 helper.maskForeignDOFs(Backend::native(x));
876 Dune::PDELab::AddDataHandle<GFS,DOF> adddh(gfs,x);
877 if (gfs.gridView().comm().size()>1)
878 gfs.gridView().communicate(adddh,Dune::InteriorBorder_All_Interface,Dune::ForwardCommunication);
879 }
880 private:
881 std::shared_ptr<CON> conp;
882 };
883
884 // Discontinuous space
885 // default implementation, use only specializations below
886 template<typename T, typename N, unsigned int degree,
888 typename VBET=ISTL::VectorBackend<ISTL::Blocking::fixed,Dune::PB::PkSize<degree,T::dimension>::value> >
889 class DGPkSpace
890 {
891 public:
892
893 // export types
894 typedef T Grid;
895 typedef typename T::LeafGridView GV;
896 typedef typename T::ctype ctype;
897 static const int dim = T::dimension;
898 static const int dimworld = T::dimensionworld;
899 typedef N NT;
900#if HAVE_GMP
901 typedef OPBLocalFiniteElementMap<ctype,NT,degree,dim,gt,Dune::GMPField<512>,Dune::PB::BasisType::Pk> FEM;
902#else
903 typedef OPBLocalFiniteElementMap<ctype,NT,degree,dim,gt> FEM;
904#endif
905 typedef DGCONBase<st> CONB;
906 typedef typename CONB::CON CON;
907 typedef VBET VBE;
908 typedef GridFunctionSpace<GV,FEM,CON,VBE> GFS;
909 using DOF = Backend::Vector<GFS,N>;
911 typedef typename GFS::template ConstraintsContainer<N>::Type CC;
912 typedef VTKGridFunctionAdapter<DGF> VTKF;
913
914 // constructor making the grid function space an all that is needed
915 DGPkSpace (const GV& gridview) : gv(gridview), conb()
916 {
917 femp = std::shared_ptr<FEM>(new FEM());
918 gfsp = std::shared_ptr<GFS>(new GFS(gv,*femp));
919 // initialize ordering
920 gfsp->update();
921 ccp = std::shared_ptr<CC>(new CC());
922 }
923
924 FEM& getFEM() { return *femp; }
925 const FEM& getFEM() const { return *femp; }
926
927 // return gfs reference
928 GFS& getGFS () { return *gfsp; }
929
930 // return gfs reference const version
931 const GFS& getGFS () const {return *gfsp;}
932
933 // return gfs reference
934 CC& getCC () { return *ccp;}
935
936 // return gfs reference const version
937 const CC& getCC () const { return *ccp;}
938
939 template<class BCTYPE>
940 void assembleConstraints (const BCTYPE& bctype)
941 {
942 ccp->clear();
943 constraints(bctype,*gfsp,*ccp);
944 }
945
946 void clearConstraints ()
947 {
948 ccp->clear();
949 }
950
951 void setConstrainedDOFS (DOF& x, NT nt) const
952 {
953 set_constrained_dofs(*ccp,nt,x);
954 conb.make_consistent(*gfsp,x);
955 }
956
957 void setNonConstrainedDOFS (DOF& x, NT nt) const
958 {
959 set_nonconstrained_dofs(*ccp,nt,x);
960 conb.make_consistent(*gfsp,x);
961 }
962
963 void copyConstrainedDOFS (const DOF& xin, DOF& xout) const
964 {
965 copy_constrained_dofs(*ccp,xin,xout);
966 conb.make_consistent(*gfsp,xout);
967 }
968
969 void copyNonConstrainedDOFS (const DOF& xin, DOF& xout) const
970 {
971 copy_nonconstrained_dofs(*ccp,xin,xout);
972 conb.make_consistent(*gfsp,xout);
973 }
974
975 private:
976 GV gv; // need this object here because FEM and GFS store a const reference !!
977 CONB conb;
978 std::shared_ptr<FEM> femp;
979 std::shared_ptr<GFS> gfsp;
980 std::shared_ptr<CC> ccp;
981 };
982
983 // Discontinuous space
984 // default implementation, use only specializations below
985 template<typename T, typename N, unsigned int degree,
987 //typename VBET=ISTL::VectorBackend<ISTL::Blocking::fixed,Dune::PB::PkSize<degree,T::dimension>::value> >
988 typename VBET=ISTL::VectorBackend<> >
989 class DGQkOPBSpace
990 {
991 public:
992
993 // export types
994 typedef T Grid;
995 typedef typename T::LeafGridView GV;
996 typedef typename T::ctype ctype;
997 static const int dim = T::dimension;
998 static const int dimworld = T::dimensionworld;
999 typedef N NT;
1000#if HAVE_GMP
1001 typedef OPBLocalFiniteElementMap<ctype,NT,degree,dim,gt,Dune::GMPField<512>,Dune::PB::BasisType::Qk> FEM;
1002#else
1003 typedef OPBLocalFiniteElementMap<ctype,NT,degree,dim,gt,N,Dune::PB::BasisType::Qk> FEM;
1004#endif
1005 typedef DGCONBase<st> CONB;
1006 typedef typename CONB::CON CON;
1007 typedef VBET VBE;
1008 typedef GridFunctionSpace<GV,FEM,CON,VBE> GFS;
1009 using DOF = Backend::Vector<GFS,N>;
1011 typedef typename GFS::template ConstraintsContainer<N>::Type CC;
1012 typedef VTKGridFunctionAdapter<DGF> VTKF;
1013
1014 // constructor making the grid function space an all that is needed
1015 DGQkOPBSpace (const GV& gridview) : gv(gridview), conb()
1016 {
1017 femp = std::shared_ptr<FEM>(new FEM());
1018 gfsp = std::shared_ptr<GFS>(new GFS(gv,*femp));
1019 // initialize ordering
1020 gfsp->update();
1021 ccp = std::shared_ptr<CC>(new CC());
1022 }
1023
1024 FEM& getFEM() { return *femp; }
1025 const FEM& getFEM() const { return *femp; }
1026
1027 // return gfs reference
1028 GFS& getGFS () { return *gfsp; }
1029
1030 // return gfs reference const version
1031 const GFS& getGFS () const {return *gfsp;}
1032
1033 // return gfs reference
1034 CC& getCC () { return *ccp;}
1035
1036 // return gfs reference const version
1037 const CC& getCC () const { return *ccp;}
1038
1039 template<class BCTYPE>
1040 void assembleConstraints (const BCTYPE& bctype)
1041 {
1042 ccp->clear();
1043 constraints(bctype,*gfsp,*ccp);
1044 }
1045
1046 void clearConstraints ()
1047 {
1048 ccp->clear();
1049 }
1050
1051 void setConstrainedDOFS (DOF& x, NT nt) const
1052 {
1053 set_constrained_dofs(*ccp,nt,x);
1054 conb.make_consistent(*gfsp,x);
1055 }
1056
1057 void setNonConstrainedDOFS (DOF& x, NT nt) const
1058 {
1059 set_nonconstrained_dofs(*ccp,nt,x);
1060 conb.make_consistent(*gfsp,x);
1061 }
1062
1063 void copyConstrainedDOFS (const DOF& xin, DOF& xout) const
1064 {
1065 copy_constrained_dofs(*ccp,xin,xout);
1066 conb.make_consistent(*gfsp,xout);
1067 }
1068
1069 void copyNonConstrainedDOFS (const DOF& xin, DOF& xout) const
1070 {
1071 copy_nonconstrained_dofs(*ccp,xin,xout);
1072 conb.make_consistent(*gfsp,xout);
1073 }
1074
1075 private:
1076 GV gv; // need this object here because FEM and GFS store a const reference !!
1077 CONB conb;
1078 std::shared_ptr<FEM> femp;
1079 std::shared_ptr<GFS> gfsp;
1080 std::shared_ptr<CC> ccp;
1081 };
1082
1083 // Discontinuous space
1084 // default implementation, use only specializations below
1085 template<typename T, typename N, unsigned int degree,
1087 typename VBET=ISTL::VectorBackend<ISTL::Blocking::fixed,Dune::QkStuff::QkSize<degree,T::dimension>::value> >
1088 class DGQkSpace
1089 {
1090 public:
1091
1092 // export types
1093 typedef T Grid;
1094 typedef typename T::LeafGridView GV;
1095 typedef typename T::ctype ctype;
1096 static const int dim = T::dimension;
1097 static const int dimworld = T::dimensionworld;
1098 typedef N NT;
1099 typedef QkDGLocalFiniteElementMap<ctype,NT,degree,dim> FEM;
1100 typedef DGCONBase<st> CONB;
1101 typedef typename CONB::CON CON;
1102 typedef VBET VBE;
1103 typedef GridFunctionSpace<GV,FEM,CON,VBE> GFS;
1104 using DOF = Backend::Vector<GFS,N>;
1106 typedef typename GFS::template ConstraintsContainer<N>::Type CC;
1107 typedef VTKGridFunctionAdapter<DGF> VTKF;
1108
1109 // constructor making the grid function space an all that is needed
1110 DGQkSpace (const GV& gridview) : gv(gridview), conb()
1111 {
1112 femp = std::shared_ptr<FEM>(new FEM());
1113 gfsp = std::shared_ptr<GFS>(new GFS(gv,*femp));
1114 // initialize ordering
1115 gfsp->update();
1116 ccp = std::shared_ptr<CC>(new CC());
1117 }
1118
1119 FEM& getFEM() { return *femp; }
1120 const FEM& getFEM() const { return *femp; }
1121
1122 // return gfs reference
1123 GFS& getGFS () { return *gfsp; }
1124
1125 // return gfs reference const version
1126 const GFS& getGFS () const {return *gfsp;}
1127
1128 // return gfs reference
1129 CC& getCC () { return *ccp;}
1130
1131 // return gfs reference const version
1132 const CC& getCC () const { return *ccp;}
1133
1134 template<class BCTYPE>
1135 void assembleConstraints (const BCTYPE& bctype)
1136 {
1137 ccp->clear();
1138 constraints(bctype,*gfsp,*ccp);
1139 }
1140
1141 void clearConstraints ()
1142 {
1143 ccp->clear();
1144 }
1145
1146 void setConstrainedDOFS (DOF& x, NT nt) const
1147 {
1148 set_constrained_dofs(*ccp,nt,x);
1149 conb.make_consistent(*gfsp,x);
1150 }
1151
1152 void setNonConstrainedDOFS (DOF& x, NT nt) const
1153 {
1154 set_nonconstrained_dofs(*ccp,nt,x);
1155 conb.make_consistent(*gfsp,x);
1156 }
1157
1158 void copyConstrainedDOFS (const DOF& xin, DOF& xout) const
1159 {
1160 copy_constrained_dofs(*ccp,xin,xout);
1161 conb.make_consistent(*gfsp,xout);
1162 }
1163
1164 void copyNonConstrainedDOFS (const DOF& xin, DOF& xout) const
1165 {
1166 copy_nonconstrained_dofs(*ccp,xin,xout);
1167 conb.make_consistent(*gfsp,xout);
1168 }
1169
1170 private:
1171 GV gv; // need this object here because FEM and GFS store a const reference !!
1172 CONB conb;
1173 std::shared_ptr<FEM> femp;
1174 std::shared_ptr<GFS> gfsp;
1175 std::shared_ptr<CC> ccp;
1176 };
1177
1178
1179 // Discontinuous space using QK with Gauss Lobatto points (use only for cube elements)
1180 template<typename T, typename N, unsigned int degree,
1182 //typename VBET=ISTL::VectorBackend<ISTL::Blocking::fixed,Dune::QkStuff::QkSize<degree,T::dimension>::value> >
1183 typename VBET=ISTL::VectorBackend<> >
1184 class DGQkGLSpace
1185 {
1186 public:
1187
1188 // export types
1189 typedef T Grid;
1190 typedef typename T::LeafGridView GV;
1191 typedef typename T::ctype ctype;
1192 static const int dim = T::dimension;
1193 static const int dimworld = T::dimensionworld;
1194 typedef N NT;
1195 typedef QkDGLocalFiniteElementMap<ctype,NT,degree,dim,QkDGBasisPolynomial::lobatto> FEM;
1196 typedef DGCONBase<st> CONB;
1197 typedef typename CONB::CON CON;
1198 typedef VBET VBE;
1199 typedef GridFunctionSpace<GV,FEM,CON,VBE> GFS;
1200 using DOF = Backend::Vector<GFS,N>;
1202 typedef typename GFS::template ConstraintsContainer<N>::Type CC;
1203 typedef VTKGridFunctionAdapter<DGF> VTKF;
1204
1205 // constructor making the grid function space an all that is needed
1206 DGQkGLSpace (const GV& gridview) : gv(gridview), conb()
1207 {
1208 femp = std::shared_ptr<FEM>(new FEM());
1209 gfsp = std::shared_ptr<GFS>(new GFS(gv,*femp));
1210 // initialize ordering
1211 gfsp->update();
1212 ccp = std::shared_ptr<CC>(new CC());
1213 }
1214
1215 FEM& getFEM() { return *femp; }
1216 const FEM& getFEM() const { return *femp; }
1217
1218 // return gfs reference
1219 GFS& getGFS () { return *gfsp; }
1220
1221 // return gfs reference const version
1222 const GFS& getGFS () const {return *gfsp;}
1223
1224 // return gfs reference
1225 CC& getCC () { return *ccp;}
1226
1227 // return gfs reference const version
1228 const CC& getCC () const { return *ccp;}
1229
1230 template<class BCTYPE>
1231 void assembleConstraints (const BCTYPE& bctype)
1232 {
1233 ccp->clear();
1234 constraints(bctype,*gfsp,*ccp);
1235 }
1236
1237 void clearConstraints ()
1238 {
1239 ccp->clear();
1240 }
1241
1242 void setConstrainedDOFS (DOF& x, NT nt) const
1243 {
1244 set_constrained_dofs(*ccp,nt,x);
1245 conb.make_consistent(*gfsp,x);
1246 }
1247
1248 void setNonConstrainedDOFS (DOF& x, NT nt) const
1249 {
1250 set_nonconstrained_dofs(*ccp,nt,x);
1251 conb.make_consistent(*gfsp,x);
1252 }
1253
1254 void copyConstrainedDOFS (const DOF& xin, DOF& xout) const
1255 {
1256 copy_constrained_dofs(*ccp,xin,xout);
1257 conb.make_consistent(*gfsp,xout);
1258 }
1259
1260 void copyNonConstrainedDOFS (const DOF& xin, DOF& xout) const
1261 {
1262 copy_nonconstrained_dofs(*ccp,xin,xout);
1263 conb.make_consistent(*gfsp,xout);
1264 }
1265
1266 private:
1267 GV gv; // need this object here because FEM and GFS store a const reference !!
1268 CONB conb;
1269 std::shared_ptr<FEM> femp;
1270 std::shared_ptr<GFS> gfsp;
1271 std::shared_ptr<CC> ccp;
1272 };
1273
1274
1275 // Discontinuous space using Legendre polynomials (use only for cube elements)
1276 template<typename T, typename N, unsigned int degree,
1278 //typename VBET=ISTL::VectorBackend<ISTL::Blocking::fixed,Dune::QkStuff::QkSize<degree,T::dimension>::value> >
1279 typename VBET=ISTL::VectorBackend<> >
1280 class DGLegendreSpace
1281 {
1282 public:
1283
1284 // export types
1285 typedef T Grid;
1286 typedef typename T::LeafGridView GV;
1287 typedef typename T::ctype ctype;
1288 static const int dim = T::dimension;
1289 static const int dimworld = T::dimensionworld;
1290 typedef N NT;
1291 typedef QkDGLocalFiniteElementMap<ctype,NT,degree,dim,QkDGBasisPolynomial::legendre> FEM;
1292 typedef DGCONBase<st> CONB;
1293 typedef typename CONB::CON CON;
1294 typedef VBET VBE;
1295 typedef GridFunctionSpace<GV,FEM,CON,VBE> GFS;
1296 using DOF = Backend::Vector<GFS,N>;
1298 typedef typename GFS::template ConstraintsContainer<N>::Type CC;
1299 typedef VTKGridFunctionAdapter<DGF> VTKF;
1300
1301 // constructor making the grid function space an all that is needed
1302 DGLegendreSpace (const GV& gridview) : gv(gridview), conb()
1303 {
1304 femp = std::shared_ptr<FEM>(new FEM());
1305 gfsp = std::shared_ptr<GFS>(new GFS(gv,*femp));
1306 // initialize ordering
1307 gfsp->update();
1308 ccp = std::shared_ptr<CC>(new CC());
1309 }
1310
1311 FEM& getFEM() { return *femp; }
1312 const FEM& getFEM() const { return *femp; }
1313
1314 // return gfs reference
1315 GFS& getGFS () { return *gfsp; }
1316
1317 // return gfs reference const version
1318 const GFS& getGFS () const {return *gfsp;}
1319
1320 // return gfs reference
1321 CC& getCC () { return *ccp;}
1322
1323 // return gfs reference const version
1324 const CC& getCC () const { return *ccp;}
1325
1326 template<class BCTYPE>
1327 void assembleConstraints (const BCTYPE& bctype)
1328 {
1329 ccp->clear();
1330 constraints(bctype,*gfsp,*ccp);
1331 }
1332
1333 void clearConstraints ()
1334 {
1335 ccp->clear();
1336 }
1337
1338 void setConstrainedDOFS (DOF& x, NT nt) const
1339 {
1340 set_constrained_dofs(*ccp,nt,x);
1341 conb.make_consistent(*gfsp,x);
1342 }
1343
1344 void setNonConstrainedDOFS (DOF& x, NT nt) const
1345 {
1346 set_nonconstrained_dofs(*ccp,nt,x);
1347 conb.make_consistent(*gfsp,x);
1348 }
1349
1350 void copyConstrainedDOFS (const DOF& xin, DOF& xout) const
1351 {
1352 copy_constrained_dofs(*ccp,xin,xout);
1353 conb.make_consistent(*gfsp,xout);
1354 }
1355
1356 void copyNonConstrainedDOFS (const DOF& xin, DOF& xout) const
1357 {
1358 copy_nonconstrained_dofs(*ccp,xin,xout);
1359 conb.make_consistent(*gfsp,xout);
1360 }
1361
1362 private:
1363 GV gv; // need this object here because FEM and GFS store a const reference !!
1364 CONB conb;
1365 std::shared_ptr<FEM> femp;
1366 std::shared_ptr<GFS> gfsp;
1367 std::shared_ptr<CC> ccp;
1368 };
1369
1370
1371 // Discontinuous P0 space
1372 template<typename T, typename N,
1374 typename VBET=ISTL::VectorBackend<> >
1375 class P0Space
1376 {
1377 public:
1378
1379 // export types
1380 typedef T Grid;
1381 typedef typename T::LeafGridView GV;
1382 typedef typename T::ctype ctype;
1383 static const int dim = T::dimension;
1384 static const int dimworld = T::dimensionworld;
1385 typedef N NT;
1387 typedef DGCONBase<st> CONB;
1388 typedef typename CONB::CON CON;
1389 typedef VBET VBE;
1390 typedef GridFunctionSpace<GV,FEM,CON,VBE> GFS;
1391 using DOF = Backend::Vector<GFS,N>;
1393 typedef typename GFS::template ConstraintsContainer<N>::Type CC;
1394 typedef VTKGridFunctionAdapter<DGF> VTKF;
1395
1396 // constructor making the grid function space an all that is needed
1397 P0Space (const GV& gridview) : gv(gridview), conb()
1398 {
1399 femp = std::shared_ptr<FEM>(new FEM(Dune::GeometryType(gt,dim)));
1400 gfsp = std::shared_ptr<GFS>(new GFS(gv,*femp));
1401 // initialize ordering
1402 gfsp->update();
1403 ccp = std::shared_ptr<CC>(new CC());
1404 }
1405
1406 FEM& getFEM() { return *femp; }
1407 const FEM& getFEM() const { return *femp; }
1408
1409 // return gfs reference
1410 GFS& getGFS () { return *gfsp; }
1411
1412 // return gfs reference const version
1413 const GFS& getGFS () const {return *gfsp;}
1414
1415 // return gfs reference
1416 CC& getCC () { return *ccp;}
1417
1418 // return gfs reference const version
1419 const CC& getCC () const { return *ccp;}
1420
1421 template<class BCTYPE>
1422 void assembleConstraints (const BCTYPE& bctype)
1423 {
1424 ccp->clear();
1425 constraints(bctype,*gfsp,*ccp);
1426 }
1427
1428 void clearConstraints ()
1429 {
1430 ccp->clear();
1431 }
1432
1433 void setConstrainedDOFS (DOF& x, NT nt) const
1434 {
1435 set_constrained_dofs(*ccp,nt,x);
1436 conb.make_consistent(*gfsp,x);
1437 }
1438
1439 void setNonConstrainedDOFS (DOF& x, NT nt) const
1440 {
1441 set_nonconstrained_dofs(*ccp,nt,x);
1442 conb.make_consistent(*gfsp,x);
1443 }
1444
1445 void copyConstrainedDOFS (const DOF& xin, DOF& xout) const
1446 {
1447 copy_constrained_dofs(*ccp,xin,xout);
1448 conb.make_consistent(*gfsp,xout);
1449 }
1450
1451 void copyNonConstrainedDOFS (const DOF& xin, DOF& xout) const
1452 {
1453 copy_nonconstrained_dofs(*ccp,xin,xout);
1454 conb.make_consistent(*gfsp,xout);
1455 }
1456
1457 private:
1458 GV gv; // need this object here because FEM and GFS store a const reference !!
1459 CONB conb;
1460 std::shared_ptr<FEM> femp;
1461 std::shared_ptr<GFS> gfsp;
1462 std::shared_ptr<CC> ccp;
1463 };
1464
1465
1466 // how can we most easily specify a grid function
1467 // pass a function space as parameter
1468 template<typename FS, typename Functor>
1469 class UserFunction
1470 : public GridFunctionBase<GridFunctionTraits<typename FS::GV, typename FS::NT,
1471 1,FieldVector<typename FS::NT,1> >
1472 ,UserFunction<FS,Functor> >
1473 {
1474 public:
1475 typedef GridFunctionTraits<typename FS::GV, typename FS::NT,
1476 1,FieldVector<typename FS::NT,1> > Traits;
1477
1479 UserFunction (const FS& fs_, const Functor& f_)
1480 : fs(fs_), f(f_)
1481 {}
1482
1484 inline void evaluate (const typename Traits::ElementType& e,
1485 const typename Traits::DomainType& x,
1486 typename Traits::RangeType& y) const
1487 {
1488 typename Traits::DomainType x_ = e.geometry().global(x);
1489 std::vector<double> x__(x.size());
1490 for (size_t i=0; i<x.size(); ++i) x__[i]=x_[i];
1491 y = f(x__);
1492 }
1493
1494 inline const typename FS::GV& getGridView () const
1495 {
1496 return fs.getGFS().gridView();
1497 }
1498
1499 private:
1500 const FS fs; // store a copy of the function space
1501 const Functor f;
1502 };
1503
1504
1505 template<typename FS, typename LOP, SolverCategory::Category st = SolverCategory::sequential>
1506 class GalerkinGlobalAssembler
1507 {
1508 public:
1509 // export types
1510 typedef ISTL::BCRSMatrixBackend<> MBE;
1511 typedef Dune::PDELab::GridOperator<typename FS::GFS,typename FS::GFS,LOP,MBE,
1512 typename FS::NT,typename FS::NT,typename FS::NT,
1513 typename FS::CC,typename FS::CC> GO;
1514 typedef typename GO::Jacobian MAT;
1515
1516 GalerkinGlobalAssembler (const FS& fs, LOP& lop, const std::size_t nonzeros)
1517 {
1518 gop = std::shared_ptr<GO>(new GO(fs.getGFS(),fs.getCC(),fs.getGFS(),fs.getCC(),lop,MBE(nonzeros)));
1519 }
1520
1521 // return grid reference
1522 GO& getGO ()
1523 {
1524 return *gop;
1525 }
1526
1527 // return grid reference const version
1528 const GO& getGO () const
1529 {
1530 return *gop;
1531 }
1532
1533 GO& operator*()
1534 {
1535 return *gop;
1536 }
1537
1538 GO* operator->()
1539 {
1540 return gop.operator->();
1541 }
1542
1543 const GO& operator*() const
1544 {
1545 return *gop;
1546 }
1547
1548 const GO* operator->() const
1549 {
1550 return gop.operator->();
1551 }
1552
1553 private:
1554 std::shared_ptr<GO> gop;
1555 };
1556
1557
1558 template<typename FS, typename LOP, SolverCategory::Category st = SolverCategory::sequential>
1559 class GalerkinGlobalAssemblerNewBackend
1560 {
1561 public:
1562 // export types
1564 typedef Dune::PDELab::GridOperator<typename FS::GFS,typename FS::GFS,LOP,MBE,
1565 typename FS::NT,typename FS::NT,typename FS::NT,
1566 typename FS::CC,typename FS::CC> GO;
1567 typedef typename GO::Jacobian MAT;
1568
1569 GalerkinGlobalAssemblerNewBackend (const FS& fs, LOP& lop, const MBE& mbe)
1570 {
1571 gop = std::shared_ptr<GO>(new GO(fs.getGFS(),fs.getCC(),fs.getGFS(),fs.getCC(),lop,mbe));
1572 }
1573
1574 // return grid reference
1575 GO& getGO ()
1576 {
1577 return *gop;
1578 }
1579
1580 // return grid reference const version
1581 const GO& getGO () const
1582 {
1583 return *gop;
1584 }
1585
1586 GO& operator*()
1587 {
1588 return *gop;
1589 }
1590
1591 GO* operator->()
1592 {
1593 return gop.operator->();
1594 }
1595
1596 const GO& operator*() const
1597 {
1598 return *gop;
1599 }
1600
1601 const GO* operator->() const
1602 {
1603 return gop.operator->();
1604 }
1605
1606 private:
1607 std::shared_ptr<GO> gop;
1608 };
1609
1610
1611 // variant with two different function spaces
1612 template<typename FSU, typename FSV, typename LOP, SolverCategory::Category st>
1613 class GlobalAssembler
1614 {
1615 public:
1616 // export types
1617 typedef ISTL::BCRSMatrixBackend<> MBE;
1618 typedef Dune::PDELab::GridOperator<typename FSU::GFS,typename FSV::GFS,LOP,MBE,
1619 typename FSU::NT,typename FSU::NT,typename FSU::NT,
1620 typename FSU::CC,typename FSV::CC> GO;
1621 typedef typename GO::Jacobian MAT;
1622
1623 GlobalAssembler (const FSU& fsu, const FSV& fsv, LOP& lop, const std::size_t nonzeros)
1624 {
1625 gop = std::shared_ptr<GO>(new GO(fsu.getGFS(),fsu.getCC(),fsv.getGFS(),fsv.getCC(),lop,MBE(nonzeros)));
1626 }
1627
1628 // return grid reference
1629 GO& getGO ()
1630 {
1631 return *gop;
1632 }
1633
1634 // return grid reference const version
1635 const GO& getGO () const
1636 {
1637 return *gop;
1638 }
1639
1640 GO& operator*()
1641 {
1642 return *gop;
1643 }
1644
1645 GO* operator->()
1646 {
1647 return gop.operator->();
1648 }
1649
1650 const GO& operator*() const
1651 {
1652 return *gop;
1653 }
1654
1655 const GO* operator->() const
1656 {
1657 return gop.operator->();
1658 }
1659
1660 private:
1661 std::shared_ptr<GO> gop;
1662 };
1663
1664
1665 template<typename GO1, typename GO2, bool implicit = true>
1666 class OneStepGlobalAssembler
1667 {
1668 public:
1669 // export types
1670 typedef ISTL::BCRSMatrixBackend<> MBE;
1671 typedef Dune::PDELab::OneStepGridOperator<typename GO1::GO,typename GO2::GO,implicit> GO;
1672 typedef typename GO::Jacobian MAT;
1673
1674 OneStepGlobalAssembler (GO1& go1, GO2& go2)
1675 {
1676 gop = std::shared_ptr<GO>(new GO(*go1,*go2));
1677 }
1678
1679 // return grid reference
1680 GO& getGO ()
1681 {
1682 return *gop;
1683 }
1684
1685 // return grid reference const version
1686 const GO& getGO () const
1687 {
1688 return *gop;
1689 }
1690
1691 GO& operator*()
1692 {
1693 return *gop;
1694 }
1695
1696 GO* operator->()
1697 {
1698 return gop.operator->();
1699 }
1700
1701 const GO& operator*() const
1702 {
1703 return *gop;
1704 }
1705
1706 const GO* operator->() const
1707 {
1708 return gop.operator->();
1709 }
1710
1711 private:
1712 std::shared_ptr<GO> gop;
1713 };
1714
1715
1716 // packaging of the CG_AMG_SSOR solver: default version is sequential
1717 template<typename FS, typename ASS, SolverCategory::Category st = SolverCategory::sequential>
1718 class ISTLSolverBackend_CG_AMG_SSOR
1719 {
1720 public:
1721 // types exported
1723
1724 ISTLSolverBackend_CG_AMG_SSOR (const FS& fs, const ASS& ass, unsigned maxiter_=5000,
1725 int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
1726 {
1727 lsp = std::shared_ptr<LS>(new LS(maxiter_,verbose_,reuse_,usesuperlu_));
1728 }
1729
1730 LS& getLS () {return *lsp;}
1731 const LS& getLS () const { return *lsp;}
1732 LS& operator*(){return *lsp;}
1733 LS* operator->() { return lsp.operator->(); }
1734 const LS& operator*() const{return *lsp;}
1735 const LS* operator->() const{ return lsp.operator->();}
1736
1737 private:
1738 std::shared_ptr<LS> lsp;
1739 };
1740
1741 // packaging of the CG_AMG_SSOR solver: nonoverlapping version
1742 template<typename FS, typename ASS>
1743 class ISTLSolverBackend_CG_AMG_SSOR<FS,ASS, SolverCategory::nonoverlapping>
1744 {
1745 public:
1746 // types exported
1748
1749 ISTLSolverBackend_CG_AMG_SSOR (const FS& fs, const ASS& ass, unsigned maxiter_=5000,
1750 int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
1751 {
1752 lsp = std::shared_ptr<LS>(new LS(fs.getGFS(),maxiter_,verbose_,reuse_,usesuperlu_));
1753 }
1754
1755 LS& getLS () {return *lsp;}
1756 const LS& getLS () const { return *lsp;}
1757 LS& operator*(){return *lsp;}
1758 LS* operator->() { return lsp.operator->(); }
1759 const LS& operator*() const{return *lsp;}
1760 const LS* operator->() const{ return lsp.operator->();}
1761
1762 private:
1763 std::shared_ptr<LS> lsp;
1764 };
1765
1766 // packaging of the CG_AMG_SSOR solver: overlapping version
1767 template<typename FS, typename ASS>
1768 class ISTLSolverBackend_CG_AMG_SSOR<FS,ASS, SolverCategory::overlapping>
1769 {
1770 public:
1771 // types exported
1773
1774 ISTLSolverBackend_CG_AMG_SSOR (const FS& fs, const ASS& ass, unsigned maxiter_=5000,
1775 int verbose_=1, bool reuse_=false, bool usesuperlu_=true)
1776 {
1777 lsp = std::shared_ptr<LS>(new LS(fs.getGFS(),maxiter_,verbose_,reuse_,usesuperlu_));
1778 }
1779
1780 LS& getLS () {return *lsp;}
1781 const LS& getLS () const { return *lsp;}
1782 LS& operator*(){return *lsp;}
1783 LS* operator->() { return lsp.operator->(); }
1784 const LS& operator*() const{return *lsp;}
1785 const LS* operator->() const{ return lsp.operator->();}
1786
1787 private:
1788 std::shared_ptr<LS> lsp;
1789 };
1790
1791 // packaging of the CG_SSOR solver: default version is sequential
1792 template<typename FS, typename ASS, SolverCategory::Category st = SolverCategory::sequential>
1793 class ISTLSolverBackend_CG_SSOR
1794 {
1795 public:
1796 // types exported
1797 typedef ISTLBackend_SEQ_CG_SSOR LS;
1798
1799 ISTLSolverBackend_CG_SSOR (const FS& fs, const ASS& ass, unsigned maxiter_=5000,
1800 int steps_=5, int verbose_=1)
1801 {
1802 lsp = std::shared_ptr<LS>(new LS(maxiter_,verbose_));
1803 }
1804
1805 LS& getLS () {return *lsp;}
1806 const LS& getLS () const { return *lsp;}
1807 LS& operator*(){return *lsp;}
1808 LS* operator->() { return lsp.operator->(); }
1809 const LS& operator*() const{return *lsp;}
1810 const LS* operator->() const{ return lsp.operator->();}
1811
1812 private:
1813 std::shared_ptr<LS> lsp;
1814 };
1815
1816 // packaging of the CG_SSOR solver: nonoverlapping version
1817 template<typename FS, typename ASS>
1818 class ISTLSolverBackend_CG_SSOR<FS,ASS,SolverCategory::nonoverlapping>
1819 {
1820 public:
1821 // types exported
1822 typedef ISTLBackend_NOVLP_CG_SSORk<typename ASS::GO> LS;
1823
1824 ISTLSolverBackend_CG_SSOR (const FS& fs, const ASS& ass, unsigned maxiter_=5000,
1825 int steps_=5, int verbose_=1)
1826 {
1827 lsp = std::shared_ptr<LS>(new LS(fs.getGFS(),maxiter_,steps_,verbose_));
1828 }
1829
1830 LS& getLS () {return *lsp;}
1831 const LS& getLS () const { return *lsp;}
1832 LS& operator*(){return *lsp;}
1833 LS* operator->() { return lsp.operator->(); }
1834 const LS& operator*() const{return *lsp;}
1835 const LS* operator->() const{ return lsp.operator->();}
1836
1837 private:
1838 std::shared_ptr<LS> lsp;
1839 };
1840
1841 // packaging of the CG_SSOR solver: overlapping version
1842 template<typename FS, typename ASS>
1843 class ISTLSolverBackend_CG_SSOR<FS,ASS,SolverCategory::overlapping>
1844 {
1845 public:
1846 // types exported
1847 typedef ISTLBackend_OVLP_CG_SSORk<typename FS::GFS, typename FS::CC> LS;
1848
1849 ISTLSolverBackend_CG_SSOR (const FS& fs, const ASS& ass, unsigned maxiter_=5000,
1850 int steps_=5, int verbose_=1)
1851 {
1852 lsp = std::shared_ptr<LS>(new LS(fs.getGFS(),fs.getCC(),maxiter_,steps_,verbose_));
1853 }
1854
1855 LS& getLS () {return *lsp;}
1856 const LS& getLS () const { return *lsp;}
1857 LS& operator*(){return *lsp;}
1858 LS* operator->() { return lsp.operator->(); }
1859 const LS& operator*() const{return *lsp;}
1860 const LS* operator->() const{ return lsp.operator->();}
1861
1862 private:
1863 std::shared_ptr<LS> lsp;
1864 };
1865
1866
1867 // packaging of a default solver that should always work
1868 // in the sequential case : BCGS SSOR
1869 template<typename FS, typename ASS, SolverCategory::Category st = SolverCategory::sequential>
1870 class ISTLSolverBackend_IterativeDefault
1871 {
1872 public:
1873 // types exported
1874 typedef ISTLBackend_SEQ_BCGS_SSOR LS;
1875
1876 ISTLSolverBackend_IterativeDefault (const FS& fs, const ASS& ass, unsigned maxiter_=5000, int verbose_=1)
1877 {
1878 lsp = std::shared_ptr<LS>(new LS(maxiter_,verbose_));
1879 }
1880
1881 LS& getLS () {return *lsp;}
1882 const LS& getLS () const { return *lsp;}
1883 LS& operator*(){return *lsp;}
1884 LS* operator->() { return lsp.operator->(); }
1885 const LS& operator*() const{return *lsp;}
1886 const LS* operator->() const{ return lsp.operator->();}
1887
1888 private:
1889 std::shared_ptr<LS> lsp;
1890 };
1891
1892 // in the nonoverlapping case : BCGS SSORk
1893 template<typename FS, typename ASS>
1894 class ISTLSolverBackend_IterativeDefault<FS,ASS,SolverCategory::nonoverlapping>
1895 {
1896 public:
1897 // types exported
1899
1900 ISTLSolverBackend_IterativeDefault (const FS& fs, const ASS& ass, unsigned maxiter_=5000, int verbose_=1)
1901 {
1902 lsp = std::shared_ptr<LS>(new LS(ass.getGO(),maxiter_,3,verbose_));
1903 }
1904
1905 LS& getLS () {return *lsp;}
1906 const LS& getLS () const { return *lsp;}
1907 LS& operator*(){return *lsp;}
1908 LS* operator->() { return lsp.operator->(); }
1909 const LS& operator*() const{return *lsp;}
1910 const LS* operator->() const{ return lsp.operator->();}
1911
1912 private:
1913 std::shared_ptr<LS> lsp;
1914 };
1915
1916 // in the overlapping case : BCGS SSORk
1917 template<typename FS, typename ASS>
1918 class ISTLSolverBackend_IterativeDefault<FS,ASS,SolverCategory::overlapping>
1919 {
1920 public:
1921 // types exported
1922 typedef ISTLBackend_OVLP_BCGS_SSORk<typename FS::GFS, typename FS::CC> LS;
1923
1924 ISTLSolverBackend_IterativeDefault (const FS& fs, const ASS& ass, unsigned maxiter_=5000, int verbose_=1)
1925 {
1926 lsp = std::shared_ptr<LS>(new LS(fs.getGFS(),fs.getCC(),maxiter_,3,verbose_));
1927 }
1928
1929 LS& getLS () {return *lsp;}
1930 const LS& getLS () const { return *lsp;}
1931 LS& operator*(){return *lsp;}
1932 LS* operator->() { return lsp.operator->(); }
1933 const LS& operator*() const{return *lsp;}
1934 const LS* operator->() const{ return lsp.operator->();}
1935
1936 private:
1937 std::shared_ptr<LS> lsp;
1938 };
1939
1940 // packaging of a default solver that should always work
1941 // in the sequential case : BCGS SSOR
1942 template<typename FS, typename ASS, SolverCategory::Category st = SolverCategory::sequential>
1943 class ISTLSolverBackend_ExplicitDiagonal
1944 {
1945 public:
1946 // types exported
1948
1949 ISTLSolverBackend_ExplicitDiagonal (const FS& fs, const ASS& ass, unsigned maxiter_=5000, int verbose_=1)
1950 {
1951 lsp = std::shared_ptr<LS>(new LS());
1952 }
1953
1954 LS& getLS () {return *lsp;}
1955 const LS& getLS () const { return *lsp;}
1956 LS& operator*(){return *lsp;}
1957 LS* operator->() { return lsp.operator->(); }
1958 const LS& operator*() const{return *lsp;}
1959 const LS* operator->() const{ return lsp.operator->();}
1960
1961 private:
1962 std::shared_ptr<LS> lsp;
1963 };
1964
1965 // packaging of a default solver that should always work
1966 // in the sequential case : BCGS SSOR
1967 template<typename FS, typename ASS>
1968 class ISTLSolverBackend_ExplicitDiagonal<FS,ASS,SolverCategory::overlapping>
1969 {
1970 public:
1971 // types exported
1973
1974 ISTLSolverBackend_ExplicitDiagonal (const FS& fs, const ASS& ass, unsigned maxiter_=5000, int verbose_=1)
1975 {
1976 lsp = std::shared_ptr<LS>(new LS(fs.getGFS()));
1977 }
1978
1979 LS& getLS () {return *lsp;}
1980 const LS& getLS () const { return *lsp;}
1981 LS& operator*(){return *lsp;}
1982 LS* operator->() { return lsp.operator->(); }
1983 const LS& operator*() const{return *lsp;}
1984 const LS* operator->() const{ return lsp.operator->();}
1985
1986 private:
1987 std::shared_ptr<LS> lsp;
1988 };
1989
1990 // packaging of a default solver that should always work
1991 // in the sequential case : BCGS SSOR
1992 template<typename FS, typename ASS>
1993 class ISTLSolverBackend_ExplicitDiagonal<FS,ASS,SolverCategory::nonoverlapping>
1994 {
1995 public:
1996 // types exported
1998
1999 ISTLSolverBackend_ExplicitDiagonal (const FS& fs, const ASS& ass, unsigned maxiter_=5000, int verbose_=1)
2000 {
2001 lsp = std::shared_ptr<LS>(new LS(fs.getGFS()));
2002 }
2003
2004 LS& getLS () {return *lsp;}
2005 const LS& getLS () const { return *lsp;}
2006 LS& operator*(){return *lsp;}
2007 LS* operator->() { return lsp.operator->(); }
2008 const LS& operator*() const{return *lsp;}
2009 const LS* operator->() const{ return lsp.operator->();}
2010
2011 private:
2012 std::shared_ptr<LS> lsp;
2013 };
2014
2015
2016} // end namespace PDELab
2017 } // end namespace Dune
2018
2019#endif // DUNE_PDELAB_BOILERPLATE_PDELAB_HH
The AMG preconditioner.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:280
BasicType
Each entity can be tagged by one of these basic types plus its space dimension.
Definition: type.hh:286
@ cube
Cube element in any nonnegative dimension.
Definition: type.hh:288
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:287
static ToUniquePtr< Grid > read(const std::string &fileName, bool verbose=true, bool insertBoundarySegments=true)
Definition: gmshreader.hh:788
Provide a generic factory class for unstructured grids.
Definition: gridfactory.hh:269
virtual ToUniquePtr< GridType > createGrid()
Finalize grid creation and hand over the grid.
Definition: gridfactory.hh:327
@ dimensionworld
The dimension of the world the grid lives in.
Definition: grid.hh:393
ct ctype
Define type used for coordinates in grid module.
Definition: grid.hh:522
Dirichlet Constraints construction.
Definition: conforming.hh:38
convert a grid function space and a coefficient vector into a grid function
Definition: gridfunctionspaceutilities.hh:76
Standard grid operator implementation.
Definition: gridoperator.hh:36
Dune::PDELab::Backend::Matrix< MB, Domain, Range, JF > Jacobian
The type of the jacobian.
Definition: gridoperator.hh:47
Overlapping parallel conjugate gradient solver preconditioned with AMG smoothed by SSOR.
Definition: ovlpistlsolverbackend.hh:1258
Nonoverlapping parallel BiCGSTAB solver preconditioned by block SSOR.
Definition: novlpistlsolverbackend.hh:837
Nonoverlapping parallel CG solver preconditioned with AMG smoothed by SSOR.
Definition: novlpistlsolverbackend.hh:1075
Solver to be used for explicit time-steppers with (block-)diagonal mass matrix.
Definition: novlpistlsolverbackend.hh:636
Solver to be used for explicit time-steppers with (block-)diagonal mass matrix.
Definition: ovlpistlsolverbackend.hh:1010
Sequential conjugate gradient solver preconditioned with AMG smoothed by SSOR.
Definition: seqistlsolverbackend.hh:856
Solver to be used for explicit time-steppers with (block-)diagonal mass matrix.
Definition: seqistlsolverbackend.hh:661
A free function to provide the demangled class name of a given object or type as a string.
A few common exception classes.
@ conforming
Output conforming data.
Definition: common.hh:72
@ nonconforming
Output non-conforming data.
Definition: common.hh:80
Convenience header which includes all available VTK writers.
Some generic functions for pretty printing vectors and matrices.
Implementations of the inverse operator interface.
Utility to generate an array with a certain value.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:156
Grid< dim, dimworld, ct, GridFamily >::LeafGridView leafGridView(const Grid< dim, dimworld, ct, GridFamily > &grid)
leaf grid view for the given grid
Definition: grid.hh:809
@ ForwardCommunication
communicate as given in InterfaceType
Definition: gridenums.hh:169
@ InteriorBorder_All_Interface
send interior and border, receive all entities
Definition: gridenums.hh:86
void constraints(const GFS &gfs, CG &cg, const bool verbose=false)
construct constraints
Definition: constraints.hh:749
void set_nonconstrained_dofs(const CG &cg, typename XG::ElementType x, XG &xg)
Definition: constraints.hh:960
void set_constrained_dofs(const CG &cg, typename XG::ElementType x, XG &xg)
construct constraints from given boundary condition function
Definition: constraints.hh:796
void copy_constrained_dofs(const CG &cg, const XG &xgin, XG &xgout)
Definition: constraints.hh:936
void copy_nonconstrained_dofs(const CG &cg, const XG &xgin, XG &xgout)
Definition: constraints.hh:987
std::size_t degree(const Node &node)
Returns the degree of node as run time information.
Definition: nodeinterface.hh:71
Helpers for dealing with MPI.
Dune namespace.
Definition: alignedallocator.hh:14
The OneDGrid class.
Define general, extensible interface for operators. The available implementation wraps a matrix.
Various parser methods to get data into a ParameterTree object.
Define general preconditioner interface.
Dune::FieldVector< GV::Grid::ctype, GV::dimension > DomainType
domain type in dim-size coordinates
Definition: function.hh:50
Backend using (possibly nested) ISTL BCRSMatrices.
Definition: bcrsmatrixbackend.hh:188
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:119
Category
Definition: solvercategory.hh:21
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:23
@ nonoverlapping
Category for non-overlapping solvers.
Definition: solvercategory.hh:25
@ overlapping
Category for overlapping solvers.
Definition: solvercategory.hh:27
A class to construct structured cube and simplex grids using the grid factory.
A unique label for each type of element that can occur in a grid.
The UGGrid class.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)