stationary-poisson.cc 20.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
// -*- tab-width: 4; indent-tabs-mode: nil -*-
/** \file
    \brief High-level test with Poisson equation
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

// enable basis function caching for faster assembly
#define USECACHE 1

#include<iostream>
#include<vector>
#include<map>
#include<chrono>
#include<tbb/task_scheduler_init.h>
#include<dune/common/parametertreeparser.hh>
#include<dune/common/parallel/mpihelper.hh>
#include<dune/common/exceptions.hh>
#include<dune/common/fvector.hh>
#include<dune/common/static_assert.hh>
#include<dune/common/timer.hh>
#include<dune/grid/yaspgrid.hh>
#include<dune/istl/bvector.hh>
#include<dune/istl/operators.hh>
#include<dune/istl/solvers.hh>
#include<dune/istl/preconditioners.hh>
#include<dune/istl/io.hh>
#include<dune/istl/paamg/amg.hh>
#include<dune/istl/superlu.hh>
#include<dune/grid/io/file/vtk/subsamplingvtkwriter.hh>

#include<dune/pdelab/finiteelementmap/monomfem.hh>
#include<dune/pdelab/finiteelementmap/opbfem.hh>
#include<dune/pdelab/finiteelementmap/qkdg.hh>
#include<dune/pdelab/finiteelementmap/pkfem.hh>
#include<dune/pdelab/finiteelementmap/p0fem.hh>
#include<dune/pdelab/constraints/common/constraints.hh>
#include<dune/pdelab/constraints/conforming.hh>
#include<dune/pdelab/constraints/p0.hh>
#include<dune/pdelab/gridfunctionspace/gridfunctionspace.hh>
#include<dune/pdelab/gridfunctionspace/gridfunctionspaceutilities.hh>
#include<dune/pdelab/gridfunctionspace/interpolate.hh>
#include<dune/pdelab/common/function.hh>
#include<dune/pdelab/common/functionutilities.hh>
#include<dune/pdelab/common/vtkexport.hh>
#include<dune/pdelab/backend/istlvectorbackend.hh>
#include<dune/pdelab/backend/istlmatrixbackend.hh>
#include<dune/pdelab/backend/istlsolverbackend.hh>
#include<dune/pdelab/localoperator/convectiondiffusionparameter.hh>
#include<dune/pdelab/localoperator/convectiondiffusiondg.hh>
#include<dune/pdelab/localoperator/diffusionccfv.hh>
#include<dune/pdelab/stationary/linearproblem.hh>
#include<dune/pdelab/gridoperator/gridoperator.hh>


#include <dune/grid/utility/partitioning/ranged.hh>
#include "../models/df_convectiondiffusionccfv.hh"
#include "../models/df_darcy_CCFV.hh"
#include "../models/maxvelocity.hh"
#include "../models/cdefastdg.hh"
#include "../models/l2gl.hh"

#include <dune/pdelab/common/lockmanager.hh>
#include <dune/pdelab/gridoperator/tbb.hh>

#include "../models/l2ob.hh"

#include <dune/common/archive.hh>

#include <dune/common/memory/blocked_allocator.hh>

#include <dune/pdelab/backend/istl/blockvectorbackend.hh>
#include <dune/pdelab/backend/istl/bellmatrixbackend.hh>

#include <dune/pdelab/ordering/redblackdg.hh>
#include <dune/pdelab/ordering/permutedordering.hh>

#include<dune/istl/preconditioners/sequentialblockjacobi.hh>
//#include<dune/istl/preconditioners/sequentialsor.hh>

#ifndef SIMD_BLOCK_SIZE
#define SIMD_BLOCK_SIZE 16
#endif

/*
  With this class you can specify how to distribute the total number of
  processes to the YASP grid by passing a vector of type
  Dune::FieldVector<int,dim> to the constructor.
*/
template<int dim, class iTupel>
class YaspPartition : public Dune::YLoadBalance<dim>
{
private:
  const iTupel& yasppartitions;

public:
  //constructor:
  YaspPartition( const iTupel& yasppartitions_ )
    : yasppartitions( yasppartitions_ )
  {
  }

  void loadbalance (const iTupel& size, int P, iTupel& dims) const
  {
    dims = yasppartitions;
  }
};




template<class GV>
void test (const GV& gv)
{
/*
  typedef typename GV::Grid::ctype DF;
  typedef double RF;
  const int dim = GV::dimension;
  Dune::Timer watch;

  // instantiate finite element maps
  typedef Dune::PDELab::P0LocalFiniteElementMap<DF,RF,dim> FEM;
  FEM fem(Dune::GeometryType(Dune::GeometryType::cube,dim)); // works only for cubes

  // make function space
  typedef Dune::PDELab::ISTLVectorBackend<> VBE;
  typedef Dune::PDELab::GridFunctionSpace<GV,FEM,Dune::PDELab::P0ParallelConstraints,VBE> GFS;
  watch.reset();
  GFS gfs(gv,fem);

  // local operator
  watch.reset();
  typedef k_A<GV,RF> KType;
  KType k(gv);
  typedef A0_A<GV,RF> A0Type;
  A0Type a0(gv);
  typedef F_A<GV,RF> FType;
  FType f(gv);
  typedef B_A<GV> BType;
  BType b(gv);
  typedef J_A<GV,RF> JType;
  JType j(gv);
  typedef G_A<GV,RF> GType;
  GType g(gv);
  typedef Dune::PDELab::DiffusionCCFV<KType,A0Type,FType,BType,JType,GType> LOP;
  LOP lop(k,a0,f,b,j,g);

  // make constraints map and initialize it from a function
  typedef typename GFS::template ConstraintsContainer<RF>::Type CC;
  CC cc;
  cc.clear();
  Dune::PDELab::constraints(g,gfs,cc,false);

  // grid operator
  typedef Dune::PDELab::ISTLMatrixBackend MBE;
  typedef Dune::PDELab::GridOperator<GFS,GFS,LOP,MBE,RF,RF,RF,CC,CC> GO;
  GO go(gfs,cc,gfs,cc,lop);

  // make coefficent Vector and initialize it from a function
  typedef typename GO::Traits::Domain V;
  V x(gfs);
  x = 0.0;
  Dune::PDELab::interpolate(g,gfs,x);

  // typedef  Dune::PDELab::ISTLBackend_BCGS_AMG_SSOR<GO> LS;
  // LS ls(gfs,5000,3);
  typedef Dune::PDELab::ISTLBackend_OVLP_CG_SSORk<GFS,CC> LS;
  LS ls(gfs,cc,10,5,1);
  typedef Dune::PDELab::StationaryLinearProblemSolver<GO,LS,V> SLP;
  SLP slp(go,x,ls,1e-6);
  slp.apply();

  // make discrete function object
  typedef Dune::PDELab::DiscreteGridFunction<GFS,V> DGF;
  DGF dgf(gfs,x);
*/
}

template<typename GV, typename RF>
class Parameter
{
  typedef Dune::PDELab::ConvectionDiffusionBoundaryConditions::Type BCType;

public:
  typedef Dune::PDELab::ConvectionDiffusionParameterTraits<GV,RF> Traits;

  //! tensor diffusion coefficient
  typename Traits::PermTensorType
  A (const typename Traits::ElementType& e, const typename Traits::DomainType& x) const
  {
    typename Traits::PermTensorType I;
    for (std::size_t i=0; i<Traits::dimDomain; i++)
      for (std::size_t j=0; j<Traits::dimDomain; j++)
        I[i][j] = (i==j) ? 1 : 0;
    return I;
  }

  //! velocity field
  typename Traits::RangeType
  b (const typename Traits::ElementType& e, const typename Traits::DomainType& x) const
  {
    typename Traits::RangeType v(0.0);
    return v;
  }

  //! sink term
  typename Traits::RangeFieldType
  c (const typename Traits::ElementType& e, const typename Traits::DomainType& x) const
  {
    return 0.0;
  }

  //! source term
  typename Traits::RangeFieldType
  f (const typename Traits::ElementType& e, const typename Traits::DomainType& x) const
  {
    typename Traits::DomainType xglobal = e.geometry().global(x);
    typename Traits::RangeFieldType norm = xglobal.two_norm2();
    return (2.0*GV::dimension-4.0*norm)*exp(-norm);
  }

  //! boundary condition type function
  BCType
  bctype (const typename Traits::IntersectionType& is, const typename Traits::IntersectionDomainType& x) const
  {
    return Dune::PDELab::ConvectionDiffusionBoundaryConditions::Dirichlet;
  }

  //! Dirichlet boundary condition value
  typename Traits::RangeFieldType
  g (const typename Traits::ElementType& e, const typename Traits::DomainType& x) const
  {
    typename Traits::DomainType xglobal = e.geometry().global(x);
    typename Traits::RangeFieldType norm = xglobal.two_norm2();
    return exp(-norm);
  }

  //! Neumann boundary condition
  typename Traits::RangeFieldType
  j (const typename Traits::IntersectionType& is, const typename Traits::IntersectionDomainType& x) const
  {
    return 0.0;
  }

  //! outflow boundary condition
  typename Traits::RangeFieldType
  o (const typename Traits::IntersectionType& is, const typename Traits::IntersectionDomainType& x) const
  {
    return 0.0;
  }
};


//! solve problem with DG method
template<class GV, class PROBLEM, int degree, int blocksize>
void runDG ( const GV& gv,
             //const FEM& fem,
             PROBLEM& problem,
             std::string basename,
             int level,
             std::string method,
             std::string weights,
             const Dune::ParameterTree& params)
{

  std::cout << "blocked linear algebra" << std::endl;
  std::cout << "SIMD block size: " << SIMD_BLOCK_SIZE << std::endl;

  std::cout << "DG order: " << degree << std::endl;
  std::cout << "DG block size: " << blocksize << std::endl;

  Dune::Timer timer;

  // coordinate and result type
  typedef double Real;
  const int dim = GV::Grid::dimension;

  std::stringstream fullname;
  fullname << basename << "_" << method << "_w" << weights << "_k" << degree << "_dim" << dim << "_level" << level << "_simd" << SIMD_BLOCK_SIZE;

  std::size_t chunk_size = params.get<std::size_t>("tunables.host.chunk_size",512);

  std::cout << "host thread chunk size: " << chunk_size << std::endl;

  // ****************************** Allocators ******************************

  typedef Dune::Memory::blocked_cache_aligned_allocator<double,std::size_t,SIMD_BLOCK_SIZE> HostAllocator;

  // ************************************************************************

  // make grid function space
  typedef Dune::PDELab::P0ParallelConstraints CON;
  //const Dune::PDELab::ISTLParameters::Blocking blocking
  //  = Dune::PDELab::ISTLParameters::static_blocking;
  //typedef Dune::PDELab::ISTLVectorBackend<blocking,blocksize> VBE;

  typedef Dune::PDELab::istl::BlockVectorBackend<HostAllocator> VBE;
  VBE vbe(blocksize);

  typedef Dune::PDELab::DefaultLeafOrderingTag OrderingTag;
  OrderingTag orderingTag;

  /*
  typedef Dune::PDELab::ordering::Permuted<
    Dune::PDELab::DefaultLeafOrderingTag
    > OrderingTag;

  OrderingTag orderingTag;
  std::size_t black_offset;

  std::tie(orderingTag.template permuted<1>().permutation(),black_offset) = Dune::PDELab::redBlackDGOrdering(gv);

  std::cout << "offset of black partition: " << black_offset << std::endl;
  */

#if not SINGLETHREAD
  // Partitioning
  typedef Dune::RangedPartitioning<GV, 0> Partitioning;
  std::shared_ptr<Partitioning> partitioning = std::make_shared<Partitioning>
    (gv, tbb::task_scheduler_init::default_num_threads());

  // Locking
  typedef Dune::PDELab::PerElementLockManager<
    GV, std::mutex> LockManager;
  std::shared_ptr<LockManager> lockManager =
    std::make_shared<LockManager>(gv);
#endif // !SINGLETHREAD


  std::cout << "Creating GFS and Ordering... " << std::flush;

  typedef Dune::PDELab::QkDGGLLocalFiniteElementMap<Real,Real,degree,dim> FEM;
  FEM fem;

  typedef Dune::PDELab::GridFunctionSpace<GV,FEM,CON,VBE,OrderingTag> GFS;
  GFS gfs(gv,fem,vbe,orderingTag);
  gfs.ordering();

  std::cout << timer.elapsed() << std::endl;
  std::cout << gfs.ordering().size() << " DOFs, " << gfs.ordering().blockCount() << " blocks" << std::endl;

  typedef Dune::PDELab::ConvectionDiffusionDGFast<PROBLEM,degree,2*degree+1,true,true,false,false,true,true> LOP;
  LOP lop(problem,Dune::PDELab::ConvectionDiffusionDGFastMethod::SIPG,Dune::PDELab::ConvectionDiffusionDGFastWeights::weightsOn,3.0);

  typedef typename Dune::PDELab::istl::BELLMatrixBackend<HostAllocator> MBE;

  typedef Dune::PDELab::ConvectionDiffusionDirichletExtensionAdapter<PROBLEM> G;
  G g(gv,problem);
  typedef typename GFS::template ConstraintsContainer<Real>::Type CC;
  CC cc;

  timer.reset();
  std::cout << "Evaluating constraints... " << std::flush;

  Dune::PDELab::constraints(g,gfs,cc,false);

  std::cout << timer.elapsed() << std::endl;
  timer.reset();


#if SINGLETHREAD
  typedef Dune::PDELab::GridOperator<GFS,GFS,LOP,MBE,Real,Real,Real,CC,CC> GO;
  GO go(gfs,cc,gfs,cc,lop);
#else
  typedef Dune::PDELab::TBBGridOperator<
    Partitioning,
    GFS,GFS,
    LOP,
    MBE,Real,Real,Real,
    LockManager,
    CC,CC
    > GO;
  GO go(gfs,cc,gfs,cc,lop,lockManager);
  go.assembler().setPartitioning(partitioning);
#endif

  // make a vector of degree of freedom vectors and initialize it with Dirichlet extension
  typedef typename GO::Traits::Domain U;
  U u(gfs,0.0);
  raw(u).setChunkSize(chunk_size);

  std::shared_ptr<U> r;
  std::shared_ptr<typename GO::Traits::Jacobian> mat;

  if (!params.get<bool>("io.system.load",false))
    {
      r = std::make_shared<U>(gfs,0.0);
      raw(*r).setChunkSize(chunk_size);

      timer.reset();
      std::cout << "Evaluating residual... " << std::flush;

      go.residual(u,*r);

      std::cout << timer.elapsed() << std::endl;

      timer.reset();
      std::cout << "Creating matrix... " << std::flush;

      mat = std::make_shared<typename GO::Traits::Jacobian>(
        go,
        Dune::PDELab::istl::MatrixParameters(7) // we can hardcode the entries per row for this problem
        );

      std::cout << timer.elapsed() << std::endl;

      std::cout << raw(*mat).layout().nonzeros() << " effective non-zero entries" << std::endl;

      timer.reset();
      std::cout << "Evaluating jacobian... " << std::flush;

      raw(*mat).setChunkSize(chunk_size);
      go.jacobian(u,*mat);

      std::cout << timer.elapsed() << std::endl;

      if (params.get<bool>("io.system.dump",false))
        {
          std::cout << "Dumping assembled system to '" << params["io.system.file"] << "'..." << std::endl;

          std::ofstream f(params["io.system.file"],std::ios::binary);
          Dune::BinaryOutStreamArchive<std::ofstream> ar(f);
          ar & Dune::PDELab::istl::raw(*r);
          ar & Dune::PDELab::istl::raw(*mat);
        }
    }
  else
    {
      std::cout << "Loading assembled system from '" << params["io.system.file"] << "'..." << std::endl;

      std::ifstream f(params["io.system.file"],std::ios::binary);
      Dune::BinaryInStreamArchive<std::ifstream> ar(f);

      std::cout << "Loading residual..." << std::endl;

      r = std::make_shared<U>(gfs,Dune::PDELab::tags::unattached_container());
      auto r_raw = std::make_shared<typename Dune::PDELab::istl::raw_type<U>::type>();
      ar & *r_raw;
      r->attach(r_raw);
      raw(*r).setChunkSize(chunk_size);

      std::cout << "Loading matrix..." << std::endl;

      mat = std::make_shared<typename GO::Traits::Jacobian>(Dune::PDELab::tags::attached_container());
      ar & Dune::PDELab::istl::raw(*mat);
      raw(*mat).setChunkSize(chunk_size);
    }

  // make linear solver and solve problem
  typedef Dune::PDELab::OverlappingOperator<
    CC,
    typename GO::Traits::Jacobian,
    typename GO::Traits::Domain,
    typename GO::Traits::Range
    > POP;
  POP pop(cc,*mat);

  Dune::PDELab::istl::ParallelHelper<GFS> helper(gfs);

  typedef Dune::PDELab::OverlappingScalarProduct<
    GFS,
    typename GO::Traits::Domain
    > PSP;
  PSP psp(gfs,helper);

  /*
  typedef Dune::ISTL::SequentialRedBlackBlockSOR<
    typename GO::Traits::Jacobian::Container,
    typename U::Container,
    typename U::Container
    > PC;
    PC pc(raw(mat),black_offset,1.0,false,5);
  */

  typedef Dune::ISTL::SequentialBlockJacobi<
    typename GO::Traits::Jacobian::Container,
    typename U::Container,
    typename U::Container
    > PC;
  PC pc(
    raw(*mat),
    params.get<double>("solver.jacobi.relaxation_factor",1.0),
    params.get<bool>("solver.jacobi.lu_pivot",false),
    params.get<int>("solver.jacobi.iterations",5)
    );

  typedef Dune::PDELab::OverlappingWrappedPreconditioner<
    CC,
    GFS,
    PC
    > PPC;
  PPC ppc(gfs,pc,cc,helper);

  U z(gfs,0.0);
  raw(z).setChunkSize(chunk_size);

  int verbosity = gfs.gridView().comm().rank() == 0 ? params.get<int>("solver.verbosity",2) : 0;

  typedef decltype(std::chrono::high_resolution_clock::now()) TimePoint;

  TimePoint solve_start, solve_end;

  Dune::InverseOperatorResult stat;

  if (method=="SIPG")
    {
      typedef Dune::CGSolver<U> Solver;

      Solver solver(
        pop,
        psp,
        ppc,
        params.get<double>("solver.reduction",1e-10),
        params.get<int>("solver.iterations",500),
        verbosity
        );

      solve_start = std::chrono::high_resolution_clock::now();
      solver.apply(z,*r,stat);
    }
  else
    {
      typedef Dune::BiCGSTABSolver<U> Solver;

      Solver solver(
        pop,
        psp,
        ppc,
        params.get<double>("solver.reduction",1e-10),
        params.get<int>("solver.iterations",500),
        verbosity
        );

      solve_start = std::chrono::high_resolution_clock::now();
      solver.apply(z,*r,stat);
    }

  solve_end = std::chrono::high_resolution_clock::now();

  u -= z;

  auto solve_time = std::chrono::duration_cast<std::chrono::duration<double> >(solve_end - solve_start);

  if (verbosity > 0)
    {
      std::cout << "Solver wallclock time: " <<  solve_time.count() << std::endl;
      std::cout << "wallclock time / iteration: " <<  (solve_time.count() / stat.iterations) << std::endl;
    }

  if(params.get<bool>("io.vtk",false)){
    typedef Dune::PDELab::DiscreteGridFunction<GFS,U> UDGF;
    UDGF udgf(gfs,u);
    Dune::SubsamplingVTKWriter<GV> vtkwriter(gv,std::max(0,degree-1));
    vtkwriter.addVertexData(new Dune::PDELab::VTKGridFunctionAdapter<UDGF>(udgf,"u_h"));
    vtkwriter.write(fullname.str(),Dune::VTK::appendedraw);
  }

}



int main(int argc, char** argv)
{
  try
    {

      Dune::ParameterTree params;
      Dune::ParameterTreeParser::readINITree(argv[1],params);

      // start up TBB task scheduler
      int threads = params.get<int>("tunables.host.threads",tbb::task_scheduler_init::default_num_threads());
      tbb::task_scheduler_init tbb_task_scheduler_init(threads);

      //Maybe initialize Mpi
      Dune::MPIHelper& helper = Dune::MPIHelper::instance(argc, argv);
      if(Dune::MPIHelper::isFake)
        std::cout<< "This is a sequential program." << std::endl;
      else
        {
          if(helper.rank()==0)
            std::cout << "parallel run on " << helper.size() << " process(es)" << std::endl;
        }


      if (helper.rank() == 0)
        std::cout << "Using " << threads << " threads" << std::endl;

      int degree_dyn = params.get<int>("discretization.order");
      int nx = params.get<int>("mesh.xcells");
      int ny = params.get<int>("mesh.ycells");
      int nz = params.get<int>("mesh.zcells");

      std::cout << "mesh size: " << nx << "x" << ny << "x" << nz << std::endl;

      int px = params.get<int>("mesh.xpartitions",0);
      int py = params.get<int>("mesh.ypartitions",0);
      int pz = params.get<int>("mesh.zpartitions",0);

      int overlap = params.get<int>("mesh.overlap",1);

      const int dim = 3;
      Dune::FieldVector<double,dim> L(1.0);
      std::array<int,dim> N;
      N[0] = nx; N[1] = ny; N[2] = nz;
      std::bitset<dim> B(false);

      typedef YaspPartition<dim,Dune::FieldVector<int,dim>> YP;
      YP* yp = (YP*) Dune::YaspGrid<dim>::defaultLoadbalancer();
      if( px*py*pz==0 ){
        // If px,py,pz were not specified choose the default load balancer
        if( helper.rank() == 0 )
          std::cout << "Using default partitioning of YASP." << std::endl;
      }

      else if( px*py*pz != helper.size() ){
        // If px*py*pz is not equal to the available number of processors
        // wrong input, stop and output warning!
        if( helper.rank()==0 )
          std::cerr << "Wrong input: px*py*pz != np" << std::endl;
        exit(1);
      }

      else {
        Dune::FieldVector<int,dim> yasppartitions;
        yasppartitions[0] = px;
        yasppartitions[1] = py;
        yasppartitions[2] = pz;
        yp = new YP(yasppartitions);
        if( helper.rank() == 0 )
          std::cout << "Partitioning of YASP: " << yasppartitions << std::endl;
      }

      Dune::YaspGrid<dim> grid(helper.getCommunicator(),L,N,B,overlap,yp);

      typedef Dune::YaspGrid<dim> Grid;
      typedef Grid::LeafGridView GV;

      const GV& gv=grid.leafGridView();
      typedef Parameter<GV,double> PROBLEM;
      PROBLEM problem;

      if (degree_dyn==0) {
        test(gv);
      }
      if (degree_dyn==1) {
        const int degree=1;
        //typedef Dune::PDELab::QkDGLocalFiniteElementMap<Grid::ctype,double,degree,dim> FEMDG;
        //FEMDG femdg;
        const int blocksize = Dune::QkStuff::QkSize<degree,dim>::value;
        runDG<GV,PROBLEM,degree,blocksize>(gv,problem,"CUBE",0,"SIPG","ON",params);
      }
      if (degree_dyn==2) {
        const int degree=2;
        //typedef Dune::PDELab::QkDGLocalFiniteElementMap<Grid::ctype,double,degree,dim> FEMDG;
        //FEMDG femdg;
        const int blocksize = Dune::QkStuff::QkSize<degree,dim>::value;
        runDG<GV,PROBLEM,degree,blocksize>(gv,problem,"CUBE",0,"SIPG","ON",params);
      }
      if (degree_dyn==3) {
        const int degree=3;
        //typedef Dune::PDELab::QkDGLocalFiniteElementMap<Grid::ctype,double,degree,dim> FEMDG;
        //FEMDG femdg;
        const int blocksize = Dune::QkStuff::QkSize<degree,dim>::value;
        runDG<GV,PROBLEM,degree,blocksize>(gv,problem,"CUBE",0,"SIPG","ON",params);
      }
    }
  catch (Dune::Exception &e)
    {
      std::cerr << "Dune reported error: " << e << std::endl;
      return 1;
    }
  catch (...)
    {
      std::cerr << "Unknown exception thrown!" << std::endl;
      return 1;
    }
}