Commit cf795e62 authored by Tomáš Jakubec's avatar Tomáš Jakubec
Browse files

save

parent 2a530671
Loading
Loading
Loading
Loading
+82 −0
Original line number Diff line number Diff line
#ifndef VTKMESHDATAWRITER_H
#define VTKMESHDATAWRITER_H
#include "../Traits.h"
#include "../MeshDataContainer.h"
#include "../../MeshIO/MeshWriter/VTKMeshWriter.h"

#include <ostream>

template <unsigned int MeshDimension>
class VTKMeshDataWriter {

    /**
     * @brief writeColumn
     * writes a single column of traited data
     */
    static void writeColumn(...){}

    template<typename T, unsigned int Index, unsigned int Position, typename IndexType, typename Real>
    static auto writeColumn(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer)
    -> typename std::enable_if<
        Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value
    >::type
    {
        if (data.at(0).size() == MeshDimension)
        ost << "VECTORS ";
        else if (data.at(0).size() == MeshDimension * MeshDimension)
        ost << "TENZORS ";

        ost << Traits<T>::ttype::template getName<Index>() << "double";

        IndexType i = 0;
        for (; i < data.size(); i++) {
            for (unsigned int j = 0; j < data.at(i).size(); j++) {
                ost << data.at(i)[j];
            }

        }
    }



    template<typename T,unsigned int Index = 0, typename VOID = void>
    struct writeCellData{};

    template<typename T,unsigned int Index, typename... Types>
    struct writeCellData <Traits<T, Types...>, Index, std::enable_if_t<Index < Traits<T, Types...>::size() - 1>>{
        template<unsigned int Position, typename IndexType, typename Real>
        static void write(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer){

            ost << "CELL_DATA " << writer.cellVert.template getDataByPos<0>().size() << std::endl;

            ost << '"' << Traits<T, Types...>::template getName<Index>() << "\" : ";
            VariableExport::_writeWar(ost, Traits<T, Types...>::template getReference<Index>()->getValue(data));
            ost << ", ";
            writeCellData<Traits<T, Types...>, Index + 1>::print(ost, data);

        }
    };

    template<typename T,unsigned int Index, typename ... Types>
    struct writeCellData <Traits<T, Types...>, Index, std::enable_if_t<Index == Traits<T, Types...>::size() - 1>>{
        static void write(std::ostream& ost, const T &traitedClass){
            ost << '"' << Traits<T, Types...>::template getName<Traits<T, Types...>::size() - 1>() << "\" : ";
            VariableExport::_writeWar(ost, Traits<T, Types...>::template getReference<Traits<T, Types...>::size() - 1>()->getValue(traitedClass));
        }
    };




public:
    template<typename T,typename IndexType, typename Real, unsigned int ...Dimensions>
    static void writeToStream(std::ostream& ost, MeshDataContainer<T, Dimensions...>& data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer) {
        using type = typename decltype(data.template getDataByDim<MeshDimension>())::DataType;
        static_assert (Detail::has_default_traits<type>::value, "The class T must have defined traits for example using macro MAKE_ATTRIBUTE_TRAIT in header Traits.h");

    }

};


#endif // VTKMESHDATAWRITER_H
+2 −2
Original line number Diff line number Diff line
@@ -7,10 +7,10 @@

template<typename Class, typename...Types>
class Traits {

public:
    template <unsigned int Index>
    using type = std::tuple_element_t<Index,std::tuple<Types...>>;

private:
    template<unsigned int Index = sizeof...(Types) - 1, typename Dummy = void>
    struct MemRefs: public MemRefs<Index - 1>{
        friend class Singleton<MemRefs<1, void>>;
+1 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ HEADERS += \
    InlineArrayOperations.h \
    UnstructuredMesh/MeshDataContainer/MemberApproach.h \
    UnstructuredMesh/MeshDataContainer/MeshDataContainer.h \
    UnstructuredMesh/MeshDataContainer/MeshDataIO/VTKMeshDataWriter.h \
    UnstructuredMesh/MeshDataContainer/Singleton.h \
    UnstructuredMesh/MeshDataContainer/Traits.h \
    UnstructuredMesh/MeshElements/CellBoundaryConnection.h \
+2 −2
Original line number Diff line number Diff line
@@ -2,12 +2,11 @@
#define DEBUG_H


#include "../Macros/MacroForEach.h"

#define STRVAR(var) #var, var


#ifndef UNDEBUG
#include "../Macros/MacroForEach.h"
#include <iostream>
#include "HTMLLogger.h"
#include "ConsoleLogger.h"
@@ -19,6 +18,7 @@

extern HtmlLogger HDBGLog;

#define STRVAR(var) #var, var

#define DBG(comment)            \
std::cerr << "DBG in file "     \
+24 −4
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ struct VariableExport {
    }


    template<typename T,unsigned int Index = 0>
    template<typename T,unsigned int Index = 0, typename VOID = void>
    struct PrintClass{
        static void print(std::ostream& ost, const T &traitedClass){
            ost << '"' << Traits<T>::ttype::template getName<Index>() << "\" : ";
@@ -218,14 +218,34 @@ struct VariableExport {
        }
    };

    template<typename T>
    struct PrintClass<T, Traits<T>::ttype::size() - 1>{
    template<typename T,unsigned int Index, typename... Types>
    struct PrintClass <Traits<T, Types...>, Index, std::enable_if_t<Index < Traits<T, Types...>::size() - 1>>{
        static void print(std::ostream& ost, const T &traitedClass){
            ost << '"' << Traits<T, Types...>::template getName<Index>() << "\" : ";
            VariableExport::_writeWar(ost, Traits<T, Types...>::template getReference<Index>()->getValue(traitedClass));
            ost << ", ";
            PrintClass<Traits<T, Types...>, Index + 1>::print(ost, traitedClass);

        }
    };

    template<typename T,unsigned int Index, typename ... Types>
    struct PrintClass <Traits<T, Types...>, Index, std::enable_if_t<Index == Traits<T, Types...>::size() - 1>>{
        static void print(std::ostream& ost, const T &traitedClass){
            ost << '"' << Traits<T, Types...>::template getName<Traits<T, Types...>::size() - 1>() << "\" : ";
            VariableExport::_writeWar(ost, Traits<T, Types...>::template getReference<Traits<T, Types...>::size() - 1>()->getValue(traitedClass));
        }
    };

    template<typename T, unsigned int Index>
    struct PrintClass<T, Index, std::enable_if_t<Index == Traits<T>::ttype::size() - 1>>{
        static void print(std::ostream& ost, const T &traitedClass){
            ost << '"' << Traits<T>::ttype::template getName<Traits<T>::ttype::size() - 1>() << "\" : ";
            VariableExport::_writeWar(ost, Traits<T>::ttype::template getReference<Traits<T>::ttype::size() - 1>()->getValue(traitedClass));
        }
    };


    template<typename T>
    static auto _writeWar(std::ostream& ost, const T &traitedClass)
      -> typename std::enable_if<
@@ -233,7 +253,7 @@ struct VariableExport {
         >::type
    {
        ost << "{ ";
        PrintClass<T>::print(ost, traitedClass);
        PrintClass<typename Traits<T>::ttype>::print(ost, traitedClass);
        ost << " }";
    }