Skip to content
Snippets Groups Projects
Commit 24a38646 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Refactoring MeshFunctionGnuplotWriter

parent b0df95ea
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,6 @@ SET( headers Domain.h
MeshFunctionEvaluator.h
MeshFunctionEvaluator_impl.h
MeshFunctionGnuplotWriter.h
MeshFunctionGnuplotWriter_impl.h
MeshFunctionNormGetter.h
MeshFunctionVTKWriter.h
OperatorFunction.h
......
......@@ -13,175 +13,73 @@
#include <TNL/Meshes/Grid.h>
namespace TNL {
namespace Functions {
template< typename, int, typename > class MeshFunction;
namespace Meshes {
template< typename, typename, typename > class MeshEntity;
}
namespace Functions {
template< typename MeshFunction >
class MeshFunctionGnuplotWriter
{
public:
static bool write( const MeshFunction& function,
std::ostream& str,
const double& scale );
};
/***
* 1D grids cells
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
class MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, 1, Real > >
{
public:
typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType;
typedef Real RealType;
typedef Functions::MeshFunction< MeshType, 1, RealType > MeshFunctionType;
static bool write( const MeshFunctionType& function,
std::ostream& str,
const double& scale );
};
/***
* 1D grids vertices
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
class MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, 0, Real > >
{
public:
typedef Meshes::Grid< 1, MeshReal, Device, MeshIndex > MeshType;
typedef Real RealType;
typedef Functions::MeshFunction< MeshType, 0, RealType > MeshFunctionType;
static bool write( const MeshFunctionType& function,
std::ostream& str,
const double& scale );
};
/***
* 2D grids cells
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
class MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, 2, Real > >
{
public:
typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType;
typedef Real RealType;
typedef Functions::MeshFunction< MeshType, 2, RealType > MeshFunctionType;
static bool write( const MeshFunctionType& function,
std::ostream& str,
const double& scale );
};
/***
* 2D grids faces
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
class MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, 1, Real > >
{
public:
typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType;
typedef Real RealType;
typedef Functions::MeshFunction< MeshType, 1, RealType > MeshFunctionType;
static bool write( const MeshFunctionType& function,
std::ostream& str,
const double& scale );
};
/***
* 2D grids vertices
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
class MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, 0, Real > >
{
public:
typedef Meshes::Grid< 2, MeshReal, Device, MeshIndex > MeshType;
typedef Real RealType;
typedef Functions::MeshFunction< MeshType, 0, RealType > MeshFunctionType;
static bool write( const MeshFunctionType& function,
std::ostream& str,
const double& scale );
};
/***
* 3D grids cells
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
class MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, 3, Real > >
{
public:
typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType;
typedef Real RealType;
typedef Functions::MeshFunction< MeshType, 3, RealType > MeshFunctionType;
static bool write( const MeshFunctionType& function,
std::ostream& str,
const double& scale );
};
/***
* 3D grids faces
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
class MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, 2, Real > >
{
public:
typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType;
typedef Real RealType;
typedef Functions::MeshFunction< MeshType, 2, RealType > MeshFunctionType;
static bool write( const MeshFunctionType& function,
std::ostream& str,
const double& scale );
};
/***
* 3D grids vertices
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
class MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, 0, Real > >
{
public:
typedef Meshes::Grid< 3, MeshReal, Device, MeshIndex > MeshType;
typedef Real RealType;
typedef Functions::MeshFunction< MeshType, 0, RealType > MeshFunctionType;
static bool write( const MeshFunctionType& function,
std::ostream& str,
const double& scale );
using MeshType = typename MeshFunction::MeshType;
using EntityType = typename MeshType::template EntityType< MeshFunction::getEntitiesDimension() >;
using GlobalIndex = typename MeshType::GlobalIndexType;
template< typename Entity, int dim = Entity::getEntityDimension() >
struct center
{
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())
{
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 )
{
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 )
{
throw "not implemented";
}
};
public:
static bool write( const MeshFunction& function,
std::ostream& str,
const double& scale = 1.0 )
{
const MeshType& mesh = function.getMesh();
const GlobalIndex entitiesCount = mesh.template getEntitiesCount< EntityType >();
for( GlobalIndex i = 0; i < entitiesCount; i++ ) {
const EntityType& entity = mesh.template getEntity< EntityType >( i );
typename MeshType::PointType v = center< EntityType >::get( entity );
for( int j = 0; j < v.getSize(); j++ )
str << v[ j ] << " ";
str << scale * function.getData().getElement( i ) << "\n";
}
return true;
}
};
} // namespace Functions
} // namespace TNL
#include <TNL/Functions/MeshFunctionGnuplotWriter_impl.h>
/***************************************************************************
MeshFunctionGnuplotWriter.h - description
-------------------
begin : Jan 28, 2016
copyright : (C) 2016 by oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/* See Copyright Notice in tnl/Copyright */
#pragma once
#include <TNL/Functions/MeshFunctionGnuplotWriter.h>
namespace TNL {
namespace Functions {
template< typename MeshFunction >
bool
MeshFunctionGnuplotWriter< MeshFunction >::
write( const MeshFunction& function,
std::ostream& str,
const double& scale )
{
std::cerr << "Gnuplot writer for mesh functions defined on mesh type " << MeshFunction::MeshType::getType() << " is not (yet) implemented." << std::endl;
return false;
}
/****
* 1D grid, cells
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
bool
MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, 1, Real > >::
write( const MeshFunctionType& function,
std::ostream& str,
const double& scale )
{
const MeshType& mesh = function.getMesh();
typename MeshType::Cell entity( mesh );
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() < mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
return true;
}
/****
* 1D grid, vertices
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
bool
MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 1, MeshReal, Device, MeshIndex >, 0, Real > >::
write( const MeshFunctionType& function,
std::ostream& str,
const double& scale )
{
const MeshType& mesh = function.getMesh();
typename MeshType::Vertex entity( mesh );
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() <= mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
return true;
}
/****
* 2D grid, cells
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
bool
MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, 2, Real > >::
write( const MeshFunctionType& function,
std::ostream& str,
const double& scale )
{
const MeshType& mesh = function.getMesh();
typename MeshType::Cell entity( mesh );
for( entity.getCoordinates().y() = 0;
entity.getCoordinates().y() < mesh.getDimensions().y();
entity.getCoordinates().y() ++ )
{
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() < mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " " << v.y() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
str << std::endl;
}
return true;
}
/****
* 2D grid, faces
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
bool
MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, 1, Real > >::
write( const MeshFunctionType& function,
std::ostream& str,
const double& scale )
{
const MeshType& mesh = function.getMesh();
typedef typename MeshType::Face EntityType;
typedef typename EntityType::EntityOrientationType EntityOrientation;
EntityType entity( mesh );
entity.setOrientation( EntityOrientation( 1.0, 0.0 ) );
for( entity.getCoordinates().y() = 0;
entity.getCoordinates().y() < mesh.getDimensions().y();
entity.getCoordinates().y() ++ )
{
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() <= mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " " << v.y() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
str << std::endl;
}
entity.setOrientation( EntityOrientation( 0.0, 1.0 ) );
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() < mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
{
for( entity.getCoordinates().y() = 0;
entity.getCoordinates().y() <= mesh.getDimensions().y();
entity.getCoordinates().y() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " " << v.y() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
str << std::endl;
}
return true;
}
/****
* 2D grid, vertices
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
bool
MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 2, MeshReal, Device, MeshIndex >, 0, Real > >::
write( const MeshFunctionType& function,
std::ostream& str,
const double& scale )
{
const MeshType& mesh = function.getMesh();
typename MeshType::Vertex entity( mesh );
for( entity.getCoordinates().y() = 0;
entity.getCoordinates().y() <= mesh.getDimensions().y();
entity.getCoordinates().y() ++ )
{
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() <= mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " " << v.y() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
str << std::endl;
}
return true;
}
/****
* 3D grid, cells
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
bool
MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, 3, Real > >::
write( const MeshFunctionType& function,
std::ostream& str,
const double& scale )
{
const MeshType& mesh = function.getMesh();
typename MeshType::Cell entity( mesh );
for( entity.getCoordinates().z() = 0;
entity.getCoordinates().z() < mesh.getDimensions().z();
entity.getCoordinates().z() ++ )
for( entity.getCoordinates().y() = 0;
entity.getCoordinates().y() < mesh.getDimensions().y();
entity.getCoordinates().y() ++ )
{
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() < mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " " << v.y() << " " << v.z() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
str << std::endl;
}
return true;
}
/****
* 3D grid, faces
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
bool
MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, 2, Real > >::
write( const MeshFunctionType& function,
std::ostream& str,
const double& scale )
{
const MeshType& mesh = function.getMesh();
typedef typename MeshType::Face EntityType;
typedef typename EntityType::EntityOrientationType EntityOrientation;
EntityType entity( mesh );
entity.setOrientation( EntityOrientation( 1.0, 0.0, 0.0 ) );
for( entity.getCoordinates().z() = 0;
entity.getCoordinates().z() < mesh.getDimensions().z();
entity.getCoordinates().z() ++ )
for( entity.getCoordinates().y() = 0;
entity.getCoordinates().y() < mesh.getDimensions().y();
entity.getCoordinates().y() ++ )
{
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() <= mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " " << v.y() << " " << v.z() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
str << std::endl;
}
entity.setOrientation( EntityOrientation( 0.0, 1.0, 0.0 ) );
for( entity.getCoordinates().z() = 0;
entity.getCoordinates().z() < mesh.getDimensions().z();
entity.getCoordinates().z() ++ )
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() < mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
{
for( entity.getCoordinates().y() = 0;
entity.getCoordinates().y() <= mesh.getDimensions().y();
entity.getCoordinates().y() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " " << v.y() << " " << v.z() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
str << std::endl;
}
entity.setOrientation( EntityOrientation( 0.0, 0.0, 1.0 ) );
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() < mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
for( entity.getCoordinates().y() = 0;
entity.getCoordinates().y() <= mesh.getDimensions().y();
entity.getCoordinates().y() ++ )
{
for( entity.getCoordinates().z() = 0;
entity.getCoordinates().z() < mesh.getDimensions().z();
entity.getCoordinates().z() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " " << v.y() << " " << v.z() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
str << std::endl;
}
return true;
}
/****
* 3D grid, vertices
*/
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real >
bool
MeshFunctionGnuplotWriter< MeshFunction< Meshes::Grid< 3, MeshReal, Device, MeshIndex >, 0, Real > >::
write( const MeshFunctionType& function,
std::ostream& str,
const double& scale )
{
const MeshType& mesh = function.getMesh();
typename MeshType::Vertex entity( mesh );
for( entity.getCoordinates().z() = 0;
entity.getCoordinates().z() <= mesh.getDimensions().z();
entity.getCoordinates().z() ++ )
for( entity.getCoordinates().y() = 0;
entity.getCoordinates().y() <= mesh.getDimensions().y();
entity.getCoordinates().y() ++ )
{
for( entity.getCoordinates().x() = 0;
entity.getCoordinates().x() <= mesh.getDimensions().x();
entity.getCoordinates().x() ++ )
{
entity.refresh();
typename MeshType::PointType v = entity.getCenter();
str << v.x() << " " << v.y() << " " << v.z() << " "
<< scale * function.getData().getElement( entity.getIndex() ) << std::endl;
}
str << std::endl;
}
return true;
}
} // namespace Functions
} // namespace TNL
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment