-
Notifications
You must be signed in to change notification settings - Fork 18
Add interpolation to powder fill example #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function misses the copyright notice. Also, it seems the ability to interpolate would be helpful for other fields, not just density.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will add |
||
| namespace CabanaPD | ||
| { | ||
| template <typename ParticleType, typename NewParticleType> | ||
| void interpolate( const ParticleType& particles, | ||
| NewParticleType& new_particles ) | ||
| { | ||
| using memory_space = typename NewParticleType::memory_space; | ||
|
|
||
| // Interpolate to the background grid. | ||
| auto powder_positions = particles.sliceCurrentPosition(); | ||
| auto density = particles.sliceDensity(); | ||
| auto num_particles = particles.localOffset(); | ||
| auto scalar_p2g = Cabana::Grid::createScalarValueP2G( density, 0.125 ); | ||
| auto scalar_layout = Cabana::Grid::createArrayLayout( | ||
| new_particles.local_grid, 1, Cabana::Grid::Node() ); | ||
| auto scalar_grid_field = Cabana::Grid::createArray<double, memory_space>( | ||
| "scalar_grid_field", scalar_layout ); | ||
| auto scalar_halo = Cabana::Grid::createHalo( | ||
| Cabana::Grid::NodeHaloPattern<3>(), new_particles.halo_width, | ||
| *scalar_grid_field ); | ||
| Cabana::Grid::p2g( scalar_p2g, powder_positions, num_particles, | ||
| Cabana::Grid::Spline<0>(), *scalar_halo, | ||
| *scalar_grid_field ); | ||
| Cabana::Grid::Experimental::BovWriter::writeTimeStep( | ||
| "grid_density", 0, 0.0, *scalar_grid_field ); | ||
|
|
||
| // Now interpolate to what would be the consolidation particles. | ||
| auto consolidation_positions = new_particles.sliceCurrentPosition(); | ||
| auto consolidation_density = new_particles.sliceDensity(); | ||
| auto pd_num_particles = new_particles.localOffset(); | ||
| auto scalar_value_g2p = | ||
| Cabana::Grid::createScalarValueG2P( consolidation_density, 1.0 ); | ||
| Cabana::Grid::g2p( *scalar_grid_field, *scalar_halo, | ||
| consolidation_positions, pd_num_particles, | ||
| Cabana::Grid::Spline<0>(), scalar_value_g2p ); | ||
| } | ||
| } // namespace CabanaPD | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -479,7 +479,7 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension> | |
| v( pid, d ) = 0.0; | ||
| f( pid, d ) = 0.0; | ||
| } | ||
| type( pid ) = 0; | ||
| type( pid ) = 1; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why changing type from 0 to 1? Why rho = 1 below?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a temporary way to get this to work - I will change before we merge |
||
| nofail( pid ) = 0; | ||
| rho( pid ) = 1.0; | ||
| } ); | ||
|
|
@@ -735,14 +735,26 @@ class Particles<MemorySpace, PMB, TemperatureIndependent, BaseOutput, Dimension> | |
| [[maybe_unused]] const double output_time, | ||
| [[maybe_unused]] const bool use_reference, | ||
| [[maybe_unused]] OtherFields&&... other ) | ||
| { | ||
| output( "particles", output_step, output_time, use_reference, | ||
| other... ); | ||
| } | ||
|
|
||
| // TODO: enable ignoring frozen particles. | ||
| template <typename... OtherFields> | ||
| void output( [[maybe_unused]] const std::string name, | ||
| [[maybe_unused]] const int output_step, | ||
| [[maybe_unused]] const double output_time, | ||
| [[maybe_unused]] const bool use_reference, | ||
| [[maybe_unused]] OtherFields&&... other ) | ||
| { | ||
| _output_timer.start(); | ||
|
|
||
| #ifdef Cabana_ENABLE_HDF5 | ||
| Cabana::Experimental::HDF5ParticleOutput::writeTimeStep( | ||
| h5_config, "particles", MPI_COMM_WORLD, output_step, output_time, | ||
| h5_config, name, MPI_COMM_WORLD, output_step, output_time, | ||
| localOffset(), getPosition( use_reference ), sliceForce(), | ||
| sliceDisplacement(), sliceVelocity(), | ||
| sliceDisplacement(), sliceVelocity(), sliceDensity(), sliceType(), | ||
| std::forward<OtherFields>( other )... ); | ||
| #else | ||
| #ifdef Cabana_ENABLE_SILO | ||
|
|
@@ -880,6 +892,27 @@ class Particles<MemorySpace, LPS, TemperatureIndependent, BaseOutput, Dimension> | |
| _timer.stop(); | ||
| } | ||
|
|
||
| template <typename KeepType> | ||
| void remove( const int num_keep, const KeepType& keep ) | ||
| { | ||
| base_type::remove( num_keep, keep ); | ||
| _timer.start(); | ||
| Cabana::remove( typename base_type::execution_space(), num_keep, keep, | ||
| _aosoa_theta, base_type::numFrozen() ); | ||
| Cabana::remove( typename base_type::execution_space(), num_keep, keep, | ||
| _aosoa_m, base_type::numFrozen() ); | ||
| _timer.stop(); | ||
| } | ||
|
|
||
| template <typename... OtherFields> | ||
| void output( const std::string name, const int output_step, | ||
| const double output_time, const bool use_reference, | ||
| OtherFields&&... other ) | ||
| { | ||
| base_type::output( name, output_step, output_time, use_reference, | ||
| sliceWeightedVolume(), sliceDilatation(), | ||
| std::forward<OtherFields>( other )... ); | ||
| } | ||
| template <typename... OtherFields> | ||
| void output( const int output_step, const double output_time, | ||
| const bool use_reference, OtherFields&&... other ) | ||
|
|
@@ -998,6 +1031,25 @@ class Particles<MemorySpace, ModelType, TemperatureDependent, BaseOutput, | |
| _aosoa_temp.resize( base_type::referenceOffset() ); | ||
| } | ||
|
|
||
| template <typename KeepType> | ||
| void remove( const int num_keep, const KeepType& keep ) | ||
| { | ||
| base_type::remove( num_keep, keep ); | ||
| _timer.start(); | ||
| Cabana::remove( typename base_type::execution_space(), num_keep, keep, | ||
| _aosoa_temp, base_type::numFrozen() ); | ||
| _timer.stop(); | ||
| } | ||
|
|
||
| template <typename... OtherFields> | ||
| void output( const std::string name, const int output_step, | ||
| const double output_time, const bool use_reference, | ||
| OtherFields&&... other ) | ||
| { | ||
| base_type::output( name, output_step, output_time, use_reference, | ||
| sliceTemperature(), | ||
| std::forward<OtherFields>( other )... ); | ||
| } | ||
| template <typename... OtherFields> | ||
| void output( const int output_step, const double output_time, | ||
| const bool use_reference, OtherFields&&... other ) | ||
|
|
@@ -1020,6 +1072,7 @@ class Particles<MemorySpace, ModelType, TemperatureDependent, BaseOutput, | |
| } | ||
|
|
||
| aosoa_temp_type _aosoa_temp; | ||
| using base_type::_timer; | ||
| }; | ||
|
|
||
| template <class MemorySpace, class ThermalType, int Dimension> | ||
|
|
@@ -1091,6 +1144,16 @@ class Particles<MemorySpace, Contact, ThermalType, BaseOutput, Dimension> | |
| _aosoa_u_neigh.resize( base_type::localOffset() ); | ||
| } | ||
|
|
||
| template <typename KeepType> | ||
| void remove( const int num_keep, const KeepType& keep ) | ||
| { | ||
| base_type::remove( num_keep, keep ); | ||
| _timer.start(); | ||
| Cabana::remove( typename base_type::execution_space(), num_keep, keep, | ||
| _aosoa_u_neigh, base_type::numFrozen() ); | ||
| _timer.stop(); | ||
| } | ||
|
|
||
| void setMaxDisplacement( double new_max ) { _max_displacement = new_max; } | ||
| double getMaxDisplacement() const { return _max_displacement; } | ||
|
|
||
|
|
@@ -1110,6 +1173,7 @@ class Particles<MemorySpace, Contact, ThermalType, BaseOutput, Dimension> | |
| double _max_displacement; | ||
|
|
||
| aosoa_u_neigh_type _aosoa_u_neigh; | ||
| using base_type::_timer; | ||
| }; | ||
|
|
||
| template <class MemorySpace, class ModelType, class ThermalType, int Dimension> | ||
|
|
@@ -1209,6 +1273,26 @@ class Particles<MemorySpace, ModelType, ThermalType, EnergyOutput, Dimension> | |
| _aosoa_output.resize( base_type::localOffset() ); | ||
| } | ||
|
|
||
| template <typename KeepType> | ||
| void remove( const int num_keep, const KeepType& keep ) | ||
| { | ||
| base_type::remove( num_keep, keep ); | ||
| _timer.start(); | ||
| Cabana::remove( typename base_type::execution_space(), num_keep, keep, | ||
| _aosoa_output, base_type::numFrozen() ); | ||
| _timer.stop(); | ||
| } | ||
|
|
||
| template <typename... OtherFields> | ||
| void output( const std::string name, const int output_step, | ||
| const double output_time, const bool use_reference, | ||
| OtherFields&&... other ) | ||
| { | ||
| base_type::output( name, output_step, output_time, use_reference, | ||
| sliceStrainEnergy(), sliceDamage(), | ||
| std::forward<OtherFields>( other )... ); | ||
| } | ||
|
|
||
| template <typename... OtherFields> | ||
| void output( const int output_step, const double output_time, | ||
| const bool use_reference, OtherFields&&... other ) | ||
|
|
@@ -1233,6 +1317,7 @@ class Particles<MemorySpace, ModelType, ThermalType, EnergyOutput, Dimension> | |
| } | ||
|
|
||
| aosoa_output_type _aosoa_output; | ||
| using base_type::_timer; | ||
| }; | ||
|
|
||
| template <class MemorySpace, class ModelType, class ThermalType, int Dimension> | ||
|
|
@@ -1307,6 +1392,25 @@ class Particles<MemorySpace, ModelType, ThermalType, EnergyStressOutput, | |
| _aosoa_stress.resize( new_local + new_ghost ); | ||
| } | ||
|
|
||
| template <typename KeepType> | ||
| void remove( const int num_keep, const KeepType& keep ) | ||
| { | ||
| base_type::remove( num_keep, keep ); | ||
| _timer.start(); | ||
| Cabana::remove( typename base_type::execution_space(), num_keep, keep, | ||
| _aosoa_stress, base_type::numFrozen() ); | ||
| _timer.stop(); | ||
| } | ||
|
|
||
| template <typename... OtherFields> | ||
| void output( const std::string name, const int output_step, | ||
| const double output_time, const bool use_reference, | ||
| OtherFields&&... other ) | ||
| { | ||
| base_type::output( name, output_step, output_time, use_reference, | ||
| sliceStress(), | ||
| std::forward<OtherFields>( other )... ); | ||
| } | ||
| template <typename... OtherFields> | ||
| void output( const int output_step, const double output_time, | ||
| const bool use_reference, OtherFields&&... other ) | ||
|
|
@@ -1329,6 +1433,7 @@ class Particles<MemorySpace, ModelType, ThermalType, EnergyStressOutput, | |
| } | ||
|
|
||
| aosoa_stress_type _aosoa_stress; | ||
| using base_type::_timer; | ||
| }; | ||
|
|
||
| /****************************************************************************** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this example suppose to run the powder setting first and then interpolate the final density profile and output to a file? (just making sure I understand)
Also, any reason to choose a coarser grid of half the number of cells per dimension? Is this an arbitrary choice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you understand and yes that was an arbitrary choice