Commit 5e56a751 authored by Jeremy BLEYER's avatar Jeremy BLEYER

Added periodic homog example + changes in process files for including zip and notebooks

parent 7513fac1
...@@ -24,8 +24,9 @@ sys.path.insert(0, os.path.abspath('..')) ...@@ -24,8 +24,9 @@ sys.path.insert(0, os.path.abspath('..'))
#sys.path.insert(0, os.path.abspath('../examples</')) #sys.path.insert(0, os.path.abspath('../examples</'))
sys.path.append(os.getcwd()) sys.path.append(os.getcwd())
import rstprocess import process_sources
rstprocess.process() process_sources.process()
# -- General configuration ------------------------------------------------ # -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here. # If your documentation needs a minimal Sphinx version, state it here.
...@@ -35,13 +36,17 @@ rstprocess.process() ...@@ -35,13 +36,17 @@ rstprocess.process()
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones. # ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
'sphinx.ext.mathjax', 'sphinx.ext.napoleon'] 'sphinx.ext.mathjax', 'sphinx.ext.napoleon', 'nbsphinx']
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ['_templates']
source_parsers = {
'.md': 'recommonmark.parser.CommonMarkParser',
}
# The suffix of source filenames. # The suffix of source filenames.
source_suffix = '.rst'#,'.txt'] source_suffix = ['.rst','.md']#,'.txt']
# The encoding of source files. # The encoding of source files.
#source_encoding = 'utf-8-sig' #source_encoding = 'utf-8-sig'
...@@ -58,9 +63,9 @@ copyright = u'2016, Jeremy Bleyer' ...@@ -58,9 +63,9 @@ copyright = u'2016, Jeremy Bleyer'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = '1.0' version = 'master'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = '1.0' release = 'master'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
...@@ -74,7 +79,7 @@ release = '1.0' ...@@ -74,7 +79,7 @@ release = '1.0'
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
exclude_patterns = ['_build'] exclude_patterns = ['_build', '**.ipynb_checkpoints']
# The reST default role (used for this markup: `text`) to use for all # The reST default role (used for this markup: `text`) to use for all
# documents. # documents.
...@@ -186,6 +191,7 @@ html_static_path = ['_static'] ...@@ -186,6 +191,7 @@ html_static_path = ['_static']
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = 'NumericaltoursofcontinuummechanicsusingFEniCSdoc' htmlhelp_basename = 'NumericaltoursofcontinuummechanicsusingFEniCSdoc'
html_short_title = "Numerical tours of continuum mechanics using FEniCS"
# -- Options for LaTeX output --------------------------------------------- # -- Options for LaTeX output ---------------------------------------------
...@@ -204,7 +210,7 @@ latex_elements = { ...@@ -204,7 +210,7 @@ latex_elements = {
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
('index', 'NumericaltoursofcontinuummechanicsusingFEniCS.tex', u'Numerical tours of continuum mechanics using FEniCS Documentation', ('index', 'NumericaltoursofcontinuummechanicsusingFEniCS.tex', u'Numerical tours of continuum mechanics using FEniCS',
u'Jeremy Bleyer', 'manual'), u'Jeremy Bleyer', 'manual'),
] ]
...@@ -216,6 +222,7 @@ latex_documents = [ ...@@ -216,6 +222,7 @@ latex_documents = [
# not chapters. # not chapters.
#latex_use_parts = False #latex_use_parts = False
# If true, show page references after internal links. # If true, show page references after internal links.
#latex_show_pagerefs = False #latex_show_pagerefs = False
...@@ -234,7 +241,7 @@ latex_documents = [ ...@@ -234,7 +241,7 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
('index', 'numericaltoursofcontinuummechanicsusingfenics', u'Numerical tours of continuum mechanics using FEniCS Documentation', ('index', 'numericaltoursofcontinuummechanicsusingfenics', u'Numerical tours of continuum mechanics using FEniCS',
[u'Jeremy Bleyer'], 1) [u'Jeremy Bleyer'], 1)
] ]
...@@ -248,7 +255,7 @@ man_pages = [ ...@@ -248,7 +255,7 @@ man_pages = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
('index', 'NumericaltoursofcontinuummechanicsusingFEniCS', u'Numerical tours of continuum mechanics using FEniCS Documentation', ('index', 'NumericaltoursofcontinuummechanicsusingFEniCS', u'Numerical tours of continuum mechanics using FEniCS',
u'Jeremy Bleyer', 'NumericaltoursofcontinuummechanicsusingFEniCS', 'One line description of project.', u'Jeremy Bleyer', 'NumericaltoursofcontinuummechanicsusingFEniCS', 'One line description of project.',
'Miscellaneous'), 'Miscellaneous'),
] ]
...@@ -264,3 +271,19 @@ texinfo_documents = [ ...@@ -264,3 +271,19 @@ texinfo_documents = [
# If true, do not generate a @detailmenu in the "Top" node's menu. # If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False #texinfo_no_detailmenu = False
#nbsphinx_prolog = """
#Go there: https://example.org/notebooks/{{ env.doc2path(env.docname, base=None) }}
#
#----
#"""
#{% set docname = env.doc2path(env.docname, base='doc') %}
nbsphinx_prolog = r"""
{% set docname = env.docname.split("/")[-1] %}
.. role:: raw-html(raw)
:format: html
.. nbinfo::
The corresponding files can be obtained from:
- Jupyter Notebook: :download:`{{docname+".ipynb"}}`
- Python script: :download:`{{docname+".py"}}`"""
\ No newline at end of file
.. Numerical tours of continuum mechanics using FEniCS documentation master file, created by
sphinx-quickstart on Wed Jun 8 21:25:10 2016.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Homogenization of heterogeneous materials
=========================================
Contents:
.. toctree::
:maxdepth: 1
demo/periodic_homog_elas/periodic_homog_elas.ipynb
...@@ -13,6 +13,7 @@ Contents: ...@@ -13,6 +13,7 @@ Contents:
intro intro
linear_problems linear_problems
homogenization
nonlinear_problems nonlinear_problems
demo/reissner_mindlin/reissner_mindlin.rst demo/reissner_mindlin/reissner_mindlin.rst
tips_and_tricks tips_and_tricks
......
...@@ -10,7 +10,7 @@ Contents: ...@@ -10,7 +10,7 @@ Contents:
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
demo/nonlinear_materials/vonMises_plasticity.py.rst demo/2D_plasticity/vonMises_plasticity.py.rst
...@@ -19,9 +19,11 @@ ...@@ -19,9 +19,11 @@
import sys import sys
import os import os
import shutil import shutil
import zipfile
# extensions of files which must be copied with the demo when building docs # extensions of files which must be copied with the demo when building docs
file_extensions = [".png",".gif", ".geo", ".xml", ".msh", ".pdf"] file_extensions = [".png",".gif", ".geo", ".xml", ".msh", ".pdf"]
zipfile_extensions = [".geo", ".msh", ".xml", ".py", ".ipynb"]
def process(): def process():
"""Copy demo rst files (C++ and Python) from the DOLFIN source tree """Copy demo rst files (C++ and Python) from the DOLFIN source tree
...@@ -36,7 +38,7 @@ def process(): ...@@ -36,7 +38,7 @@ def process():
# Directories to scan # Directories to scan
subdirs = ["../examples"] subdirs = ["../examples"]
retval = os.getcwd()
# Iterate over subdirectories containing demos # Iterate over subdirectories containing demos
for subdir in subdirs: for subdir in subdirs:
...@@ -55,28 +57,51 @@ def process(): ...@@ -55,28 +57,51 @@ def process():
if not os.path.isdir(version_path): if not os.path.isdir(version_path):
continue continue
# Build list of rst files in demo source directory
rst_files = [f for f in os.listdir(version_path) if os.path.splitext(f)[1] == ".rst" ]
# Create directory in documentation tree for demo # Create directory in documentation tree for demo
demo_dir = os.path.join('./demo/', demo, version) demo_dir = os.path.join('./demo/', demo)
if not os.path.exists(demo_dir): if not os.path.exists(demo_dir):
os.makedirs(demo_dir) os.makedirs(demo_dir)
ipynb_files = [f for f in os.listdir(version_path) if f.endswith("ipynb") ]
for f in ipynb_files:
ff = os.path.join(path, f)
shutil.copy(ff, demo_dir)
ret = os.system("jupyter-nbconvert --to script %s --output %s" % (ff, os.path.join("../../doc",demo_dir, os.path.splitext(f)[0])))
if not ret == 0:
raise RuntimeError("Unable to convert ipynb file to a .py ({})".format(f))
# Build list of rst files in demo source directory
rst_files = [f for f in os.listdir(version_path) if f.endswith("rst") ]
# Copy rst files into documentation demo directory and process with Pylit # Copy rst files into documentation demo directory and process with Pylit
for f in rst_files: for f in rst_files:
shutil.copy(os.path.join(version_path, f), demo_dir) shutil.copy(os.path.join(version_path, f), demo_dir)
# Run pylit on cpp.rst and py.rst files (file with 'double extensions') # Run pylit on cpp.rst and py.rst files (file with 'double extensions')
if os.path.splitext(os.path.splitext(f)[0])[1] in (".py"): if "py" in f.split("."):
rst_file = os.path.join(demo_dir, f) rst_file = os.path.join(demo_dir, f)
command = pylit_parser + " " + rst_file command = pylit_parser + " " + rst_file
ret = os.system("python "+command) ret = os.system("python "+command)
if not ret == 0: if not ret == 0:
raise RuntimeError("Unable to convert rst file to a .py ({})".format(f)) raise RuntimeError("Unable to convert rst file to a .py ({})".format(f))
tocopy_files = [f for f in os.listdir(version_path) if os.path.splitext(f)[1] in file_extensions ] tocopy_files = [f for f in os.listdir(version_path) if os.path.splitext(f)[1] in file_extensions ]
for f in tocopy_files: for f in tocopy_files:
source = os.path.join(version_path, f) source = os.path.join(version_path, f)
print("Copying {} to {}".format(source, demo_dir)) print("Copying {} to {}".format(source, demo_dir))
shutil.copy(source, demo_dir) shutil.copy(source, demo_dir)
for f in ipynb_files + rst_files:
cwd = os.getcwd()
os.chdir(demo_dir)
files = os.listdir(".")
zip_files = []
for ff in files:
if any([ff.endswith(ext) for ext in zipfile_extensions]):
zip_files.append(ff)
with zipfile.ZipFile(f.split(".")[0]+".zip", 'w') as myzip:
for a in zip_files:
myzip.write(a, compress_type=zipfile.ZIP_DEFLATED)
os.chdir(cwd)
...@@ -14,7 +14,7 @@ von Mises material. The structure response is computed using an iterative ...@@ -14,7 +14,7 @@ von Mises material. The structure response is computed using an iterative
predictor-corrector return mapping algorithm embedded in a Newton-Raphson global predictor-corrector return mapping algorithm embedded in a Newton-Raphson global
loop for restoring equilibrium. Due to the simple expression of the von Mises criterion, loop for restoring equilibrium. Due to the simple expression of the von Mises criterion,
the return mapping procedure is completely analytical (with linear isotropic the return mapping procedure is completely analytical (with linear isotropic
hardening). The corresponding file can be obtained from :download:`vonMises_plasticity.py`. hardening). The corresponding sources can be obtained from :download:`vonMises_plasticity.zip`.
Another implementation of von Mises plasticity can also be found at Another implementation of von Mises plasticity can also be found at
https://bitbucket.org/fenics-apps/fenics-solid-mechanics. https://bitbucket.org/fenics-apps/fenics-solid-mechanics.
......
...@@ -15,7 +15,7 @@ Introduction ...@@ -15,7 +15,7 @@ Introduction
In this first numerical tour, we will show how to compute a small strain solution for In this first numerical tour, we will show how to compute a small strain solution for
a 2D isotropic linear elastic medium, either in plane stress or in plane strain, a 2D isotropic linear elastic medium, either in plane stress or in plane strain,
in a tradtional displacement-based finite element formulation. The corresponding in a tradtional displacement-based finite element formulation. The corresponding
file can be obtained from :download:`2D_elasticity.py`.Extension to 3D file can be obtained from :download:`2D_elasticity.py`. Extension to 3D
is straightforward and an example can be found in the :ref:`ModalAnalysis` example. is straightforward and an example can be found in the :ref:`ModalAnalysis` example.
We consider here the case of a cantilever beam modeled as a 2D medium of dimensions We consider here the case of a cantilever beam modeled as a 2D medium of dimensions
......
// Gmsh project created on Mon Sep 14 09:33:57 2015
a = 1.;
R = 0.2;
t = Pi/3;
b = Sin(t)*a;
bR = Sin(t)*R;
c = a*Cos(t);
cR = R*Cos(t);
d = 1.;
nx = 80;
nR = R*nx;
ns = nx-2*nR;
Point(1) = {0, 0, 0, d};
Point(2) = {a, 0, 0, d};
Point(3) = {a+c, b, 0, d};
Point(4) = {c, b, 0, d};
Point(5) = {R,0,0,d};
Point(6) = {a-R,0,0,d};
Point(7) = {a+cR,bR,0,d};
Point(8) = {a+c-cR,b-bR,0,d};
Point(9) = {a+c-R,b,0,d};
Point(10) = {c+R,b,0,d};
Point(11) = {c-cR,b-bR,0,d};
Point(12) = {cR,bR,0,d};
Line(1) = {1, 5};
Line(2) = {5, 6};
Line(3) = {6, 2};
Line(4) = {2, 7};
Line(5) = {7, 8};
Line(6) = {8, 3};
Line(7) = {3, 9};
Line(8) = {9, 10};
Line(9) = {10, 4};
Line(10) = {4, 11};
Line(11) = {11, 12};
Line(12) = {12, 1};
Circle(13) = {5, 1, 12};
Circle(14) = {7, 2, 6};
Circle(15) = {9, 3, 8};
Circle(16) = {11, 4, 10};
Line Loop(17) = {13, -11, 16, -8, 15, -5, 14, -2};
Plane Surface(18) = {17};
Line Loop(19) = {1, 13, 12};
Plane Surface(20) = {19};
Line Loop(21) = {3, 4, 14};
Plane Surface(22) = {21};
Line Loop(23) = {7, 15, 6};
Plane Surface(24) = {23};
Line Loop(25) = {10, 16, 9};
Plane Surface(26) = {25};
Transfinite Line{1,3,4,6,7,9,10,12} = nR;
Transfinite Line{2,5,8,11} = ns;
Transfinite Line{14,16} = 2*nR;
Transfinite Line{13,15} = nR;
Periodic Line{1} = {9};
Periodic Line{2} = {8};
Periodic Line{3} = {7};
Periodic Line{4} = {12};
Periodic Line{5} = {11};
Periodic Line{6} = {10};
Physical Line(1) = {1,2,3};
Physical Line(2) = {4,5,6};
Physical Line(3) = {7,8,9};
Physical Line(4) = {10,11,12};
Physical Surface(0) = {18};
Physical Surface(1) = {20,22,24,26};
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment