Skip to content

Commit

Permalink
Add source code of d3plot example
Browse files Browse the repository at this point in the history
  • Loading branch information
PucklaJ committed Feb 29, 2024
1 parent 03e4c0a commit 53beba4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ binout
d3plot
d3plot*
!examples/*
!examples/d3plot/d3plot.odin
examples/binout/binout0000
.xmake/
build/
Expand Down
61 changes: 61 additions & 0 deletions examples/d3plot/d3plot.odin
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import dro "../../."
import "core:c"
import "core:c/libc"
import "core:fmt"
import "core:os"

main :: proc() {
d := dro.d3plot_open("./examples/d3plot/d3plot")
defer dro.d3plot_close(&d)
if err := d.error_string; err != nil {
fmt.eprintf("failed to open d3plot: {}\n", err)
os.exit(1)
}

num_nodes: c.size_t
node_ids := dro.d3plot_read_node_ids(&d, &num_nodes)
defer libc.free(rawptr(node_ids))

fmt.printf("Number of Nodes: {}\n", num_nodes)
fmt.printf("[")
for i: c.size_t; i < num_nodes; i += 1 {
fmt.printf("{}", node_ids[i])
if i != num_nodes - 1 {
fmt.printf(", ")
}
}
fmt.printf("]\n")

num_shells: c.size_t
shell_ids := dro.d3plot_read_shell_element_ids(&d, &num_shells)
defer libc.free(rawptr(shell_ids))

fmt.printf("Num Shells: {}\n", num_shells)
fmt.printf("[")
for i: c.size_t; i < num_shells; i += 1 {
fmt.printf("{}", shell_ids[i])
if i != num_shells - 1 {
fmt.printf(", ")
}
}
fmt.printf("]\n")

fmt.printf("Num States: {}\n", d.num_states)
for i: c.size_t; i < d.num_states; i += 1 {
fmt.printf("State {}={}\n", i, dro.d3plot_read_time(&d, i))

num_els, num_his: c.size_t
shells := dro.d3plot_read_shells_state(&d, i, &num_els, &num_his)
defer dro.d3plot_free_shells_state(shells)

for j: c.size_t; j < num_els; j += 1 {
mean := dro.d3plot_get_shell_mean(&shells[j])
defer dro.d3plot_free_surface(mean)

fmt.printf("Shell {}={}: {}\n", j, shell_ids[j], mean.stress)
}
}
}

0 comments on commit 53beba4

Please sign in to comment.