nsch.cc 5.15 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "AMDiS.h"
#include "CahnHilliard_.h"
#include "NavierStokes_TH_MultiPhase.h"
#include "CahnHilliardNavierStokes_.h"
#include "SignedDistFunctors.h"
#include "PhaseFieldConvert.h"
//#include "CahnHilliard_.h"

#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
  #include "parallel/PetscSolverCahnHilliard.h"
  #include "parallel/PetscSolverCahnHilliard2.h"
  #include "parallel/PetscSolverNavierStokes.h"
#endif

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

using namespace AMDiS;
using namespace boost::posix_time;



class CahnHilliardPC : public CahnHilliard_
{
public:
  CahnHilliardPC(std::string name) : CahnHilliard_(name), delta(1.0)
  { }
 
  void initData()
  {   
    #ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    string initFileStr = name + "->space->solver", solverType = "";
    Parameters::get(initFileStr, solverType);
    if (solverType == "petsc-ch") {
      PetscSolverCahnHilliard* solver = dynamic_cast<PetscSolverCahnHilliard*>(prob->getSolver());
      if (solver)
	solver->setChData(&eps, &delta, prob->getSolution());	
    } else if (solverType == "petsc-ch2") {
      PetscSolverCahnHilliard2* solver = dynamic_cast<PetscSolverCahnHilliard2*>(prob->getSolver()); 
      if (solver)
	solver->setChData(&eps, &delta);
    }
    #endif
  }
  
  virtual void setTime(AdaptInfo* adaptInfo) 
  {
    super::setTime(adaptInfo);
    delta = gamma*adaptInfo->getTimestep();
  }
  
  double delta;
};





class NavierStokes_TaylorHoodPC : public NavierStokes_TH_MultiPhase
{
public:
  NavierStokes_TaylorHoodPC(std::string name) : NavierStokes_TH_MultiPhase(name)
  { }
 
 
 void initData()
  {   
    NavierStokes_TH_MultiPhase::initData(); /// warum geht super::initData() nicht ? 
    #ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    string initFileStr = name + "->space->solver", solverType = "";
    Parameters::get(initFileStr, solverType);
    if (solverType == "petsc-navierstokes") {
      PetscSolverNavierStokes *s = dynamic_cast<PetscSolverNavierStokes*>(prob->getPetscSolver());
      if (s) {
	  s->setStokesData( getInvTau(), prob->getSolution(), &viscosity1, &viscosity2, &density1, &density2);
	  s->setPhase(multiPhase);
      }
    } 
    #endif    
  }
  
  void initPhasefield()
  {   
    #ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    string initFileStr = name + "->space->solver", solverType = "";
    Parameters::get(initFileStr, solverType);
    if (solverType == "petsc-navierstokes") {
      PetscSolverNavierStokes *s = dynamic_cast<PetscSolverNavierStokes*>(prob->getPetscSolver());
      if (s) {
	  s->setPhase(multiPhase);
      }
    } 
    #endif    
  }
  
};




class MyNavierStokes_PC : public NavierStokes_TaylorHoodPC
{
public:
  MyNavierStokes_PC(std::string name_) : NavierStokes_TaylorHoodPC(name_) {}
  
protected:
  void fillBoundaryConditions()
  { FUNCNAME("MyNavierStokes_PC::fillBoundaryConditions()");
    
    DOFVector<double> *zeroDOF = new DOFVector<double>(getFeSpace(0), "zero");
    zeroDOF->set(0.0);
    size_t dow = Global::getGeo(WORLD);

    /// at rigid wall: no-slip boundary condition  
    // oben-unten
    getProblem()->addDirichletBC(2, 0, 0, zeroDOF);
    getProblem()->addDirichletBC(2, 1, 1, zeroDOF);
    // links-rechts
    getProblem()->addDirichletBC(1, 0, 0, zeroDOF); 
  }
  
  
};


class MyNavierStokes: public NavierStokes_TH_MultiPhase
{
public:
  MyNavierStokes(std::string name_) : NavierStokes_TH_MultiPhase(name_) {}
  
protected:
  void fillBoundaryConditions()
  { FUNCNAME("MyNavierStokes::fillBoundaryConditions()");
    
    DOFVector<double> *zeroDOF = new DOFVector<double>(getFeSpace(0), "zero");
    zeroDOF->set(0.0);
    size_t dow = Global::getGeo(WORLD);

    /// at rigid wall: no-slip boundary condition  
    // oben-unten
    getProblem()->addDirichletBC(2, 0, 0, zeroDOF);
    getProblem()->addDirichletBC(2, 1, 1, zeroDOF);
    // links-rechts
    getProblem()->addDirichletBC(1, 0, 0, zeroDOF); 
  }
  
  
};



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

  AMDiS::init(argc, argv);
  
  #ifdef HAVE_PARALLEL_DOMAIN_AMDIS
      CreatorMap<OEMSolver>::addCreator("petsc-ch", new PetscSolverCahnHilliard::Creator);
      CreatorMap<OEMSolver>::addCreator("petsc-ch2", new PetscSolverCahnHilliard2::Creator);
  #endif

  #ifdef HAVE_PARALLEL_DOMAIN_AMDIS      
    CahnHilliardPC chProb("ch");
    MyNavierStokes_PC nsProb("ns");
    CahnHilliardNavierStokes_<CahnHilliardPC,MyNavierStokes_PC> mainProb("main", &chProb, &nsProb);
  #else
    CahnHilliard_ chProb("ch");
167
    MyNavierStokes nsProb("ns");
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
    CahnHilliardNavierStokes_<CahnHilliard_,MyNavierStokes> mainProb("main", &chProb, &nsProb);
  #endif
  
  
  
    
  // Adapt-Infos
  AdaptInfo adaptInfo("adapt", mainProb.getNumComponents());
  mainProb.initialize(&adaptInfo);
  
  nsProb.setMultiPhase(chProb.getSolution()->getDOFVector(1));
  #ifdef HAVE_PARALLEL_DOMAIN_AMDIS      
    nsProb.initPhasefield();
  #endif
  // adaption loop - solve ch-prob and ns-prob
  AdaptInstationary adaptInstat("adapt", mainProb, adaptInfo, mainProb, adaptInfo);


  
  ptime start_time = microsec_clock::local_time();
  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;
};