Skip to content
Snippets Groups Projects
Commit 5fc2b3ed authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Jakub Klinkovský
Browse files

Added specialization of MeshFunctionGnuplotWriter for grids.

parent ab0345c8
No related branches found
No related tags found
1 merge request!10Periodic BC in distributed grid
......@@ -20,50 +20,59 @@ namespace Meshes {
namespace Functions {
template< typename MeshFunction >
class MeshFunctionGnuplotWriter
class MeshFunctionGnuplotWriterBase
{
using MeshType = typename MeshFunction::MeshType;
using EntityType = typename MeshType::template EntityType< MeshFunction::getEntitiesDimension() >;
using GlobalIndex = typename MeshType::GlobalIndexType;
protected:
template< typename Entity, int dim = Entity::getEntityDimension() >
struct center
{
static auto get( const Entity& entity ) -> decltype(entity.getCenter())
template< typename Entity, int dim = Entity::getEntityDimension() >
struct center
{
return entity.getCenter();
}
};
static auto get( const Entity& entity ) -> decltype(entity.getCenter())
{
return entity.getCenter();
}
};
template< typename Entity >
struct center< Entity, 0 >
{
static auto get( const Entity& entity ) -> decltype(entity.getPoint())
template< typename Entity >
struct center< Entity, 0 >
{
return entity.getPoint();
}
};
static auto get( const Entity& entity ) -> decltype(entity.getPoint())
{
return entity.getPoint();
}
};
template< typename MeshConfig, typename Device, typename Topology, int dim >
struct center< TNL::Meshes::MeshEntity< MeshConfig, Device, Topology >, dim >
{
static int get( const TNL::Meshes::MeshEntity< MeshConfig, Device, Topology >& entity )
template< typename MeshConfig, typename Device, typename Topology, int dim >
struct center< TNL::Meshes::MeshEntity< MeshConfig, Device, Topology >, dim >
{
throw "not implemented";
}
};
static int get( const TNL::Meshes::MeshEntity< MeshConfig, Device, Topology >& entity )
{
throw "not implemented";
}
};
template< typename MeshConfig, typename Device, typename Topology >
struct center< TNL::Meshes::MeshEntity< MeshConfig, Device, Topology >, 0 >
{
static int get( const TNL::Meshes::MeshEntity< MeshConfig, Device, Topology >& entity )
template< typename MeshConfig, typename Device, typename Topology >
struct center< TNL::Meshes::MeshEntity< MeshConfig, Device, Topology >, 0 >
{
throw "not implemented";
}
};
static int get( const TNL::Meshes::MeshEntity< MeshConfig, Device, Topology >& entity )
{
throw "not implemented";
}
};
};
template< typename MeshFunction,
typename Mesh = typename MeshFunction::MeshType,
int EntitiesDimension = MeshFunction::getEntitiesDimension() >
class MeshFunctionGnuplotWriter
: public MeshFunctionGnuplotWriterBase
{
public:
using MeshType = typename MeshFunction::MeshType;
using EntityType = typename MeshType::template EntityType< MeshFunction::getEntitiesDimension() >;
using GlobalIndex = typename MeshType::GlobalIndexType;
public:
static bool write( const MeshFunction& function,
std::ostream& str,
const double& scale = 1.0 )
......@@ -81,5 +90,82 @@ public:
}
};
template< typename MeshFunction,
typename Real,
typename Device,
typename Index,
int EntityDimension >
class MeshFunctionGnuplotWriter< MeshFunction, Meshes::Grid< 2, Real, Device, Index >, EntityDimension >
: public MeshFunctionGnuplotWriterBase
{
public:
using MeshType = typename MeshFunction::MeshType;
using EntityType = typename MeshType::template EntityType< MeshFunction::getEntitiesDimension() >;
using GlobalIndex = typename MeshType::GlobalIndexType;
static bool write( const MeshFunction& function,
std::ostream& str,
const double& scale = 1.0 )
{
const MeshType& grid = function.getMesh();
EntityType entity( grid );
auto& c = entity.getCoordinates();
for( c.y() = 0; c.y() < grid.getDimensions().y(); c.y()++ )
{
for( c.x() = 0; c.x() < grid.getDimensions().x(); c.x()++ )
{
entity.refresh();
typename MeshType::PointType v = center< EntityType >::get( entity );
//std::cerr << entity.getCoordinates() << " -> " << v << std::endl;
for( int j = 0; j < v.getSize(); j++ )
str << v[ j ] << " ";
str << scale * function.getData().getElement( entity.getIndex() ) << "\n";
}
str << "\n";
}
return true;
}
};
template< typename MeshFunction,
typename Real,
typename Device,
typename Index,
int EntityDimension >
class MeshFunctionGnuplotWriter< MeshFunction, Meshes::Grid< 3, Real, Device, Index >, EntityDimension >
: public MeshFunctionGnuplotWriterBase
{
public:
using MeshType = typename MeshFunction::MeshType;
using EntityType = typename MeshType::template EntityType< MeshFunction::getEntitiesDimension() >;
using GlobalIndex = typename MeshType::GlobalIndexType;
static bool write( const MeshFunction& function,
std::ostream& str,
const double& scale = 1.0 )
{
const MeshType& grid = function.getMesh();
EntityType entity( grid );
auto& c = entity.getCoordinates();
for( c.z() = 0; c.z() < grid.getDimensions().z(); c.z()++ )
for( c.y() = 0; c.y() < grid.getDimensions().y(); c.y()++ )
{
for( c.x() = 0; c.x() < grid.getDimensions().x(); c.x()++ )
{
entity.refresh();
typename MeshType::PointType v = center< EntityType >::get( entity );
for( int j = 0; j < v.getSize(); j++ )
str << v[ j ] << " ";
str << scale * function.getData().getElement( entity.getIndex() ) << "\n";
}
str << "\n";
}
return true;
}
};
} // namespace Functions
} // namespace TNL
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment