Newer
Older
#ifndef eulerPROBLEM_IMPL_H_
#define eulerPROBLEM_IMPL_H_
#include <core/mfilename.h>
#include <matrices/tnlMatrixSetter.h>
#include <solvers/pde/tnlExplicitUpdater.h>
#include <solvers/pde/tnlLinearSystemAssembler.h>
#include <solvers/pde/tnlBackwardTimeDiscretisation.h>
#include "LaxFridrichsContinuity.h"
#include "LaxFridrichsMomentum.h"
#include "LaxFridrichsEnergy.h"
#include "EulerVelGetter.h"
#include "EulerPressureGetter.h"
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
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
tnlString
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
getTypeStatic()
{
return tnlString( "eulerProblem< " ) + Mesh :: getTypeStatic() + " >";
}
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
tnlString
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
getPrologHeader() const
{
return tnlString( "euler" );
}
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
void
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
writeProlog( tnlLogger& logger, const tnlParameterContainer& parameters ) const
{
/****
* Add data you want to have in the computation report (log) as follows:
* logger.writeParameter< double >( "Parameter description", parameter );
*/
}
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
bool
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
setup( const tnlParameterContainer& parameters )
{
if( ! this->boundaryCondition.setup( parameters, "boundary-conditions-" ) ||
! this->rightHandSide.setup( parameters, "right-hand-side-" ) )
return false;
return true;
}
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
typename eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::IndexType
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
getDofs( const MeshType& mesh ) const
{
/****
* Return number of DOFs (degrees of freedom) i.e. number
* of unknowns to be resolved by the main solver.
*/
return 3*mesh.template getEntitiesCount< typename MeshType::Cell >();
}
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
void
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
bindDofs( const MeshType& mesh,
DofVectorType& dofVector )
{
}
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
bool
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
setInitialCondition( const tnlParameterContainer& parameters,
const MeshType& mesh,
DofVectorType& dofs,
MeshDependentDataType& meshDependentData )
{
typedef typename MeshType::Cell Cell;
double gamma = parameters.getParameter< double >( "gamma" );
double rhoL = parameters.getParameter< double >( "left-density" );
double velL = parameters.getParameter< double >( "left-velocity" );
double preL = parameters.getParameter< double >( "left-pressure" );
double eL = ( preL / (gamma - 1) ) + 0.5 * rhoL * velL * velL;
double rhoR = parameters.getParameter< double >( "right-density" );
double velR = parameters.getParameter< double >( "right-velocity" );
double preR = parameters.getParameter< double >( "right-pressure" );
double eR = ( preR / (gamma - 1) ) + 0.5 * rhoR * velR * velR;
double x0 = parameters.getParameter< double >( "riemann-border" );
cout << gamma << " " << rhoL << " " << velL << " " << preL << " " << eL << " " << rhoR << " " << velR << " " << preR << " " << eR << " " << x0 << " " << gamma << endl;
int count = mesh.template getEntitiesCount< Cell >()/3;
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
this->rho.bind(dofs,0,count);
this->rhoVel.bind(dofs,count,count);
this->energy.bind(dofs,2 * count,count);
this->data.setSize(2*count);
this->pressure.bind(this->data,0,count);
this->velocity.bind(this->data,count,count);
for(long int i = 0; i < count; i++)
if (i < x0 * count )
{
this->rho[i] = rhoL;
this->rhoVel[i] = rhoL * velL;
this->energy[i] = eL;
this->velocity[i] = velL;
this->pressure[i] = preL;
}
else
{
this->rho[i] = rhoR;
this->rhoVel[i] = rhoR * velR;
this->energy[i] = eR;
this->velocity[i] = velR;
this->pressure[i] = preR;
};
this->gamma = gamma;
cout << "dofs = " << dofs << endl;
getchar();
/*
const tnlString& initialConditionFile = parameters.getParameter< tnlString >( "initial-condition" );
if( ! dofs.load( initialConditionFile ) )
{
cerr << "I am not able to load the initial condition from the file " << initialConditionFile << "." << endl;
return false;
}
*/
return true;
}
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
template< typename Matrix >
bool
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
setupLinearSystem( const MeshType& mesh,
Matrix& matrix )
{
/* const IndexType dofs = this->getDofs( mesh );
typedef typename Matrix::CompressedRowsLengthsVector CompressedRowsLengthsVectorType;
CompressedRowsLengthsVectorType rowLengths;
if( ! rowLengths.setSize( dofs ) )
return false;
tnlMatrixSetter< MeshType, DifferentialOperator, BoundaryCondition, CompressedRowsLengthsVectorType > matrixSetter;
matrixSetter.template getCompressedRowsLengths< typename Mesh::Cell >( mesh,
differentialOperator,
boundaryCondition,
rowLengths );
matrix.setDimensions( dofs, dofs );
if( ! matrix.setCompressedRowsLengths( rowLengths ) )
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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
237
238
239
240
241
242
243
244
245
246
247
248
return true;
}
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
bool
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
makeSnapshot( const RealType& time,
const IndexType& step,
const MeshType& mesh,
DofVectorType& dofs,
MeshDependentDataType& meshDependentData )
{
cout << endl << "Writing output at time " << time << " step " << step << "." << endl;
this->bindDofs( mesh, dofs );
tnlString fileName;
ofstream vysledek;
cout << "pressure:" << endl;
for (int i = 0; i<100; i++) cout << this->pressure[i] << " " ;
vysledek.open("pressure" + to_string(step) + ".txt");
for (int i = 0; i<101; i++)
vysledek << 0.01*i << " " << pressure[i] << endl;
vysledek.close();
cout << " " << endl;
cout << "velocity:" << endl;
for (int i = 0; i<100; i++) cout << this->velocity[i] << " " ;
vysledek.open("velocity" + to_string(step) + ".txt");
for (int i = 0; i<101; i++)
vysledek << 0.01*i << " " << pressure[i] << endl;
vysledek.close();
cout << "energy:" << endl;
for (int i = 0; i<100; i++) cout << this->energy[i] << " " ;
vysledek.open("energy" + to_string(step) + ".txt");
for (int i = 0; i<101; i++)
vysledek << 0.01*i << " " << energy[i] << endl;
vysledek.close();
cout << " " << endl;
cout << "density:" << endl;
for (int i = 0; i<100; i++) cout << this->rho[i] << " " ;
vysledek.open("density" + to_string(step) + ".txt");
for (int i = 0; i<101; i++)
vysledek << 0.01*i << " " << rho[i] << endl;
vysledek.close();
getchar();
FileNameBaseNumberEnding( "rho-", step, 5, ".tnl", fileName );
if( ! rho.save( fileName ) )
return false;
FileNameBaseNumberEnding( "rhoVel-", step, 5, ".tnl", fileName );
if( ! rhoVel.save( fileName ) )
return false;
FileNameBaseNumberEnding( "energy-", step, 5, ".tnl", fileName );
if( ! energy.save( fileName ) )
return false;
return true;
}
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
void
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
getExplicitRHS( const RealType& time,
const RealType& tau,
const MeshType& mesh,
DofVectorType& _u,
DofVectorType& _fu,
MeshDependentDataType& meshDependentData )
{
typedef typename MeshType::Cell Cell;
int count = mesh.template getEntitiesCount< Cell >()/3;
//bind _u
this->_uRho.bind(_u,0,count);
this->_uRhoVelocity.bind(_u,count,count);
this->_uEnergy.bind(_u,2 * count,count);
//bind _fu
this->_fuRho.bind(_u,0,count);
this->_fuRhoVelocity.bind(_u,count,count);
this->_fuEnergy.bind(_u,2 * count,count);
MeshFunctionType velocity( mesh, this->velocity );
MeshFunctionType pressure( mesh, this->pressure );
MeshFunctionType uRho( mesh, _uRho );
MeshFunctionType fuRho( mesh, _fuRho );
MeshFunctionType uRhoVelocity( mesh, _uRhoVelocity );
MeshFunctionType fuRhoVelocity( mesh, _fuRhoVelocity );
MeshFunctionType uEnergy( mesh, _uEnergy );
MeshFunctionType fuEnergy( mesh, _fuEnergy );
//generating Differential operator object
Continuity lF1DContinuity;
Momentum lF1DMomentum;
Energy lF1DEnergy;
//rho
this->bindDofs( mesh, _u );
lF1DContinuity.setTau(tau);
lF1DContinuity.setVelocity(velocity);
tnlExplicitUpdater< Mesh, MeshFunctionType, Continuity, BoundaryCondition, RightHandSide > explicitUpdaterContinuity;
explicitUpdaterContinuity.template update< typename Mesh::Cell >( time,
this->boundaryCondition,
this->rightHandSide,
uRho,
fuRho );
lF1DMomentum.setTau(tau);
lF1DMomentum.setVelocity(velocity);
lF1DMomentum.setPressure(pressure);
tnlExplicitUpdater< Mesh, MeshFunctionType, Momentum, BoundaryCondition, RightHandSide > explicitUpdaterMomentum;
explicitUpdaterMomentum.template update< typename Mesh::Cell >( time,
this->boundaryCondition,
this->rightHandSide,
uRhoVelocity,
fuRhoVelocity );
lF1DEnergy.setTau(tau);
lF1DEnergy.setPressure(pressure);
lF1DEnergy.setVelocity(velocity);
tnlExplicitUpdater< Mesh, MeshFunctionType, Energy, BoundaryCondition, RightHandSide > explicitUpdaterEnergy;
explicitUpdaterEnergy.template update< typename Mesh::Cell >( time,
this->boundaryCondition,
this->rightHandSide,
tnlBoundaryConditionsSetter< MeshFunctionType, BoundaryCondition > boundaryConditionsSetter;
boundaryConditionsSetter.template apply< typename Mesh::Cell >(
this->boundaryCondition,
time + tau,
}
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
template< typename Matrix >
void
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
assemblyLinearSystem( const RealType& time,
const RealType& tau,
const MeshType& mesh,
DofVectorType& _u,
Matrix& matrix,
DofVectorType& b,
MeshDependentDataType& meshDependentData )
{
MeshFunctionType,
DifferentialOperator,
BoundaryCondition,
RightHandSide,
tnlBackwardTimeDiscretisation,
Matrix,
DofVectorType > systemAssembler;
tnlMeshFunction< Mesh > u( mesh, _u );
systemAssembler.template assembly< typename Mesh::Cell >( time,
tau,
mesh,
this->differentialOperator,
this->boundaryCondition,
this->rightHandSide,
u,
matrix,
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
template< typename Mesh,
typename BoundaryCondition,
typename RightHandSide,
typename DifferentialOperator >
bool
eulerProblem< Mesh, BoundaryCondition, RightHandSide, DifferentialOperator >::
postIterate( const RealType& time,
const RealType& tau,
const MeshType& mesh,
DofVectorType& dofs,
MeshDependentDataType& meshDependentData )
{
typedef typename MeshType::Cell Cell;
int count = mesh.template getEntitiesCount< Cell >()/3;
//bind _u
this->_uRho.bind(dofs, 0, count);
this->_uRhoVelocity.bind(dofs, count, count);
this->_uEnergy.bind(dofs, 2 * count, count);
//bind meshfunction
MeshFunctionType velocity( mesh, this->velocity );
MeshFunctionType pressure( mesh, this->pressure );
MeshFunctionType uRho( mesh, _uRho );
MeshFunctionType uRhoVel( mesh, _uRhoVelocity );
MeshFunctionType uEnergy( mesh, _uEnergy );
//Generating differential operators
Velocity euler1DVelocity;
Pressure euler1DPressure;
//velocity
euler1DVelocity.setRhoVel(uRhoVel);
euler1DVelocity.setRho(uRho);
// tnlOperatorFunction< Velocity, MeshFunction, void, true > OFVel;
// velocity = OFVel;
//pressure
euler1DPressure.setRhoVel(uRhoVel);
euler1DPressure.setVelocity(velocity);
euler1DPressure.setGamma(gamma);
euler1DPressure.setEnergy(uEnergy);
// tnlOperatorFunction< Pressure, MeshFunction, void, true > OFPressure;
// pressure = OFPressure;
}