11@doc raw """
22 TotalLagrangianSPHSystem(initial_condition, smoothing_kernel, smoothing_length,
33 young_modulus, poisson_ratio;
4- n_clamped_particles=0, clamped_particles_motion=nothing,
5- boundary_model=nothing,
4+ n_clamped_particles=0,
5+ clamped_particles=Int[],
6+ clamped_particles_motion=nothing,
67 acceleration=ntuple(_ -> 0.0, NDIMS),
7- penalty_force=nothing, source_terms=nothing)
8+ penalty_force=nothing, viscosity=nothing,
9+ source_terms=nothing, boundary_model=nothing)
810
911System for particles of an elastic structure.
1012
@@ -23,9 +25,13 @@ See [Total Lagrangian SPH](@ref tlsph) for more details on the method.
2325 See [Smoothing Kernels](@ref smoothing_kernel).
2426
2527# Keywords
26- - `n_clamped_particles`: Number of clamped particles which are fixed and not integrated
27- to clamp the structure. Note that the clamped particles must be the **last**
28- particles in the `InitialCondition`. See the info box below.
28+ - `n_clamped_particles` (deprecated): Number of clamped particles that are fixed and not integrated
29+ to clamp the structure. Note that the clamped particles must be the **last**
30+ particles in the `InitialCondition`. See the info box below.
31+ This keyword is deprecated and will be removed in a future release.
32+ Instead pass `clamped_particles` with the explicit particle indices to be clamped.
33+ - `clamped_particles`: Indices specifying the clamped particles that are fixed
34+ and not integrated to clamp the structure.
2935- `clamped_particles_motion`: Prescribed motion of the clamped particles.
3036 If `nothing` (default), the clamped particles are fixed.
3137 See [`PrescribedMotion`](@ref) for details.
@@ -43,7 +49,8 @@ See [Total Lagrangian SPH](@ref tlsph) for more details on the method.
4349 See, for example, [`SourceTermDamping`](@ref).
4450
4551!!! note
46- The clamped particles must be the **last** particles in the `InitialCondition`.
52+ If specifying the clamped particles manually (via `n_clamped_particles`),
53+ the clamped particles must be the **last** particles in the `InitialCondition`.
4754 To do so, e.g. use the `union` function:
4855 ```jldoctest; output = false, setup = :(clamped_particles = RectangularShape(0.1, (1, 4), (0.0, 0.0), density=1.0); beam = RectangularShape(0.1, (3, 4), (0.1, 0.0), density=1.0))
4956 structure = union(beam, clamped_particles)
9097
9198function TotalLagrangianSPHSystem (initial_condition, smoothing_kernel, smoothing_length,
9299 young_modulus, poisson_ratio;
93- n_clamped_particles= 0 , clamped_particles_motion= nothing ,
94- boundary_model= nothing ,
100+ n_clamped_particles= 0 ,
101+ clamped_particles= Int[],
102+ clamped_particles_motion= nothing ,
95103 acceleration= ntuple (_ -> 0.0 ,
96104 ndims (smoothing_kernel)),
97105 penalty_force= nothing , viscosity= nothing ,
98- source_terms= nothing )
106+ source_terms= nothing , boundary_model = nothing )
99107 NDIMS = ndims (initial_condition)
100108 ELTYPE = eltype (initial_condition)
101109 n_particles = nparticles (initial_condition)
@@ -110,30 +118,63 @@ function TotalLagrangianSPHSystem(initial_condition, smoothing_kernel, smoothing
110118 throw (ArgumentError (" `acceleration` must be of length $NDIMS for a $(NDIMS) D problem" ))
111119 end
112120
113- initial_coordinates = copy (initial_condition. coordinates)
114- current_coordinates = copy (initial_condition. coordinates)
115- mass = copy (initial_condition. mass)
116- material_density = copy (initial_condition. density)
121+ # Backwards compatibility: `n_clamped_particles` is deprecated.
122+ # Emit a deprecation warning and (if the user didn't supply explicit indices)
123+ # convert the old `n_clamped_particles` convention to `clamped_particles`.
124+ if n_clamped_particles != 0
125+ Base. depwarn (" keyword `n_clamped_particles` is deprecated and will be removed in a future release; " *
126+ " pass `clamped_particles` (Vector{Int} of indices) instead." ,
127+ :n_clamped_particles )
128+ if isempty (clamped_particles)
129+ clamped_particles = collect ((n_particles - n_clamped_particles + 1 ): n_particles)
130+ else
131+ throw (ArgumentError (" Either `n_clamped_particles` or `clamped_particles` can be specified, not both." ))
132+ end
133+ end
134+
135+ # Handle clamped particles
136+ if ! isempty (clamped_particles)
137+ @assert allunique (clamped_particles) " `clamped_particles` contains duplicate particle indices"
138+
139+ n_clamped_particles = length (clamped_particles)
140+ initial_condition_sorted = deepcopy (initial_condition)
141+ young_modulus_sorted = copy (young_modulus)
142+ poisson_ratio_sorted = copy (poisson_ratio)
143+ move_particles_to_end! (initial_condition_sorted, clamped_particles)
144+ move_particles_to_end! (young_modulus_sorted, clamped_particles)
145+ move_particles_to_end! (poisson_ratio_sorted, clamped_particles)
146+ else
147+ initial_condition_sorted = initial_condition
148+ young_modulus_sorted = young_modulus
149+ poisson_ratio_sorted = poisson_ratio
150+ end
151+
152+ initial_coordinates = copy (initial_condition_sorted. coordinates)
153+ current_coordinates = copy (initial_condition_sorted. coordinates)
154+ mass = copy (initial_condition_sorted. mass)
155+ material_density = copy (initial_condition_sorted. density)
117156 correction_matrix = Array {ELTYPE, 3} (undef, NDIMS, NDIMS, n_particles)
118157 pk1_rho2 = Array {ELTYPE, 3} (undef, NDIMS, NDIMS, n_particles)
119158 deformation_grad = Array {ELTYPE, 3} (undef, NDIMS, NDIMS, n_particles)
120159
121160 n_integrated_particles = n_particles - n_clamped_particles
122161
123- lame_lambda = @. young_modulus * poisson_ratio /
124- ((1 + poisson_ratio) * (1 - 2 * poisson_ratio))
125- lame_mu = @. (young_modulus / 2 ) / (1 + poisson_ratio)
162+ lame_lambda = @. young_modulus_sorted * poisson_ratio_sorted /
163+ ((1 + poisson_ratio_sorted) *
164+ (1 - 2 * poisson_ratio_sorted))
165+ lame_mu = @. (young_modulus_sorted / 2 ) / (1 + poisson_ratio_sorted)
126166
127167 ismoving = Ref (! isnothing (clamped_particles_motion))
128- initialize_prescribed_motion! (clamped_particles_motion, initial_condition ,
168+ initialize_prescribed_motion! (clamped_particles_motion, initial_condition_sorted ,
129169 n_clamped_particles)
130170
131- cache = create_cache_tlsph (clamped_particles_motion, initial_condition )
171+ cache = create_cache_tlsph (clamped_particles_motion, initial_condition_sorted )
132172
133- return TotalLagrangianSPHSystem (initial_condition , initial_coordinates,
173+ return TotalLagrangianSPHSystem (initial_condition_sorted , initial_coordinates,
134174 current_coordinates, mass, correction_matrix,
135175 pk1_rho2, deformation_grad, material_density,
136- n_integrated_particles, young_modulus, poisson_ratio,
176+ n_integrated_particles, young_modulus_sorted,
177+ poisson_ratio_sorted,
137178 lame_lambda, lame_mu, smoothing_kernel,
138179 smoothing_length, acceleration_, boundary_model,
139180 penalty_force, viscosity, source_terms,
0 commit comments