Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JTHesse committed Nov 20, 2024
1 parent ed031b1 commit 98e874f
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 136 deletions.
6 changes: 4 additions & 2 deletions src/Compute/compute_global_values.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ function calculate_nodelist(
# get block_nodes
# check NP1
if datamanager.has_key(field_key * "NP1")
field_key *= "NP1"
field = datamanager.get_field(field_key, "NP1")
field_key = field_key * "NP1"
else
field = datamanager.get_field(field_key)
end
if !datamanager.has_key(field_key)
@error "Field $field_key does not exists for compute sum."
return nothing
end
field = datamanager.get_field(field_key)
field_type = datamanager.get_field_type(field_key)

if calculation_type == "Sum"
Expand Down
23 changes: 14 additions & 9 deletions src/Core/BC_manager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ function check_valid_bcs(bcs::Dict{String,Any}, datamanager::Module)
end

for data_entry in datamanager.get_all_field_keys()
if (occursin(bcs[bc]["Variable"], data_entry) && occursin("NP1", data_entry)) ||
bcs[bc]["Variable"] == data_entry
bcs[bc]["Initial"] = bcs[bc]["Type"] == "Initial"
if (occursin(bcs[bc]["Variable"], data_entry) && occursin("NP1", data_entry))
bcs[bc]["Time"] = "NP1"
valid = true
elseif bcs[bc]["Variable"] == data_entry
bcs[bc]["Variable"] = data_entry
working_bcs[bc] = bcs[bc]
bcs[bc]["Time"] = "constant"
valid = true
end
if valid
bcs[bc]["Initial"] = bcs[bc]["Type"] == "Initial"
working_bcs[bc] = bcs[bc]
break
end
end
Expand Down Expand Up @@ -134,11 +139,11 @@ function apply_bc_dirichlet(bcs::Dict, datamanager::Module, time::Float64)
for name in keys(bcs)
bc = bcs[name]
if !(bc["Type"] in ["Initial", "Dirichlet"]) ||
bc["Variable"] == "Force DensitiesNP1" ||
bc["Variable"] == "ForcesNP1"
bc["Variable"] == "Force Densities" ||
bc["Variable"] == "Forces"
continue
end
field = datamanager.get_field(bc["Variable"])
field = datamanager.get_field(bc["Variable"], bc["Time"])

if ndims(field) > 1
if haskey(dof_mapping, bc["Coordinate"])
Expand Down Expand Up @@ -195,9 +200,9 @@ function apply_bc_dirichlet_force(bcs::Dict, datamanager::Module, time::Float64)
if bc["Type"] != "Dirichlet"
continue
end
if bc["Variable"] == "ForcesNP1"
if bc["Variable"] == "Forces"
field = datamanager.get_field("External Forces")
elseif bc["Variable"] == "Force DensitiesNP1"
elseif bc["Variable"] == "Force Densities"
field = datamanager.get_field("External Force Densities")
else
continue
Expand Down
44 changes: 25 additions & 19 deletions src/Core/Solver/Verlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,35 +421,19 @@ function run_solver(
active_list = datamanager.get_field("Active")
density = datamanager.get_field("Density")
coor = datamanager.get_field("Coordinates")
uNP1 = datamanager.get_field("Displacements", "NP1")
# index = datamanager.get_field("Index")
comm = datamanager.get_comm()

deformed_coorNP1 = datamanager.get_field("Deformed Coordinates", "NP1")
if "Material" in solver_options["Models"]
forces = datamanager.get_field("Forces", "NP1")
external_forces = datamanager.get_field("External Forces")
force_densities = datamanager.get_field("Force Densities", "NP1")
external_force_densities = datamanager.get_field("External Force Densities")
uN = datamanager.get_field("Displacements", "N")
vN = datamanager.get_field("Velocity", "N")
vNP1 = datamanager.get_field("Velocity", "NP1")
a = datamanager.get_field("Acceleration")
deformed_coorN = datamanager.get_field("Deformed Coordinates", "N")
end
if "Thermal" in solver_options["Models"]
flowN = datamanager.get_field("Heat Flow", "N")
flowNP1 = datamanager.get_field("Heat Flow", "NP1")
temperatureN = datamanager.get_field("Temperature", "N")
temperatureNP1 = datamanager.get_field("Temperature", "NP1")
deltaT = datamanager.get_field("Delta Temperature")
heat_capacity = datamanager.get_field("Specific Heat Capacity")
end
if "Corrosion" in solver_options["Models"]
concentrationN = datamanager.get_field("Concentration", "N")
concentrationNP1 = datamanager.get_field("Concentration", "NP1")
concentration_fluxN = datamanager.get_field("Concentration Flux", "N")
concentration_fluxNP1 = datamanager.get_field("Concentration Flux", "NP1")
## TODO field creation not in run
delta_concentration =
datamanager.create_constant_node_field("Delta Concentration", Float64, 1)
Expand All @@ -460,9 +444,6 @@ function run_solver(
lumped_mass = datamanager.get_field("Lumped Mass Matrix")
fe_nodes = datamanager.get_field("FE Nodes")
end
if "Damage" in solver_options["Models"]
damage = datamanager.get_damage("NP1")
end
active = datamanager.get_field("Active")

dt::Float64 = solver_options["dt"]
Expand All @@ -478,6 +459,31 @@ function run_solver(
#nodes::Vector{Int64} = Vector{Int64}(1:datamanager.get_nnodes())
@inbounds @fastmath for idt in iter
@timeit to "Verlet" begin
uNP1 = datamanager.get_field("Displacements", "NP1")
deformed_coorNP1 = datamanager.get_field("Deformed Coordinates", "NP1")
if "Material" in solver_options["Models"]
forces = datamanager.get_field("Forces", "NP1")
force_densities = datamanager.get_field("Force Densities", "NP1")
uN = datamanager.get_field("Displacements", "N")
vN = datamanager.get_field("Velocity", "N")
vNP1 = datamanager.get_field("Velocity", "NP1")
deformed_coorN = datamanager.get_field("Deformed Coordinates", "N")
end
if "Thermal" in solver_options["Models"]
flowN = datamanager.get_field("Heat Flow", "N")
flowNP1 = datamanager.get_field("Heat Flow", "NP1")
temperatureN = datamanager.get_field("Temperature", "N")
temperatureNP1 = datamanager.get_field("Temperature", "NP1")
end
if "Corrosion" in solver_options["Models"]
concentrationN = datamanager.get_field("Concentration", "N")
concentrationNP1 = datamanager.get_field("Concentration", "NP1")
concentration_fluxN = datamanager.get_field("Concentration Flux", "N")
concentration_fluxNP1 = datamanager.get_field("Concentration Flux", "NP1")
end
if "Damage" in solver_options["Models"]
damage = datamanager.get_damage("NP1")
end
active_nodes = datamanager.get_field("Active Nodes")
active_nodes =
find_active_nodes(active_list, active_nodes, 1:datamanager.get_nnodes())
Expand Down
58 changes: 36 additions & 22 deletions src/Core/data_manager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ function create_field(
VectorOrArray::String = "Vector",
)
if has_key(name)
if size(get_field(name), 1) != data["nnodes"]
if size(_get_field(name), 1) != data["nnodes"]
@warn "Field $name exists already with different size. Predefined field is returned"
end
return get_field(name)
return _get_field(name)
end
value = vartype(default_value)
if bond_or_node == "Node_Field"
Expand All @@ -461,7 +461,7 @@ function create_field(
end
end
elseif bond_or_node == "Bond_Field"
nBonds = get_field("Number of Neighbors")
nBonds = _get_field("Number of Neighbors")
if dof == 1
fields[vartype][name] = [fill(value, n) for n in nBonds]
else
Expand All @@ -473,7 +473,7 @@ function create_field(
end
end
elseif bond_or_node == "Element_Field"
nElements = get_field("Number of Element Neighbors")
nElements = _get_field("Number of Element Neighbors")
if dof == 1
fields[vartype][name] = [fill(value, n) for n in nElements]
else
Expand Down Expand Up @@ -581,22 +581,36 @@ Returns the field with the given name and time.
# Returns
- `field::Field`: The field with the given name and time.
"""
function get_field(name::String, time::String)

try
if time == "N"
return get_field(data["NP1_to_N"][name][1])
else
return get_field(data["NP1_to_N"][name][2])
function get_field(name::String, time::String = "constant")

if time == "constant"
return _get_field(name)
elseif time == "N"
try
return _get_field(data["NP1_to_N"][name][1])
catch
@error "Field ''" *
name *
"'' does not exist. Check if it is initialized as constant."
return nothing
end
catch
@error "Field $name does not exist. Check if it is initialized as constant."
elseif time == "NP1"
try
return _get_field(data["NP1_to_N"][name][2])
catch
@error "Field ''" *
name *
"'' does not exist. Check if it is initialized as constant."
return nothing
end
else
@error "Time $time is not supported. Use 'constant', 'N', or 'NP1'"
return nothing
end
end

"""
get_field(name::String)
_get_field(name::String)
Returns the field with the given name.
Expand All @@ -605,7 +619,7 @@ Returns the field with the given name.
# Returns
- `field::Field`: The field with the given name.
"""
function get_field(name::String)
function _get_field(name::String)
try
return data["field_array_type"][name]["get_function"]()
catch
Expand Down Expand Up @@ -705,7 +719,7 @@ end
Get the neighborhood list.
"""
function get_nlist()
return get_field("Neighborhoodlist")
return _get_field("Neighborhoodlist")
end

"""
Expand All @@ -717,7 +731,7 @@ function get_filtered_nlist()
if !has_key("FilteredNeighborhoodlist")
return nothing
end
return get_field("FilteredNeighborhoodlist")
return _get_field("FilteredNeighborhoodlist")
end

"""
Expand Down Expand Up @@ -1481,7 +1495,7 @@ Sets the synchronization dictionary globally.
"""
function set_synch(name, download_from_cores, upload_to_cores, dof = 0)
if name in get_all_field_keys()
field = get_field(name)
field = _get_field(name)
if dof == 0
dof = length(field[1, :, :])
end
Expand All @@ -1491,7 +1505,7 @@ function set_synch(name, download_from_cores, upload_to_cores, dof = 0)
"dof" => dof,
)
elseif name * "NP1" in get_all_field_keys()
field = get_field(name * "NP1")
field = get_field(name, "NP1")
if dof == 0
dof = length(field[1, :, :])
end
Expand Down Expand Up @@ -1521,7 +1535,7 @@ function set_local_synch(model, name, download_from_cores, upload_to_cores, dof
return nothing
end
if name in get_all_field_keys()
field = get_field(name)
field = _get_field(name)
if dof == 0
dof = length(field[1, :, :])
end
Expand All @@ -1531,7 +1545,7 @@ function set_local_synch(model, name, download_from_cores, upload_to_cores, dof
"dof" => dof,
)
elseif name * "NP1" in get_all_field_keys()
field = get_field(name * "NP1")
field = get_field(name, "NP1")
if dof == 0
dof = length(field[1, :, :])
end
Expand All @@ -1550,7 +1564,7 @@ end
Switches the fields from NP1 to N.active
"""
function switch_NP1_to_N()
active = get_field("Active")
active = _get_field("Active")
for key in keys(data["NP1_to_N"])
data["NP1_to_N"][key][1], data["NP1_to_N"][key][2] =
data["NP1_to_N"][key][2], data["NP1_to_N"][key][1]
Expand Down
Loading

0 comments on commit 98e874f

Please sign in to comment.