From 3798b3803dd2085a3db2a0b8d2754c657d3cb147 Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Tue, 2 Jul 2013 16:41:44 +0200 Subject: [PATCH] Implementing vector fields visualization in tnl-view. --- src/core/param-types.h | 4 +- src/core/tnlArray.h | 4 +- src/core/tnlObject.h | 4 +- src/core/tnlString.h | 2 + src/core/tnlTuple.h | 28 +++-- src/core/tnlVector.h | 4 +- src/implementation/core/tnlArray_impl.h | 10 +- src/implementation/core/tnlObject.cpp | 13 +- src/implementation/core/tnlString.cpp | 4 + src/implementation/core/tnlVector_impl.h | 11 +- src/implementation/mesh/tnlGrid2D_impl.h | 15 ++- src/implementation/mesh/tnlGrid3D_impl.h | 6 +- src/matrix/tnlAdaptiveRgCSRMatrix.h | 5 + src/mesh/CMakeLists.txt | 1 + src/mesh/tnlGnuplotWriter.h | 44 +++++++ src/mesh/tnlGrid.h | 16 +-- tests/mesh/main.cpp | 3 +- tests/unit-tests/core/tnlArrayTester.h | 5 + tools/src/tnl-view.h | 144 ++++++++++++++++++----- 19 files changed, 251 insertions(+), 72 deletions(-) create mode 100644 src/mesh/tnlGnuplotWriter.h diff --git a/src/core/param-types.h b/src/core/param-types.h index 8a6525eae9..ee64ef496d 100644 --- a/src/core/param-types.h +++ b/src/core/param-types.h @@ -23,13 +23,15 @@ #include <core/tnlString.h> template< typename T > -tnlString getParameterType() { return tnlString( "unknown type" ); }; +tnlString getParameterType() { return T :: getType(); }; template<> inline tnlString getParameterType< bool >() { return tnlString( "bool" ); }; template<> inline tnlString getParameterType< int >() { return tnlString( "int" ); }; +template<> inline tnlString getParameterType< long int >() { return tnlString( "long int" ); }; template<> inline tnlString getParameterType< char >() { return tnlString( "char" ); }; template<> inline tnlString getParameterType< float >() { return tnlString( "float" ); }; template<> inline tnlString getParameterType< double >() { return tnlString( "double" ); }; +template<> inline tnlString getParameterType< long double >() { return tnlString( "long double" ); }; template<> inline tnlString getParameterType< tnlFloat >() { return tnlString( "tnlFloat" ); }; template<> inline tnlString getParameterType< tnlDouble> () { return tnlString( "tnlDouble" ); }; diff --git a/src/core/tnlArray.h b/src/core/tnlArray.h index 283950bd60..6fbf53ba4a 100644 --- a/src/core/tnlArray.h +++ b/src/core/tnlArray.h @@ -42,7 +42,9 @@ class tnlArray : public tnlObject tnlArray( const tnlString& name ); - tnlString getType() const; + static tnlString getType(); + + tnlString getTypeVirtual() const; bool setSize( Index size ); diff --git a/src/core/tnlObject.h b/src/core/tnlObject.h index 0e746b8827..ed05ae2e3c 100644 --- a/src/core/tnlObject.h +++ b/src/core/tnlObject.h @@ -48,7 +48,9 @@ class tnlObject * Type getter. This returns the type in C++ style - for example the returned value * may look ass follows: "tnlVector< double, tnlCuda >". */ - virtual tnlString getType() const; + static tnlString getType(); + + virtual tnlString getTypeVirtual() const; /**** * Name getter diff --git a/src/core/tnlString.h b/src/core/tnlString.h index d915ab5e6b..c4c6cd09fc 100644 --- a/src/core/tnlString.h +++ b/src/core/tnlString.h @@ -49,6 +49,8 @@ class tnlString int prefix_cut_off = 0, int sufix_cut_off = 0 ); + static tnlString getType(); + //! Copy constructor tnlString( const tnlString& str ); diff --git a/src/core/tnlTuple.h b/src/core/tnlTuple.h index 5a65917b25..54d289e4b6 100644 --- a/src/core/tnlTuple.h +++ b/src/core/tnlTuple.h @@ -21,6 +21,7 @@ #include <core/tnlAssert.h> #include <string.h> #include <core/tnlFile.h> +#include <core/tnlString.h> #include "param-types.h" //! Aliases for the coordinates @@ -47,8 +48,10 @@ class tnlTuple //! This is constructore of vector with Size = 3. tnlTuple( const Real& v1, - const Real& v2, - const Real& v3 ); + const Real& v2, + const Real& v3 ); + + static tnlString getType(); const Real& operator[]( int i ) const; @@ -222,6 +225,16 @@ tnlTuple< Size, Real > :: tnlTuple( const Real& v1, data[ 2 ] = v3; } +template< int Size, typename Real > +tnlString tnlTuple< Size, Real > :: getType() +{ + return tnlString( "tnlTuple< " ) + + tnlString( Size ) + + tnlString( ", " ) + + getParameterType< Real >() + + tnlString( " >" ); +} + template< int Size, typename Real > const Real& tnlTuple< Size, Real > :: operator[]( int i ) const { @@ -628,15 +641,6 @@ ostream& operator << ( ostream& str, const tnlTuple< Size, Real >& v ) return str; }; -template< int Size, typename Real > tnlString getParameterType() -{ - return tnlString( "tnlTuple< " ) + - tnlString( Size ) + - tnlString( ", " ) + - tnlString( getParameterType< Real >() ) + - tnlString( " >" ); -}; - template< typename Real > tnlTuple< 3, Real > tnlVectorProduct( const tnlTuple< 3, Real >& u, const tnlTuple< 3, Real >& v ) @@ -679,6 +683,4 @@ Real tnlTriangleArea( const tnlTuple< 2, Real >& a, return 0.5 * sqrt( tnlScalarProduct( v, v ) ); }; - - #endif diff --git a/src/core/tnlVector.h b/src/core/tnlVector.h index 28315edd1a..a5ee396aad 100644 --- a/src/core/tnlVector.h +++ b/src/core/tnlVector.h @@ -39,7 +39,9 @@ class tnlVector : public tnlArray< Real, Device, Index > tnlVector( const tnlString& name, const Index size ); - tnlString getType() const; + static tnlString getType(); + + tnlString getTypeVirtual() const; tnlVector< Real, Device, Index >& operator = ( const tnlVector< Real, Device, Index >& array ); diff --git a/src/implementation/core/tnlArray_impl.h b/src/implementation/core/tnlArray_impl.h index 731357949f..be0d33e7a1 100644 --- a/src/implementation/core/tnlArray_impl.h +++ b/src/implementation/core/tnlArray_impl.h @@ -46,7 +46,7 @@ tnlArray< Element, Device, Index > :: tnlArray( const tnlString& name ) template< typename Element, typename Device, typename Index > -tnlString tnlArray< Element, Device, Index > :: getType() const +tnlString tnlArray< Element, Device, Index > :: getType() { return tnlString( "tnlArray< " ) + getParameterType< Element >() + @@ -55,6 +55,14 @@ tnlString tnlArray< Element, Device, Index > :: getType() const " >"; }; +template< typename Element, + typename Device, + typename Index > +tnlString tnlArray< Element, Device, Index > :: getTypeVirtual() const +{ + return this->getType(); +}; + template< typename Element, typename Device, typename Index > diff --git a/src/implementation/core/tnlObject.cpp b/src/implementation/core/tnlObject.cpp index 5dcab3896b..7a8d9d86c5 100644 --- a/src/implementation/core/tnlObject.cpp +++ b/src/implementation/core/tnlObject.cpp @@ -42,11 +42,16 @@ tnlObject :: tnlObject( const tnlString& _name ) dbgCout( "Initiating object " << getName() ); } -tnlString tnlObject :: getType() const +tnlString tnlObject :: getType() { return tnlString( "tnlObject" ); } +tnlString tnlObject :: getTypeVirtual() const +{ + return this->getType(); +} + void tnlObject :: setName( const tnlString& name) { this -> name = name; @@ -68,7 +73,7 @@ bool tnlObject :: save( tnlFile& file ) const #endif return false; dbgCout( "Writing object name " << name ); - if( ! this -> getType(). save( file ) || ! name. save( file ) ) return false; + if( ! this->getTypeVirtual().save( file ) || ! name. save( file ) ) return false; return true; } @@ -79,9 +84,9 @@ bool tnlObject :: load( tnlFile& file ) tnlString load_type; if( ! getObjectType( file, load_type ) ) return false; - if( load_type != getType() ) + if( load_type != getTypeVirtual() ) { - cerr << "Given file contains instance of " << load_type << " but " << getType() << " is expected." << endl; + cerr << "Given file contains instance of " << load_type << " but " << getTypeVirtual() << " is expected." << endl; return false; } dbgCout( "Reading object name " ); diff --git a/src/implementation/core/tnlString.cpp b/src/implementation/core/tnlString.cpp index d128923e3d..f19eaae2fa 100644 --- a/src/implementation/core/tnlString.cpp +++ b/src/implementation/core/tnlString.cpp @@ -76,6 +76,10 @@ tnlString :: tnlString( double number ) sprintf( string, "%f", number ); } +tnlString tnlString :: getType() +{ + return tnlString( "tnlString" ); +} tnlString :: ~tnlString() { diff --git a/src/implementation/core/tnlVector_impl.h b/src/implementation/core/tnlVector_impl.h index d490f257aa..46c1b3dcda 100644 --- a/src/implementation/core/tnlVector_impl.h +++ b/src/implementation/core/tnlVector_impl.h @@ -49,7 +49,7 @@ tnlVector< Real, Device, Index > :: tnlVector( const tnlString& name, const Inde template< typename Real, typename Device, typename Index > -tnlString tnlVector< Real, Device, Index > :: getType() const +tnlString tnlVector< Real, Device, Index > :: getType() { return tnlString( "tnlVector< " ) + getParameterType< Real >() + ", " + @@ -57,6 +57,15 @@ tnlString tnlVector< Real, Device, Index > :: getType() const getParameterType< Index >() + " >"; }; +template< typename Real, + typename Device, + typename Index > +tnlString tnlVector< Real, Device, Index > :: getTypeVirtual() const +{ + return this->getType(); +}; + + template< typename Real, typename Device, typename Index > diff --git a/src/implementation/mesh/tnlGrid2D_impl.h b/src/implementation/mesh/tnlGrid2D_impl.h index 3cc7fd3a01..0f2b53670f 100644 --- a/src/implementation/mesh/tnlGrid2D_impl.h +++ b/src/implementation/mesh/tnlGrid2D_impl.h @@ -21,6 +21,7 @@ #include <fstream> #include <iomanip> #include <core/tnlAssert.h> +#include <mesh/tnlGnuplotWriter.h> using namespace std; @@ -37,7 +38,7 @@ template< typename Real, typename Device, typename Index, template< int, typename, typename, typename > class Geometry > -tnlString tnlGrid< 2, Real, Device, Index, Geometry > :: getTypeStatic() +tnlString tnlGrid< 2, Real, Device, Index, Geometry > :: getType() { return tnlString( "tnlGrid< " ) + tnlString( Dimensions ) + ", " + @@ -51,9 +52,9 @@ template< typename Real, typename Device, typename Index, template< int, typename, typename, typename > class Geometry > -tnlString tnlGrid< 2, Real, Device, Index, Geometry > :: getType() const +tnlString tnlGrid< 2, Real, Device, Index, Geometry > :: getTypeVirtual() const { - return this -> getTypeStatic(); + return this -> getType(); } template< typename Real, @@ -537,7 +538,7 @@ bool tnlGrid< 2, Real, Device, Index, Geometry > :: writeMesh( const tnlString& << this -> getProportions(). y() << "cm );" << endl << endl; VertexType v; - for( Index j = 0; j <= this -> dimensions. y(); j ++ ) + for( Index j = 0; j < this -> dimensions. y(); j ++ ) { file << "draw( "; this -> getVertex< -1, -1 >( CoordinatesType( 0, j ), v ); @@ -550,7 +551,7 @@ bool tnlGrid< 2, Real, Device, Index, Geometry > :: writeMesh( const tnlString& file << " );" << endl; } file << endl; - for( Index i = 0; i <= this -> dimensions. x(); i ++ ) + for( Index i = 0; i < this -> dimensions. x(); i ++ ) { file << "draw( "; this -> getVertex< -1, -1 >( CoordinatesType( i, 0 ), v ); @@ -653,7 +654,9 @@ bool tnlGrid< 2, Real, Device, Index, Geometry > :: write( const MeshFunction& f { VertexType v; this -> getVertex< 0, 0 >( CoordinatesType( i, j ), v ); - file << v. x() << " " << " " << v. y() << " " << function[ this -> getElementIndex( i, j ) ] << endl; + file << v. x() << " " << " " << v. y() << " "; + tnlGnuplotWriter::write( file, function[ this -> getElementIndex( i, j ) ] ); + file << endl; } file << endl; } diff --git a/src/implementation/mesh/tnlGrid3D_impl.h b/src/implementation/mesh/tnlGrid3D_impl.h index dbcb00dccd..da2fc393e3 100644 --- a/src/implementation/mesh/tnlGrid3D_impl.h +++ b/src/implementation/mesh/tnlGrid3D_impl.h @@ -33,7 +33,7 @@ template< typename Real, typename Device, typename Index, template< int, typename, typename, typename > class Geometry > -tnlString tnlGrid< 3, Real, Device, Index, Geometry > :: getTypeStatic() +tnlString tnlGrid< 3, Real, Device, Index, Geometry > :: getType() { return tnlString( "tnlGrid< " ) + tnlString( Dimensions ) + ", " + @@ -46,9 +46,9 @@ template< typename Real, typename Device, typename Index, template< int, typename, typename, typename > class Geometry > -tnlString tnlGrid< 3, Real, Device, Index, Geometry > :: getType() const +tnlString tnlGrid< 3, Real, Device, Index, Geometry > :: getTypeVirtual() const { - return this -> getTypeStatic(); + return this -> getType(); } template< typename Real, diff --git a/src/matrix/tnlAdaptiveRgCSRMatrix.h b/src/matrix/tnlAdaptiveRgCSRMatrix.h index e23a3f7f3e..71cbbb6682 100644 --- a/src/matrix/tnlAdaptiveRgCSRMatrix.h +++ b/src/matrix/tnlAdaptiveRgCSRMatrix.h @@ -36,6 +36,11 @@ struct tnlARGCSRGroupProperties int chunkSize; int firstRow; int offset; + + static tnlString getType() + { + return tnlString( "tnlARGCSRGroupProperties" ); + }; }; inline tnlString GetParameterType( const tnlARGCSRGroupProperties& a ) diff --git a/src/mesh/CMakeLists.txt b/src/mesh/CMakeLists.txt index a80df75497..ab8f457ef0 100755 --- a/src/mesh/CMakeLists.txt +++ b/src/mesh/CMakeLists.txt @@ -11,6 +11,7 @@ SET( headers tnlGrid.h tnlIdenticalGridGeometry.h tnlLinearGridGeometry.h tnlDummyMesh.h + tnlGnuplotWriter.h config.h information.h mesh.h diff --git a/src/mesh/tnlGnuplotWriter.h b/src/mesh/tnlGnuplotWriter.h new file mode 100644 index 0000000000..5529b58e73 --- /dev/null +++ b/src/mesh/tnlGnuplotWriter.h @@ -0,0 +1,44 @@ +/*************************************************************************** + tnlGnuplotWriter.h - description + ------------------- + begin : Jul 2, 2013 + copyright : (C) 2013 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 TNLGNUPLOTWRITER_H_ +#define TNLGNUPLOTWRITER_H_ + +#include <ostream> +#include <core/tnlTuple.h> + +class tnlGnuplotWriter +{ + public: + + template< typename Element > + static void write( std::ostream& str, + const Element& d ) + { + str << d; + }; + + template< typename Real > + static void write( std::ostream& str, + const tnlTuple< 2, Real >& d ) + { + str << d.x() << " " << d.y(); + }; +}; + + +#endif /* TNLGNUPLOTWRITER_H_ */ diff --git a/src/mesh/tnlGrid.h b/src/mesh/tnlGrid.h index be4b9bb40a..e367c6ba63 100644 --- a/src/mesh/tnlGrid.h +++ b/src/mesh/tnlGrid.h @@ -90,8 +90,8 @@ class tnlGrid< 1, Real, Device, Index, Geometry > : public tnlObject template< typename MeshFunction > bool write( const MeshFunction& function, - const tnlString& fileName, - const tnlString& format ) const; + const tnlString& fileName, + const tnlString& format ) const; protected: @@ -123,9 +123,9 @@ class tnlGrid< 2, Real, Device, Index, Geometry > : public tnlObject tnlGrid(); - static tnlString getTypeStatic(); + static tnlString getType(); - tnlString getType() const; + tnlString getTypeVirtual() const; bool setDimensions( const Index xSize, const Index ySize ); @@ -243,9 +243,9 @@ class tnlGrid< 3, Real, Device, Index, Geometry > : public tnlObject tnlGrid(); - static tnlString getTypeStatic(); + static tnlString getType(); - tnlString getType() const; + tnlString getTypeVirtual() const; void setDimensions( const Index xSize, const Index ySize, const Index zSize ); @@ -281,8 +281,8 @@ class tnlGrid< 3, Real, Device, Index, Geometry > : public tnlObject template< typename MeshFunction > bool write( const MeshFunction& function, - const tnlString& fileName, - const tnlString& format ) const; + const tnlString& fileName, + const tnlString& format ) const; protected: diff --git a/tests/mesh/main.cpp b/tests/mesh/main.cpp index a04089d19b..aa47a49b15 100644 --- a/tests/mesh/main.cpp +++ b/tests/mesh/main.cpp @@ -68,6 +68,7 @@ void testWithoutOutput(MeshType &mesh) int main() { + /* cout << "Testing linear mesh ... " << endl; Mesh<LinearMeshConfig> mesh0; mesh0.load( lineVtkFile); @@ -143,6 +144,6 @@ int main() tetramesh.write( canyon3DVtkOutFile ); cout << "done" << endl; - +*/ return 0; } diff --git a/tests/unit-tests/core/tnlArrayTester.h b/tests/unit-tests/core/tnlArrayTester.h index 5a9d720faa..9bb9e8b017 100644 --- a/tests/unit-tests/core/tnlArrayTester.h +++ b/tests/unit-tests/core/tnlArrayTester.h @@ -30,7 +30,12 @@ class testingClassForArrayManagerTester { + public: + static tnlString getType() + { + return tnlString( "testingClassForArrayManagerTester" ); + }; }; tnlString GetParameterType( const testingClassForArrayManagerTester& c ) diff --git a/tools/src/tnl-view.h b/tools/src/tnl-view.h index 8cfddcf099..e974bf2305 100644 --- a/tools/src/tnl-view.h +++ b/tools/src/tnl-view.h @@ -28,30 +28,37 @@ using namespace std; -template< typename Mesh, typename Element, typename Index, int Dimensions > -bool convertObject( const Mesh& mesh, - const tnlString& inputFileName, - const tnlList< tnlString >& parsedObjectType, - const tnlParameterContainer& parameters ) +bool getOutputFileName( const tnlString& inputFileName, + const tnlString& outputFormat, + tnlString& outputFileName ) { - int verbose = parameters. GetParameter< int >( "verbose"); - bool checkOutputFile = parameters. GetParameter< bool >( "check-output-file" ); - tnlString outputFileName( inputFileName ); + outputFileName = inputFileName; RemoveFileExtension( outputFileName ); - tnlString outputFormat = parameters. GetParameter< tnlString >( "output-format" ); if( outputFormat == "gnuplot" ) + { outputFileName += ".gplt"; + return true; + } else { cerr << "Unknown file format " << outputFormat << "."; return false; } - if( checkOutputFile && fileExists( outputFileName ) ) - { - if( verbose ) - cout << " file already exists. Skipping. \r" << flush; - return true; - } +} + +template< typename Mesh, typename Element, typename Real, typename Index, int Dimensions > +bool convertObject( const Mesh& mesh, + const tnlString& inputFileName, + const tnlList< tnlString >& parsedObjectType, + const tnlParameterContainer& parameters ) +{ + int verbose = parameters. GetParameter< int >( "verbose"); + tnlString outputFormat = parameters. GetParameter< tnlString >( "output-format" ); + tnlString outputFileName; + if( ! getOutputFileName( inputFileName, + outputFormat, + outputFileName ) ) + return false; if( verbose ) cout << " writing to " << outputFileName << " ... " << flush; @@ -72,12 +79,12 @@ bool convertObject( const Mesh& mesh, tnlMultiVector< Dimensions, Element, tnlHost, Index > multiVector; if( ! multiVector. load( inputFileName ) ) return false; - tnlGrid< Dimensions, Element, tnlHost, Index > grid; + tnlGrid< Dimensions, Real, tnlHost, Index > grid; grid. setDimensions( multiVector. getDimensions() ); - grid. setOrigin( tnlTuple< Dimensions, Element >( 0.0 ) ); - grid. setProportions( tnlTuple< Dimensions, Element >( 1.0 ) ); - const Element spaceStep = grid. getParametricStep(). x(); - grid. setParametricStep( tnlTuple< Dimensions, Element >( spaceStep ) ); + grid. setOrigin( tnlTuple< Dimensions, Real >( 0.0 ) ); + grid. setProportions( tnlTuple< Dimensions, Real >( 1.0 ) ); + const Real spaceStep = grid. getParametricStep(). x(); + grid. setParametricStep( tnlTuple< Dimensions, Real >( spaceStep ) ); if( ! grid. write( multiVector, outputFileName, outputFormat ) ) return false; } @@ -86,7 +93,7 @@ bool convertObject( const Mesh& mesh, return true; } -template< typename Mesh, typename Element, typename Index > +template< typename Mesh, typename Element, typename Real, typename Index > bool setDimensions( const Mesh& mesh, const tnlString& inputFileName, const tnlList< tnlString >& parsedObjectType, @@ -102,17 +109,17 @@ bool setDimensions( const Mesh& mesh, switch( dimensions ) { case 1: - return convertObject< Mesh, Element, Index, 1 >( mesh, inputFileName, parsedObjectType, parameters ); + return convertObject< Mesh, Element, Real, Index, 1 >( mesh, inputFileName, parsedObjectType, parameters ); case 2: - return convertObject< Mesh, Element, Index, 2 >( mesh, inputFileName, parsedObjectType, parameters ); + return convertObject< Mesh, Element, Real, Index, 2 >( mesh, inputFileName, parsedObjectType, parameters ); case 3: - return convertObject< Mesh, Element, Index, 3 >( mesh, inputFileName, parsedObjectType, parameters ); + return convertObject< Mesh, Element, Real, Index, 3 >( mesh, inputFileName, parsedObjectType, parameters ); } cerr << "Cannot convert objects with " << dimensions << " dimensions." << endl; return false; } -template< typename Mesh, typename Element > +template< typename Mesh, typename Element, typename Real > bool setIndexType( const Mesh& mesh, const tnlString& inputFileName, const tnlList< tnlString >& parsedObjectType, @@ -127,13 +134,63 @@ bool setIndexType( const Mesh& mesh, indexType = parsedObjectType[ 3 ]; if( indexType == "int" ) - return setDimensions< Mesh, Element, int >( mesh, inputFileName, parsedObjectType, parameters ); + return setDimensions< Mesh, Element, Real, int >( mesh, inputFileName, parsedObjectType, parameters ); if( indexType == "long-int" ) - return setDimensions< Mesh, Element, long int >( mesh, inputFileName, parsedObjectType, parameters ); + return setDimensions< Mesh, Element, Real, long int >( mesh, inputFileName, parsedObjectType, parameters ); cerr << "Unknown index type " << indexType << "." << endl; return false; } +template< typename Mesh > +bool setTupleType( const Mesh& mesh, + const tnlString& inputFileName, + const tnlList< tnlString >& parsedObjectType, + const tnlList< tnlString >& parsedElementType, + const tnlParameterContainer& parameters ) +{ + int dimensions = atoi( parsedElementType[ 1 ].getString() ); + tnlString dataType = parsedElementType[ 2 ]; + if( dataType == "float" ) + switch( dimensions ) + { + case 1: + return setIndexType< Mesh, tnlTuple< 1, float >, float >( mesh, inputFileName, parsedObjectType, parameters ); + break; + case 2: + return setIndexType< Mesh, tnlTuple< 2, float >, float >( mesh, inputFileName, parsedObjectType, parameters ); + break; + case 3: + return setIndexType< Mesh, tnlTuple< 3, float >, float >( mesh, inputFileName, parsedObjectType, parameters ); + break; + } + if( dataType == "double" ) + switch( dimensions ) + { + case 1: + return setIndexType< Mesh, tnlTuple< 1, double >, double >( mesh, inputFileName, parsedObjectType, parameters ); + break; + case 2: + return setIndexType< Mesh, tnlTuple< 2, double >, double >( mesh, inputFileName, parsedObjectType, parameters ); + break; + case 3: + return setIndexType< Mesh, tnlTuple< 3, double >, double >( mesh, inputFileName, parsedObjectType, parameters ); + break; + } + if( dataType == "long double" ) + switch( dimensions ) + { + case 1: + return setIndexType< Mesh, tnlTuple< 1, long double >, long double >( mesh, inputFileName, parsedObjectType, parameters ); + break; + case 2: + return setIndexType< Mesh, tnlTuple< 2, long double >, long double >( mesh, inputFileName, parsedObjectType, parameters ); + break; + case 3: + return setIndexType< Mesh, tnlTuple< 3, long double >, long double >( mesh, inputFileName, parsedObjectType, parameters ); + break; + } +} + template< typename Mesh > bool setElementType( const Mesh& mesh, const tnlString& inputFileName, @@ -141,6 +198,7 @@ bool setElementType( const Mesh& mesh, const tnlParameterContainer& parameters ) { tnlString elementType; + if( parsedObjectType[ 0 ] == "tnlMultiVector" || parsedObjectType[ 0 ] == "tnlSharedMultiVector" ) elementType = parsedObjectType[ 2 ]; @@ -148,12 +206,22 @@ bool setElementType( const Mesh& mesh, parsedObjectType[ 0 ] == "tnlVector" ) elementType = parsedObjectType[ 1 ]; + if( elementType == "float" ) - return setIndexType< Mesh, float >( mesh, inputFileName, parsedObjectType, parameters ); + return setIndexType< Mesh, float, float >( mesh, inputFileName, parsedObjectType, parameters ); if( elementType == "double" ) - return setIndexType< Mesh, double >( mesh, inputFileName, parsedObjectType, parameters ); - if( elementType == "long-double" ) - return setIndexType< Mesh, long double >( mesh, inputFileName, parsedObjectType, parameters ); + return setIndexType< Mesh, double, double >( mesh, inputFileName, parsedObjectType, parameters ); + if( elementType == "long double" ) + return setIndexType< Mesh, long double, long double >( mesh, inputFileName, parsedObjectType, parameters ); + tnlList< tnlString > parsedElementType; + if( ! parseObjectType( elementType, parsedElementType ) ) + { + cerr << "Unable to parse object type " << elementType << "." << endl; + return false; + } + if( parsedElementType[ 0 ] == "tnlTuple" ) + return setTupleType< Mesh >( mesh, inputFileName, parsedObjectType, parsedElementType, parameters ); + cerr << "Unknown element type " << elementType << "." << endl; return false; } @@ -173,6 +241,7 @@ bool processFiles( const tnlParameterContainer& parameters ) } mesh. writeMesh( "mesh.asy", "asymptote" ); + bool checkOutputFile = parameters. GetParameter< bool >( "check-output-file" ); tnlList< tnlString > inputFiles = parameters. GetParameter< tnlList< tnlString > >( "input-files" ); #ifdef HAVE_OPENMP #pragma omp parallel for @@ -182,6 +251,19 @@ bool processFiles( const tnlParameterContainer& parameters ) if( verbose ) cout << "Processing file " << inputFiles[ i ] << " ... " << flush; + tnlString outputFormat = parameters. GetParameter< tnlString >( "output-format" ); + tnlString outputFileName; + if( ! getOutputFileName( inputFiles[ i ], + outputFormat, + outputFileName ) ) + return false; + if( checkOutputFile && fileExists( outputFileName ) ) + { + if( verbose ) + cout << " file already exists. Skipping. \r" << flush; + continue; + } + tnlString objectType; if( ! getObjectType( inputFiles[ i ], objectType ) ) cerr << "unknown object ... SKIPPING!" << endl; -- GitLab