pfc_rb.cc 7.69 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
#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 PFC_RosenbrockStationary : public RosenbrockStationary
{
public:
  PFC_RosenbrockStationary(std::string name) : RosenbrockStationary(name) {};
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  void addTimeOperator(int row, int col) override
  {
    FUNCNAME("PFC_RosenbrockStationary::addTimeOperator()");
    MSG("PFC_RosenbrockStationary::addTimeOperator()\n");

    Operator *op = new Operator(componentSpaces[row], componentSpaces[col]);
    addZOT(op, 1.0 / rm->getGamma() );
    ProblemStat::addMatrixOperator(op, row, col);

    Operator *opRhs = new Operator(componentSpaces[row]);
    addZOT(opRhs, valueOf(timeRhsVec->getDOFVector(col)) );
    ProblemStat::addVectorOperator(opRhs, row, tauPtr, tauPtr);
  }
};

class PfcPC : public base_problems::detail::PhaseFieldCrystal<PFC_RosenbrockStationary>
{
public:
  typedef base_problems::detail::PhaseFieldCrystal<PFC_RosenbrockStationary> super;
43

44
45
public:
  PfcPC(std::string name) : super(name) { }
46

47
48
49
50
51
52
53
54
55
56
  /// initialize the preconditioners, i.e. set parameters
  void initData() override
  {
    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);
57
      runner->setData(getTau());
58
59
60
61
62
63
64
65
66
    }
#endif

    // parallel PFC preconditioner
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    Parallel::PetscSolverPfc* solver = dynamic_cast<Parallel::PetscSolverPfc*>(prob->getSolver());
    if (solver)
      solver->setData(getTau());
#endif
67
68

    // sequential PFC preconditioner using MTL
69
70
71
72
#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)
73
      precon->setData(getTau());
74
75
#endif
  }
76

77
78
79
80
81
82
83
  /// generate initial solution for evolution equation
  void solveInitialProblem(AdaptInfo *adaptInfo) override
  { FUNCNAME("PFC_Demo::solveInitialProblem()");

    Flag initFlag = initDataFromFile(adaptInfo);
    if (initFlag.isSet(DATA_ADOPTED))
      return;
84

85
86
    double amplitude = 0.1;
    Parameters::get(name + "->density amplitude",amplitude);
87

88
89
90
    DOFVector<double>* rho = prob->getSolution()->getDOFVector(1);
    *rho << eval(new Random(density, amplitude));
  }
91

92
93
94
95
96
97
  /// add Rosenbrock operators
  void fillOperators() override
  {
    const FiniteElemSpace* feSpace0 = prob->getFeSpace(0);
    const FiniteElemSpace* feSpace1 = prob->getFeSpace(1);
    const FiniteElemSpace* feSpace2 = prob->getFeSpace(2);
98

99
100
101
    DOFVector<double>* mu = prob->getStageSolution(0);
    DOFVector<double>* rho = prob->getStageSolution(1);
    DOFVector<double>* nu = prob->getStageSolution(2);
102

103
104
    DOFVector<double>* mu_old = prob->getUnVec(0);
    DOFVector<double>* rho_old = prob->getUnVec(1);
105

106
107
108
109
110
111
112
    // F = -mu_s + (1+r)*rho_s + 2*laplace(rho_s) + laplace(nu_s) + rho_s^3
    // -J = mu - (1+r)*rho - 2*laplace(rho) - laplace(nu) - 3*rho_old^2 * rho
    // ----------------------------------------------------------------------
    Operator *op01_lhs = new Operator(feSpace0, feSpace1);
    addZOT(op01_lhs, -(1.0 + r) - 3.0 * pow<2>(valueOf(rho_old)) );
    addSOT(op01_lhs, 2.0);
    prob->addMatrixOperator(op01_lhs, 0, 1);
113

114
115
116
    Operator *op00_lhs = new Operator(feSpace0, feSpace0);
    addZOT(op00_lhs, 1.0);
    prob->addMatrixOperator(op00_lhs, 0, 0);
117

118
119
120
    Operator *op02_lhs = new Operator(feSpace0, feSpace2);
    addSOT(op02_lhs, 1.0);
    prob->addMatrixOperator(op02_lhs, 0, 2);
121

122
    // ------- //
123

124
    Operator *op01_rhs0 = new Operator(feSpace0, feSpace1);
125
    addSOT(op01_rhs0, -2.0);
126
127
    op01_rhs0->setUhOld(rho);
    prob->addVectorOperator(op01_rhs0, 0);
128

129
130
131
    Operator *op01_rhs1 = new Operator(feSpace0, feSpace1);
    addZOT(op01_rhs1, ((1.0 + r) + pow<2>(valueOf(rho)))*valueOf(rho) - valueOf(mu) );
    prob->addVectorOperator(op01_rhs1, 0);
132

133
134
135
136
    Operator *op02_rhs = new Operator(feSpace0, feSpace2);
    addSOT(op02_rhs, -1.0);
    op02_rhs->setUhOld(nu);
    prob->addVectorOperator(op02_rhs, 0);
137

138
139
140
    // dt(rho) = laplace(mu)
    // -----------------------------------
    prob->addTimeOperator(1, 1);
141

142
143
    Operator *opLM_lhs0 = new Operator(feSpace1, feSpace0);
    Operator *opLM_rhs = new Operator(feSpace1, feSpace0);
144
    if (mobility_type > 0) {
145
      addSOT(opLM_lhs0, max(abs_(valueOf(rho_old) + 1.5)*M0, 1.e-5));
146

147
148
      // ------- //
      Operator *opLM_lhs1 = new Operator(feSpace1, feSpace0);
149
150
151
152
153
      addFOT(opLM_lhs1, gradientOf(mu_old), GRD_PSI);

      prob->addMatrixOperator(opLM_lhs0, 1, 0, prob->getTau(), prob->getTau());
      prob->addMatrixOperator(opLM_lhs1, 1, 1, prob->getTau(), prob->getTau());

154
155
156
157
158
159
      // ------- //
      addSOT(opLM_rhs, -max(abs_(valueOf(rho) + 1.5)*M0, 1.e-5));
      opLM_rhs->setUhOld(mu);
      prob->addVectorOperator(opLM_rhs, 1, prob->getTau(), prob->getTau());
    } else {
      addSOT(opLM_lhs0, M0);
160
161
      prob->addMatrixOperator(opLM_lhs0, 1, 0, prob->getTau(), prob->getTau());

162
163
164
165
166
      // ------- //
      addSOT(opLM_rhs, -M0);
      opLM_rhs->setUhOld(mu);
      prob->addVectorOperator(opLM_rhs, 1, prob->getTau(), prob->getTau());
    }
167

168
169
170
171
172
173
    // F  =-nu + laplace(rho)
    // -J = nu - laplace(rho)
    // -------------------
    Operator *op21_lhs = new Operator(feSpace2, feSpace1);
    addSOT(op21_lhs, 1.0);
    prob->addMatrixOperator(op21_lhs, 2, 1);
174

175
176
177
    Operator *op22_lhs = new Operator(feSpace2, feSpace2);
    addZOT(op22_lhs, 1.0);
    prob->addMatrixOperator(op22_lhs, 2, 2); // nu
178
179
180

    // ------- //

181
182
183
184
    Operator *op21_rhs = new Operator(feSpace2, feSpace1);
    addSOT(op21_rhs, -1.0);
    op21_rhs->setUhOld(rho);
    prob->addVectorOperator(op21_rhs, 2);
185

186
187
188
189
190
191
192
193
194
195
196
197
    Operator *op22_rhs = new Operator(feSpace2, feSpace2);
    addZOT(op22_rhs, -valueOf(nu));
    prob->addVectorOperator(op22_rhs, 2); // nu
  }
};


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

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

199
200
  // add preconditioner / solver to the parameter list. Must be added before problem is initialized.
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
201
  CreatorMap<LinearSolverInterface>::addCreator("petsc_pfc", new PetscSolver<PetscPreconPfc>::Creator);
202
#endif
203

204
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
205
  CreatorMap<LinearSolverInterface>::addCreator("p_petsc_pfc", new Parallel::PetscSolverPfc::Creator);
206
#endif
207

208
209
#if (!defined HAVE_SEQ_PETSC) && (!defined HAVE_PETSC) && (!defined HAVE_PARALLEL_DOMAIN_AMDIS)
  using AMDiS::extensions::MTLPreconPfc;
210
  CreatorMap<typename MTLPreconPfc::precon_base>::addCreator("pfc", new MTLPreconPfc::Creator);
211
#endif
212

213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
  // create and initialize the PFC BaseProblem
  PfcPC pfcProb("pfc");
  pfcProb.initialize(INIT_ALL);

  // Adapt-Infos
  AdaptInfo adaptInfo("adapt", pfcProb.getNumComponents());
  RosenbrockAdaptInstationary adaptInstat("adapt", pfcProb.getProblem(), &adaptInfo, &pfcProb, &adaptInfo);
  pfcProb.initTimeInterface(); // fill operators and BC

  // 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);
  }

231
232
233
  int error_code = adaptInstat.adapt();

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