From 352c92740fd080a9157ebb60d3e5f6e1058a1ce9 Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Mon, 6 Feb 2017 14:46:40 +0100 Subject: [PATCH] Adding analytic operators for basic transformations: - sign - Heaviside - smooth Heaviside - shift - rotation --- examples/advection/advectionProblem_impl.h | 25 +------ src/TNL/Operators/Analytic/CMakeLists.txt | 10 +++ src/TNL/Operators/Analytic/Heaviside.h | 41 ++++++++++++ src/TNL/Operators/Analytic/Rotation.h | 68 ++++++++++++++++++++ src/TNL/Operators/Analytic/Shift.h | 56 ++++++++++++++++ src/TNL/Operators/Analytic/Sign.h | 44 +++++++++++++ src/TNL/Operators/Analytic/SmoothHeaviside.h | 57 ++++++++++++++++ src/TNL/Operators/CMakeLists.txt | 1 + 8 files changed, 280 insertions(+), 22 deletions(-) create mode 100755 src/TNL/Operators/Analytic/CMakeLists.txt create mode 100644 src/TNL/Operators/Analytic/Heaviside.h create mode 100644 src/TNL/Operators/Analytic/Rotation.h create mode 100644 src/TNL/Operators/Analytic/Shift.h create mode 100644 src/TNL/Operators/Analytic/Sign.h create mode 100644 src/TNL/Operators/Analytic/SmoothHeaviside.h diff --git a/examples/advection/advectionProblem_impl.h b/examples/advection/advectionProblem_impl.h index cd37f52eff..7fe70760bb 100644 --- a/examples/advection/advectionProblem_impl.h +++ b/examples/advection/advectionProblem_impl.h @@ -105,7 +105,7 @@ setInitialCondition( const Config::ParameterContainer& parameters, const RealType& size = parameters.getParameter< double >( "realSize" ) / ::pow(count, 1.0/dimensions); const String& beginChoice = parameters.getParameter< String >( "begin" ); std::cout << beginChoice << " " << dimensions << " " << size << " " << count << " "<< 1/dimensions << std::endl; - getchar(); + //getchar(); if (beginChoice == "sin_square") { double constantFunction; @@ -166,8 +166,8 @@ setInitialCondition( const Config::ParameterContainer& parameters, }; }; //setting velocity field - std::cout << *dofs << std::endl; - getchar(); + //std::cout << *dofs << std::endl; + //getchar(); /*const String& initialConditionFile = parameters.getParameter< String >( "initial-condition" ); if( ! dofs.load( initialConditionFile ) ) { @@ -316,25 +316,6 @@ assemblyLinearSystem( const RealType& time, DofVectorPointer& b, MeshDependentDataPointer& meshDependentData ) { - /*LinearSystemAssembler< Mesh, - MeshFunctionType, - DifferentialOperator, - BoundaryCondition, - RightHandSide, - BackwardTimeDiscretisation, - Matrix, - DofVectorType > systemAssembler; - - MeshFunction< Mesh > u( mesh, _u ); - systemAssembler.template assembly< typename Mesh::Cell >( time, - tau, - mesh, - this->differentialOperator, - this->boundaryCondition, - this->rightHandSide, - u, - matrix, - b );*/ } } // namespace TNL diff --git a/src/TNL/Operators/Analytic/CMakeLists.txt b/src/TNL/Operators/Analytic/CMakeLists.txt new file mode 100755 index 0000000000..5f91292966 --- /dev/null +++ b/src/TNL/Operators/Analytic/CMakeLists.txt @@ -0,0 +1,10 @@ +SET( headers Sign.h + Heaviside.h + SmoothHeaviside.h + Shift.h + Rotation.h ) + +SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL/Operators/Analytic ) + + +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/TNL/Operators/Analytic ) diff --git a/src/TNL/Operators/Analytic/Heaviside.h b/src/TNL/Operators/Analytic/Heaviside.h new file mode 100644 index 0000000000..75f96d78f4 --- /dev/null +++ b/src/TNL/Operators/Analytic/Heaviside.h @@ -0,0 +1,41 @@ +/*************************************************************************** + Heaviside.h - description + ------------------- + begin : Feb 6, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/Functions/Domain.h> +#include <TNL/Devices/Cuda.h> + +namespace TNL { +namespace Operators { +namespace Analytic { + + +template< typename Function > +class Heaviside : public Functions::Domain< Function::getDomainDimenions(), + Function::getDomainTyep() > +{ + public: + + typedef typename Function::RealType RealType; + typedef Containers::StaticVector< Function::getDomainDimenions(), + RealType > VertexType; + + __cuda_callable__ + RealType operator()( const Function& function, + const VertexType& vertex, + const RealType& time = 0 ) const + { + const RealType aux = function( vertex ); + if( aux > 0.0 ) + return 1.0; + return 0.0; + } +}; diff --git a/src/TNL/Operators/Analytic/Rotation.h b/src/TNL/Operators/Analytic/Rotation.h new file mode 100644 index 0000000000..1e4a04dd9b --- /dev/null +++ b/src/TNL/Operators/Analytic/Rotation.h @@ -0,0 +1,68 @@ +/*************************************************************************** + Rotation.h - description + ------------------- + begin : Feb 6, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/Functions/Domain.h> +#include <TNL/Devices/Cuda.h> + +namespace TNL { +namespace Operators { +namespace Analytic { + + +template< typename Real, + int Dimensions > +class RotationBase +{ + public: + typedef Real RealType; + typedef Containers::StaticVector< Dimenions, RealType > VertexType; + + RotationBase() : center( 0.0 ) {}; + + void setCenter( const VertexType& center ) + { + this->center = center; + } + + __cuda_callable__ + const VertexType& getCenter() const + { + return this->center; + } + + protected: + + VertexType center; +}; + +template< typename Function, + int Dimensions = Function::getDomainDimenions() > +class Rotation; + +template< typename Function, 1 > +class Rotation: public Functions::Domain< Function::getDomainDimenions(), + Function::getDomainType() > +{ + public: + + typedef typename Function::RealType RealType; + typedef Containers::StaticVector< Function::getDomainDimenions(), + RealType > VertexType; + + __cuda_callable__ + RealType operator()( const Function& function, + const VertexType& vertex, + const RealType& time = 0 ) const + { + return function( vertex ); + } +}; diff --git a/src/TNL/Operators/Analytic/Shift.h b/src/TNL/Operators/Analytic/Shift.h new file mode 100644 index 0000000000..f23410632f --- /dev/null +++ b/src/TNL/Operators/Analytic/Shift.h @@ -0,0 +1,56 @@ +/*************************************************************************** + Shift.h - description + ------------------- + begin : Feb 6, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/Functions/Domain.h> +#include <TNL/Devices/Cuda.h> + +namespace TNL { +namespace Operators { +namespace Analytic { + + +template< typename Function > +class Shift : public Functions::Domain< Function::getDomainDimenions(), + Function::getDomainTyep() > +{ + public: + + typedef typename Function::RealType RealType; + typedef Containers::StaticVector< Function::getDomainDimenions(), + RealType > VertexType; + + + Shift() : shift( 0.0 ) {}; + + void setShift( const VertexType& vertex ) + { + this->shift = shift; + } + + __cuda_callable__ + const VertexType& getShift() const + { + return this->shift; + } + + __cuda_callable__ + RealType operator()( const Function& function, + const VertexType& vertex, + const RealType& time = 0 ) const + { + return function( vertex + shift ); + } + + protected: + + VerexType shift; +}; diff --git a/src/TNL/Operators/Analytic/Sign.h b/src/TNL/Operators/Analytic/Sign.h new file mode 100644 index 0000000000..8ba59255b2 --- /dev/null +++ b/src/TNL/Operators/Analytic/Sign.h @@ -0,0 +1,44 @@ +/*************************************************************************** + ExpBump.h - description + ------------------- + begin : Dec 5, 2013 + copyright : (C) 2013 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/Functions/Domain.h> +#include <TNL/Devices/Cuda.h> + +namespace TNL { +namespace Operators { +namespace Analytic { + + +template< typename Function > +class Sign : public Functions::Domain< Function::getDomainDimenions(), + Function::getDomainTyep() > +{ + public: + + typedef typename Function::RealType RealType; + typedef Containers::StaticVector< Function::getDomainDimenions(), + RealType > VertexType; + + __cuda_callable__ + RealType operator()( const Function& function, + const VertexType& vertex, + const RealType& time = 0 ) const + { + const RealType aux = function( vertex ); + if( aux > 0.0 ) + return 1.0; + else + if( aux < 0.0 ) + return -1.0; + return 0.0; + } +}; diff --git a/src/TNL/Operators/Analytic/SmoothHeaviside.h b/src/TNL/Operators/Analytic/SmoothHeaviside.h new file mode 100644 index 0000000000..96d753270d --- /dev/null +++ b/src/TNL/Operators/Analytic/SmoothHeaviside.h @@ -0,0 +1,57 @@ +/*************************************************************************** + SmoothHeaviside.h - description + ------------------- + begin : Feb 6, 2017 + copyright : (C) 2017 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +#pragma once + +#include <TNL/Functions/Domain.h> +#include <TNL/Devices/Cuda.h> + +namespace TNL { +namespace Operators { +namespace Analytic { + + +template< typename Function > +class SmoothHeaviside : public Functions::Domain< Function::getDomainDimenions(), + Function::getDomainTyep() > +{ + public: + + typedef typename Function::RealType RealType; + typedef Containers::StaticVector< Function::getDomainDimenions(), + RealType > VertexType; + + SmoothHeaviside() + : sharpness( 1.0 ) + + void setSharpness( const RealType& sharpness ) + { + this->sharpness = sharpness; + } + + __cuda_callable__ + const RealType getShaprness() const + { + return this->sharpness; + } + + __cuda_callable__ + RealType operator()( const Function& function, + const VertexType& vertex, + const RealType& time = 0 ) const + { + const RealType aux = function( vertex ); + return 1.0 / ( 1.0 + exp( -2.0 * sharpness * aux ) ) + } + + protected: + + RealType sharpness; +}; diff --git a/src/TNL/Operators/CMakeLists.txt b/src/TNL/Operators/CMakeLists.txt index dcdb7d3dda..721e6ebc81 100755 --- a/src/TNL/Operators/CMakeLists.txt +++ b/src/TNL/Operators/CMakeLists.txt @@ -1,3 +1,4 @@ +ADD_SUBDIRECTORY( Analytic ) ADD_SUBDIRECTORY( diffusion ) ADD_SUBDIRECTORY( euler ) ADD_SUBDIRECTORY( interpolants ) -- GitLab