Skip to content
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

Enhancements to storages #180

Merged
merged 15 commits into from
Oct 18, 2024
Merged

Enhancements to storages #180

merged 15 commits into from
Oct 18, 2024

Conversation

kaipartmann
Copy link
Owner

@kaipartmann kaipartmann commented Oct 15, 2024

Major enhancements on how storages are initializes and used. The amount of boilerplate code is reduced.
Fixes #131, closes #129, closes #72, closes #70.

NEW
@storage BBMaterial struct BBStorage <: AbstractStorage
    @lthfield position::Matrix{Float64}
    @pointfield displacement::Matrix{Float64}
    @pointfield velocity::Matrix{Float64}
    @pointfield velocity_half::Matrix{Float64}
    @pointfield velocity_half_old::Matrix{Float64}
    @pointfield acceleration::Matrix{Float64}
    @pointfield b_int::Matrix{Float64}
    @pointfield b_int_old::Matrix{Float64}
    @pointfield b_ext::Matrix{Float64}
    @pointfield density_matrix::Matrix{Float64}
    @pointfield damage::Vector{Float64}
    bond_active::Vector{Bool}
    @pointfield n_active_bonds::Vector{Int}
end
OLD
struct BBVerletStorage <: AbstractStorage
    position::Matrix{Float64}
    displacement::Matrix{Float64}
    velocity::Matrix{Float64}
    velocity_half::Matrix{Float64}
    acceleration::Matrix{Float64}
    b_int::Matrix{Float64}
    b_ext::Matrix{Float64}
    damage::Vector{Float64}
    bond_active::Vector{Bool}
    n_active_bonds::Vector{Int}
end

function BBVerletStorage(::BBMaterial, ::VelocityVerlet, system::BondSystem, ch)
    n_loc_points = length(ch.loc_points)
    position = copy(system.position)
    displacement = zeros(3, n_loc_points)
    velocity = zeros(3, n_loc_points)
    velocity_half = zeros(3, n_loc_points)
    acceleration = zeros(3, n_loc_points)
    b_int = zeros(3, n_loc_points)
    b_ext = zeros(3, n_loc_points)
    damage = zeros(n_loc_points)
    bond_active = ones(Bool, length(system.bonds))
    n_active_bonds = copy(system.n_neighbors)
    s = BBVerletStorage(position, displacement, velocity, velocity_half, acceleration,
                        b_int, b_ext, damage, bond_active, n_active_bonds)
    return s
end

@storage BBMaterial VelocityVerlet BBVerletStorage

@loc_to_halo_fields BBVerletStorage :position

struct BBRelaxationStorage <: AbstractStorage
    position::Matrix{Float64}
    displacement::Matrix{Float64}
    velocity::Matrix{Float64}
    velocity_half::Matrix{Float64}
    velocity_half_old::Matrix{Float64}
    b_int::Matrix{Float64}
    b_int_old::Matrix{Float64}
    b_ext::Matrix{Float64}
    density_matrix::Matrix{Float64}
    damage::Vector{Float64}
    bond_active::Vector{Bool}
    n_active_bonds::Vector{Int}
end

function BBRelaxationStorage(::BBMaterial, ::DynamicRelaxation, system::BondSystem, ch)
    n_loc_points = length(ch.loc_points)
    position = copy(system.position)
    displacement = zeros(3, n_loc_points)
    velocity = zeros(3, n_loc_points)
    velocity_half = zeros(3, n_loc_points)
    velocity_half_old = zeros(3, n_loc_points)
    b_int = zeros(3, n_loc_points)
    b_int_old = zeros(3, n_loc_points)
    b_ext = zeros(3, n_loc_points)
    density_matrix = zeros(3, n_loc_points)
    damage = zeros(n_loc_points)
    bond_active = ones(Bool, length(system.bonds))
    n_active_bonds = copy(system.n_neighbors)
    s = BBRelaxationStorage(position, displacement, velocity, velocity_half,
                            velocity_half_old, b_int, b_int_old, b_ext, density_matrix,
                            damage, bond_active, n_active_bonds)
    return s
end

@storage BBMaterial DynamicRelaxation BBRelaxationStorage

@loc_to_halo_fields BBRelaxationStorage :position

const BBStorage = Union{BBVerletStorage,BBRelaxationStorage}

@kaipartmann kaipartmann added enhancement New feature or request refactoring Refactoring code without functional changes labels Oct 15, 2024
Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 91.53005% with 31 lines in your changes missing coverage. Please review.

Project coverage is 91.63%. Comparing base (d64c097) to head (e1f93f2).
Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
src/core/storages.jl 87.57% 20 Missing ⚠️
src/discretization/interaction_system.jl 78.26% 5 Missing ⚠️
src/core/systems.jl 81.81% 4 Missing ⚠️
src/discretization/body_chunk.jl 90.90% 1 Missing ⚠️
src/time_solvers/dynamic_relaxation.jl 97.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #180      +/-   ##
==========================================
+ Coverage   91.11%   91.63%   +0.52%     
==========================================
  Files          44       44              
  Lines        4187     4258      +71     
==========================================
+ Hits         3815     3902      +87     
+ Misses        372      356      -16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kaipartmann kaipartmann marked this pull request as ready for review October 18, 2024 10:03
@kaipartmann kaipartmann merged commit 0abbded into main Oct 18, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactoring Refactoring code without functional changes
Projects
None yet
1 participant