Commit 8ba02696 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Implementing write method in tnlGrid.

parent f8b7fa52
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -25,10 +25,15 @@ template< typename Real,
          typename Index >
tnlString tnlSharedVector< Real, Device, Index > :: getType() const
{
   return tnlString( "tnlSharedVector< " ) +
   return tnlString( "tnlVector< " ) +
                     getParameterType< Real >() + ", " +
                     Device :: getDeviceType() + ", " +
                     getParameterType< Index >() + " >";
   /****
    * It seems that there is no reason to differ here between vector and shared vector.
    * This method is used mainly (or only) for loading and saving of objects.
    * Making difference between shared vector and vector only complicates thinks.
    */
};

template< typename Real,
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ template< typename Real,
          typename Index >
tnlString tnlVector< Real, Device, Index > :: getType() const
{
   return tnlString( "tnlVector< " ) + ", " +
   return tnlString( "tnlVector< " ) +
                     getParameterType< Real >() + ", " +
                     Device :: getDeviceType() + ", " +
                     getParameterType< Index >() + " >";
+1 −0
Original line number Diff line number Diff line
@@ -178,6 +178,7 @@ bool tnlGrid< 1, Real, Device, Index> :: load( tnlFile& file )
           << this -> getName() << endl;
      return false;
   }
   this -> dofs = this -> getDimensions(). x();
   return true;
};

+47 −2
Original line number Diff line number Diff line
@@ -18,8 +18,11 @@
#ifndef TNLGRID2D_IMPL_H_
#define TNLGRID2D_IMPL_H_

#include <fstream>
#include <core/tnlAssert.h>

using namespace std;

template< typename Real,
          typename Device,
          typename Index >
@@ -197,6 +200,8 @@ bool tnlGrid< 2, Real, Device, Index> :: load( tnlFile& file )
           << this -> getName() << endl;
      return false;
   }
   this -> dofs = this -> getDimensions(). x() *
                   this -> getDimensions(). y();
   return true;
};

@@ -216,4 +221,44 @@ bool tnlGrid< 2, Real, Device, Index> :: load( const tnlString& fileName )
   return tnlObject :: load( fileName );
};

template< typename Real,
           typename Device,
           typename Index >
   template< typename MeshFunction >
bool tnlGrid< 2, Real, Device, Index> :: write( const MeshFunction& function,
                                                   const tnlString& fileName,
                                                   const tnlString& format ) const
{
   if( this -> getDofs() != function. getSize() )
   {
      cerr << "The size ( " << function. getSize() << " ) of the mesh function " << function. getName()
           << " does not agree with the DOFs ( " << this -> getDofs() << " ) of the mesh " << this -> getName() << "." << endl;
      return false;
   }
   fstream file;
   file. open( fileName. getString(), ios :: out );
   if( ! file )
   {
      cerr << "I am not able to open the file " << fileName << "." << endl;
      return false;
   }
   const RealType hx = getSpaceStep(). x();
   const RealType hy = getSpaceStep(). y();
   if( format == "gnuplot" )
      for( IndexType j = 0; j < getDimensions(). y(); j++ )
      {
         for( IndexType i = 0; i < getDimensions(). x(); i++ )
         {
            const RealType x = this -> getLowerCorner(). x() + i * hx;
            const RealType y = this -> getLowerCorner(). y() + i * hy;
            file << x << " " << " " << y << " " << function[ this -> getNodeIndex( j, i ) ] << endl;
         }
         file << endl;
      }

   file. close();
   return true;
}


#endif /* TNLGRID2D_IMPL_H_ */
+3 −0
Original line number Diff line number Diff line
@@ -213,6 +213,9 @@ bool tnlGrid< 3, Real, Device, Index> :: load( tnlFile& file )
           << this -> getName() << endl;
      return false;
   }
   this -> dofs = this -> getDimensions(). x() *
                   this -> getDimensions(). y() *
                   this -> getDimensions(). z();
   return true;
};

Loading