Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Roxana Bujack
VTK-m
Commits
2ca10ef4
Commit
2ca10ef4
authored
Sep 29, 2021
by
Roxana Bujack
Browse files
fix cast and call
parent
19727959
Changes
1
Hide whitespace changes
Inline
Side-by-side
vtkm/cont/MergePartitionedDataSet.cxx
View file @
2ca10ef4
...
...
@@ -14,6 +14,8 @@
#include
<vtkm/cont/DataSetBuilderExplicit.h>
#include
<vtkm/cont/PartitionedDataSet.h>
#include
<vtkm/cont/ArrayCopy.h>
#include
<vtkm/List.h>
#include
<vtkm/TypeList.h>
//#include <vtkm/filter/filter.h>
//#include <vtkm/filter/policyBase.h>
#include
<numeric>
// for std::accumulate
...
...
@@ -24,66 +26,47 @@ namespace cont
{
struct
Transfer
Array
Functor
struct
Transfer
Cells
Functor
{
TransferArrayFunctor
(
vtkm
::
cont
::
UnknownArrayHandle
&
outArray
,
unsigned
int
startIndex
)
:
StartIndex
(
startIndex
),
OutArray
(
outArray
)
{
}
template
<
typename
T
,
typename
S
>
VTKM_CONT
void
operator
()(
const
vtkm
::
cont
::
ArrayHandle
<
T
,
S
>&
inArray
)
const
template
<
typename
T
>
VTKM_CONT
void
operator
()(
const
T
&
cellSetIn
,
std
::
vector
<
vtkm
::
UInt8
>&
shapes
,
std
::
vector
<
vtkm
::
IdComponent
>&
numIndices
,
std
::
vector
<
vtkm
::
Id
>&
connectivity
,
vtkm
::
Id
startIndex
)
const
{
vtkm
::
cont
::
ArrayHandle
<
T
,
S
>
knownArray
=
OutArray
.
AsArrayHandle
<
vtkm
::
cont
::
ArrayHandle
<
T
,
S
>>
();
for
(
unsigned
int
i
=
0
;
i
<
inArray
.
GetNumberOfValues
();
i
++
)
for
(
unsigned
int
c
=
0
;
c
<
cellSetIn
.
GetNumberOfCells
();
c
++
)
{
knownArray
.
WritePortal
().
Set
(
this
->
StartIndex
+
i
,
inArray
.
ReadPortal
().
Get
(
i
));
shapes
.
push_back
(
cellSetIn
.
GetCellShape
(
c
));
numIndices
.
push_back
(
cellSetIn
.
GetNumberOfPointsInCell
(
c
));
vtkm
::
Id
pointIds
[
cellSetIn
.
GetNumberOfPointsInCell
(
c
)];
cellSetIn
.
GetCellPointIds
(
c
,
pointIds
);
for
(
int
i
=
0
;
i
<
cellSetIn
.
GetNumberOfPointsInCell
(
c
);
i
++
)
{
connectivity
.
push_back
(
startIndex
+
pointIds
[
i
]);
}
}
}
private:
unsigned
int
StartIndex
;
vtkm
::
cont
::
UnknownArrayHandle
&
OutArray
;
};
void
Transfer
Array
(
const
vtkm
::
cont
::
UnknownArrayHandle
&
inArray
,
vtkm
::
cont
::
UnknownArrayHandle
&
outArray
,
unsigned
int
startIndex
)
void
Transfer
Cells
(
const
vtkm
::
cont
::
DynamicCellSet
&
cellSetIn
,
std
::
vector
<
vtkm
::
UInt8
>&
shapes
,
std
::
vector
<
vtkm
::
IdComponent
>&
numIndices
,
std
::
vector
<
vtkm
::
Id
>&
connectivity
,
vtkm
::
Id
startIndex
)
{
inArray
.
CastAndCallForTypes
<
VTKM_DEFAULT_TYPE_LIST
,
VTKM_DEFAULT_STORAGE_LIST
>
(
TransferArrayFunctor
{
outArray
,
startIndex
});
// PrintArrayContents(outArray);
cellSetIn
.
CastAndCall
(
TransferCellsFunctor
{},
shapes
,
numIndices
,
connectivity
,
startIndex
);
}
struct
PrintArrayContents
Functor
struct
TransferArray
Functor
{
template
<
typename
T
,
typename
S
>
VTKM_CONT
void
operator
()(
const
vtkm
::
cont
::
ArrayHandle
<
T
,
S
>&
array
,
vtkm
::
cont
::
ArrayHandle
<
T
,
S
>&
arrayOut
,
double
variable
)
const
{
std
::
cout
<<
variable
<<
std
::
endl
;
this
->
PrintArrayPortal
(
array
.
ReadPortal
());
}
private:
template
<
typename
PortalType
>
VTKM_CONT
void
PrintArrayPortal
(
const
PortalType
&
portal
)
const
VTKM_CONT
void
operator
()(
const
vtkm
::
cont
::
ArrayHandle
<
T
,
S
>&
arrayIn
,
vtkm
::
cont
::
UnknownArrayHandle
&
arrayOut
,
vtkm
::
Id
startIndex
)
const
{
for
(
vtkm
::
I
d
in
dex
=
0
;
i
ndex
<
portal
.
GetNumberOfValues
();
i
ndex
++
)
for
(
unsigne
d
in
t
i
=
0
;
i
<
arrayIn
.
GetNumberOfValues
();
i
++
)
{
// All ArrayPortal objects have ValueType for the type of each value.
using
ValueType
=
typename
PortalType
::
ValueType
;
using
VTraits
=
vtkm
::
VecTraits
<
ValueType
>
;
ValueType
value
=
portal
.
Get
(
index
);
vtkm
::
IdComponent
numComponents
=
VTraits
::
GetNumberOfComponents
(
value
);
for
(
vtkm
::
IdComponent
componentIndex
=
0
;
componentIndex
<
numComponents
;
componentIndex
++
)
{
std
::
cout
<<
" "
<<
float
(
VTraits
::
GetComponent
(
value
,
componentIndex
));
}
std
::
cout
<<
std
::
endl
;
arrayOut
.
AsArrayHandle
<
vtkm
::
cont
::
ArrayHandle
<
T
,
S
>>
().
WritePortal
().
Set
(
startIndex
+
i
,
arrayIn
.
ReadPortal
().
Get
(
i
));
}
}
};
void
PrintArrayContents
(
const
vtkm
::
cont
::
UnknownArrayHandle
&
array
)
void
TransferArray
(
const
vtkm
::
cont
::
UnknownArrayHandle
&
arrayIn
,
vtkm
::
cont
::
UnknownArrayHandle
&
array
Out
,
vtkm
::
Id
startIndex
)
{
array
.
CastAndCallForTypes
<
VTKM_DEFAULT_TYPE_LIST
,
VTKM_DEFAULT_STORAGE_LIST
>
(
PrintArrayContentsFunctor
{},
array
,
0.0
);
arrayIn
.
CastAndCallForTypes
<
VTKM_DEFAULT_TYPE_LIST
,
StorageListBasic
>
(
TransferArrayFunctor
{},
arrayOut
,
startIndex
);
}
//-----------------------------------------------------------------------------
VTKM_CONT
vtkm
::
cont
::
DataSet
MergePartitionedDataSet
(
const
vtkm
::
cont
::
PartitionedDataSet
&
partitionedDataSet
)
...
...
@@ -105,114 +88,51 @@ vtkm::cont::DataSet MergePartitionedDataSet(const vtkm::cont::PartitionedDataSet
}
// Transfer cells
vtkm
::
cont
::
CellSetStructured
<
2
>
cellset
;
partition
.
GetCellSet
().
CopyTo
(
cellset
);
// vtkm::filter::PolicyBase<Policy> policy;
// vtkm::cont::DynamicCellSet cellset = partition.GetCellSet();
// auto cellset = vtkm::filter::ApplyPolicyCellSet(cellSet, Policy(), *this);
for
(
unsigned
int
c
=
0
;
c
<
cellset
.
GetNumberOfCells
();
c
++
)
{
shapes
.
push_back
(
cellset
.
GetCellShape
(
c
));
numIndices
.
push_back
(
cellset
.
GetNumberOfPointsInCell
(
c
));
vtkm
::
Id
pointIds
[
cellset
.
GetNumberOfPointsInCell
(
c
)];
cellset
.
GetCellPointIds
(
c
,
pointIds
);
for
(
int
i
=
0
;
i
<
cellset
.
GetNumberOfPointsInCell
(
c
);
i
++
)
{
connectivity
.
push_back
(
numberOfPointsSoFar
+
pointIds
[
i
]);
}
}
//
// // Transfer fields
// vtkm::cont::ArrayHandle<vtkm::UInt8> ghostArrayHandle;
// partition.GetField("vtkGhostType").GetData().AsArrayHandle(ghostArrayHandle);
// vtkm::cont::ArrayHandle<vtkm::FloatDefault> fieldArrayHandle;
// partition.GetField("scalarsCells").GetData().AsArrayHandle(fieldArrayHandle);
//
// for (unsigned int c = 0; c < cellset.GetNumberOfCells(); c++)
// {
// fieldOut.push_back(fieldArrayHandle.ReadPortal().Get(c));
// }
vtkm
::
cont
::
DynamicCellSet
cellset
;
cellset
=
partitionedDataSet
.
GetPartition
(
partitionId
).
GetCellSet
();
TransferCells
(
cellset
,
shapes
,
numIndices
,
connectivity
,
numberOfPointsSoFar
);
numberOfPointsSoFar
+=
partition
.
GetNumberOfPoints
();
}
vtkm
::
cont
::
DataSetBuilderExplicit
dataSetBuilder
;
vtkm
::
cont
::
DataSet
derivedDataSet
=
dataSetBuilder
.
Create
(
coordsOut
,
shapes
,
numIndices
,
connectivity
);
std
::
cout
<<
derivedDataSet
.
GetNumberOfCells
()
<<
std
::
endl
;
// derivedDataSet.SetCellSet(shapes);
// derivedDataSet.AddCellField("scalarsCells", fieldOut);
// derivedDataSet.PrintSummary(std::cout);
std
::
string
name
=
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
0
).
GetName
();
PrintArrayContents
(
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
name
).
GetData
());
std
::
cout
<<
name
<<
" "
<<
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
name
).
IsFieldCell
()
<<
std
::
endl
;
vtkm
::
cont
::
UnknownArrayHandle
outFieldHandle
;
vtkm
::
cont
::
ArrayCopy
(
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
name
).
GetData
()
,
outFieldHandle
);
PrintArrayContents
(
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
name
).
GetData
());
// Transfer fields
for
(
vtkm
::
IdComponent
f
=
0
;
f
<
partitionedDataSet
.
GetPartition
(
0
).
GetNumberOfFields
();
f
++
)
{
std
::
string
name
=
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
f
).
GetName
();
// std::cout << name << " " << partitionedDataSet.GetPartition(0).GetField(name).IsFieldCell() << std::endl;
vtkm
::
cont
::
UnknownArrayHandle
outFieldHandle
;
vtkm
::
cont
::
ArrayCopy
(
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
name
).
GetData
(),
outFieldHandle
);
// TransferArray(partitionedDataSet.GetPartition(0).GetField(name).GetData(), outFieldHandle, 0);
// // Transfer fields
// PrintArrayContents(partitionedDataSet.GetPartition(0).GetField("vtkGhostType").GetData());
//// PrintArrayContents(partitionedDataSet.GetPartition(0).GetField("scalarsCells").GetData());
//
// for (vtkm::IdComponent f = 0; f < partitionedDataSet.GetPartition(0).GetNumberOfFields(); f++)
// {
// std::string name = partitionedDataSet.GetPartition(0).GetField(f).GetName();
// std::cout << name << " " << partitionedDataSet.GetPartition(0).GetField(f).IsFieldCell() << std::endl;
//// partitionedDataSet.GetPartition(0).GetField(f).GetData().PrintSelf(cout);
//
// vtkm::cont::UnknownArrayHandle outFieldHandle;
// if (partitionedDataSet.GetPartition(0).GetField(f).IsFieldCell())
// {
// outFieldHandle.Allocate(derivedDataSet.GetNumberOfCells());
// unsigned int numberOfValuesSoFar = 0;
// for (unsigned int partitionId = 0; partitionId < partitionedDataSet.GetNumberOfPartitions(); partitionId++)
// {
// TransferArray(partitionedDataSet.GetPartition(partitionId).GetField(name).GetData(), outFieldHandle, numberOfValuesSoFar);
//// outFieldHandle.AsArrayHandle(partitionedDataSet.GetPartition(0).GetField(f).GetData()).WritePortal().Set(i, partitionedDataSet.GetPartition(0).GetField(f).GetData().ReadPortal().Get(i));
// numberOfValuesSoFar += partitionedDataSet.GetPartition(partitionId).GetNumberOfCells();
// }
// derivedDataSet.AddCellField(name, outFieldHandle);
// }
//
// if (partitionedDataSet.GetPartition(0).GetField(f).IsFieldCell())
// {
// outFieldHandle.Allocate(derivedDataSet.GetNumberOfCells());
// unsigned int numberOfValuesSoFar = 0;
// for (unsigned int partitionId = 0; partitionId < partitionedDataSet.GetNumberOfPartitions(); partitionId++)
// {
// auto partition = partitionedDataSet.GetPartition(partitionId);
// for (unsigned int v = 0; v < partition.GetNumberOfCells(); v++)
// {
// outFieldHandle.WritePortal.Set(numberOfValuesSoFar + v, partition.GetField(name).GetData());
// }
// numberOfValuesSoFar += partition.GetNumberOfCells();
// }
// derivedDataSet.AddCellField(name, outFieldHandle);
// }
// else if (partitionedDataSet.GetPartition(0).GetField(f).IsFieldPoint())
// {
// outFieldHandle.Allocate(derivedDataSet.GetNumberOfPoints());
// unsigned int numberOfValuesSoFar = 0;
// for (unsigned int partitionId = 0; partitionId < partitionedDataSet.GetNumberOfPartitions(); partitionId++)
// {
// auto partition = partitionedDataSet.GetPartition(partitionId);
// for (unsigned int v = 0; v < partition.GetNumberOfPoints(); v++)
// {
// outFieldHandle.WritePortal.Set(numberOfValuesSoFar + v, partition.GetField(name).GetData());
// }
// numberOfValuesSoFar += partition.GetNumberOfPoints();
// }
// derivedDataSet.AddPointField(name, outFieldHandle);
// }
// }
if
(
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
name
).
IsFieldCell
())
{
outFieldHandle
.
Allocate
(
derivedDataSet
.
GetNumberOfCells
());
}
else
if
(
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
name
).
IsFieldPoint
())
{
outFieldHandle
.
Allocate
(
derivedDataSet
.
GetNumberOfPoints
());
}
unsigned
int
numberOfValuesSoFar
=
0
;
for
(
unsigned
int
partitionId
=
0
;
partitionId
<
partitionedDataSet
.
GetNumberOfPartitions
();
partitionId
++
)
{
auto
field
=
partitionedDataSet
.
GetPartition
(
partitionId
).
GetField
(
name
).
GetData
();
TransferArray
(
field
,
outFieldHandle
,
numberOfValuesSoFar
);
numberOfValuesSoFar
+=
field
.
GetNumberOfValues
();
}
if
(
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
f
).
IsFieldCell
())
{
derivedDataSet
.
AddCellField
(
name
,
outFieldHandle
);
}
else
if
(
partitionedDataSet
.
GetPartition
(
0
).
GetField
(
f
).
IsFieldPoint
())
{
derivedDataSet
.
AddPointField
(
name
,
outFieldHandle
);
}
}
return
derivedDataSet
;
// return partitionedDataSet.GetPartition(0);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment