diff --git a/Applications/Python/ogs.mesh/OGSMesh.cpp b/Applications/Python/ogs.mesh/OGSMesh.cpp index b8c3aba18d7a7c735dd33340e55786fb1edb0992..11096881a9c5fb649002a83f53c96353ba232d39 100644 --- a/Applications/Python/ogs.mesh/OGSMesh.cpp +++ b/Applications/Python/ogs.mesh/OGSMesh.cpp @@ -78,13 +78,14 @@ void OGSMesh::setPointDataArray(std::string const& name, { OGS_FATAL("Couldn't access cell/element property '{}'.", name); } - for (int i = 0; i < pv->getNumberOfTuples(); ++i) + if (pv->size() != values.size()) { - for (std::size_t k = 0; k < number_of_components; ++k) - { - pv->getComponent(i, k) = values[i * number_of_components + k]; - } + OGS_FATAL( + "OGSMesh::setPointDataArray: size mismatch: property vector has " + "size '{}', while the number of values is '{}'.", + pv->size(), values.size()); } + std::copy(values.begin(), values.end(), pv->data()); } std::vector<double> OGSMesh::getPointDataArray( @@ -104,18 +105,23 @@ std::vector<double> OGSMesh::getPointDataArray( } void OGSMesh::setCellDataArray(std::string const& name, - std::vector<double> const& values) + std::vector<double> const& values, + std::size_t const number_of_components) { auto* pv = MeshLib::getOrCreateMeshProperty<double>( - _mesh, name, MeshLib::MeshItemType::Cell, 1); + _mesh, name, MeshLib::MeshItemType::Cell, number_of_components); if (pv == nullptr) { OGS_FATAL("Couldn't access cell/element property '{}'.", name); } - for (int i = 0; i < pv->getNumberOfTuples(); ++i) + if (pv->size() != values.size()) { - pv->getComponent(i, 0) = values[i]; + OGS_FATAL( + "OGSMesh::setCellDataArray: size mismatch: property vector has " + "size '{}', while the number of values is '{}'.", + pv->size(), values.size()); } + std::copy(values.begin(), values.end(), pv->data()); } std::vector<double> OGSMesh::getCellDataArray( diff --git a/Applications/Python/ogs.mesh/OGSMesh.h b/Applications/Python/ogs.mesh/OGSMesh.h index 315c474bf6f8edf633cbe2a86bf8b5b2a0a4928f..ce17f92179dec6f241151ceab094fcc28f393e93 100644 --- a/Applications/Python/ogs.mesh/OGSMesh.h +++ b/Applications/Python/ogs.mesh/OGSMesh.h @@ -45,7 +45,8 @@ public: std::size_t const number_of_components = 1) const; std::pair<std::vector<int>, std::vector<int>> getCells() const; void setCellDataArray(std::string const& name, - std::vector<double> const& values); + std::vector<double> const& values, + std::size_t const number_of_components); std::vector<double> getCellDataArray( std::string const& name, std::size_t const number_of_components) const;