Skip to content

Commit

Permalink
Merge pull request #25 from adtzlr/fix-r4-compatibility
Browse files Browse the repository at this point in the history
Fix compatibility with default `real(kind=8)`
  • Loading branch information
adtzlr authored Apr 12, 2022
2 parents e3e41fd + a3e01c6 commit b196db9
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 73 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Andreas D.
Copyright (c) 2022 Andreas Dutzler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you use *Tensor Toolbox for Modern Fortran (ttb)* in your work, please cite t
Andreas Dutzler. *Tensor Toolbox for Modern Fortran - High-Level Tensor Manipulation in Fortran*. DOI: 10.5281/zenodo.4077378.

```
@software{dutzler2021,
@software{dutzler2022,
author = {Andreas Dutzler},
title = {Tensor Toolbox for Modern Fortran - High-Level Tensor Manipulation in Fortran},
doi = {10.5281/zenodo.4077378},
Expand Down Expand Up @@ -52,7 +52,7 @@ The idea is to create derived data types for rank 1, rank 2 and rank 4 tensors (
The most basic example on how to use this module is to [download the module](https://github.com/adtzlr/ttb/archive/main.zip), put the 'ttb'-Folder in your working directory and add two lines of code:

```fortran
#include "ttb/ttb_library.F"
include 'ttb/ttb_library.f'
program script101_ttb
use Tensor
Expand All @@ -62,15 +62,15 @@ The most basic example on how to use this module is to [download the module](htt
end program script101_ttb
```
The `#include "ttb/ttb_library.F"` statement replaces the line with the content of the ttb-module. The first line in a program or subroutine is now a `use Tensor` statement. That's it - now you're ready to go. As this module uses preprocessor definitions it is necessary to save your files with **UPPERCASE** file extensions (e.g. `filename.F`).
The `include 'ttb/ttb_library.f'` statement replaces the line with the content of the ttb-module. The first line in a program or subroutine is now a `use Tensor` statement. That's it - now you're ready to go.

## Tensor or Voigt Notation

It depends on your preferences: either you store all tensors in full tensor `dimension(3,3)` or in [voigt](https://en.wikipedia.org/wiki/Voigt_notation) `dimension(6)` notation. The equations remain (nearly) the same. Dot Product, Double Dot Product - every function is implemented in both full tensor and voigt notation. Look for the voigt-comments in an [example](docs/examples/hypela2_nh_ttb.F) of a user subroutine for MSC.Marc.
It depends on your preferences: either you store all tensors in full tensor `dimension(3,3)` or in [voigt](https://en.wikipedia.org/wiki/Voigt_notation) `dimension(6)` notation. The equations remain (nearly) the same. Dot Product, Double Dot Product - every function is implemented in both full tensor and voigt notation. Look for the voigt-comments in an [example](docs/examples/hypela2_nh_ttb.f) of a user subroutine for MSC.Marc.

## Access Tensor components by Array

Tensor components may be accessed by a conventional array with the name of the tensor variable `T` followed by a percent operator `%` and a keyword as follows:
Tensor components may be accessed by a conventional array with the name of the tensor variable `T` followed by a percent operator `%` and a type-specific keyword as follows:

- Tensor of rank 1 components as array: `T%a`. i-th component of T: `T%a(i)`
- Tensor of rank 2 components as array: `T%ab`. i,j component of T: `T%ab(i,j)`
Expand Down Expand Up @@ -110,11 +110,11 @@ With the help of the Tensor module the Second Piola-Kirchhoff stress tensor `S`
S = mu*det(C)**(-1./3.)*dev(C)*inv(C)+p*det(C)**(1./2.)*inv(C)
```

While this is of course not the fastest way of calculating the stress tensor it is extremely short and readable. Also the second order tensor variables `S, C` and scalar quantities `mu, p` have to be created at the beginning of the program. A minimal working example for a very simple umat user subroutine can be found in [script_umat.F](docs/examples/script_umat.F). The program is just an example where umat is called and an output information is printed. It is shown that the tensor toolbox is only used inside the material user subroutine umat.
While this is of course not the fastest way of calculating the stress tensor it is extremely short and readable. Also the second order tensor variables `S, C` and scalar quantities `mu, p` have to be created at the beginning of the program. A minimal working example for a very simple umat user subroutine can be found in [script_umat.f](docs/examples/script_umat.f). The program is just an example where a subroutine `umat` is called and an output information is printed. It is shown that the tensor toolbox is only used inside the material user subroutine `umat`.

### Material Elasticity Tensor

Isochoric part of the material elasticity tensor `C4_iso` of a nearly-incompressible Neo-Hookean material model:
The isochoric part of the material elasticity tensor `C4_iso` of a nearly-incompressible Neo-Hookean material model is defined and coded as:

```fortran
C4_iso = det(F)**(-2./3.) * 2./3.* (
Expand All @@ -125,9 +125,9 @@ Isochoric part of the material elasticity tensor `C4_iso` of a nearly-incompress

### Example of MSC.Marc HYPELA2

[Here](docs/examples/hypela2_nh_ttb.F) you can find an example of a nearly-incompressible version of a Neo-Hookean material for MSC.Marc. ~It works **only** in Total Lagrange (no push forward implemented)~. Updated Lagrange is implemented with a push forward of both stress tensor and tangent matrix. Herrmann Elements are automatically detected. As HYPELA2 is called twice per iteration the stiffness calculation is only active during stage `lovl == 4`. One of the best things is the super-simple switch from tensor to voigt notation: Change data types of all symmetric tensors and save the right Cauchy-Green deformation tensor in voigt notation. See commented lines for details.
[Here](docs/examples/hypela2_nh_ttb.f) you can find an example of a nearly-incompressible version of a Neo-Hookean material for MSC.Marc. Updated Lagrange is implemented by a push forward operator of both the stress and the fourth-order elasticity tensor. Herrmann Elements are automatically detected. As HYPELA2 is called twice per iteration the stiffness calculation is only active during stage `lovl == 4`. One of the best things is the super-simple switch from tensor to voigt notation: Change data types of all symmetric tensors and save the right Cauchy-Green deformation tensor in voigt notation. See commented lines for details.

[Download HYPELA2](docs/examples/hypela2_nh_ttb.F): Neo-Hooke, MSC.Marc, Total Lagrange, Tensor Toolbox
[Download HYPELA2](docs/examples/hypela2_nh_ttb.f): Neo-Hooke, MSC.Marc, Total Lagrange, Tensor Toolbox

## Credits
Naumann, C.: [Chemisch-mechanisch gekoppelte Modellierung und Simulation oxidativer Alterungsvorgänge in Gummibauteilen (German)](http://nbn-resolving.de/urn:nbn:de:bsz:ch1-qucosa-222075). PhD thesis. Fakultät für Maschinenbau der Technischen Universität Chemnitz, 2016.
3 changes: 1 addition & 2 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ theme: jekyll-theme-cayman
title: Tensor Toolbox for Modern Fortran
description: High-Level Tensor Manipulation in Fortran

show_downloads: true
google_analytics: UA-111667836-1
show_downloads: true
4 changes: 2 additions & 2 deletions docs/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ with the fourth order identity tensor
The two equations are now implemented in a Total Lagrange user subroutine with the help of this Tensor module as follows:

```fortran
#include "ttb/ttb_library.F"
include 'ttb/ttb_library.f'
subroutine hypela2(d,g,e,de,s,t,dt,ngens,m,nn,kcus,matus,ndi,
2 nshear,disp,dispt,coord,ffn,frotn,strechn,eigvn,ffn1,
Expand Down Expand Up @@ -95,4 +95,4 @@ The two equations are now implemented in a Total Lagrange user subroutine with
end
```

There are also examples for a [basic understandig of the tensor toolbox](examples/script_umat.F), the implementation of the [St.Venant Kirchhoff material](example_stvenantkirchhoff.md) and a [full featured MSC.Marc Neo-Hookean material HYPELA2 user subroutine](examples/hypela2_nh_ttb.F).
There are also examples for a [basic understandig of the tensor toolbox](examples/script_umat.f), the implementation of the [St.Venant Kirchhoff material](example_stvenantkirchhoff.md) and a [full featured MSC.Marc Neo-Hookean material HYPELA2 user subroutine](examples/hypela2_nh_ttb.f).
4 changes: 2 additions & 2 deletions docs/example_neohooke.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ with the fourth order identity tensor
The two equations are now implemented in a Total Lagrange user subroutine with the help of this Tensor module as follows:

```fortran
#include "ttb/ttb_library.F"
include 'ttb/ttb_library.f'
subroutine hypela2(d,g,e,de,s,t,dt,ngens,m,nn,kcus,matus,ndi,
2 nshear,disp,dispt,coord,ffn,frotn,strechn,eigvn,ffn1,
Expand Down Expand Up @@ -95,4 +95,4 @@ The two equations are now implemented in a Total Lagrange user subroutine with
end
```

There are also examples for a [basic understandig of the tensor toolbox](examples/script_umat.F), the implementation of the [St.Venant Kirchhoff material](example_stvenantkirchhoff.md) and a [full featured MSC.Marc Neo-Hookean material HYPELA2 user subroutine](examples/hypela2_nh_ttb.F).
There are also examples for a [basic understandig of the tensor toolbox](examples/script_umat.f), the implementation of the [St.Venant Kirchhoff material](example_stvenantkirchhoff.md) and a [full featured MSC.Marc Neo-Hookean material HYPELA2 user subroutine](examples/hypela2_nh_ttb.f).
4 changes: 2 additions & 2 deletions docs/example_stvenantkirchhoff.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and
Before we are able to add our own user code, we have to start with an empty fortran subroutine header for MSC.Marc's HYPELA2. Similar headers are provided for Abaqus, ANSYS, etc in the corresponding manuals.

```fortran
#include "ttb/ttb_library.F"
include 'ttb/ttb_library.f'
subroutine hypela2(d,g,e,de,s,t,dt,ngens,m,nn,kcus,matus,ndi,
2 nshear,disp,dispt,coord,ffn,frotn,strechn,eigvn,ffn1,
Expand Down Expand Up @@ -138,7 +138,7 @@ If we would like to use the Updated Lagrange framework too, we'll have to check
endif
```

In this code `iupdat` is an integer with `0` for total lagrange and `1` for updated lagrange. You may download the whole example as a [HYPELA2 user subroutine](examples/hypela2_stvenantkirchhoff.F) for MSC.Marc.
In this code `iupdat` is an integer with `0` for total lagrange and `1` for updated lagrange. You may download the whole example as a [HYPELA2 user subroutine](examples/hypela2_stvenantkirchhoff.f) for MSC.Marc.

## Sources
[1] Bonet, J., Gil, A. J., & Wood, R. D. (2016). Nonlinear Solid Mechanics for Finite Element Analysis: Statics. Cambridge University Press. [![DOI:10.1017/cbo9781316336144](https://zenodo.org/badge/DOI/10.1017/cbo9781316336144.svg)](https://doi.org/10.1017/cbo9781316336144)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ttb/ttb_library.F"
include 'ttb/ttb_library.f'

subroutine hypela2(d,g,e,de,s,t,dt,ngens,m,nn,kcus,matus,ndi,
2 nshear,disp,dispt,coord,ffn,frotn,strechn,eigvn,ffn1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ttb/ttb_library.F"
include 'ttb/ttb_library.f'

subroutine hypela2(d,g,e,de,s,t,dt,ngens,m,nn,kcus,matus,ndi,
2 nshear,disp,dispt,coord,ffn,frotn,strechn,eigvn,ffn1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ttb/ttb_library.F"
include 'ttb/ttb_library.f'

subroutine hypela2(d,g,e,de,s,t,dt,ngens,m,nn,kcus,matus,ndi,
2 nshear,disp,dispt,coord,ffn,frotn,strechn,eigvn,ffn1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ttb/ttb_library.F"
include 'ttb/ttb_library.f'

subroutine hypela2(d,g,e,de,s,t,dt,ngens,m,nn,kcus,matus,ndi,
2 nshear,disp,dispt,coord,ffn,frotn,strechn,eigvn,ffn1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ttb/ttb_library.F"
include 'ttb/ttb_library.f'

program script_tensortoolbox

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ttb/ttb_library.F"
include 'ttb/ttb_library.f'

SUBROUTINE UMAT(STRESS,STATEV,DDSDDE,SSE,SPD,SCD,
1 RPL,DDSDDT,DRPLDE,DRPLDT,
Expand Down
10 changes: 1 addition & 9 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,4 @@ This Toolbox is a fortran module which can be used inside modern Fortran compile
This Toolbox is tested on Windows with both Intel Fortran >2015 (in combination with MSC.Marc) and GFortran >6.3. If you are using Linux it **should** work (but it is untested).

## Download
[Download the module](https://github.com/adtzlr/ttb/archive/main.zip), put the `ttb`-Folder in your working directory and you are ready to dive into comfortable tensor manipulations in Fortran.

## A note on LS-DYNA Users
If you have problems as reported [here] (https://github.com/adtzlr/ttb/issues/10), please add the following line **before** the Tensor-Toolbox include statement. This deactivates tensor with single-precision scalar multiplications and divisions. **Warning**: Now take care to only use double-precision constants in your code!

```fortran
#define NOR4
#include "ttb/ttb_library.F"
```
[Download the module](https://github.com/adtzlr/ttb/archive/main.zip), put the `ttb`-Folder in your working directory and you are ready to dive into comfortable tensor manipulations in Fortran.
4 changes: 2 additions & 2 deletions docs/quickstartguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The most basic example on how to use this module is to [download the module](https://github.com/adtzlr/ttb/archive/main.zip), put the 'ttb'-Folder in your working directory and add two lines of code:

```fortran
#include 'ttb/ttb_library.F'
include 'ttb/ttb_library.f'
program script101_ttb
use Tensor
Expand All @@ -12,6 +12,6 @@ The most basic example on how to use this module is to [download the module](htt
end program script101_ttb
```
The `#include 'ttb/ttb_library.F'` statement replaces the line with the content of the ttb-module. The first line in a program or subroutine is now a `use Tensor` statement. That's it - now you're ready to go. Be sure to save your files with **UPPERCASE** file endings, e.g. `file.F` instead of `file.f`. This tells the Fortran compiler to use a preprocessor.
The `include 'ttb/ttb_library.f'` statement replaces the line with the content of the ttb-module. The first line in a program or subroutine is now a `use Tensor` statement. That's it - now you're ready to go.

Continue to [Example](example.md) section. For a list and detailed information of available functions go [here](functions.md).
10 changes: 5 additions & 5 deletions ttb/libassignarray.f
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ subroutine assignarr_2sr4(T,A)
implicit none

type(Tensor2s), intent(inout) :: T
real, dimension(6), intent(in) :: A
real(kind=4), dimension(6), intent(in) :: A

T%a6 = dble(A)

Expand All @@ -32,7 +32,7 @@ subroutine assignarr_4sr4(T,A)
implicit none

type(Tensor4s), intent(inout) :: T
real, dimension(6,6), intent(in) :: A
real(kind=4), dimension(6,6), intent(in) :: A

T%a6b6 = dble(A)

Expand All @@ -52,7 +52,7 @@ subroutine assignarr_1r4(T,A)
implicit none

type(Tensor1), intent(inout) :: T
real, dimension(3), intent(in) :: A
real(kind=4), dimension(3), intent(in) :: A

T%a = dble(A)

Expand All @@ -72,7 +72,7 @@ subroutine assignarr_2r4(T,A)
implicit none

type(Tensor2), intent(inout) :: T
real, dimension(3,3), intent(in) :: A
real(kind=4), dimension(3,3), intent(in) :: A

T%ab = dble(A)

Expand All @@ -92,7 +92,7 @@ subroutine assignarr_4r4(T,A)
implicit none

type(Tensor4), intent(inout) :: T
real, dimension(3,3,3,3), intent(in) :: A
real(kind=4), dimension(3,3,3,3), intent(in) :: A

T%abcd = dble(A)

Expand Down
10 changes: 5 additions & 5 deletions ttb/libassignscalar.f
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ subroutine assignscalar_2sr4(T,w)
implicit none

type(Tensor2s), intent(inout) :: T
real, intent(in) :: w
real(kind=4), intent(in) :: w

T%a6 = T%a6*dble(w)

Expand All @@ -32,7 +32,7 @@ subroutine assignscalar_4sr4(T,w)
implicit none

type(Tensor4s), intent(inout) :: T
real, intent(in) :: w
real(kind=4), intent(in) :: w

T%a6b6 = T%a6b6*dble(w)

Expand All @@ -52,7 +52,7 @@ subroutine assignscalar_1r4(T,w)
implicit none

type(Tensor1), intent(inout) :: T
real, intent(in) :: w
real(kind=4), intent(in) :: w

T%a = T%a*dble(w)

Expand All @@ -72,7 +72,7 @@ subroutine assignscalar_2r4(T,w)
implicit none

type(Tensor2), intent(inout) :: T
real, intent(in) :: w
real(kind=4), intent(in) :: w

T%ab = T%ab*dble(w)

Expand All @@ -92,7 +92,7 @@ subroutine assignscalar_4r4(T,w)
implicit none

type(Tensor4), intent(inout) :: T
real, intent(in) :: w
real(kind=4), intent(in) :: w

T%abcd = T%abcd*dble(w)

Expand Down
10 changes: 5 additions & 5 deletions ttb/libdiv.f
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ end function div_40s
function div_10_r4(T, w)
implicit none

real, intent(in) :: w
real(kind=4), intent(in) :: w
type(Tensor1), intent(in) :: T
type(Tensor1) :: div_10_r4

Expand All @@ -68,7 +68,7 @@ end function div_10_r4
function div_20_r4(T, w)
implicit none

real, intent(in) :: w
real(kind=4), intent(in) :: w
type(Tensor2), intent(in) :: T
type(Tensor2) :: div_20_r4

Expand All @@ -79,7 +79,7 @@ end function div_20_r4
function div_20s_r4(T, w)
implicit none

real, intent(in) :: w
real(kind=4), intent(in) :: w
type(Tensor2s), intent(in) :: T
type(Tensor2s) :: div_20s_r4

Expand All @@ -90,7 +90,7 @@ end function div_20s_r4
function div_40_r4(T, w)
implicit none

real, intent(in) :: w
real(kind=4), intent(in) :: w
type(Tensor4), intent(in) :: T
type(Tensor4) :: div_40_r4

Expand All @@ -101,7 +101,7 @@ end function div_40_r4
function div_40s_r4(T, w)
implicit none

real, intent(in) :: w
real(kind=4), intent(in) :: w
type(Tensor4s), intent(in) :: T
type(Tensor4s) :: div_40s_r4

Expand Down
Loading

0 comments on commit b196db9

Please sign in to comment.