From b03caffd9df633e1bc8f4aae2112cfcb565eb15b Mon Sep 17 00:00:00 2001 From: mrbuche Date: Tue, 31 Dec 2024 10:34:55 -0700 Subject: [PATCH] startup --- .github/CODE_OF_CONDUCT.md | 3 + .github/CONTRIBUTING.md | 28 + .github/ISSUE_TEMPLATE/bug_report.md | 38 + .github/ISSUE_TEMPLATE/feature_request.md | 20 + .github/SECURITY.md | 5 + .github/dependabot.yml | 6 + .github/pull_request_template.md | 15 + .github/workflows/Docs.yml | 63 + .github/workflows/TagBot.yml | 33 + .github/workflows/Test.yml | 21 + .gitignore | 5 + Project.toml | 29 + deps/build.jl | 3 + deps/conspire_wrapper/Cargo.toml | 21 + deps/conspire_wrapper/src/lib.rs | 1141 +++++++++++++++++ docs/Project.toml | 2 + docs/make.jl | 12 + docs/src/constitutive.md | 22 + docs/src/constitutive/elastic.md | 3 + .../src/constitutive/elastic/almansi_hamel.md | 31 + docs/src/constitutive/hyperelastic.md | 15 + .../constitutive/hyperelastic/arruda_boyce.md | 35 + docs/src/constitutive/hyperelastic/fung.md | 35 + docs/src/constitutive/hyperelastic/gent.md | 35 + .../hyperelastic/mooney_rivlin.md | 35 + .../constitutive/hyperelastic/neo_hookean.md | 35 + .../hyperelastic/saint_venant_kirchoff.md | 35 + docs/src/constitutive/hyperelastic/yeoh.md | 35 + docs/src/genindex.md | 4 + docs/src/index.md | 1 + src/Conspire.jl | 15 + src/constitutive.jl | 1 + src/constitutive/solid.jl | 2 + src/constitutive/solid/elastic.jl | 1 + .../solid/elastic/almansi_hamel.jl | 100 ++ src/constitutive/solid/hyperelastic.jl | 7 + .../solid/hyperelastic/arruda_boyce.jl | 122 ++ src/constitutive/solid/hyperelastic/fung.jl | 130 ++ src/constitutive/solid/hyperelastic/gent.jl | 146 +++ .../solid/hyperelastic/mooney_rivlin.jl | 122 ++ .../solid/hyperelastic/neo_hookean.jl | 114 ++ .../hyperelastic/saint_venant_kirchoff.jl | 120 ++ src/constitutive/solid/hyperelastic/yeoh.jl | 129 ++ test/constitutive.jl | 32 + test/constitutive/elastic.jl | 64 + test/constitutive/hyperelastic.jl | 78 ++ test/runtests.jl | 13 + 47 files changed, 2962 insertions(+) create mode 100644 .github/CODE_OF_CONDUCT.md create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/SECURITY.md create mode 100644 .github/dependabot.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/Docs.yml create mode 100644 .github/workflows/TagBot.yml create mode 100644 .github/workflows/Test.yml create mode 100644 .gitignore create mode 100644 Project.toml create mode 100644 deps/build.jl create mode 100644 deps/conspire_wrapper/Cargo.toml create mode 100644 deps/conspire_wrapper/src/lib.rs create mode 100644 docs/Project.toml create mode 100644 docs/make.jl create mode 100644 docs/src/constitutive.md create mode 100644 docs/src/constitutive/elastic.md create mode 100644 docs/src/constitutive/elastic/almansi_hamel.md create mode 100644 docs/src/constitutive/hyperelastic.md create mode 100644 docs/src/constitutive/hyperelastic/arruda_boyce.md create mode 100644 docs/src/constitutive/hyperelastic/fung.md create mode 100644 docs/src/constitutive/hyperelastic/gent.md create mode 100644 docs/src/constitutive/hyperelastic/mooney_rivlin.md create mode 100644 docs/src/constitutive/hyperelastic/neo_hookean.md create mode 100644 docs/src/constitutive/hyperelastic/saint_venant_kirchoff.md create mode 100644 docs/src/constitutive/hyperelastic/yeoh.md create mode 100644 docs/src/genindex.md create mode 120000 docs/src/index.md create mode 100644 src/Conspire.jl create mode 100644 src/constitutive.jl create mode 100644 src/constitutive/solid.jl create mode 100644 src/constitutive/solid/elastic.jl create mode 100644 src/constitutive/solid/elastic/almansi_hamel.jl create mode 100644 src/constitutive/solid/hyperelastic.jl create mode 100644 src/constitutive/solid/hyperelastic/arruda_boyce.jl create mode 100644 src/constitutive/solid/hyperelastic/fung.jl create mode 100644 src/constitutive/solid/hyperelastic/gent.jl create mode 100644 src/constitutive/solid/hyperelastic/mooney_rivlin.jl create mode 100644 src/constitutive/solid/hyperelastic/neo_hookean.jl create mode 100644 src/constitutive/solid/hyperelastic/saint_venant_kirchoff.jl create mode 100644 src/constitutive/solid/hyperelastic/yeoh.jl create mode 100644 test/constitutive.jl create mode 100644 test/constitutive/elastic.jl create mode 100644 test/constitutive/hyperelastic.jl create mode 100644 test/runtests.jl diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..cc0d752 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,3 @@ +# Code of Conduct + +Don't be a jerk! diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..6f288a8 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,28 @@ +# Contributing + +Contributors can open issues or create pull requests. + +## Issues + +Contributors can open new issues on the GitHub repository [here](https://github.com/mrbuche/Conspire.jl/issues). An issue can either report an existing bug, or request a new feature. Contributors should ensure that their candidate issue does not match an existing open issue before opening it. If a closely-related but incomplete open issue exists, contributors should comment on the existing open issue. + +### Bug Reports + +A new bug report can be opened [here](https://github.com/mrbuche/Conspire.jl/issues/new?template=bug_report.md). + +### Feature Requests + +A new feature request can be opened [here](https://github.com/mrbuche/Conspire.jl/issues/new?template=feature_request.md). Feature requests that are deemed feasible will be considered by the developers, and could even be addressed by a contributor through a pull request. Feature requests that are deemed infeasible will likely be denied. + +## Pull Requests + +Contributors can propose changes to the code in the repository by creating a pull request as follows: + +- Fork the base repository [here](https://github.com/mrbuche/Conspire.jl/fork). +- Clone the forked repository, make changes, and push them back to the fork. +- Create a pull request between the base and forked repositories [here](https://github.com/mrbuche/Conspire.jl/pulls). +- Wait for the pull request to be either approved or dismissed. Approval and subsequent merging of pull requests is contingent upon: + + - The tests are all passing, resulting in a high (desirably, complete) code coverage, and any changes are properly tested. + - The documentation is successfully built, and any changes are properly documented. + - The changes provide an appropriate and substantial improvement to the repository. diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000..24a97b1 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,5 @@ +# Security Policy + +## Reporting a Vulnerability + +If there are any vulnerabilities, do not hesitate to report them, but please report them privately. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..1230149 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..b489c2a --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,15 @@ +# Pull Request Template + +This template should be used for making any pull requests. + +## Goal + +Here, describe the goal of the pull request, i.e. what does it seek to address? Does this pull request fix an existing bug, or create a new feature? Why are the changes proposed by this pull request necessary? + +## Specifics + +Here, describe the specific changes to the repository suggested by this pull request. Which modules/methods/etc. were added or edited, and why? Have any new dependencies been introduced, and why? + +## Verification + +Here, describe steps taken to verify that the pull request is up to the standards of the repository. Were the suggested changes fully documented and tested, and do they match the existing code style? How exactly was this verification completed? diff --git a/.github/workflows/Docs.yml b/.github/workflows/Docs.yml new file mode 100644 index 0000000..d81981b --- /dev/null +++ b/.github/workflows/Docs.yml @@ -0,0 +1,63 @@ +name: Docs +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + release: + types: [ "published" ] +permissions: + contents: read + pages: write + id-token: write +concurrency: + group: "Docs" + cancel-in-progress: true +jobs: + Build: + runs-on: ubuntu-latest + steps: + - name: Get last release + id: last_release + uses: InsonusK/get-latest-release@v1.1.0 + with: + myToken: ${{ github.token }} + view_top: 1 + - name: Julia + uses: julia-actions/setup-julia@v2 + with: + version: '1.9' + - name: Dependencies + run: julia --color=yes -e 'using Pkg; Pkg.add(["DocStringExtensions", "Documenter"])' + - name: Checkout stable + uses: actions/checkout@v4 + with: + ref: ${{ steps.last_release.outputs.tag_name }} + - name: Stable + run: | + julia --color=yes -e 'using Pkg; Pkg.develop(path="."); Pkg.build("Conspire")' + julia --color=yes docs/make.jl + mkdir -p ../_site/stable/ + cp -r docs/build/* ../_site/stable/ + - name: Checkout latest + uses: actions/checkout@v4 + - name: Latest + run: | + julia --color=yes -e 'using Pkg; Pkg.develop(path="."); Pkg.build("Conspire")' + julia --color=yes docs/make.jl + mkdir -p ../_site/latest/ + cp -r docs/build/* ../_site/latest/ + - name: Upload + uses: actions/upload-pages-artifact@v3 + with: + path: ../_site/ + Deploy: + if: github.event_name != 'pull_request' + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: Build + steps: + - id: deployment + uses: actions/deploy-pages@v4 \ No newline at end of file diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml new file mode 100644 index 0000000..3042569 --- /dev/null +++ b/.github/workflows/TagBot.yml @@ -0,0 +1,33 @@ +name: TagBot +on: + issue_comment: + types: + - created + workflow_dispatch: + inputs: + lookback: + default: 3 +permissions: + actions: read + checks: read + contents: write + deployments: read + issues: read + discussions: read + packages: read + pages: read + pull-requests: read + repository-projects: read + security-events: read + statuses: read +jobs: + TagBot: + if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' + runs-on: ubuntu-latest + steps: + - uses: JuliaRegistries/TagBot@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + # Edit the following line to reflect the actual name of the GitHub Secret containing your private key + ssh: ${{ secrets.DOCUMENTER_KEY }} + # ssh: ${{ secrets.NAME_OF_MY_SSH_PRIVATE_KEY_SECRET }} \ No newline at end of file diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml new file mode 100644 index 0000000..a6ec977 --- /dev/null +++ b/.github/workflows/Test.yml @@ -0,0 +1,21 @@ +name: Test +on: + pull_request: + branches: [ main ] +jobs: + Julia: + strategy: + fail-fast: false + matrix: + julia-version: [1.10.0, 1.11.0] + os: [macos-latest, ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Julia + uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.julia-version }} + - name: Test + run: julia --color=yes -e 'using Pkg; Pkg.develop(path="."); Pkg.build("Conspire"); Pkg.test("Conspire")' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2372bed --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +deps/build.log +deps/conspire_wrapper/Cargo.lock +deps/conspire_wrapper/target/ +docs/build/ +.vscode \ No newline at end of file diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..8528c20 --- /dev/null +++ b/Project.toml @@ -0,0 +1,29 @@ +name = "Conspire" +uuid = "e166284d-f01f-4403-abd1-910b06ed061e" +authors = ["Michael R. Buche "] +version = "0.1.0" + +[deps] +DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" + +[compat] +Aqua = "0" +DocStringExtensions = "0.9" +Documenter = "1" +JET = "0" +JuliaFormatter = "1" +LinearAlgebra = "1" +Test = "1" +julia = "1" + +[extras] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" +JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +docs = ["Documenter", "DocStringExtensions"] +test = ["Aqua", "JET", "JuliaFormatter", "LinearAlgebra", "Test"] diff --git a/deps/build.jl b/deps/build.jl new file mode 100644 index 0000000..94a9977 --- /dev/null +++ b/deps/build.jl @@ -0,0 +1,3 @@ +cd("conspire_wrapper") +run(`cargo clippy --release -- -D warnings`) +run(`cargo build --release`) diff --git a/deps/conspire_wrapper/Cargo.toml b/deps/conspire_wrapper/Cargo.toml new file mode 100644 index 0000000..3b926cf --- /dev/null +++ b/deps/conspire_wrapper/Cargo.toml @@ -0,0 +1,21 @@ +[package] +authors = ["Michael R. Buche "] +categories = ["mathematics", "science"] +description = "c o n s p i r e" +edition = "2021" +keywords = ["conspire", "mrbuche"] +license = "GPL-3.0" +name = "conspire_wrapper" +version = "0.1.0" + +[dependencies] +conspire = { features = ["constitutive"], git = "https://github.com/mrbuche/conspire.rs.git", rev = "a0ea82466d9e1b6cb4711ef121dde926673dc50f" } + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +lto = true +panic = "abort" +strip = "symbols" diff --git a/deps/conspire_wrapper/src/lib.rs b/deps/conspire_wrapper/src/lib.rs new file mode 100644 index 0000000..6f854f8 --- /dev/null +++ b/deps/conspire_wrapper/src/lib.rs @@ -0,0 +1,1141 @@ +use conspire:: +{ + constitutive:: + { + Constitutive, + solid:: + { + elastic:: + { + Elastic, + AlmansiHamel + }, + hyperelastic:: + { + Hyperelastic, + ArrudaBoyce, + Fung, + Gent, + MooneyRivlin, + NeoHookean, + SaintVenantKirchoff, + Yeoh, + } + } + }, + math::TensorArray, + mechanics:: + { + DeformationGradient, + Scalar + } +}; +use std::slice::from_raw_parts; + +#[no_mangle] +unsafe extern fn almansi_hamel_cauchy_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + AlmansiHamel::new( + &[bulk_modulus, shear_modulus] + ).calculate_cauchy_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn almansi_hamel_cauchy_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + AlmansiHamel::new( + &[bulk_modulus, shear_modulus] + ).calculate_cauchy_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn almansi_hamel_first_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + AlmansiHamel::new( + &[bulk_modulus, shear_modulus] + ).calculate_first_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn almansi_hamel_first_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + AlmansiHamel::new( + &[bulk_modulus, shear_modulus] + ).calculate_first_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn almansi_hamel_second_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + AlmansiHamel::new( + &[bulk_modulus, shear_modulus] + ).calculate_second_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn almansi_hamel_second_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + AlmansiHamel::new( + &[bulk_modulus, shear_modulus] + ).calculate_second_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn arruda_boyce_cauchy_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + number_of_links: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + ArrudaBoyce::new( + &[bulk_modulus, shear_modulus, number_of_links] + ).calculate_cauchy_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn arruda_boyce_cauchy_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + number_of_links: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + ArrudaBoyce::new( + &[bulk_modulus, shear_modulus, number_of_links] + ).calculate_cauchy_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn arruda_boyce_first_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + number_of_links: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + ArrudaBoyce::new( + &[bulk_modulus, shear_modulus, number_of_links] + ).calculate_first_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn arruda_boyce_first_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + number_of_links: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + ArrudaBoyce::new( + &[bulk_modulus, shear_modulus, number_of_links] + ).calculate_first_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn arruda_boyce_second_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + number_of_links: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + ArrudaBoyce::new( + &[bulk_modulus, shear_modulus, number_of_links] + ).calculate_second_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn arruda_boyce_second_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + number_of_links: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + ArrudaBoyce::new( + &[bulk_modulus, shear_modulus, number_of_links] + ).calculate_second_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn arruda_boyce_helmholtz_free_energy_density( + bulk_modulus: Scalar, + shear_modulus: Scalar, + number_of_links: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> Scalar { + ArrudaBoyce::new( + &[bulk_modulus, shear_modulus, number_of_links] + ).calculate_helmholtz_free_energy_density( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap() +} + +#[no_mangle] +unsafe extern fn gent_cauchy_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extensibility: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + Gent::new( + &[bulk_modulus, shear_modulus, extensibility] + ).calculate_cauchy_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn gent_cauchy_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extensibility: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + Gent::new( + &[bulk_modulus, shear_modulus, extensibility] + ).calculate_cauchy_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn gent_first_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extensibility: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + Gent::new( + &[bulk_modulus, shear_modulus, extensibility] + ).calculate_first_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn gent_first_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extensibility: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + Gent::new( + &[bulk_modulus, shear_modulus, extensibility] + ).calculate_first_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn gent_second_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extensibility: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + Gent::new( + &[bulk_modulus, shear_modulus, extensibility] + ).calculate_second_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn gent_second_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extensibility: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + Gent::new( + &[bulk_modulus, shear_modulus, extensibility] + ).calculate_second_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn gent_helmholtz_free_energy_density( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extensibility: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> Scalar { + Gent::new( + &[bulk_modulus, shear_modulus, extensibility] + ).calculate_helmholtz_free_energy_density( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap() +} + +#[no_mangle] +unsafe extern fn mooney_rivlin_cauchy_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + MooneyRivlin::new( + &[bulk_modulus, shear_modulus, extra_modulus] + ).calculate_cauchy_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn mooney_rivlin_cauchy_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + MooneyRivlin::new( + &[bulk_modulus, shear_modulus, extra_modulus] + ).calculate_cauchy_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn mooney_rivlin_first_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + MooneyRivlin::new( + &[bulk_modulus, shear_modulus, extra_modulus] + ).calculate_first_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn mooney_rivlin_first_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + MooneyRivlin::new( + &[bulk_modulus, shear_modulus, extra_modulus] + ).calculate_first_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn mooney_rivlin_second_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + MooneyRivlin::new( + &[bulk_modulus, shear_modulus, extra_modulus] + ).calculate_second_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn mooney_rivlin_second_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + MooneyRivlin::new( + &[bulk_modulus, shear_modulus, extra_modulus] + ).calculate_second_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn mooney_rivlin_helmholtz_free_energy_density( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> Scalar { + MooneyRivlin::new( + &[bulk_modulus, shear_modulus, extra_modulus] + ).calculate_helmholtz_free_energy_density( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap() +} + +#[no_mangle] +unsafe extern fn neo_hookean_cauchy_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + NeoHookean::new( + &[bulk_modulus, shear_modulus] + ).calculate_cauchy_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn neo_hookean_cauchy_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + NeoHookean::new( + &[bulk_modulus, shear_modulus] + ).calculate_cauchy_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn neo_hookean_first_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + NeoHookean::new( + &[bulk_modulus, shear_modulus] + ).calculate_first_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn neo_hookean_first_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + NeoHookean::new( + &[bulk_modulus, shear_modulus] + ).calculate_first_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn neo_hookean_second_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + NeoHookean::new( + &[bulk_modulus, shear_modulus] + ).calculate_second_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn neo_hookean_second_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + NeoHookean::new( + &[bulk_modulus, shear_modulus] + ).calculate_second_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn neo_hookean_helmholtz_free_energy_density( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> Scalar { + NeoHookean::new( + &[bulk_modulus, shear_modulus] + ).calculate_helmholtz_free_energy_density( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap() +} + +#[no_mangle] +unsafe extern fn saint_venant_kirchoff_cauchy_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + SaintVenantKirchoff::new( + &[bulk_modulus, shear_modulus] + ).calculate_cauchy_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn saint_venant_kirchoff_cauchy_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + SaintVenantKirchoff::new( + &[bulk_modulus, shear_modulus] + ).calculate_cauchy_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn saint_venant_kirchoff_first_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + SaintVenantKirchoff::new( + &[bulk_modulus, shear_modulus] + ).calculate_first_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn saint_venant_kirchoff_first_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + SaintVenantKirchoff::new( + &[bulk_modulus, shear_modulus] + ).calculate_first_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn saint_venant_kirchoff_second_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + SaintVenantKirchoff::new( + &[bulk_modulus, shear_modulus] + ).calculate_second_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn saint_venant_kirchoff_second_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + SaintVenantKirchoff::new( + &[bulk_modulus, shear_modulus] + ).calculate_second_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn saint_venant_kirchoff_helmholtz_free_energy_density( + bulk_modulus: Scalar, + shear_modulus: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> Scalar { + SaintVenantKirchoff::new( + &[bulk_modulus, shear_modulus] + ).calculate_helmholtz_free_energy_density( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap() +} + +#[no_mangle] +unsafe extern fn fung_cauchy_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + exponent: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + Fung::new( + &[bulk_modulus, shear_modulus, extra_modulus, exponent] + ).calculate_cauchy_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn fung_cauchy_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + exponent: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + Fung::new( + &[bulk_modulus, shear_modulus, extra_modulus, exponent] + ).calculate_cauchy_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn fung_first_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + exponent: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + Fung::new( + &[bulk_modulus, shear_modulus, extra_modulus, exponent] + ).calculate_first_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn fung_first_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + exponent: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + Fung::new( + &[bulk_modulus, shear_modulus, extra_modulus, exponent] + ).calculate_first_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn fung_second_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + exponent: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + Fung::new( + &[bulk_modulus, shear_modulus, extra_modulus, exponent] + ).calculate_second_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn fung_second_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + exponent: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + Fung::new( + &[bulk_modulus, shear_modulus, extra_modulus, exponent] + ).calculate_second_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn fung_helmholtz_free_energy_density( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_modulus: Scalar, + exponent: Scalar, + deformation_gradient: *const [[Scalar; 3]; 3] +) -> Scalar { + Fung::new( + &[bulk_modulus, shear_modulus, extra_modulus, exponent] + ).calculate_helmholtz_free_energy_density( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap() +} + +#[no_mangle] +unsafe extern fn yeoh_cauchy_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_moduli: *const Scalar, + len_extra_moduli: usize, + deformation_gradient: *const [[Scalar; 3]; 3], +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + Yeoh::new( + &[ + &[bulk_modulus], &[shear_modulus], from_raw_parts( + extra_moduli, len_extra_moduli + ) + ].concat() + ).calculate_cauchy_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn yeoh_cauchy_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_moduli: *const Scalar, + len_extra_moduli: usize, + deformation_gradient: *const [[Scalar; 3]; 3], +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + Yeoh::new( + &[ + &[bulk_modulus], &[shear_modulus], from_raw_parts( + extra_moduli, len_extra_moduli + ) + ].concat() + ).calculate_cauchy_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn yeoh_first_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_moduli: *const Scalar, + len_extra_moduli: usize, + deformation_gradient: *const [[Scalar; 3]; 3], +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + Yeoh::new( + &[ + &[bulk_modulus], &[shear_modulus], from_raw_parts( + extra_moduli, len_extra_moduli + ) + ].concat() + ).calculate_first_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn yeoh_first_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_moduli: *const Scalar, + len_extra_moduli: usize, + deformation_gradient: *const [[Scalar; 3]; 3], +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + Yeoh::new( + &[ + &[bulk_modulus], &[shear_modulus], from_raw_parts( + extra_moduli, len_extra_moduli + ) + ].concat() + ).calculate_first_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn yeoh_second_piola_kirchoff_stress( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_moduli: *const Scalar, + len_extra_moduli: usize, + deformation_gradient: *const [[Scalar; 3]; 3], +) -> *const [[Scalar; 3]; 3] { + Box::into_raw(Box::new( + Yeoh::new( + &[ + &[bulk_modulus], &[shear_modulus], from_raw_parts( + extra_moduli, len_extra_moduli + ) + ].concat() + ).calculate_second_piola_kirchoff_stress( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn yeoh_second_piola_kirchoff_tangent_stiffness( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_moduli: *const Scalar, + len_extra_moduli: usize, + deformation_gradient: *const [[Scalar; 3]; 3], +) -> *const [[[[Scalar; 3]; 3]; 3]; 3] { + Box::into_raw(Box::new( + Yeoh::new( + &[ + &[bulk_modulus], &[shear_modulus], from_raw_parts( + extra_moduli, len_extra_moduli + ) + ].concat() + ).calculate_second_piola_kirchoff_tangent_stiffness( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap().as_array() + )) +} + +#[no_mangle] +unsafe extern fn yeoh_helmholtz_free_energy_density( + bulk_modulus: Scalar, + shear_modulus: Scalar, + extra_moduli: *const Scalar, + len_extra_moduli: usize, + deformation_gradient: *const [[Scalar; 3]; 3], +) -> Scalar { + Yeoh::new( + &[ + &[bulk_modulus], &[shear_modulus], from_raw_parts( + extra_moduli, len_extra_moduli + ) + ].concat() + ).calculate_helmholtz_free_energy_density( + &DeformationGradient::new( + from_raw_parts( + deformation_gradient, 9 + )[0] + ) + ).unwrap() +} diff --git a/docs/Project.toml b/docs/Project.toml new file mode 100644 index 0000000..becf5a3 --- /dev/null +++ b/docs/Project.toml @@ -0,0 +1,2 @@ +[deps] +Conspire = "e166284d-f01f-4403-abd1-910b06ed061e" diff --git a/docs/make.jl b/docs/make.jl new file mode 100644 index 0000000..b32081c --- /dev/null +++ b/docs/make.jl @@ -0,0 +1,12 @@ +using Conspire, Documenter + +makedocs( + format = Documenter.HTML(), + modules = [Conspire], + pages = [ + "Home" => "index.md", + "Constitutive" => "constitutive.md", + "Index" => "genindex.md", + ], + sitename = "Conspire.jl", +) diff --git a/docs/src/constitutive.md b/docs/src/constitutive.md new file mode 100644 index 0000000..a625200 --- /dev/null +++ b/docs/src/constitutive.md @@ -0,0 +1,22 @@ +# Constitutive + +* [Elastic](constitutive/elastic.md) +* [Hyperelastic](constitutive/hyperelastic.md) + +## Functions + +```@docs +cauchy_stress +``` + +```@docs +cauchy_tangent_stiffness +``` + +```@docs +first_piola_kirchoff_stress +``` + +```@docs +first_piola_kirchoff_tangent_stiffness +``` diff --git a/docs/src/constitutive/elastic.md b/docs/src/constitutive/elastic.md new file mode 100644 index 0000000..e75b633 --- /dev/null +++ b/docs/src/constitutive/elastic.md @@ -0,0 +1,3 @@ +# Elastic + +* [Almansi-Hamel](elastic/almansi_hamel.md) diff --git a/docs/src/constitutive/elastic/almansi_hamel.md b/docs/src/constitutive/elastic/almansi_hamel.md new file mode 100644 index 0000000..4318189 --- /dev/null +++ b/docs/src/constitutive/elastic/almansi_hamel.md @@ -0,0 +1,31 @@ +# Almansi-Hamel + +```@docs +AlmansiHamel +``` + +## Methods + +```@docs +cauchy_stress(model::AlmansiHamel, F) +``` + +```@docs +cauchy_tangent_stiffness(model::AlmansiHamel, F) +``` + +```@docs +first_piola_kirchoff_stress(model::AlmansiHamel, F) +``` + +```@docs +first_piola_kirchoff_tangent_stiffness(model::AlmansiHamel, F) +``` + +```@docs +second_piola_kirchoff_stress(model::AlmansiHamel, F) +``` + +```@docs +second_piola_kirchoff_tangent_stiffness(model::AlmansiHamel, F) +``` diff --git a/docs/src/constitutive/hyperelastic.md b/docs/src/constitutive/hyperelastic.md new file mode 100644 index 0000000..c776a16 --- /dev/null +++ b/docs/src/constitutive/hyperelastic.md @@ -0,0 +1,15 @@ +# Hyperelastic + +* [Arruda-Boyce](hyperelastic/arruda_boyce.md) +* [Fung](hyperelastic/fung.md) +* [Gent](hyperelastic/gent.md) +* [Mooney-Rivlin](hyperelastic/mooney_rivlin.md) +* [Neo-Hookean](hyperelastic/neo_hookean.md) +* [Saint Venant-Kirchoff](hyperelastic/saint_venant_kirchoff.md) +* [Yeoh](hyperelastic/yeoh.md) + +## Functions + +```@docs +helmholtz_free_energy_density +``` diff --git a/docs/src/constitutive/hyperelastic/arruda_boyce.md b/docs/src/constitutive/hyperelastic/arruda_boyce.md new file mode 100644 index 0000000..8db9ede --- /dev/null +++ b/docs/src/constitutive/hyperelastic/arruda_boyce.md @@ -0,0 +1,35 @@ +# Arruda-Boyce + +```@docs +ArrudaBoyce +``` + +## Methods + +```@docs +cauchy_stress(model::ArrudaBoyce, F) +``` + +```@docs +cauchy_tangent_stiffness(model::ArrudaBoyce, F) +``` + +```@docs +first_piola_kirchoff_stress(model::ArrudaBoyce, F) +``` + +```@docs +first_piola_kirchoff_tangent_stiffness(model::ArrudaBoyce, F) +``` + +```@docs +second_piola_kirchoff_stress(model::ArrudaBoyce, F) +``` + +```@docs +second_piola_kirchoff_tangent_stiffness(model::ArrudaBoyce, F) +``` + +```@docs +helmholtz_free_energy_density(model::ArrudaBoyce, F) +``` diff --git a/docs/src/constitutive/hyperelastic/fung.md b/docs/src/constitutive/hyperelastic/fung.md new file mode 100644 index 0000000..eab84ed --- /dev/null +++ b/docs/src/constitutive/hyperelastic/fung.md @@ -0,0 +1,35 @@ +# Fung + +```@docs +Fung +``` + +## Methods + +```@docs +cauchy_stress(model::Fung, F) +``` + +```@docs +cauchy_tangent_stiffness(model::Fung, F) +``` + +```@docs +first_piola_kirchoff_stress(model::Fung, F) +``` + +```@docs +first_piola_kirchoff_tangent_stiffness(model::Fung, F) +``` + +```@docs +second_piola_kirchoff_stress(model::Fung, F) +``` + +```@docs +second_piola_kirchoff_tangent_stiffness(model::Fung, F) +``` + +```@docs +helmholtz_free_energy_density(model::Fung, F) +``` diff --git a/docs/src/constitutive/hyperelastic/gent.md b/docs/src/constitutive/hyperelastic/gent.md new file mode 100644 index 0000000..22499a5 --- /dev/null +++ b/docs/src/constitutive/hyperelastic/gent.md @@ -0,0 +1,35 @@ +# Gent + +```@docs +Gent +``` + +## Methods + +```@docs +cauchy_stress(model::Gent, F) +``` + +```@docs +cauchy_tangent_stiffness(model::Gent, F) +``` + +```@docs +first_piola_kirchoff_stress(model::Gent, F) +``` + +```@docs +first_piola_kirchoff_tangent_stiffness(model::Gent, F) +``` + +```@docs +second_piola_kirchoff_stress(model::Gent, F) +``` + +```@docs +second_piola_kirchoff_tangent_stiffness(model::Gent, F) +``` + +```@docs +helmholtz_free_energy_density(model::Gent, F) +``` diff --git a/docs/src/constitutive/hyperelastic/mooney_rivlin.md b/docs/src/constitutive/hyperelastic/mooney_rivlin.md new file mode 100644 index 0000000..e64aebd --- /dev/null +++ b/docs/src/constitutive/hyperelastic/mooney_rivlin.md @@ -0,0 +1,35 @@ +# Mooney-Rivlin + +```@docs +MooneyRivlin +``` + +## Methods + +```@docs +cauchy_stress(model::MooneyRivlin, F) +``` + +```@docs +cauchy_tangent_stiffness(model::MooneyRivlin, F) +``` + +```@docs +first_piola_kirchoff_stress(model::MooneyRivlin, F) +``` + +```@docs +first_piola_kirchoff_tangent_stiffness(model::MooneyRivlin, F) +``` + +```@docs +second_piola_kirchoff_stress(model::MooneyRivlin, F) +``` + +```@docs +second_piola_kirchoff_tangent_stiffness(model::MooneyRivlin, F) +``` + +```@docs +helmholtz_free_energy_density(model::MooneyRivlin, F) +``` diff --git a/docs/src/constitutive/hyperelastic/neo_hookean.md b/docs/src/constitutive/hyperelastic/neo_hookean.md new file mode 100644 index 0000000..8a8d16c --- /dev/null +++ b/docs/src/constitutive/hyperelastic/neo_hookean.md @@ -0,0 +1,35 @@ +# Neo-Hookean + +```@docs +NeoHookean +``` + +## Methods + +```@docs +cauchy_stress(model::NeoHookean, F) +``` + +```@docs +cauchy_tangent_stiffness(model::NeoHookean, F) +``` + +```@docs +first_piola_kirchoff_stress(model::NeoHookean, F) +``` + +```@docs +first_piola_kirchoff_tangent_stiffness(model::NeoHookean, F) +``` + +```@docs +second_piola_kirchoff_stress(model::NeoHookean, F) +``` + +```@docs +second_piola_kirchoff_tangent_stiffness(model::NeoHookean, F) +``` + +```@docs +helmholtz_free_energy_density(model::NeoHookean, F) +``` diff --git a/docs/src/constitutive/hyperelastic/saint_venant_kirchoff.md b/docs/src/constitutive/hyperelastic/saint_venant_kirchoff.md new file mode 100644 index 0000000..709e115 --- /dev/null +++ b/docs/src/constitutive/hyperelastic/saint_venant_kirchoff.md @@ -0,0 +1,35 @@ +# Saint Venant-Kirchoff + +```@docs +SaintVenantKirchoff +``` + +## Methods + +```@docs +cauchy_stress(model::SaintVenantKirchoff, F) +``` + +```@docs +cauchy_tangent_stiffness(model::SaintVenantKirchoff, F) +``` + +```@docs +first_piola_kirchoff_stress(model::SaintVenantKirchoff, F) +``` + +```@docs +first_piola_kirchoff_tangent_stiffness(model::SaintVenantKirchoff, F) +``` + +```@docs +second_piola_kirchoff_stress(model::SaintVenantKirchoff, F) +``` + +```@docs +second_piola_kirchoff_tangent_stiffness(model::SaintVenantKirchoff, F) +``` + +```@docs +helmholtz_free_energy_density(model::SaintVenantKirchoff, F) +``` diff --git a/docs/src/constitutive/hyperelastic/yeoh.md b/docs/src/constitutive/hyperelastic/yeoh.md new file mode 100644 index 0000000..02ef315 --- /dev/null +++ b/docs/src/constitutive/hyperelastic/yeoh.md @@ -0,0 +1,35 @@ +# Yeoh + +```@docs +Yeoh +``` + +## Methods + +```@docs +cauchy_stress(model::Yeoh, F) +``` + +```@docs +cauchy_tangent_stiffness(model::Yeoh, F) +``` + +```@docs +first_piola_kirchoff_stress(model::Yeoh, F) +``` + +```@docs +first_piola_kirchoff_tangent_stiffness(model::Yeoh, F) +``` + +```@docs +second_piola_kirchoff_stress(model::Yeoh, F) +``` + +```@docs +second_piola_kirchoff_tangent_stiffness(model::Yeoh, F) +``` + +```@docs +helmholtz_free_energy_density(model::Yeoh, F) +``` diff --git a/docs/src/genindex.md b/docs/src/genindex.md new file mode 100644 index 0000000..aa651b9 --- /dev/null +++ b/docs/src/genindex.md @@ -0,0 +1,4 @@ +# Index + +```@index +``` diff --git a/docs/src/index.md b/docs/src/index.md new file mode 120000 index 0000000..fe84005 --- /dev/null +++ b/docs/src/index.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/src/Conspire.jl b/src/Conspire.jl new file mode 100644 index 0000000..ea00733 --- /dev/null +++ b/src/Conspire.jl @@ -0,0 +1,15 @@ +module Conspire + +const CONSPIRE_WRAPPER = string(dirname(@__FILE__), "/../deps/conspire_wrapper/") +const CONSPIRE_WRAPPER_LIB = string(CONSPIRE_WRAPPER, "target/release/libconspire_wrapper") + +include("constitutive.jl") + +export cauchy_stress, cauchy_tangent_stiffness +export first_piola_kirchoff_stress, first_piola_kirchoff_tangent_stiffness +export second_piola_kirchoff_stress, second_piola_kirchoff_tangent_stiffness +export helmholtz_free_energy_density +export AlmansiHamel +export ArrudaBoyce, Fung, Gent, MooneyRivlin, NeoHookean, SaintVenantKirchoff, Yeoh + +end diff --git a/src/constitutive.jl b/src/constitutive.jl new file mode 100644 index 0000000..d1a69db --- /dev/null +++ b/src/constitutive.jl @@ -0,0 +1 @@ +include("constitutive/solid.jl") diff --git a/src/constitutive/solid.jl b/src/constitutive/solid.jl new file mode 100644 index 0000000..66ec247 --- /dev/null +++ b/src/constitutive/solid.jl @@ -0,0 +1,2 @@ +include("solid/elastic.jl") +include("solid/hyperelastic.jl") diff --git a/src/constitutive/solid/elastic.jl b/src/constitutive/solid/elastic.jl new file mode 100644 index 0000000..bd9d9f8 --- /dev/null +++ b/src/constitutive/solid/elastic.jl @@ -0,0 +1 @@ +include("elastic/almansi_hamel.jl") diff --git a/src/constitutive/solid/elastic/almansi_hamel.jl b/src/constitutive/solid/elastic/almansi_hamel.jl new file mode 100644 index 0000000..7e65ca1 --- /dev/null +++ b/src/constitutive/solid/elastic/almansi_hamel.jl @@ -0,0 +1,100 @@ +using DocStringExtensions + +""" +**Parameters** +$(FIELDS) +""" +struct AlmansiHamel + κ::Real + μ::Real +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_stress(model::AlmansiHamel, F) + raw = ccall( + (:almansi_hamel_cauchy_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_tangent_stiffness(model::AlmansiHamel, F) + raw = ccall( + (:almansi_hamel_cauchy_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_stress(model::AlmansiHamel, F) + raw = ccall( + (:almansi_hamel_first_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_tangent_stiffness(model::AlmansiHamel, F) + raw = ccall( + (:almansi_hamel_first_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_stress(model::AlmansiHamel, F) + raw = ccall( + (:almansi_hamel_second_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_tangent_stiffness(model::AlmansiHamel, F) + raw = ccall( + (:almansi_hamel_second_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end diff --git a/src/constitutive/solid/hyperelastic.jl b/src/constitutive/solid/hyperelastic.jl new file mode 100644 index 0000000..560088d --- /dev/null +++ b/src/constitutive/solid/hyperelastic.jl @@ -0,0 +1,7 @@ +include("hyperelastic/arruda_boyce.jl") +include("hyperelastic/fung.jl") +include("hyperelastic/gent.jl") +include("hyperelastic/mooney_rivlin.jl") +include("hyperelastic/neo_hookean.jl") +include("hyperelastic/saint_venant_kirchoff.jl") +include("hyperelastic/yeoh.jl") diff --git a/src/constitutive/solid/hyperelastic/arruda_boyce.jl b/src/constitutive/solid/hyperelastic/arruda_boyce.jl new file mode 100644 index 0000000..841662b --- /dev/null +++ b/src/constitutive/solid/hyperelastic/arruda_boyce.jl @@ -0,0 +1,122 @@ +using DocStringExtensions + +""" +**Parameters** +$(FIELDS) +""" +struct ArrudaBoyce + κ::Real + μ::Real + N::Real +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_stress(model::ArrudaBoyce, F) + raw = ccall( + (:arruda_boyce_cauchy_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.N, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_tangent_stiffness(model::ArrudaBoyce, F) + raw = ccall( + (:arruda_boyce_cauchy_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.N, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_stress(model::ArrudaBoyce, F) + raw = ccall( + (:arruda_boyce_first_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.N, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_tangent_stiffness(model::ArrudaBoyce, F) + raw = ccall( + (:arruda_boyce_first_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.N, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_stress(model::ArrudaBoyce, F) + raw = ccall( + (:arruda_boyce_second_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.N, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_tangent_stiffness(model::ArrudaBoyce, F) + raw = ccall( + (:arruda_boyce_second_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.N, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function helmholtz_free_energy_density(model::ArrudaBoyce, F) + return ccall( + (:arruda_boyce_helmholtz_free_energy_density, CONSPIRE_WRAPPER_LIB), + Float64, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.N, + F, + ) +end diff --git a/src/constitutive/solid/hyperelastic/fung.jl b/src/constitutive/solid/hyperelastic/fung.jl new file mode 100644 index 0000000..c36c20b --- /dev/null +++ b/src/constitutive/solid/hyperelastic/fung.jl @@ -0,0 +1,130 @@ +using DocStringExtensions + +""" +**Parameters** +$(FIELDS) +""" +struct Fung + κ::Real + μ::Real + μₘ::Real + η::Real +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_stress(model::Fung, F) + raw = ccall( + (:fung_cauchy_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + model.η, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_tangent_stiffness(model::Fung, F) + raw = ccall( + (:fung_cauchy_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + model.η, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_stress(model::Fung, F) + raw = ccall( + (:fung_first_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + model.η, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_tangent_stiffness(model::Fung, F) + raw = ccall( + (:fung_first_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + model.η, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_stress(model::Fung, F) + raw = ccall( + (:fung_second_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + model.η, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_tangent_stiffness(model::Fung, F) + raw = ccall( + (:fung_second_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + model.η, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function helmholtz_free_energy_density(model::Fung, F) + return ccall( + (:fung_helmholtz_free_energy_density, CONSPIRE_WRAPPER_LIB), + Float64, + (Float64, Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + model.η, + F, + ) +end diff --git a/src/constitutive/solid/hyperelastic/gent.jl b/src/constitutive/solid/hyperelastic/gent.jl new file mode 100644 index 0000000..c3b725c --- /dev/null +++ b/src/constitutive/solid/hyperelastic/gent.jl @@ -0,0 +1,146 @@ +using DocStringExtensions + +""" +The Gent hyperelastic constitutive model.[^1] + +[^1]: A.N. Gent, [Rubber Chem. Technol. **69**, 59 (1996)](https://doi.org/10.5254/1.3538357). + +**Parameters** +- The bulk modulus ``\\kappa``. +- The shear modulus ``\\mu``. +- The extensibility ``J_m``. + +**External variables** +- The deformation gradient ``\\mathbf{F}``. + +**Internal variables** +- None. + +**Notes** +- The Gent model reduces to the [`NeoHookean`](@ref) model when ``J_m\\to\\infty``. +""" +struct Gent + κ::Real + μ::Real + Jₘ::Real +end + +""" +$(TYPEDSIGNATURES) +```math +\\boldsymbol{\\sigma}(\\mathbf{F}) = \\frac{J^{-1}\\mu J_m {\\mathbf{B}^* }'}{J_m - \\mathrm{tr}(\\mathbf{B}^* ) + 3} + \\frac{\\kappa}{2}\\left(J - \\frac{1}{J}\\right)\\mathbf{1} +``` +""" +function cauchy_stress(model::Gent, F) + raw = ccall( + (:gent_cauchy_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.Jₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +```math +\\mathcal{T}_{ijkL}(\\mathbf{F}) = \\frac{J^{-5/3}\\mu J_m}{J_m - \\mathrm{tr}(\\mathbf{B}^* ) + 3}\\Bigg[ \\delta_{ik}F_{jL} + \\delta_{jk}F_{iL} - \\frac{2}{3}\\,\\delta_{ij}F_{kL} + \\frac{2{B_{ij}^* }' F_{kL}}{J_m - \\mathrm{tr}(\\mathbf{B}^* ) + 3} - \\left(\\frac{5}{3} + \\frac{2}{3}\\frac{\\mathrm{tr}(\\mathbf{B}^* )}{J_m - \\mathrm{tr}(\\mathbf{B}^* ) + 3}\\right) J^{2/3} {B_{ij}^* }' F_{kL}^{-T} \\Bigg] + \\frac{\\kappa}{2} \\left(J + \\frac{1}{J}\\right)\\delta_{ij}F_{kL}^{-T} +``` +""" +function cauchy_tangent_stiffness(model::Gent, F) + raw = ccall( + (:gent_cauchy_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.Jₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_stress(model::Gent, F) + raw = ccall( + (:gent_first_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.Jₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_tangent_stiffness(model::Gent, F) + raw = ccall( + (:gent_first_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.Jₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_stress(model::Gent, F) + raw = ccall( + (:gent_second_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.Jₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_tangent_stiffness(model::Gent, F) + raw = ccall( + (:gent_second_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.Jₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +```math +a(\\mathbf{F}) = -\\frac{\\mu J_m}{2}\\,\\ln\\left[1 - \\frac{\\mathrm{tr}(\\mathbf{B}^* ) - 3}{J_m}\\right] + \\frac{\\kappa}{2}\\left[\\frac{1}{2}\\left(J^2 - 1\\right) - \\ln J\\right] +``` +""" +function helmholtz_free_energy_density(model::Gent, F) + return ccall( + (:gent_helmholtz_free_energy_density, CONSPIRE_WRAPPER_LIB), + Float64, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.Jₘ, + F, + ) +end diff --git a/src/constitutive/solid/hyperelastic/mooney_rivlin.jl b/src/constitutive/solid/hyperelastic/mooney_rivlin.jl new file mode 100644 index 0000000..482d324 --- /dev/null +++ b/src/constitutive/solid/hyperelastic/mooney_rivlin.jl @@ -0,0 +1,122 @@ +using DocStringExtensions + +""" +**Parameters** +$(FIELDS) +""" +struct MooneyRivlin + κ::Real + μ::Real + μₘ::Real +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_stress(model::MooneyRivlin, F) + raw = ccall( + (:mooney_rivlin_cauchy_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_tangent_stiffness(model::MooneyRivlin, F) + raw = ccall( + (:mooney_rivlin_cauchy_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_stress(model::MooneyRivlin, F) + raw = ccall( + (:mooney_rivlin_first_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_tangent_stiffness(model::MooneyRivlin, F) + raw = ccall( + (:mooney_rivlin_first_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_stress(model::MooneyRivlin, F) + raw = ccall( + (:mooney_rivlin_second_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_tangent_stiffness(model::MooneyRivlin, F) + raw = ccall( + (:mooney_rivlin_second_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function helmholtz_free_energy_density(model::MooneyRivlin, F) + return ccall( + (:mooney_rivlin_helmholtz_free_energy_density, CONSPIRE_WRAPPER_LIB), + Float64, + (Float64, Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + model.μₘ, + F, + ) +end diff --git a/src/constitutive/solid/hyperelastic/neo_hookean.jl b/src/constitutive/solid/hyperelastic/neo_hookean.jl new file mode 100644 index 0000000..bc96202 --- /dev/null +++ b/src/constitutive/solid/hyperelastic/neo_hookean.jl @@ -0,0 +1,114 @@ +using DocStringExtensions + +""" +**Parameters** +$(FIELDS) +""" +struct NeoHookean + κ::Real + μ::Real +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_stress(model::NeoHookean, F) + raw = ccall( + (:neo_hookean_cauchy_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_tangent_stiffness(model::NeoHookean, F) + raw = ccall( + (:neo_hookean_cauchy_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_stress(model::NeoHookean, F) + raw = ccall( + (:neo_hookean_first_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_tangent_stiffness(model::NeoHookean, F) + raw = ccall( + (:neo_hookean_first_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_stress(model::NeoHookean, F) + raw = ccall( + (:neo_hookean_second_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_tangent_stiffness(model::NeoHookean, F) + raw = ccall( + (:neo_hookean_second_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function helmholtz_free_energy_density(model::NeoHookean, F) + return ccall( + (:neo_hookean_helmholtz_free_energy_density, CONSPIRE_WRAPPER_LIB), + Float64, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) +end diff --git a/src/constitutive/solid/hyperelastic/saint_venant_kirchoff.jl b/src/constitutive/solid/hyperelastic/saint_venant_kirchoff.jl new file mode 100644 index 0000000..2dfb284 --- /dev/null +++ b/src/constitutive/solid/hyperelastic/saint_venant_kirchoff.jl @@ -0,0 +1,120 @@ +using DocStringExtensions + +""" +**Parameters** +$(FIELDS) +""" +struct SaintVenantKirchoff + κ::Real + μ::Real +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_stress(model::SaintVenantKirchoff, F) + raw = ccall( + (:saint_venant_kirchoff_cauchy_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_tangent_stiffness(model::SaintVenantKirchoff, F) + raw = ccall( + (:saint_venant_kirchoff_cauchy_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_stress(model::SaintVenantKirchoff, F) + raw = ccall( + (:saint_venant_kirchoff_first_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_tangent_stiffness(model::SaintVenantKirchoff, F) + raw = ccall( + ( + :saint_venant_kirchoff_first_piola_kirchoff_tangent_stiffness, + CONSPIRE_WRAPPER_LIB, + ), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_stress(model::SaintVenantKirchoff, F) + raw = ccall( + (:saint_venant_kirchoff_second_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_tangent_stiffness(model::SaintVenantKirchoff, F) + raw = ccall( + ( + :saint_venant_kirchoff_second_piola_kirchoff_tangent_stiffness, + CONSPIRE_WRAPPER_LIB, + ), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function helmholtz_free_energy_density(model::SaintVenantKirchoff, F) + return ccall( + (:saint_venant_kirchoff_helmholtz_free_energy_density, CONSPIRE_WRAPPER_LIB), + Float64, + (Float64, Float64, Ptr{Float64}), + model.κ, + model.μ, + F, + ) +end diff --git a/src/constitutive/solid/hyperelastic/yeoh.jl b/src/constitutive/solid/hyperelastic/yeoh.jl new file mode 100644 index 0000000..e652be5 --- /dev/null +++ b/src/constitutive/solid/hyperelastic/yeoh.jl @@ -0,0 +1,129 @@ +using DocStringExtensions + +""" +**Parameters** +$(FIELDS) +""" +struct Yeoh + κ::Real + μ::Real + μₑ::Vector +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_stress(model::Yeoh, F) + raw = ccall( + (:yeoh_cauchy_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}, UInt8, Ptr{Float64}), + model.κ, + model.μ, + model.μₑ, + length(model.μₑ), + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function cauchy_tangent_stiffness(model::Yeoh, F) + raw = ccall( + (:yeoh_cauchy_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}, UInt8, Ptr{Float64}), + model.κ, + model.μ, + model.μₑ, + length(model.μₑ), + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_stress(model::Yeoh, F) + raw = ccall( + (:yeoh_first_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}, UInt8, Ptr{Float64}), + model.κ, + model.μ, + model.μₑ, + length(model.μₑ), + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function first_piola_kirchoff_tangent_stiffness(model::Yeoh, F) + raw = ccall( + (:yeoh_first_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}, UInt8, Ptr{Float64}), + model.κ, + model.μ, + model.μₑ, + length(model.μₑ), + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_stress(model::Yeoh, F) + raw = ccall( + (:yeoh_second_piola_kirchoff_stress, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}, UInt8, Ptr{Float64}), + model.κ, + model.μ, + model.μₑ, + length(model.μₑ), + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 9, own = false), (3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function second_piola_kirchoff_tangent_stiffness(model::Yeoh, F) + raw = ccall( + (:yeoh_second_piola_kirchoff_tangent_stiffness, CONSPIRE_WRAPPER_LIB), + Ptr{Float64}, + (Float64, Float64, Ptr{Float64}, UInt8, Ptr{Float64}), + model.κ, + model.μ, + model.μₑ, + length(model.μₑ), + F, + ) + return reshape(unsafe_wrap(Array{Float64}, raw, 81, own = false), (3, 3, 3, 3)) +end + +""" +$(TYPEDSIGNATURES) +""" +function helmholtz_free_energy_density(model::Yeoh, F) + return ccall( + (:yeoh_helmholtz_free_energy_density, CONSPIRE_WRAPPER_LIB), + Float64, + (Float64, Float64, Ptr{Float64}, UInt8, Ptr{Float64}), + model.κ, + model.μ, + model.μₑ, + length(model.μₑ), + F, + ) +end diff --git a/test/constitutive.jl b/test/constitutive.jl new file mode 100644 index 0000000..c904555 --- /dev/null +++ b/test/constitutive.jl @@ -0,0 +1,32 @@ +κ = 13.0 +μ = 3.0 +μₑ = [-1.0, 3e-1, -1e-3, 1e-5] +μₘ = 1.0 +Jₘ = 23.0 +η = 1.0 +N = 8.0 + +I = [ + 1.0 0.0 0.0 + 0.0 1.0 0.0 + 0.0 0.0 1.0 +] +Zero = [ + 0.0 0.0 0.0 + 0.0 0.0 0.0 + 0.0 0.0 0.0 +] +SimpleShearSmall = [ + 1.0 ϵ 0.0 + 0.0 1.0 0.0 + 0.0 0.0 1.0 +] +VolumetricSmall = I * (1 + ϵ)^(1 / 3) +F = [ + 0.63595746 0.69157849 0.71520784 + 0.80589604 0.83687323 0.19312595 + 0.05387420 0.86551549 0.41880244 +] + +include("constitutive/elastic.jl") +include("constitutive/hyperelastic.jl") diff --git a/test/constitutive/elastic.jl b/test/constitutive/elastic.jl new file mode 100644 index 0000000..3cb4160 --- /dev/null +++ b/test/constitutive/elastic.jl @@ -0,0 +1,64 @@ +function test_elastic(model) + σ(F) = cauchy_stress(model, F) + P(F) = first_piola_kirchoff_stress(model, F) + S(F) = second_piola_kirchoff_stress(model, F) + @test σ(I) == Zero + @test P(I) == Zero + @test S(I) == Zero + @test σ(F) ≈ transpose(σ(F)) + @test σ(F) ≈ (transpose(F) * P(F)) / det(F) + @test σ(F) ≈ (transpose(F) * S(F) * F) / det(F) + @test abs(σ(SimpleShearSmall)[4] / ϵ - μ) < ϵ + @test abs(tr(σ(VolumetricSmall)) / 3 / ϵ / κ - 1) < 3 * ϵ + T = cauchy_tangent_stiffness(model, F) + for i = 1:3 + for j = 1:3 + for k = 1:3 + for l = 1:3 + @test T[l, k, j, i] ≈ T[l, k, i, j] + Fd = copy(F) + Fd[l, k] += ϵ / 2 + dσᵢⱼ = σ(Fd)[j, i] + Fd[l, k] -= ϵ + dσᵢⱼ -= σ(Fd)[j, i] + @test abs(T[l, k, j, i] - dσᵢⱼ / ϵ) < 1.11 * ϵ + end + end + end + end + C = first_piola_kirchoff_tangent_stiffness(model, F) + for i = 1:3 + for j = 1:3 + for k = 1:3 + for l = 1:3 + Fd = copy(F) + Fd[l, k] += ϵ / 2 + dPᵢⱼ = P(Fd)[j, i] + Fd[l, k] -= ϵ + dPᵢⱼ -= P(Fd)[j, i] + @test abs(C[l, k, j, i] - dPᵢⱼ / ϵ) < ϵ + end + end + end + end + G = second_piola_kirchoff_tangent_stiffness(model, F) + for i = 1:3 + for j = 1:3 + for k = 1:3 + for l = 1:3 + Fd = copy(F) + Fd[l, k] += ϵ / 2 + dSᵢⱼ = S(Fd)[j, i] + Fd[l, k] -= ϵ + dSᵢⱼ -= S(Fd)[j, i] + @test abs(G[l, k, j, i] - dSᵢⱼ / ϵ) < 2.0 * ϵ + end + end + end + end +end + +@testset "Almansi-Hamel model" begin + almansi_hamel_model = AlmansiHamel(κ, μ) + test_elastic(almansi_hamel_model) +end diff --git a/test/constitutive/hyperelastic.jl b/test/constitutive/hyperelastic.jl new file mode 100644 index 0000000..d8f1131 --- /dev/null +++ b/test/constitutive/hyperelastic.jl @@ -0,0 +1,78 @@ +function test_hyperelastic(model) + a(F) = helmholtz_free_energy_density(model, F) + P(F) = first_piola_kirchoff_stress(model, F) + @test a(I) == 0.0 + for (i, Pᵢ) in enumerate(eachrow(P(I))) + for (j, Pᵢⱼ) in enumerate(Pᵢ) + Fd = copy(I) + Fd[i, j] += ϵ / 2 + da = a(Fd) + Fd[i, j] -= ϵ + da -= a(Fd) + @test abs(Pᵢⱼ - da / ϵ) < ϵ + end + end + @test a(F) > 0.0 + for (i, Pᵢ) in enumerate(eachrow(P(F))) + for (j, Pᵢⱼ) in enumerate(Pᵢ) + Fd = copy(F) + Fd[i, j] += ϵ / 2 + da = a(Fd) + Fd[i, j] -= ϵ + da -= a(Fd) + @test abs(Pᵢⱼ - da / ϵ) < ϵ + end + end + C = first_piola_kirchoff_tangent_stiffness(model, F) + for i = 1:3 + for j = 1:3 + for k = 1:3 + for l = 1:3 + @test C[l, k, j, i] ≈ C[j, i, l, k] + end + end + end + end +end + +@testset "Arruda-Boyce model" begin + arruda_boyce_model = ArrudaBoyce(κ, μ, N) + test_elastic(arruda_boyce_model) + test_hyperelastic(arruda_boyce_model) +end + +@testset "Gent model" begin + gent_model = Gent(κ, μ, Jₘ) + test_elastic(gent_model) + test_hyperelastic(gent_model) +end + +@testset "Fung model" begin + fung_model = Fung(κ, μ, μₘ, η) + test_elastic(fung_model) + test_hyperelastic(fung_model) +end + +@testset "Mooney-Rivlin model" begin + mooney_rivlin_model = MooneyRivlin(κ, μ, μₘ) + test_elastic(mooney_rivlin_model) + test_hyperelastic(mooney_rivlin_model) +end + +@testset "Neo-Hookean model" begin + neo_hookean_model = NeoHookean(κ, μ) + test_elastic(neo_hookean_model) + test_hyperelastic(neo_hookean_model) +end + +@testset "Saint Venant-Kirchoff model" begin + saint_venant_kirchoff_model = SaintVenantKirchoff(κ, μ) + test_elastic(saint_venant_kirchoff_model) + test_hyperelastic(saint_venant_kirchoff_model) +end + +@testset "Yeoh model" begin + yeoh_model = Yeoh(κ, μ, μₑ) + test_elastic(yeoh_model) + test_hyperelastic(yeoh_model) +end diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..b0c888b --- /dev/null +++ b/test/runtests.jl @@ -0,0 +1,13 @@ +using Aqua, Conspire, JET, JuliaFormatter, LinearAlgebra, Test + +ϵ = 1e-6 + +include("constitutive.jl") + +Aqua.test_all(Conspire) + +println("\nJET:\n", report_package("Conspire"; toplevel_logger = nothing)) + +if !format("../", overwrite = false, verbose = true) + error("File(s) not properly formatted.") +end