Skip to content

Commit

Permalink
Merge pull request #3 from jpsferreira/feat/volumetric-tensors
Browse files Browse the repository at this point in the history
update codecov action version
  • Loading branch information
jpsferreira authored Nov 21, 2024
2 parents 1fff3d2 + db77f80 commit 16be195
Show file tree
Hide file tree
Showing 15 changed files with 618 additions and 393 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ jobs:
run: tox

- name: Upload coverage reports to Codecov with GitHub Action on Python 3.11
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
if: ${{ matrix.python-version == '3.11' }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

check-docs:
runs-on: ubuntu-latest
Expand Down
67 changes: 35 additions & 32 deletions hyper_surrogate/materials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Iterable

import sympy as sym
from sympy import Expr, ImmutableDenseNDimArray, Matrix, MutableDenseNDimArray, Symbol

from hyper_surrogate.symbolic import SymbolicHandler

Expand All @@ -11,72 +11,75 @@ class Material(SymbolicHandler):
The class is inherited from the SymbolicHandler class and provides
the necessary methods to define the constitutive model in symbolic form.
args:
parameters: Iterable[Any] - The material parameters as a list of strings
Args:
parameters: Iterable[Any] - The material parameters as a list of strings
properties:
sef: The strain energy function in symbolic form
Properties:
sef: The strain energy function in symbolic form
methods:
pk2() -> Any: Returns the second Piola-Kirchhoff stress tensor
cmat() -> Any: Returns the material stiffness tensor
Methods:
pk2() -> Callable[..., Any]: Returns the second Piola-Kirchhoff stress tensor
cmat() -> Callable[..., Any]: Returns the material stiffness tensor
"""

def __init__(self, parameters: Iterable[Any]) -> None:
def __init__(self, parameters: Iterable[str]) -> None:
super().__init__()
self.parameters = parameters

@property
def sef(self) -> Any:
def sef(self) -> Expr:
"""Strain energy function in symbolic form."""
# Dummy placeholder
return sym.Symbol("sef")
return Symbol("sef")

@property
def pk2_symb(self) -> Any:
def pk2_symb(self) -> Matrix:
"""Second Piola-Kirchhoff stress tensor in symbolic form."""
return self.pk2_tensor(self.sef)

@property
def cmat_symb(self) -> Any:
def cmat_symb(self) -> ImmutableDenseNDimArray:
"""Material stiffness tensor in symbolic form."""
return self.cmat_tensor(self.pk2_symb)

def sigma_symb(self, f: sym.Matrix) -> Any:
def sigma_symb(self, f: Matrix) -> Matrix:
"""Cauchy stress tensor in symbolic form."""
return self.pushforward_2nd_order(self.pk2_symb, f)

def smat_symb(self, f: sym.Matrix) -> Any:
def smat_symb(self, f: Matrix) -> MutableDenseNDimArray:
"""Material stiffness tensor in spatial form."""
return self.pushforward_4th_order(self.cmat_symb, f)

def jr_symb(self, f: sym.Matrix) -> Any:
def jr_symb(self, f: Matrix) -> Matrix:
"""Jaumann rate contribution to the tangent tensor in symbolic form."""
return self.jr(self.sigma_symb(f))

def cauchy(self, f: sym.Matrix) -> Any:
def cauchy(self, f: Matrix) -> Matrix:
"""Reduce Cauchy stress tensor to 6x1 matrix using Voigt notation."""
return self.reduce_2nd_order(self.sigma_symb(f))

def tangent(self, f: sym.Matrix, use_jaumann_rate: bool = False) -> Any:
def tangent(self, f: Matrix, use_jaumann_rate: bool = False) -> Matrix:
"""Reduce tangent tensor to 6x6 matrix using Voigt notation."""
tangent = self.smat_symb(f)
if use_jaumann_rate:
tangent += self.jr_symb(f)
return self.reduce_4th_order(tangent)

def pk2(self) -> Any:
"""Second Piola-Kirchhoff stress tensor generator of numerical form."""
return self.lambdify(self.pk2_symb, *self.parameters)
return self.lambda_tensor(self.pk2_symb, *self.parameters)

def cmat(self) -> Any:
"""Material stiffness tensor generator of numerical form."""
return self.lambdify(self.cmat_symb, *self.parameters)
return self.lambda_tensor(self.cmat_symb, *self.parameters)

def sigma(self, f: sym.Matrix) -> Any:
def sigma(self, f: Matrix) -> Any:
"""Cauchy stress tensor generator of numerical form."""
return self.lambdify(self.sigma_symb(f), *self.parameters)
return self.lambda_tensor(self.sigma_symb(f), *self.parameters)

def smat(self, f: sym.Matrix) -> Any:
def smat(self, f: Matrix) -> Any:
"""Material stiffness tensor generator of numerical form."""
return self.lambdify(self.smat_symb(f), *self.parameters)
return self.lambda_tensor(self.smat_symb(f), *self.parameters)


class NeoHooke(Material):
Expand All @@ -85,17 +88,17 @@ class NeoHooke(Material):
The class inherits from the Material class and provides the necessary
methods to define the Neo-Hookean model in symbolic form.
properties:
sef: The strain energy function in symbolic form
Properties:
sef: The strain energy function in symbolic form
"""

def __init__(self) -> None:
params = ["C10"]
super().__init__(params)

@property
def sef(self) -> Any:
return (self.invariant1 - 3) * sym.Symbol("C10")
def sef(self) -> Expr:
return (self.invariant1 - 3) * Symbol("C10")


class MooneyRivlin(Material):
Expand All @@ -104,14 +107,14 @@ class MooneyRivlin(Material):
The class inherits from the Material class and provides the necessary
methods to define the Mooney-Rivlin model in symbolic form.
properties:
sef: The strain energy function in symbolic form
Properties:
sef: The strain energy function in symbolic form
"""

def __init__(self) -> None:
params = ["C10", "C01"]
super().__init__(params)

@property
def sef(self) -> Any:
return (self.invariant1 - 3) * sym.Symbol("C10") + (self.invariant2 - 3) * sym.Symbol("C01")
def sef(self) -> Expr:
return (self.invariant1 - 3) * Symbol("C10") + (self.invariant2 - 3) * Symbol("C01")
23 changes: 1 addition & 22 deletions hyper_surrogate/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

# import pandas as pd
import seaborn as sns
Expand All @@ -21,7 +20,7 @@ class Reporter:
"""
Generate a PDF report from batches of tensors.
It provides various methods to create different types of visualizations and tables based on the parsed data.
It provides various methods to create different types of visualizations and tables.
"""

Expand Down Expand Up @@ -74,26 +73,6 @@ def visualize_determinants(self) -> list[matplotlib.figure.Figure]:
plt.ylabel("Frequency")
return [fig]

@staticmethod
def tablefig(
df: pd.DataFrame,
figsize: tuple = (8.27, 11.69),
location: str = "center left",
title: str = "Title",
) -> list[matplotlib.figure.Figure]:
"""Create a table figure using the provided DataFrame and displays it using Matplotlib."""
fig, ax = plt.subplots(figsize=figsize)
ax.table(
cellText=df.values,
colLabels=df.columns,
loc=location,
rowLabels=df.index,
)

ax.axis("off")
ax.set_title(title)
return [fig]

def generate_figures(self) -> list[matplotlib.figure.Figure]:
"""Generate figures for report."""
fig_list = []
Expand Down
Loading

0 comments on commit 16be195

Please sign in to comment.