NavierStokes_TaylorHood.cc 9.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "NavierStokes_TaylorHood.h"

using namespace std;
using namespace AMDiS;

NavierStokes_TaylorHood::NavierStokes_TaylorHood(const std::string &name_) :
  super(name_),
  forceDBC(false),
  initialVelocityIsSet(false),
  laplaceType(0),
  nonLinTerm(2),
  oldTimestep(0.0),
  viscosity(1.0),
  density(1.0),
  c(0.0),
  theta(0.5),
  theta1(0.5),
  minusTheta1(-0.5),
19
20
21
22
  velocity(NULL),
  fileWriter(NULL),
  initialX(NULL),
  initialY(NULL)
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
{  
  // force the homogeniouse dirichlet BC if combination of dirichlet and neumann BC
  // are set and AMDiS can not handle this combination automatically
  Initfile::get(name + "->force dirichlet bc", forceDBC);
  if (forceDBC) {
    int numDirichletPoints = 0;
    Initfile::get("number of dirichlet points", numDirichletPoints);
    dirichletPoints.resize(numDirichletPoints);
    for (int i = 0; i < numDirichletPoints; i++)
      Initfile::get("dirichlet point[" + Helpers::toString(i) + "]",dirichletPoints[i]);
  }

  // parameters for navier-stokes
  Initfile::get(name + "->viscosity", viscosity);
  Initfile::get(name + "->density", density);
  // type of laplace operator: 0... div(nu*grad(u)), 1... div(0.5*nu*(grad(u)+grad(u)^T))
  Initfile::get(name + "->laplace operator", laplaceType); 
  // type of non-linear term: 0... u^old*grad(u_i^old), 1... u'*grad(u_i^old), 2... u^old*grad(u'_i)
  Initfile::get(name + "->non-linear term", nonLinTerm); 

  Initfile::get(name + "->theta", theta); 
  theta1 = 1.0-theta;
  minusTheta1 = -theta1;

  force.set(0.0);
  Initfile::get(name + "->force", force);

  bool scaleMesh = false;
  Initfile::get("mesh->scale mesh",scaleMesh);
  if (scaleMesh) {
    Initfile::get("mesh->scale",dimension);
  } else
    dimension.set(1.0);
56
57
58
59
  
  
  for (size_t i = 0; i < dow; i++)
    oldSolution[i] = NULL;
60
61
62
63
64
65
66
67
68
69
}


NavierStokes_TaylorHood::~NavierStokes_TaylorHood() 
{ FUNCNAME("NavierStokes_TaylorHood::~NavierStokes_TaylorHood()");

  if (initialVelocityIsSet) {
    delete initialX;
    delete initialY;
  }
70
71
  
  if (velocity != NULL) {
72
    delete velocity;
73
74
75
76
77
78
79
80
81
    velocity = NULL;
  }
  
  for (size_t i = 0; i < dow; i++) {
    if (oldSolution[i] != NULL)
      delete oldSolution[i];
    oldSolution[i] = NULL;
  }
  
82
83
84
85
86
87
88
89
90
  delete fileWriter;
}


void NavierStokes_TaylorHood::initData()
{ FUNCNAME("NavierStokes_TaylorHood::initTimeInterface()");

  if (velocity == NULL)
    velocity = new DOFVector<WorldVector<double> >(getFeSpace(0), "velocity");
91
92
93
94
  
  for (size_t i = 0; i < dow; i++)
    oldSolution[i] = new DOFVector<double>(getFeSpace(i), "old(v_"+Helpers::toString(i)+")");
  
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
  fileWriter = new FileVectorWriter(name + "->velocity->output", getFeSpace()->getMesh(), velocity);

  super::initData();
}


void NavierStokes_TaylorHood::solveInitialProblem(AdaptInfo *adaptInfo) 
{ FUNCNAME("NavierStokes_TaylorHood::solveInitialProblem()");

  int initialVelocity = 0, flowDirection = 1;
  Initfile::get(name + "->initial velocity", initialVelocity);
  Initfile::get(name + "->initial velocity->value", c);
  Initfile::get(name + "->initial velocity->flow direction", flowDirection);

  std::vector<AbstractFunction<double, WorldVector<double> >*> initialFcts(2);
  if (initialVelocity == 0) { // no initial velocity
    initialFcts[0]= new ConstantFct(0.0);
    initialFcts[1]= new ConstantFct(0.0);
  } else if(initialVelocity == 1) { // constant inflow
      initialFcts[flowDirection] = new ConstantFct(c);
      initialFcts[1-flowDirection] = new ConstantFct(0.0);
  } else if(initialVelocity == 2) { // parabolic inflow
    double dist = -1.0;
    Initfile::get(name + "->initial velocity->parabolic inflow->boundary dist", dist);
    if (dist <= 0.0)
      dist = 2.0*dimension[1-flowDirection];
    initialFcts[flowDirection] = new ParabolicInflow(dist/2.0, c, flowDirection);
    initialFcts[1-flowDirection] = new ConstantFct(0.0);
  } else
    throw(std::runtime_error("Unknown initial velocity."));

  initialX = initialFcts[0];
  initialY = initialFcts[1];
  initialVelocityIsSet = true;
  
  MSG("solve initial problem...\n");
  for (unsigned i = 0; i < dow; ++i) {
    prob->getSolution()->getDOFVector(i)->interpol(initialFcts[i]);
    prob->setExactSolutionFct(initialFcts[i], i);
  }
}


void NavierStokes_TaylorHood::transferInitialSolution(AdaptInfo *adaptInfo)
{ FUNCNAME("NavierStokes_TaylorHood::transferInitialSolution()");

  calcVelocity();
  
  for (int i = 0; i < dow; i++)
    prob->setExactSolution(prob->getSolution()->getDOFVector(i), i);

146
147
148
  for (size_t i = 0; i < dow; i++)
    oldSolution[i]->copy(*prob->getSolution()->getDOFVector(i));
  
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
197
  fileWriter->writeFiles(adaptInfo, false);
  writeFiles(adaptInfo, false);

  // initial parameters for detecting mesh changes
  oldMeshChangeIdx= getMesh()->getChangeIndex();
}


void NavierStokes_TaylorHood::fillOperators()
{ FUNCNAME("NavierStokes_TaylorHood::fillOperators()");

  // fill operators for prob
  for (unsigned i = 0; i < dow; ++i) {
    /// < (1/tau)*u'_i , psi >
    Operator *opTime = new Operator(getFeSpace(i), getFeSpace(i));
    opTime->addTerm(new Simple_ZOT(density));
    prob->addMatrixOperator(*opTime, i, i, getInvTau(), getInvTau());
    /// < (1/tau)*u_i^old , psi >
    opTime->setUhOld(prob->getSolution()->getDOFVector(i));
    prob->addVectorOperator(*opTime, i, getInvTau(), getInvTau());
 
    /// < u^old*grad(u_i^old) , psi >
    Operator *opUGradU0 = new Operator(getFeSpace(i), getFeSpace(i));
    opUGradU0->addTerm(new WorldVector_FOT(velocity, -density), GRD_PHI);
    opUGradU0->setUhOld(prob->getSolution()->getDOFVector(i));
    if (nonLinTerm == 0) {
      prob->addVectorOperator(*opUGradU0, i);
    } else if (abs(theta1) > DBL_TOL) {
      prob->addVectorOperator(*opUGradU0, i, &theta1, &theta1);
    }

    if (nonLinTerm == 1) {
      /// < u'*grad(u_i^old) , psi >
      for (unsigned j = 0; j < dow; ++j) {
        Operator *opUGradU1 = new Operator(getFeSpace(i),getFeSpace(i));
        opUGradU1->addTerm(new PartialDerivative_ZOT(
          prob->getSolution()->getDOFVector(i), j, density));
        prob->addMatrixOperator(*opUGradU1, i, j, &theta, &theta);
      }
    } else if (nonLinTerm == 2) {
      /// < u^old*grad(u'_i) , psi >
      for(unsigned j = 0; j < dow; ++j) {
        Operator *opUGradU2 = new Operator(getFeSpace(i),getFeSpace(i));
        opUGradU2->addTerm(new VecAndPartialDerivative_FOT(
          prob->getSolution()->getDOFVector(j), j, density), GRD_PHI);
        prob->addMatrixOperator(*opUGradU2, i, i, &theta, &theta);
      }
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
198
199
200
201
202
//     for (int j = 0; j < dow; ++j) {
//       Operator *opNull = new Operator(getFeSpace(i), getFeSpace(j));
//       opNull->addTerm(new Simple_ZOT(0.0));
//       prob->addMatrixOperator(*opNull, i, j);
//     }
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236

    /// Diffusion-Operator (including Stress-Tensor for space-dependent viscosity
    addLaplaceTerm(i);
  
    /// < p , d_i(psi) >
    Operator *opGradP = new Operator(getFeSpace(i),getFeSpace(dow));
    opGradP->addTerm(new PartialDerivative_FOT(i, -1.0), GRD_PSI);
    prob->addMatrixOperator(*opGradP, i, dow);
  
    /// external force, i.e. gravitational force
    if (norm(force) > DBL_TOL) {
      Operator *opForce = new Operator(getFeSpace(i), getFeSpace(i));
      opForce->addTerm(new Simple_ZOT(force[i]));
      prob->addVectorOperator(*opForce, i);
    }
  }

  /// div(u) = 0
  for (unsigned i = 0; i < dow; ++i) {
    /// < d_i(u'_i) , psi >
    Operator *opDivU = new Operator(getFeSpace(dow),getFeSpace(i));
    opDivU->addTerm(new PartialDerivative_FOT(i), GRD_PHI);
    prob->addMatrixOperator(*opDivU, dow, i);
  }
}


void NavierStokes_TaylorHood::addLaplaceTerm(int i)
{ FUNCNAME("NavierStokes_TaylorHood::addLaplaceTerm()");

    /// < alpha*[grad(u)+grad(u)^t] , grad(psi) >
    if (laplaceType == 1) {
      for (unsigned j = 0; j < dow; ++j) {
        Operator *opLaplaceUi1 = new Operator(getFeSpace(i), getFeSpace(j));
237
        opLaplaceUi1->addTerm(new MatrixIJ_SOT(j, i, viscosity));
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
        prob->addMatrixOperator(*opLaplaceUi1, i, j, &theta, &theta);

	if (abs(minusTheta1) > DBL_TOL) {
	  opLaplaceUi1->setUhOld(prob->getSolution()->getDOFVector(j));
	  prob->addVectorOperator(*opLaplaceUi1, i, &minusTheta1, &minusTheta1);
	}
      }
    }
    
    /// < alpha*grad(u'_i) , grad(psi) >
    Operator *opLaplaceUi = new Operator(getFeSpace(i), getFeSpace(i));
      opLaplaceUi->addTerm(new Simple_SOT(viscosity));
    prob->addMatrixOperator(*opLaplaceUi, i, i, &theta, &theta);

    if (abs(minusTheta1) > DBL_TOL) {
      opLaplaceUi->setUhOld(prob->getSolution()->getDOFVector(i));
      prob->addVectorOperator(*opLaplaceUi, i, &minusTheta1, &minusTheta1);
    }
}


void NavierStokes_TaylorHood::fillBoundaryConditions()
{ FUNCNAME("NavierStokes_TaylorHood::fillBoundaryConditions()");

  ERROR("You have to implement some boundary conditions!\n");
}


void NavierStokes_TaylorHood::closeTimestep(AdaptInfo *adaptInfo)
{ FUNCNAME("NavierStokes_TaylorHood::closeTimestep()");

  calcVelocity();
270
271
272
273
274
275
276
277
278
  for (size_t i = 0; i < dow; i++)
    oldSolution[i]->copy(*prob->getSolution()->getDOFVector(i));
}


void NavierStokes_TaylorHood::writeFiles(AdaptInfo *adaptInfo, bool force)
{ FUNCNAME("NavierStokesPhase_TaylorHood::closeTimestep()");

  super::writeFiles(adaptInfo, force);
279
280
  fileWriter->writeFiles(adaptInfo, false);
}