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

DataContainer refactor (omit Position)

MeshDataContainer operator=(& and &&) and little documentation
parent 41399e93
Loading
Loading
Loading
Loading
+16 −8
Original line number Original line Diff line number Diff line
@@ -803,6 +803,12 @@ void testMeshDataContainer() {
    MeshDataContainer<std::tuple<int, double, char, double>, 3,2,0> container(mesh3);
    MeshDataContainer<std::tuple<int, double, char, double>, 3,2,0> container(mesh3);




    MeshDataContainer<double, 3,3,1> cont(mesh3, 52.2);
    MeshDataContainer<double, 1,1> contAlloc;
    contAlloc.allocateData(cont, 42.2);

    DBGVAR(cont.getDataByDim<1>(), contAlloc.getDataByDim<1>());



    for(auto& c : container.getDataByDim<0>()) {
    for(auto& c : container.getDataByDim<0>()) {
        c=42;
        c=42;
@@ -812,7 +818,7 @@ void testMeshDataContainer() {
        DBGVAR(container.at(v));
        DBGVAR(container.at(v));
    }
    }


    MeshDataContainer<std::tuple<int, double, char, int>, 3, 2, 0, 2> containerIni(mesh3,3, 42.15, 'a', 15);
    MeshDataContainer<std::tuple<int, double, char, int>, 3, 2, 0, 1> containerIni(mesh3,3, 42.15, 'a', 15);




    for (auto& val : containerIni.getDataByPos<0>()){
    for (auto& val : containerIni.getDataByPos<0>()){
@@ -832,13 +838,15 @@ void testMeshDataContainer() {
    }
    }


    DBGMSG("assign test");
    DBGMSG("assign test");
    MeshDataContainer<std::tuple<int, double, char, int>, 3, 2, 0, 2> containerAssign;
    MeshDataContainer<std::tuple<int, double, char, int>, 3, 2, 0, 1> containerAssign;


    containerAssign = containerIni;
    containerAssign = containerIni;


    for (auto& val : containerAssign.getDataByPos<0>()){
    contAlloc.getDataByDim<1>().clear();
        DBGVAR(val);
    contAlloc.allocateData(containerAssign, 87);
    }


    DBGVAR(contAlloc.getDataByDim<1>(), contAlloc.getDataByPos<1>(),containerAssign.getDataByPos<0>());
}
}




@@ -969,9 +977,9 @@ int main()
{
{
    //testMesh2D();
    //testMesh2D();
    //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();
+339 −74

File changed.

Preview size limit exceeded, changes collapsed.

+15 −15
Original line number Original line Diff line number Diff line
@@ -16,13 +16,13 @@ class VTKMeshDataReader {
     * @brief readColumn
     * @brief readColumn
     * reads a single column of traited data
     * reads a single column of traited data
     */
     */
    static void readColumn(std::istream& ist [[maybe_unused]],...){
    static void readColumn(std::istream& ,...){
        DBGMSG("capture");
        DBGMSG("capture");
        throw std::runtime_error("capture of read column must not be called.");
        throw std::runtime_error("capture of read column must not be called.");
    }
    }


    template<typename T, unsigned int Index, unsigned int Position>
    template<typename T, unsigned int Index>
    static auto readColumn(std::istream& ist, DataContainer<T, Position, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions)
    static auto readColumn(std::istream& ist, DataContainer<T, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions)
    -> typename std::enable_if<
    -> typename std::enable_if<
        IsIndexable<typename Traits<T>::ttype::template type<Index>>::value &&
        IsIndexable<typename Traits<T>::ttype::template type<Index>>::value &&
        MeshDimension == 3
        MeshDimension == 3
@@ -43,8 +43,8 @@ class VTKMeshDataReader {
    }
    }




    template<typename T, unsigned int Index, unsigned int Position>
    template<typename T, unsigned int Index>
    static auto readColumn(std::istream& ist, DataContainer<T, Position, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions)
    static auto readColumn(std::istream& ist, DataContainer<T, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions)
    -> typename std::enable_if<
    -> typename std::enable_if<
        IsIndexable<typename Traits<T>::ttype::template type<Index>>::value &&
        IsIndexable<typename Traits<T>::ttype::template type<Index>>::value &&
        MeshDimension == 2
        MeshDimension == 2
@@ -69,8 +69,8 @@ class VTKMeshDataReader {
    }
    }




    template<typename T, unsigned int Index, unsigned int Position>
    template<typename T, unsigned int Index>
    static auto readColumn(std::istream& ist, DataContainer<T, Position, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions)
    static auto readColumn(std::istream& ist, DataContainer<T, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions)
    -> typename std::enable_if<
    -> typename std::enable_if<
        !IsIndexable<typename Traits<T>::ttype::template type<Index>>::value
        !IsIndexable<typename Traits<T>::ttype::template type<Index>>::value
    >::type
    >::type
@@ -95,11 +95,11 @@ private:
    template<typename T,unsigned int Index, typename... Types>
    template<typename T,unsigned int Index, typename... Types>
    struct readCellData <Traits<T, Types...>, Index, std::enable_if_t<Index < Traits<T, Types...>::size() - 1>>{
    struct readCellData <Traits<T, Types...>, Index, std::enable_if_t<Index < Traits<T, Types...>::size() - 1>>{


        template<unsigned int Position>


        static void read(std::istream& ist, DataContainer<T, Position, MeshDimension> &data, std::map<std::string, std::istream::pos_type>& dataPositions){

        static void read(std::istream& ist, DataContainer<T, MeshDimension> &data, std::map<std::string, std::istream::pos_type>& dataPositions){
            DBGVAR(IsIndexable<typename Traits<T>::ttype::template type<Index>>::value);
            DBGVAR(IsIndexable<typename Traits<T>::ttype::template type<Index>>::value);
            readColumn<T, Index, Position>(ist, data, dataPositions);
            readColumn<T, Index>(ist, data, dataPositions);
            readCellData<Traits<T, Types...>, Index + 1>::read(ist, data, dataPositions);
            readCellData<Traits<T, Types...>, Index + 1>::read(ist, data, dataPositions);


        }
        }
@@ -107,10 +107,10 @@ private:


    template<typename T,unsigned int Index, typename ... Types>
    template<typename T,unsigned int Index, typename ... Types>
    struct readCellData <Traits<T, Types...>, Index, std::enable_if_t<Index == Traits<T, Types...>::size() - 1>>{
    struct readCellData <Traits<T, Types...>, Index, std::enable_if_t<Index == Traits<T, Types...>::size() - 1>>{
        template<unsigned int Position>
        static void read(std::istream& ist, DataContainer<T, Position, MeshDimension> &data, std::map<std::string, std::istream::pos_type>& dataPositions){


            readColumn<T, Index, Position>(ist, data, dataPositions);
        static void read(std::istream& ist, DataContainer<T, MeshDimension> &data, std::map<std::string, std::istream::pos_type>& dataPositions){

            readColumn<T, Index>(ist, data, dataPositions);


        }
        }
    };
    };
@@ -146,8 +146,8 @@ public:
        return dataPositions;
        return dataPositions;
    }
    }


    template<typename T, unsigned int Position>
    template<typename T>
    static void readData(std::istream& ist, DataContainer<T, Position, MeshDimension>& data) {
    static void readData(std::istream& ist, DataContainer<T, MeshDimension>& data) {


        std::map<std::string, std::istream::pos_type> dataPositions = indexData(ist);
        std::map<std::string, std::istream::pos_type> dataPositions = indexData(ist);


+18 −18
Original line number Original line Diff line number Diff line
@@ -17,13 +17,13 @@ class VTKMeshDataWriter {
     * @brief writeColumn
     * @brief writeColumn
     * writes a single column of traited data
     * writes a single column of traited data
     */
     */
    static void writeColumn(std::ostream& ost [[maybe_unused]],...){
    static void writeColumn(std::ostream&,...){
        DBGMSG("capture");
        DBGMSG("capture");
        throw std::runtime_error("capture of write column must not be called.");
        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, 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, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer)
    -> typename std::enable_if<
    -> typename std::enable_if<
        IsIndexable<typename Traits<T>::ttype::template type<Index>>::value &&
        IsIndexable<typename Traits<T>::ttype::template type<Index>>::value &&
        MeshDimension == 3
        MeshDimension == 3
@@ -65,8 +65,8 @@ class VTKMeshDataWriter {






    template<typename T, unsigned int Index, unsigned int Position, typename IndexType, typename Real>
    template<typename T, unsigned int Index, 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, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer)
    -> typename std::enable_if<
    -> typename std::enable_if<
        IsIndexable<typename Traits<T>::ttype::template type<Index>>::value &&
        IsIndexable<typename Traits<T>::ttype::template type<Index>>::value &&
        MeshDimension == 2
        MeshDimension == 2
@@ -105,8 +105,8 @@ class VTKMeshDataWriter {
        }
        }
    }
    }


    template<typename T, unsigned int Index, unsigned int Position, typename IndexType, typename Real>
    template<typename T, unsigned int Index, 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, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer)
    -> typename std::enable_if<
    -> typename std::enable_if<
        !IsIndexable<typename Traits<T>::ttype::template type<Index>>::value
        !IsIndexable<typename Traits<T>::ttype::template type<Index>>::value
    >::type
    >::type
@@ -140,11 +140,11 @@ 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>
        template<typename IndexType, typename Real>


        static void write(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer){
        static void write(std::ostream& ost, const DataContainer<T, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer){
            DBGVAR(IsIndexable<typename Traits<T>::ttype::template type<Index>>::value);
            DBGVAR(IsIndexable<typename Traits<T>::ttype::template type<Index>>::value);
            writeColumn<T, Index, Position, IndexType, Real>(ost, data, writer);
            writeColumn<T, Index, IndexType, Real>(ost, data, writer);
            ost << std::endl;
            ost << std::endl;
            writeCellData<Traits<T, Types...>, Index + 1>::write(ost, data, writer);
            writeCellData<Traits<T, Types...>, Index + 1>::write(ost, data, writer);


@@ -153,18 +153,18 @@ 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>
        template< typename IndexType, typename Real>
        static void write(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer){
        static void write(std::ostream& ost, const DataContainer<T, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer){


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




public:
public:
    template<typename T,typename IndexType, typename Real, unsigned int Position>
    template<typename T,typename IndexType, typename Real>
    static void writeToStream(std::ostream& ost, DataContainer<T, Position, MeshDimension>& data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer) {
    static void writeToStream(std::ostream& ost, DataContainer<T, MeshDimension>& data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer) {
        using type = T;//typename std::remove_reference<decltype(data.template getDataByDim<MeshDimension>())>::type::DataType;
        using type = T;//typename std::remove_reference<decltype(data.template getDataByDim<MeshDimension>())>::type::DataType;
        static_assert (HasDefaultTraits<type>::value, "The class T must have defined traits for example using macro MAKE_ATTRIBUTE_TRAIT in header Traits.h");
        static_assert (HasDefaultTraits<type>::value, "The class T must have defined traits for example using macro MAKE_ATTRIBUTE_TRAIT in header Traits.h");
        ost << "CELL_DATA " << writer.getNumberOfCells() << std::endl;
        ost << "CELL_DATA " << writer.getNumberOfCells() << std::endl;
@@ -209,9 +209,9 @@ private:
    template <bool OK>
    template <bool OK>
    struct MeshDataIterator <0, OK> {
    struct MeshDataIterator <0, OK> {
        template<typename T,typename IndexType, typename Real, unsigned int ...Dimensions>
        template<typename T,typename IndexType, typename Real, unsigned int ...Dimensions>
        static auto writeToStream(std::ostream& ost [[maybe_unused]],
        static auto writeToStream(std::ostream&,
                                  MeshDataContainer<T, Dimensions...>& data [[maybe_unused]],
                                  MeshDataContainer<T, Dimensions...>&,
                                  VTKMeshWriter<MeshDimension,IndexType, Real>& writer [[maybe_unused]]) -> typename
                                  VTKMeshWriter<MeshDimension,IndexType, Real>&) -> typename
            std::enable_if<
            std::enable_if<
                (!HasDefaultTraits<typename MeshDataContainer<T, Dimensions...>::template DataContainerType<0>::type>::value) ||
                (!HasDefaultTraits<typename MeshDataContainer<T, Dimensions...>::template DataContainerType<0>::type>::value) ||
                (!(MeshDataContainer<T, Dimensions...>::template DataContainerType<0>::getMappedDimension() == MeshDimension))
                (!(MeshDataContainer<T, Dimensions...>::template DataContainerType<0>::getMappedDimension() == MeshDimension))