pfc.cc 3.86 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 39
    PetscPreconPfc* precon = dynamic_cast<PetscPreconPfc*>(prob->getSolver()->getRightPrecon());
    if (precon) {
      precon->setData(getTau(), M0);	
40
    }
41 42 43 44 45 46 47 48 49
//     PetscPreconPfcDiag* precon2 = dynamic_cast<PetscPreconPfcDiag*>(prob->getSolver()->getRightPrecon());
//     if (precon2) {
//       precon2->setData(getTau(), M0);	
    }
#elif !defined(HAVE_PARALLEL_DOMAIN_AMDIS)
     MTLPreconPfc* precon = dynamic_cast<MTLPreconPfc*>(prob->getSolver()->getRightPrecon());
     if (precon)
	precon->setData(getTau(), M0);	
#else
50 51 52
    // parallel PFC preconditioner
    Parallel::PetscSolverPfc* solver = dynamic_cast<Parallel::PetscSolverPfc*>(prob->getSolver());
    if (solver)
53 54 55 56 57
      solver->setData(getTau(), M0);
    
//     Parallel::PetscSolverPfcDiag* solver2 = dynamic_cast<Parallel::PetscSolverPfcDiag*>(prob->getSolver());
//     if (solver2)
//       solver2->setData(getTau(), M0);
58 59
#endif
      
60 61 62 63
#endif
  }
  
  /// generate initial solution for evolution equation
64 65
  void solveInitialProblem(AdaptInfo *adaptInfo) override
  { 
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    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;
  
85 86
#ifdef USE_PRECON
  
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 98
#endif
  
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
#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;
}