Skip to content

Commit 8b07325

Browse files
committed
current status
1 parent 99c74b7 commit 8b07325

File tree

2 files changed

+120
-11
lines changed

2 files changed

+120
-11
lines changed

src/Physics/Material/Material_Models/Correspondence_UMAT.jl

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function init_material_model(datamanager::Module, nodes::Union{SubArray,Vector{I
7676
end
7777
properties[iID] = material_parameter["Property_$iID"]
7878
end
79-
println()
79+
8080
if !haskey(material_parameter, "UMAT Material Name")
8181
@warn "No UMAT Material Name is defined. Please check if you use it as method to check different material in your UMAT."
8282
material_parameter["UMAT Material Name"] = ""
@@ -169,7 +169,11 @@ Example:
169169
function compute_stresses(datamanager::Module, nodes::Union{SubArray,Vector{Int64}}, dof::Int64, material_parameter::Dict, time::Float64, dt::Float64, strain_increment::SubArray, stress_N::SubArray, stress_NP1::SubArray)
170170
# the notation from the Abaqus Fortran subroutine is used.
171171
nstatev = material_parameter["Number of State Variables"]
172+
nprops = material_parameter["Number of Properties"]
173+
props = datamanager.get_field("Properties")
174+
172175
statev = datamanager.get_field("State Variables")
176+
173177
stress_temp::Vector{Float64} = zeros(Float64, 3 * dof - 3)
174178
DDSDDE = zeros(Float64, 3 * dof - 3, 3 * dof - 3)
175179
SSE = datamanager.get_field("Specific Elastic Strain Energy")
@@ -195,15 +199,15 @@ function compute_stresses(datamanager::Module, nodes::Union{SubArray,Vector{Int6
195199
nshr = 2 * dof - 3
196200
# Size of the stress or strain component array
197201
ntens = ndi + nshr
198-
not_supported_float = 0.0
202+
not_supported_float::Float64 = 0.0
199203
angles = datamanager.get_field("Angles")
200204
DFGRD0 = datamanager.get_field("Deformation Gradient", "N")
201205
DFGRD1 = datamanager.get_field("Deformation Gradient", "NP1")
202-
not_supported_int = 0
206+
not_supported_int::Int64 = 0
203207
for iID in nodes
204208
stress_NP1[iID, :, :] = UMAT_interface
205209
rotNP1[iID, :, :] = Geometry.rotation_tensor(angles[iID, :])
206-
UMAT_interface(material_parameter["file"], stress_temp, statev[iID, :], DDSDDE, SSE, SPD, SCD, RPL, DDSDDT, DRPLDE, DRPLDT, matrix_to_voigt(strain_N[iID, :, :]), matrix_to_voigt(strain_increment[iID, :, :]), time, time + dt, dt, temperature_N[iID], temperature_increment[iID], PREDEF[iID, :], DPRED[iID, :], CMNAME, ndi, nshr, ntens, nstatev, coords[iID, :], rot_NP1[iID, :, :] - rot_N[iID, :, :], not_supported_float, not_supported_float, DFGRD0, DFGRD1, not_supported_int, not_supported_int, not_supported_int, not_supported_int, not_supported_int, not_supported_int)
210+
UMAT_interface(material_parameter["file"], stress_temp, statev[iID, :], DDSDDE, SSE, SPD, SCD, RPL, DDSDDT, DRPLDE, DRPLDT, matrix_to_voigt(strain_N[iID, :, :]), matrix_to_voigt(strain_increment[iID, :, :]), time, dt, temperature_N[iID], temperature_increment[iID], PREDEF[iID, :], DPRED[iID, :], CMNAME, ndi, nshr, ntens, nstatev, props, nprops, coords[iID, :], rot_NP1[iID, :, :] - rot_N[iID, :, :], not_supported_float, not_supported_float, DFGRD0, DFGRD1, not_supported_int, not_supported_int, not_supported_int, not_supported_int, not_supported_int, not_supported_int)
207211
stress_NP1[iID, :, :] = voigt_to_matrix(stress_temp)
208212
end
209213
# CORRESPONDENCE::UMATINT(sigmaNP1LocVoigt, statev, DDSDDE, &SSE, &SPD, &SCD, &RPL,
@@ -236,10 +240,58 @@ Example:
236240
```julia
237241
```
238242
"""
239-
function UMAT_interface(filename::String)
240-
#ccall((:__simplemodule_MOD_foo, "./simplemodule.so"), Int32, (Ptr{Int32},), a)
241-
#ccall((:__simplemodule_MOD_foo, filename), Int32, (Ptr{Int32},), a)
242-
243+
function UMAT_interface(filename::String, STRESS::Vector{Float64}, STATEV::Vector{Float64}, DDSDDE::Matrix{Float64}, SSE::Float64, SPD::Float64, SCD::Float64, RPL::Float64, DDSDDT::Vector{Float64}, DRPLDE::Vector{Float64}, DRPLDT::Float64, STRAN::Vector{Float64}, DSTRAN::Vector{Float64}, TIME::Float64, DTIME::Float64, TEMP::Float64, DTEMP::Float64, PREDEF::Vector{Float64}, DPRED::Vector{Float64}, CMNAME::Cstring, NDI::Int64, NSHR::Int64, NTENS::Int64, NSTATEV::Int64, PROPS::Vector{Float64}, NPROPS::Int64, COORDS::Vector{Float64}, DROT::Matrix{Float64}, PNEWDT::Float64, CELENT::Float64, DFGRD0::Matrix{Float64}, DFGRD1::Matrix{Float64}, NOEL::Int64, NPT::Int64, LAYER::Int64, KSPT::Int64, JSTEP::Int64, KINC::Int64)
244+
# Define the path to the shared library
245+
global libtest = filename
246+
println()
247+
# Call the UMAT subroutine with uppercase variables
248+
"""
249+
ccall((:UMAT, libtest), Cvoid,
250+
(
251+
Ptr{Float64}, # STRESS
252+
Ptr{Float64}, # STATEV
253+
Ptr{Float64}, # DDSDDE
254+
Ptr{Float64}, # SSE
255+
Ptr{Float64}, # SPD
256+
Ptr{Float64}, # SCD
257+
Ptr{Float64}, # RPL
258+
Ptr{Float64}, # DDSDDT
259+
Ptr{Float64}, # DRPLDE
260+
Ptr{Float64}, # DRPLDT
261+
Ptr{Float64}, # STRAN
262+
Ptr{Float64}, # DSTRAN
263+
Ptr{Float64}, # TIME
264+
Ptr{Float64}, # DTIME
265+
Ptr{Float64}, # TEMP
266+
Ptr{Float64}, # DTEMP
267+
Ptr{Float64}, # PREDEF
268+
Ptr{Float64}, # DPRED
269+
Ptr{UInt8}, # CMNAME
270+
Cint, # NDI
271+
Cint, # NSHR
272+
Cint, # NTENS
273+
Cint, # NSTATEV
274+
Ptr{Float64}, # PROPS
275+
Cint, # NPROPS
276+
Ptr{Float64}, # COORDS
277+
Ptr{Float64}, # DROT
278+
Ptr{Float64}, # PNEWDT
279+
Ptr{Float64}, # CELENT
280+
Ptr{Float64}, # DFGRD0
281+
Ptr{Float64}, # DFGRD1
282+
Ptr{Cint}, # NOEL
283+
Ptr{Cint}, # NPT
284+
Ptr{Cint}, # LAYER
285+
Ptr{Cint}, # KSPT
286+
Ptr{Cint}, # JSTEP
287+
Ptr{Cint} # KINC
288+
),
289+
STRESS, STATEV, DDSDDE, SSE, SPD, SCD, RPL, DDSDDT, DRPLDE, DRPLDT,
290+
STRAN, DSTRAN, TIME, DTIME, TEMP, DTEMP, PREDEF, DPRED, CMNAME,
291+
NDI, NSHR, NTENS, NSTATEV, PROPS, NPROPS, COORDS, DROT, PNEWDT,
292+
CELENT, DFGRD0, DFGRD1, NOEL, NPT, LAYER, KSPT, JSTEP, KINC
293+
)
294+
"""
243295
end
244296

245297

test/unit_tests/Physics/Material/Material_Models/ut_Correspondence_UMAT.jl

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
#
33
# SPDX-License-Identifier: BSD-3-Clause
44
using Test
5+
using LinearAlgebra
56
include("../../../../../src/Physics/Material/Material_Models/Correspondence_UMAT.jl")
6-
# include("../../../../../src/Support/data_manager.jl")
7+
include("../../../../../src/Support/data_manager.jl")
78
@testset "get_name&fe_support" begin
89
@test Correspondence_UMAT.correspondence_name() == "Correspondence UMAT"
910
@test Correspondence_UMAT.fe_support()
1011
end
1112
@testset "init exceptions" begin
1213
nodes = 2
13-
test_Data_manager = PeriLab.Data_manager
14+
test_Data_manager = Data_manager
1415
test_Data_manager.set_num_controller(nodes)
1516
dof = 3
1617
test_Data_manager.set_dof(dof)
@@ -50,4 +51,60 @@ end
5051
@test fields[2, 1] == test_1[2]
5152
@test fields[1, 2] == test_2[1]
5253
@test fields[2, 2] == test_2[2]
53-
end
54+
end
55+
@testset "ut_malloc_cstring" begin
56+
CMNAME = Correspondence_UMAT.malloc_cstring("UMAT_TEST")
57+
@test typeof(CMNAME) == Cstring
58+
end
59+
60+
# Test wrapper function for UMAT_interface
61+
#@testset "UMAT_interface Tests" begin
62+
# Example test case (you should define your own)
63+
file = "./src/Physics/Material/UMATs/libusertest.so"
64+
if !isfile(file)
65+
file = "../src/Physics/Material/UMATs/libusertest.so"
66+
end
67+
STRESS::Vector{Float64} = zeros(Float64, 6) # Example initialization, adjust the size as needed
68+
STATEV::Vector{Float64} = zeros(Float64, 10) # Adjust the size and values as needed
69+
DDSDDE::Matrix{Float64} = Matrix{Float64}(I, 6, 6) # Identity matrix for simplicity, adjust as needed
70+
SSE::Float64 = 0.0
71+
SPD::Float64 = 0.0
72+
SCD::Float64 = 0.0
73+
RPL::Float64 = 0.0
74+
DDSDDT::Vector{Float64} = zeros(Float64, 6) # Adjust as needed
75+
DRPLDE::Vector{Float64} = zeros(Float64, 6) # Adjust as needed
76+
DRPLDT::Float64 = 0.0 # Adjust as needed
77+
STRAN::Vector{Float64} = zeros(Float64, 6) # Adjust as needed
78+
DSTRAN::Vector{Float64} = zeros(Float64, 6) # Adjust as needed
79+
TIME::Float64 = 0.0
80+
DTIME::Float64 = 0.1
81+
TEMP::Float64 = 25.0
82+
DTEMP::Float64 = 0.1
83+
PREDEF::Vector{Float64} = zeros(Float64, 1) # Adjust as needed
84+
DPRED::Vector{Float64} = zeros(Float64, 1) # Adjust as needed
85+
CMNAME::Cstring = Correspondence_UMAT.malloc_cstring("UMAT_TEST") # Adjust as needed
86+
NDI::Int64 = 3
87+
NSHR::Int64 = 3
88+
NTENS::Int64 = 6
89+
NSTATEV::Int64 = length(STATEV)
90+
PROPS::Vector{Float64} = zeros(Float64, 2) # Adjust as needed
91+
NPROPS::Int64 = 2
92+
COORDS::Vector{Float64} = zeros(Float64, 3) # Adjust as needed
93+
DROT::Matrix{Float64} = Matrix{Float64}(I, 3, 3) # Adjust as needed
94+
PNEWDT::Float64 = 0.1
95+
CELENT::Float64 = 1.0
96+
DFGRD0::Matrix{Float64} = Matrix{Float64}(I, 3, 3) # Adjust as needed
97+
DFGRD1::Matrix{Float64} = Matrix{Float64}(I, 3, 3) # Adjust as needed
98+
NOEL::Int64 = 1
99+
NPT::Int64 = 1
100+
LAYER::Int64 = 1
101+
KSPT::Int64 = 1
102+
JSTEP::Int64 = 1
103+
KINC::Int64 = 1
104+
105+
# Call the UMAT_interface
106+
Correspondence_UMAT.UMAT_interface(file, STRESS, STATEV, DDSDDE, SSE, SPD, SCD, RPL, DDSDDT, DRPLDE, DRPLDT, STRAN, DSTRAN, TIME, DTIME, TEMP, DTEMP, PREDEF, DPRED, CMNAME, NDI, NSHR, NTENS, NSTATEV, PROPS, NPROPS, COORDS, DROT, PNEWDT, CELENT, DFGRD0, DFGRD1, NOEL, NPT, LAYER, KSPT, JSTEP, KINC)
107+
println()
108+
# Example assertion (you should define appropriate checks based on your UMAT's expected behavior)
109+
# @test STRESS != zeros(Float64, 6) # Check if STRESS was updated (or any other appropriate check)
110+
#end

0 commit comments

Comments
 (0)