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

Compile errors were fixed, but the export is not finite

parent 4c2fae73
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -447,7 +447,7 @@ MeshDataContainer<Real, Dimension-1> ComputeCellsDistance(MeshElements<Dimension



namespace temp1 {



template <unsigned int CurrentDimension, unsigned int StartDimension, unsigned int TargetDimension, unsigned int MeshDimension, bool End, bool Descend>
@@ -715,10 +715,24 @@ bool edgeIsLeft(MeshElements<3, IndexType, Real, Reserve...>& mesh, IndexType fa

}

template<typename IndexType, typename Real, unsigned int ...Reserve>
MeshDataContainer<std::vector<bool>, 2> edgesOrientation(MeshElements<3, IndexType, Real, Reserve...>& mesh) {

    MeshDataContainer<std::vector<bool>, 2> orientations(mesh);
    auto normals = ComputeFaceNormals(mesh);

    for (auto& face : mesh.getFaces()) {
        orientations[face].resize(face.getSubelements().getNumberOfSubElements());
        for (IndexType i = 0; i < face.getSubelements().getNumberOfSubElements(); i++){
            typename MeshElements<3, IndexType, Real, Reserve...>::Edge& edge = mesh.getEdges().at(face.getSubelements()[i].index);

            orientations[face][i] = edgeIsLeft(mesh, face, edge, normals[face]);
        }
    }
    return orientations;
}




#endif // MESH_FUNCTIONS_H
+7 −3
Original line number Diff line number Diff line
@@ -7,14 +7,18 @@ class MeshWriter{

};

enum {
    hmmm
};

template <typename IndexType, typename Real>
class MeshWriter<2, IndexType, Real> {
public:
    using type = MeshNativeType<2>;

};

template <typename IndexType, typename Real>
class MeshWriter<3, IndexType, Real> {
public:
    using type = MeshNativeType<3>;

};
#endif // MESHWRITER_H
+178 −44
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ public:
        }
        ost << std::endl;

        auto cellVert = temp1::MeshConnections<2,0>::connections(mesh);
        auto cellVert = ::MeshConnections<2,0>::connections(mesh);
        int cnt = 0;
        for (auto verts : cellVert.template getDataByPos<0>()){
            cnt += verts.size() + 1;
@@ -111,11 +111,11 @@ public:


template<typename IndexType, typename Real, unsigned int... Reserve>
class VTKMeshWriter<3, IndexType, Real, Reserve...> : public MeshWriter<2, IndexType, Real>{
    using writer = MeshWriter<2, IndexType, Real>;
class VTKMeshWriter<3, IndexType, Real, Reserve...> : public MeshWriter<3, IndexType, Real>{
    using writer = MeshWriter<3, IndexType, Real>;
    std::map<typename writer::type::ElementType, int> TypeConversionTable{
        {writer::type::ElementType::TETRA, 10},
        {writer::type::ElementType::HEXAGON, 12},
        {writer::type::ElementType::HEXAHEDRON, 12},
        {writer::type::ElementType::WEDGE, 13},
        {writer::type::ElementType::PYRAMID, 14},
    };
@@ -126,9 +126,54 @@ public:
               dataName << "\nASCII\nDATASET UNSTRUCTURED_GRID" << std::endl;
    }


    std::vector<IndexType> writeFace(std::ostream& ost,
                   MeshElements<3, IndexType, Real, Reserve...>& mesh,
                   typename MeshElements<3, IndexType, Real, Reserve...>::Face& face,
                   MeshDataContainer<std::vector<bool>, 2>& faceEdgeOri){

        std::vector<IndexType> verticesWritten;
        verticesWritten.reserve(face.getSubelements().getNumberOfSubElements());

        IndexType startVertex = INVALID_INDEX(IndexType);
        IndexType nextVertex = INVALID_INDEX(IndexType);
        if (faceEdgeOri[face][0] == true){ // the edge is left to the face
            startVertex = mesh.getEdges().at(face.getSubelements()[0].index).getVertexBIndex();
            ost << startVertex << ' ';
            nextVertex = mesh.getEdges().at(face.getSubelements()[0].index).getVertexAIndex();
        } else {
            startVertex = mesh.getEdges().at(face.getSubelements()[0].index).getVertexAIndex();
            ost << startVertex << ' ';
            nextVertex = mesh.getEdges().at(face.getSubelements()[0].index).getVertexBIndex();
        }

        verticesWritten.push_back(startVertex);

        IndexType lastWrittenEdge = face.getSubelements()[0].index;
        while (startVertex != nextVertex){
            for (auto& sube : face.getSubelements()) {
                auto &edge = mesh.getEdges().at(sube.index);
                if (edge.getIndex() != lastWrittenEdge) {
                    if (edge.getVertexAIndex() == nextVertex) {
                        lastWrittenEdge = edge.getIndex();
                        ost << edge.getVertexAIndex() << ' ';
                        verticesWritten.push_back(edge.getVertexAIndex());
                        nextVertex = edge.getVertexBIndex();
                    } else if (edge.getVertexAIndex() == nextVertex) {
                        lastWrittenEdge = edge.getIndex();
                        ost << edge.getVertexBIndex() << ' ';
                        verticesWritten.push_back(edge.getVertexBIndex());
                        nextVertex = edge.getVertexAIndex();
                    }
                }
            }
        }
        return verticesWritten;
    }

    void writeToStream(std::ostream& ost,
                       MeshElements<3, IndexType, Real, Reserve...>& mesh,
                       MeshDataContainer<typename writer::type::ElementType, 3> cellTypes){
                       MeshDataContainer<typename writer::type::ElementType, 3>& cellTypes){
        // first write verices
        ost << "POINTS " << mesh.getVertices().size() <<
               " double" << std::endl;
@@ -138,9 +183,9 @@ public:
        }
        ost << std::endl;

        auto cellVert = temp1::MeshConnections<3,0>::connections(mesh);
        auto cellFace = temp1::MeshConnections<3,2>::connections(mesh);
        auto faceVert = temp1::MeshConnections<2,0>::connections(mesh);
        auto cellVert = MeshConnections<3,0>::connections(mesh);
        auto cellFace = MeshConnections<3,2>::connections(mesh);
        auto faceVert = MeshConnections<2,0>::connections(mesh);

        int cnt = 0;
        for (auto verts : cellVert.template getDataByPos<0>()){
@@ -148,6 +193,9 @@ public:
        }
        ost << "CELLS " << mesh.getCells().size() << ' ' << cnt << std::endl;

        auto faceEdgeOri = edgesOrientation(mesh);


        for (auto cell : mesh.getCells()){
            ost << cellVert.at(cell).size() << " ";

@@ -157,53 +205,139 @@ public:

            case writer::type::ElementType::TETRA :{
                // write vertices of one face
                auto& face = mesh.getFaces(*(cellFace.at(cell).begin()));
                auto& face = mesh.getFaces().at(cell.getBoundaryElementIndex());

                int vertWritten = 0;
                IndexType nextVertex = INVALID_INDEX(IndexType);
                if (face.getSubelements[0].isLeft){
                    ost << mesh.getEdges().at(face.getSubelements[0].index).getVetexAIndex();
                    nextVertex = mesh.getEdges().at(face.getSubelements[0].index).getVertexBIndex() << ' ';
                } else {
                    ost << mesh.getEdges().at(face.getSubelements[0].index).getVetexBIndex();
                    nextVertex = mesh.getEdges().at(face.getSubelements[0].index).getVertexAIndex() << ' ';
                }
                std::vector<IndexType> vertWrit = writeFace(ost,mesh,face, faceEdgeOri);

                IndexType lastWrittenEdge = face.getSubelements[0].index;
                while (vertWritten != faceVert.at(face).size()){
                    for (auto& sube : face.getSubelements()) {
                        auto &edge = mesh.getEdges().at(sube.index);
                        if (edge.getIndex() != lastWrittenEdge) {
                            if (edge.getVertexAIndex() == nextVertex) {
                                lastWrittenEdge = edge.getIndex();
                                ost << edge.getVertexAIndex() << ' ';
                                nextVertex = edge.getVertexAIndex();
                for (IndexType index : faceVert[face]) {
                    bool vertOK = true;
                    for (IndexType i : vertWrit){
                       if (i == index){
                           vertOK = false;
                       }
                    }
                    if (vertOK){
                        ost << index;
                        vertWrit.push_back(index);
                    }
                }
            }break;


            case writer::type::ElementType::PYRAMID :{
                // write vertices of one face
                typename MeshElements<3, IndexType, Real, Reserve...>::Face* face = nullptr;
                // search for the base face
                for (IndexType faceIndex : cellFace[cell]){
                    if (faceVert.template getDataByPos<0>().at(faceIndex).size() == 4){
                        face = &mesh.getFaces().at(faceIndex);
                    }
                }

                std::vector<IndexType> vertWrit = writeFace(ost, mesh, *face, faceEdgeOri);
                // write the last vertex
                for (IndexType index : faceVert.at(*face)) {
                    bool vertOK = true;
                    for (IndexType i : vertWrit){
                       if (i == index){
                           vertOK = false;
                       }
                    }
                    if (vertOK){
                        ost << index;
                        vertWrit.push_back(index);
                    }
                }
            }break;

            case writer::type::ElementType::WEDGE :{
                // write vertices of one face
                typename MeshElements<3, IndexType, Real, Reserve...>::Face* face = nullptr;
                // search for the base face
                for (IndexType faceIndex : cellFace[cell]){
                    if (faceVert.template getDataByPos<0>().at(faceIndex).size() == 3){
                        face = &mesh.getFaces().at(faceIndex);
                    }
                }

                std::vector<IndexType> vertWrit = writeFace(ost, mesh, *face, faceEdgeOri);
                // write vertices of the oposite triangular side
                for (IndexType index : vertWrit) {
                    MeshRun<3,3,1,3,false, true>::run(mesh, cell.getIndex(),cell.getIndex(),
                        [&ost,&mesh,&index,&vertWrit](IndexType, IndexType edgeIndex){
                        auto& edge = mesh.getEdges().at(edgeIndex);

                        if (edge.getVertexAIndex() == index){
                            bool edgeOK = true;
                            for (IndexType i : vertWrit){
                               if (edge.getVertexBIndex() == i){
                                   edgeOK = false;
                               }
                            }
                            if(edgeOK){
                                ost << edge.getVertexBIndex() << ' ';
                                vertWrit.push_back(edge.getVertexBIndex());
                            }
                        }

                        if (edge.getVertexBIndex() == index){
                            bool edgeOK = true;
                            for (IndexType i : vertWrit){
                               if (edge.getVertexAIndex() == i){
                                   edgeOK = false;
                               }
                            }
                            if(edgeOK){
                                ost << edge.getVertexAIndex() << ' ';
                                vertWrit.push_back(edge.getVertexAIndex());
                            }
                        }
                    }
                    );
                }
            }break;

            case writer::type::ElementType::HEXAHEDRON :{
                // write vertices of one face
                auto& face = mesh.getFaces().at(cell.getBoundaryElementIndex());

                std::vector<IndexType> vertWrit = writeFace(ost, mesh, face, faceEdgeOri);
                // write vertices of the oposite triangular side
                for (IndexType index : vertWrit) {
                    MeshRun<3,3,1,3,false, true>::run(mesh, cell.getIndex(),cell.getIndex(),
                        [&ost,&mesh,&index,&vertWrit](IndexType, IndexType edgeIndex){
                        auto& edge = mesh.getEdges().at(edgeIndex);

                        if (edge.getVertexAIndex() == index){
                            bool edgeOK = true;
                            for (IndexType i : vertWrit){
                               if (edge.getVertexBIndex() == i){
                                   edgeOK = false;
                               }
                            }
                            if(edgeOK){
                                ost << edge.getVertexBIndex() << ' ';
                                vertWrit.push_back(edge.getVertexBIndex());
                            }
                        }













                        if (edge.getVertexBIndex() == index){
                            bool edgeOK = true;
                            for (IndexType i : vertWrit){
                               if (edge.getVertexAIndex() == i){
                                   edgeOK = false;
                               }
                            }
                            if(edgeOK){
                                ost << edge.getVertexAIndex() << ' ';
                                vertWrit.push_back(edge.getVertexAIndex());
                            }
                        }
                    }
                    );
                }
            }break;
            default: throw std::runtime_error("it is not possible yet to write any object into VTK");
            }

            ost << std::endl;
        }
+28 −15
Original line number Diff line number Diff line
@@ -400,7 +400,7 @@ void testMesh2DLoadAndWrite(){


    DBGMSG("mesh apply test");
    temp1::MeshRun<2, 2, 0, 2,false, true>::run(mesh,size_t(4), size_t(4), [](size_t ori, size_t i){
    MeshRun<2, 2, 0, 2,false, true>::run(mesh,size_t(4), size_t(4), [](size_t ori, size_t i){
        DBGVAR(ori,i);
    });

@@ -500,48 +500,61 @@ void testMesh3D() {
    }

    DBGMSG("mesh apply test");
    temp1::MeshApply<3, 2, 3>::apply(mesh3, [](size_t ori, size_t i){
    MeshApply<3, 2, 3>::apply(mesh3, [](size_t ori, size_t i){
        DBGVAR(ori,i);
    });
    DBGMSG("mesh apply test");
    temp1::MeshApply<2, 3, 3>::apply(mesh3,[](size_t ori, size_t i){
    MeshApply<2, 3, 3>::apply(mesh3,[](size_t ori, size_t i){
        DBGVAR(ori,i);
    });

    DBGMSG("3D edge orientation");
    temp1::MeshApply<2, 1, 3>::apply(mesh3,[&mesh3](size_t faceIndex, size_t edgeIndex){
    MeshApply<2, 1, 3>::apply(mesh3,[&mesh3](size_t faceIndex, size_t edgeIndex){
        size_t iA = mesh3.getEdges().at(edgeIndex).getVertexAIndex(), iB =mesh3.getEdges().at(edgeIndex).getVertexBIndex();
        HTMLDBGVAR(faceIndex,
        DBGVAR(faceIndex,
               edgeIndex,
               iA, iB,
               temp1::edgeIsLeft(mesh3,faceIndex, edgeIndex));
               edgeIsLeft(mesh3,faceIndex, edgeIndex));
    });


    auto orientation =  edgesOrientation(mesh3);
    for(auto & face : mesh3.getFaces()){
        DBGVAR(face.getIndex(),orientation[face]);
    }


    DBGMSG("connection test");
    auto con = temp1::MeshConnections<3,0>::connections(mesh3);
    auto con = MeshConnections<3,0>::connections(mesh3);
    for (auto& cell : mesh3.getCells()){
            DBGVAR(cell.getIndex(), con[cell]);
    }


    DBGMSG("connection test oposite");
    auto con1 = temp1::MeshConnections<0,3>::connections(mesh3);
    auto con1 = MeshConnections<0,3>::connections(mesh3);
    for (auto& vert : mesh3.getVertices()){
        DBGVAR(vert.getIndex(), con1[vert]);
    }

    DBGMSG("face to vertex colouring");
    auto colours = temp1::ColourMesh<2,0>::colour(mesh3);
    auto colours = ColourMesh<2,0>::colour(mesh3);
    for (auto& face : mesh3.getFaces()){
        DBGVAR(face.getIndex(), colours.at(face));
    }

    DBGMSG("vertex to face colouring");
    auto colours1 = temp1::ColourMesh<0,2>::colour(mesh3);
    auto colours1 = ColourMesh<0,2>::colour(mesh3);
    for (auto& vert : mesh3.getVertices()){
        DBGVAR(vert.getIndex(), colours1.at(vert));
    }

    MeshDataContainer<MeshNativeType<3>::ElementType,3> types(mesh3, MeshNativeType<3>::ElementType::WEDGE);

    VTKMeshWriter<3, size_t, double, 6> writer;
    ofstream out3D("3D_test_mesh_two_prisms.vtk");
    writer.writeHeader(out3D, "test data");
    writer.writeToStream(out3D, mesh3, types);
}


@@ -637,7 +650,7 @@ DBGVAR(mesh.getVertices().size(),mesh.getEdges().size(), mesh.getFaces().size(),


    DBGMSG("connection test");
    auto con2 = temp1::MeshConnections<1,0>::connections(mesh);
    auto con2 = MeshConnections<1,0>::connections(mesh);
    for (auto& edge : mesh.getEdges()){
            DBGVAR(edge.getIndex(), con2[edge]);
    }
@@ -650,13 +663,13 @@ DBGVAR(mesh.getVertices().size(),mesh.getEdges().size(), mesh.getFaces().size(),
    }

    DBGMSG("connection test");
    auto con1 = temp1::MeshConnections<2,1>::connections(mesh);
    auto con1 = MeshConnections<2,1>::connections(mesh);
    for (auto& face : mesh.getFaces()){
            DBGVAR(face.getIndex(), con1[face]);
    }

    DBGMSG("connection test");
    auto con = temp1::MeshConnections<3,2>::connections(mesh);
    auto con = MeshConnections<3,2>::connections(mesh);
    for (auto& cell : mesh.getCells()){
            DBGVAR(cell.getIndex(), con[cell]);
    }
@@ -674,9 +687,9 @@ DBGVAR(mesh.getVertices().size(),mesh.getEdges().size(), mesh.getFaces().size(),

int main()
{
    //testMesh2D();
    testMesh2D();
    //testMesh2DLoadAndWrite();
    //testMesh3D();
    testMesh3D();
    //test3DMeshDeformedPrisms();
    //testMeshDataContainer();
    //UnstructuredMesh<5, size_t, double, 6,5,4> m;