Merge topic 'ghost-cell-api'

a58c2cdac Change how cell ghost levels are set

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2924
This commit is contained in:
Kenneth Moreland 2022-11-11 13:00:12 +00:00 committed by Kitware Robot
commit dbc2364e35
9 changed files with 128 additions and 51 deletions

@ -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.

@ -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).

@ -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;

@ -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 <typename T, typename Storage>
VTKM_CONT void AddCellField(const std::string& fieldName,

@ -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;

@ -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;

@ -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;

@ -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;
}
}

@ -193,7 +193,7 @@ inline vtkm::cont::DataSet CreateExplicitFromStructuredDataSet(const vtkm::Bound
if (addGhost)
{
output.AddGhostCellField(input.GetGhostCellField());
output.SetGhostCellField(input.GetGhostCellField());
}
return output;