This repository was archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Streamlines from vtkm #197
Open
dpugmire
wants to merge
19
commits into
Alpine-DAV:develop
Choose a base branch
from
dpugmire:streamlines_from_vtkm
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
81a90a0
Add shell code for particle advection filter.
4132adf
Initial code for doing distributed memory streamlines.
2b47c43
support for parallel particle advection.
68f2030
Adding particle advection test, adding float64 data to test data set.
jameskress a3b4d3c
Merge branch 'develop' into particleAdd
dpugmire c3e1487
Merge pull request #2 from jameskress/particleAdd
dpugmire feffc73
Merge branch 'develop' of https://github.com/Alpine-DAV/vtk-h into de…
dpugmire 00d7f6f
Merge branch 'develop' of https://github.com/dpugmire/vtk-h into develop
dpugmire a37be9c
Merge branch 'develop' of https://github.com/Alpine-DAV/vtk-h into de…
dpugmire 4cfb998
Merge branch 'develop' of https://github.com/Alpine-DAV/vtk-h into de…
dpugmire cbe49ea
Merge branch 'develop' of https://github.com/Alpine-DAV/vtk-h into de…
dpugmire c273abb
Merge branch 'develop' of https://github.com/Alpine-DAV/vtk-h into de…
dpugmire 94b5a64
Merge branch 'develop' of https://github.com/Alpine-DAV/vtk-h into de…
dpugmire c66f7c7
Add streamline and particle advect filter.
dpugmire 69284ab
toss the vtkm_filters goulash
dpugmire 6abb50d
cleanup....
dpugmire c3c41b6
Setup communicator for vtkh / vtkm.
dpugmire 66b82d5
Add compile time errors re: mpi
dpugmire 7be4d43
Merge branch 'develop' of https://github.com/Alpine-DAV/vtk-h into st…
dpugmire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| //----------------------------------------------------------------------------- | ||
| /// | ||
| /// file: t_vtk-h_particle_advection_par.cpp | ||
| /// | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| #include <vtkh/vtkh.hpp> | ||
| #include <vtkh/DataSet.hpp> | ||
| #include <vtkh/filters/ParticleAdvection.hpp> | ||
| #include <vtkh/filters/Streamline.hpp> | ||
| #include <vtkm/io/writer/VTKDataSetWriter.h> | ||
| #include <vtkm/cont/DataSet.h> | ||
| #include <vtkm/cont/DataSetFieldAdd.h> | ||
| #include <vtkm/cont/CellSetSingleType.h> | ||
| #include "t_test_utils.hpp" | ||
| #include <iostream> | ||
| #include <mpi.h> | ||
|
|
||
| void checkValidity(vtkh::DataSet *data, const int maxSteps, bool isSL) | ||
| { | ||
| int numDomains = data->GetNumberOfDomains(); | ||
|
|
||
| //Check all domains | ||
| for(int i = 0; i < numDomains; i++) | ||
| { | ||
| auto currentDomain = data->GetDomain(i); | ||
| auto cs = currentDomain.GetCellSet(); | ||
| if (isSL) | ||
| { | ||
| auto cellSet = cs.Cast<vtkm::cont::CellSetExplicit<>>(); | ||
| //Ensure that streamlines took <= to the max number of steps | ||
| for(int j = 0; j < cellSet.GetNumberOfCells(); j++) | ||
| { | ||
| EXPECT_LE(cellSet.GetNumberOfPointsInCell(j), maxSteps); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (!cs.IsType<vtkm::cont::CellSetSingleType<>>()) | ||
| EXPECT_TRUE(false); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void writeDataSet(vtkh::DataSet *data, std::string fName, int rank) | ||
| { | ||
| int numDomains = data->GetNumberOfDomains(); | ||
| std::cerr << "num domains " << numDomains << std::endl; | ||
| for(int i = 0; i < numDomains; i++) | ||
| { | ||
| char fileNm[128]; | ||
| sprintf(fileNm, "%s.rank%d.domain%d.vtk", fName.c_str(), rank, i); | ||
| vtkm::io::writer::VTKDataSetWriter write(fileNm); | ||
| write.WriteDataSet(data->GetDomain(i)); | ||
| } | ||
| } | ||
|
|
||
| static inline vtkm::FloatDefault | ||
| rand01() | ||
| { | ||
| return (vtkm::FloatDefault)rand() / (RAND_MAX+1.0f); | ||
| } | ||
|
|
||
| static inline vtkm::FloatDefault | ||
| randRange(const vtkm::FloatDefault &a, const vtkm::FloatDefault &b) | ||
| { | ||
| return a + (b-a)*rand01(); | ||
| } | ||
|
|
||
| template <typename FilterType> | ||
| vtkh::DataSet * | ||
| RunFilter(vtkh::DataSet& input, | ||
| const std::string& fieldName, | ||
| const std::vector<vtkm::Particle>& seeds, | ||
| int maxAdvSteps, | ||
| double stepSize) | ||
| { | ||
| FilterType filter; | ||
|
|
||
| filter.SetInput(&input); | ||
| filter.SetField(fieldName); | ||
| filter.SetNumberOfSteps(maxAdvSteps); | ||
| filter.SetStepSize(stepSize); | ||
| filter.SetSeeds(seeds); | ||
| filter.Update(); | ||
|
|
||
| return filter.GetOutput(); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| TEST(vtkh_particle_advection, vtkh_serial_particle_advection) | ||
| { | ||
| MPI_Init(NULL, NULL); | ||
| int comm_size, rank; | ||
| MPI_Comm_size(MPI_COMM_WORLD, &comm_size); | ||
| MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
| vtkh::SetMPICommHandle(MPI_Comm_c2f(MPI_COMM_WORLD)); | ||
|
|
||
| std::cout << "Running parallel Particle Advection, vtkh - with " << comm_size << " ranks" << std::endl; | ||
|
|
||
| vtkh::DataSet data_set; | ||
| const int base_size = 32; | ||
| const int blocks_per_rank = 1; | ||
| const int maxAdvSteps = 1000; | ||
| const int num_blocks = comm_size * blocks_per_rank; | ||
|
|
||
| for(int i = 0; i < blocks_per_rank; ++i) | ||
| { | ||
| int domain_id = rank * blocks_per_rank + i; | ||
| data_set.AddDomain(CreateTestDataRectilinear(domain_id, num_blocks, base_size), domain_id); | ||
| } | ||
|
|
||
| std::vector<vtkm::Particle> seeds; | ||
|
|
||
| vtkm::Bounds bounds = data_set.GetGlobalBounds(); | ||
| std::cout<<"Bounds= "<<bounds<<std::endl; | ||
|
|
||
| for (int i = 0; i < 100; i++) | ||
| { | ||
| vtkm::Particle p; | ||
| p.Pos = vtkm::Vec3f(randRange(bounds.X.Min, bounds.X.Max), | ||
| randRange(bounds.Y.Min, bounds.Y.Max), | ||
| randRange(bounds.Z.Min, bounds.Z.Max)); | ||
| p.ID = static_cast<vtkm::Id>(i); | ||
|
|
||
| seeds.push_back(p); | ||
| } | ||
|
|
||
| vtkh::DataSet *outPA=NULL, *outSL=NULL; | ||
|
|
||
| outPA = RunFilter<vtkh::ParticleAdvection>(data_set, "vector_data_Float64", seeds, maxAdvSteps, 0.1); | ||
| outPA->PrintSummary(std::cout); | ||
| checkValidity(outPA, maxAdvSteps+1, false); | ||
|
|
||
| outSL = RunFilter<vtkh::Streamline>(data_set, "vector_data_Float64", seeds, maxAdvSteps, 0.1); | ||
| outSL->PrintSummary(std::cout); | ||
| checkValidity(outSL, maxAdvSteps+1, true); | ||
|
|
||
| writeDataSet(outSL, "advection_SeedsRandomWhole", rank); | ||
|
|
||
| MPI_Barrier(MPI_COMM_WORLD); | ||
| MPI_Finalize(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #include <iostream> | ||
| #include <vtkh/filters/ParticleAdvection.hpp> | ||
| #include <vtkm/filter/ParticleAdvection.h> | ||
| #include <vtkh/vtkh.hpp> | ||
| #include <vtkh/Error.hpp> | ||
|
|
||
| namespace vtkh | ||
| { | ||
|
|
||
| ParticleAdvection::ParticleAdvection() | ||
| { | ||
| } | ||
|
|
||
| ParticleAdvection::~ParticleAdvection() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| void ParticleAdvection::PreExecute() | ||
| { | ||
| Filter::PreExecute(); | ||
| Filter::CheckForRequiredField(m_field_name); | ||
| } | ||
|
|
||
| void ParticleAdvection::PostExecute() | ||
| { | ||
| Filter::PostExecute(); | ||
| } | ||
|
|
||
| void ParticleAdvection::DoExecute() | ||
| { | ||
| this->m_output = new DataSet(); | ||
|
|
||
| #ifndef VTKH_BYPASS_VTKM_BIH | ||
|
|
||
| #ifdef VTKH_PARALLEL | ||
| // Setup VTK-h and VTK-m comm. | ||
| MPI_Comm mpi_comm = MPI_Comm_f2c(vtkh::GetMPICommHandle()); | ||
| vtkm::cont::EnvironmentTracker::SetCommunicator(vtkmdiy::mpi::communicator(vtkmdiy::mpi::make_DIY_MPI_Comm(mpi_comm))); | ||
| #endif | ||
|
|
||
| const int num_domains = this->m_input->GetNumberOfDomains(); | ||
|
|
||
| vtkm::cont::PartitionedDataSet inputs; | ||
| for(int i = 0; i < num_domains; ++i) | ||
| { | ||
| vtkm::Id domain_id; | ||
| vtkm::cont::DataSet dom; | ||
| this->m_input->GetDomain(i, dom, domain_id); | ||
| if(dom.HasField(m_field_name)) | ||
| { | ||
| using vectorField_d = vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float64, 3>>; | ||
| using vectorField_f = vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32, 3>>; | ||
| auto field = dom.GetField(m_field_name).GetData(); | ||
| if(!field.IsType<vectorField_d>() && !field.IsType<vectorField_f>()) | ||
| { | ||
| throw Error("Vector field type does not match <vtkm::Vec<vtkm::Float32,3>> or <vtkm::Vec<vtkm::Float64,3>>"); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| throw Error("Domain does not contain specified vector field for ParticleAdvection analysis."); | ||
| } | ||
|
|
||
| inputs.AppendPartition(dom); | ||
| } | ||
|
|
||
| vtkm::filter::ParticleAdvection particleAdvectionFilter; | ||
| auto seedsAH = vtkm::cont::make_ArrayHandle(m_seeds, vtkm::CopyFlag::Off); | ||
|
|
||
| particleAdvectionFilter.SetStepSize(m_step_size); | ||
| particleAdvectionFilter.SetActiveField(m_field_name); | ||
| particleAdvectionFilter.SetSeeds(seedsAH); | ||
| particleAdvectionFilter.SetNumberOfSteps(m_num_steps); | ||
| auto out = particleAdvectionFilter.Execute(inputs); | ||
|
|
||
| for (vtkm::Id i = 0; i < out.GetNumberOfPartitions(); i++) | ||
| { | ||
| this->m_output->AddDomain(out.GetPartition(i), i); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| } // namespace vtkh | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #ifndef VTK_H_PARTICLE_ADVECTION_HPP | ||
| #define VTK_H_PARTICLE_ADVECTION_HPP | ||
|
|
||
| #include <vtkh/vtkh_exports.h> | ||
| #include <vtkh/vtkh.hpp> | ||
| #include <vtkh/filters/Filter.hpp> | ||
| #include <vtkh/DataSet.hpp> | ||
|
|
||
| #include <vtkm/Particle.h> | ||
|
|
||
| namespace vtkh | ||
| { | ||
|
|
||
| class VTKH_API ParticleAdvection : public Filter | ||
| { | ||
| public: | ||
| ParticleAdvection(); | ||
| virtual ~ParticleAdvection(); | ||
| std::string GetName() const override { return "vtkh::ParticleAdvection";} | ||
| void SetField(const std::string &field_name) { m_field_name = field_name; } | ||
| void SetStepSize(const double &step_size) { m_step_size = step_size; } | ||
| void SetSeeds(const std::vector<vtkm::Particle>& seeds) { m_seeds = seeds; } | ||
| void SetNumberOfSteps(int numSteps) { m_num_steps = numSteps; } | ||
|
|
||
| protected: | ||
| void PreExecute() override; | ||
| void PostExecute() override; | ||
| void DoExecute() override; | ||
|
|
||
| std::string m_field_name; | ||
| double m_step_size; | ||
| int m_num_steps; | ||
| std::vector<vtkm::Particle> m_seeds; | ||
| }; | ||
|
|
||
| } //namespace vtkh | ||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.