diff --git a/docs/changelog/ghost-cell-api.md b/docs/changelog/ghost-cell-api.md new file mode 100644 index 000000000..dbc937d10 --- /dev/null +++ b/docs/changelog/ghost-cell-api.md @@ -0,0 +1,5 @@ +# Change name of method to set the cell ghost levels in a DataSet + +Previously, the method was named `AddGhostCellField`. However, only one +ghost cell field can be marked at a time, so `SetGhostCellField` is more +appropriate. diff --git a/docs/changelog/ghost-cell-global-name.md b/docs/changelog/ghost-cell-global-name.md new file mode 100644 index 000000000..0dfbfc528 --- /dev/null +++ b/docs/changelog/ghost-cell-global-name.md @@ -0,0 +1,7 @@ +# Automatically make the fields with the global cell ghosts the cell ghosts + +Previously, if you added a cell field to a `DataSet` with a name that was +the same as that returned from `GetGlobalCellFieldName`, it was still only +recognized as a normal field. Now, that field is automatically recognized +as a the cell ghost levels (unless the global cell field name is changed or +a different field is explicitly set as the cell ghost levels). diff --git a/vtkm/cont/DataSet.cxx b/vtkm/cont/DataSet.cxx index 8e18a83fc..26ae43976 100644 --- a/vtkm/cont/DataSet.cxx +++ b/vtkm/cont/DataSet.cxx @@ -129,6 +129,35 @@ vtkm::Id DataSet::GetNumberOfPoints() const return 0; } +const std::string& DataSet::GetGhostCellFieldName() const +{ + if (this->GhostCellName) + { + return *this->GhostCellName; + } + else + { + return GetGlobalGhostCellFieldName(); + } +} + +bool DataSet::HasGhostCellField() const +{ + return this->HasCellField(this->GetGhostCellFieldName()); +} + +const vtkm::cont::Field& DataSet::GetGhostCellField() const +{ + if (this->HasGhostCellField()) + { + return this->GetCellField(this->GetGhostCellFieldName()); + } + else + { + throw vtkm::cont::ErrorBadValue("No Ghost Cell Field"); + } +} + void DataSet::AddCoordinateSystem(const vtkm::cont::CoordinateSystem& cs) { CheckFieldSize(this->CellSet, cs); @@ -141,6 +170,47 @@ void DataSet::SetCellSetImpl(const vtkm::cont::UnknownCellSet& cellSet) this->CellSet = cellSet; } +void DataSet::SetGhostCellFieldName(const std::string& name) +{ + this->GhostCellName.reset(new std::string(name)); +} + +void DataSet::SetGhostCellField(const std::string& name) +{ + if (this->HasCellField(name)) + { + this->SetGhostCellFieldName(name); + } + else + { + throw vtkm::cont::ErrorBadValue("No such cell field " + name); + } +} + +void DataSet::SetGhostCellField(const vtkm::cont::Field& field) +{ + if (field.GetAssociation() == vtkm::cont::Field::Association::Cells) + { + this->SetGhostCellField(field.GetName(), field.GetData()); + } + else + { + throw vtkm::cont::ErrorBadValue("A ghost cell field must be a cell field."); + } +} + +void DataSet::SetGhostCellField(const std::string& fieldName, + const vtkm::cont::UnknownArrayHandle& field) +{ + this->AddCellField(fieldName, field); + this->SetGhostCellField(fieldName); +} + +void DataSet::SetGhostCellField(const vtkm::cont::UnknownArrayHandle& field) +{ + this->SetGhostCellField(GetGlobalGhostCellFieldName(), field); +} + void DataSet::CopyStructure(const vtkm::cont::DataSet& source) { this->CoordSystems = source.CoordSystems; diff --git a/vtkm/cont/DataSet.h b/vtkm/cont/DataSet.h index 486194389..a23ae3381 100644 --- a/vtkm/cont/DataSet.h +++ b/vtkm/cont/DataSet.h @@ -77,30 +77,10 @@ public: } VTKM_CONT - bool HasGhostCellField() const - { - if (this->GhostCellName) - { - return this->HasCellField(*this->GhostCellName); - } - else - { - return false; - } - } + bool HasGhostCellField() const; VTKM_CONT - const std::string& GetGhostCellFieldName() const - { - if (this->HasGhostCellField()) - { - return *this->GhostCellName; - } - else - { - throw vtkm::cont::ErrorBadValue("No Ghost Cell Field Name"); - } - } + const std::string& GetGhostCellFieldName() const; VTKM_CONT bool HasPointField(const std::string& name) const @@ -156,21 +136,11 @@ public: } ///@} - /// Returns the first cell field that matches the provided name. + /// Returns the cell field that matches the ghost cell field name. /// Will throw an exception if no match is found ///@{ VTKM_CONT - const vtkm::cont::Field& GetGhostCellField() const - { - if (this->HasGhostCellField()) - { - return this->GetCellField(*(this->GhostCellName)); - } - else - { - throw vtkm::cont::ErrorBadValue("No Ghost Cell Field"); - } - } + const vtkm::cont::Field& GetGhostCellField() const; ///@} /// Returns the first point field that matches the provided name. @@ -223,24 +193,49 @@ public: this->AddField(make_FieldCell(fieldName, field)); } + /// \brief Sets the name of the field to use for cell ghost levels. + /// + /// This value can be set regardless of whether such a cell field actually exists. + VTKM_CONT void SetGhostCellFieldName(const std::string& name); + + /// \brief Sets the cell field of the given name as the cell ghost levels. + /// + /// If a cell field of the given name does not exist, an exception is thrown. + VTKM_CONT void SetGhostCellField(const std::string& name); + + ///@{ + /// \brief Sets the ghost cell levels. + /// + /// A field of the given name is added to the `DataSet`, and that field is set as the cell + /// ghost levels. + VTKM_CONT void SetGhostCellField(const vtkm::cont::Field& field); + VTKM_CONT void SetGhostCellField(const std::string& fieldName, + const vtkm::cont::UnknownArrayHandle& field); + ///@} + + /// \brief Sets the ghost cell levels to the given array. + /// + /// A field with the global ghost cell field name (see `GlobalGhostCellFieldName`) is added + /// to the `DataSet` and made to be the cell ghost levels. + VTKM_CONT void SetGhostCellField(const vtkm::cont::UnknownArrayHandle& field); + + VTKM_DEPRECATED(2.0, "Use SetGhostCellField.") VTKM_CONT void AddGhostCellField(const std::string& fieldName, const vtkm::cont::UnknownArrayHandle& field) { - this->GhostCellName.reset(new std::string(fieldName)); - this->AddField(make_FieldCell(fieldName, field)); + this->SetGhostCellField(fieldName, field); } + VTKM_DEPRECATED(2.0, "Use SetGhostCellField.") VTKM_CONT void AddGhostCellField(const vtkm::cont::UnknownArrayHandle& field) { - this->AddGhostCellField(GetGlobalGhostCellFieldName(), field); + this->SetGhostCellField(field); } + VTKM_DEPRECATED(2.0, "Use SetGhostCellField.") VTKM_CONT - void AddGhostCellField(const vtkm::cont::Field& field) - { - this->AddGhostCellField(field.GetName(), field.GetData()); - } + void AddGhostCellField(const vtkm::cont::Field& field) { this->SetGhostCellField(field); } template VTKM_CONT void AddCellField(const std::string& fieldName, diff --git a/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx b/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx index ef2936825..42ac24b7f 100644 --- a/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx +++ b/vtkm/filter/entity_extraction/testing/UnitTestGhostCellRemove.cxx @@ -97,11 +97,11 @@ vtkm::cont::DataSet MakeUniform(vtkm::Id numI, if (ghostName == "default") { - ds.AddGhostCellField(ghosts); + ds.SetGhostCellField(ghosts); } else { - ds.AddGhostCellField(ghostName, ghosts); + ds.SetGhostCellField(ghostName, ghosts); } return ds; } @@ -138,11 +138,11 @@ vtkm::cont::DataSet MakeRectilinear(vtkm::Id numI, if (ghostName == "default") { - ds.AddGhostCellField(ghosts); + ds.SetGhostCellField(ghosts); } else { - ds.AddGhostCellField(ghostName, ghosts); + ds.SetGhostCellField(ghostName, ghosts); } return ds; @@ -226,11 +226,11 @@ vtkm::cont::DataSet MakeExplicit(vtkm::Id numI, if (ghostName == "default") { - ds.AddGhostCellField(ghosts); + ds.SetGhostCellField(ghosts); } else { - ds.AddGhostCellField(ghostName, ghosts); + ds.SetGhostCellField(ghostName, ghosts); } return ds; diff --git a/vtkm/filter/flow/testing/UnitTestStreamlineFilter.cxx b/vtkm/filter/flow/testing/UnitTestStreamlineFilter.cxx index c138ddd7c..34116f632 100644 --- a/vtkm/filter/flow/testing/UnitTestStreamlineFilter.cxx +++ b/vtkm/filter/flow/testing/UnitTestStreamlineFilter.cxx @@ -195,7 +195,7 @@ void TestAMRStreamline(bool useSL) ghosts[idx] = vtkm::CellClassification::Normal; idx++; } - dsOuter.AddGhostCellField(vtkm::cont::make_ArrayHandle(ghosts, vtkm::CopyFlag::On)); + dsOuter.SetGhostCellField(vtkm::cont::make_ArrayHandle(ghosts, vtkm::CopyFlag::On)); //Create a partitioned dataset with 1 inner and 1 outer. vtkm::cont::PartitionedDataSet pds; diff --git a/vtkm/filter/flow/testing/UnitTestStreamlineFilterMPI.cxx b/vtkm/filter/flow/testing/UnitTestStreamlineFilterMPI.cxx index db3d2a89e..4f6aa647a 100644 --- a/vtkm/filter/flow/testing/UnitTestStreamlineFilterMPI.cxx +++ b/vtkm/filter/flow/testing/UnitTestStreamlineFilterMPI.cxx @@ -113,7 +113,7 @@ void TestAMRStreamline(FilterType fType, bool useThreaded) ghosts[idx] = vtkm::CellClassification::Normal; idx++; } - dsOuter.AddGhostCellField(vtkm::cont::make_ArrayHandle(ghosts, vtkm::CopyFlag::On)); + dsOuter.SetGhostCellField(vtkm::cont::make_ArrayHandle(ghosts, vtkm::CopyFlag::On)); //Create a partitioned dataset with 1 inner and 1 outer. vtkm::cont::PartitionedDataSet pds; diff --git a/vtkm/filter/mesh_info/GhostCellClassify.cxx b/vtkm/filter/mesh_info/GhostCellClassify.cxx index 366e1a063..d7f062f41 100644 --- a/vtkm/filter/mesh_info/GhostCellClassify.cxx +++ b/vtkm/filter/mesh_info/GhostCellClassify.cxx @@ -143,7 +143,7 @@ VTKM_CONT vtkm::cont::DataSet GhostCellClassify::DoExecute(const vtkm::cont::Dat } auto output = this->CreateResult(input); - output.AddGhostCellField(this->GhostCellName, ghosts); + output.SetGhostCellField(this->GhostCellName, ghosts); return output; } } diff --git a/vtkm/worklet/testing/GenerateTestDataSets.h b/vtkm/worklet/testing/GenerateTestDataSets.h index cbf13d69b..6ec53a9ec 100644 --- a/vtkm/worklet/testing/GenerateTestDataSets.h +++ b/vtkm/worklet/testing/GenerateTestDataSets.h @@ -193,7 +193,7 @@ inline vtkm::cont::DataSet CreateExplicitFromStructuredDataSet(const vtkm::Bound if (addGhost) { - output.AddGhostCellField(input.GetGhostCellField()); + output.SetGhostCellField(input.GetGhostCellField()); } return output;