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

VTK data export almost done

parent cf795e62
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -269,10 +269,10 @@ public:
    using ttype = Traits<tempData, double, Vector<3,double>>;
    using ttype = Traits<tempData, double, Vector<3,double>>;
    const static ttype tr;
    const static ttype tr;
};
};

const Traits<tempData>::ttype Traits<tempData>::tr("density", &tempData::density, "momentum"s, std::make_pair(&tempData::getMomentum, &tempData::setMomentum));
const Traits<tempData>::ttype Traits<tempData>::tr("density", &tempData::density, "momentum"s, std::make_pair(&tempData::getMomentum, &tempData::setMomentum));
*/
*/



//MAKE_NAMED_ATTRIBUTE_TRAIT(tempData, "density", density, "velocity", velocity);
//MAKE_NAMED_ATTRIBUTE_TRAIT(tempData, "density", density, "velocity", velocity);
//MAKE_ATTRIBUTE_TRAIT(tempData, density, velocity);
//MAKE_ATTRIBUTE_TRAIT(tempData, density, velocity);


@@ -304,7 +304,7 @@ void testMemberRef(){
    DBGVAR(Traits<tempData>::is_specialized,Detail::has_default_traits<tempData>::value, d);
    DBGVAR(Traits<tempData>::is_specialized,Detail::has_default_traits<tempData>::value, d);


    ExportTest e;
    ExportTest e;
    DBGVAR(e);
    DBGVAR(e, ClassC<>());
}
}




+67 −22
Original line number Original line Diff line number Diff line
@@ -9,11 +9,15 @@
template <unsigned int MeshDimension>
template <unsigned int MeshDimension>
class VTKMeshDataWriter {
class VTKMeshDataWriter {



    /**
    /**
     * @brief writeColumn
     * @brief writeColumn
     * writes a single column of traited data
     * writes a single column of traited data
     */
     */
    static void writeColumn(...){}
    static void writeColumn(std::ostream& ost [[maybe_unused]],...){
        DBGMSG("capture");
        throw std::runtime_error("capture of write column must not be called.");
    }


    template<typename T, unsigned int Index, unsigned int Position, typename IndexType, typename Real>
    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)
    static auto writeColumn(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer)
@@ -21,22 +25,61 @@ class VTKMeshDataWriter {
        Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value
        Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value
       >::type
       >::type
    {
    {
        if (data.at(0).size() == MeshDimension)

        if (Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size() == MeshDimension)
        ost << "VECTORS ";
        ost << "VECTORS ";
        else if (data.at(0).size() == MeshDimension * MeshDimension)
        else if (Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size() == MeshDimension * MeshDimension)
        ost << "TENZORS ";
        ost << "TENZORS ";


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


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


        IndexType realIndex = 0;
        for (IndexType i = 0; i < writer.cellVert.template getDataByPos<0>().size(); i++) {

            auto iterator = writer.backwardCellIndexMapping.find(i);
            if (iterator == writer.backwardCellIndexMapping.end()){
                for (unsigned int j = 0; j < Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size(); j++) {
                    ost << Traits<T>::ttype::template getValue<Index>(data.at(realIndex))[j] << ' ';
                }
                }
                realIndex++;
            } else {
                realIndex = iterator->second;
                for (unsigned int j = 0; j < Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size(); j++) {
                    ost << Traits<T>::ttype::template getValue<Index>(data.at(realIndex))[j] << ' ';
                }
                }
            }
        }
    }


    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
    {


        ost << "SCALARS " << Traits<T>::ttype::template getName<Index>() << " double 1\nLOOKUP_TABLE default\n";

        IndexType realIndex = 0;
        for (IndexType i = 0; i < writer.cellVert.template getDataByPos<0>().size(); i++) {


            auto iterator = writer.backwardCellIndexMapping.find(i);
            if (iterator == writer.backwardCellIndexMapping.end()){

                ost << Traits<T>::ttype::template getValue<Index>(data.at(realIndex)) << ' ';

                realIndex++;
            } else {

                realIndex = iterator->second;
                ost << Traits<T>::ttype::template getValue<Index>(data.at(realIndex)) << ' ';

            }
        }
    }




    template<typename T,unsigned int Index = 0, typename VOID = void>
    template<typename T,unsigned int Index = 0, typename VOID = void>
@@ -44,24 +87,25 @@ class VTKMeshDataWriter {


    template<typename T,unsigned int Index, typename... Types>
    template<typename T,unsigned int Index, typename... Types>
    struct writeCellData <Traits<T, Types...>, Index, std::enable_if_t<Index < Traits<T, Types...>::size() - 1>>{
    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;
        template<unsigned int Position, typename IndexType, typename Real>


            ost << '"' << Traits<T, Types...>::template getName<Index>() << "\" : ";
        static void write(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer){
            VariableExport::_writeWar(ost, Traits<T, Types...>::template getReference<Index>()->getValue(data));
            DBGVAR(Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value);
            ost << ", ";
            writeColumn<T, Index, Position, IndexType, Real>(ost, data, writer);
            writeCellData<Traits<T, Types...>, Index + 1>::print(ost, data);
            ost << std::endl;
            writeCellData<Traits<T, Types...>, Index + 1>::write(ost, data, writer);


        }
        }
    };
    };


    template<typename T,unsigned int Index, typename ... Types>
    template<typename T,unsigned int Index, typename ... Types>
    struct writeCellData <Traits<T, Types...>, Index, std::enable_if_t<Index == Traits<T, Types...>::size() - 1>>{
    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){
        template<unsigned int Position, typename IndexType, typename Real>
            ost << '"' << Traits<T, Types...>::template getName<Traits<T, Types...>::size() - 1>() << "\" : ";
        static void write(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer){
            VariableExport::_writeWar(ost, Traits<T, Types...>::template getReference<Traits<T, Types...>::size() - 1>()->getValue(traitedClass));

            writeColumn<T, Index, Position, IndexType, Real>(ost, data, writer);
            ost << std::endl;
        }
        }
    };
    };


@@ -71,9 +115,10 @@ class VTKMeshDataWriter {
public:
public:
    template<typename T,typename IndexType, typename Real, unsigned int ...Dimensions>
    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) {
    static void writeToStream(std::ostream& ost, MeshDataContainer<T, Dimensions...>& data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer) {
        using type = typename decltype(data.template getDataByDim<MeshDimension>())::DataType;
        using type = T;//typename std::remove_reference<decltype(data.template getDataByDim<MeshDimension>())>::type::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");
        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");

        ost << "CELL_DATA " << writer.cellVert.template getDataByPos<0>().size() << std::endl;
        writeCellData<typename Traits<type>::ttype>::write(ost, data.template getDataByDim<MeshDimension>(), writer);
    }
    }


};
};
+22 −1
Original line number Original line Diff line number Diff line
@@ -65,6 +65,27 @@ public:
        return refs::getInstance().MemRefs<Index, void>::ref;
        return refs::getInstance().MemRefs<Index, void>::ref;
    }
    }


    template<unsigned int Index>
    static type<Index> getValue(const Class* c){
        return getReference<Index>()->getValue(c);
    }

    template<unsigned int Index>
    static type<Index> getValue(const Class& c){
        return getReference<Index>()->getValue(c);
    }

    template<unsigned int Index>
    static void setValue(const Class* c, const type<Index>& val){
        getReference<Index>()->setValue(c, val);
    }

    template<unsigned int Index>
    static void setValue(const Class& c, const type<Index>& val){
        getReference<Index>()->setValue(c, val);
    }


    template<unsigned int Index>
    template<unsigned int Index>
    static const std::string& getName(){
    static const std::string& getName(){
        return refs::getInstance().MemRefs<Index, void>::name;
        return refs::getInstance().MemRefs<Index, void>::name;
+1 −1
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.10.0, 2019-11-03T16:14:20. -->
<!-- Written by QtCreator 4.10.0, 2019-11-06T13:58:55. -->
<qtcreator>
<qtcreator>
 <data>
 <data>
  <variable>EnvironmentId</variable>
  <variable>EnvironmentId</variable>
+25 −3
Original line number Original line Diff line number Diff line
@@ -5,7 +5,7 @@
#include "UnstructuredMesh/MeshFunctions/MeshFunctions.h"
#include "UnstructuredMesh/MeshFunctions/MeshFunctions.h"
#include "UnstructuredMesh/MeshIO/MeshReader/VTKMeshReader.h"
#include "UnstructuredMesh/MeshIO/MeshReader/VTKMeshReader.h"
#include "UnstructuredMesh/MeshIO/MeshWriter/VTKMeshWriter.h"
#include "UnstructuredMesh/MeshIO/MeshWriter/VTKMeshWriter.h"

#include "UnstructuredMesh/MeshDataContainer/MeshDataIO/VTKMeshDataWriter.h"
#include "UnstructuredMesh/MeshIO/MeshReader/FPMAMeshReader.h"
#include "UnstructuredMesh/MeshIO/MeshReader/FPMAMeshReader.h"
#include "UnstructuredMesh/MeshIO/MeshWriter/FPMAMeshWriter.h"
#include "UnstructuredMesh/MeshIO/MeshWriter/FPMAMeshWriter.h"


@@ -585,6 +585,13 @@ void testMesh3D() {
}
}




struct colourData {
    unsigned int colour;
    Vector<3, double> firstEdgeNormal;
};

MAKE_ATTRIBUTE_TRAIT(colourData, colour, firstEdgeNormal);

void testMeshRefine() {
void testMeshRefine() {
    UnstructuredMesh<3, size_t, double, 6> mesh;
    UnstructuredMesh<3, size_t, double, 6> mesh;
    twoPrisms(mesh);
    twoPrisms(mesh);
@@ -614,7 +621,20 @@ void testMeshRefine() {
    writer1.writeToStream(out3D, mesh, types1);
    writer1.writeToStream(out3D, mesh, types1);
    auto colours1 = MeshColouring<3,0>::colour(mesh);
    auto colours1 = MeshColouring<3,0>::colour(mesh);


    out3D << "CELL_DATA " << writer1.cellVert.getDataByPos<0>().size() << endl;
    MeshDataContainer<colourData, 3> cd(mesh);
    auto normals = mesh.computeFaceNormals();

    for(auto& cell : mesh.getCells()){
        cd.at(cell).colour = colours1.at(cell);
        cd.at(cell).firstEdgeNormal = normals.getDataByDim<2>().at(mesh.getFaces().at(cell.getBoundaryElementIndex()).getNextBElem(cell.getIndex()));
    }
    DBGVAR(cd.getDataByDim<3>());

    VTKMeshDataWriter<3> dataWriter;

    dataWriter.writeToStream(out3D, cd, writer1);

    //out3D << "CELL_DATA " << writer1.cellVert.getDataByPos<0>().size() << endl;
    out3D << "SCALARS cell_wrt_vertex_colour double 1\nLOOKUP_TABLE default" << endl;
    out3D << "SCALARS cell_wrt_vertex_colour double 1\nLOOKUP_TABLE default" << endl;
    size_t realIndex = 0;
    size_t realIndex = 0;
    for (size_t i = 0; i < writer1.cellVert.getDataByPos<0>().size(); i++) {
    for (size_t i = 0; i < writer1.cellVert.getDataByPos<0>().size(); i++) {
@@ -691,6 +711,8 @@ void testMeshRefine() {








void test3DMeshDeformedPrisms() {
void test3DMeshDeformedPrisms() {
    UnstructuredMesh<3, size_t, double, 6> mesh3;
    UnstructuredMesh<3, size_t, double, 6> mesh3;
    twoDeformedPrisms(mesh3);
    twoDeformedPrisms(mesh3);
@@ -903,7 +925,7 @@ int main()
    //testMesh2DLoadAndWrite();
    //testMesh2DLoadAndWrite();
    //testMesh3D();
    //testMesh3D();
    //test3DMeshDeformedPrisms();
    //test3DMeshDeformedPrisms();
    //testMeshRefine();
    testMeshRefine();
    //testMeshDataContainer();
    //testMeshDataContainer();
    //UnstructuredMesh<5, size_t, double, 6,5,4> m;
    //UnstructuredMesh<5, size_t, double, 6,5,4> m;
    //m.ComputeElementMeasures();
    //m.ComputeElementMeasures();