From 3c4cbac59ef1b29de0f539efd492b53d0b0134dc Mon Sep 17 00:00:00 2001
From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz>
Date: Sun, 21 Sep 2014 19:46:01 +0200
Subject: [PATCH] Implementing the EOC test.

---
 TODO                                          | 35 ++++--------------
 .../tnl-run-heat-equation-eoc-test            | 12 ++++---
 src/functions/tnlTestFunction.h               |  3 ++
 src/implementation/CMakeLists.txt             |  4 +--
 src/implementation/functions/CMakeLists.txt   | 11 +++---
 .../functions/tnlTestFunction_impl.cpp        | 36 +++++++++++++++++++
 .../functions/tnlTestFunction_impl.cu         | 36 +++++++++++++++++++
 .../functions/tnlTestFunction_impl.h          | 30 ++++++++++++++++
 .../tnlDirichletBoundaryConditions_impl.h     | 10 +++---
 .../tnlDirichletBoundaryConditions.h          |  6 ++--
 tools/src/tnl-diff.cpp                        | 10 ++----
 tools/src/tnl-diff.h                          | 29 ++++++++-------
 12 files changed, 152 insertions(+), 70 deletions(-)
 create mode 100644 src/implementation/functions/tnlTestFunction_impl.cpp
 create mode 100644 src/implementation/functions/tnlTestFunction_impl.cu

diff --git a/TODO b/TODO
index 765655209e..601def17fe 100644
--- a/TODO
+++ b/TODO
@@ -1,36 +1,13 @@
+TODO: neumanovy okrajove podminky
+
 TODO: implementovat tridu tnlFileName pro generovani jmen souboru
 
 TODO: metodu pro tnlString pro nahrazeni napr. podretezce XXXXX indexem 00001 tj. uXXXXX.bin -> u00001.bin
       to by melo byt robustnejsi, nez doposavadni pristup 
 
-TODO: implementovat tridu tnlParabolicSolver pro odvozovani resicu k casove promennym uloham
-
-
-TODO: objekt pro osetreni chyb - zavedeni funkce tnlGetError
-      - mozna dat do tnlObject priznak, zda je objekt ok nebo 
-        v nefunkcnim stavu   
-
-TODO: implementovat casovace merici jen cas resicu
-
-     
+TODO: vyjimky 
+    
 TODO: implementovat maticovy format COO - mimo jine by se dal vyuzit k rychlejsimu parsovani mtx souboru
 
-TODO: implementovat metodu tnlObject passToDevice, ktera vytvori obraz daneho objektu na GPU.
-      Vrati ukazatel na tridu, ktetou lze pouzivat v kernelech. To by melo zjednodusti psani kernelu a
-      priblizit je kodu pro CPU.
-
-TODO: Zkusit z tnlExplicitSolver udelat tnlTimeSolver, od nej odvodit tnlEulerSolver, tnlMersonSolver a
-      tnlParabolicSolver. Objekt by obsahoval i metodu pro ukladani stavu v prubehu vypoctu. 
-      
-TODO: - odvodit tnlArray primo z tnlArrayManager
-      - tnlGrid prejmenovat na tnlGridOfNodes
-      - zavest tnlGrid podle tnlMesh - tj. bude to pouze popis site bez sitove fce.
-      - po prepsani vsech schemat se tnlGridOfNodes zrusi
-      - zavest tnlObjectArray pro pole objektu - rozdil je v tom, ze treba save a load bude volat pro kazdy element
-        jeho metodu save a load apod.           
-      
-DONE: Nahradit mGrid2D, mGrid3D za mGrid obecne dimenze 
-
-DONE: trida tnlArray - misto tnlLongVector a tnlField (nebo postavenou na tnlLongVector)
-      template< typename REAL, int DIM, tnlDevice >
-DONE: do tnlGrid pridat metodu pro osetreni Dirichletovych a Neumannovych o.p.           
\ No newline at end of file
+TODO: prubezne ukladani vysledku behem vypoctu 
+                 
\ No newline at end of file
diff --git a/examples/heat-equation/tnl-run-heat-equation-eoc-test b/examples/heat-equation/tnl-run-heat-equation-eoc-test
index 365503ee46..098a247748 100644
--- a/examples/heat-equation/tnl-run-heat-equation-eoc-test
+++ b/examples/heat-equation/tnl-run-heat-equation-eoc-test
@@ -1,8 +1,8 @@
 #!/bin/bash
 
 device="host"
-dimensions="1D" # 2D 3D"
-sizes1D="16" # 32 64 128 256 512"
+dimensions="1D 2D 3D"
+sizes1D="16 32 64 128 256 512"
 sizes2D="16 32 64 128 256 512"
 sizes3D="16 32 64 128"
 testFunctions="exp-bump"
@@ -80,7 +80,7 @@ solve()
    timeDiscretisation=$1
    discreteSolver=$2
    ${solverName} --mesh mesh.tnl \
-                 --initial-condition exact-u-0000.tnl \
+                 --initial-condition exact-u-00000.tnl \
                  --time-discretisation ${timeDiscretisation} \
                  --discrete-solver ${discreteSolver} \
                  --test-function ${testFunction}\
@@ -107,9 +107,10 @@ computeError()
 {
 
    tnl-diff --mesh mesh.tnl \
-            --input-files numericalSolution-*.tnl analyticSolution-*.tnl \
+            --input-files exact-u-*.tnl u-*.tnl \
             --mode halves \
-            --output-file ${dofSize}-dofs 
+            --snapshot-period ${snapshotPeriod} \
+            --output-file errors.txt 
 }
 
 runTest()
@@ -149,6 +150,7 @@ runTest()
                   solve explicit merson
                   mv computation-in-progress computation-done
                fi
+               computeError
             cd ..
          done
 
diff --git a/src/functions/tnlTestFunction.h b/src/functions/tnlTestFunction.h
index 215d921c70..746232d2a6 100644
--- a/src/functions/tnlTestFunction.h
+++ b/src/functions/tnlTestFunction.h
@@ -19,6 +19,9 @@
 #define TNLTESTFUNCTION_H_
 
 #include <core/tnlHost.h>
+#include <core/vectors/tnlStaticVector.h>
+#include <config/tnlConfigDescription.h>
+#include <config/tnlParameterContainer.h>
 
 template< int FunctionDimensions,
           typename Real = double,
diff --git a/src/implementation/CMakeLists.txt b/src/implementation/CMakeLists.txt
index fcfa595dcf..876a8f8bd4 100755
--- a/src/implementation/CMakeLists.txt
+++ b/src/implementation/CMakeLists.txt
@@ -13,7 +13,7 @@ IF( BUILD_CUDA )
         ${tnl_implementation_core_CUDA__SOURCES}
         ${tnl_implementation_matrices_CUDA__SOURCES}
         ${tnl_implementation_mesh_CUDA__SOURCES}
-        ${tnl_implementation_generators_CUDA__SOURCES}
+        ${tnl_implementation_functions_CUDA__SOURCES}
         ${tnl_implementation_operators_CUDA__SOURCES}
         ${tnl_implementation_solvers_CUDA__SOURCES}         
         PARENT_SCOPE )
@@ -22,7 +22,7 @@ ENDIF()
 set( tnl_implementation_SOURCES 
      ${tnl_implementation_config_SOURCES}
      ${tnl_implementation_core_SOURCES}
-     ${tnl_implementation_generators_SOURCES}
+     ${tnl_implementation_functions_SOURCES}
      ${tnl_implementation_matrices_SOURCES}
      ${tnl_implementation_mesh_SOURCES}
      ${tnl_implementation_operators_SOURCES}
diff --git a/src/implementation/functions/CMakeLists.txt b/src/implementation/functions/CMakeLists.txt
index 65cd33c652..4dbc5b94ac 100755
--- a/src/implementation/functions/CMakeLists.txt
+++ b/src/implementation/functions/CMakeLists.txt
@@ -4,19 +4,20 @@ SET( headers tnlFunctionDiscretizer_impl.h
              tnlSinBumpsFunction_impl.h
              tnlSinWaveFunction_impl.h )
 
-SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/implementation/generators/functions )
+SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/implementation/functions )
 set( common_SOURCES
-      )       
+     ${CURRENT_DIR}/tnlTestFunction_impl.cpp )       
 
 IF( BUILD_CUDA )
-   set( tnl_implementation_generators_functions_CUDA__SOURCES
+   set( tnl_implementation_functions_CUDA__SOURCES
         ${common_SOURCES} 
+        ${CURRENT_DIR}/tnlTestFunction_impl.cu
         PARENT_SCOPE )
 ENDIF()    
 
-set( tnl_implementation_generators_functions_SOURCES     
+set( tnl_implementation_functions_SOURCES     
      ${common_SOURCES}
      PARENT_SCOPE )
         
-INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/implementation/generators/functions )
+INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/implementation/functions )
 
diff --git a/src/implementation/functions/tnlTestFunction_impl.cpp b/src/implementation/functions/tnlTestFunction_impl.cpp
new file mode 100644
index 0000000000..c8baf09f22
--- /dev/null
+++ b/src/implementation/functions/tnlTestFunction_impl.cpp
@@ -0,0 +1,36 @@
+/***************************************************************************
+                          tnlTestFunction_impl.cpp  -  description
+                             -------------------
+    begin                : Sep 21, 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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+
+#ifdef TEMPLATE_EXPLICIT_INSTANTIATION
+
+#include <functions/tnlTestFunction.h>
+
+template class tnlTestFunction< 1, float, tnlHost >;
+template class tnlTestFunction< 2, float, tnlHost >;
+template class tnlTestFunction< 3, float, tnlHost >;
+
+template class tnlTestFunction< 1, double, tnlHost >;
+template class tnlTestFunction< 2, double, tnlHost >;
+template class tnlTestFunction< 3, double, tnlHost >;
+
+template class tnlTestFunction< 1, long double, tnlHost >;
+template class tnlTestFunction< 2, long double, tnlHost >;
+template class tnlTestFunction< 3, long double, tnlHost >;
+
+#endif
+
diff --git a/src/implementation/functions/tnlTestFunction_impl.cu b/src/implementation/functions/tnlTestFunction_impl.cu
new file mode 100644
index 0000000000..7304a74c81
--- /dev/null
+++ b/src/implementation/functions/tnlTestFunction_impl.cu
@@ -0,0 +1,36 @@
+/***************************************************************************
+                          tnlTestFunction_impl.cu  -  description
+                             -------------------
+    begin                : Sep 21, 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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifdef TEMPLATE_EXPLICIT_INSTANTIATION
+#ifdef HAVE_CUDA
+
+#include <functions/tnlTestFunction.h>
+
+template class tnlTestFunction< 1, float, tnlCuda >;
+template class tnlTestFunction< 2, float, tnlCuda >;
+template class tnlTestFunction< 3, float, tnlCuda >;
+
+template class tnlTestFunction< 1, double, tnlCuda >;
+template class tnlTestFunction< 2, double, tnlCuda >;
+template class tnlTestFunction< 3, double, tnlCuda >;
+
+template class tnlTestFunction< 1, long double, tnlCuda >;
+template class tnlTestFunction< 2, long double, tnlCuda >;
+template class tnlTestFunction< 3, long double, tnlCuda >;
+
+#endif
+#endif
diff --git a/src/implementation/functions/tnlTestFunction_impl.h b/src/implementation/functions/tnlTestFunction_impl.h
index 3eb99ea8eb..e7242f002d 100644
--- a/src/implementation/functions/tnlTestFunction_impl.h
+++ b/src/implementation/functions/tnlTestFunction_impl.h
@@ -299,5 +299,35 @@ tnlTestFunction< FunctionDimensions, Real, Device >::
    }
 }
 
+#ifdef TEMPLATE_EXPLICIT_INSTANTIATION
+
+extern template class tnlTestFunction< 1, float, tnlHost >;
+extern template class tnlTestFunction< 2, float, tnlHost >;
+extern template class tnlTestFunction< 3, float, tnlHost >;
+
+extern template class tnlTestFunction< 1, double, tnlHost >;
+extern template class tnlTestFunction< 2, double, tnlHost >;
+extern template class tnlTestFunction< 3, double, tnlHost >;
+
+extern template class tnlTestFunction< 1, long double, tnlHost >;
+extern template class tnlTestFunction< 2, long double, tnlHost >;
+extern template class tnlTestFunction< 3, long double, tnlHost >;
+
+#ifdef HAVE_CUDA
+extern template class tnlTestFunction< 1, float, tnlCuda>;
+extern template class tnlTestFunction< 2, float, tnlCuda >;
+extern template class tnlTestFunction< 3, float, tnlCuda >;
+
+extern template class tnlTestFunction< 1, double, tnlCuda >;
+extern template class tnlTestFunction< 2, double, tnlCuda >;
+extern template class tnlTestFunction< 3, double, tnlCuda >;
+
+extern template class tnlTestFunction< 1, long double, tnlCuda >;
+extern template class tnlTestFunction< 2, long double, tnlCuda >;
+extern template class tnlTestFunction< 3, long double, tnlCuda >;
+#endif
+
+#endif
+
 
 #endif /* TNLTESTFUNCTION_IMPL_H_ */
diff --git a/src/implementation/operators/tnlDirichletBoundaryConditions_impl.h b/src/implementation/operators/tnlDirichletBoundaryConditions_impl.h
index 18685874b0..530d9f2b5c 100644
--- a/src/implementation/operators/tnlDirichletBoundaryConditions_impl.h
+++ b/src/implementation/operators/tnlDirichletBoundaryConditions_impl.h
@@ -44,9 +44,10 @@ template< typename MeshReal,
           typename Index >
 bool
 tnlDirichletBoundaryConditions< tnlGrid< 2,MeshReal, Device, MeshIndex >, Function, Real, Index >::
-init( const tnlParameterContainer& parameters )
+init( const tnlParameterContainer& parameters,
+      const tnlString& prefix )
 {
-   return function.init( parameters, "boundary-conditions-" );
+   return function.init( parameters, prefix );
 }
 
 
@@ -78,9 +79,10 @@ template< typename MeshReal,
           typename Index >
 bool
 tnlDirichletBoundaryConditions< tnlGrid< 3,MeshReal, Device, MeshIndex >, Function, Real, Index >::
-init( const tnlParameterContainer& parameters )
+init( const tnlParameterContainer& parameters,
+      const tnlString& prefix )
 {
-   return function.init( parameters, "boundary-conditions-" );
+   return function.init( parameters, prefix );
 }
 
 template< typename MeshReal,
diff --git a/src/operators/tnlDirichletBoundaryConditions.h b/src/operators/tnlDirichletBoundaryConditions.h
index b03e97d258..29b1a199ef 100644
--- a/src/operators/tnlDirichletBoundaryConditions.h
+++ b/src/operators/tnlDirichletBoundaryConditions.h
@@ -71,7 +71,8 @@ class tnlDirichletBoundaryConditions< tnlGrid< 2, MeshReal, Device, MeshIndex >,
    typedef tnlStaticVector< 2, RealType > VertexType;
    typedef typename MeshType::CoordinatesType CoordinatesType;
 
-   bool init( const tnlParameterContainer& parameters );
+   bool init( const tnlParameterContainer& parameters,
+              const tnlString& prefix = "" );
 
    void setBoundaryConditions( const RealType& time,
                                const RealType& tau,
@@ -107,7 +108,8 @@ class tnlDirichletBoundaryConditions< tnlGrid< 3, MeshReal, Device, MeshIndex >,
    typedef tnlStaticVector< 3, RealType > VertexType;
    typedef typename MeshType::CoordinatesType CoordinatesType;
 
-   bool init( const tnlParameterContainer& parameters );
+   bool init( const tnlParameterContainer& parameters,
+              const tnlString& prefix = "" );
 
    void setBoundaryConditions( const RealType& time,
                                const RealType& tau,
diff --git a/tools/src/tnl-diff.cpp b/tools/src/tnl-diff.cpp
index e9ee5cc68c..b9dcffaefa 100644
--- a/tools/src/tnl-diff.cpp
+++ b/tools/src/tnl-diff.cpp
@@ -33,7 +33,7 @@ void setupConfig( tnlConfigDescription& config )
    config.addEntry< int >( "edges-skip", "Width of the edges that will be skipped - not included into the error norms.", 0 );
    config.addEntry< bool >( "write-graph", "Draws a graph in the Gnuplot format of the dependence of the error norm on t.", true );
    config.addEntry< bool >( "write-log-graph", "Draws a logarithmic graph in the Gnuplot format of the dependence of the error norm on t.", true );
-   config.addEntry< double >( "tau", "Time period between the subsequent solutions.", 0.0 );
+   config.addEntry< double >( "snapshot-period", "The period between consecutive snapshots.", 0.0 );
    config.addEntry< int >( "verbose", "Sets verbosity.", 1 );
 }
 
@@ -71,13 +71,7 @@ int main( int argc, char* argv[] )
    }
    if( parsedMeshType[ 0 ] == "tnlGrid" )
    {
-      tnlList< tnlString > parsedGeometryType;
-      if( ! parseObjectType( parsedMeshType[ 5 ], parsedGeometryType ) )
-      {
-         cerr << "Unable to parse the geometry type " << parsedMeshType[ 5 ] << "." << endl;
-         return false;
-      }
-      int dimensions = atoi( parsedGeometryType[ 1 ].getString() );
+      int dimensions = atoi( parsedMeshType[ 1 ].getString() );
       if( dimensions == 1 )
       {
          typedef tnlGrid< 1, double, tnlHost, int > MeshType;
diff --git a/tools/src/tnl-diff.h b/tools/src/tnl-diff.h
index 576963453e..c0013697c7 100644
--- a/tools/src/tnl-diff.h
+++ b/tools/src/tnl-diff.h
@@ -31,7 +31,7 @@ bool computeDifference( const Mesh& mesh, const tnlParameterContainer& parameter
    tnlList< tnlString > inputFiles = parameters. GetParameter< tnlList< tnlString > >( "input-files" );
    tnlString mode = parameters. GetParameter< tnlString >( "mode" );
    tnlString outputFileName = parameters. GetParameter< tnlString >( "output-file" );
-   double tau = parameters. GetParameter< double >( "tau" );
+   double snapshotPeriod = parameters. GetParameter< double >( "snapshot-period" );
    bool writeDifference = parameters. GetParameter< bool >( "write-difference" );
 
    fstream outputFile;
@@ -42,8 +42,8 @@ bool computeDifference( const Mesh& mesh, const tnlParameterContainer& parameter
       return false;
    }
    outputFile << "#";
-   if( tau != 0 )
-      outputFile << std::setw( 5 ) << "Time";
+   //if( tau != 0 )
+   outputFile << std::setw( 5 ) << "Time";
    outputFile << std::setw( 16 ) << "L1 diff."
               << std::setw( 16 ) << "L2 diff."
               << std::setw( 16 ) << "Max. diff." << endl;
@@ -71,8 +71,8 @@ bool computeDifference( const Mesh& mesh, const tnlParameterContainer& parameter
             outputFile.close();
             return false;
          }
-         if( tau != 0.0 )
-            outputFile << std::setw( 6 ) << i/2 * tau << " ";
+         //if( snapshotPeriod != 0.0 )
+         outputFile << std::setw( 6 ) << i/2 * snapshotPeriod << " ";
          i++;
       }
       if( mode == "sequence" )
@@ -96,8 +96,8 @@ bool computeDifference( const Mesh& mesh, const tnlParameterContainer& parameter
             outputFile.close();
             return false;
          }
-         if( tau != 0.0 )
-            outputFile << std::setw( 6 ) << ( i - 1 ) * tau << " ";
+         //if( snapshotPeriod != 0.0 )
+         outputFile << std::setw( 6 ) << ( i - 1 ) * snapshotPeriod << " ";
       }
       if( mode == "halves" )
       {
@@ -113,8 +113,8 @@ bool computeDifference( const Mesh& mesh, const tnlParameterContainer& parameter
             outputFile.close();
             return false;
          }
-         if( tau != 0.0 )
-            outputFile << std::setw( 6 ) << ( i - half ) * tau << " ";
+         //if( snapshotPeriod != 0.0 )
+         outputFile << std::setw( 6 ) << ( i - half ) * snapshotPeriod << " ";
       }
       Real l1Diff = mesh.getDifferenceLpNorm( v1, v2, 1.0 );
       Real l2Diff = mesh.getDifferenceLpNorm( v1, v2, 2.0 );
@@ -122,12 +122,11 @@ bool computeDifference( const Mesh& mesh, const tnlParameterContainer& parameter
       outputFile << std::setw( 16 ) << l1Diff
                  << std::setw( 16 ) << l2Diff
                  << std::setw( 16 ) << maxDiff << endl;
-      if( tau != 0.0 )
+      if( snapshotPeriod != 0.0 )
       {
-         totalL1Diff += tau * l1Diff;
-         totalL2Diff += tau * l2Diff * l2Diff;
+         totalL1Diff += snapshotPeriod * l1Diff;
+         totalL2Diff += snapshotPeriod * l2Diff * l2Diff;
          totalMaxDiff = Max( totalMaxDiff, maxDiff );
-         cout << totalL2Diff << endl;
       }
       if( writeDifference )
       {
@@ -142,9 +141,9 @@ bool computeDifference( const Mesh& mesh, const tnlParameterContainer& parameter
          diff.save( differenceFileName );
       }
    }
-   if( tau != 0 )
+   if( snapshotPeriod != 0 )
    {
-      outputFile << endl << "# Total differences:" << endl << endl;
+      outputFile << "----------------------------------------------------------" << endl;
       outputFile << std::setw( 8 ) << " "
                  << std::setw( 16 ) << totalL1Diff
                  << std::setw( 16 ) << sqrt( totalL2Diff )
-- 
GitLab