diff --git a/docs/literate/src/files/non_periodic_boundaries.jl b/docs/literate/src/files/non_periodic_boundaries.jl index 3b238ad4533..8f0e320dfdc 100644 --- a/docs/literate/src/files/non_periodic_boundaries.jl +++ b/docs/literate/src/files/non_periodic_boundaries.jl @@ -99,7 +99,7 @@ sol = solve(ode, CarpenterKennedy2N54(williamson_condition=false), save_everystep=false, saveat=visnodes, callback=callbacks); using Plots -@gif for step in 1:length(sol.u) +@gif for step in eachindex(sol.u) plot(sol.u[step], semi, ylim=(-1.5, 1.5), legend=true, label="approximation", title="time t=$(round(sol.t[step], digits=5))") scatter!([0.0], [sum(boundary_condition(SVector(0.0), sol.t[step], equations))], label="boundary condition") end diff --git a/docs/literate/src/files/scalar_linear_advection_1d.jl b/docs/literate/src/files/scalar_linear_advection_1d.jl index 9b48f29d341..c7d55e26d2a 100644 --- a/docs/literate/src/files/scalar_linear_advection_1d.jl +++ b/docs/literate/src/files/scalar_linear_advection_1d.jl @@ -120,7 +120,7 @@ integral = sum(nodes.^3 .* weights) x = Matrix{Float64}(undef, length(nodes), n_elements) for element in 1:n_elements x_l = coordinates_min + (element - 1) * dx + dx/2 - for i in 1:length(nodes) + for i in eachindex(nodes) ξ = nodes[i] # nodes in [-1, 1] x[i, element] = x_l + dx/2 * ξ end @@ -417,7 +417,7 @@ dx = (coordinates_max - coordinates_min) / n_elements # length of one element x = Matrix{Float64}(undef, length(nodes), n_elements) for element in 1:n_elements x_l = -1 + (element - 1) * dx + dx/2 - for i in 1:length(nodes) # basis points in [-1, 1] + for i in eachindex(nodes) # basis points in [-1, 1] ξ = nodes[i] x[i, element] = x_l + dx/2 * ξ end diff --git a/examples/p4est_2d_dgsem/elixir_advection_amr_solution_independent.jl b/examples/p4est_2d_dgsem/elixir_advection_amr_solution_independent.jl index 5a2537be4e6..a1ddc6a314f 100644 --- a/examples/p4est_2d_dgsem/elixir_advection_amr_solution_independent.jl +++ b/examples/p4est_2d_dgsem/elixir_advection_amr_solution_independent.jl @@ -33,7 +33,7 @@ function (indicator::IndicatorSolutionIndependent)(u::AbstractArray{<:Any, 4}, outer_distance = 1.85 #Iterate over all elements - for element in 1:length(alpha) + for element in eachindex(alpha) # Calculate periodic distance between cell and center. # This requires an uncurved mesh! coordinates = SVector(0.5 * (cache.elements.node_coordinates[1, 1, 1, element] + diff --git a/examples/t8code_2d_dgsem/elixir_advection_amr_solution_independent.jl b/examples/t8code_2d_dgsem/elixir_advection_amr_solution_independent.jl index 0589e76a6a9..1ed08e1961b 100644 --- a/examples/t8code_2d_dgsem/elixir_advection_amr_solution_independent.jl +++ b/examples/t8code_2d_dgsem/elixir_advection_amr_solution_independent.jl @@ -32,7 +32,7 @@ function (indicator::IndicatorSolutionIndependent)(u::AbstractArray{<:Any, 4}, outer_distance = 1.85 # Iterate over all elements. - for element in 1:length(alpha) + for element in eachindex(alpha) # Calculate periodic distance between cell and center. # This requires an uncurved mesh! coordinates = SVector(0.5 * (cache.elements.node_coordinates[1, 1, 1, element] + diff --git a/examples/tree_2d_dgsem/elixir_advection_amr_solution_independent.jl b/examples/tree_2d_dgsem/elixir_advection_amr_solution_independent.jl index 03a213689ec..c7412660b0c 100644 --- a/examples/tree_2d_dgsem/elixir_advection_amr_solution_independent.jl +++ b/examples/tree_2d_dgsem/elixir_advection_amr_solution_independent.jl @@ -31,7 +31,7 @@ function (indicator::IndicatorSolutionIndependent)(u::AbstractArray{<:Any, 4}, outer_distance = 1.85 #Iterate over all elements - for element in 1:length(alpha) + for element in eachindex(alpha) #Calculate periodic distance between cell and center. cell_id = cache.elements.cell_ids[element] coordinates = mesh.tree.coordinates[1:2, cell_id] diff --git a/src/callbacks_step/amr.jl b/src/callbacks_step/amr.jl index 1ab65a3553e..45f03fba8fe 100644 --- a/src/callbacks_step/amr.jl +++ b/src/callbacks_step/amr.jl @@ -243,7 +243,7 @@ function (amr_callback::AMRCallback)(u_ode::AbstractVector, mesh::TreeMesh, @unpack to_refine, to_coarsen = amr_callback.amr_cache empty!(to_refine) empty!(to_coarsen) - for element in 1:length(lambda) + for element in eachindex(lambda) controller_value = lambda[element] if controller_value > 0 push!(to_refine, leaf_cell_ids[element]) @@ -307,7 +307,7 @@ function (amr_callback::AMRCallback)(u_ode::AbstractVector, mesh::TreeMesh, end # Extract only those parent cells for which all children should be coarsened - to_coarsen = collect(1:length(parents_to_coarsen))[parents_to_coarsen .== 2^ndims(mesh)] + to_coarsen = collect(eachindex(parents_to_coarsen))[parents_to_coarsen .== 2^ndims(mesh)] # Finally, coarsen mesh coarsened_original_cells = @trixi_timeit timer() "mesh" coarsen!(mesh.tree, @@ -395,7 +395,7 @@ function (amr_callback::AMRCallback)(u_ode::AbstractVector, mesh::TreeMesh, @unpack to_refine, to_coarsen = amr_callback.amr_cache empty!(to_refine) empty!(to_coarsen) - for element in 1:length(lambda) + for element in eachindex(lambda) controller_value = lambda[element] if controller_value > 0 push!(to_refine, leaf_cell_ids[element]) @@ -456,7 +456,7 @@ function (amr_callback::AMRCallback)(u_ode::AbstractVector, mesh::TreeMesh, end # Extract only those parent cells for which all children should be coarsened - to_coarsen = collect(1:length(parents_to_coarsen))[parents_to_coarsen .== 2^ndims(mesh)] + to_coarsen = collect(eachindex(parents_to_coarsen))[parents_to_coarsen .== 2^ndims(mesh)] # Finally, coarsen mesh coarsened_original_cells = @trixi_timeit timer() "mesh" coarsen!(mesh.tree, diff --git a/src/callbacks_step/euler_acoustics_coupling_dg2d.jl b/src/callbacks_step/euler_acoustics_coupling_dg2d.jl index 16fac4f2d8d..8a8bb893dcd 100644 --- a/src/callbacks_step/euler_acoustics_coupling_dg2d.jl +++ b/src/callbacks_step/euler_acoustics_coupling_dg2d.jl @@ -12,7 +12,7 @@ function calc_acoustic_sources!(acoustic_source_terms, u_euler, u_acoustics, dg::DGSEM, cache) acoustic_source_terms .= zero(eltype(acoustic_source_terms)) - @threaded for k in 1:length(coupled_element_ids) + @threaded for k in eachindex(coupled_element_ids) element = coupled_element_ids[k] for j in eachnode(dg), i in eachnode(dg) diff --git a/src/callbacks_step/time_series_dg_tree.jl b/src/callbacks_step/time_series_dg_tree.jl index 37d4e6ea705..0af1688a8ed 100644 --- a/src/callbacks_step/time_series_dg_tree.jl +++ b/src/callbacks_step/time_series_dg_tree.jl @@ -25,7 +25,7 @@ function get_elements_by_coordinates!(element_ids, coordinates, mesh::TreeMesh, cell_id = cell_ids[element] # Iterate over coordinates - for index in 1:length(element_ids) + for index in eachindex(element_ids) # Skip coordinates for which an element has already been found if element_ids[index] > 0 continue @@ -63,7 +63,7 @@ function calc_interpolating_polynomials!(interpolating_polynomials, coordinates, wbary = barycentric_weights(nodes) - for index in 1:length(element_ids) + for index in eachindex(element_ids) # Construct point x = SVector(ntuple(i -> coordinates[i, index], ndims(mesh))) @@ -94,7 +94,7 @@ function record_state_at_points!(point_data, u, solution_variables, new_length = old_length + n_solution_variables # Loop over all points/elements that should be recorded - for index in 1:length(element_ids) + for index in eachindex(element_ids) # Extract data array and element id data = point_data[index] element_id = element_ids[index] @@ -108,7 +108,7 @@ function record_state_at_points!(point_data, u, solution_variables, u_node = solution_variables(get_node_vars(u, equations, dg, i, element_id), equations) - for v in 1:length(u_node) + for v in eachindex(u_node) data[old_length + v] += (u_node[v] * interpolating_polynomials[i, 1, index]) end @@ -126,7 +126,7 @@ function record_state_at_points!(point_data, u, solution_variables, new_length = old_length + n_solution_variables # Loop over all points/elements that should be recorded - for index in 1:length(element_ids) + for index in eachindex(element_ids) # Extract data array and element id data = point_data[index] element_id = element_ids[index] @@ -140,7 +140,7 @@ function record_state_at_points!(point_data, u, solution_variables, u_node = solution_variables(get_node_vars(u, equations, dg, i, j, element_id), equations) - for v in 1:length(u_node) + for v in eachindex(u_node) data[old_length + v] += (u_node[v] * interpolating_polynomials[i, 1, index] * interpolating_polynomials[j, 2, index]) @@ -159,7 +159,7 @@ function record_state_at_points!(point_data, u, solution_variables, new_length = old_length + n_solution_variables # Loop over all points/elements that should be recorded - for index in 1:length(element_ids) + for index in eachindex(element_ids) # Extract data array and element id data = point_data[index] element_id = element_ids[index] @@ -173,7 +173,7 @@ function record_state_at_points!(point_data, u, solution_variables, u_node = solution_variables(get_node_vars(u, equations, dg, i, j, k, element_id), equations) - for v in 1:length(u_node) + for v in eachindex(u_node) data[old_length + v] += (u_node[v] * interpolating_polynomials[i, 1, index] * interpolating_polynomials[j, 2, index] diff --git a/src/callbacks_step/time_series_dg_unstructured.jl b/src/callbacks_step/time_series_dg_unstructured.jl index f6d1bb48f24..85427f1273a 100644 --- a/src/callbacks_step/time_series_dg_unstructured.jl +++ b/src/callbacks_step/time_series_dg_unstructured.jl @@ -31,7 +31,7 @@ function get_elements_by_coordinates!(element_ids, coordinates, # Iterate over coordinates distances = zeros(eltype(mesh.corners), mesh.n_elements) indices = zeros(Int, mesh.n_elements, 2) - for index in 1:length(element_ids) + for index in eachindex(element_ids) # Grab the current point for which the element needs found point = SVector(coordinates[1, index], coordinates[2, index]) @@ -77,7 +77,7 @@ function get_elements_by_coordinates!(element_ids, coordinates, # Loop through all the element candidates until we find a vector from the barycenter # to the surface that points in the same direction as the current `point` vector. # This then gives us the correct element. - for element in 1:length(candidates) + for element in eachindex(candidates) bary_center = SVector(bary_centers[1, candidates[element]], bary_centers[2, candidates[element]]) # Vector pointing from the barycenter toward the minimal `surface_point` @@ -153,7 +153,7 @@ function calc_interpolating_polynomials!(interpolating_polynomials, coordinates, # Helper array for a straight-sided quadrilateral element corners = zeros(eltype(mesh.corners), 4, 2) - for index in 1:length(element_ids) + for index in eachindex(element_ids) # Construct point x = SVector(ntuple(i -> coordinates[i, index], ndims(mesh))) @@ -280,7 +280,7 @@ function record_state_at_points!(point_data, u, solution_variables, new_length = old_length + n_solution_variables # Loop over all points/elements that should be recorded - for index in 1:length(element_ids) + for index in eachindex(element_ids) # Extract data array and element id data = point_data[index] element_id = element_ids[index] @@ -294,7 +294,7 @@ function record_state_at_points!(point_data, u, solution_variables, u_node = solution_variables(get_node_vars(u, equations, dg, i, j, element_id), equations) - for v in 1:length(u_node) + for v in eachindex(u_node) data[old_length + v] += (u_node[v] * interpolating_polynomials[i, 1, index] * interpolating_polynomials[j, 2, index]) diff --git a/src/semidiscretization/semidiscretization_euler_acoustics.jl b/src/semidiscretization/semidiscretization_euler_acoustics.jl index 173523ff892..286315fb960 100644 --- a/src/semidiscretization/semidiscretization_euler_acoustics.jl +++ b/src/semidiscretization/semidiscretization_euler_acoustics.jl @@ -103,7 +103,7 @@ function precompute_weights(source_region, weights, coupled_element_ids, equatio (nnodes(dg), nnodes(dg), length(coupled_element_ids))) - @threaded for k in 1:length(coupled_element_ids) + @threaded for k in eachindex(coupled_element_ids) element = coupled_element_ids[k] for j in eachnode(dg), i in eachnode(dg) x = get_node_coords(cache.elements.node_coordinates, equations, dg, i, j, @@ -197,7 +197,7 @@ function add_acoustic_source_terms!(du_acoustics, acoustic_source_terms, source_ coupled_element_ids, mesh::TreeMesh{2}, equations, dg::DGSEM, cache) - @threaded for k in 1:length(coupled_element_ids) + @threaded for k in eachindex(coupled_element_ids) element = coupled_element_ids[k] for j in eachnode(dg), i in eachnode(dg) diff --git a/src/visualization/utilities.jl b/src/visualization/utilities.jl index 05457395ac0..c1108128c92 100644 --- a/src/visualization/utilities.jl +++ b/src/visualization/utilities.jl @@ -495,7 +495,7 @@ function cell2node(cell_centered_data) resolution_in, _ = size(first(cell_centered_data)) resolution_out = resolution_in + 1 node_centered_data = [Matrix{Float64}(undef, resolution_out, resolution_out) - for _ in 1:length(cell_centered_data)] + for _ in eachindex(cell_centered_data)] for (cell_data, node_data) in zip(cell_centered_data, node_centered_data) # Fill center with original data @@ -1545,7 +1545,7 @@ end # Create an axis. function axis_curve(nodes_x, nodes_y, nodes_z, slice, point, n_points) - if n_points == nothing + if n_points === nothing n_points = 64 end dimensions = length(point) diff --git a/test/test_unit.jl b/test/test_unit.jl index 79950f58d59..9a4ae2ede13 100644 --- a/test/test_unit.jl +++ b/test/test_unit.jl @@ -284,7 +284,7 @@ end function MyContainer(data, capacity) c = MyContainer(Vector{Int}(undef, capacity + 1), capacity, length(data), capacity + 1) - c.data[1:length(data)] .= data + c.data[eachindex(data)] .= data return c end MyContainer(data::AbstractArray) = MyContainer(data, length(data)) diff --git a/utils/trixi2txt.jl b/utils/trixi2txt.jl index 12a3d46760e..52ee904d2f6 100644 --- a/utils/trixi2txt.jl +++ b/utils/trixi2txt.jl @@ -86,7 +86,7 @@ function trixi2txt(filename::AbstractString...; "maximum supported level $max_supported_level") end max_available_nodes_per_finest_element = 2^(max_supported_level - max_level) - if nvisnodes == nothing + if nvisnodes === nothing max_nvisnodes = 2 * n_nodes elseif nvisnodes == 0 max_nvisnodes = n_nodes @@ -137,9 +137,9 @@ function trixi2txt(filename::AbstractString...; println(io) # Data - for idx in 1:length(xs) + for idx in eachindex(xs) @printf(io, "%+10.8e", xs[idx]) - for variable_id in 1:length(variables) + for variable_id in eachindex(variables) @printf(io, " %+10.8e ", node_centered_data[idx, variable_id]) end println(io) @@ -199,7 +199,7 @@ function read_meshfile(filename::String) # Extract leaf cells (= cells to be plotted) and contract all other arrays accordingly leaf_cells = similar(levels) n_cells = 0 - for cell_id in 1:length(levels) + for cell_id in eachindex(levels) if sum(child_ids[:, cell_id]) > 0 continue end