Skip to content
Open
14 changes: 14 additions & 0 deletions src/docs/sphinx/Actions/Examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,20 @@ YAML actions:

.. literalinclude:: examples/tout_sample_plane_000100.yaml

An example of using the sample filter to sample on a plane topology from the input dataset.
-------------------------------------------------------------------------------------------

YAML actions:

.. literalinclude:: examples/tout_sample_topology_plane_000100.yaml

An example of using the sample filter to sample on a sphere surface topology from the input dataset.
----------------------------------------------------------------------------------------------------

YAML actions:

.. literalinclude:: examples/tout_sample_topology_sphere_000100.yaml

An example of using the sample filter to sample a list of 3D points.
---------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#An example of using the sample filter to sample on a topology from the input dataset.

-
action: "add_pipelines"
pipelines:
pl1:
f1:
type: "sample"
params:
fields:
- "braid"
topology: "sample_plane"
invalid_value: -10.0
-
action: "add_extracts"
extracts:
e1:
pipeline: "pl1"
type: "relay"
params:
protocol: "hdf5"
path: "/usr/WS1/nicolem/sadbox/ascent/scripts/build_ascent/build/ascent-checkout/tests/_output/tout_sample_topology_plane"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#An example of using the sample filter to sample on a sphere surface topology from the input dataset.

-
action: "add_pipelines"
pipelines:
pl1:
f1:
type: "sample"
params:
fields:
- "braid"
topology: "sample_sphere"
invalid_value: -10.0
-
action: "add_extracts"
extracts:
e1:
pipeline: "pl1"
type: "relay"
params:
protocol: "hdf5"
path: "/usr/WS1/nicolem/sadbox/ascent/scripts/build_ascent/build/ascent-checkout/tests/_output/tout_sample_topology_sphere"
Original file line number Diff line number Diff line change
Expand Up @@ -3325,6 +3325,7 @@ VTKHSample::declare_interface(Node &i)

string_schema(param_schema["properties/field"]);
array_schema(param_schema["properties/fields"]);
string_schema(param_schema["properties/topology"]);
number_schema(param_schema["properties/invalid_value"]);

// --- Line ---
Expand Down Expand Up @@ -3447,8 +3448,75 @@ VTKHSample::execute()
vtkh::DataSet &data = collection->dataset_by_topology(topo_name);

vtkh::Sample sampler;
std::string output_topo_name = topo_name;

if(params().has_path("line"))
const bool has_topology = params().has_path("topology");
if(has_topology)
{
std::string sample_topo_name = params()["topology"].as_string();
if(!collection->has_topology(sample_topo_name))
{
ASCENT_ERROR("vtkh_sample topology '" << sample_topo_name
<< "' does not exist. Known topologies: "
<< detail::possible_topologies(collection));
}

std::shared_ptr<VTKHCollection> sample_collection;
#ifdef ASCENT_MPI_ENABLED
MPI_Comm mpi_comm = MPI_Comm_f2c(Workspace::default_mpi_comm());
int rank = 0;
MPI_Comm_rank(mpi_comm, &rank);

std::shared_ptr<conduit::Node> blueprint_data = data_object->as_low_order_bp();
conduit::Node sample_mesh;
if(rank == 0)
{
const std::vector<const Node *> domains = blueprint::mesh::domains(*blueprint_data);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


//make a conduit::Node sample mesh with input topo
for(size_t i = 0; i < domains.size(); ++i)
{
const conduit::Node &src_dom = *domains[i];
const std::string topo_path = "topologies/" + sample_topo_name;
if(src_dom.has_path(topo_path))
{
conduit::Node &dst_dom = sample_mesh.append();
if(src_dom.has_path("state"))
{
dst_dom["state"].set(src_dom["state"]);
}

dst_dom[topo_path].set(src_dom[topo_path]);
const std::string coordset_name = src_dom[topo_path + "/coordset"].as_string();
dst_dom["coordsets/" + coordset_name].set(src_dom["coordsets/" + coordset_name]);
}
}

if(sample_mesh.number_of_children() == 0)
{
ASCENT_ERROR("vtkh_sample topology '" << sample_topo_name
<< "' must be present on rank 0 for MPI topology sampling");
}
}
//broadcast created sample node and convert back to vtkh
conduit::relay::mpi::broadcast_using_schema(sample_mesh, 0, mpi_comm);
sample_collection.reset(VTKHDataAdapter::BlueprintToVTKHCollection(sample_mesh,
false));
#else
sample_collection = collection;
#endif

vtkh::DataSet &sample_data = sample_collection->dataset_by_topology(sample_topo_name);
std::vector<viskores::cont::DataSet> sample_domains;
std::vector<viskores::Id> sample_domain_ids = sample_data.GetDomainIds();
for(size_t i = 0; i < sample_domain_ids.size(); ++i)
{
sample_domains.push_back(sample_data.GetDomainById(sample_domain_ids[i]));
}
sampler.Topology(sample_domains, sample_domain_ids);
output_topo_name = sample_topo_name;
}
else if(params().has_path("line"))
{
const Node &line_p = params()["line"];
int num_samples = line_p["num_samples"].to_int();
Expand Down Expand Up @@ -3782,7 +3850,7 @@ VTKHSample::execute()
vtkh::DataSet *grid_output = sampler.GetOutput();

VTKHCollection *new_coll = new VTKHCollection();
new_coll->add(*grid_output, topo_name);
new_coll->add(*grid_output, output_topo_name);
// re wrap in data object
DataObject *res = new DataObject(new_coll);
delete grid_output;
Expand Down
Loading
Loading