pfc.cc 2.46 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
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
#include "AMDiS.h"
#include "PhaseFieldCrystal_Base.h"
#include "Helpers.h"

#include "boost/date_time/posix_time/posix_time.hpp"

using namespace AMDiS;
using namespace boost::posix_time;

/// Functor that gives random values for each coordinate argument
struct RandomValues : public AbstractFunction<double, WorldVector<double> >
{
  RandomValues(double mean_, double amplitude_) : mean(mean_), amplitude(amplitude_)
  {
    std::srand(time(NULL));
  }
  
  double operator()(const WorldVector<double> &x) const
  {
    return mean + amplitude * (std::rand() / static_cast<double>(RAND_MAX-0.5));
  }
  
private:
  double mean;
  double amplitude;
};

/// derived class from BaseProblem->PhaseFieldCrystal
struct PFC_Demo : public PhaseFieldCrystal
{
  PFC_Demo(const std::string &name_) : PhaseFieldCrystal(name_) {}

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

    // random data
    prob->getSolution()->getDOFVector(0)->interpol(new RandomValues(density, amplitude));
  }

  // add periodic boundary condition on all boundaries
  void fillBoundaryConditions()
  {
    for (size_t i = 0; i < prob->getNumComponents(); i++) {
    for (size_t j = 0; j < prob->getNumComponents(); j++) {
      prob->addPeriodicBC(-1, i, j);
      prob->addPeriodicBC(-2, i, j);
    }
    }
  }
};


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

  AMDiS::init(argc, argv);

  PFC_Demo pfcProb("pfc");
  pfcProb.initialize(INIT_ALL);

  // Adapt-Infos
  AdaptInfo adaptInfo("adapt", pfcProb.getNumComponents());
  // adaption loop - solve problems up to stationary solution
  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);
  }

  ptime start_time = microsec_clock::local_time();
  pfcProb.initTimeInterface(); // fill operators and BC
  int error_code = adaptInstat.adapt(); 
  time_duration td = microsec_clock::local_time()-start_time;

  MSG("elapsed time= %d sec\n", td.total_seconds());

  AMDiS::finalize();

  return error_code;
};