pfc.cc 3.81 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include "AMDiS.h"
#include "Helpers.h"
#include "PhaseFieldCrystal.h"

#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
#include "preconditioner/PetscPreconPfc.h"
#endif
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
#include "preconditioner/PetscSolverPfc.h"
#endif
#if (!defined HAVE_SEQ_PETSC) && (!defined HAVE_PETSC) && (!defined HAVE_PARALLEL_DOMAIN_AMDIS)
#include "preconditioner/MTLPreconPfc.h"
#endif

15
#include "Expressions.h"
16
#include "ProblemStat.h"
17 18 19

using namespace AMDiS;

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

25
public:
26
  PfcPC(std::string name) : super(name) { }
27

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

33
#ifdef USE_PRECON
34 35 36

    // sequential PFC preconditioner
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
37 38
    PetscPreconPfc* precon = dynamic_cast<PetscPreconPfc*>(prob->getSolver()->getRightPrecon());
    if (precon) {
39
      precon->setData(getTau(), M0);
40
    }
41 42
//     PetscPreconPfcDiag* precon2 = dynamic_cast<PetscPreconPfcDiag*>(prob->getSolver()->getRightPrecon());
//     if (precon2) {
43
//       precon2->setData(getTau(), M0);
44 45 46 47
    }
#elif !defined(HAVE_PARALLEL_DOMAIN_AMDIS)
     MTLPreconPfc* precon = dynamic_cast<MTLPreconPfc*>(prob->getSolver()->getRightPrecon());
     if (precon)
48
	precon->setData(getTau(), M0);
49
#else
50 51 52
    // parallel PFC preconditioner
    Parallel::PetscSolverPfc* solver = dynamic_cast<Parallel::PetscSolverPfc*>(prob->getSolver());
    if (solver)
53
      solver->setData(getTau(), M0);
54

55 56 57
//     Parallel::PetscSolverPfcDiag* solver2 = dynamic_cast<Parallel::PetscSolverPfcDiag*>(prob->getSolver());
//     if (solver2)
//       solver2->setData(getTau(), M0);
58
#endif
59

60 61
#endif
  }
62

63
  /// generate initial solution for evolution equation
64
  void solveInitialProblem(AdaptInfo *adaptInfo) override
65
  {
66 67 68
    Flag initFlag = initDataFromFile(adaptInfo);
    if (initFlag.isSet(DATA_ADOPTED))
      return;
69

70 71
    double amplitude = 0.1;
    Parameters::get(name + "->density amplitude",amplitude);
72

73 74 75 76 77 78 79 80 81 82 83
    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;
84

85
#ifdef USE_PRECON
86

87 88
  // add preconditioner / solver to the parameter list. Must be added before problem is initialized.
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
89 90 91 92 93 94 95 96
  CreatorMap<PetscPreconditionerNested>::addCreator("pfc", new PetscPreconPfc::Creator);
//   CreatorMap<PetscPreconditionerNested>::addCreator("pfc_diag", new PetscPreconPfcDiag::Creator);
#elif !defined(HAVE_PARALLEL_DOMAIN_AMDIS)
  CreatorMap<typename MTLPreconPfc::precon_base>::addCreator("pfc", new MTLPreconPfc::Creator);
//   CreatorMap<typename MTLPreconPfc_Diag::base_precon>::addCreator("pfc", new MTLPreconPfc::Creator);
#else
  CreatorMap<LinearSolverInterface>::addCreator("p_petsc_pfc", new Parallel::PetscSolverPfc::Creator);
//   CreatorMap<LinearSolverInterface>::addCreator("p_petsc_pfc_diag", new Parallel::PetscSolverPfcDiag::Creator);
97
#endif
98

99
#endif
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
  // 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);
  }
117

118
  pfcProb.initTimeInterface(); // fill operators and BC
119
  int error_code = adaptInstat.adapt();
120

121
  MSG("elapsed time= %f sec\n", t.elapsed());
122 123 124
  AMDiS::finalize();
  return error_code;
}