pfc.cc 3 KB
Newer Older
1 2 3 4
#include "AMDiS.h"
#include "Helpers.h"
#include "PhaseFieldCrystal.h"

Praetorius, Simon's avatar
Praetorius, Simon committed
5
#if defined(USE_SEQ_PETSC)
6
#include "preconditioner/PetscPreconPfc.h"
Praetorius, Simon's avatar
Praetorius, Simon committed
7
#elif defined(USE_PARALLEL_PETSC)
8
#include "preconditioner/PetscSolverPfc.h"
Praetorius, Simon's avatar
Praetorius, Simon committed
9
#elif defined(USE_MTL)
10 11 12
#include "preconditioner/MTLPreconPfc.h"
#endif

13
#include "Expressions.h"
14
#include "ProblemStat.h"
15 16 17

using namespace AMDiS;

18
class PfcPC : public base_problems::detail::PhaseFieldCrystal<ProblemStat>
19 20
{
public:
21
  typedef base_problems::detail::PhaseFieldCrystal<ProblemStat> super;
22

23
public:
24
  PfcPC(std::string name) : super(name) { }
25

26
  /// initialize the preconditioners, i.e. set parameters
27
  void finalizeData() override
28
  {
29
    super::finalizeData();
30

Praetorius, Simon's avatar
Praetorius, Simon committed
31
#if defined(USE_SEQ_PETSC)
32
    // sequential PFC preconditioner
33 34
    PetscPreconPfc* precon = dynamic_cast<PetscPreconPfc*>(prob->getSolver()->getRightPrecon());
    if (precon) {
35
      precon->setData(getTau(), M0);
36
    }
Praetorius, Simon's avatar
Praetorius, Simon committed
37
#elif defined(USE_PARALLEL_PETSC)
38 39
    // parallel PFC preconditioner
    Parallel::PetscSolverPfc* solver = dynamic_cast<Parallel::PetscSolverPfc*>(prob->getSolver());
Praetorius, Simon's avatar
Praetorius, Simon committed
40
    if (solver) {
41
      solver->setData(getTau(), M0);
Praetorius, Simon's avatar
Praetorius, Simon committed
42 43 44 45 46 47 48
    }
#elif defined(USE_MTL)
    // mtl4 preconditioner
    MTLPreconPfc* precon = dynamic_cast<MTLPreconPfc*>(prob->getSolver()->getRightPrecon());
    if (precon) {
      precon->setData(getTau(), M0);
    }
49 50
#endif
  }
51

52
  /// generate initial solution for evolution equation
53
  void solveInitialProblem(AdaptInfo *adaptInfo) override
54
  {
55 56 57
    Flag initFlag = initDataFromFile(adaptInfo);
    if (initFlag.isSet(DATA_ADOPTED))
      return;
58

59 60
    double amplitude = 0.1;
    Parameters::get(name + "->density amplitude",amplitude);
61

62 63 64 65 66 67 68 69 70 71 72
    DOFVector<double>* rho = prob->getSolution()->getDOFVector(1);
    *rho << eval(new Random(density, amplitude));
  }
};


int main(int argc, char** argv)
{ FUNCNAME("main");

  AMDiS::init(argc, argv);
  Timer t;
73

74
  // add preconditioner / solver to the parameter list. Must be added before problem is initialized.
Praetorius, Simon's avatar
Praetorius, Simon committed
75
#if defined(USE_SEQ_PETSC)
76
  CreatorMap<PetscPreconditionerNested>::addCreator("pfc", new PetscPreconPfc::Creator);
Praetorius, Simon's avatar
Praetorius, Simon committed
77
#elif defined(USE_PARALLEL_PETSC)
78
  CreatorMap<LinearSolverInterface>::addCreator("p_petsc_pfc", new Parallel::PetscSolverPfc::Creator);
Praetorius, Simon's avatar
Praetorius, Simon committed
79 80
#elif defined(USE_MTL)
  CreatorMap<typename MTLPreconPfc::precon_base>::addCreator("pfc", new MTLPreconPfc::Creator);
81
#endif
82

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
  // create and initialize the PFC BaseProblem
  PfcPC pfcProb("pfc");
  pfcProb.initialize(INIT_ALL);

  // Adapt-Infos
  AdaptInfo adaptInfo("adapt", pfcProb.getNumComponents());
  AdaptInstationary adaptInstat("adapt", pfcProb, adaptInfo, pfcProb, adaptInfo);

  // Scale Mesh
  bool scaleMesh = false;
  Initfile::get("mesh->scale mesh",scaleMesh);
  if (scaleMesh) {
    WorldVector<double> scale; scale.set(1.0);
    Initfile::get("mesh->dimension",scale);
    Helpers::scaleMesh(pfcProb.getMesh(), scale);
  }
99

100
  pfcProb.initTimeInterface(); // fill operators and BC
101
  int error_code = adaptInstat.adapt();
102

103
  MSG("elapsed time= %f sec\n", t.elapsed());
104 105 106
  AMDiS::finalize();
  return error_code;
}