Newer
Older
#ifndef LaxFridrichs_IMPL_H
#define LaxFridrichs_IMPL_H
/****
* 1D problem
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
LaxFridrichs< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >::
return String( "LaxFridrichs< " ) +
TNL::getType< Real >() + ", " +
TNL::getType< Index >() + " >";
}
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
template< typename MeshFunction, typename MeshEntity >
__cuda_callable__
Real
LaxFridrichs< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >::
operator()( const MeshFunction& u,
const MeshEntity& entity,
const Real& time ) const
{
/****
* Implement your explicit form of the differential operator here.
* The following example is the Laplace operator approximated
* by the Finite difference method.
*/
static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." );
static_assert( MeshFunction::getEntitiesDimensions() == 1, "Wrong preimage function" );
const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities();
const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1 >();
const IndexType& center = entity.getIndex();
const IndexType& east = neighbourEntities.template getEntityIndex< 1 >();
const IndexType& west = neighbourEntities.template getEntityIndex< -1 >();
double a;
a = this->advectionSpeedX;
return (0.5 / this->tau ) * this->artificalViscosity *
( u[ west ]- 2.0 * u[ center ] + u[ east ] )
- (a = this->advectionSpeedX * ( u[ east ] - u[west] ) ) * hxInverse * 0.5;
}
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
template< typename MeshEntity >
__cuda_callable__
Index
LaxFridrichs< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >::
getLinearSystemRowLength( const MeshType& mesh,
const IndexType& index,
const MeshEntity& entity ) const
{
/****
* Return a number of non-zero elements in a line (associated with given grid element) of
* the linear system.
* The following example is the Laplace operator approximated
* by the Finite difference method.
*/
return 2*Dimensions + 1;
}
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
template< typename MeshEntity, typename Vector, typename MatrixRow >
__cuda_callable__
void
LaxFridrichs< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, Real, Index >::
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
updateLinearSystem( const RealType& time,
const RealType& tau,
const MeshType& mesh,
const IndexType& index,
const MeshEntity& entity,
const MeshFunctionType& u,
Vector& b,
MatrixRow& matrixRow ) const
{
/****
* Setup the non-zero elements of the linear system here.
* The following example is the Laplace operator appriximated
* by the Finite difference method.
*/
const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities();
const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >();
const IndexType& center = entity.getIndex();
const IndexType& east = neighbourEntities.template getEntityIndex< 1 >();
const IndexType& west = neighbourEntities.template getEntityIndex< -1 >();
matrixRow.setElement( 0, west, - lambdaX );
matrixRow.setElement( 1, center, 2.0 * lambdaX );
matrixRow.setElement( 2, east, - lambdaX );
}
/****
* 2D problem
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
LaxFridrichs< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >::
return String( "LaxFridrichs< " ) +
TNL::getType< Real >() + ", " +
TNL::getType< Index >() + " >";
}
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
template< typename MeshFunction, typename MeshEntity >
__cuda_callable__
Real
LaxFridrichs< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >::
operator()( const MeshFunction& u,
const MeshEntity& entity,
const Real& time ) const
{
/****
* Implement your explicit form of the differential operator here.
* The following example is the Laplace operator approximated
* by the Finite difference method.
*/
static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." );
static_assert( MeshFunction::getEntitiesDimensions() == 2, "Wrong preimage function" );
const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities();
const RealType& hxInverse = entity.getMesh().template getSpaceStepsProducts< -1, 0 >();
const RealType& hyInverse = entity.getMesh().template getSpaceStepsProducts< 0, -1 >();
const IndexType& center = entity.getIndex();
const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >();
const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >();
const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >();
const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >();
double a;
double b;
a = this->advectionSpeedX;
b = this->advectionSpeedY;
return ( 0.25 / this->tau ) * this->artificalViscosity *
( u[ west ] + u[ east ] + u[ south ] + u[ north ] - 4 * u[ center ] ) -
(a * ( u[ east ] - u[west] ) ) * hxInverse * 0.5 -
(b * ( u[ north ] - u[ south ] ) ) * hyInverse * 0.5;
}
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
template< typename MeshEntity >
__cuda_callable__
Index
LaxFridrichs< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >::
getLinearSystemRowLength( const MeshType& mesh,
const IndexType& index,
const MeshEntity& entity ) const
{
/****
* Return a number of non-zero elements in a line (associated with given grid element) of
* the linear system.
* The following example is the Laplace operator approximated
* by the Finite difference method.
*/
return 2*Dimensions + 1;
}
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
template< typename MeshEntity, typename Vector, typename MatrixRow >
__cuda_callable__
void
LaxFridrichs< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, Real, Index >::
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
updateLinearSystem( const RealType& time,
const RealType& tau,
const MeshType& mesh,
const IndexType& index,
const MeshEntity& entity,
const MeshFunctionType& u,
Vector& b,
MatrixRow& matrixRow ) const
{
/****
* Setup the non-zero elements of the linear system here.
* The following example is the Laplace operator appriximated
* by the Finite difference method.
*/
const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities();
const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >();
const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >();
const IndexType& center = entity.getIndex();
const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0 >();
const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0 >();
const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1 >();
const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1 >();
matrixRow.setElement( 0, south, -lambdaY );
matrixRow.setElement( 1, west, -lambdaX );
matrixRow.setElement( 2, center, 2.0 * ( lambdaX + lambdaY ) );
matrixRow.setElement( 3, east, -lambdaX );
matrixRow.setElement( 4, north, -lambdaY );
}
/****
* 3D problem
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
LaxFridrichs< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >::
return String( "LaxFridrichs< " ) +
TNL::getType< Real >() + ", " +
TNL::getType< Index >() + " >";
}
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
template< typename MeshFunction, typename MeshEntity >
__cuda_callable__
Real
LaxFridrichs< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >::
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
operator()( const MeshFunction& u,
const MeshEntity& entity,
const Real& time ) const
{
/****
* Implement your explicit form of the differential operator here.
* The following example is the Laplace operator approximated
* by the Finite difference method.
*/
static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." );
static_assert( MeshFunction::getEntitiesDimensions() == 3, "Wrong preimage function" );
const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities();
const RealType& hxSquareInverse = entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >();
const RealType& hySquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >();
const RealType& hzSquareInverse = entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >();
const IndexType& center = entity.getIndex();
const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >();
const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >();
const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >();
const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >();
const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >();
const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >();
return ( u[ west ] - 2.0 * u[ center ] + u[ east ] ) * hxSquareInverse +
( u[ south ] - 2.0 * u[ center ] + u[ north ] ) * hySquareInverse +
( u[ up ] - 2.0 * u[ center ] + u[ down ] ) * hzSquareInverse;
}
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
template< typename MeshEntity >
__cuda_callable__
Index
LaxFridrichs< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >::
getLinearSystemRowLength( const MeshType& mesh,
const IndexType& index,
const MeshEntity& entity ) const
{
/****
* Return a number of non-zero elements in a line (associated with given grid element) of
* the linear system.
* The following example is the Laplace operator approximated
* by the Finite difference method.
*/
}
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
template< typename MeshEntity, typename Vector, typename MatrixRow >
__cuda_callable__
void
LaxFridrichs< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, Real, Index >::
updateLinearSystem( const RealType& time,
const RealType& tau,
const MeshType& mesh,
const IndexType& index,
const MeshEntity& entity,
const MeshFunctionType& u,
Vector& b,
MatrixRow& matrixRow ) const
{
/****
* Setup the non-zero elements of the linear system here.
* The following example is the Laplace operator appriximated
* by the Finite difference method.
*/
/* const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities();
const RealType& lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >();
const RealType& lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >();
const RealType& lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >();
const IndexType& center = entity.getIndex();
const IndexType& east = neighbourEntities.template getEntityIndex< 1, 0, 0 >();
const IndexType& west = neighbourEntities.template getEntityIndex< -1, 0, 0 >();
const IndexType& north = neighbourEntities.template getEntityIndex< 0, 1, 0 >();
const IndexType& south = neighbourEntities.template getEntityIndex< 0, -1, 0 >();
const IndexType& up = neighbourEntities.template getEntityIndex< 0, 0, 1 >();
const IndexType& down = neighbourEntities.template getEntityIndex< 0, 0, -1 >();
matrixRow.setElement( 0, down, -lambdaZ );
matrixRow.setElement( 1, south, -lambdaY );
matrixRow.setElement( 2, west, -lambdaX );
matrixRow.setElement( 3, center, 2.0 * ( lambdaX + lambdaY + lambdaZ ) );
matrixRow.setElement( 4, east, -lambdaX );
matrixRow.setElement( 5, north, -lambdaY );
matrixRow.setElement( 6, up, -lambdaZ );*/
} // namespace TNL
#endif /* LaxFridrichsIMPL_H */