Skip to content

Commit

Permalink
Merge pull request #71 from MineralsCloud:ElasticConstantSolver
Browse files Browse the repository at this point in the history
Fix `_cᵢⱼ`
  • Loading branch information
singularitti authored Feb 17, 2022
2 parents dcf3580 + 54ff6b3 commit 8f295fb
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/calc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,26 @@ function (::ElasticConstantSolver{Cubic})(
)
end

function _find_nonzero_element(strain_or_stress::Union{EngineeringStress,EngineeringStrain})
indices = findall(!iszero, strain_or_stress)
function _find_nonzero_element(strain::EngineeringStrain)
indices = findall(!iszero, strain)
return only(indices)
end

function _pick_nonzero(strains_or_stresses::AbstractVector)
indices = map(_find_nonzero_element, strains_or_stresses)
function _pick_from(strains::AbstractVector{<:EngineeringStrain})
indices = map(_find_nonzero_element, strains)
function _at_index(desired_index)
positions = findall(==(desired_index), indices) # No duplicated directions allowed
position = only(positions)
return strains_or_stresses[position]
return only(positions)
end
end

_isnegative(number) = number < zero(number)

function _cᵢⱼ(
strains::AbstractVector{<:EngineeringStrain},
stresses::AbstractVector{<:EngineeringStress},
i,
j,
i,
)
ϵⱼ, σᵢ = _pick_nonzero(strains)(i), _pick_nonzero(stresses)(j)
return σᵢ / ϵⱼ
position = _pick_from(strains)(j)
σᵢ, ϵⱼ = stresses[position][i], strains[position][j]
return -σᵢ / ϵⱼ
end

0 comments on commit 8f295fb

Please # to comment.