Commit 3db0331a authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Removed StaticVectorFor from the Algorithms namespace

It is an implementation detail specific to the CutMeshFunction class,
not something that should be part of the public interface. There are
many problems with this approach: e.g. it does not scale to higher
dimensions and it is not parallel.
parent 82605ea8
Loading
Loading
Loading
Loading
+0 −53
Original line number Diff line number Diff line
/***************************************************************************
                          StaticVectorFor.h  -  description
                             -------------------
    begin                : July 12, 2018
    copyright            : (C) 2018 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

#include <TNL/Containers/StaticVector.h>

namespace TNL {
namespace Algorithms {

struct StaticVectorFor
{
   template< typename Index,
             typename Function,
             typename... FunctionArgs,
             int dim >
   static void exec( const Containers::StaticVector< dim, Index >& begin,
                     const Containers::StaticVector< dim, Index >& end,
                     Function f,
                     FunctionArgs... args )
   {
      static_assert( 1 <= dim && dim <= 3, "unsupported dimension" );
      Containers::StaticVector< dim, Index > index;

      if( dim == 1 ) {
         for( index[0] = begin[0]; index[0] < end[0]; index[0]++ )
            f( index, args... );
      }

      if( dim == 2 ) {
         for( index[1] = begin[1]; index[1] < end[1]; index[1]++ )
         for( index[0] = begin[0]; index[0] < end[0]; index[0]++ )
               f( index, args... );
      }

      if( dim == 3 ) {
         for( index[2] = begin[2]; index[2] < end[2]; index[2]++ )
         for( index[1] = begin[1]; index[1] < end[1]; index[1]++ )
         for( index[0] = begin[0]; index[0] < end[0]; index[0]++ )
            f( index, args... );
      }
   }
};

} // namespace Algorithms
} // namespace TNL
+33 −2
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@

#pragma once

#include <TNL/Algorithms/StaticVectorFor.h>
#include <TNL/Containers/StaticVector.h>

namespace TNL {
@@ -22,6 +21,38 @@ template < typename MeshFunctionType,
            int codimension=MeshFunctionType::getMeshDimension()-OutMesh::getMeshDimension()>
class CutMeshFunction
{
   template< typename Index,
             typename Function,
             typename... FunctionArgs,
             int dim >
   static void
   staticVectorFor( const Containers::StaticVector< dim, Index >& begin,
                    const Containers::StaticVector< dim, Index >& end,
                    Function f,
                    FunctionArgs... args )
   {
      static_assert( 1 <= dim && dim <= 3, "unsupported dimension" );
      Containers::StaticVector< dim, Index > index;

      if( dim == 1 ) {
         for( index[0] = begin[0]; index[0] < end[0]; index[0]++ )
            f( index, args... );
      }

      if( dim == 2 ) {
         for( index[1] = begin[1]; index[1] < end[1]; index[1]++ )
         for( index[0] = begin[0]; index[0] < end[0]; index[0]++ )
               f( index, args... );
      }

      if( dim == 3 ) {
         for( index[2] = begin[2]; index[2] < end[2]; index[2]++ )
         for( index[1] = begin[1]; index[1] < end[1]; index[1]++ )
         for( index[0] = begin[0]; index[0] < end[0]; index[0]++ )
            f( index, args... );
      }
   }

  public:
    static bool Cut(MeshFunctionType &inputMeshFunction,
                    OutMesh &outMesh,
@@ -99,7 +130,7 @@ class CutMeshFunction

            typename OutMesh::CoordinatesType starts;
            starts.setValue(0);
            Algorithms::StaticVectorFor::exec(starts,outMesh.getDimensions(),kernel);
            staticVectorFor(starts,outMesh.getDimensions(),kernel);
        }

        return inCut;