From 7992e1b6bf737430af8f917c8ae5b7e8a5d317a6 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 31 Aug 2023 14:03:30 -0500 Subject: [PATCH] Store constant AMR arrays with less memory The `AmrArrays` filter generates some cell fields that specify information about the hierarchy, which are constant across all cells in a partition. These were previously stored as an array with the same value throughout. Now, the field is stored as an `ArrayHandleConstant`, which does not require any real storage. Recent changes to VTK-m allow code to extract the array as a component efficiently without knowing the storage type. Fixes #794 --- docs/changelog/constant-amr-arrays.md | 8 ++++++++ vtkm/filter/multi_block/AmrArrays.cxx | 20 +++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 docs/changelog/constant-amr-arrays.md diff --git a/docs/changelog/constant-amr-arrays.md b/docs/changelog/constant-amr-arrays.md new file mode 100644 index 000000000..c2afda9df --- /dev/null +++ b/docs/changelog/constant-amr-arrays.md @@ -0,0 +1,8 @@ +# Store constant AMR arrays with less memory + +The `AmrArrays` filter generates some cell fields that specify information +about the hierarchy, which are constant across all cells in a partition. +These were previously stored as an array with the same value throughout. +Now, the field is stored as an `ArrayHandleConstant`, which does not +require any real storage. Recent changes to VTK-m allow code to extract the +array as a component efficiently without knowing the storage type. diff --git a/vtkm/filter/multi_block/AmrArrays.cxx b/vtkm/filter/multi_block/AmrArrays.cxx index ec2c49b40..6962e180e 100644 --- a/vtkm/filter/multi_block/AmrArrays.cxx +++ b/vtkm/filter/multi_block/AmrArrays.cxx @@ -274,21 +274,15 @@ void AmrArrays::GenerateIndexArrays() { vtkm::cont::DataSet partition = this->AmrDataSet.GetPartition(this->PartitionIds.at(l).at(b)); - vtkm::cont::ArrayHandle fieldAmrLevel; - vtkm::cont::ArrayCopy( - vtkm::cont::ArrayHandleConstant(l, partition.GetNumberOfCells()), fieldAmrLevel); - partition.AddCellField("vtkAmrLevel", fieldAmrLevel); + partition.AddCellField( + "vtkAmrLevel", vtkm::cont::ArrayHandleConstant(l, partition.GetNumberOfCells())); - vtkm::cont::ArrayHandle fieldBlockId; - vtkm::cont::ArrayCopy( - vtkm::cont::ArrayHandleConstant(b, partition.GetNumberOfCells()), fieldBlockId); - partition.AddCellField("vtkAmrIndex", fieldBlockId); + partition.AddCellField( + "vtkAmrIndex", vtkm::cont::ArrayHandleConstant(b, partition.GetNumberOfCells())); - vtkm::cont::ArrayHandle fieldPartitionIndex; - vtkm::cont::ArrayCopy(vtkm::cont::ArrayHandleConstant( - this->PartitionIds.at(l).at(b), partition.GetNumberOfCells()), - fieldPartitionIndex); - partition.AddCellField("vtkCompositeIndex", fieldPartitionIndex); + partition.AddCellField("vtkCompositeIndex", + vtkm::cont::ArrayHandleConstant( + this->PartitionIds.at(l).at(b), partition.GetNumberOfCells())); this->AmrDataSet.ReplacePartition(this->PartitionIds.at(l).at(b), partition); }