@@ -21,7 +21,7 @@ use crate::neighborhood_search::{
2121} ;
2222use crate :: uniform_grid:: { EdgeIndex , GridConstructionError , UniformCartesianCubeGrid3d } ;
2323use crate :: {
24- Aabb3d , MapType , Parameters , SpatialDecomposition , SurfaceReconstruction , new_map,
24+ Aabb3d , MapType , Parameters , RealConvert , SpatialDecomposition , SurfaceReconstruction , new_map,
2525 new_parallel_map, profile,
2626} ;
2727use crate :: { Index , Real } ;
@@ -30,26 +30,6 @@ use crate::{Index, Real};
3030
3131type GlobalIndex = u64 ;
3232
33- /// Converts any literal or expression to the Index type I (panics if value does not fit)
34- macro_rules! to_index {
35- ( $value: literal) => {
36- <I as NumCast >:: from( $value) . expect( "literal has to fit in index type" )
37- } ;
38- ( $value: expr) => {
39- <I as NumCast >:: from( $value) . expect( "value has to fit in index type" )
40- } ;
41- }
42-
43- /// Converts any literal or expression to the Real type R (panics if value does not fit)
44- macro_rules! to_real {
45- ( $value: literal) => {
46- <R as NumCast >:: from( $value) . expect( "literal has to fit in real type" )
47- } ;
48- ( $value: expr) => {
49- <R as NumCast >:: from( $value) . expect( "value has to fit in real type" )
50- } ;
51- }
52-
5333pub ( crate ) struct ParametersSubdomainGrid < I : Index , R : Real > {
5434 /// SPH particle radius (in simulation units)
5535 #[ allow( unused) ]
@@ -134,7 +114,7 @@ pub(crate) fn initialize_parameters<I: Index, R: Real>(
134114 let particle_rest_mass = particle_rest_volume * particle_rest_density;
135115
136116 let ghost_particle_margin =
137- ( compact_support_radius / cube_size) . ceil ( ) * cube_size * to_real ! ( 1.01 ) ;
117+ ( compact_support_radius / cube_size) . ceil ( ) * cube_size * 1.01 . convert ( ) ;
138118
139119 // Compute information of ghost margin volume for debugging
140120 {
@@ -144,7 +124,7 @@ pub(crate) fn initialize_parameters<I: Index, R: Real>(
144124 let vol_subdomain = subdomain_cubes
145125 . checked_cubed ( )
146126 . expect ( "number of cubes per subdomain has to be representable in index type" ) ;
147- let vol_margin = ( ghost_margin_cubes * to_index ! ( 2 ) + subdomain_cubes)
127+ let vol_margin = ( ghost_margin_cubes * I :: two ( ) + subdomain_cubes)
148128 . checked_cubed ( )
149129 . expect (
150130 "number of cubes per subdomain with margin has to be representable in index type" ,
@@ -153,15 +133,17 @@ pub(crate) fn initialize_parameters<I: Index, R: Real>(
153133
154134 info ! (
155135 "The ghost margin volume per subdomain is {:.2}% of the subdomain volume" ,
156- ( to_real!( vol_margin) / to_real!( vol_subdomain) ) * to_real!( 100.0 )
136+ ( vol_margin. to_real( ) . unwrap_or( R :: one( ) )
137+ / vol_subdomain. to_real( ) . unwrap_or( R :: one( ) ) )
138+ * 100.0 . convert( )
157139 ) ;
158140 info ! (
159141 "The ghost margin per subdomain is {:.2} MC cells or {:.2} subdomains wide" ,
160142 ghost_particle_margin / cube_size,
161143 ghost_particle_margin / ( cube_size * subdomain_cubes. to_real_unchecked( ) )
162144 ) ;
163145
164- if ghost_margin_cubes > subdomain_cubes / to_index ! ( 2 ) {
146+ if ghost_margin_cubes > subdomain_cubes / I :: two ( ) {
165147 panic ! (
166148 "The ghost margin is {ghost_margin_cubes} cubes wide (rounded up), while the subdomain only has an extent of {subdomain_cubes} cubes. The subdomain has to have at least twice the number of cubes ({})!" ,
167149 ghost_margin_cubes. times( 2 )
@@ -274,7 +256,7 @@ pub(crate) fn extract_narrow_band<I: Index, R: Real>(
274256 let compact_support_radius = parameters. compact_support_radius ;
275257 let ghost_particle_margin = ( compact_support_radius / parameters. cube_size ) . ceil ( )
276258 * parameters. cube_size
277- * to_real ! ( 1.01 ) ;
259+ * 1.01 . convert ( ) ;
278260
279261 // AABB of the particles
280262 let aabb = {
@@ -580,7 +562,7 @@ pub(crate) fn compute_global_densities_and_neighbors<I: Index, R: Real>(
580562 let margin_aabb = {
581563 let mut margin_aabb = subdomain_aabb. clone ( ) ;
582564 // TODO: Verify if we can omit this extra margin?
583- margin_aabb. grow_uniformly ( parameters. ghost_particle_margin * to_real ! ( 1.5 ) ) ;
565+ margin_aabb. grow_uniformly ( parameters. ghost_particle_margin * 1.5 . convert ( ) ) ;
584566 margin_aabb
585567 } ;
586568
@@ -686,7 +668,7 @@ pub(crate) fn reconstruction<I: Index, R: Real>(
686668
687669 let squared_support = parameters. compact_support_radius * parameters. compact_support_radius ;
688670 // Add 1% so that we don't exclude grid points that are just on the kernel boundary
689- let squared_support_with_margin = squared_support * to_real ! ( 1.01 ) ;
671+ let squared_support_with_margin = squared_support * 1.01 . convert ( ) ;
690672 // Compute radial distance in terms of grid points we have to evaluate for each particle
691673 let cube_radius = I :: from ( ( parameters. compact_support_radius / parameters. cube_size ) . ceil ( ) )
692674 . expect ( "kernel radius in cubes has to fit in index type" ) ;
@@ -710,12 +692,8 @@ pub(crate) fn reconstruction<I: Index, R: Real>(
710692 . unwrap_or ( 0 ) ;
711693 info ! ( "Largest subdomain has {} particles." , max_particles) ;
712694
713- // Maximum number of particles such that a subdomain will be considered "sparse"
714- let sparse_limit = ( to_real ! ( max_particles) * to_real ! ( 0.05 ) )
715- . ceil ( )
716- . to_usize ( )
717- . unwrap ( )
718- . max ( 100 ) ;
695+ // Maximum number of particles such that a subdomain will be considered "sparse" (5% of max)
696+ let sparse_limit = ( max_particles / ( 100 / 5 ) ) . max ( 100 ) ;
719697 info ! (
720698 "Subdomains with {} or less particles will be considered sparse." ,
721699 sparse_limit
@@ -1640,9 +1618,9 @@ pub(crate) mod subdomain_classification {
16401618
16411619 if in_ghost_margin {
16421620 let neighbor_subdomain_ijk = [
1643- subdomain_ijk[ 0 ] + to_index ! ( i ) ,
1644- subdomain_ijk[ 1 ] + to_index ! ( j ) ,
1645- subdomain_ijk[ 2 ] + to_index ! ( k ) ,
1621+ subdomain_ijk[ 0 ] + I :: from ( i ) . unwrap ( ) ,
1622+ subdomain_ijk[ 1 ] + I :: from ( j ) . unwrap ( ) ,
1623+ subdomain_ijk[ 2 ] + I :: from ( k ) . unwrap ( ) ,
16461624 ] ;
16471625 // The potential neighbor subdomain might not even be part of our computation domain
16481626 if let Some ( cell) = subdomain_grid. get_cell ( neighbor_subdomain_ijk) {
@@ -1786,24 +1764,29 @@ pub(crate) mod debug {
17861764 let vertex_offset = hexmesh. vertices . len ( ) ;
17871765
17881766 {
1789- let mut push_vertex = |a : i32 , b : i32 , c : i32 | {
1767+ let mut push_vertex = |abc : [ i8 ; 3 ] | {
1768+ let [ a, b, c] = abc;
17901769 hexmesh. vertices . push (
17911770 subdomain_grid. point_coordinates (
17921771 & subdomain_grid
1793- . get_point ( [ i + to_index ! ( a) , j + to_index ! ( b) , k + to_index ! ( c) ] )
1772+ . get_point ( [
1773+ i + I :: from ( a) . unwrap ( ) ,
1774+ j + I :: from ( b) . unwrap ( ) ,
1775+ k + I :: from ( c) . unwrap ( ) ,
1776+ ] )
17941777 . unwrap ( ) ,
17951778 ) ,
17961779 ) ;
17971780 } ;
17981781
1799- push_vertex ( 0 , 0 , 0 ) ;
1800- push_vertex ( 1 , 0 , 0 ) ;
1801- push_vertex ( 1 , 1 , 0 ) ;
1802- push_vertex ( 0 , 1 , 0 ) ;
1803- push_vertex ( 0 , 0 , 1 ) ;
1804- push_vertex ( 1 , 0 , 1 ) ;
1805- push_vertex ( 1 , 1 , 1 ) ;
1806- push_vertex ( 0 , 1 , 1 ) ;
1782+ push_vertex ( [ 0 , 0 , 0 ] ) ;
1783+ push_vertex ( [ 1 , 0 , 0 ] ) ;
1784+ push_vertex ( [ 1 , 1 , 0 ] ) ;
1785+ push_vertex ( [ 0 , 1 , 0 ] ) ;
1786+ push_vertex ( [ 0 , 0 , 1 ] ) ;
1787+ push_vertex ( [ 1 , 0 , 1 ] ) ;
1788+ push_vertex ( [ 1 , 1 , 1 ] ) ;
1789+ push_vertex ( [ 0 , 1 , 1 ] ) ;
18071790 }
18081791
18091792 hexmesh. cells . push ( [
0 commit comments