From 02fbadb809eb9240a29f5496a4c69697178ed0c7 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 30 Jan 2024 11:20:17 +0100 Subject: [PATCH 1/5] GridDataOutput: add translation unit --- CMakeLists_files.cmake | 6 +- flow/flow_blackoil_alugrid.cpp | 1 + flow/flow_blackoil_polyhedralgrid.cpp | 1 + opm/simulators/utils/GridDataOutput.cpp | 54 ++ opm/simulators/utils/GridDataOutput.hpp | 448 +--------------- opm/simulators/utils/GridDataOutput_impl.hpp | 517 +++++++++++++++++++ 6 files changed, 597 insertions(+), 430 deletions(-) create mode 100644 opm/simulators/utils/GridDataOutput.cpp create mode 100644 opm/simulators/utils/GridDataOutput_impl.hpp diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 87b6d9706..2654a5863 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -621,8 +621,10 @@ if (Damaris_FOUND AND MPI_FOUND) list (APPEND PUBLIC_HEADER_FILES ebos/damaris_properties.hh) list (APPEND PUBLIC_HEADER_FILES ebos/damariswriter.hh) list (APPEND PUBLIC_HEADER_FILES opm/simulators/utils/DamarisVar.hpp) - list (APPEND PUBLIC_HEADER_FILES opm/simulators/utils/GridDataOutput.hpp) - list(APPEND MAIN_SOURCE_FILES opm/simulators/utils/DamarisVar.cpp) + list (APPEND PUBLIC_HEADER_FILES opm/simulators/utils/GridDataOutput.hpp + opm/simulators/utils/GridDataOutput_impl.hpp) + list(APPEND MAIN_SOURCE_FILES opm/simulators/utils/DamarisVar.cpp + opm/simulators/utils/GridDataOutput.cpp) endif() if(HDF5_FOUND) diff --git a/flow/flow_blackoil_alugrid.cpp b/flow/flow_blackoil_alugrid.cpp index f7a46a075..4514670b8 100644 --- a/flow/flow_blackoil_alugrid.cpp +++ b/flow/flow_blackoil_alugrid.cpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace Opm { namespace Properties { diff --git a/flow/flow_blackoil_polyhedralgrid.cpp b/flow/flow_blackoil_polyhedralgrid.cpp index ca1b5dd59..9eb77060f 100644 --- a/flow/flow_blackoil_polyhedralgrid.cpp +++ b/flow/flow_blackoil_polyhedralgrid.cpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace Opm { namespace Properties { diff --git a/opm/simulators/utils/GridDataOutput.cpp b/opm/simulators/utils/GridDataOutput.cpp new file mode 100644 index 000000000..1d6eaca53 --- /dev/null +++ b/opm/simulators/utils/GridDataOutput.cpp @@ -0,0 +1,54 @@ +/* + Copyright 2023 Inria, Bretagne–Atlantique Research Center + + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ +#include +#include + +#include + +#include + +#if HAVE_DUNE_FEM +#include +#include +#include +#endif // HAVE_DUNE_FEM + +namespace Opm::GridDataOutput { + +template using DV = DamarisOutput::DamarisVar; + +#define INSTANCE(part, ...) \ + template class SimMeshDataAccessor<__VA_ARGS__, part>; \ + template long SimMeshDataAccessor<__VA_ARGS__,part>:: \ + writeGridPoints>(DV&, DV&, DV&); \ + template long SimMeshDataAccessor<__VA_ARGS__,part>:: \ + writeConnectivity>(DV&, ConnectivityVertexOrder); \ + template long SimMeshDataAccessor<__VA_ARGS__,part>:: \ + writeOffsetsCells>(DV&); \ + template long SimMeshDataAccessor<__VA_ARGS__,part>:: \ + writeCellTypes>(DV&); + +INSTANCE(1, Dune::GridView>) + +#if HAVE_DUNE_FEM +INSTANCE(1, Dune::Fem::GridPart2GridViewImpl >) +INSTANCE(1, Dune::GridView>>) +#endif + +} // namespace Opm::GridDataOutput diff --git a/opm/simulators/utils/GridDataOutput.hpp b/opm/simulators/utils/GridDataOutput.hpp index a5410e3a2..7f0974f92 100644 --- a/opm/simulators/utils/GridDataOutput.hpp +++ b/opm/simulators/utils/GridDataOutput.hpp @@ -22,10 +22,8 @@ #include -#include -#include +#include -#include #include /** @file @@ -129,14 +127,8 @@ public: * polyhedralCellPresent() to test if polyhedral cells are present and decide * what they want to do before copying data using the data accessor methods. */ - explicit SimMeshDataAccessor(const GridView& gridView, Dune::PartitionSet dunePartition) - : gridView_(gridView) - , dunePartition_(dunePartition) - { - dimw_ = GridView::dimension; // this is an enum - partition_value_ = dunePartition.value; - countEntities(); - } + explicit SimMeshDataAccessor(const GridView& gridView, + Dune::PartitionSet dunePartition); /** Checks for cells that have polyhedral type within the current partition of @@ -146,16 +138,7 @@ public: partition is not going to be available for visualisation as this class does not yet handle polyhedral cells. */ - bool polyhedralCellPresent() - { - for (const auto& cit : elements(gridView_, dunePartition_)) { - auto corner_geom = cit.geometry(); - if (Dune::VTK::geometryType(corner_geom.type()) == Dune::VTK::polyhedron) { - return true; - } - } - return false; - } + bool polyhedralCellPresent(); /** Count the vertices, cells and corners. @@ -164,22 +147,7 @@ public: do not need to renumber the vertices as all the subsets use references to the full set. */ - void countEntities() - { - // We include all the vertices for this ranks partition - const auto& vert_partition = vertices(gridView_, Dune::Partitions::all); - nvertices_ = std::distance(vert_partition.begin(), vert_partition.end()); - - const auto& cell_partition = elements(gridView_, dunePartition_); - ncells_ = 0; - ncorners_ = 0; - for (const auto& cit : cell_partition) { - auto corner_geom = cit.geometry(); - ncorners_ += corner_geom.corners(); - ++ncells_; - } - } - + void countEntities(); /** Write the positions of vertices - directly to the pointers given in @@ -194,38 +162,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints(T* x_inout, T* y_inout, T* z_inout, long max_size = 0) - { - if (max_size < nvertices_) { - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeGridPoints( T& x_inout, T& " - "y_inout, T& z_inout ) " - + " Input objects max_size (" + std::to_string(max_size) - + ") is not sufficient to fit the nvertices_ values (" + std::to_string(nvertices_) + ")"); - } - - long i = 0; - if (dimw_ == 3) { - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); // vertices only have one corner - x_inout[i] = static_cast(xyz_local[0]); - y_inout[i] = static_cast(xyz_local[1]); - z_inout[i] = static_cast(xyz_local[2]); - i++; - } - } else if (dimw_ == 2) { - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); // vertices only have one corner - x_inout[i] = static_cast(xyz_local[0]); - y_inout[i] = static_cast(xyz_local[1]); - z_inout[i] = static_cast(0.0); - i++; - } - } - assert(i == nvertices_); // As we are templated on the - // Dune::PartitionSet, this cannot change - return i; - } + long writeGridPoints(T* x_inout, T* y_inout, T* z_inout, long max_size = 0); /** Write the positions of vertices - directly to the pointers given in @@ -241,49 +178,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints(VectType& x_inout, VectType& y_inout, VectType& z_inout) - { - const std::size_t check_size_x = x_inout.size(); - const std::size_t check_size_y = y_inout.size(); - const std::size_t check_size_z = z_inout.size(); - - using VT = decltype(x_inout.data()[0]); - - if ((check_size_x < static_cast(nvertices_)) || - (check_size_y < static_cast(nvertices_)) || - (check_size_z < static_cast(nvertices_))) { - // assert(check_size >= nvertices_); - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeGridPoints( VectType& x_inout, VectType& " - "y_inout, VectType& z_inout ) At least one of the inputs" - + " object x size " + std::to_string(check_size_x) + " object y size " - + std::to_string(check_size_y) + " object z size " + std::to_string(check_size_z) - + " is not sufficient to fit the nvertices_ values( " + std::to_string(nvertices_) + " )"); - } - - long i = 0; - if (dimw_ == 3) { - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); // vertices only have one corner - x_inout.data()[i] = static_cast(xyz_local[0]); - y_inout.data()[i] = static_cast(xyz_local[1]); - z_inout.data()[i] = static_cast(xyz_local[2]); - i++; - } - } else if (dimw_ == 2) { - double td = 0.0; - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); // vertices only have one corner - x_inout.data()[i] = static_cast(xyz_local[0]); - y_inout.data()[i] = static_cast(xyz_local[1]); - z_inout.data()[i] = static_cast(td); - i++; - } - } - assert(i == nvertices_); // As we are templated on the - // Dune::PartitionSet, this cannot change - return i; - } + long writeGridPoints(VectType& x_inout, VectType& y_inout, VectType& z_inout); /** Write the positions of vertices - directly to the pointers given in @@ -296,35 +191,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints_AOS(T* xyz_inout, long max_size = 0) - { - if (max_size < nvertices_ * 3) { - assert(max_size >= nvertices_ * 3); - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeGridPoints_AOS( T* xyz_inout ) " + " Input objects max_size (" - + std::to_string(max_size) + ") is not sufficient to fit the nvertices_ * 3 values (" - + std::to_string(nvertices_ * 3) + ")"); - } - - long i = 0; - if (dimw_ == 3) { - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); - xyz_inout[i++] = static_cast(xyz_local[0]); - xyz_inout[i++] = static_cast(xyz_local[1]); - xyz_inout[i++] = static_cast(xyz_local[2]); - } - } else if (dimw_ == 2) { - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); - xyz_inout[i++] = static_cast(xyz_local[0]); - xyz_inout[i++] = static_cast(xyz_local[1]); - xyz_inout[i++] = static_cast(0.0); - } - } - return ((i) / 3); - } - + long writeGridPoints_AOS(T* xyz_inout, long max_size = 0); /** Write the positions of vertices - directly to the pointers given in @@ -336,40 +203,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints_AOS(VectType& xyz_inout) - { - const std::size_t check_size = xyz_inout.size(); - - using VT = decltype(xyz_inout.data()[0]); - - if (check_size < static_cast(nvertices_ * 3)) { - assert(check_size >= nvertices_ * 3); - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeGridPoints_AOS( VectType& xyz_inout ) " - + " Input objects check_size (" + std::to_string(check_size) - + ") is not sufficient to fit the nvertices_ * 3 values (" + std::to_string(nvertices_ * 3) - + ")"); - } - - long i = 0; - if (dimw_ == 3) { - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); - xyz_inout.data()[i++] = static_cast(xyz_local[0]); - xyz_inout[i++] = static_cast(xyz_local[1]); - xyz_inout[i++] = static_cast(xyz_local[2]); - } - } else if (dimw_ == 2) { - double td = 0.0; - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); - xyz_inout[i++] = static_cast(xyz_local[0]); - xyz_inout[i++] = static_cast(xyz_local[1]); - xyz_inout[i++] = static_cast(td); - } - } - return ((i) / 3); - } + long writeGridPoints_AOS(VectType& xyz_inout); /** Write the positions of vertices - directly to the pointers given in @@ -382,40 +216,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints_SOA(T* xyz_inout, long max_size = 0) - { - if (max_size < nvertices_ * 3) { - // assert(max_size >= nvertices_ * 3); - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeGridPoints_SOA( T& xyz_inout ) " + " Input objects max_size (" - + std::to_string(max_size) + ") is not sufficient to fit the nvertices_ * 3 values (" - + std::to_string(nvertices_ * 3) + ")"); - } - - long i = 0; - // Get offsets into structure - T* xyz_inout_y = xyz_inout + nvertices_; - T* xyz_inout_z = xyz_inout + (2 * nvertices_); - - if (dimw_ == 3) { - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); - xyz_inout[i] = static_cast(xyz_local[0]); - xyz_inout_y[i] = static_cast(xyz_local[1]); - xyz_inout_z[i] = static_cast(xyz_local[2]); - i++; - } - } else if (dimw_ == 2) { - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); - xyz_inout[i] = static_cast(xyz_local[0]); - xyz_inout_y[i] = static_cast(xyz_local[1]); - xyz_inout_z[i] = static_cast(0.0); - i++; - } - } - return (i); - } + long writeGridPoints_SOA(T* xyz_inout, long max_size = 0); /** Write the positions of vertices - directly to the pointers given in @@ -427,46 +228,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints_SOA(VectType& xyz_inout) - { - const std::size_t check_size = xyz_inout.size(); - - if (check_size < static_cast(nvertices_ * 3)) { - // assert(check_size >= nvertices_ * 3); - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeGridPoints_SOA( VectType& xyz_inout ) " - + " Input objects check_size (" + std::to_string(check_size) - + ") is not sufficient to fit the nvertices_ * 3 values (" + std::to_string(nvertices_ * 3) - + ")"); - } - - using VT = decltype(xyz_inout.data()[0]); - - long i = 0; - // Get offsets into structure - VT* xyz_inout_y = xyz_inout.data() + nvertices_; - VT* xyz_inout_z = xyz_inout.data() + (2 * nvertices_); - - if (dimw_ == 3) { - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); - xyz_inout.data()[i] = static_cast(xyz_local[0]); - xyz_inout_y[i] = static_cast(xyz_local[1]); - xyz_inout_z[i] = static_cast(xyz_local[2]); - i++; - } - } else if (dimw_ == 2) { - double td = 0.0; - for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { - auto xyz_local = vit.geometry().corner(0); - xyz_inout.data()[i] = static_cast(xyz_local[0]); - xyz_inout_y[i] = static_cast(xyz_local[1]); - xyz_inout_z[i] = static_cast(td); - i++; - } - } - return (i); - } + long writeGridPoints_SOA(VectType& xyz_inout); /** * Write the connectivity array - directly to the pointer given in parameter 1 @@ -480,42 +242,8 @@ public: Returns the number of corner indices written. */ template - long writeConnectivity(Integer* connectivity_inout, ConnectivityVertexOrder whichOrder, long max_size = 0) - { - if (max_size < ncorners_) { - - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeConnectivity( T* connectivity_inout,... ) " - + " Input max_size value (" + std::to_string(max_size) - + ") is not sufficient to fit the ncorners_ values (" + std::to_string(ncorners_) + ")"); - } - - long i = 0; - if (whichOrder == DUNE) { - // DUNE order - for (const auto& cit : elements(gridView_, dunePartition_)) { - auto cell_corners = cit.geometry().corners(); - for (auto vx = 0; vx < cell_corners; ++vx) { - const int vxIdx = gridView_.indexSet().subIndex(cit, vx, 3); - connectivity_inout[i + vx] = vxIdx; - } - i += cell_corners; - } - } else { - // VTK order - for (const auto& cit : elements(gridView_, dunePartition_)) { - auto cell_corners = cit.geometry().corners(); - for (auto vx = 0; vx < cell_corners; ++vx) { - const int vxIdx = gridView_.indexSet().subIndex(cit, vx, 3); - int vtkOrder; - vtkOrder = Dune::VTK::renumber(cit.type(), vx); - connectivity_inout[i + vtkOrder] = vxIdx; - } - i += cell_corners; - } - } - return (i); - } + long writeConnectivity(Integer* connectivity_inout, + ConnectivityVertexOrder whichOrder, long max_size = 0); /** * Write the connectivity array - directly to a VectType object given in parameter 1 @@ -530,46 +258,7 @@ public: Returns the number of corner indices written. */ template - long writeConnectivity(VectType& connectivity_inout, ConnectivityVertexOrder whichOrder) - { - const std::size_t check_size = connectivity_inout.size(); - - if (check_size < static_cast(ncorners_)) { - // assert(check_size >= ncorners_); - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeConnectivity( VectType& " - "connectivity_inout ) " - + " Input objects size (" + std::to_string(check_size) - + ") is not sufficient to fit the ncorners_ values (" + std::to_string(ncorners_) + ")"); - } - - long i = 0; - if (whichOrder == DUNE) { - // DUNE order - for (const auto& cit : elements(gridView_, dunePartition_)) { - auto cell_corners = cit.geometry().corners(); - for (auto vx = 0; vx < cell_corners; ++vx) { - const int vxIdx = gridView_.indexSet().subIndex(cit, vx, 3); - connectivity_inout.data()[i + vx] = vxIdx; - } - i += cell_corners; - } - } else { - // VTK order - for (const auto& cit : elements(gridView_, dunePartition_)) { - auto cell_corners = cit.geometry().corners(); - for (auto vx = 0; vx < cell_corners; ++vx) { - const int vxIdx = gridView_.indexSet().subIndex(cit, vx, 3); - int vtkOrder; - vtkOrder = Dune::VTK::renumber(cit.type(), vx); - connectivity_inout.data()[i + vtkOrder] = vxIdx; - } - i += cell_corners; - } - } - return (i); - } - + long writeConnectivity(VectType& connectivity_inout, ConnectivityVertexOrder whichOrder); /** * Write the offsets values - directly to the pointer given in parameter 1 @@ -583,24 +272,7 @@ public: Returns number of offset values written + 1 */ template - long writeOffsetsCells(Integer* offsets_inout, long max_size = 0) - { - if (max_size < ncells_) { - // assert(max_size >= ncells_); - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeOffsetsCells( T* offsets_inout ) " + " Input objects max_size (" - + std::to_string(max_size) + ") is not sufficient to fit the ncells_ values (" - + std::to_string(ncells_) + ")"); - } - long i = 1; - offsets_inout[0] = 0; - for (const auto& cit : elements(gridView_, dunePartition_)) { - auto cell_corners = cit.geometry().corners(); - offsets_inout[i] = offsets_inout[i - 1] + cell_corners; - i++; - } - return (i); // This should be 1 greater than ncells_ - } + long writeOffsetsCells(Integer* offsets_inout, long max_size = 0); /** * Write the offsets values - directly to a VectType object given in parameter 1 @@ -613,29 +285,7 @@ public: Returns number of offset values written + 1 */ template - long writeOffsetsCells(VectType& offsets_inout) - { - const std::size_t check_size = offsets_inout.size(); - if (check_size < static_cast(ncells_)) { - // assert(check_size >= ncells_); - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeOffsetsCells( VectType& " - "offsets_inout ) " - + " Input objects size (" + std::to_string(offsets_inout.size()) - + ") is not sufficient to fit the ncells_ values (" + std::to_string(ncells_) + ")"); - } - - // using VT = decltype(offsets_inout.data()[0]); - - long i = 1; - offsets_inout.data()[0] = 0; - for (const auto& cit : elements(gridView_, dunePartition_)) { - auto cell_corners = cit.geometry().corners(); - offsets_inout.data()[i] = offsets_inout.data()[i - 1] + cell_corners; - i++; - } - return (i); // This should be 1 greater than ncells_ - } + long writeOffsetsCells(VectType& offsets_inout); /** * Write the cell types values - directly to the pointer given in parameter 1 @@ -648,22 +298,7 @@ public: Returns number of cells type values written */ template - long writeCellTypes(Integer* types_inout, long max_size = 0) - { - if (max_size < ncells_) { - // assert(max_size >= ncells_); - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeCellTypes( T* types_inout ) " + " Input objects max_size (" - + std::to_string(max_size) + ") is not sufficient to fit the ncells_ values (" - + std::to_string(ncells_) + ")"); - } - int i = 0; - for (const auto& cit : elements(gridView_, dunePartition_)) { - Integer vtktype = static_cast(Dune::VTK::geometryType(cit.type())); - types_inout[i++] = vtktype; - } - return (i); - } + long writeCellTypes(Integer* types_inout, long max_size = 0); /** * Write the cell types values - directly to the VectType object given in parameter 1 @@ -674,59 +309,16 @@ public: Returns number of cells type values written */ template - long writeCellTypes(VectType& types_inout) - { - const std::size_t check_size = types_inout.size(); + long writeCellTypes(VectType& types_inout); - if (check_size < static_cast(ncells_)) { - OPM_THROW(std::runtime_error, - "Opm::GridDataOutput::writeCellTypes( VectType& types_inout ) " + " Input objects check_size (" - + std::to_string(check_size) + ") is not sufficient to fit the ncells_ values (" - + std::to_string(ncells_) + ")"); - } - - int i = 0; - for (const auto& cit : elements(gridView_, dunePartition_)) { - int vtktype = static_cast(Dune::VTK::geometryType(cit.type())); - types_inout.data()[i++] = vtktype; - } - return (i); - } - - std::string getPartitionTypeString() - { - if (this->dunePartition_ == Dune::Partitions::all) - return (std::string("Dune::Partitions::all")); - if (this->dunePartition_ == Dune::Partitions::interior) - return (std::string("Dune::Partitions::interior")); - if (this->dunePartition_ == Dune::Partitions::interiorBorder) - return (std::string("Dune::Partitions::interiorBorder")); - if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlap) - return (std::string("Dune::Partitions::interiorBorderOverlap")); - if (this->dunePartition_ == Dune::Partitions::front) - return (std::string("Dune::Partitions::front")); - if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlapFront) - return (std::string("Dune::Partitions::InteriorBorderOverlapFront")); - if (this->dunePartition_ == Dune::Partitions::border) - return (std::string("Dune::Partitions::border")); - if (this->dunePartition_ == Dune::Partitions::ghost) - return (std::string("Dune::Partitions::ghost")); - - return (std::string("Unknown Dune::PartitionSet<>")); - } + std::string getPartitionTypeString(); Dune::PartitionSet getPartition(void) { return (this->dunePartition_); } - void printGridDetails(std::ostream& outstr) - { - outstr << "Dune Partition = " << partition_value_ << ", " << getPartitionTypeString() << std::endl; - outstr << "ncells_: " << getNCells() << std::endl; - outstr << "nvertices_: " << getNVertices() << std::endl; - outstr << "ncorners_: " << getNCorners() << std::endl; - } + void printGridDetails(std::ostream& outstr); int getNCells() { diff --git a/opm/simulators/utils/GridDataOutput_impl.hpp b/opm/simulators/utils/GridDataOutput_impl.hpp new file mode 100644 index 000000000..0d7b5f954 --- /dev/null +++ b/opm/simulators/utils/GridDataOutput_impl.hpp @@ -0,0 +1,517 @@ +/* + Copyright 2023 Inria, Bretagne–Atlantique Research Center + + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ +#include + +#include +#include + +#include + +#include +#include +#include +#include + +namespace Opm::GridDataOutput { + +template +SimMeshDataAccessor:: + SimMeshDataAccessor(const GridView& gridView, Dune::PartitionSet dunePartition) + : gridView_(gridView) + , dunePartition_(dunePartition) +{ + dimw_ = GridView::dimension; // this is an enum + partition_value_ = dunePartition.value; + countEntities(); +} + +template +bool SimMeshDataAccessor::polyhedralCellPresent() +{ + for (const auto& cit : elements(gridView_, dunePartition_)) { + auto corner_geom = cit.geometry(); + if (Dune::VTK::geometryType(corner_geom.type()) == Dune::VTK::polyhedron) { + return true; + } + } + return false; +} + +template +void SimMeshDataAccessor::countEntities() +{ + // We include all the vertices for this ranks partition + const auto& vert_partition = vertices(gridView_, Dune::Partitions::all); + nvertices_ = std::distance(vert_partition.begin(), vert_partition.end()); + + const auto& cell_partition = elements(gridView_, dunePartition_); + ncells_ = 0; + ncorners_ = 0; + for (const auto& cit : cell_partition) { + auto corner_geom = cit.geometry(); + ncorners_ += corner_geom.corners(); + ++ncells_; + } +} + +template +template +long SimMeshDataAccessor:: +writeGridPoints(T* x_inout, T* y_inout, T* z_inout, long max_size) +{ + if (max_size < nvertices_) { + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeGridPoints( T& x_inout, T& " + "y_inout, T& z_inout ) " + + " Input objects max_size (" + std::to_string(max_size) + + ") is not sufficient to fit the nvertices_ values (" + std::to_string(nvertices_) + ")"); + } + + long i = 0; + if (dimw_ == 3) { + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); // vertices only have one corner + x_inout[i] = static_cast(xyz_local[0]); + y_inout[i] = static_cast(xyz_local[1]); + z_inout[i] = static_cast(xyz_local[2]); + i++; + } + } else if (dimw_ == 2) { + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); // vertices only have one corner + x_inout[i] = static_cast(xyz_local[0]); + y_inout[i] = static_cast(xyz_local[1]); + z_inout[i] = static_cast(0.0); + i++; + } + } + assert(i == nvertices_); // As we are templated on the + // Dune::PartitionSet, this cannot change + return i; +} + +template +template +long SimMeshDataAccessor:: +writeGridPoints(VectType& x_inout, VectType& y_inout, VectType& z_inout) +{ + const std::size_t check_size_x = x_inout.size(); + const std::size_t check_size_y = y_inout.size(); + const std::size_t check_size_z = z_inout.size(); + + using VT = decltype(x_inout.data()[0]); + + if ((check_size_x < static_cast(nvertices_)) || + (check_size_y < static_cast(nvertices_)) || + (check_size_z < static_cast(nvertices_))) { + // assert(check_size >= nvertices_); + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeGridPoints( VectType& x_inout, VectType& " + "y_inout, VectType& z_inout ) At least one of the inputs" + + " object x size " + std::to_string(check_size_x) + " object y size " + + std::to_string(check_size_y) + " object z size " + std::to_string(check_size_z) + + " is not sufficient to fit the nvertices_ values( " + std::to_string(nvertices_) + " )"); + } + + long i = 0; + if (dimw_ == 3) { + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); // vertices only have one corner + x_inout.data()[i] = static_cast(xyz_local[0]); + y_inout.data()[i] = static_cast(xyz_local[1]); + z_inout.data()[i] = static_cast(xyz_local[2]); + i++; + } + } else if (dimw_ == 2) { + double td = 0.0; + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); // vertices only have one corner + x_inout.data()[i] = static_cast(xyz_local[0]); + y_inout.data()[i] = static_cast(xyz_local[1]); + z_inout.data()[i] = static_cast(td); + i++; + } + } + assert(i == nvertices_); // As we are templated on the + // Dune::PartitionSet, this cannot change + return i; +} + +template +template +long SimMeshDataAccessor:: +writeGridPoints_AOS(T* xyz_inout, long max_size) +{ + if (max_size < nvertices_ * 3) { + assert(max_size >= nvertices_ * 3); + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeGridPoints_AOS( T* xyz_inout ) " + " Input objects max_size (" + + std::to_string(max_size) + ") is not sufficient to fit the nvertices_ * 3 values (" + + std::to_string(nvertices_ * 3) + ")"); + } + + long i = 0; + if (dimw_ == 3) { + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); + xyz_inout[i++] = static_cast(xyz_local[0]); + xyz_inout[i++] = static_cast(xyz_local[1]); + xyz_inout[i++] = static_cast(xyz_local[2]); + } + } else if (dimw_ == 2) { + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); + xyz_inout[i++] = static_cast(xyz_local[0]); + xyz_inout[i++] = static_cast(xyz_local[1]); + xyz_inout[i++] = static_cast(0.0); + } + } + return ((i) / 3); +} + +template +template +long SimMeshDataAccessor:: +writeGridPoints_AOS(VectType& xyz_inout) +{ + const std::size_t check_size = xyz_inout.size(); + + using VT = decltype(xyz_inout.data()[0]); + + if (check_size < static_cast(nvertices_ * 3)) { + assert(check_size >= nvertices_ * 3); + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeGridPoints_AOS( VectType& xyz_inout ) " + + " Input objects check_size (" + std::to_string(check_size) + + ") is not sufficient to fit the nvertices_ * 3 values (" + std::to_string(nvertices_ * 3) + + ")"); + } + + long i = 0; + if (dimw_ == 3) { + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); + xyz_inout.data()[i++] = static_cast(xyz_local[0]); + xyz_inout[i++] = static_cast(xyz_local[1]); + xyz_inout[i++] = static_cast(xyz_local[2]); + } + } else if (dimw_ == 2) { + double td = 0.0; + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); + xyz_inout[i++] = static_cast(xyz_local[0]); + xyz_inout[i++] = static_cast(xyz_local[1]); + xyz_inout[i++] = static_cast(td); + } + } + return ((i) / 3); +} + +template +template +long SimMeshDataAccessor:: +writeGridPoints_SOA(T* xyz_inout, long max_size) +{ + if (max_size < nvertices_ * 3) { + // assert(max_size >= nvertices_ * 3); + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeGridPoints_SOA( T& xyz_inout ) " + " Input objects max_size (" + + std::to_string(max_size) + ") is not sufficient to fit the nvertices_ * 3 values (" + + std::to_string(nvertices_ * 3) + ")"); + } + + long i = 0; + // Get offsets into structure + T* xyz_inout_y = xyz_inout + nvertices_; + T* xyz_inout_z = xyz_inout + (2 * nvertices_); + + if (dimw_ == 3) { + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); + xyz_inout[i] = static_cast(xyz_local[0]); + xyz_inout_y[i] = static_cast(xyz_local[1]); + xyz_inout_z[i] = static_cast(xyz_local[2]); + i++; + } + } else if (dimw_ == 2) { + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); + xyz_inout[i] = static_cast(xyz_local[0]); + xyz_inout_y[i] = static_cast(xyz_local[1]); + xyz_inout_z[i] = static_cast(0.0); + i++; + } + } + return (i); +} + +template +template +long SimMeshDataAccessor:: +writeGridPoints_SOA(VectType& xyz_inout) +{ + const std::size_t check_size = xyz_inout.size(); + + if (check_size < static_cast(nvertices_ * 3)) { + // assert(check_size >= nvertices_ * 3); + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeGridPoints_SOA( VectType& xyz_inout ) " + + " Input objects check_size (" + std::to_string(check_size) + + ") is not sufficient to fit the nvertices_ * 3 values (" + std::to_string(nvertices_ * 3) + + ")"); + } + + using VT = decltype(xyz_inout.data()[0]); + + long i = 0; + // Get offsets into structure + VT* xyz_inout_y = xyz_inout.data() + nvertices_; + VT* xyz_inout_z = xyz_inout.data() + (2 * nvertices_); + + if (dimw_ == 3) { + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); + xyz_inout.data()[i] = static_cast(xyz_local[0]); + xyz_inout_y[i] = static_cast(xyz_local[1]); + xyz_inout_z[i] = static_cast(xyz_local[2]); + i++; + } + } else if (dimw_ == 2) { + double td = 0.0; + for (const auto& vit : vertices(gridView_, Dune::Partitions::all)) { + auto xyz_local = vit.geometry().corner(0); + xyz_inout.data()[i] = static_cast(xyz_local[0]); + xyz_inout_y[i] = static_cast(xyz_local[1]); + xyz_inout_z[i] = static_cast(td); + i++; + } + } + return (i); +} + +template +template +long SimMeshDataAccessor:: +writeConnectivity(Integer* connectivity_inout, + ConnectivityVertexOrder whichOrder, long max_size) +{ + if (max_size < ncorners_) { + + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeConnectivity( T* connectivity_inout,... ) " + + " Input max_size value (" + std::to_string(max_size) + + ") is not sufficient to fit the ncorners_ values (" + std::to_string(ncorners_) + ")"); + } + + long i = 0; + if (whichOrder == DUNE) { + // DUNE order + for (const auto& cit : elements(gridView_, dunePartition_)) { + auto cell_corners = cit.geometry().corners(); + for (auto vx = 0; vx < cell_corners; ++vx) { + const int vxIdx = gridView_.indexSet().subIndex(cit, vx, 3); + connectivity_inout[i + vx] = vxIdx; + } + i += cell_corners; + } + } else { + // VTK order + for (const auto& cit : elements(gridView_, dunePartition_)) { + auto cell_corners = cit.geometry().corners(); + for (auto vx = 0; vx < cell_corners; ++vx) { + const int vxIdx = gridView_.indexSet().subIndex(cit, vx, 3); + int vtkOrder; + vtkOrder = Dune::VTK::renumber(cit.type(), vx); + connectivity_inout[i + vtkOrder] = vxIdx; + } + i += cell_corners; + } + } + return (i); +} + +template +template +long SimMeshDataAccessor:: +writeConnectivity(VectType& connectivity_inout, ConnectivityVertexOrder whichOrder) +{ + const std::size_t check_size = connectivity_inout.size(); + + if (check_size < static_cast(ncorners_)) { + // assert(check_size >= ncorners_); + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeConnectivity( VectType& " + "connectivity_inout ) " + + " Input objects size (" + std::to_string(check_size) + + ") is not sufficient to fit the ncorners_ values (" + std::to_string(ncorners_) + ")"); + } + + long i = 0; + if (whichOrder == DUNE) { + // DUNE order + for (const auto& cit : elements(gridView_, dunePartition_)) { + auto cell_corners = cit.geometry().corners(); + for (auto vx = 0; vx < cell_corners; ++vx) { + const int vxIdx = gridView_.indexSet().subIndex(cit, vx, 3); + connectivity_inout.data()[i + vx] = vxIdx; + } + i += cell_corners; + } + } else { + // VTK order + for (const auto& cit : elements(gridView_, dunePartition_)) { + auto cell_corners = cit.geometry().corners(); + for (auto vx = 0; vx < cell_corners; ++vx) { + const int vxIdx = gridView_.indexSet().subIndex(cit, vx, 3); + int vtkOrder; + vtkOrder = Dune::VTK::renumber(cit.type(), vx); + connectivity_inout.data()[i + vtkOrder] = vxIdx; + } + i += cell_corners; + } + } + return (i); +} + +template +template +long SimMeshDataAccessor:: +writeOffsetsCells(Integer* offsets_inout, long max_size) +{ + if (max_size < ncells_) { + // assert(max_size >= ncells_); + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeOffsetsCells( T* offsets_inout ) " + " Input objects max_size (" + + std::to_string(max_size) + ") is not sufficient to fit the ncells_ values (" + + std::to_string(ncells_) + ")"); + } + long i = 1; + offsets_inout[0] = 0; + for (const auto& cit : elements(gridView_, dunePartition_)) { + auto cell_corners = cit.geometry().corners(); + offsets_inout[i] = offsets_inout[i - 1] + cell_corners; + i++; + } + return (i); // This should be 1 greater than ncells_ +} + +template +template +long SimMeshDataAccessor:: +writeOffsetsCells(VectType& offsets_inout) +{ + const std::size_t check_size = offsets_inout.size(); + if (check_size < static_cast(ncells_)) { + // assert(check_size >= ncells_); + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeOffsetsCells( VectType& " + "offsets_inout ) " + + " Input objects size (" + std::to_string(offsets_inout.size()) + + ") is not sufficient to fit the ncells_ values (" + std::to_string(ncells_) + ")"); + } + + // using VT = decltype(offsets_inout.data()[0]); + + long i = 1; + offsets_inout.data()[0] = 0; + for (const auto& cit : elements(gridView_, dunePartition_)) { + auto cell_corners = cit.geometry().corners(); + offsets_inout.data()[i] = offsets_inout.data()[i - 1] + cell_corners; + i++; + } + return (i); // This should be 1 greater than ncells_ +} + +template +template +long SimMeshDataAccessor:: +writeCellTypes(Integer* types_inout, long max_size) +{ + if (max_size < ncells_) { + // assert(max_size >= ncells_); + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeCellTypes( T* types_inout ) " + " Input objects max_size (" + + std::to_string(max_size) + ") is not sufficient to fit the ncells_ values (" + + std::to_string(ncells_) + ")"); + } + int i = 0; + for (const auto& cit : elements(gridView_, dunePartition_)) { + Integer vtktype = static_cast(Dune::VTK::geometryType(cit.type())); + types_inout[i++] = vtktype; + } + return (i); +} + +template +template +long SimMeshDataAccessor:: +writeCellTypes(VectType& types_inout) +{ + const std::size_t check_size = types_inout.size(); + + if (check_size < static_cast(ncells_)) { + OPM_THROW(std::runtime_error, + "Opm::GridDataOutput::writeCellTypes( VectType& types_inout ) " + " Input objects check_size (" + + std::to_string(check_size) + ") is not sufficient to fit the ncells_ values (" + + std::to_string(ncells_) + ")"); + } + + int i = 0; + for (const auto& cit : elements(gridView_, dunePartition_)) { + int vtktype = static_cast(Dune::VTK::geometryType(cit.type())); + types_inout.data()[i++] = vtktype; + } + return (i); +} + +template +std::string SimMeshDataAccessor:: +getPartitionTypeString() +{ + if (this->dunePartition_ == Dune::Partitions::all) + return (std::string("Dune::Partitions::all")); + if (this->dunePartition_ == Dune::Partitions::interior) + return (std::string("Dune::Partitions::interior")); + if (this->dunePartition_ == Dune::Partitions::interiorBorder) + return (std::string("Dune::Partitions::interiorBorder")); + if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlap) + return (std::string("Dune::Partitions::interiorBorderOverlap")); + if (this->dunePartition_ == Dune::Partitions::front) + return (std::string("Dune::Partitions::front")); + if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlapFront) + return (std::string("Dune::Partitions::InteriorBorderOverlapFront")); + if (this->dunePartition_ == Dune::Partitions::border) + return (std::string("Dune::Partitions::border")); + if (this->dunePartition_ == Dune::Partitions::ghost) + return (std::string("Dune::Partitions::ghost")); + + return (std::string("Unknown Dune::PartitionSet<>")); +} + +template +void SimMeshDataAccessor:: +printGridDetails(std::ostream& outstr) +{ + outstr << "Dune Partition = " << partition_value_ << ", " << getPartitionTypeString() << std::endl; + outstr << "ncells_: " << getNCells() << std::endl; + outstr << "nvertices_: " << getNVertices() << std::endl; + outstr << "ncorners_: " << getNCorners() << std::endl; +} + +} // namespace Opm::GridDataOutput From 26d3802ea6e0a130b96ac3b4a288d0bb096e12c5 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 30 Jan 2024 11:27:57 +0100 Subject: [PATCH 2/5] GridDataOutput: remove parantheses in return statements --- opm/simulators/utils/GridDataOutput.hpp | 8 ++--- opm/simulators/utils/GridDataOutput_impl.hpp | 38 ++++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/opm/simulators/utils/GridDataOutput.hpp b/opm/simulators/utils/GridDataOutput.hpp index 7f0974f92..1f205780c 100644 --- a/opm/simulators/utils/GridDataOutput.hpp +++ b/opm/simulators/utils/GridDataOutput.hpp @@ -315,24 +315,24 @@ public: Dune::PartitionSet getPartition(void) { - return (this->dunePartition_); + return this->dunePartition_; } void printGridDetails(std::ostream& outstr); int getNCells() { - return (ncells_); + return ncells_; } int getNVertices() { - return (nvertices_); + return nvertices_; } int getNCorners() { - return (ncorners_); + return ncorners_; } std::string getError() diff --git a/opm/simulators/utils/GridDataOutput_impl.hpp b/opm/simulators/utils/GridDataOutput_impl.hpp index 0d7b5f954..b02c912d3 100644 --- a/opm/simulators/utils/GridDataOutput_impl.hpp +++ b/opm/simulators/utils/GridDataOutput_impl.hpp @@ -182,7 +182,7 @@ writeGridPoints_AOS(T* xyz_inout, long max_size) xyz_inout[i++] = static_cast(0.0); } } - return ((i) / 3); + return i / 3; } template @@ -220,7 +220,7 @@ writeGridPoints_AOS(VectType& xyz_inout) xyz_inout[i++] = static_cast(td); } } - return ((i) / 3); + return i / 3; } template @@ -258,7 +258,7 @@ writeGridPoints_SOA(T* xyz_inout, long max_size) i++; } } - return (i); + return i; } template @@ -302,7 +302,7 @@ writeGridPoints_SOA(VectType& xyz_inout) i++; } } - return (i); + return i; } template @@ -343,7 +343,7 @@ writeConnectivity(Integer* connectivity_inout, i += cell_corners; } } - return (i); + return i; } template @@ -386,7 +386,7 @@ writeConnectivity(VectType& connectivity_inout, ConnectivityVertexOrder whichOrd i += cell_corners; } } - return (i); + return i; } template @@ -408,7 +408,7 @@ writeOffsetsCells(Integer* offsets_inout, long max_size) offsets_inout[i] = offsets_inout[i - 1] + cell_corners; i++; } - return (i); // This should be 1 greater than ncells_ + return i; // This should be 1 greater than ncells_ } template @@ -435,7 +435,7 @@ writeOffsetsCells(VectType& offsets_inout) offsets_inout.data()[i] = offsets_inout.data()[i - 1] + cell_corners; i++; } - return (i); // This should be 1 greater than ncells_ + return i; // This should be 1 greater than ncells_ } template @@ -455,7 +455,7 @@ writeCellTypes(Integer* types_inout, long max_size) Integer vtktype = static_cast(Dune::VTK::geometryType(cit.type())); types_inout[i++] = vtktype; } - return (i); + return i; } template @@ -477,7 +477,7 @@ writeCellTypes(VectType& types_inout) int vtktype = static_cast(Dune::VTK::geometryType(cit.type())); types_inout.data()[i++] = vtktype; } - return (i); + return i; } template @@ -485,23 +485,23 @@ std::string SimMeshDataAccessor:: getPartitionTypeString() { if (this->dunePartition_ == Dune::Partitions::all) - return (std::string("Dune::Partitions::all")); + return std::string("Dune::Partitions::all"); if (this->dunePartition_ == Dune::Partitions::interior) - return (std::string("Dune::Partitions::interior")); + return std::string("Dune::Partitions::interior"); if (this->dunePartition_ == Dune::Partitions::interiorBorder) - return (std::string("Dune::Partitions::interiorBorder")); + return std::string("Dune::Partitions::interiorBorder"); if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlap) - return (std::string("Dune::Partitions::interiorBorderOverlap")); + return std::string("Dune::Partitions::interiorBorderOverlap"); if (this->dunePartition_ == Dune::Partitions::front) - return (std::string("Dune::Partitions::front")); + return std::string("Dune::Partitions::front"); if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlapFront) - return (std::string("Dune::Partitions::InteriorBorderOverlapFront")); + return std::string("Dune::Partitions::InteriorBorderOverlapFront"); if (this->dunePartition_ == Dune::Partitions::border) - return (std::string("Dune::Partitions::border")); + return std::string("Dune::Partitions::border"); if (this->dunePartition_ == Dune::Partitions::ghost) - return (std::string("Dune::Partitions::ghost")); + return std::string("Dune::Partitions::ghost"); - return (std::string("Unknown Dune::PartitionSet<>")); + return std::string("Unknown Dune::PartitionSet<>"); } template From 54c386ae2c6ab0a12a54ca1ec309c391eb410f18 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 30 Jan 2024 11:47:17 +0100 Subject: [PATCH 3/5] GridDataOutput: add const correctness --- opm/simulators/utils/GridDataOutput.cpp | 8 ++-- opm/simulators/utils/GridDataOutput.hpp | 41 ++++++++++---------- opm/simulators/utils/GridDataOutput_impl.hpp | 31 ++++++++------- 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/opm/simulators/utils/GridDataOutput.cpp b/opm/simulators/utils/GridDataOutput.cpp index 1d6eaca53..0b66606c3 100644 --- a/opm/simulators/utils/GridDataOutput.cpp +++ b/opm/simulators/utils/GridDataOutput.cpp @@ -36,13 +36,13 @@ template using DV = DamarisOutput::DamarisVar; #define INSTANCE(part, ...) \ template class SimMeshDataAccessor<__VA_ARGS__, part>; \ template long SimMeshDataAccessor<__VA_ARGS__,part>:: \ - writeGridPoints>(DV&, DV&, DV&); \ + writeGridPoints>(DV&, DV&, DV&) const; \ template long SimMeshDataAccessor<__VA_ARGS__,part>:: \ - writeConnectivity>(DV&, ConnectivityVertexOrder); \ + writeConnectivity>(DV&, ConnectivityVertexOrder) const; \ template long SimMeshDataAccessor<__VA_ARGS__,part>:: \ - writeOffsetsCells>(DV&); \ + writeOffsetsCells>(DV&) const; \ template long SimMeshDataAccessor<__VA_ARGS__,part>:: \ - writeCellTypes>(DV&); + writeCellTypes>(DV&) const; INSTANCE(1, Dune::GridView>) diff --git a/opm/simulators/utils/GridDataOutput.hpp b/opm/simulators/utils/GridDataOutput.hpp index 1f205780c..548163847 100644 --- a/opm/simulators/utils/GridDataOutput.hpp +++ b/opm/simulators/utils/GridDataOutput.hpp @@ -138,7 +138,7 @@ public: partition is not going to be available for visualisation as this class does not yet handle polyhedral cells. */ - bool polyhedralCellPresent(); + bool polyhedralCellPresent() const; /** Count the vertices, cells and corners. @@ -162,7 +162,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints(T* x_inout, T* y_inout, T* z_inout, long max_size = 0); + long writeGridPoints(T* x_inout, T* y_inout, T* z_inout, long max_size = 0) const; /** Write the positions of vertices - directly to the pointers given in @@ -178,7 +178,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints(VectType& x_inout, VectType& y_inout, VectType& z_inout); + long writeGridPoints(VectType& x_inout, VectType& y_inout, VectType& z_inout) const; /** Write the positions of vertices - directly to the pointers given in @@ -191,7 +191,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints_AOS(T* xyz_inout, long max_size = 0); + long writeGridPoints_AOS(T* xyz_inout, long max_size = 0) const; /** Write the positions of vertices - directly to the pointers given in @@ -203,7 +203,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints_AOS(VectType& xyz_inout); + long writeGridPoints_AOS(VectType& xyz_inout) const; /** Write the positions of vertices - directly to the pointers given in @@ -216,7 +216,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints_SOA(T* xyz_inout, long max_size = 0); + long writeGridPoints_SOA(T* xyz_inout, long max_size = 0) const; /** Write the positions of vertices - directly to the pointers given in @@ -228,7 +228,7 @@ public: Returns the number of vertices written */ template - long writeGridPoints_SOA(VectType& xyz_inout); + long writeGridPoints_SOA(VectType& xyz_inout) const; /** * Write the connectivity array - directly to the pointer given in parameter 1 @@ -243,7 +243,7 @@ public: */ template long writeConnectivity(Integer* connectivity_inout, - ConnectivityVertexOrder whichOrder, long max_size = 0); + ConnectivityVertexOrder whichOrder, long max_size = 0) const; /** * Write the connectivity array - directly to a VectType object given in parameter 1 @@ -258,7 +258,8 @@ public: Returns the number of corner indices written. */ template - long writeConnectivity(VectType& connectivity_inout, ConnectivityVertexOrder whichOrder); + long writeConnectivity(VectType& connectivity_inout, + ConnectivityVertexOrder whichOrder) const; /** * Write the offsets values - directly to the pointer given in parameter 1 @@ -272,7 +273,7 @@ public: Returns number of offset values written + 1 */ template - long writeOffsetsCells(Integer* offsets_inout, long max_size = 0); + long writeOffsetsCells(Integer* offsets_inout, long max_size = 0) const; /** * Write the offsets values - directly to a VectType object given in parameter 1 @@ -285,7 +286,7 @@ public: Returns number of offset values written + 1 */ template - long writeOffsetsCells(VectType& offsets_inout); + long writeOffsetsCells(VectType& offsets_inout) const; /** * Write the cell types values - directly to the pointer given in parameter 1 @@ -298,7 +299,7 @@ public: Returns number of cells type values written */ template - long writeCellTypes(Integer* types_inout, long max_size = 0); + long writeCellTypes(Integer* types_inout, long max_size = 0) const; /** * Write the cell types values - directly to the VectType object given in parameter 1 @@ -309,33 +310,33 @@ public: Returns number of cells type values written */ template - long writeCellTypes(VectType& types_inout); + long writeCellTypes(VectType& types_inout) const; - std::string getPartitionTypeString(); + std::string getPartitionTypeString() const; Dune::PartitionSet getPartition(void) { return this->dunePartition_; } - void printGridDetails(std::ostream& outstr); + void printGridDetails(std::ostream& outstr) const; - int getNCells() + int getNCells() const { return ncells_; } - int getNVertices() + int getNVertices() const { return nvertices_; } - int getNCorners() + int getNCorners() const { return ncorners_; } - std::string getError() + std::string getError() const { return error_strm_.str(); } @@ -345,7 +346,7 @@ public: error_strm_.str(""); } - bool hasError() + bool hasError() const { if (error_strm_.str().length() > 0) return true; diff --git a/opm/simulators/utils/GridDataOutput_impl.hpp b/opm/simulators/utils/GridDataOutput_impl.hpp index b02c912d3..8c211e621 100644 --- a/opm/simulators/utils/GridDataOutput_impl.hpp +++ b/opm/simulators/utils/GridDataOutput_impl.hpp @@ -42,7 +42,7 @@ SimMeshDataAccessor:: } template -bool SimMeshDataAccessor::polyhedralCellPresent() +bool SimMeshDataAccessor::polyhedralCellPresent() const { for (const auto& cit : elements(gridView_, dunePartition_)) { auto corner_geom = cit.geometry(); @@ -73,7 +73,7 @@ void SimMeshDataAccessor::countEntities() template template long SimMeshDataAccessor:: -writeGridPoints(T* x_inout, T* y_inout, T* z_inout, long max_size) +writeGridPoints(T* x_inout, T* y_inout, T* z_inout, long max_size) const { if (max_size < nvertices_) { OPM_THROW(std::runtime_error, @@ -109,7 +109,7 @@ writeGridPoints(T* x_inout, T* y_inout, T* z_inout, long max_size) template template long SimMeshDataAccessor:: -writeGridPoints(VectType& x_inout, VectType& y_inout, VectType& z_inout) +writeGridPoints(VectType& x_inout, VectType& y_inout, VectType& z_inout) const { const std::size_t check_size_x = x_inout.size(); const std::size_t check_size_y = y_inout.size(); @@ -156,7 +156,7 @@ writeGridPoints(VectType& x_inout, VectType& y_inout, VectType& z_inout) template template long SimMeshDataAccessor:: -writeGridPoints_AOS(T* xyz_inout, long max_size) +writeGridPoints_AOS(T* xyz_inout, long max_size) const { if (max_size < nvertices_ * 3) { assert(max_size >= nvertices_ * 3); @@ -188,7 +188,7 @@ writeGridPoints_AOS(T* xyz_inout, long max_size) template template long SimMeshDataAccessor:: -writeGridPoints_AOS(VectType& xyz_inout) +writeGridPoints_AOS(VectType& xyz_inout) const { const std::size_t check_size = xyz_inout.size(); @@ -226,7 +226,7 @@ writeGridPoints_AOS(VectType& xyz_inout) template template long SimMeshDataAccessor:: -writeGridPoints_SOA(T* xyz_inout, long max_size) +writeGridPoints_SOA(T* xyz_inout, long max_size) const { if (max_size < nvertices_ * 3) { // assert(max_size >= nvertices_ * 3); @@ -264,7 +264,7 @@ writeGridPoints_SOA(T* xyz_inout, long max_size) template template long SimMeshDataAccessor:: -writeGridPoints_SOA(VectType& xyz_inout) +writeGridPoints_SOA(VectType& xyz_inout) const { const std::size_t check_size = xyz_inout.size(); @@ -309,7 +309,7 @@ template template long SimMeshDataAccessor:: writeConnectivity(Integer* connectivity_inout, - ConnectivityVertexOrder whichOrder, long max_size) + ConnectivityVertexOrder whichOrder, long max_size) const { if (max_size < ncorners_) { @@ -349,7 +349,8 @@ writeConnectivity(Integer* connectivity_inout, template template long SimMeshDataAccessor:: -writeConnectivity(VectType& connectivity_inout, ConnectivityVertexOrder whichOrder) +writeConnectivity(VectType& connectivity_inout, + ConnectivityVertexOrder whichOrder) const { const std::size_t check_size = connectivity_inout.size(); @@ -392,7 +393,7 @@ writeConnectivity(VectType& connectivity_inout, ConnectivityVertexOrder whichOrd template template long SimMeshDataAccessor:: -writeOffsetsCells(Integer* offsets_inout, long max_size) +writeOffsetsCells(Integer* offsets_inout, long max_size) const { if (max_size < ncells_) { // assert(max_size >= ncells_); @@ -414,7 +415,7 @@ writeOffsetsCells(Integer* offsets_inout, long max_size) template template long SimMeshDataAccessor:: -writeOffsetsCells(VectType& offsets_inout) +writeOffsetsCells(VectType& offsets_inout) const { const std::size_t check_size = offsets_inout.size(); if (check_size < static_cast(ncells_)) { @@ -441,7 +442,7 @@ writeOffsetsCells(VectType& offsets_inout) template template long SimMeshDataAccessor:: -writeCellTypes(Integer* types_inout, long max_size) +writeCellTypes(Integer* types_inout, long max_size) const { if (max_size < ncells_) { // assert(max_size >= ncells_); @@ -461,7 +462,7 @@ writeCellTypes(Integer* types_inout, long max_size) template template long SimMeshDataAccessor:: -writeCellTypes(VectType& types_inout) +writeCellTypes(VectType& types_inout) const { const std::size_t check_size = types_inout.size(); @@ -482,7 +483,7 @@ writeCellTypes(VectType& types_inout) template std::string SimMeshDataAccessor:: -getPartitionTypeString() +getPartitionTypeString() const { if (this->dunePartition_ == Dune::Partitions::all) return std::string("Dune::Partitions::all"); @@ -506,7 +507,7 @@ getPartitionTypeString() template void SimMeshDataAccessor:: -printGridDetails(std::ostream& outstr) +printGridDetails(std::ostream& outstr) const { outstr << "Dune Partition = " << partition_value_ << ", " << getPartitionTypeString() << std::endl; outstr << "ncells_: " << getNCells() << std::endl; From a588d4196dc11f39f125e0713c04f416617a2be1 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 30 Jan 2024 11:52:22 +0100 Subject: [PATCH 4/5] GridDataOutput: avoid stringstream member --- opm/simulators/utils/GridDataOutput.hpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/opm/simulators/utils/GridDataOutput.hpp b/opm/simulators/utils/GridDataOutput.hpp index 548163847..c24c7f758 100644 --- a/opm/simulators/utils/GridDataOutput.hpp +++ b/opm/simulators/utils/GridDataOutput.hpp @@ -24,7 +24,8 @@ #include -#include +#include +#include /** @file @brief Allows model geometry data to be passed to external code - via a copy @@ -338,20 +339,17 @@ public: std::string getError() const { - return error_strm_.str(); + return error_; } void clearError() { - error_strm_.str(""); + error_.clear(); } bool hasError() const { - if (error_strm_.str().length() > 0) - return true; - else - return false; + return !error_.empty(); } protected: @@ -376,7 +374,7 @@ protected: int dimw_; // dimensions of the input grid private: - std::stringstream error_strm_; + std::string error_; }; } // namespace Opm::GridDataOutput From aa37225ad1e0d59963e034be213a2e35775d402d Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 30 Jan 2024 12:09:55 +0100 Subject: [PATCH 5/5] GridDataOutput: use implicit std::string constructor --- opm/simulators/utils/GridDataOutput_impl.hpp | 42 ++++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/opm/simulators/utils/GridDataOutput_impl.hpp b/opm/simulators/utils/GridDataOutput_impl.hpp index 8c211e621..3b4b62912 100644 --- a/opm/simulators/utils/GridDataOutput_impl.hpp +++ b/opm/simulators/utils/GridDataOutput_impl.hpp @@ -485,24 +485,32 @@ template std::string SimMeshDataAccessor:: getPartitionTypeString() const { - if (this->dunePartition_ == Dune::Partitions::all) - return std::string("Dune::Partitions::all"); - if (this->dunePartition_ == Dune::Partitions::interior) - return std::string("Dune::Partitions::interior"); - if (this->dunePartition_ == Dune::Partitions::interiorBorder) - return std::string("Dune::Partitions::interiorBorder"); - if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlap) - return std::string("Dune::Partitions::interiorBorderOverlap"); - if (this->dunePartition_ == Dune::Partitions::front) - return std::string("Dune::Partitions::front"); - if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlapFront) - return std::string("Dune::Partitions::InteriorBorderOverlapFront"); - if (this->dunePartition_ == Dune::Partitions::border) - return std::string("Dune::Partitions::border"); - if (this->dunePartition_ == Dune::Partitions::ghost) - return std::string("Dune::Partitions::ghost"); + if (this->dunePartition_ == Dune::Partitions::all) { + return "Dune::Partitions::all"; + } + if (this->dunePartition_ == Dune::Partitions::interior) { + return "Dune::Partitions::interior"; + } + if (this->dunePartition_ == Dune::Partitions::interiorBorder) { + return "Dune::Partitions::interiorBorder"; + } + if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlap) { + return "Dune::Partitions::interiorBorderOverlap"; + } + if (this->dunePartition_ == Dune::Partitions::front) { + return "Dune::Partitions::front"; + } + if (this->dunePartition_ == Dune::Partitions::interiorBorderOverlapFront) { + return "Dune::Partitions::InteriorBorderOverlapFront"; + } + if (this->dunePartition_ == Dune::Partitions::border) { + return "Dune::Partitions::border"; + } + if (this->dunePartition_ == Dune::Partitions::ghost) { + return "Dune::Partitions::ghost"; + } - return std::string("Unknown Dune::PartitionSet<>"); + return "Unknown Dune::PartitionSet<>"; } template