From e2b5c90034607475b88f50f2fc2210264a2dbbe7 Mon Sep 17 00:00:00 2001
From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz>
Date: Sun, 3 Aug 2014 16:28:22 +0200
Subject: [PATCH] Implementing the test function.

---
 src/functions/tnlConstantFunction.h           |  7 +-
 src/functions/tnlTestFunction.h               | 37 +++++++
 .../functions/tnlTestFunction_impl.h          | 97 +++++++++++++++++++
 3 files changed, 137 insertions(+), 4 deletions(-)
 create mode 100644 src/implementation/functions/tnlTestFunction_impl.h

diff --git a/src/functions/tnlConstantFunction.h b/src/functions/tnlConstantFunction.h
index 67920376c3..2c6254c5c9 100644
--- a/src/functions/tnlConstantFunction.h
+++ b/src/functions/tnlConstantFunction.h
@@ -21,15 +21,14 @@
 #include <core/vectors/tnlStaticVector.h>
 
 template< int FunctionDimensions,
-          typename Vertex = tnlStaticVector< FunctionDimensions, double >,
-          typename Device = tnlHost >
+          typename Real >
 class tnlConstantFunction
 {
    public:
 
    enum { Dimensions = FunctionDimensions };
-   typedef Vertex VertexType;
-   typedef typename VertexType::RealType RealType;
+   typedef Real RealType;
+   typedef tnlStaticVector< Dimensions, Real > VertexType;
 
    tnlConstantFunction();
 
diff --git a/src/functions/tnlTestFunction.h b/src/functions/tnlTestFunction.h
index e8cd3c9ee5..8a06a3e714 100644
--- a/src/functions/tnlTestFunction.h
+++ b/src/functions/tnlTestFunction.h
@@ -19,6 +19,43 @@
 #define TNLTESTFUNCTION_H_
 
 
+template< int FunctionDimensions,
+          typename Real,
+          typename Device >
+class tnlTestingFunction
+{
+   protected:
 
+   enum TestFunctions{ none,
+                       constant,
+                       expBump,
+                       sinBumps,
+                       sinWaves };
+
+   public:
+
+   enum{ Dimensions = FunctionDimensions };
+   typedef Real RealType;
+   typedef tnlStaticVector< Dimensions, Real > VertexType;
+
+   tnlTestingFunction();
+
+   bool init( const tnlParameterContainer& parameters );
+
+   template< typename Vertex,
+             typename Real = typename Vertex::RealType >
+   Real getValue( const Vertex& vertex ) const;
+
+   ~tnlTestingFunction();
+
+   protected:
+
+   void* function;
+
+   TestFunction functionType;
+
+};
+
+#include <implementation/functions/tnlTestFunction_impl.h>
 
 #endif /* TNLTESTFUNCTION_H_ */
diff --git a/src/implementation/functions/tnlTestFunction_impl.h b/src/implementation/functions/tnlTestFunction_impl.h
new file mode 100644
index 0000000000..9d8316346e
--- /dev/null
+++ b/src/implementation/functions/tnlTestFunction_impl.h
@@ -0,0 +1,97 @@
+/***************************************************************************
+                          tnlTestFunction_impl.h  -  description
+                             -------------------
+    begin                : Aug 3, 2014
+    copyright            : (C) 2014 by Tomas Oberhuber
+    email                : tomas.oberhuber@fjfi.cvut.cz
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef TNLTESTFUNCTION_IMPL_H_
+#define TNLTESTFUNCTION_IMPL_H_
+
+#include <functions/tnlConstantFunction.h>
+#include <functions/tnlExpBumpFunction.h>
+#include <functions/tnlSinBumpsFunction.h>
+#include <functions/tnlSinWavesFunction.h>
+
+template< int FunctionDimensions,
+          typename Real,
+          typename Device >
+tnlTestingFunction< FunctionDimensions, Real, Device >::
+tnlTestingFunction()
+: function( 0 ),
+  functionType( none )
+{
+}
+
+template< int FunctionDimensions,
+          typename Real,
+          typename Device >
+bool
+tnlTestingFunction< FunctionDimensions, Real, Device >::
+init( const tnlParameterContainer& parameters )
+{
+   const tnlString& testFunction = parameters.getParameter< tnlString >( "test-function" );
+
+   if( testFunction == "constant" )
+   {
+      typedef tnlConstantFunction< Dimensions, Real > FunctionType;
+      FunctionType* auxFunction = new FunctionType;
+      if( ! auxFunction->init( parameters ) )
+      {
+         delete auxFunction;
+         return false;
+      }
+      functionType = constant;
+      if( Device::DeviceType == tnlHostType )
+      {
+         function = auxFunction;
+      }
+      if( Device::DeviceType == tnlCudaType )
+      {
+         function = passToDevice( *auxFunction );
+      }
+   }
+   if( testFunction == "exp-bump" )
+   {
+
+   }
+   if( testFunction == "sin-bumps" )
+   {
+
+   }
+   if( testFunction == "sin-waves" )
+   {
+
+   }
+}
+
+template< int FunctionDimensions,
+          typename Real,
+          typename Device >
+tnlTestingFunction< FunctionDimensions, Real, Device >::
+~tnlTestingFunction()
+{
+   if( Device::DeviceType == tnlHostType )
+   {
+      switch( functionType )
+      {
+         case constant:
+            delete ( tnlConstantFunction< Dimensions, Real> * ) function;
+            break;
+      }
+   }
+
+}
+
+
+#endif /* TNLTESTFUNCTION_IMPL_H_ */
-- 
GitLab