Loading TemplateTest/main.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -269,10 +269,10 @@ public: using ttype = Traits<tempData, double, Vector<3,double>>; const static ttype tr; }; 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_ATTRIBUTE_TRAIT(tempData, density, velocity); Loading Loading @@ -304,7 +304,7 @@ void testMemberRef(){ DBGVAR(Traits<tempData>::is_specialized,Detail::has_default_traits<tempData>::value, d); ExportTest e; DBGVAR(e); DBGVAR(e, ClassC<>()); } Loading Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MeshDataIO/VTKMeshDataWriter.h +67 −22 Original line number Diff line number Diff line Loading @@ -9,11 +9,15 @@ template <unsigned int MeshDimension> class VTKMeshDataWriter { /** * @brief writeColumn * 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> static auto writeColumn(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer) Loading @@ -21,22 +25,61 @@ class VTKMeshDataWriter { Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value >::type { if (data.at(0).size() == MeshDimension) if (Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size() == MeshDimension) 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 << 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> Loading @@ -44,24 +87,25 @@ class VTKMeshDataWriter { 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; template<unsigned int Position, typename IndexType, typename Real> 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); static void write(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer){ DBGVAR(Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value); writeColumn<T, Index, Position, IndexType, Real>(ost, data, writer); ost << std::endl; writeCellData<Traits<T, Types...>, Index + 1>::write(ost, data, writer); } }; 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)); 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){ writeColumn<T, Index, Position, IndexType, Real>(ost, data, writer); ost << std::endl; } }; Loading @@ -71,9 +115,10 @@ class VTKMeshDataWriter { 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; 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"); ost << "CELL_DATA " << writer.cellVert.template getDataByPos<0>().size() << std::endl; writeCellData<typename Traits<type>::ttype>::write(ost, data.template getDataByDim<MeshDimension>(), writer); } }; Loading Unstructured_mesh/UnstructuredMesh/MeshDataContainer/Traits.h +22 −1 Original line number Diff line number Diff line Loading @@ -65,6 +65,27 @@ public: 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> static const std::string& getName(){ return refs::getInstance().MemRefs<Index, void>::name; Loading Unstructured_mesh/Unstructured_mesh.pro.user +1 −1 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <!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> <data> <variable>EnvironmentId</variable> Loading Unstructured_mesh/main.cpp +25 −3 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ #include "UnstructuredMesh/MeshFunctions/MeshFunctions.h" #include "UnstructuredMesh/MeshIO/MeshReader/VTKMeshReader.h" #include "UnstructuredMesh/MeshIO/MeshWriter/VTKMeshWriter.h" #include "UnstructuredMesh/MeshDataContainer/MeshDataIO/VTKMeshDataWriter.h" #include "UnstructuredMesh/MeshIO/MeshReader/FPMAMeshReader.h" #include "UnstructuredMesh/MeshIO/MeshWriter/FPMAMeshWriter.h" Loading Loading @@ -585,6 +585,13 @@ void testMesh3D() { } struct colourData { unsigned int colour; Vector<3, double> firstEdgeNormal; }; MAKE_ATTRIBUTE_TRAIT(colourData, colour, firstEdgeNormal); void testMeshRefine() { UnstructuredMesh<3, size_t, double, 6> mesh; twoPrisms(mesh); Loading Loading @@ -614,7 +621,20 @@ void testMeshRefine() { writer1.writeToStream(out3D, mesh, types1); 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; size_t realIndex = 0; for (size_t i = 0; i < writer1.cellVert.getDataByPos<0>().size(); i++) { Loading Loading @@ -691,6 +711,8 @@ void testMeshRefine() { void test3DMeshDeformedPrisms() { UnstructuredMesh<3, size_t, double, 6> mesh3; twoDeformedPrisms(mesh3); Loading Loading @@ -903,7 +925,7 @@ int main() //testMesh2DLoadAndWrite(); //testMesh3D(); //test3DMeshDeformedPrisms(); //testMeshRefine(); testMeshRefine(); //testMeshDataContainer(); //UnstructuredMesh<5, size_t, double, 6,5,4> m; //m.ComputeElementMeasures(); Loading Loading
TemplateTest/main.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -269,10 +269,10 @@ public: using ttype = Traits<tempData, double, Vector<3,double>>; const static ttype tr; }; 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_ATTRIBUTE_TRAIT(tempData, density, velocity); Loading Loading @@ -304,7 +304,7 @@ void testMemberRef(){ DBGVAR(Traits<tempData>::is_specialized,Detail::has_default_traits<tempData>::value, d); ExportTest e; DBGVAR(e); DBGVAR(e, ClassC<>()); } Loading
Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MeshDataIO/VTKMeshDataWriter.h +67 −22 Original line number Diff line number Diff line Loading @@ -9,11 +9,15 @@ template <unsigned int MeshDimension> class VTKMeshDataWriter { /** * @brief writeColumn * 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> static auto writeColumn(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer) Loading @@ -21,22 +25,61 @@ class VTKMeshDataWriter { Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value >::type { if (data.at(0).size() == MeshDimension) if (Traits<T>::ttype::template getReference<Index>()->getValue(data.at(0)).size() == MeshDimension) 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 << 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> Loading @@ -44,24 +87,25 @@ class VTKMeshDataWriter { 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; template<unsigned int Position, typename IndexType, typename Real> 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); static void write(std::ostream& ost, const DataContainer<T, Position, MeshDimension> &data, VTKMeshWriter<MeshDimension,IndexType, Real>& writer){ DBGVAR(Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value); writeColumn<T, Index, Position, IndexType, Real>(ost, data, writer); ost << std::endl; writeCellData<Traits<T, Types...>, Index + 1>::write(ost, data, writer); } }; 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)); 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){ writeColumn<T, Index, Position, IndexType, Real>(ost, data, writer); ost << std::endl; } }; Loading @@ -71,9 +115,10 @@ class VTKMeshDataWriter { 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; 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"); ost << "CELL_DATA " << writer.cellVert.template getDataByPos<0>().size() << std::endl; writeCellData<typename Traits<type>::ttype>::write(ost, data.template getDataByDim<MeshDimension>(), writer); } }; Loading
Unstructured_mesh/UnstructuredMesh/MeshDataContainer/Traits.h +22 −1 Original line number Diff line number Diff line Loading @@ -65,6 +65,27 @@ public: 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> static const std::string& getName(){ return refs::getInstance().MemRefs<Index, void>::name; Loading
Unstructured_mesh/Unstructured_mesh.pro.user +1 −1 Original line number Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <!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> <data> <variable>EnvironmentId</variable> Loading
Unstructured_mesh/main.cpp +25 −3 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ #include "UnstructuredMesh/MeshFunctions/MeshFunctions.h" #include "UnstructuredMesh/MeshIO/MeshReader/VTKMeshReader.h" #include "UnstructuredMesh/MeshIO/MeshWriter/VTKMeshWriter.h" #include "UnstructuredMesh/MeshDataContainer/MeshDataIO/VTKMeshDataWriter.h" #include "UnstructuredMesh/MeshIO/MeshReader/FPMAMeshReader.h" #include "UnstructuredMesh/MeshIO/MeshWriter/FPMAMeshWriter.h" Loading Loading @@ -585,6 +585,13 @@ void testMesh3D() { } struct colourData { unsigned int colour; Vector<3, double> firstEdgeNormal; }; MAKE_ATTRIBUTE_TRAIT(colourData, colour, firstEdgeNormal); void testMeshRefine() { UnstructuredMesh<3, size_t, double, 6> mesh; twoPrisms(mesh); Loading Loading @@ -614,7 +621,20 @@ void testMeshRefine() { writer1.writeToStream(out3D, mesh, types1); 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; size_t realIndex = 0; for (size_t i = 0; i < writer1.cellVert.getDataByPos<0>().size(); i++) { Loading Loading @@ -691,6 +711,8 @@ void testMeshRefine() { void test3DMeshDeformedPrisms() { UnstructuredMesh<3, size_t, double, 6> mesh3; twoDeformedPrisms(mesh3); Loading Loading @@ -903,7 +925,7 @@ int main() //testMesh2DLoadAndWrite(); //testMesh3D(); //test3DMeshDeformedPrisms(); //testMeshRefine(); testMeshRefine(); //testMeshDataContainer(); //UnstructuredMesh<5, size_t, double, 6,5,4> m; //m.ComputeElementMeasures(); Loading