diff --git a/Applications/DataExplorer/DataView/ElementTreeModel.cpp b/Applications/DataExplorer/DataView/ElementTreeModel.cpp index 4580f83e2e4595943dc376bd55a7a8db9b68e52b..5e184e87993b13b10b3072ac2149ccaedef881d4 100644 --- a/Applications/DataExplorer/DataView/ElementTreeModel.cpp +++ b/Applications/DataExplorer/DataView/ElementTreeModel.cpp @@ -67,9 +67,12 @@ void ElementTreeModel::setElement(vtkUnstructuredGridAlgorithm const*const grid, TreeItem* typeItem = new TreeItem(typeData, elemItem); elemItem->appendChild(typeItem); + MeshLib::PropertyVector<int> const*const mat_ids = + mesh->getProperties().existsPropertyVector<int>("MaterialIDs") + ? mesh->getProperties().getPropertyVector<int>("MaterialIDs") + : nullptr; + QString matIdString = !mat_ids ? QString("not defined") : QString::number((*mat_ids)[elem->getID()]); QList<QVariant> materialData; - auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs"); - QString matIdString = !materialIds ? QString("not defined") : QString::number((*materialIds)[elem->getID()]); materialData << "MaterialID: " << matIdString; TreeItem* matItem = new TreeItem(materialData, elemItem); elemItem->appendChild(matItem); diff --git a/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp b/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp index 39083a92677dbd36d640a4a3bdfdd1e4c39b6d95..043b6f31e8d90437504b81e0d1fdb71fd807362a 100644 --- a/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp +++ b/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp @@ -171,14 +171,14 @@ void MeshElementRemovalDialog::on_materialIDCheckBox_toggled(bool is_checked) materialListWidget->clear(); _matIDIndex = _currentIndex; auto mesh = _project.getMesh(meshNameComboBox->currentText().toStdString()); - auto const* const mat_ids = - mesh->getProperties().getPropertyVector<int>("MaterialIDs"); - if (!mat_ids) + if (!mesh->getProperties().existsPropertyVector<int>("MaterialIDs")) { INFO("Properties \"MaterialIDs\" not found in the mesh \"%s\".", mesh->getName().c_str()); return; } + auto const* const mat_ids = + mesh->getProperties().getPropertyVector<int>("MaterialIDs"); if (mat_ids->size() != mesh->getNumberOfElements()) { INFO( @@ -205,10 +205,10 @@ void MeshElementRemovalDialog::on_meshNameComboBox_currentIndexChanged(int idx) this->materialListWidget->clearSelection(); if (this->boundingBoxCheckBox->isChecked()) this->on_boundingBoxCheckBox_toggled(true); auto mesh = _project.getMesh(meshNameComboBox->currentText().toStdString()); - auto const* const materialIds = - mesh->getProperties().getPropertyVector<int>("MaterialIDs"); - if (materialIds) + if (mesh->getProperties().existsPropertyVector<int>("MaterialIDs")) { + auto const* const materialIds = + mesh->getProperties().getPropertyVector<int>("MaterialIDs"); if (materialIds->size() != mesh->getNumberOfElements()) { ERR ("Incorrect mesh structure: Number of Material IDs does not match number of mesh elements."); diff --git a/Applications/FileIO/SHPInterface.cpp b/Applications/FileIO/SHPInterface.cpp index 7c9377f8c19f7cb8345b22f47b23f61d0d8ddbbd..c1589b7f95d858e9160bf6d408ef7ba1baa37e16 100644 --- a/Applications/FileIO/SHPInterface.cpp +++ b/Applications/FileIO/SHPInterface.cpp @@ -237,10 +237,12 @@ bool SHPInterface::write2dMeshToSHP(const std::string &file_name, const MeshLib: { // write element ID and material group to DBF-file DBFWriteIntegerAttribute(hDBF, polygon_id, elem_id_field, i); - auto materialIds = mesh.getProperties().getPropertyVector<int>("MaterialIDs"); - if (materialIds) + if (mesh.getProperties().existsPropertyVector<int>("MaterialIDs")) + { + auto const* const materialIds = + mesh.getProperties().getPropertyVector<int>("MaterialIDs"); DBFWriteIntegerAttribute(hDBF, polygon_id, mat_field, (*materialIds)[i]); - + } unsigned nNodes (e->getNumberOfBaseNodes()); padfX = new double[nNodes+1]; padfY = new double[nNodes+1]; diff --git a/Applications/FileIO/TetGenInterface.cpp b/Applications/FileIO/TetGenInterface.cpp index 0508d87b4544f780c0d9cbd3d1876a106b3d312a..215a6f91b4853a8c53fe221fba6e2bf08d6c3486 100644 --- a/Applications/FileIO/TetGenInterface.cpp +++ b/Applications/FileIO/TetGenInterface.cpp @@ -614,14 +614,15 @@ void TetGenInterface::write2dElements(std::ofstream &out, out << nTotalTriangles << " 1\n"; const std::vector<MeshLib::Element*> &elements = mesh.getElements(); - auto const* const materialIds = - mesh.getProperties().getPropertyVector<int>("MaterialIDs"); + MeshLib::PropertyVector<int> const*const mat_ids = + mesh.getProperties().existsPropertyVector<int>("MaterialIDs") + ? mesh.getProperties().getPropertyVector<int>("MaterialIDs") + : nullptr; const std::size_t nElements (elements.size()); unsigned element_count(0); for (std::size_t i=0; i<nElements; ++i) { - std::string matId = - materialIds ? std::to_string((*materialIds)[i]) : ""; + std::string const matId = mat_ids ? std::to_string((*mat_ids)[i]) : ""; this->writeElementToFacets(out, *elements[i], element_count, matId); } } diff --git a/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp b/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp index 0cfc5639a6286aad550408fd5a17d9da94b107ae..2153f4bec4c33de60b37839c3e463c144190c50c 100644 --- a/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp +++ b/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp @@ -51,12 +51,12 @@ int main (int argc, char* argv[]) INFO("Could not read mesh from file \"%s\".", mesh_arg.getValue().c_str()); return EXIT_FAILURE; } - auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs"); - if (!materialIds) + if (!mesh->getProperties().existsPropertyVector<int>("MaterialIDs")) { ERR("Mesh contains no int-property vector named \"MaterialIds\"."); return EXIT_FAILURE; } + auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs"); std::size_t const n_properties(materialIds->size()); if (n_properties != mesh->getNumberOfElements()) { diff --git a/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp b/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp index 9a0b181d4bafbf740bb63a12224d170e1c313ad4..68d9b2e949f38de46cdb3ca522cdcbf93846419d 100644 --- a/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp +++ b/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp @@ -79,12 +79,13 @@ template <typename PT> void resetMeshElementProperty(MeshLib::Mesh &mesh, GeoLib::Polygon const& polygon, std::string const& property_name, PT new_property_value) { - auto* const pv = mesh.getProperties().getPropertyVector<PT>(property_name); - if (!pv) { + if (!mesh.getProperties().existsPropertyVector<PT>(property_name)) + { WARN("Did not find a PropertyVector with name \"%s\".", property_name.c_str()); return; } + auto* const pv = mesh.getProperties().getPropertyVector<PT>(property_name); if (pv->getMeshItemType() != MeshLib::MeshItemType::Cell) { @@ -204,8 +205,12 @@ int main (int argc, char* argv[]) char new_property_val(char_property_arg.getValue()); // check if PropertyVector exists - auto* pv = mesh->getProperties().getPropertyVector<char>(property_name); - if (!pv) + MeshLib::PropertyVector<char>* pv(nullptr); + if (mesh->getProperties().existsPropertyVector<char>(property_name)) + { + pv = mesh->getProperties().getPropertyVector<char>(property_name); + } + else { pv = mesh->getProperties().createNewPropertyVector<char>( property_name, MeshLib::MeshItemType::Cell, 1); diff --git a/Applications/Utils/MeshEdit/queryMesh.cpp b/Applications/Utils/MeshEdit/queryMesh.cpp index 35cfb60ff6ec43cdff301a895e5493bb60cf75d9..f545d5f7761cd9f9d388dacc3115c074ef1f61d8 100644 --- a/Applications/Utils/MeshEdit/queryMesh.cpp +++ b/Applications/Utils/MeshEdit/queryMesh.cpp @@ -48,8 +48,6 @@ int main(int argc, char *argv[]) if (!mesh) return EXIT_FAILURE; - auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs"); - std::vector<std::size_t> selected_node_ids; if (showNodeWithMaxEle_arg.getValue()) { @@ -63,6 +61,10 @@ int main(int argc, char *argv[]) } selected_node_ids.insert(selected_node_ids.end(), nodeId_arg.getValue().begin(), nodeId_arg.getValue().end()); + MeshLib::PropertyVector<int> const*const materialIds = + mesh->getProperties().existsPropertyVector<int>("MaterialIDs") + ? mesh->getProperties().getPropertyVector<int>("MaterialIDs") + : nullptr; for (auto ele_id : eleId_arg.getValue()) { std::stringstream out; diff --git a/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp b/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp index dbfbd24a20446f1c04e7035a01465330872cec53..0fae44f72fa940f325348c9a0c44e7d944703b0f 100644 --- a/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp +++ b/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp @@ -82,12 +82,11 @@ int main (int argc, char* argv[]) surface_mesh->getNumberOfElements()); // ToDo check if mesh is read correct and if the mesh is a surface mesh + MeshLib::PropertyVector<std::size_t>* orig_node_ids(nullptr); // check if a node property containing the subsurface ids is available - auto* orig_node_ids = - surface_mesh->getProperties().getPropertyVector<std::size_t>( - id_prop_name.getValue()); // if the node property is not available generate it - if (!orig_node_ids) + if (!surface_mesh->getProperties().existsPropertyVector<std::size_t>( + id_prop_name.getValue())) { orig_node_ids = surface_mesh->getProperties().createNewPropertyVector<std::size_t>( @@ -100,6 +99,12 @@ int main (int argc, char* argv[]) orig_node_ids->resize(surface_mesh->getNumberOfNodes()); std::iota(orig_node_ids->begin(), orig_node_ids->end(), 0); } + else + { + orig_node_ids = + surface_mesh->getProperties().getPropertyVector<std::size_t>( + id_prop_name.getValue()); + } std::vector<double> areas( MeshLib::MeshSurfaceExtraction::getSurfaceAreaForNodes(*surface_mesh)); diff --git a/Applications/Utils/ModelPreparation/createNeumannBc.cpp b/Applications/Utils/ModelPreparation/createNeumannBc.cpp index 42fecaec905c9e539d9e5513b7990902f5a91e2e..fd6ea0a8856be607571320f5b4a7ca3f0cebdbbd 100644 --- a/Applications/Utils/ModelPreparation/createNeumannBc.cpp +++ b/Applications/Utils/ModelPreparation/createNeumannBc.cpp @@ -38,16 +38,15 @@ std::vector<double> getSurfaceIntegratedValuesForNodes( return std::vector<double>(); } - auto const* const elem_pv = - mesh.getProperties().getPropertyVector<double>(prop_name); - if (!elem_pv) + if (!mesh.getProperties().existsPropertyVector<double>(prop_name)) { ERR("Need element property, but the property \"%s\" is not " "available.", prop_name.c_str()); return std::vector<double>(); } - + auto const* const elem_pv = + mesh.getProperties().getPropertyVector<double>(prop_name); std::vector<double> integrated_node_area_vec; double total_area(0); diff --git a/MeshGeoToolsLib/AppendLinesAlongPolyline.cpp b/MeshGeoToolsLib/AppendLinesAlongPolyline.cpp index 1d4cdf9792a9bba63b4287da0c0524dc15999870..ec658fe74a54c77057a8826d8862912de16fe79a 100644 --- a/MeshGeoToolsLib/AppendLinesAlongPolyline.cpp +++ b/MeshGeoToolsLib/AppendLinesAlongPolyline.cpp @@ -34,11 +34,12 @@ std::unique_ptr<MeshLib::Mesh> appendLinesAlongPolylines( std::vector<int> new_mat_ids; { - auto mat_ids = mesh.getProperties().getPropertyVector<int>("MaterialIDs"); - if (mat_ids) { - new_mat_ids.reserve((*mat_ids).size()); - std::copy((*mat_ids).cbegin(), (*mat_ids).cend(), - std::back_inserter(new_mat_ids)); + if (mesh.getProperties().existsPropertyVector<int>("MaterialIDs")) { + auto ids = + mesh.getProperties().getPropertyVector<int>("MaterialIDs"); + new_mat_ids.reserve(ids->size()); + std::copy(ids->cbegin(), ids->cend(), + std::back_inserter(new_mat_ids)); } } int max_matID(0); diff --git a/MeshLib/ElementStatus.cpp b/MeshLib/ElementStatus.cpp index 17fa4542354bffbc7229eeb444dbd764c6dac2a2..3beef299edc1d78a7c40aa881ef6f1fb98768729 100644 --- a/MeshLib/ElementStatus.cpp +++ b/MeshLib/ElementStatus.cpp @@ -34,8 +34,10 @@ ElementStatus::ElementStatus(Mesh const* const mesh, std::vector<int> const& vec_inactive_matIDs) : ElementStatus(mesh, !vec_inactive_matIDs.empty()) { - auto materialIds = mesh->getProperties().getPropertyVector<int>("MaterialIDs"); - if (materialIds) { + if (mesh->getProperties().existsPropertyVector<int>("MaterialIDs")) + { + auto* const materialIds = + mesh->getProperties().getPropertyVector<int>("MaterialIDs"); for (auto material_id : vec_inactive_matIDs) { for (auto e : _mesh->getElements()) { if ((*materialIds)[e->getID()] == material_id) { diff --git a/MeshLib/IO/Legacy/MeshIO.cpp b/MeshLib/IO/Legacy/MeshIO.cpp index edbce896d2b72cb47ac37e5bed9691567a41bc7c..f68335d9133e11a661c431d12821b70f9bb6a82f 100644 --- a/MeshLib/IO/Legacy/MeshIO.cpp +++ b/MeshLib/IO/Legacy/MeshIO.cpp @@ -281,10 +281,16 @@ bool MeshIO::write() _out << "$ELEMENTS\n" << " "; - auto const* const materials = - _mesh->getProperties().getPropertyVector<int>("MaterialIDs"); - writeElements(_mesh->getElements(), materials, _out); - + if (!_mesh->getProperties().existsPropertyVector<int>("MaterialIDs")) + { + writeElements(_mesh->getElements(), nullptr, _out); + } + else + { + writeElements( + _mesh->getElements(), + _mesh->getProperties().getPropertyVector<int>("MaterialIDs"), _out); + } _out << "#STOP\n"; return true; diff --git a/MeshLib/Mesh.cpp b/MeshLib/Mesh.cpp index c811bc3ab9c0bf5b7a2cff5cbe7a00d7588c3ba8..a3a0b0e6420ad1f764d0b633afc4df1080c46a13 100644 --- a/MeshLib/Mesh.cpp +++ b/MeshLib/Mesh.cpp @@ -323,6 +323,12 @@ void scaleMeshPropertyVector(MeshLib::Mesh & mesh, std::string const& property_name, double factor) { + if (!mesh.getProperties().existsPropertyVector<double>(property_name)) + { + WARN("Did not find PropertyVector '%s' for scaling.", + property_name.c_str()); + return; + } for (auto& v : *mesh.getProperties().getPropertyVector<double>(property_name)) v *= factor; diff --git a/MeshLib/MeshEditing/AddLayerToMesh.cpp b/MeshLib/MeshEditing/AddLayerToMesh.cpp index c650d24c2116c3ec055c28dcc0613be4f11bc7dd..594c0e81d2147be8aa19c9cbfd66e5dbfaf8db16 100644 --- a/MeshLib/MeshEditing/AddLayerToMesh.cpp +++ b/MeshLib/MeshEditing/AddLayerToMesh.cpp @@ -131,16 +131,17 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness, std::vector<MeshLib::Node*> const& sfc_nodes(sfc_mesh->getNodes()); std::size_t const n_sfc_nodes(sfc_nodes.size()); - // fetch subsurface node ids PropertyVector - auto const* const node_id_pv = - sfc_mesh->getProperties().getPropertyVector<std::size_t>(prop_name); - if (!node_id_pv) { + if (!sfc_mesh->getProperties().existsPropertyVector<std::size_t>(prop_name)) + { ERR( "Need subsurface node ids, but the property \"%s\" is not " "available.", prop_name.c_str()); return nullptr; } + // fetch subsurface node ids PropertyVector + auto const* const node_id_pv = + sfc_mesh->getProperties().getPropertyVector<std::size_t>(prop_name); // *** copy sfc nodes to subsfc mesh node std::map<std::size_t, std::size_t> subsfc_sfc_id_map; @@ -162,14 +163,14 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness, auto new_mesh = new MeshLib::Mesh(name, subsfc_nodes, subsfc_elements); - auto const* const opt_materials = - mesh.getProperties().getPropertyVector<int>("MaterialIDs"); - if (!opt_materials) + if (!mesh.getProperties().existsPropertyVector<int>("MaterialIDs")) { ERR("Could not copy the property \"MaterialIDs\" since the original " "mesh does not contain such a property."); return new_mesh; } + auto const* const materials = + mesh.getProperties().getPropertyVector<int>("MaterialIDs"); auto* const new_materials = new_mesh->getProperties().createNewPropertyVector<int>( @@ -182,9 +183,8 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness, new_materials->reserve(subsfc_elements.size()); int new_layer_id( - *(std::max_element(opt_materials->cbegin(), opt_materials->cend())) + - 1); - std::copy(opt_materials->cbegin(), opt_materials->cend(), + *(std::max_element(materials->cbegin(), materials->cend())) + 1); + std::copy(materials->cbegin(), materials->cend(), std::back_inserter(*new_materials)); auto const n_new_props(subsfc_elements.size() - mesh.getNumberOfElements()); std::fill_n(std::back_inserter(*new_materials), n_new_props, new_layer_id); diff --git a/MeshLib/MeshEditing/ConvertToLinearMesh.cpp b/MeshLib/MeshEditing/ConvertToLinearMesh.cpp index 4be6af9a2af414bcbef10bada239447c76f93f3f..235b063cfba53cae3d936d26cf3032eb887231a8 100644 --- a/MeshLib/MeshEditing/ConvertToLinearMesh.cpp +++ b/MeshLib/MeshEditing/ConvertToLinearMesh.cpp @@ -74,9 +74,9 @@ std::unique_ptr<MeshLib::Mesh> convertToLinearMesh(MeshLib::Mesh const& org_mesh MeshLib::Properties const& src_properties = org_mesh.getProperties(); for (auto name : src_properties.getPropertyVectorNames()) { - auto const* src_prop = src_properties.getPropertyVector<double>(name); - if (!src_prop) + if (!src_properties.existsPropertyVector<double>(name)) continue; + auto const* src_prop = src_properties.getPropertyVector<double>(name); if (src_prop->getMeshItemType() != MeshLib::MeshItemType::Node) continue; diff --git a/MeshLib/MeshEditing/ElementValueModification.cpp b/MeshLib/MeshEditing/ElementValueModification.cpp index fc8bf6f65383e3ea0a3c8f0bc676ee02f2b783a5..8cdbbb71b3ab3392b971c487fcedfed18343ee6d 100644 --- a/MeshLib/MeshEditing/ElementValueModification.cpp +++ b/MeshLib/MeshEditing/ElementValueModification.cpp @@ -28,13 +28,12 @@ bool ElementValueModification::replace(MeshLib::Mesh &mesh, std::string const& property_name, int const old_value, int const new_value, bool replace_if_exists) { - auto* const property_value_vec = - mesh.getProperties().getPropertyVector<int>(property_name); - - if (!property_value_vec) + if (!mesh.getProperties().existsPropertyVector<int>(property_name)) { return false; } + auto* const property_value_vec = + mesh.getProperties().getPropertyVector<int>(property_name); const std::size_t n_property_tuples( property_value_vec->getNumberOfTuples()); diff --git a/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp b/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp index 41197cc4658f29920c268469c25f987edd4e8b0b..1736ad6159d1a1e87ba172d92803bcebb26ee5a9 100644 --- a/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp +++ b/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp @@ -51,9 +51,13 @@ bool Mesh2MeshPropertyInterpolation::setPropertiesForMesh(Mesh& dest_mesh) const return false; } - auto* dest_properties = - dest_mesh.getProperties().getPropertyVector<double>(_property_name); - if (!dest_properties) + MeshLib::PropertyVector<double>* dest_properties; + if (dest_mesh.getProperties().existsPropertyVector<double>(_property_name)) + { + dest_properties = + dest_mesh.getProperties().getPropertyVector<double>(_property_name); + } + else { INFO("Create new PropertyVector \"%s\" of type double.", _property_name.c_str()); @@ -140,14 +144,14 @@ void Mesh2MeshPropertyInterpolation::interpolateElementPropertiesToNodePropertie std::vector<double> &interpolated_properties) const { // fetch the source of property values - auto const* elem_props = - _src_mesh.getProperties().getPropertyVector<double>(_property_name); - if (!elem_props) + if (!_src_mesh.getProperties().existsPropertyVector<double>(_property_name)) { WARN("Did not find PropertyVector<double> \"%s\".", _property_name.c_str()); return; } + auto const* elem_props = + _src_mesh.getProperties().getPropertyVector<double>(_property_name); std::vector<MeshLib::Node*> const& src_nodes(_src_mesh.getNodes()); const std::size_t n_src_nodes(src_nodes.size()); diff --git a/MeshLib/MeshEditing/MeshRevision.cpp b/MeshLib/MeshEditing/MeshRevision.cpp index d322b4746d5d983e9e8b21454d1a7032cea2c27e..3d53c0df14483eae63db34c4af25a7da6d4bf798 100644 --- a/MeshLib/MeshEditing/MeshRevision.cpp +++ b/MeshLib/MeshEditing/MeshRevision.cpp @@ -63,15 +63,16 @@ MeshLib::Mesh* MeshRevision::simplifyMesh(const std::string &new_mesh_name, // original data std::vector<MeshLib::Element*> const& elements(this->_mesh.getElements()); MeshLib::Properties const& properties(_mesh.getProperties()); - auto const* const material_vec = - properties.getPropertyVector<int>("MaterialIDs"); // data structures for the new mesh std::vector<MeshLib::Node*> new_nodes = this->constructNewNodesArray(this->collapseNodeIndices(eps)); std::vector<MeshLib::Element*> new_elements; MeshLib::Properties new_properties; PropertyVector<int>* new_material_vec = nullptr; - if (material_vec) { + PropertyVector<int> const* material_vec = nullptr; + if (properties.existsPropertyVector<int>("MaterialIDs")) + { + material_vec = properties.getPropertyVector<int>("MaterialIDs"); new_material_vec = new_properties.createNewPropertyVector<int>( "MaterialIDs", MeshItemType::Cell, 1); } @@ -94,10 +95,10 @@ MeshLib::Mesh* MeshRevision::simplifyMesh(const std::string &new_mesh_name, this->cleanUp(new_nodes, new_elements); return nullptr; } - if (!material_vec) - continue; - new_material_vec->insert(new_material_vec->end(), - n_new_elements, (*material_vec)[k]); + if (material_vec) + new_material_vec->insert(new_material_vec->end(), + n_new_elements, + (*material_vec)[k]); } else { new_elements.push_back(MeshLib::copyElement(elem, new_nodes)); // copy material values diff --git a/MeshLib/MeshInformation.h b/MeshLib/MeshInformation.h index 867b4d9f2d561c88a897ca91d296f487f424efaf..659c97ba6723a3f5b7758f7545bc68971e7fb71c 100644 --- a/MeshLib/MeshInformation.h +++ b/MeshLib/MeshInformation.h @@ -37,10 +37,10 @@ public: static std::pair<T, T> const getValueBounds(MeshLib::Mesh const& mesh, std::string const& name) { + if (!mesh.getProperties().existsPropertyVector<T>(name)) + return {std::numeric_limits<T>::max(), std::numeric_limits<T>::max()}; auto const* const data_vec = mesh.getProperties().getPropertyVector<T>(name); - if (!data_vec) - return {std::numeric_limits<T>::max(), std::numeric_limits<T>::max()}; if (data_vec->empty()) { INFO("Mesh does not contain values for the property \"%s\".", name.c_str()); return {std::numeric_limits<T>::max(), std::numeric_limits<T>::max()}; diff --git a/MeshLib/MeshSearch/ElementSearch.h b/MeshLib/MeshSearch/ElementSearch.h index 80b48055953294422c76f06ea3e22f8e4d2b0341..d18d9f10d5a8bdc765457df3d4a58ee80c2149f8 100644 --- a/MeshLib/MeshSearch/ElementSearch.h +++ b/MeshLib/MeshSearch/ElementSearch.h @@ -47,14 +47,15 @@ public: PROPERTY_TYPE const property_value, std::string const& property_name = "MaterialIDs") { - auto const* const pv = - _mesh.getProperties().getPropertyVector<PROPERTY_TYPE>( - property_name); - if (!pv) + if (!_mesh.getProperties().existsPropertyVector<PROPERTY_TYPE>( + property_name)) { WARN("Property \"%s\" not found in mesh.", property_name.c_str()); return 0; } + auto const* const pv = + _mesh.getProperties().getPropertyVector<PROPERTY_TYPE>( + property_name); if (pv->getMeshItemType() != MeshLib::MeshItemType::Cell) { diff --git a/MeshLib/Vtk/VtkMappedMeshSource.h b/MeshLib/Vtk/VtkMappedMeshSource.h index b3ec4cfae488b072081658a066463ae2593906e0..43fc037a2f9467273542d4257b624e8708cc3d08 100644 --- a/MeshLib/Vtk/VtkMappedMeshSource.h +++ b/MeshLib/Vtk/VtkMappedMeshSource.h @@ -76,9 +76,9 @@ private: bool addProperty(MeshLib::Properties const& properties, std::string const& prop_name) const { - auto* const propertyVector = properties.getPropertyVector<T>(prop_name); - if(!propertyVector) + if (!properties.existsPropertyVector<T>(prop_name)) return false; + auto* const propertyVector = properties.getPropertyVector<T>(prop_name); vtkNew<VtkMappedPropertyVectorTemplate<T> > dataArray; dataArray->SetPropertyVector(const_cast<MeshLib::PropertyVector<T> &>(*propertyVector)); diff --git a/MeshLib/convertMeshToGeo.cpp b/MeshLib/convertMeshToGeo.cpp index 7d77314bfeda3a513157588eb0d881945c0f783e..7b1f2b2562b1376173f66d7bedbf61fc9299d0bd 100644 --- a/MeshLib/convertMeshToGeo.cpp +++ b/MeshLib/convertMeshToGeo.cpp @@ -63,7 +63,10 @@ bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects const std::vector<MeshLib::Element*> &elements = mesh.getElements(); const std::size_t nElems (mesh.getNumberOfElements()); - auto const materialIds = mesh.getProperties().getPropertyVector<int>(mat_name); + MeshLib::PropertyVector<int> const*const materialIds = + mesh.getProperties().existsPropertyVector<int>("MaterialIDs") + ? mesh.getProperties().getPropertyVector<int>("MaterialIDs") + : nullptr; for (unsigned i=0; i<nElems; ++i) { diff --git a/ProcessLib/HT/CreatePorousMediaProperties.cpp b/ProcessLib/HT/CreatePorousMediaProperties.cpp index d10e7392eb43dc901fa1f89ab653101ad2c80ee3..cc18b29f5ffaca25db30df23bbaab828bc36344d 100644 --- a/ProcessLib/HT/CreatePorousMediaProperties.cpp +++ b/ProcessLib/HT/CreatePorousMediaProperties.cpp @@ -72,10 +72,10 @@ PorousMediaProperties createPorousMediaProperties( BaseLib::reorderVector(storage_models, mat_ids); std::vector<int> material_ids(mesh.getNumberOfElements()); - auto const& mesh_material_ids = - mesh.getProperties().getPropertyVector<int>("MaterialIDs"); - if (mesh_material_ids) + if (mesh.getProperties().existsPropertyVector<int>("MaterialIDs")) { + auto const& mesh_material_ids = + mesh.getProperties().getPropertyVector<int>("MaterialIDs"); material_ids.reserve(mesh_material_ids->size()); std::copy(mesh_material_ids->cbegin(), mesh_material_ids->cend(), material_ids.begin()); diff --git a/ProcessLib/LIE/Common/PostUtils.cpp b/ProcessLib/LIE/Common/PostUtils.cpp index 9f320c54af5131fa63492323e8bdd915bbbbea4f..7e08cd88d57941115042f17b3b53c2b1572fdf98 100644 --- a/ProcessLib/LIE/Common/PostUtils.cpp +++ b/ProcessLib/LIE/Common/PostUtils.cpp @@ -121,9 +121,10 @@ void PostProcessTool::createProperties() MeshLib::Properties const& src_properties = _org_mesh.getProperties(); for (auto name : src_properties.getPropertyVectorNames()) { - auto const* src_prop = src_properties.getPropertyVector<T>(name); - if (!src_prop) + if (!src_properties.existsPropertyVector<T>(name)) continue; + auto const* src_prop = src_properties.getPropertyVector<T>(name); + auto const n_src_comp = src_prop->getNumberOfComponents(); // convert 2D vector to 3D. Otherwise Paraview Calculator filter does not recognize // it as a vector @@ -159,11 +160,10 @@ void PostProcessTool::copyProperties() MeshLib::Properties const& src_properties = _org_mesh.getProperties(); for (auto name : src_properties.getPropertyVectorNames()) { - auto const* src_prop = src_properties.getPropertyVector<T>(name); - if (!src_prop) + if (!src_properties.existsPropertyVector<T>(name)) continue; + auto const* src_prop = src_properties.getPropertyVector<T>(name); auto* dest_prop = _output_mesh->getProperties().getPropertyVector<T>(name); - assert(dest_prop); if (src_prop->getMeshItemType() == MeshLib::MeshItemType::Node) { diff --git a/ProcessLib/LiquidFlow/CreateLiquidFlowProcess.cpp b/ProcessLib/LiquidFlow/CreateLiquidFlowProcess.cpp index e81a4749bb6820f28e48b1fa6dadf8cb3da75ddd..1259fd9758491df54a628b9a015e07e361661176 100644 --- a/ProcessLib/LiquidFlow/CreateLiquidFlowProcess.cpp +++ b/ProcessLib/LiquidFlow/CreateLiquidFlowProcess.cpp @@ -78,12 +78,12 @@ std::unique_ptr<Process> createLiquidFlowProcess( //! \ogs_file_param{prj__processes__process__LIQUID_FLOW__material_property} auto const& mat_config = config.getConfigSubtree("material_property"); - auto const& mat_ids = - mesh.getProperties().getPropertyVector<int>("MaterialIDs"); - if (mat_ids) + if (mesh.getProperties().existsPropertyVector<int>("MaterialIDs")) { INFO("The liquid flow is in heterogeneous porous media."); const bool has_material_ids = true; + auto const& mat_ids = + mesh.getProperties().getPropertyVector<int>("MaterialIDs"); return std::unique_ptr<Process>{new LiquidFlowProcess{ mesh, std::move(jacobian_assembler), parameters, integration_order, std::move(process_variables), std::move(secondary_variables), diff --git a/ProcessLib/TwoPhaseFlowWithPP/CreateTwoPhaseFlowWithPPProcess.cpp b/ProcessLib/TwoPhaseFlowWithPP/CreateTwoPhaseFlowWithPPProcess.cpp index cfbf98b87305c52f2cefbf251be9eb72e446272e..460edafca73b46490d4048747991d0ed721be349 100644 --- a/ProcessLib/TwoPhaseFlowWithPP/CreateTwoPhaseFlowWithPPProcess.cpp +++ b/ProcessLib/TwoPhaseFlowWithPP/CreateTwoPhaseFlowWithPPProcess.cpp @@ -75,17 +75,16 @@ std::unique_ptr<Process> CreateTwoPhaseFlowWithPPProcess( //! \ogs_file_param{prj__processes__process__TWOPHASE_FLOW_PP__material_property} auto const& mat_config = config.getConfigSubtree("material_property"); - auto const& mat_ids = - mesh.getProperties().getPropertyVector<int>("MaterialIDs"); - std::unique_ptr< MaterialLib::TwoPhaseFlowWithPP::TwoPhaseFlowWithPPMaterialProperties> material = nullptr; - if (mat_ids) + if (mesh.getProperties().existsPropertyVector<int>("MaterialIDs")) { INFO("The twophase flow is in heterogeneous porous media."); const bool has_material_ids = true; + auto const& mat_ids = + mesh.getProperties().getPropertyVector<int>("MaterialIDs"); material = MaterialLib::TwoPhaseFlowWithPP:: CreateTwoPhaseFlowMaterialProperties(mat_config, has_material_ids, *mat_ids); diff --git a/ProcessLib/TwoPhaseFlowWithPrho/CreateTwoPhaseFlowWithPrhoProcess.cpp b/ProcessLib/TwoPhaseFlowWithPrho/CreateTwoPhaseFlowWithPrhoProcess.cpp index 81a42ce819d76a73460fd9f722f44e366e0b3141..62288cf12b38b1d9311a70e6e0688fcd048c077d 100644 --- a/ProcessLib/TwoPhaseFlowWithPrho/CreateTwoPhaseFlowWithPrhoProcess.cpp +++ b/ProcessLib/TwoPhaseFlowWithPrho/CreateTwoPhaseFlowWithPrhoProcess.cpp @@ -83,15 +83,12 @@ std::unique_ptr<Process> createTwoPhaseFlowWithPrhoProcess( //! \ogs_file_param{prj__processes__process__TWOPHASE_FLOW_PRHO__material_property} auto const& mat_config = config.getConfigSubtree("material_property"); - auto const& mat_ids = - mesh.getProperties().getPropertyVector<int>("MaterialIDs"); - - std::unique_ptr<TwoPhaseFlowWithPrhoMaterialProperties> material = nullptr; - boost::optional<MeshLib::PropertyVector<int> const&> material_ids; - if (mat_ids != nullptr) + if (mesh.getProperties().existsPropertyVector<int>("MaterialIDs")) { INFO("The twophase flow is in heterogeneous porous media."); + auto const& mat_ids = + mesh.getProperties().getPropertyVector<int>("MaterialIDs"); material_ids = *mat_ids; } else @@ -99,7 +96,7 @@ std::unique_ptr<Process> createTwoPhaseFlowWithPrhoProcess( INFO("The twophase flow is in homogeneous porous media."); } - material = + std::unique_ptr<TwoPhaseFlowWithPrhoMaterialProperties> material = createTwoPhaseFlowPrhoMaterialProperties(mat_config, material_ids); TwoPhaseFlowWithPrhoProcessData process_data{ diff --git a/Tests/MeshLib/MeshProperties.cpp b/Tests/MeshLib/MeshProperties.cpp index 14b24478a14569b90817b80de770cc0cc6c471eb..db3a116880e77d69b8ef488ec879f82d9c76d849 100644 --- a/Tests/MeshLib/MeshProperties.cpp +++ b/Tests/MeshLib/MeshProperties.cpp @@ -122,19 +122,15 @@ TEST_F(MeshLibProperties, AddDoubleProperties) ASSERT_EQ(static_cast<double>(k+1), (*double_properties)[k]); } + ASSERT_TRUE(mesh->getProperties().existsPropertyVector<double>(prop_name)); auto* const double_properties_cpy = mesh->getProperties().getPropertyVector<double>(prop_name); - ASSERT_FALSE(!double_properties_cpy); - for (std::size_t k(0); k<size; k++) { ASSERT_EQ((*double_properties)[k], (*double_properties_cpy)[k]); } mesh->getProperties().removePropertyVector(prop_name); - auto* const removed_double_properties = - mesh->getProperties().getPropertyVector<double>(prop_name); - - ASSERT_TRUE(!removed_double_properties); + ASSERT_FALSE(mesh->getProperties().existsPropertyVector<double>(prop_name)); } TEST_F(MeshLibProperties, AddDoublePointerProperties) @@ -204,10 +200,8 @@ TEST_F(MeshLibProperties, AddDoublePointerProperties) } mesh->getProperties().removePropertyVector(prop_name); - auto const* const removed_group_properties = - mesh->getProperties().getPropertyVector<double*>(prop_name); - - ASSERT_TRUE(!removed_group_properties); + ASSERT_FALSE( + mesh->getProperties().existsPropertyVector<double*>(prop_name)); } TEST_F(MeshLibProperties, AddArrayPointerProperties) @@ -285,11 +279,10 @@ TEST_F(MeshLibProperties, AddArrayPointerProperties) } mesh->getProperties().removePropertyVector(prop_name); - auto const* const removed_group_properties = - mesh->getProperties().getPropertyVector<std::array<double, 3>*>( + auto exists = + mesh->getProperties().existsPropertyVector<std::array<double, 3>*>( prop_name); - - ASSERT_TRUE(!removed_group_properties); + ASSERT_FALSE(exists); } TEST_F(MeshLibProperties, AddVariousDifferentProperties)