Skip to content

Commit

Permalink
Replace *_def.jl with *_types.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
lxmota committed Feb 7, 2025
1 parent 1953ceb commit 6455571
Show file tree
Hide file tree
Showing 18 changed files with 273 additions and 241 deletions.
3 changes: 2 additions & 1 deletion src/Norma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# the U.S. Government retains certain rights in this software. This software
# is released under the BSD license detailed in the file license.txt in the
# top-level Norma.jl directory.

module Norma

using Logging
Expand Down Expand Up @@ -34,7 +35,7 @@ function run(input_file::String)
return sim
end

function run(params::Dict{String,Any}, name::String)
function run(params::Dict{String, Any}, name::String)
sim = create_simulation(params, name)
evolve(sim)
return sim
Expand Down
40 changes: 16 additions & 24 deletions src/constitutive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@
# is released under the BSD license detailed in the file license.txt in the
# top-level Norma.jl directory.

using LinearAlgebra

using .MiniTensor

abstract type Material end
abstract type Solid <: Material end
abstract type Thermal <: Material end

function elastic_constants(params::Dict{String,Any})
function elastic_constants(params::Dict{String, Any})
E = 0.0
ν = 0.0
κ = 0.0
Expand Down Expand Up @@ -104,7 +96,7 @@ mutable struct SaintVenant_Kirchhoff <: Solid
λ::Float64
μ::Float64
ρ::Float64
function SaintVenant_Kirchhoff(params::Dict{String,Any})
function SaintVenant_Kirchhoff(params::Dict{String, Any})
E, ν, κ, λ, μ = elastic_constants(params)
ρ = params["density"]
new(E, ν, κ, λ, μ, ρ)
Expand All @@ -118,7 +110,7 @@ mutable struct Linear_Elastic <: Solid
λ::Float64
μ::Float64
ρ::Float64
function Linear_Elastic(params::Dict{String,Any})
function Linear_Elastic(params::Dict{String, Any})
E, ν, κ, λ, μ = elastic_constants(params)
ρ = params["density"]
new(E, ν, κ, λ, μ, ρ)
Expand All @@ -132,7 +124,7 @@ mutable struct Neohookean <: Solid
λ::Float64
μ::Float64
ρ::Float64
function Neohookean(params::Dict{String,Any})
function Neohookean(params::Dict{String, Any})
E, ν, κ, λ, μ = elastic_constants(params)
ρ = params["density"]
new(E, ν, κ, λ, μ, ρ)
Expand All @@ -148,7 +140,7 @@ mutable struct SethHill <: Solid
ρ::Float64
m::Int
n::Int
function SethHill(params::Dict{String,Any})
function SethHill(params::Dict{String, Any})
E, ν, κ, λ, μ = elastic_constants(params)
ρ = params["density"]
new(E, ν, κ, λ, μ, ρ, params["m"], params["n"])
Expand All @@ -173,7 +165,7 @@ mutable struct J2 <: Solid
T₀::Float64
Tₘ::Float64
M::Float64
function J2(params::Dict{String,Any})
function J2(params::Dict{String, Any})
E, ν, κ, λ, μ = elastic_constants(params)
ρ = params["density"]
Y₀ = params["yield stress"]
Expand Down Expand Up @@ -360,7 +352,7 @@ end

struct Linear_Isotropic <: Thermal
κ::Float64
function Linear_Isotropic(params::Dict{String,Any})
function Linear_Isotropic(params::Dict{String, Any})
κ = params["thermal conductivity"]
new(κ)
end
Expand Down Expand Up @@ -474,13 +466,13 @@ function constitutive(material::SaintVenant_Kirchhoff, F::Matrix{Float64})
W = 0.5 * λ * trE * trE + μ * tr(E * E)
S = λ * trE * I + 2.0 * μ * E
CC = zeros(3, 3, 3, 3)
for i = 1:3
for j = 1:3
for i 1:3
for j 1:3
δᵢⱼ = I[i, j]
for k = 1:3
for k 1:3
δᵢₖ = I[i, k]
δⱼₖ = I[j, k]
for l = 1:3
for l 1:3
δᵢₗ = I[i, l]
δⱼₗ = I[j, l]
δₖₗ = I[k, l]
Expand All @@ -503,13 +495,13 @@ function constitutive(material::Linear_Elastic, F::Matrix{Float64})
W = 0.5 * λ * trϵ * trϵ + μ * tr* ϵ)
σ = λ * trϵ * I + 2.0 * μ * ϵ
CC = zeros(3, 3, 3, 3)
for i = 1:3
for j = 1:3
for i 1:3
for j 1:3
δᵢⱼ = I[i, j]
for k = 1:3
for k 1:3
δᵢₖ = I[i, k]
δⱼₖ = I[j, k]
for l = 1:3
for l 1:3
δᵢₗ = I[i, l]
δⱼₗ = I[j, l]
δₖₗ = I[k, l]
Expand Down Expand Up @@ -573,7 +565,7 @@ function constitutive(material::SethHill, F::Matrix{Float64})
return W, P, AA
end

function create_material(params::Dict{String,Any})
function create_material(params::Dict{String, Any})
model_name = params["model"]
if model_name == "linear elastic"
return Linear_Elastic(params)
Expand Down
13 changes: 13 additions & 0 deletions src/constitutive_types.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Norma.jl 1.0: Copyright 2025 National Technology & Engineering Solutions of
# Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS,
# the U.S. Government retains certain rights in this software. This software
# is released under the BSD license detailed in the file license.txt in the
# top-level Norma.jl directory.

using LinearAlgebra

using .MiniTensor

abstract type Material end
abstract type Solid <: Material end
abstract type Thermal <: Material end
6 changes: 3 additions & 3 deletions src/evolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ end

function advance_time(sim::SingleDomainSimulation)
sim.integrator.prev_time = sim.integrator.time
next_time = round(sim.integrator.time + sim.integrator.time_step; digits=12)
next_time = round(sim.integrator.time + sim.integrator.time_step; digits = 12)
sim.integrator.time = sim.model.time = next_time
sim.integrator.stop += 1
end
Expand All @@ -236,7 +236,7 @@ function advance_time(sim::MultiDomainSimulation)
final_time = sim.schwarz_controller.final_time
initial_time = sim.schwarz_controller.initial_time
num_stops = sim.schwarz_controller.num_stops
next_time = round((final_time - initial_time) * Float64(stop) / Float64(num_stops - 1) + initial_time, digits=12)
next_time = round((final_time - initial_time) * Float64(stop) / Float64(num_stops - 1) + initial_time, digits = 12)
sim.schwarz_controller.time = next_time
sim.schwarz_controller.stop = stop
end
Expand Down Expand Up @@ -275,4 +275,4 @@ function end_runtimer(sim::MultiDomainSimulation)
for subsim sim.subsims
subsim.integrator.runtime_step = time() - subsim.integrator.runtime_step
end
end
end
31 changes: 16 additions & 15 deletions src/ics_bcs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# the U.S. Government retains certain rights in this software. This software
# is released under the BSD license detailed in the file license.txt in the
# top-level Norma.jl directory.

@variables t, x, y, z
D = Differential(t)

function SMDirichletBC(input_mesh::ExodusDatabase, bc_params::Dict{String,Any})
function SMDirichletBC(input_mesh::ExodusDatabase, bc_params::Dict{String, Any})
node_set_name = bc_params["node set"]
expression = bc_params["function"]
offset = component_offset_from_string(bc_params["component"])
Expand All @@ -27,7 +28,7 @@ function SMDirichletBC(input_mesh::ExodusDatabase, bc_params::Dict{String,Any})
)
end

function SMDirichletInclined(input_mesh::ExodusDatabase, bc_params::Dict{String,Any})
function SMDirichletInclined(input_mesh::ExodusDatabase, bc_params::Dict{String, Any})
node_set_name = bc_params["node set"]
expression = bc_params["function"]
node_set_id = node_set_id_from_name(node_set_name, input_mesh)
Expand All @@ -47,11 +48,11 @@ function SMDirichletInclined(input_mesh::ExodusDatabase, bc_params::Dict{String,
velo_num,
acce_num,
rotation_matrix,
reference_normal
reference_normal,
)
end

function SMNeumannBC(input_mesh::ExodusDatabase, bc_params::Dict{String,Any})
function SMNeumannBC(input_mesh::ExodusDatabase, bc_params::Dict{String, Any})
side_set_name = bc_params["side set"]
expression = bc_params["function"]
offset = component_offset_from_string(bc_params["component"])
Expand All @@ -73,7 +74,7 @@ end
function SMContactSchwarzBC(
coupled_subsim::SingleDomainSimulation,
input_mesh::ExodusDatabase,
bc_params::Dict{String,Any},
bc_params::Dict{String, Any},
)
side_set_name = bc_params["side set"]
side_set_id = side_set_id_from_name(side_set_name, input_mesh)
Expand Down Expand Up @@ -105,7 +106,7 @@ function SMContactSchwarzBC(
transfer_operator,
rotation_matrix,
active_contact,
swap_bcs
swap_bcs,
)
end

Expand Down Expand Up @@ -136,7 +137,7 @@ function SMCouplingSchwarzBC(
coupled_subsim::SingleDomainSimulation,
input_mesh::ExodusDatabase,
bc_type::String,
bc_params::Dict{String,Any},
bc_params::Dict{String, Any},
)
side_set_name = bc_params["side set"]
side_set_id = side_set_id_from_name(side_set_name, input_mesh)
Expand Down Expand Up @@ -180,7 +181,7 @@ function SMCouplingSchwarzBC(
coupled_subsim,
subsim,
is_dirichlet,
swap_bcs
swap_bcs,
)
elseif bc_type == "Schwarz nonoverlap"
if haskey(bc_params, "default BC type") == true
Expand All @@ -205,7 +206,7 @@ function SMCouplingSchwarzBC(
subsim,
coupled_side_set_id,
is_dirichlet,
swap_bcs
swap_bcs,
)
else
error("Unknown boundary condition type : ", bc_type)
Expand Down Expand Up @@ -345,7 +346,7 @@ function find_point_in_mesh(
point::Vector{Float64},
model::SolidMechanics,
blk_id::Int,
tol::Float64
tol::Float64,
)
mesh = model.mesh
element_type = Exodus.read_block_parameters(mesh, Int32(blk_id))[1]
Expand All @@ -370,7 +371,7 @@ function find_point_in_mesh(
point::Vector{Float64},
model::LinearOpInfRom,
blk_id::Int,
tol::Float64
tol::Float64,
)
node_indices, ξ, found = find_point_in_mesh(point, model.fom_model, blk_id, tol)
return node_indices, ξ, found
Expand Down Expand Up @@ -713,7 +714,7 @@ function apply_sm_schwarz_contact_neumann(model::SolidMechanics, bc::SMContactSc
model.boundary_force[3*global_node-2:3*global_node] += transfer_normal_component(
node_tractions,
model.boundary_force[3*global_node-2:3*global_node],
normal
normal,
)
end
end
Expand Down Expand Up @@ -835,7 +836,7 @@ function extract_value(symbol::Num)
return symbol.val
end

function create_bcs(params::Dict{String,Any})
function create_bcs(params::Dict{String, Any})
boundary_conditions = Vector{BoundaryCondition}()
if haskey(params, "boundary conditions") == false
return boundary_conditions
Expand Down Expand Up @@ -904,7 +905,7 @@ function apply_bcs(model::LinearOpInfRom)

end

function apply_ics(params::Dict{String,Any}, model::SolidMechanics)
function apply_ics(params::Dict{String, Any}, model::SolidMechanics)
if haskey(params, "initial conditions") == false
return
end
Expand Down Expand Up @@ -941,7 +942,7 @@ function apply_ics(params::Dict{String,Any}, model::SolidMechanics)
end
end

function apply_ics(params::Dict{String,Any}, model::LinearOpInfRom)
function apply_ics(params::Dict{String, Any}, model::LinearOpInfRom)

apply_ics(params, model.fom_model)

Expand Down
1 change: 1 addition & 0 deletions src/ics_bcs_def.jl → src/ics_bcs_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# the U.S. Government retains certain rights in this software. This software
# is released under the BSD license detailed in the file license.txt in the
# top-level Norma.jl directory.

abstract type BoundaryCondition end
abstract type SchwarzBoundaryCondition <: BoundaryCondition end
abstract type RegularBoundaryCondition <: BoundaryCondition end
Expand Down
15 changes: 8 additions & 7 deletions src/interpolation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# the U.S. Government retains certain rights in this software. This software
# is released under the BSD license detailed in the file license.txt in the
# top-level Norma.jl directory.

function barycentricD2N3::Vector{Float64})
N = [1.0 - ξ[1] - ξ[2], ξ[1], ξ[2]]
dN = [
Expand Down Expand Up @@ -461,7 +462,7 @@ using Symbolics
function get_side_set_nodal_forces(
nodal_coord::Matrix{Float64},
traction_num::Num,
time::Float64
time::Float64,
)
_, num_side_nodes = size(nodal_coord)
element_type = get_element_type(2, num_side_nodes)
Expand Down Expand Up @@ -539,7 +540,7 @@ end
function map_to_parametric(
element_type::String,
nodes::Matrix{Float64},
point::Vector{Float64}
point::Vector{Float64},
)
tol = 1.0e-08
max_iters = 1024
Expand Down Expand Up @@ -579,7 +580,7 @@ function interpolate(element_type::String, ξ::Vector{Float64})
end
end

function is_inside_parametric(element_type::String, ξ::Vector{Float64}, tol::Float64=1.0e-06)
function is_inside_parametric(element_type::String, ξ::Vector{Float64}, tol::Float64 = 1.0e-06)
factor = 1.0 + tol
if element_type == "BAR2"
return -factor ξ factor
Expand All @@ -594,7 +595,7 @@ function is_inside_parametric(element_type::String, ξ::Vector{Float64}, tol::Fl
end
end

function is_inside(element_type::String, nodes::Matrix{Float64}, point::Vector{Float64}, tol::Float64=1.0e-06)
function is_inside(element_type::String, nodes::Matrix{Float64}, point::Vector{Float64}, tol::Float64 = 1.0e-06)
ξ = zeros(length(point))
if is_inside_guess(element_type, nodes, point, 0.1) == false
return ξ, false
Expand All @@ -603,7 +604,7 @@ function is_inside(element_type::String, nodes::Matrix{Float64}, point::Vector{F
return ξ, is_inside_parametric(element_type, ξ, tol)
end

function is_inside_guess(element_type::String, nodes::Matrix{Float64}, point::Vector{Float64}, tol::Float64=1.0e-06)
function is_inside_guess(element_type::String, nodes::Matrix{Float64}, point::Vector{Float64}, tol::Float64 = 1.0e-06)
if element_type == "TETRA4" || element_type == "TETRA10"
return in_tetrahedron(point, nodes[:, 1], nodes[:, 2], nodes[:, 3], nodes[:, 4], tol)
elseif element_type == "HEX8"
Expand Down Expand Up @@ -648,7 +649,7 @@ end

function get_distance_to_centroid(nodes::Matrix{Float64}, point::Vector{Float64})
num_nodes = size(nodes, 2)
centroid = sum(nodes, dims=2) / num_nodes
centroid = sum(nodes, dims = 2) / num_nodes
distance = norm(centroid - point)
return distance
end
Expand All @@ -663,7 +664,7 @@ function get_side_set_local_from_global_map(mesh::ExodusDatabase, side_set_id::I
Exodus.read_side_set_node_list(mesh, side_set_id)
unique_node_indices = unique(side_set_node_indices)
num_nodes = length(unique_node_indices)
local_from_global_map = Dict{Int64,Int64}()
local_from_global_map = Dict{Int64, Int64}()
for i 1:num_nodes
local_from_global_map[Int64(unique_node_indices[i])] = i
end
Expand Down
Loading

0 comments on commit 6455571

Please sign in to comment.