Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Exodus"
uuid = "f57ae99e-f805-4780-bdca-96e224be1e5a"
version = "0.14.4"
version = "0.15.0"
authors = ["cmhamel <cmhamel32@gmail.com>"]

[deps]
Expand Down
8 changes: 3 additions & 5 deletions lib/IncludeMe.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
include("LibExodus.jl")
# TODO make below constants not hardcoded. Read from LibExodus.
const cpu_word_size = Int32(sizeof(Float64)) # TODO make parametric so we can have float models
const IO_word_size = Int32(8) # This was what we did before
const cpu_word_size = Int32(sizeof(Float64)) # TODO make parametric so we can have float models
const IO_word_size = Int32(8) # This was what we did before
const version_number = LibExodus.EX_API_VERS
import .LibExodus:
ex_entity_type,
ex_inquiry,
EX_ABORT,
EX_API_VERS_NODOT,
EX_BULK_INT64_API,
Expand All @@ -27,4 +25,4 @@ import .LibExodus:
EX_WRITE,
EX_VERBOSE,
MAX_LINE_LENGTH,
MAX_STR_LENGTH
MAX_STR_LENGTH
7 changes: 5 additions & 2 deletions lib/LibExodus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export Exodus_jll

using CEnum: CEnum, @cenum

to_c_type(t::Type) = t
to_c_type_pairs(va_list) = map(enumerate(to_c_type.(va_list))) do (ind, type)
:(va_list[$ind]::$type)
end

function interface(nvtxs, start, adjacency, vwgts, ewgts, x, y, z, outassignname, outfilename, assignment, architecture, ndims_tot, mesh_dims, goal, global_method, local_method, rqi_flag, vmax, ndims, eigtol, seed)
@ccall libexodus.interface(nvtxs::Cint, start::Ptr{Cint}, adjacency::Ptr{Cint}, vwgts::Ptr{Cint}, ewgts::Ptr{Cfloat}, x::Ptr{Cfloat}, y::Ptr{Cfloat}, z::Ptr{Cfloat}, outassignname::Cstring, outfilename::Cstring, assignment::Ptr{Cint}, architecture::Cint, ndims_tot::Cint, mesh_dims::Ptr{Cint}, goal::Ptr{Cdouble}, global_method::Cint, local_method::Cint, rqi_flag::Cint, vmax::Cint, ndims::Cint, eigtol::Cdouble, seed::Clong)::Cint
end
Expand Down Expand Up @@ -2258,8 +2263,6 @@ const CHACO_VERSION_MINOR = 0

const CHACO_VERSION_PATCH = 0

# const EX_MAX_NAME = NC_MAX_NAME

const EXODUS_VERSION = "9.04"

const EXODUS_VERSION_MAJOR = 9
Expand Down
21 changes: 8 additions & 13 deletions lib/generator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,9 @@ epilogue_file_path = ""

# node with an id in the `output_ignorelist` will be ignored in the printing passes.
# this is very useful for custom editing.
# output_ignorelist = [
# "CINDEX_EXPORTS",
# "CINDEX_VERSION",
# "CINDEX_VERSION_STRING",
# "CINDEX_LINKAGE",
# "CINDEX_DEPRECATED",
# "LLVM_CLANG_C_STRICT_PROTOTYPES_BEGIN",
# "LLVM_CLANG_C_STRICT_PROTOTYPES_END",
# "LLVM_CLANG_C_EXTERN_C_BEGIN",
# "LLVM_CLANG_C_EXTERN_C_END"
# ]
output_ignorelist = [
"EX_MAX_NAME"
]

# Julia's `@enum` do not allow duplicated values, so by default, C enums are translated to
# CEnum.jl's `@cenum`.
Expand Down Expand Up @@ -176,7 +168,7 @@ opaque_as_mutable_struct = true
use_ccall_macro = true

# if true, variadic functions are wrapped with `@ccall` macro. Otherwise variadic functions are ignored.
wrap_variadic_function = false
wrap_variadic_function = true

# Generate getproperty/setproperty! methods for the types in the following list.
# Warning: the generated methods will only work on the architecture that they
Expand Down Expand Up @@ -213,4 +205,7 @@ ignore_header_guards = true
ignore_header_guards_with_suffixes = []

# if true, ignore those pure definition macros in the C code
ignore_pure_definition = true
ignore_pure_definition = true

[codegen.typemap]
"Ptr{Cvoid}" = "Ptr{Cfloat}"
17 changes: 16 additions & 1 deletion lib/make.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
using Clang.Generators
# using Clang.LibClang.Clang_unified_jll
using Exodus_jll

function patch!(ctx)
Clang.Generators.walk!(ctx.dag) do node
if node isa Clang.Generators.FunctionDecl
for arg in node.args
if arg.type == :(Ptr{Cvoid})
arg.type = :(Ptr{Cfloat})
end
end

if node.rettype == :(Ptr{Cvoid})
node.rettype = :(Ptr{Cfloat})
end
end
end
end

cd(@__DIR__)

include_dir = normpath(Exodus_jll.artifact_dir, "include")
Expand Down
118 changes: 49 additions & 69 deletions src/Blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,29 @@ TODO fix this to not use void_int... use a proper type
function read_block_id_map(exo::ExodusDatabase{M, I, B, F}, block_id) where {M, I, B, F}
_, num_elem, _, _, _, _ = read_block_parameters(exo, block_id)
block_id_map = Vector{get_map_int_type(exo)}(undef, num_elem)
error_code = @ccall libexodus.ex_get_block_id_map(
get_file_id(exo)::Cint, EX_ELEM_BLOCK::ex_entity_type, block_id::ex_entity_id, block_id_map::Ptr{B}
)::Cint
exodus_error_check(exo, error_code, "Exodus.read_element_block_id_map -> libexodus.ex_get_block_id_map")
error_code = LibExodus.ex_get_block_id_map(get_file_id(exo), EX_ELEM_BLOCK, block_id, block_id_map)
exodus_error_check(exo, error_code, "Exodus.read_element_block_id_map -> LibExodus.ex_get_block_id_map")
return block_id_map
end

"""
$(TYPEDSIGNATURES)
"""
function read_block_parameters(exo::ExodusDatabase{M, I, B, F}, block_id::Integer) where {M, I, B, F}
num_elem = Ref{B}(0)
num_nodes = Ref{B}(0)
num_edges = Ref{B}(0)
num_faces = Ref{B}(0)
num_attributes = Ref{B}(0)

element_type = Vector{UInt8}(undef, MAX_STR_LENGTH)

error_code = @ccall libexodus.ex_get_block(
get_file_id(exo)::Cint, EX_ELEM_BLOCK::ex_entity_type, block_id::ex_entity_id,
element_type::Ptr{UInt8},
num_elem::Ptr{B}, num_nodes::Ptr{B}, num_edges::Ptr{B},
num_faces::Ptr{B}, num_attributes::Ptr{B}
)::Cint
exodus_error_check(exo, error_code, "Exodus.read_element_block_parameters -> libexodus.ex_get_block")
num_elem = Base.RefValue{B}(0)
num_nodes = Base.RefValue{B}(0)
num_edges = Base.RefValue{B}(0)
num_faces = Base.RefValue{B}(0)
num_attributes = Base.RefValue{B}(0)
element_type = Vector{Cchar}(undef, MAX_STR_LENGTH)

error_code = LibExodus.ex_get_block(
get_file_id(exo), EX_ELEM_BLOCK, block_id,
pointer(element_type),
num_elem, num_nodes, num_edges,
num_faces, num_attributes
)
exodus_error_check(exo, error_code, "Exodus.read_element_block_parameters -> LibExodus.ex_get_block")
element_type_out = unsafe_string(pointer(element_type))
return element_type_out, num_elem[], num_nodes[], num_edges[], num_faces[], num_attributes[]
end
Expand All @@ -41,11 +38,11 @@ $(TYPEDSIGNATURES)
"""
function read_block_connectivity(exo::ExodusDatabase{M, I, B, F}, block_id::Integer, conn_length::Integer) where {M, I, B, F}
conn = Vector{B}(undef, conn_length)
error_code = @ccall libexodus.ex_get_conn(
get_file_id(exo)::Cint, EX_ELEM_BLOCK::ex_entity_type, block_id::ex_entity_id,
conn::Ptr{B}, C_NULL::Ptr{Cvoid}, C_NULL::Ptr{Cvoid}
)::Cint
exodus_error_check(exo, error_code, "Exodus.read_element_block_connectivity -> libexodus.ex_get_conn")
error_code = LibExodus.ex_get_conn(
get_file_id(exo), EX_ELEM_BLOCK, block_id,
conn, C_NULL, C_NULL
)
exodus_error_check(exo, error_code, "Exodus.read_element_block_connectivity -> LibExodus.ex_get_conn")
return conn
end

Expand All @@ -60,11 +57,11 @@ function write_block_connectivity(exo::ExodusDatabase, block_id::Integer, conn::
# TODO currently not using face or edges, should probably be there own methods maybe?
conn_face = C_NULL # Not using these currently
conn_edge = C_NULL # Not using these currently
error_code = @ccall libexodus.ex_put_conn(
get_file_id(exo)::Cint, EX_ELEM_BLOCK::ex_entity_type, block_id::ex_entity_id,
conn::Ptr{void_int}, conn_face::Ptr{void_int}, conn_edge::Ptr{void_int}
)::Cint
exodus_error_check(exo, error_code, "Exodus_write_block_connectivity -> libexodus.ex_put_conn")
error_code = LibExodus.ex_put_conn(
get_file_id(exo), EX_ELEM_BLOCK, block_id,
conn, conn_face, conn_edge
)
exodus_error_check(exo, error_code, "Exodus_write_block_connectivity -> LibExodus.ex_put_conn")
end

"""
Expand All @@ -76,24 +73,22 @@ function read_partial_block_connectivity(exo::ExodusDatabase, block_id::I, start
conn = Vector{get_bulk_int_type(exo)}(undef, num_nodes * num_ent)
conn_face = Vector{get_bulk_int_type(exo)}(undef, num_nodes * num_ent) # Not using these currently
conn_edge = Vector{get_bulk_int_type(exo)}(undef, num_nodes * num_ent) # Not using these currently
error_code = @ccall libexodus.ex_get_partial_conn(
get_file_id(exo)::Cint, EX_ELEM_BLOCK::ex_entity_type, block_id::ex_entity_id,
start_num::Clonglong, num_ent::Clonglong,
conn::Ptr{void_int}, conn_face::Ptr{void_int}, conn_edge::Ptr{void_int}
)::Cint
exodus_error_check(exo, error_code, "Exodus.read_partial_element_block_connectivity -> libexodus.ex_get_partial_conn")
error_code = LibExodus.ex_get_partial_conn(
get_file_id(exo), EX_ELEM_BLOCK, block_id,
start_num, num_ent,
conn, conn_face, conn_edge
)
exodus_error_check(exo, error_code, "Exodus.read_partial_element_block_connectivity -> LibExodus.ex_get_partial_conn")
return conn
end

"""
$(TYPEDSIGNATURES)
"""
function read_element_type(exo::ExodusDatabase, block_id::I) where I <: Integer
element_type = Vector{UInt8}(undef, MAX_STR_LENGTH)
error_code = @ccall libexodus.ex_get_elem_type(
get_file_id(exo)::Cint, block_id::ex_entity_id, element_type::Ptr{UInt8}
)::Cint
exodus_error_check(exo, error_code, "Exodus.read_element_type -> libexodus.ex_get_elem_type")
element_type = Vector{Cchar}(undef, MAX_STR_LENGTH)
error_code = LibExodus.ex_get_elem_type(get_file_id(exo), block_id, pointer(element_type))
exodus_error_check(exo, error_code, "Exodus.read_element_type -> LibExodus.ex_get_elem_type")
return unsafe_string(pointer(element_type))
end

Expand Down Expand Up @@ -144,13 +139,13 @@ WARNING:
currently does not support edges, faces and attributes
"""
function write_block(exo::ExodusDatabase, block::Block)
error_code = @ccall libexodus.ex_put_block(
get_file_id(exo)::Cint, EX_ELEM_BLOCK::ex_entity_type, block.id::ex_entity_id,
block.elem_type::Ptr{UInt8},
block.num_elem::Clonglong, block.num_nodes_per_elem::Clonglong,
0::Clonglong, 0::Clonglong, 0::Clonglong
)::Cint
exodus_error_check(exo, error_code, "Exodus.write_element_block -> libexodus.ex_put_block")
error_code = LibExodus.ex_put_block(
get_file_id(exo), EX_ELEM_BLOCK, block.id,
block.elem_type,
block.num_elem, block.num_nodes_per_elem,
0, 0, 0
)
exodus_error_check(exo, error_code, "Exodus.write_element_block -> LibExodus.ex_put_block")
write_block_connectivity(exo, block.id, block.conn)
end

Expand All @@ -160,13 +155,13 @@ $(TYPEDSIGNATURES)
function write_block(exo::ExodusDatabase, block_id::Integer, elem_type::String, conn::Matrix{I}) where I <: Integer
num_nodes_per_elem, num_elem = size(conn)
elem_type = uppercase(elem_type)
error_code = @ccall libexodus.ex_put_block(
get_file_id(exo)::Cint, EX_ELEM_BLOCK::ex_entity_type, block_id::ex_entity_id,
elem_type::Ptr{UInt8},
num_elem::Clonglong, num_nodes_per_elem::Clonglong,
0::Clonglong, 0::Clonglong, 0::Clonglong
)::Cint
exodus_error_check(exo, error_code, "Exodus.write_element_block -> libexodus.ex_put_block")
error_code = LibExodus.ex_put_block(
get_file_id(exo), EX_ELEM_BLOCK, block_id,
elem_type,
num_elem, num_nodes_per_elem,
0, 0, 0
)
exodus_error_check(exo, error_code, "Exodus.write_element_block -> LibExodus.ex_put_block")
write_block_connectivity(exo, block_id, conn)
end

Expand All @@ -178,18 +173,3 @@ function write_blocks(exo::ExodusDatabase, blocks::Vector{<:Block})
write_block(exo, block)
end
end

# # some tools below
# """
# TODO reduce allocations and check for type instabilities
# """
# function collect_block_connectivities(exo::ExodusDatabase, block_ids::Vector{<:Integer})
# blocks = Block.((exo,), block_ids)
# conns = [block.conn for block in blocks]
# return mapreduce(permutedims, vcat, conns)' |> collect
# end

# """
# """
# collect_block_connectivities(exo::ExodusDatabase) =
# collect_block_connectivities(exo, read_ids(exo, Block))
Loading
Loading