Thanks to visit codestin.com
Credit goes to github.com

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: Deploy Jekyll site to Pages

on:
push:
branches:
branches:
- "main"
paths:
- "docs/**"
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ _site/
# Ignore folders generated by Bundler
.bundle/
vendor/
build/*
external/*
lib/*
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

---
repos:
- repo: local
hooks:
- id: fortran-fprettify
name: Fortran fprettify
entry: fprettify
language: system
files: \.(f90|F90|f95|F95|f03|F03|for|FOR|ftn|FTN)$
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
name: CMake Format
entry: cmake-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-shebang-scripts-are-executable
- id: check-executables-have-shebangs
- id: check-json
- id: check-yaml
- id: check-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: check-case-conflict
- id: mixed-line-ending
- id: trailing-whitespace
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ title: "Tensor Toolbox for Modern Fortran - High-Level Tensor Manipulation in Fo
type: software
doi: 10.5281/zenodo.4077378
url: https://github.com/adtzlr/ttb
license: GPL-3.0
license: GPL-3.0
83 changes: 83 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
cmake_minimum_required(VERSION 3.21)
cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0083 NEW)
cmake_policy(SET CMP0104 NEW)
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0048 NEW)

# Project name and settings
project(
ttb
VERSION 0.0.0
LANGUAGES Fortran)
set(project_name ttb)
enable_language(Fortran)
enable_testing()
include(ExternalProject)
# Set the source directory path
set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")

# set(test-drive_version 0.5.0) ExternalProject_Add( test-drive URL
# https://github.com/fortran-lang/test-drive/archive/refs/tags/v${test-drive_version}.tar.gz
# PREFIX ${PROJECT_SOURCE_DIR}/external/test-drive CMAKE_ARGS
# -DCMAKE_INSTALL_PREFIX=${PROJECT_SOURCE_DIR}/lib/test-drive)
set(ttb_lib tensor_ttbs)
add_library(${ttb_lib} STATIC)
if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU")
# so far this seems to only pop up on gcc 11.1...
target_compile_options(
${ttb_lib}
PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:
-pedantic
-Wampersand
-Wsurprising
-std=f2018
-g
-fbacktrace
-Wall
-Wextra
-Wunderflow
-Wconversion
-Wline-truncation
-Wcharacter-truncation
# I need to think more how to remove these warnings
# -Warray-temporaries
-fcheck=all
-finit-real=snan
-finit-integer=-2147483648
-finit-logical=true
-fimplicit-none
>)
elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Cray")

elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "Intel"
OR ${CMAKE_Fortran_COMPILER_ID} STREQUAL "IntelLLVM")

elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "NVHPC")

elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "LLVMFlang")

endif()
# Create the static library set(debug_exec_name ${project_name})

target_link_libraries(
${ttb_lib} PRIVATE ${PROJECT_SOURCE_DIR}/lib/test-drive/lib/libtest-drive.a)

# Set the library output and module directories
set_target_properties(
${ttb_lib} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/modules")

include_directories(
${PROJECT_SOURCE_DIR}/lib/test-drive/include/test-drive/${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}
)
add_subdirectory(src)
add_subdirectory(test)
add_executable(bob ${PROJECT_SOURCE_DIR}/app/main.f90)
target_include_directories(bob PRIVATE "${CMAKE_BINARY_DIR}/modules")
target_link_libraries(bob PRIVATE ${ttb_lib})

# ${PROJECT_SOURCE_DIR}/lib/test-drive/lib/libtest-drive.a) Link the library to
91 changes: 91 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Disable the default rules
MAKEFLAGS += --no-builtin-rules --no-builtin-variables

# Project name
NAME := ttb

# Configuration settings
FC := gfortran
AR := ar rcs
LD := $(FC)
RM := rm -f
GD := ./deps.awk

# List of all source files
SRCS := src/ttb_rotation.f90 \
src/ttb_library.f90 \
src/ttb_sqrt.f90 \
src/ttb_norm.f90 \
src/ttb_crossdyadic.f90 \
src/ttb_sub.f90 \
src/ttb_piola.f90 \
src/ttb_reducedim.f90 \
src/ttb_permute.f90 \
src/ttb_dyadic.f90 \
src/ttb_add.f90 \
src/ttb_types.f90 \
src/ttb_assign.f90 \
src/ttb_det.f90 \
src/ttb_assignscalar.f90 \
src/ttb_transp.f90 \
src/ttb_asarray.f90 \
src/ttb_tools.f90 \
src/ttb_dev.f90 \
src/ttb_assignten2sym.f90 \
src/ttb_dot.f90 \
src/ttb_asabqarray.f90 \
src/ttb_assignarray.f90 \
src/ttb_ddot.f90 \
src/ttb_div.f90 \
src/ttb_unimodular.f90 \
src/ttb_strainstore.f90 \
src/ttb_inv.f90 \
src/ttb_symstore.f90 \
src/ttb_identity.f90 \
src/ttb_tenstore.f90 \
src/ttb_trace.f90 \
src/ttb_power.f90
TEST_SRCS := app/main.f90
# Add source and tests directories to search paths
vpath % .: src
vpath % .: app

# Define a map from each file name to its object file
obj = $(src).o
$(foreach src, $(SRCS) $(TEST_SRCS), $(eval $(src) := $(obj)))

# Create lists of the build artefacts in this project
OBJS := $(addsuffix .o, $(SRCS))
DEPS := $(addsuffix .d, $(SRCS))
TEST_OBJS := $(addsuffix .o, $(TEST_SRCS))
TEST_DEPS := $(addsuffix .d, $(TEST_SRCS))
LIB := $(patsubst %, lib%.a, $(NAME))
TEST_EXE := $(patsubst %.f90, %.exe, $(TEST_SRCS))

# Declare all public targets
.PHONY: all clean
all: $(LIB) $(TEST_EXE)

# Create the static library from the object files
$(LIB): $(OBJS)
$(AR) $@ $^

# Link the test executables
$(TEST_EXE): %.exe: %.f90.o $(LIB)
$(LD) -o $@ $^

# Create object files from Fortran source
$(OBJS) $(TEST_OBJS): %.o: % | %.d
$(FC) -c -o $@ $<

# Process the Fortran source for module dependencies
$(DEPS) $(TEST_DEPS): %.d: %
$(GD) $< > $@

# Define all module interdependencies
include $(DEPS) $(TEST_DEPS)
$(foreach dep, $(OBJS) $(TEST_OBJS), $(eval $(dep): $($(dep))))

# Cleanup, filter to avoid removing source code by accident
clean:
$(RM) $(filter %.o, $(OBJS) $(TEST_OBJS)) $(filter %.d, $(DEPS) $(TEST_DEPS)) $(filter %.exe, $(TEST_EXE)) $(LIB) $(wildcard *.mod)
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ This tensor toolbox provides the following [basic operations for tensor calculus

The idea is to create derived data types for rank 1, rank 2 and rank 4 tensors (and it's symmetric variants). In a next step the operators are defined in a way that Fortran calls different functions based on the input types of the operator: performing a dot product between a vector and a rank 2 tensor or a rank 2 and a rank 2 tensor is a different function. Best of it: you don't have to take care of that.

## Building

The TensorToolBox can be used in several ways. Since moving to free form, slotting it into existing build systems in Fortran legacy applications might cause trouble! Therefore, we have included several new ways to integrate it.

The TTB can be built either with Makefiles, CMake, or the Fortran Package Mangager (FPM). This will ensure maximum compatibility with any build system available. Therefore...

### Makefiles

You can include the dependencies and the build logic into an existing Makefile build system using the existing Makefile provided here as a template. Otherwise, you can make sure this is built first and then your main application, linking statically to yours.

### CMake

Via CMake one can include the building of the TTB into another CMake application via Fetch commands. An example is provided in the examples/ directory.

### FPM

TTB can be built and linked to using the FPM. An example is show in the examples directory/

## Basic Usage
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:

Expand Down
6 changes: 6 additions & 0 deletions app/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
program test
use Tensor
implicit none

call print_banner()
end program test
56 changes: 56 additions & 0 deletions deps.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/awk -f

BEGIN {
# Fortran is case insensitive, disable case sensitivity for matching
IGNORECASE = 1
}

# Match a module statement
# - the first argument ($1) should be the whole word module
# - the second argument ($2) should be a valid module name
$1 ~ /^module$/ &&
$2 ~ /^[a-zA-Z][a-zA-Z0-9_]*$/ {
# count module names per file to avoid having modules twice in our list
if (modc[FILENAME,$2]++ == 0) {
# add to the module list, the generated module name is expected
# to be lowercase, the FILENAME is the current source file
mod[++im] = sprintf("%s.mod = $(%s)", tolower($2), FILENAME)
}
}

# Match a use statement
# - the first argument ($1) should be the whole word use
# - the second argument ($2) should be a valid module name
$1 ~ /^use$/ &&
$2 ~ /^[a-zA-Z][a-zA-Z0-9_]*,?$/ {
# Remove a trailing comma from an optional only statement
gsub(/,/, "", $2)
# count used module names per file to avoid using modules twice in our list
if (usec[FILENAME,$2]++ == 0) {
# add to the used modules, the generated module name is expected
# to be lowercase, the FILENAME is the current source file
use[++iu] = sprintf("$(%s) += $(%s.mod)", FILENAME, tolower($2))
}
}

# Match an include statement
# - the first argument ($1) should be the whole word include
# - the second argument ($2) can be everything, as long as delimited by quotes
$1 ~ /^(#:?)?include$/ &&
$2 ~ /^["'].+["']$/ {
# Remove quotes from the included file name
gsub(/'|"/, "", $2)
# count included files per file to avoid having duplicates in our list
if (incc[FILENAME,$2]++ == 0) {
# Add the included file to our list, this might be case-sensitive
inc[++ii] = sprintf("$(%s) += %s", FILENAME, $2)
}
}

# Finally, produce the output for make, loop over all modules, use statements
# and include statements, empty lists are ignored in awk
END {
for (i in mod) print mod[i]
for (i in use) print use[i]
for (i in inc) print inc[i]
}
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ last_edit_timestamp: true # requires `last_modified_date` in frontmatter
last_edit_time_format: "%Y-%m-%d"

aux_links:
Tensor Toolbox on GitHub: https://github.com/adtzlr/ttb
Tensor Toolbox on GitHub: https://github.com/adtzlr/ttb
2 changes: 1 addition & 1 deletion docs/_includes/head_custom.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
{% case math %}
{% when "mathjax" %}
{% include mathjax.html %}
{% endcase %}
{% endcase %}
6 changes: 3 additions & 3 deletions docs/_includes/mathjax.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</script>

<script>
window.MathJax = {
tex: { tags: 'ams' }
window.MathJax = {
tex: { tags: 'ams' }
};
</script>
</script>
4 changes: 2 additions & 2 deletions docs/_layouts/mathjax.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
---
<div style="display: none">
\(
<!-- optional definitions using \newcommand, etc.
<!-- optional definitions using \newcommand, etc.
see https://docs.mathjax.org/en/latest/input/tex/macros.html -->
\)
</div>

{{ content }}
{{ content }}
2 changes: 1 addition & 1 deletion docs/api/assignments.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ type(Tensor2s) :: C ! now stored as 6x1 matrix
C = transpose(F)*F
```

The same assignments are also possible for rank 4 Tensor data types.
The same assignments are also possible for rank 4 Tensor data types.
2 changes: 1 addition & 1 deletion docs/api/functions/asabqarray.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ grand_parent: API Reference

## As Abaqus Array

Same function as [`asarray`]({% link api/functions/asarray.md %}) but with `11,22,33,12,13,23` output ordering for Abaqus. For details see [`asarray`]({% link api/functions/asarray.md %}).
Same function as [`asarray`]({% link api/functions/asarray.md %}) but with `11,22,33,12,13,23` output ordering for Abaqus. For details see [`asarray`]({% link api/functions/asarray.md %}).
4 changes: 2 additions & 2 deletions docs/api/functions/asarray.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ grand_parent: API Reference

## As Array

Convert Tensor to Array. This is useful to export results back to the code which is not using the tensor toolbox.
Convert Tensor to Array. This is useful to export results back to the code which is not using the tensor toolbox.

{: .note }
> This function is very useful because Fortran does not allow access to Tensor components of a function result `s = (dev(S*C)*inv(C))%ab`. Instead this function can be used.
> This function is very useful because Fortran does not allow access to Tensor components of a function result `s = (dev(S*C)*inv(C))%ab`. Instead this function can be used.

{: .warning }
> If you use Abaqus please use [`asabqarray`]({% link api/functions/asabqarray.md %}) to export Tensor components.
Expand Down
1 change: 0 additions & 1 deletion docs/api/functions/identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ invC = I4invC**C
```

**Note**: the operator `**` for two tensor data types represents a double contraction. See double contraction for details. `Eye.cdya.Eye` is equivalent to `identity4(Eye)`. See crossed-dyadic product for details.

2 changes: 1 addition & 1 deletion docs/api/functions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ parent: API Reference
has_children: true
---

# Functions
# Functions
Loading