pfc.cc 3.46 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
#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

#include "GenericOperatorTerm.h"

using namespace AMDiS;

class PfcPC : public PhaseFieldCrystal
{
public:
  typedef PhaseFieldCrystal super;
  
public:
  PfcPC(std::string name) : PhaseFieldCrystal(name) { }
  
  /// initialize the preconditioners, i.e. set parameters
  void initData() 
  {
    super::initData();

    // sequential PFC preconditioner
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
    PetscPreconPfc* runner = dynamic_cast<PetscPreconPfc*>(prob->getSolver()->getRunner());
    if (runner) {
      dynamic_cast<PetscSolver<PetscPreconPfc>*>(prob->getSolver())->setNested(true);
      runner->setData(getTau());	
    }
#endif

    // parallel PFC preconditioner
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    Parallel::PetscSolverPfc* solver = dynamic_cast<Parallel::PetscSolverPfc*>(prob->getSolver());
    if (solver)
      solver->setData(getTau());
#endif
      
    // sequential PFC preconditioner using MTL    
#if (!defined HAVE_SEQ_PETSC) && (!defined HAVE_PETSC) && (!defined HAVE_PARALLEL_DOMAIN_AMDIS)
    using AMDiS::extensions::MTLPreconPfc;
    MTLPreconPfc* precon = dynamic_cast<MTLPreconPfc*>(prob->getSolver()->getRightPrecon());
    if (precon)
      precon->setData(getTau());	
#endif
  }
  
  /// generate initial solution for evolution equation
  void solveInitialProblem(AdaptInfo *adaptInfo)
  { FUNCNAME("PFC_Demo::solveInitialProblem()");

    Flag initFlag = initDataFromFile(adaptInfo);
    if (initFlag.isSet(DATA_ADOPTED))
      return;
    
    double amplitude = 0.1;
    Parameters::get(name + "->density amplitude",amplitude);
      
    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;
  
  // add preconditioner / solver to the parameter list. Must be added before problem is initialized.
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
  CreatorMap<LinearSolver>::addCreator("petsc_pfc", new PetscSolver<PetscPreconPfc>::Creator);
#endif
  
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
  CreatorMap<LinearSolver>::addCreator("p_petsc_pfc", new Parallel::PetscSolverPfc::Creator);
#endif
  
#if (!defined HAVE_SEQ_PETSC) && (!defined HAVE_PETSC) && (!defined HAVE_PARALLEL_DOMAIN_AMDIS)
  using AMDiS::extensions::MTLPreconPfc;
  CreatorMap<BasePreconditioner>::addCreator("pfc", new MTLPreconPfc::Creator);
#endif
  
  // 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);
  }
  
  pfcProb.initTimeInterface(); // fill operators and BC
  int error_code = adaptInstat.adapt(); 

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