Skip to content

Commit

Permalink
Merge pull request #23 from Universite-Gustave-Eiffel/dev
Browse files Browse the repository at this point in the history
Doc improvements
  • Loading branch information
pierricmora committed Mar 29, 2024
2 parents 5014c5f + e0ddc5b commit f7cb12b
Show file tree
Hide file tree
Showing 43 changed files with 1,596 additions and 982 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ ignore = W605, W503
exclude =
demo
conf.py
jupyter_execute
venv
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ wheels/
.installed.cfg
*.egg
docs/_build/
jupyter_execute/

# Unit test / coverage reports
htmlcov/
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.lab
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY ./demo /root/demo/

# Install elastodynamicsx and optional dependencies
RUN pip3 install . &&\
pip3 install tqdm pyvista ipygany pythreejs ipyvtklink --upgrade &&\
pip3 install tqdm pyvista[trame] --upgrade &&\
rm -rf /tmp/*


Expand Down
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) 2022 GeoENDGroup / Instrumentation
Copyright (c) 2022-2024 ElastodynamiCSx developers

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
64 changes: 64 additions & 0 deletions demo/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Demos
=====

The following examples illustrate how to use ``elastodynamicsx`` to build and solve problems from begin to end. They can be run in parallel with:

.. code-block:: bash
# run on 2 nodes:
mpiexec -n 2 python3 example.py
Several examples rely on functions that are not embedded in the main .py file (models, analytical solutions): companion files can be found in the `demo/ <https://github.com/Universite-Gustave-Eiffel/elastodynamicsx/tree/main/demo>`_ folder in github.


Time domain
-----------

| **Explicit** scheme
| *Wave propagation modeling*, *Spectral elements*
.. nbgallery::
:maxdepth: 3
:titlesonly:
:glob:

weq*


| **Implicit** scheme
| *Structural dynamics*
.. nbgallery::
:maxdepth: 3
:titlesonly:
:glob:

tdsdyn*


Frequency domain -- Helmoltz equation
-------------------------------------

.. nbgallery::
:maxdepth: 3
:titlesonly:
:glob:

freq*


Eigenmodes
----------

.. nbgallery::
:maxdepth: 3
:titlesonly:
:glob:

eigs*


Guided waves
------------

* *coming soon*
2 changes: 0 additions & 2 deletions demo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
from . import *

Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,5 @@ def src_t(t):


if __name__ == "__main__" :
_test()
# _test()
pass
1 change: 0 additions & 1 deletion demo/analyticalsolutions/__init__.py

This file was deleted.

120 changes: 68 additions & 52 deletions demo/eigs_3D_AluminumCube.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,100 @@
"""
Eigenmodes
Free resonances of an aluminum cube, compared against litterature data
# ---
# jupyter:
# jupytext:
# text_representation:
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.15.2
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
# name: python3
# ---

# # Resonances of an aluminum cube
#
# - Eigenmodes
# - 3D
# - Comparison with literature data

Data from: Ogi, H., Sato, K., Asada, T., & Hirao, M. (2002). Complete mode
identification for resonance ultrasound spectroscopy. The Journal of the
Acoustical Society of America, 112(6), 2553-2557.
"""
# +
import numpy as np

from dolfinx import mesh, fem
from dolfinx import mesh, fem, default_scalar_type
from mpi4py import MPI
from petsc4py import PETSc
import numpy as np

from elastodynamicsx.pde import material, PDE
from elastodynamicsx.solvers import EigenmodesSolver
# -

# -----------------------------------------------------
# FE domain
# -----------------------------------------------------
L1, L2, L3 = 11.92, 10.93, 9.86 # millimeters

Nx = Ny = Nz = 6
# ### FE domain

# +
L1, L2, L3 = 11.92, 10.93, 9.86 # Lengths, in millimeters
Nx = Ny = Nz = 6 # Nb of elts.
extent = [[0., 0., 0.], [L1, L2, L3]]
domain = mesh.create_box(MPI.COMM_WORLD, extent, [Nx, Ny, Nz])
#
V = fem.FunctionSpace(domain, ("Lagrange", 2, (domain.geometry.dim,)))
#
# -----------------------------------------------------

V = fem.FunctionSpace(domain, ("Lagrange", 2, (domain.geometry.dim,)))
# -

# -----------------------------------------------------
# Material parameters
# -----------------------------------------------------
rho, C11, C44 = 2.788, 109.26, 26.72 # Aluminum. rho in g/cm3, Cij in GPa -> freq. in MHz
lambda_ = C11 - 2*C44
# ### Define the material law
# Material:
# - Aluminum
# - isotropic elasticity
#
# Units:
# - $\rho$ in g/cm3
# - $C_{ij}$ in GPa
# - -> frequencies in MHz

# +
rho, C11, C44 = 2.788, 109.26, 26.72
lambda_ = C11 - 2 * C44
mu = C44
rho = fem.Constant(domain, PETSc.ScalarType(rho))
lambda_ = fem.Constant(domain, PETSc.ScalarType(lambda_))
mu = fem.Constant(domain, PETSc.ScalarType(mu))
rho = fem.Constant(domain, default_scalar_type(rho))
lambda_ = fem.Constant(domain, default_scalar_type(lambda_))
mu = fem.Constant(domain, default_scalar_type(mu))

material = material(V, 'isotropic', rho, lambda_, mu)
#
# -----------------------------------------------------
aluminum = material(V, 'isotropic', rho, lambda_, mu)
# -

# ### Assemble the PDE

# -----------------------------------------------------
# Solve
# -----------------------------------------------------
### PDE
pde = PDE(V, materials=[material])
pde = PDE(V, materials=[aluminum])

# ### Solve

### Initialize the solver
eps = EigenmodesSolver(V.mesh.comm, pde.M(), None, pde.K(), nev=20)
# ## Initialize the solver; prepare to solve for 20 eigenvalues
M = pde.M() # mass matrix (PETSc)
C = None # None to ensure no damping
K = pde.K() # stiffness matrix (PETSc)
eps = EigenmodesSolver(V.mesh.comm, M, C, K, nev=20)

### Run the big calculation!
# ## Run the big calculation!
eps.solve()
### End of big calc.
# ## End of big calc.

### Get the result
# +
# ## Get the result
# eps.printEigenvalues()
eigenfreqs = eps.getEigenfrequencies()
# eigenmodes = eps.getEigenmodes()

eps.plot(V, slice(6,6+9), wireframe=True, factor=30) # Avoid the first 6 rigid body modes
#
# -----------------------------------------------------
# -


# ### Compare with literature values
# -----------------------------------------------------
# Compare with litterature values
# -----------------------------------------------------
# Data from: Ogi, H., Sato, K., Asada, T., & Hirao, M. (2002). Complete mode
# identification for resonance ultrasound spectroscopy. The Journal of the
# Acoustical Society of America, 112(6), 2553-2557.
# Data from:
# &emsp; Ogi, H., Sato, K., Asada, T., & Hirao, M. (2002). Complete mode
# identification for resonance ultrasound spectroscopy. *The Journal of the
# Acoustical Society of America*, 112(6), 2553-2557.

# +
freqs_OgiEtAl_exp = np.array([116.716, 143.783, 158.081, 166.5 , 169.523, 177.846, 183.875, 186.047,
190.341, 197.386, 201.133, 207.386, 209.836, 214.753, 223.548, 231.266,
233.538, 234.717, 250.98 , 251.256, 252.742, 256.122, 257.595, 258.118,
Expand All @@ -93,7 +113,3 @@
print(' FE \tOgi et al, calc.\t Ogi et al, exp. \t(kHz)')
for fFE, fOgi_calc, fOgi_exp in zip(eigenfreqs[6:]*1e3, freqs_OgiEtAl_calc, freqs_OgiEtAl_exp): # *1e3 to convert MHz into kHz
print(str(round(fFE, 3)) +"\t "+ str(round(fOgi_calc, 3)) +"\t\t "+ str(round(fOgi_exp, 3)))
#
# -----------------------------------------------------


Loading

0 comments on commit f7cb12b

Please sign in to comment.