├── .github
├── dependabot.yml
└── workflows
│ └── tests.yml
├── .gitignore
├── COPYING
├── COPYING.LESSER
├── README.md
├── demo
├── conftest.py
├── demo_kirchhoff-love-clamped.py
├── demo_nonlinear-naghdi-clamped-semicylinder.py
├── demo_reissner-mindlin-clamped-tdnns.py
├── demo_reissner-mindlin-clamped.py
├── demo_reissner-mindlin-simply-supported.py
├── pytest.ini
└── test_demos.py
├── doc
├── README.md
└── source
│ ├── .gitignore
│ ├── _static
│ └── .placeholder
│ ├── conf.py
│ ├── demos.rst
│ ├── index.rst
│ └── jupytext_process.py
├── launch-container.sh
├── pyproject.toml
├── src
└── fenicsx_shells
│ └── __init__.py
└── test
└── .placeholder
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "github-actions" # See documentation for possible values
9 | directory: "/" # Location of package manifests
10 | schedule:
11 | interval: "weekly"
12 | - package-ecosystem: "pip" # See documentation for possible values
13 | directory: "/"
14 | schedule:
15 | interval: "weekly"
16 |
--------------------------------------------------------------------------------
/.github/workflows/tests.yml:
--------------------------------------------------------------------------------
1 | name: tests
2 | on:
3 | push:
4 | branches:
5 | - "**"
6 |
7 | schedule:
8 | - cron: '0 0 * * 1'
9 |
10 | pull_request:
11 | branches:
12 | - main
13 |
14 | jobs:
15 | build-and-test:
16 | runs-on: ubuntu-latest
17 | container: ghcr.io/fenics/dolfinx/dolfinx:nightly
18 | steps:
19 | - name: Checkout
20 | uses: actions/checkout@v4
21 |
22 | - name: Install FEniCSx-Shells
23 | run: |
24 | python3 -m pip install --no-build-isolation --check-build-dependencies '.[ci]'
25 |
26 | - name: ruff checks
27 | run: |
28 | ruff check .
29 | ruff format --check .
30 |
31 | - name: Build documentation
32 | run: |
33 | cd doc
34 | python3 -m sphinx -W -b html source/ build/html/
35 |
36 | - name: Run demos
37 | run: |
38 | python3 -m pytest demo
39 |
40 | - name: Create documentation artifact
41 | run: |
42 | tar \
43 | --dereference --hard-dereference \
44 | --directory doc/build/html \
45 | -cvf artifact.tar \
46 | --exclude=.git \
47 | --exclude=.github \
48 | .
49 |
50 | - name: Upload documentation artifact
51 | uses: actions/upload-artifact@v4
52 | with:
53 | name: github-pages
54 | path: artifact.tar
55 | retention-days: 1
56 |
57 | deploy:
58 | needs: build-and-test
59 | if: github.ref == 'refs/heads/main'
60 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
61 | permissions:
62 | pages: write
63 | id-token: write
64 | environment:
65 | name: github-pages
66 | url: ${{ steps.deployment.outputs.page_url }}
67 |
68 | runs-on: ubuntu-latest
69 | steps:
70 | - name: Setup Pages
71 | uses: actions/configure-pages@v5
72 | - name: Deploy to GitHub Pages
73 | id: deployment
74 | uses: actions/deploy-pages@v4
75 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Typical DOLFINx output
2 | *.xdmf
3 | *.h5
4 |
5 | # Byte-compiled / optimized / DLL files
6 | __pycache__/
7 | *.py[cod]
8 | *$py.class
9 |
10 | # C extensions
11 | *.so
12 |
13 | # Distribution / packaging
14 | .Python
15 | build/
16 | develop-eggs/
17 | dist/
18 | downloads/
19 | eggs/
20 | .eggs/
21 | lib/
22 | lib64/
23 | parts/
24 | sdist/
25 | var/
26 | wheels/
27 | pip-wheel-metadata/
28 | share/python-wheels/
29 | *.egg-info/
30 | .installed.cfg
31 | *.egg
32 | MANIFEST
33 |
34 | # PyInstaller
35 | # Usually these files are written by a python script from a template
36 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
37 | *.manifest
38 | *.spec
39 |
40 | # Installer logs
41 | pip-log.txt
42 | pip-delete-this-directory.txt
43 |
44 | # Unit test / coverage reports
45 | htmlcov/
46 | .tox/
47 | .nox/
48 | .coverage
49 | .coverage.*
50 | .cache
51 | nosetests.xml
52 | coverage.xml
53 | *.cover
54 | *.py,cover
55 | .hypothesis/
56 | .pytest_cache/
57 |
58 | # Translations
59 | *.mo
60 | *.pot
61 |
62 | # Django stuff:
63 | *.log
64 | local_settings.py
65 | db.sqlite3
66 | db.sqlite3-journal
67 |
68 | # Flask stuff:
69 | instance/
70 | .webassets-cache
71 |
72 | # Scrapy stuff:
73 | .scrapy
74 |
75 | # Sphinx documentation
76 | docs/_build/
77 |
78 | # PyBuilder
79 | target/
80 |
81 | # Jupyter Notebook
82 | .ipynb_checkpoints
83 |
84 | # IPython
85 | profile_default/
86 | ipython_config.py
87 |
88 | # pyenv
89 | .python-version
90 |
91 | # pipenv
92 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
94 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
95 | # install all needed dependencies.
96 | #Pipfile.lock
97 |
98 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
99 | __pypackages__/
100 |
101 | # Celery stuff
102 | celerybeat-schedule
103 | celerybeat.pid
104 |
105 | # SageMath parsed files
106 | *.sage.py
107 |
108 | # Environments
109 | .env
110 | .venv
111 | env/
112 | venv/
113 | ENV/
114 | env.bak/
115 | venv.bak/
116 |
117 | # Spyder project settings
118 | .spyderproject
119 | .spyproject
120 |
121 | # Rope project settings
122 | .ropeproject
123 |
124 | # mkdocs documentation
125 | /site
126 |
127 | # mypy
128 | .mypy_cache/
129 | .dmypy.json
130 | dmypy.json
131 |
132 | # Pyre type checker
133 | .pyre/
134 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
676 |
677 | Note: Individual files contain the following tag instead of the full license text.
678 |
679 | SPDX-License-Identifier: LGPL-3.0-or-later
680 | This enables machine processing of license information based on the SPDX License Identifiers that are here available: http://spdx.org/licenses/
--------------------------------------------------------------------------------
/COPYING.LESSER:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FEniCSx-Shells
2 |
3 | A FEniCS Project-based library for simulating thin structures.
4 |
5 | [](https://github.com/FEniCS-Shells/fenicsx-shells/actions/workflows/tests.yml)
6 | [](https://fenics-shells.github.io/fenicsx-shells)
7 |
8 | ## Description
9 |
10 | FEniCSx-Shells is an open-source library that provides finite element-based
11 | numerical methods for solving a wide range of thin structural models (beams,
12 | plates and shells) expressed in the Unified Form Language (UFL) of the FEniCS
13 | Project.
14 |
15 | *FEniCSx-Shells is an experimental version targeting version v0.10.0.dev0 of the new
16 | [DOLFINx solver](https://github.com/fenics/dolfinx).*
17 |
18 | The foundational aspects of the FEniCS-Shells project are described in the paper:
19 |
20 | Simple and extensible plate and shell finite element models through automatic
21 | code generation tools, J. S. Hale, M. Brunetti, S. P. A. Bordas, C. Maurini.
22 | Computers & Structures, 209, 163-181,
23 | [doi:10.1016/j.compstruc.2018.08.001](https://doi.org/10.1016/j.compstruc.2018.08.001).
24 |
25 | ## Documentation
26 |
27 | The documentation can be viewed [here](https://fenics-shells.github.io/fenicsx-shells).
28 |
29 | ## Features
30 |
31 | FEniCSx-Shells currently includes implementations of the following structural models:
32 |
33 | * Reissner-Mindlin plates.
34 | * Kirchhoff-Love plates.
35 |
36 | A roadmap for future developments will be shared soon.
37 |
38 | We are using a variety of numerical techniques for discretising the PDEs
39 | including:
40 |
41 | * Mixed Interpolation of Tensorial Component (MITC) reduction operators.
42 | * Tangential Displacement Normal-Normal Derivative (TDNNS) methods.
43 | * Hellman-Herrmann-Johnson (HHJ) finite elements.
44 |
45 | ## Citing
46 |
47 | Please consider citing the old FEniCS-Shells paper and code if you find this
48 | repository useful.
49 |
50 | ```
51 | @article{hale_simple_2018,
52 | title = {Simple and extensible plate and shell finite element models through automatic code generation tools},
53 | volume = {209},
54 | issn = {0045-7949},
55 | url = {http://www.sciencedirect.com/science/article/pii/S0045794918306126},
56 | doi = {10.1016/j.compstruc.2018.08.001},
57 | journal = {Computers \& Structures},
58 | author = {Hale, Jack S. and Brunetti, Matteo and Bordas, Stéphane P. A. and Maurini, Corrado},
59 | month = oct,
60 | year = {2018},
61 | keywords = {Domain specific language, FEniCS, Finite element methods, Plates, Shells, Thin structures},
62 | pages = {163--181},
63 | }
64 | ```
65 | along with the appropriate general [FEniCS citations](http://fenicsproject.org/citing).
66 |
67 | ## Authors
68 |
69 | - Jack S. Hale, University of Luxembourg, Luxembourg.
70 | - Tian Yang, EPFL, Switzerland.
71 |
72 | FEniCSx-Shells contains code and text adapted from the FEniCS-Shells project
73 | hosted on [BitBucket](https://bitbucket.org/unilucompmech/fenics-shells)
74 | authored by:
75 |
76 | - Matteo Brunetti, University of Udine, Udine.
77 | - Jack S. Hale, University of Luxembourg, Luxembourg.
78 | - Corrado Maurini, Sorbonne Université, France.
79 |
80 | ## Contributing
81 |
82 | We are always looking for contributions and help with FEniCSx-Shells. If you
83 | have ideas, nice applications or code contributions then we would be happy to
84 | help you get them included. We ask you to follow the FEniCS Project git
85 | workflow.
86 |
87 | ## Issues and Support
88 |
89 | Please use the GitHub issue tracker to report any issues.
90 |
91 | ## License
92 |
93 | FEniCSx-Shells is free software: you can redistribute it and/or
94 | modify it under the terms of the GNU Lesser General Public License as published
95 | by the Free Software Foundation, either version 3 of the License, or (at your
96 | option) any later version.
97 |
98 | This program is distributed in the hope that it will be useful, but WITHOUT ANY
99 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
100 | PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
101 | details.
102 |
103 | You should have received a copy of the GNU Lesser General Public License along
104 | with FEniCSx-Shells. If not, see http://www.gnu.org/licenses/.
105 |
--------------------------------------------------------------------------------
/demo/conftest.py:
--------------------------------------------------------------------------------
1 | import pytest
2 |
3 |
4 | def pytest_addoption(parser):
5 | parser.addoption(
6 | "--mpiexec",
7 | action="store",
8 | default="mpirun",
9 | help="Name of program to run MPI, e.g. mpiexex",
10 | )
11 | parser.addoption("--num-proc", action="store", default=1, help="Number of MPI processes to use")
12 |
13 |
14 | @pytest.fixture
15 | def mpiexec(request):
16 | return request.config.getoption("--mpiexec")
17 |
18 |
19 | @pytest.fixture
20 | def num_proc(request):
21 | return request.config.getoption("--num-proc")
22 |
--------------------------------------------------------------------------------
/demo/demo_kirchhoff-love-clamped.py:
--------------------------------------------------------------------------------
1 | # ---
2 | # jupyter:
3 | # jupytext:
4 | # text_representation:
5 | # extension: .py
6 | # format_name: light
7 | # format_version: '1.5'
8 | # jupytext_version: 1.14.1
9 | # ---
10 |
11 | # # Clamped Kirchoff-Love plate under uniform load
12 | #
13 | # This demo program solves the out-of-plane Kirchoff-Love equations on the
14 | # unit square with uniform transverse loading and fully clamped boundary
15 | # conditions.
16 | #
17 | # It is assumed the reader understands most of the basic functionality of the
18 | # new FEniCSx Project.
19 | #
20 | # This demo illustrates how to:
21 | #
22 | # - Define the Kirchhoff-Love plate equations using UFL using the mixed finite
23 | # element formulation of Hellan-Herrmann-Johnson.
24 | #
25 | # A modern presentation of this approach can be found in the paper
26 | #
27 | # Arnold, D. N., Walker S. W., The Hellan--Herrmann--Johnson Method with Curved
28 | # Elements, SIAM Journal on Numerical Analysis 58:5, 2829-2855 (2020),
29 | # [doi:10.1137/19M1288723](https://doi.org/10.1137/19M1288723).
30 | #
31 | # We remark that this model can be recovered formally from the Reissner-Mindlin
32 | # models by taking the limit in the thickness $t \to 0$ and setting $\theta =
33 | # \grad w$.
34 | #
35 | # We begin by importing the necessary functionality from DOLFINx, UFL and
36 | # PETSc.
37 |
38 | from mpi4py import MPI
39 |
40 | import numpy as np
41 |
42 | import dolfinx
43 | import ufl
44 | from basix.ufl import element, mixed_element
45 | from dolfinx.fem import dirichletbc, functionspace
46 | from dolfinx.fem.petsc import LinearProblem
47 | from dolfinx.mesh import CellType, create_unit_square
48 | from ufl import FacetNormal, Identity, Measure, grad, inner, sym, tr
49 |
50 | # We then create a two-dimensional mesh of the mid-plane of the plate $\Omega =
51 | # [0, 1] \times [0, 1]$.
52 |
53 | mesh = create_unit_square(MPI.COMM_WORLD, 16, 16, CellType.triangle)
54 |
55 | # The Hellen-Herrmann-Johnson element for the Kirchhoff-Love plate problem
56 | # consists of:
57 | #
58 | # - $k + 1$-th order scalar-valued Lagrange element for the transverse displacement field
59 | # $w \in \mathrm{CG}_{k + 1}$ and,
60 | # - $k$-th order Hellan-Herrmann-Johnson finite elements for the bending moments, which
61 | # naturally discretise tensor-valued functions in $H(\mathrm{div}\;\mathrm{\bf{div}})$,
62 | # $M \in \mathrm{HHJ}_k$.
63 | #
64 | # The final element definition is
65 |
66 | # +
67 | k = 2
68 | U_el = mixed_element(
69 | [element("Lagrange", mesh.basix_cell(), k + 1), element("HHJ", mesh.basix_cell(), k)]
70 | )
71 | U = functionspace(mesh, U_el)
72 |
73 | w, M = ufl.TrialFunctions(U)
74 | w_t, M_t = ufl.TestFunctions(U)
75 |
76 | # -
77 |
78 | # We assume constant material parameters; Young's modulus $E$, Poisson's ratio
79 | # $\nu$, shear-correction factor $\kappa$, and thickness $t$.
80 |
81 | # +
82 | E = 10920.0
83 | nu = 0.3
84 | t = 0.001
85 |
86 | # -
87 |
88 | # The weak form for the problem can be written as:
89 | #
90 | # Find $(w, M) \in \mathrm{CG}_{k + 1} \times \mathrm{HHJ}_k$ such that
91 | #
92 | # $$
93 | # \left( k(M), \tilde{M} \right) + \left< \tilde{M}, \theta(w) \right> + \left<
94 | # M, \theta(\tilde{w}) \right> = -\left(f, \tilde{w} \right) \quad \forall
95 | # (\tilde{w}, \tilde{M}) \in \mathrm{CG}_{k + 1} \times \mathrm{HHJ}_k,
96 | # $$
97 | # where $\left( \cdot, \cdot \right)$ is the usual $L^2$ inner product on the
98 | # mesh $\Omega$.
99 | # The rotations $\theta$ for the Kirchhoff-Love model can be written in
100 | # terms of the transverse displacements
101 | #
102 | # $$
103 | # \theta(w) = \nabla w.
104 | # $$
105 | #
106 | # The bending strain tensor $k$ for the Kirchoff-Love model can be expressed
107 | # in terms of the rotations
108 | #
109 | # $$
110 | # k(\theta) = \dfrac{1}{2}(\nabla \theta + (\nabla \theta)^T).
111 | # $$
112 | #
113 | # The bending strain tensor $k$ can also be written in terms of the bending
114 | # moments $M$
115 | #
116 | # $$
117 | # k(M) = \frac{12}{E t^3} \left[ (1 + \nu) M - \nu \mathrm{tr}\left( M \right) I \right],
118 | # $$
119 | # with $\mathrm{tr}$ the trace operator and $I$ the identity tensor.
120 | #
121 | # The inner product $\left< \cdot, \cdot \right>$ is defined by
122 | #
123 | # $$
124 | # \left< M, \theta \right> = -\left( M, k(\theta) \right) + \int_{\partial K}
125 | # M_{nn} \cdot [[ \theta ]]_n \; \mathrm{d}s,
126 | # $$
127 | # where $M_{nn} = \left(Mn \right) \cdot n$ is the normal-normal component of
128 | # the bending moment, $\partial K$ are the facets of the mesh, $[[ \theta ]]$ is
129 | # the jump in the normal component of the rotations on the facets (reducing to
130 | # simply $\theta \cdot n$ on the exterior facets).
131 | #
132 | # The above equations can be written relatively straightforwardly in UFL as:
133 |
134 | # +
135 | dx = Measure("dx", mesh)
136 | dS = Measure("dS", mesh)
137 | ds = Measure("ds", mesh)
138 |
139 |
140 | def theta(w):
141 | """Rotations in terms of transverse displacements"""
142 | return grad(w)
143 |
144 |
145 | def k_theta(theta):
146 | """Bending strain tensor in terms of rotations"""
147 | return sym(grad(theta))
148 |
149 |
150 | def k_M(M):
151 | """Bending strain tensor in terms of bending moments"""
152 | return (12.0 / (E * t**3)) * ((1.0 + nu) * M - nu * Identity(2) * tr(M))
153 |
154 |
155 | def nn(M):
156 | """Normal-normal component of tensor"""
157 | n = FacetNormal(M.ufl_domain())
158 | M_n = ufl.dot(M, n)
159 | M_nn = ufl.dot(M_n, n)
160 | return M_nn
161 |
162 |
163 | def inner_divdiv(M, theta):
164 | """Discrete div-div inner product"""
165 | n = FacetNormal(M.ufl_domain())
166 | M_nn = nn(M)
167 | result = (
168 | -inner(M, k_theta(theta)) * dx
169 | + inner(M_nn("+"), ufl.jump(theta, n)) * dS
170 | + inner(M_nn, ufl.dot(theta, n)) * ds
171 | )
172 | return result
173 |
174 |
175 | a = inner(k_M(M), M_t) * dx + inner_divdiv(M_t, theta(w)) + inner_divdiv(M, theta(w_t))
176 | L = -inner(t**3, w_t) * dx
177 |
178 |
179 | def all_boundary(x):
180 | return np.full(x.shape[1], True, dtype=bool)
181 |
182 |
183 | # -
184 |
185 | # We apply clamped boundary conditions on the entire boundary. The essential
186 | # boundary condition $w = 0$ is enforced directly in the finite element space,
187 | # while the condition $\nabla w \cdot n = 0$ is a natural condition that is
188 | # satisfied when the corresponding essential condition on $m_{nn}$ is dropped.
189 |
190 | # TODO: Add table like TDNNS example.
191 |
192 | # +
193 | boundary_entities = dolfinx.mesh.locate_entities_boundary(mesh, mesh.topology.dim - 1, all_boundary)
194 |
195 | bcs = []
196 | # Transverse displacement
197 | boundary_dofs_displacement = dolfinx.fem.locate_dofs_topological(
198 | U.sub(0), mesh.topology.dim - 1, boundary_entities
199 | )
200 | bcs.append(dirichletbc(np.array(0.0, dtype=np.float64), boundary_dofs_displacement, U.sub(0)))
201 |
202 |
203 | # -
204 |
205 | # Finally we solve the problem and output the transverse displacement at the
206 | # centre of the plate.
207 |
208 | # +
209 | problem = LinearProblem(
210 | a,
211 | L,
212 | bcs=bcs,
213 | petsc_options={"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"},
214 | )
215 | u_h = problem.solve()
216 |
217 | bb_tree = dolfinx.geometry.bb_tree(mesh, 2)
218 | point = np.array([[0.5, 0.5, 0.0]], dtype=np.float64)
219 | cell_candidates = dolfinx.geometry.compute_collisions_points(bb_tree, point)
220 | cells = dolfinx.geometry.compute_colliding_cells(mesh, cell_candidates, point)
221 |
222 | w, M = u_h.split()
223 |
224 | if cells.array.shape[0] > 0:
225 | value = w.eval(point, cells.array[0])
226 | print(value[0])
227 |
--------------------------------------------------------------------------------
/demo/demo_nonlinear-naghdi-clamped-semicylinder.py:
--------------------------------------------------------------------------------
1 | # %% [markdown]
2 | # # Clamped semi-cylindrical Naghdi shell under point load
3 | #
4 | # Authors: Tian Yang (FEniCSx-Shells), Matteo Brunetti (FEniCS-Shells)
5 | #
6 | # %% [markdown]
7 | # This demo program solves the nonlinear Naghdi shell equations for a
8 | # semi-cylindrical shell loaded by a point force.
9 | #
10 | # This problem is a standard reference for testing shell finite element
11 | # formulations, see [1]. The numerical locking issue is cured using enriched
12 | # finite element including cubic bubble shape functions and Partial Selective
13 | # Reduced Integration (PRSI) [2].
14 | #
15 | # It is assumed the reader understands most of the basic functionality of the
16 | # new FEniCSx Project.
17 | #
18 | # This demo then illustrates how to:
19 | #
20 | # - Define and solve a nonlinear Naghdi shell problem with a curved stress-free
21 | # configuration given as analytical expression in terms of two curvilinear
22 | # coordinates.
23 | # - Use the PSRI approach to simultaneously cure shear- and membrane-locking
24 | # issues.
25 | #
26 | # We begin by importing the necessary functionality from DOLFINx, UFL and
27 | # PETSc.
28 | #
29 | # %%
30 | import typing
31 | from pathlib import Path
32 |
33 | # %%
34 | from mpi4py import MPI
35 | from petsc4py import PETSc
36 |
37 | import matplotlib.pyplot as plt
38 | import numpy as np
39 |
40 | import dolfinx
41 | import ufl
42 |
43 | # %%
44 | from basix.ufl import blocked_element, element, enriched_element, mixed_element
45 | from dolfinx.fem import Expression, Function, dirichletbc, functionspace, locate_dofs_topological
46 | from dolfinx.fem.bcs import DirichletBC
47 | from dolfinx.fem.function import Function as _Function
48 | from dolfinx.fem.petsc import NonlinearProblem, apply_lifting, assemble_vector, set_bc
49 | from dolfinx.mesh import CellType, create_rectangle, locate_entities_boundary
50 | from dolfinx.nls.petsc import NewtonSolver
51 | from ufl import grad, inner, split
52 |
53 | # %% [markdown]
54 | # We consider a semi-cylindrical shell of radius $r$ and axis length $L$. The
55 | # shell is made of a linear elastic isotropic homogeneous material with Young
56 | # modulus $E$ and Poisson ratio $\nu$. The (uniform) shell thickness is denoted
57 | # by $t$. The Lamé moduli $\lambda$, $\mu$ are introduced to write later the 2D
58 | # constitutive equation in plane-stress:
59 | #
60 | # %%
61 | r = 1.016
62 | L = 3.048
63 | E, nu = 2.0685e7, 0.3
64 | mu = E / (2.0 * (1.0 + nu))
65 | lmbda = 2.0 * mu * nu / (1.0 - 2.0 * nu)
66 | t = 0.03
67 | # %% [markdown]
68 | # The midplane of the initial (stress-free) configuration $\vec{\phi_0}$ of the
69 | # shell is given in the form of an analytical expression:
70 | #
71 | # $$
72 | # \vec{\phi}_0(\xi_1, \xi_2) \subset \mathbb{R}³
73 | # $$
74 | #
75 | # where $\xi_1 \in [-\pi/2, \pi/2]$ and $\xi_2 \in [0, L]$ are the curvilinear
76 | # coordinates. In this case, they represent the angular and axial coordinates,
77 | # respectively.
78 | #
79 | # %% [markdown]
80 | # We generate a mesh in the $(\xi_1, \xi_2)$ space with quadrilateral cells
81 | #
82 | # %%
83 | mesh = create_rectangle(
84 | MPI.COMM_WORLD, np.array([[-np.pi / 2, 0], [np.pi / 2, L]]), [20, 20], CellType.triangle
85 | )
86 | tdim = mesh.topology.dim # = 2
87 |
88 | # %% [markdown]
89 | # We provide the analytical expression of the initial shape as a `ufl`
90 | # expression
91 | #
92 | # %%
93 | x = ufl.SpatialCoordinate(mesh)
94 | phi0_ufl = ufl.as_vector([r * ufl.sin(x[0]), x[1], r * ufl.cos(x[0])])
95 |
96 |
97 | # %% [markdown]
98 | # Given the analytical expression of midplane, we define the unit normal as
99 | # below:
100 | #
101 | # $$
102 | # \vec{n} = \frac{\partial_1 \phi_0 \times \partial_2 \phi_0}{\| \partial_1 \phi_0 \times
103 | # \partial_2 \phi_0 \|}
104 | # $$
105 | #
106 | # %%
107 | def unit_normal(phi):
108 | n = ufl.cross(phi.dx(0), phi.dx(1))
109 | return n / ufl.sqrt(inner(n, n))
110 |
111 |
112 | n0_ufl = unit_normal(phi0_ufl)
113 |
114 |
115 | # %% [markdown]
116 | # We define a local orthonormal frame $\{\vec{t}_{01}, \vec{t}_{02}, \vec{n}\}$
117 | # of the initial configuration $\phi_0$ by rotating the global Cartesian basis
118 | # $\vec{e}_i$ with a rotation matrix $\mathbf{R}_0$:
119 | #
120 | # $$
121 | # \vec{t}_{0i} = \mathbf{R}_0 \vec{e}_i , \quad \vec{n} = \vec{t}_{03},
122 | # $$
123 | #
124 | # A convienient choice of $\vec{t}_{01}$ and $\vec{t}_{02}$ (when $\vec{n}
125 | # \nparallel \vec{e}_2 $) could be:
126 | #
127 | # $$
128 | # \vec{t}_{01} = \frac{\vec{e}_2 \times \vec{n}}{\| \vec{e}_2 \times \vec{n}\|} \\
129 | # \vec{t}_{02} = \vec{n} \times \vec{t}_{01}
130 | # $$
131 | #
132 | # The corresponding rotation matrix $\mathbf{R}_0$:
133 | #
134 | # $$
135 | # \mathbf{R}_0 = [\vec{t}_{01}; \vec{t}_{02}; \vec{n}]
136 | # $$
137 | #
138 | # %%
139 | def tangent_1(n):
140 | e2 = ufl.as_vector([0, 1, 0])
141 | t1 = ufl.cross(e2, n)
142 | t1 = t1 / ufl.sqrt(inner(t1, t1))
143 | return t1
144 |
145 |
146 | def tangent_2(n, t1):
147 | t2 = ufl.cross(n, t1)
148 | t2 = t2 / ufl.sqrt(inner(t2, t2))
149 | return t2
150 |
151 |
152 | # The analytical expression of t1 and t2
153 | t1_ufl = tangent_1(n0_ufl)
154 | t2_ufl = tangent_2(n0_ufl, t1_ufl)
155 |
156 |
157 | # The analytical expression of R0
158 | def rotation_matrix(t1, t2, n):
159 | R = ufl.as_matrix([[t1[0], t2[0], n[0]], [t1[1], t2[1], n[1]], [t1[2], t2[2], n[2]]])
160 | return R
161 |
162 |
163 | R0_ufl = rotation_matrix(t1_ufl, t2_ufl, n0_ufl)
164 |
165 |
166 | # %% [markdown]
167 | # The kinematics of the Nadghi shell model is defined by the following vector
168 | # fields:
169 | # - $\vec{\phi}$: the position of the midplane in the deformed configuration,
170 | # or equivalently, the displacement $\vec{u} = \vec{\phi} - \vec{\phi}_0$
171 | # - $\vec{d}$: the director, a unit vector giving the orientation of fiber at
172 | # the midplane. (not necessarily normal to the midsplane because of shears)
173 | #
174 | # According to [3], the director $\vec{d}$ in the deformed configuration can be
175 | # parameterized with two successive rotation angles $\theta_1, \theta_2$
176 | #
177 | # $$
178 | # \vec{t}_i = \mathbf{R} \vec{e}_i, \quad \mathbf{R} = \text{exp}[\theta_1
179 | # \hat{\mathbf{t}}_1] \text{exp}[\theta_2 \hat{\mathbf{t}}_{02}] \mathbf{R}_0
180 | # $$
181 | #
182 | # The rotation matrix $\mathbf{R}$ represents three successive rotations:
183 | # - First one: the initial rotation matrix $\mathbf{R}_0$
184 | # - Second one :$\text{exp}[\theta_2 \hat{\mathbf{t}}_{02}]$ rotates a vector
185 | # about the axis $\vec{t}_{02}$ of $\theta_2$ angle;
186 | # - Third one : $\text{exp}[\theta_1 \hat{\mathbf{t}}_1]$ rotates a vector
187 | # about the axis $\vec{t}_{1}$ of $\theta_1$ angle, and $\vec{t}_1 = \text{exp}
188 | # [\theta_2\hat{\mathbf{t}}_{02}] \vec{t}_{01}$
189 | #
190 | # The rotation matrix $\mathbf{R}$ on the other hand it is equivalent to rotate
191 | # around the fixed axis $\vec{e}_1$ and $\vec{e}_2$ (Proof see [3]):
192 | #
193 | # $$
194 | # \mathbf{R} = \mathbf{R}_0 \text{exp}[\theta_2 \hat{\mathbf{e}}_{2}]
195 | # \text{exp}[\theta_1 \hat{\mathbf{e}}_1]
196 | # $$
197 | #
198 | # Therefore, the director $\vec{d}$ is updated with $(\theta_1, \theta_2)$ by:
199 | #
200 | # $$
201 | # \vec{d} =\mathbf{R} \vec{e}_3 = \mathbf{R}_0 \vec{\Lambda}_3, \quad \vec{\Lambda}_3 =
202 | # [\sin(\theta_2)\cos(\theta_1), -\sin(\theta_1), \cos(\theta_2)\cos(\theta_1)]^\text{T}
203 | # $$
204 | #
205 | # Note: the above formular becomes singular when $\theta_1 = \pm \pi/2, ...$, (See Chapter 4.2.1 in
206 | # [3] for details)
207 | # %%
208 | def director(R0, theta):
209 | """Updates the director with two successive elementary rotations"""
210 | Lm3 = ufl.as_vector(
211 | [
212 | ufl.sin(theta[1]) * ufl.cos(theta[0]),
213 | -ufl.sin(theta[0]),
214 | ufl.cos(theta[1]) * ufl.cos(theta[0]),
215 | ]
216 | )
217 | d = ufl.dot(R0, Lm3)
218 | return d
219 |
220 |
221 | # %% [markdown]
222 | # In our 5-parameter Naghdi shell model the configuration of the shell is
223 | # assigned by:
224 | # - the 3-component vector field $\vec{u}$ representing the
225 | # displacement with respect to the initial configuration $\vec{\phi}_0$
226 | # - the 2-component vector field $\vec{\theta}$ representing the angle
227 | # variation of the director $\vec{d}$ with respect to initial unit normal
228 | # $\vec{n}$
229 | #
230 | # %% [markdown]
231 | # Following [1], we use a $[P_2 + B_3]^3$ element for $\vec{u}$ and a $[P_2]^2$
232 | # element for $\vec{\theta}$ and collect them in the state vector $\vec{q} =
233 | # [\vec{u}, \vec{\theta}]$:
234 | #
235 | # %%
236 | cell = mesh.basix_cell()
237 | P2 = element("Lagrange", cell, degree=2)
238 | B3 = element("Bubble", cell, degree=3)
239 | P2B3 = enriched_element([P2, B3])
240 |
241 | naghdi_shell_element = mixed_element(
242 | [blocked_element(P2B3, shape=(3,)), blocked_element(P2, shape=(2,))]
243 | )
244 | naghdi_shell_FS = functionspace(mesh, naghdi_shell_element)
245 |
246 | # %% [markdown]
247 | # Then, we define `Function`, `TrialFunction` and `TestFunction` objects to
248 | # express the variational forms and we split the mixed function into two
249 | # subfunctions for displacement and rotation.
250 |
251 | # %%
252 | q_func = Function(naghdi_shell_FS) # current configuration
253 | q_trial = ufl.TrialFunction(naghdi_shell_FS)
254 | q_test = ufl.TestFunction(naghdi_shell_FS)
255 |
256 | u_func, theta_func = split(q_func) # current displacement and rotation
257 |
258 | # %% [markdown]
259 | # We calculate the deformation gradient and the first and second fundamental
260 | # forms:
261 | #
262 | # - Deformation gradient $\mathbf{F}$
263 | #
264 | # $$
265 | # \mathbf{F} = \nabla \vec{\phi} \quad (F_{ij} = \frac{\partial \phi_i}{\partial \xi_j});
266 | # \quad \vec{\phi} =
267 | # \vec{\phi}_0 +
268 | # \vec{u} \quad i = 1,2,3; j = 1,2
269 | # $$
270 | #
271 | # - Metric tensor $\mathbf{a} \in \mathbb{S}^2_+$ and curvature tensor
272 | # $\mathbf{b} \in \mathbb{S}^2$ (First and second fundamental form)
273 | #
274 | # $$
275 | # \begin{aligned}
276 | # \mathbf{a} &= {\nabla \vec{\phi}} ^{T} \nabla \vec{\phi} \\
277 | # \mathbf{b} &= -\frac{1}{2}({\nabla \vec{\phi}} ^{T} \nabla \vec{d} + {\nabla \vec{d}} ^{T}
278 | # \nabla \vec{\phi})
279 | # \end{aligned}
280 | # $$
281 | #
282 | # In the initial configuration, $\vec{d} = \vec{n}$, $\vec{\phi} =
283 | # \vec{\phi}_0$, the conresponding initial tensors are $\mathbf{a}_0$,
284 | # $\mathbf{b}_0$
285 |
286 | # %%
287 | # Current deformation gradient
288 | F = grad(u_func) + grad(phi0_ufl)
289 |
290 | # current director
291 | d = director(R0_ufl, theta_func)
292 |
293 | # initial metric and curvature tensor a0 and b0
294 | a0_ufl = grad(phi0_ufl).T * grad(phi0_ufl)
295 | b0_ufl = -0.5 * (grad(phi0_ufl).T * grad(n0_ufl) + grad(n0_ufl).T * grad(phi0_ufl))
296 |
297 | # %% [markdown]
298 | # We define strain measures of the Naghdi shell model:
299 | # - Membrane strain tensor $\boldsymbol{\varepsilon}(\vec{u})$
300 | #
301 | # $$
302 | # \boldsymbol{\varepsilon} (\vec{u})= \frac{1}{2} \left ( \mathbf{a}(\vec{u}) - \mathbf{a}_0 \right)
303 | # $$
304 | #
305 | # - Bending strain tensor $\boldsymbol{\kappa}(\vec{u}, \vec{\theta})$
306 | #
307 | # $$
308 | # \boldsymbol{\kappa}(\vec{u}, \vec{\theta}) = \mathbf{b}(\vec{u}, \vec{\theta}) - \mathbf{b}_0
309 | # $$
310 | #
311 | # - transverse shear strain vector $\vec{\gamma}(\vec{u}, \vec{\theta})$
312 | #
313 | # $$
314 | # \begin{aligned}
315 | # \vec{\gamma}(\vec{u}, \vec{\theta}) & = {\nabla \vec{\phi}(\vec{u})}^T \vec{d}(\vec{\theta})
316 | # - {\nabla\vec{\phi}_0}^T
317 | # \vec{n} \\
318 | # & = {\nabla \vec{\phi}(\vec{u})}^T \vec{d}(\vec{\theta}) \quad \text{if zero initial shears}
319 | # \end{aligned}
320 | # $$
321 | #
322 |
323 |
324 | # %%
325 | def epsilon(F):
326 | """Membrane strain"""
327 | return 0.5 * (F.T * F - a0_ufl)
328 |
329 |
330 | def kappa(F, d):
331 | """Bending strain"""
332 | return -0.5 * (F.T * grad(d) + grad(d).T * F) - b0_ufl
333 |
334 |
335 | def gamma(F, d):
336 | """Transverse shear strain"""
337 | return F.T * d
338 |
339 |
340 | # %% [markdown]
341 | # In curvilinear coordinates, the stiffness modulus of linear isotropic
342 | # material is defined as:
343 | #
344 | # - Membrane and bending stiffness modulus $A^{\alpha\beta\sigma\tau}$,
345 | # $D^{\alpha\beta\sigma\tau}$
346 | # (contravariant components)
347 | #
348 | # $$
349 | # \frac{A^{\alpha\beta\sigma\tau}}t=12\frac{D^{\alpha\beta\sigma\tau}}{t^3}=
350 | # \frac{2\lambda\mu}{\lambda+2\mu}
351 | # a_0^{\alpha\beta}a_0^{\sigma\tau}+\mu(a_0^{\alpha\sigma}a_0^{\beta\tau}+a_0^{\alpha\tau}
352 | # a_0^{\beta\sigma})
353 | # $$
354 | #
355 | # - Shear stiffness modulus $S^{\alpha\beta}$ (contravariant components)
356 | #
357 | # $$
358 | # \frac{S^{\alpha\beta}}t = \alpha_s \mu a_0^{\alpha\beta} , \quad \alpha_s =
359 | # \frac{5}{6}: \text{shear factor}
360 | # $$
361 | #
362 | # where $a_0^{\alpha\beta}$ is the contravariant components of the initial
363 | # metric tensor $\mathbf{a}_0$
364 |
365 | # %%
366 | a0_contra_ufl = ufl.inv(a0_ufl)
367 | j0_ufl = ufl.det(a0_ufl)
368 |
369 | i, j, l, m = ufl.indices(4) # noqa: E741
370 | A_contra_ufl = ufl.as_tensor(
371 | (
372 | ((2.0 * lmbda * mu) / (lmbda + 2.0 * mu)) * a0_contra_ufl[i, j] * a0_contra_ufl[l, m]
373 | + 1.0
374 | * mu
375 | * (a0_contra_ufl[i, l] * a0_contra_ufl[j, m] + a0_contra_ufl[i, m] * a0_contra_ufl[j, l])
376 | ),
377 | [i, j, l, m],
378 | )
379 |
380 | # %% [markdown]
381 | # We define the resultant stress measures:
382 | #
383 | # - Membrane stress tensor $\mathbf{N}$
384 | #
385 | # $$
386 | # \mathbf{N} = \mathbf{A} : \boldsymbol{\varepsilon}
387 | # $$
388 | #
389 | # - Bending stress tensor $\mathbf{M}$
390 | #
391 | # $$
392 | # \mathbf{M} = \mathbf{D} : \boldsymbol{\kappa}
393 | # $$
394 | #
395 | # - Shear stress vector $\vec{T}$
396 | #
397 | # $$
398 | # \vec{T} = \mathbf{S} \cdot \vec{\gamma}
399 | # $$
400 | #
401 |
402 | # %%
403 | N = ufl.as_tensor(t * A_contra_ufl[i, j, l, m] * epsilon(F)[l, m], [i, j])
404 | M = ufl.as_tensor((t**3 / 12.0) * A_contra_ufl[i, j, l, m] * kappa(F, d)[l, m], [i, j])
405 | T = ufl.as_tensor((t * mu * 5.0 / 6.0) * a0_contra_ufl[i, j] * gamma(F, d)[j], [i])
406 |
407 | # %% [markdown]
408 | # We define elastic strain energy density $\psi_{m}$, $\psi_{b}$, $\psi_{s}$ for membrane, bending
409 | # and shear,
410 | # respectively.
411 | #
412 | # $$
413 | # \psi_m = \frac{1}{2} \mathbf{N} : \boldsymbol{\varepsilon}; \quad
414 | # \psi_b = \frac{1}{2} \mathbf{M} : \boldsymbol{\kappa}; \quad
415 | # \psi_s = \frac{1}{2} \vec{T} \cdot \vec{\gamma}
416 | # $$
417 | #
418 | # They are per unit surface in the initial configuration:
419 |
420 | # %%
421 | psi_m = 0.5 * inner(N, epsilon(F))
422 | psi_b = 0.5 * inner(M, kappa(F, d))
423 | psi_s = 0.5 * inner(T, gamma(F, d))
424 |
425 | # %% [markdown]
426 | # Shear and membrane locking is treated using the partial reduced selective
427 | # integration proposed in Arnold and Brezzi [2].
428 | #
429 | # We introduce a parameter $\alpha \in \mathbb{R}$ that splits the membrane and
430 | # shear energy in the energy functional into a weighted sum of two parts:
431 | #
432 | # $$
433 | # \begin{aligned}\Pi_{N}(u,\theta)&=\Pi^b(u_h,\theta_h)+\alpha\Pi^m(u_h)+(1-\alpha)\Pi^m(u_h)\\&+
434 | # \alpha\Pi^s(u_h,\theta_h)
435 | # +(1-\alpha)\Pi^s(u_h,\theta_h)-W_{\mathrm{ext}},\end{aligned}
436 | # $$
437 | #
438 | # We apply reduced integration to the parts weighted by the factor $(1-\alpha)$
439 | #
440 | # More details:
441 | # - Optimal choice $\alpha = \frac{t^2}{h^2}$, $h$ is the diameter of the cell
442 | # - Full integration : Gauss quadrature of degree 4 (6 integral points for triangle)
443 | # - Reduced integration : Gauss quadrature of degree 2 (3 integral points for triangle).
444 | # - While [1] suggests a 1-point reduced integration, we observed that this
445 | # leads to spurious modes in the present case.
446 | #
447 |
448 | # %%
449 | # Full integration of order 4
450 | dx_f = ufl.Measure("dx", domain=mesh, metadata={"quadrature_degree": 4})
451 |
452 | # Reduced integration of order 2
453 | dx_r = ufl.Measure("dx", domain=mesh, metadata={"quadrature_degree": 2})
454 |
455 | # Calculate the factor alpha as a function of the mesh size h
456 | h = ufl.CellDiameter(mesh)
457 | alpha_FS = functionspace(mesh, element("DG", cell, 0))
458 | alpha_expr = Expression(t**2 / h**2, alpha_FS.element.interpolation_points)
459 | alpha = Function(alpha_FS)
460 | alpha.interpolate(alpha_expr)
461 |
462 | # Full integration part of the total elastic energy
463 | Pi_PSRI = psi_b * ufl.sqrt(j0_ufl) * dx_f
464 | Pi_PSRI += alpha * psi_m * ufl.sqrt(j0_ufl) * dx_f
465 | Pi_PSRI += alpha * psi_s * ufl.sqrt(j0_ufl) * dx_f
466 |
467 | # Reduced integration part of the total elastic energy
468 | Pi_PSRI += (1.0 - alpha) * psi_m * ufl.sqrt(j0_ufl) * dx_r
469 | Pi_PSRI += (1.0 - alpha) * psi_s * ufl.sqrt(j0_ufl) * dx_r
470 |
471 | # External work part (zero in this case)
472 | W_ext = 0.0
473 | Pi_PSRI -= W_ext
474 |
475 | # %% [markdown]
476 | # The residual and jacobian are the first and second order derivatives of the
477 | # total potential energy, respectively
478 |
479 | # %%
480 | F = ufl.derivative(Pi_PSRI, q_func, q_test)
481 | J = ufl.derivative(F, q_func, q_trial)
482 |
483 |
484 | # %% [markdown]
485 | # Next, we prescribe the dirichlet boundary conditions:
486 | # - fully clamped boundary conditions on the top boundary ($\xi_2 = 0$):
487 | # - $u_{1,2,3} = \theta_{1,2} = 0$
488 | # %%
489 | def clamped_boundary(x):
490 | return np.isclose(x[1], 0.0)
491 |
492 |
493 | fdim = tdim - 1
494 | clamped_facets = locate_entities_boundary(mesh, fdim, clamped_boundary)
495 |
496 | u_FS, _ = naghdi_shell_FS.sub(0).collapse()
497 | theta_FS, _ = naghdi_shell_FS.sub(1).collapse()
498 |
499 | # u1, u2, u3 = 0 on the clamped boundary
500 | u_clamped = Function(u_FS)
501 | clamped_dofs_u = locate_dofs_topological((naghdi_shell_FS.sub(0), u_FS), fdim, clamped_facets)
502 | bc_clamped_u = dirichletbc(u_clamped, clamped_dofs_u, naghdi_shell_FS.sub(0))
503 |
504 | # theta1, theta2 = 0 on the clamped boundary
505 | theta_clamped = Function(theta_FS)
506 | clamped_dofs_theta = locate_dofs_topological(
507 | (naghdi_shell_FS.sub(1), theta_FS), fdim, clamped_facets
508 | )
509 | bc_clamped_theta = dirichletbc(theta_clamped, clamped_dofs_theta, naghdi_shell_FS.sub(1))
510 |
511 | # %% [markdown]
512 | # - symmetry boundary conditions on the left and right side ($\xi_1 = \pm
513 | # \pi/2$):
514 | # - $u_3 = \theta_2 = 0$
515 |
516 |
517 | # %%
518 | def symm_boundary(x):
519 | return np.isclose(abs(x[0]), np.pi / 2)
520 |
521 |
522 | symm_facets = locate_entities_boundary(mesh, fdim, symm_boundary)
523 |
524 | symm_dofs_u = locate_dofs_topological(
525 | (naghdi_shell_FS.sub(0).sub(2), u_FS.sub(2)), fdim, symm_facets
526 | )
527 | bc_symm_u = dirichletbc(u_clamped, symm_dofs_u, naghdi_shell_FS.sub(0).sub(2))
528 |
529 | symm_dofs_theta = locate_dofs_topological(
530 | (naghdi_shell_FS.sub(1).sub(1), theta_FS.sub(1)), fdim, symm_facets
531 | )
532 | bc_symm_theta = dirichletbc(theta_clamped, symm_dofs_theta, naghdi_shell_FS.sub(1).sub(1))
533 |
534 | bcs = [bc_clamped_u, bc_clamped_theta, bc_symm_u, bc_symm_theta]
535 |
536 |
537 | # %% [markdown]
538 | # The loading is exerted by a point force along the $z$ direction applied at
539 | # the midpoint of the bottom boundary.
540 | # Since `PointSource` function is not available by far in new FEniCSx, we
541 | # achieve the same functionality according to the method detailed in [4].
542 | # %%
543 | def compute_cell_contributions(V, points):
544 | """Returns the cell containing points and the values of the basis functions
545 | at that point"""
546 | # Determine what process owns a point and what cells it lies within
547 | mesh = V.mesh
548 | point_ownership_data = dolfinx.cpp.geometry.determine_point_ownership(
549 | mesh._cpp_object, points, 1e-6
550 | )
551 |
552 | owning_points = np.asarray(point_ownership_data.dest_points).reshape(-1, 3)
553 | cells = point_ownership_data.dest_cells
554 |
555 | # Pull owning points back to reference cell
556 | mesh_nodes = mesh.geometry.x
557 | cmap = mesh.geometry.cmap
558 | ref_x = np.zeros((len(cells), mesh.geometry.dim), dtype=mesh.geometry.x.dtype)
559 | for i, (point, cell) in enumerate(zip(owning_points, cells)):
560 | geom_dofs = mesh.geometry.dofmap[cell]
561 | ref_x[i] = cmap.pull_back(point.reshape(-1, 3), mesh_nodes[geom_dofs])
562 |
563 | # Create expression evaluating a trial function (i.e. just the basis function)
564 | u = ufl.TrialFunction(V.sub(0).sub(2))
565 | num_dofs = V.sub(0).sub(2).dofmap.dof_layout.num_dofs * V.sub(0).sub(2).dofmap.bs
566 | if len(cells) > 0:
567 | # NOTE: Expression lives on only this communicator rank
568 | expr = dolfinx.fem.Expression(u, ref_x, comm=MPI.COMM_SELF)
569 | values = expr.eval(mesh, np.asarray(cells, dtype=np.int32))
570 |
571 | # Strip out basis function values per cell
572 | basis_values = values[: num_dofs : num_dofs * len(cells)]
573 | else:
574 | basis_values = np.zeros((0, num_dofs), dtype=dolfinx.default_scalar_type)
575 | return cells, basis_values
576 |
577 |
578 | # %%
579 | # Point source
580 | if mesh.comm.rank == 0:
581 | points = np.array([[0.0, L, 0.0]], dtype=mesh.geometry.x.dtype)
582 | else:
583 | points = np.zeros((0, 3), dtype=mesh.geometry.x.dtype)
584 |
585 | cells, basis_values = compute_cell_contributions(naghdi_shell_FS, points)
586 |
587 |
588 | # %% [markdown]
589 | # We define a custom `NonlinearProblem` which is able to include the point
590 | # force.
591 | # %%
592 | class NonlinearProblemPointSource(NonlinearProblem):
593 | def __init__(
594 | self,
595 | F: ufl.form.Form,
596 | u: _Function,
597 | bcs: typing.List[DirichletBC] = [], # noqa: UP006
598 | J: ufl.form.Form = None,
599 | cells=[],
600 | basis_values=[],
601 | PS: float = 0.0,
602 | ):
603 | super().__init__(F, u, bcs, J)
604 | self.PS = PS
605 | self.cells = cells
606 | self.basis_values = basis_values
607 | self.function_space = u.function_space
608 |
609 | def F(self, x: PETSc.Vec, b: PETSc.Vec) -> None:
610 | with b.localForm() as b_local:
611 | b_local.set(0.0)
612 | assemble_vector(b, self._L)
613 |
614 | # Add point source
615 | if len(self.cells) > 0:
616 | for cell, basis_value in zip(self.cells, self.basis_values):
617 | dofs = self.function_space.sub(0).sub(2).dofmap.cell_dofs(cell)
618 | with b.localForm() as b_local:
619 | b_local.setValuesLocal(
620 | dofs, basis_value * self.PS, addv=PETSc.InsertMode.ADD_VALUES
621 | )
622 |
623 | apply_lifting(b, [self._a], bcs=[self.bcs], x0=[x], alpha=-1.0)
624 | b.ghostUpdate(addv=PETSc.InsertMode.ADD, mode=PETSc.ScatterMode.REVERSE)
625 | set_bc(b, self.bcs, x, -1.0)
626 |
627 |
628 | # %% [markdown]
629 | # We use the standard Newton iteration.
630 |
631 | # %%
632 | problem = NonlinearProblemPointSource(F, q_func, bcs, J, cells, basis_values)
633 |
634 | solver = NewtonSolver(mesh.comm, problem)
635 |
636 | # Set Newton solver options
637 | solver.rtol = 1e-6
638 | solver.atol = 1e-6
639 | solver.max_it = 30
640 | solver.convergence_criterion = "incremental"
641 | solver.report = True
642 |
643 | # Modify the linear solver in each Newton iteration
644 | ksp = solver.krylov_solver
645 | opts = PETSc.Options()
646 | option_prefix = ksp.getOptionsPrefix()
647 | opts[f"{option_prefix}ksp_type"] = "preonly"
648 | opts[f"{option_prefix}pc_factor_mat_solver_type"] = "mumps"
649 | ksp.setFromOptions()
650 |
651 | # %% [markdown]
652 | # Finally, we can solve the quasi-static problem, incrementally increasing the
653 | # loading from $0$N to $2000$N
654 | # %%
655 | PS_diff = 50.0
656 | n_step = 40
657 |
658 | # Store the displacement at the point load
659 | if mesh.comm.rank == 0:
660 | u3_list = np.zeros(n_step + 1)
661 | PS_list = np.arange(0, PS_diff * (n_step + 1), PS_diff)
662 |
663 | q_func.x.array[:] = 0.0
664 |
665 | bb_point = np.array([[0.0, L, 0.0]], dtype=np.float64)
666 |
667 | for i in range(1, n_step + 1):
668 | problem.PS = PS_diff * i
669 | n, converged = solver.solve(q_func)
670 | assert converged
671 | q_func.x.scatter_forward()
672 | if mesh.comm.rank == 0:
673 | print(f"Load step {i:d}, Number of iterations: {n:d}, Load: {problem.PS:.2f}", flush=True)
674 | # Calculate u3 at the point load
675 | u3_bb = None
676 | u3_func = q_func.sub(0).sub(2).collapse()
677 | if len(cells) > 0:
678 | u3_bb = u3_func.eval(bb_point, cells[0])[0]
679 | u3_bb = mesh.comm.gather(u3_bb, root=0)
680 | if mesh.comm.rank == 0:
681 | for u3 in u3_bb:
682 | if u3 is not None:
683 | u3_list[i] = u3
684 | break
685 |
686 | # %% [markdown]
687 | # We write the outputs of $\vec{u}$, $\vec{\theta}$, and $\vec{\phi}$ in the
688 | # second order Lagrange space.
689 | # %%
690 | # Interpolate phi_ufl into CG2 Space
691 | u_P2B3 = q_func.sub(0).collapse()
692 | theta_P2 = q_func.sub(1).collapse()
693 |
694 | # Interpolate phi in the [P2]³ Space
695 | phi_FS = functionspace(mesh, blocked_element(P2, shape=(3,)))
696 | phi_expr = Expression(phi0_ufl + u_P2B3, phi_FS.element.interpolation_points)
697 | phi_func = Function(phi_FS)
698 | phi_func.interpolate(phi_expr)
699 |
700 | # Interpolate u in the [P2]³ Space
701 | u_P2 = Function(phi_FS)
702 | u_P2.interpolate(u_P2B3)
703 |
704 | results_folder = Path("results/nonlinear_naghdi/semi_cylinder")
705 | results_folder.mkdir(exist_ok=True, parents=True)
706 |
707 | with dolfinx.io.VTXWriter(mesh.comm, results_folder / "u_naghdi.bp", [u_P2]) as vtx:
708 | vtx.write(0)
709 |
710 | with dolfinx.io.VTXWriter(mesh.comm, results_folder / "theta_naghdi.bp", [theta_P2]) as vtx:
711 | vtx.write(0)
712 |
713 | with dolfinx.io.VTXWriter(mesh.comm, results_folder / "phi_naghdi.bp", [phi_func]) as vtx:
714 | vtx.write(0)
715 |
716 | # %% [markdown]
717 | # The results for the transverse displacement at the point of application of
718 | # the force are validated against a standard reference from the literature,
719 | # obtained using Abaqus S4R element and a structured mesh of 40 times 40
720 | # elements, see [1]:
721 |
722 | # %%
723 | if mesh.comm.rank == 0:
724 | fig = plt.figure()
725 | reference_u3 = 1.0e-2 * np.array(
726 | [
727 | 0.0,
728 | 5.421,
729 | 16.1,
730 | 22.195,
731 | 27.657,
732 | 32.7,
733 | 37.582,
734 | 42.633,
735 | 48.537,
736 | 56.355,
737 | 66.410,
738 | 79.810,
739 | 94.669,
740 | 113.704,
741 | 124.751,
742 | 132.653,
743 | 138.920,
744 | 144.185,
745 | 148.770,
746 | 152.863,
747 | 156.584,
748 | 160.015,
749 | 163.211,
750 | 166.200,
751 | 168.973,
752 | 171.505,
753 | ]
754 | )
755 | reference_P = 2000.0 * np.array(
756 | [
757 | 0.0,
758 | 0.05,
759 | 0.1,
760 | 0.125,
761 | 0.15,
762 | 0.175,
763 | 0.2,
764 | 0.225,
765 | 0.25,
766 | 0.275,
767 | 0.3,
768 | 0.325,
769 | 0.35,
770 | 0.4,
771 | 0.45,
772 | 0.5,
773 | 0.55,
774 | 0.6,
775 | 0.65,
776 | 0.7,
777 | 0.75,
778 | 0.8,
779 | 0.85,
780 | 0.9,
781 | 0.95,
782 | 1.0,
783 | ]
784 | )
785 | plt.plot(-u3_list, PS_list, label="FEniCSx-Shells 20 x 20")
786 | plt.plot(reference_u3, reference_P, "or", label="Sze (Abaqus S4R)")
787 | plt.xlabel("Displacement (mm)")
788 | plt.ylabel("Load (N)")
789 | plt.legend()
790 | plt.grid()
791 | plt.tight_layout()
792 | plt.savefig(results_folder / "comparisons.pdf")
793 |
794 | # %% [markdown]
795 | # References:
796 | #
797 | # [1] K. Sze, X. Liu, and S. Lo. Popular benchmark problems for geometric
798 | # nonlinear analysis of shells. Finite Elements in Analysis and Design,
799 | # 40(11):1551 - 1569, 2004.
800 | #
801 | # [2] D. Arnold and F.Brezzi, Mathematics of Computation, 66(217): 1-14, 1997.
802 | # https://www.ima.umn.edu/~arnold//papers/shellelt.pdf
803 | #
804 | # [3] P. Betsch, A. Menzel, and E. Stein. On the parametrization of finite
805 | # rotations in computational mechanics: A classification of concepts with
806 | # application to smooth shells. Computer Methods in Applied Mechanics and
807 | # Engineering, 155(3):273 - 305, 1998.
808 | #
809 | # [4] https://fenicsproject.discourse.group/t/point-sources-redux/13496/4
810 |
--------------------------------------------------------------------------------
/demo/demo_reissner-mindlin-clamped-tdnns.py:
--------------------------------------------------------------------------------
1 | # ---
2 | # jupyter:
3 | # jupytext:
4 | # text_representation:
5 | # extension: .py
6 | # format_name: light
7 | # format_version: '1.5'
8 | # jupytext_version: 1.14.1
9 | # ---
10 |
11 | # # Clamped Reissner-Mindlin plate under uniform load using TDNNS element
12 | #
13 | # This demo program solves the out-of-plane Reissner-Mindlin equations on the
14 | # unit square with uniform transverse loading and fully clamped boundary
15 | # conditions using the TDNNS (tangential displacement normal-normal stress)
16 | # element developed in:
17 | #
18 | # Pechstein, A. S., Schöberl, J. The TDNNS method for Reissner-Mindlin plates.
19 | # Numer. Math. 137, 713-740 (2017).
20 | # [doi:10.1007/s00211-017-0883-9](https://doi.org/10.1007/s00211-017-0883-9)
21 | #
22 | # The idea behind this element construction is that the rotations, transverse
23 | # displacement and bending moments are discretised separately. The finite
24 | # element space for the transverse displacement is chosen such that the
25 | # gradient is a subset of the rotation space and therefore the Kirchhoff
26 | # constraint as the thickness parameter tends to zero is exactly satisfied by
27 | # construction.
28 | #
29 | # Mathematically the forms in this work follow exactly that shown in Pechstein
30 | # and Schöberl except for a few minor notational changes to match the rest of
31 | # FEniCSx-Shells.
32 | #
33 | # It is assumed the reader understands most of the basic functionality of the
34 | # new FEniCSx Project.
35 | #
36 | # We begin by importing the necessary functionality from DOLFINx, UFL and
37 | # PETSc.
38 |
39 | # +
40 | from mpi4py import MPI
41 |
42 | import numpy as np
43 |
44 | import dolfinx
45 | import ufl
46 | from basix.ufl import element, mixed_element
47 | from dolfinx.fem import Function, dirichletbc, functionspace
48 | from dolfinx.fem.petsc import LinearProblem
49 | from dolfinx.mesh import CellType, create_unit_square
50 | from ufl import FacetNormal, Identity, Measure, grad, inner, split, sym, tr
51 |
52 | # -
53 |
54 | # We then create a two-dimensional mesh of the mid-plane of the plate $\Omega =
55 | # [0, 1] \times [0, 1]$.
56 |
57 | # +
58 | mesh = create_unit_square(MPI.COMM_WORLD, 16, 16, CellType.triangle)
59 |
60 | # -
61 |
62 | # The Pechstein-Schöberl element of order $k$ for the Reissner-Mindlin plate problem
63 | # consists of:
64 | #
65 | # - $k$-th order vector-valued Nédélec elements of the second kind for the
66 | # rotations $\theta \in \mathrm{NED}_k$ and,
67 | # - $k + 1$-th order scalar-valued Lagrange element for the transverse displacement field
68 | # $w \in \mathrm{CG}_{k + 1}$ and,
69 | # - $k$-th order Hellan-Herrmann-Johnson finite elements for the bending moments, which
70 | # naturally discretise tensor-valued functions in $H(\mathrm{div}\;\mathrm{\bf{div}})$,
71 | # $M \in \mathrm{HHJ}_k$.
72 | #
73 | # The final element definition with $k = 3$ is:
74 |
75 | # +
76 | k = 3
77 | cell = mesh.basix_cell()
78 | U_el = mixed_element(
79 | [element("N2curl", cell, k), element("Lagrange", cell, k + 1), element("HHJ", cell, k)]
80 | )
81 | U = functionspace(mesh, U_el)
82 |
83 | u = ufl.TrialFunction(U)
84 | u_t = ufl.TestFunction(U)
85 |
86 | theta, w, M = split(u)
87 | theta_t, w_t, M_t = split(u_t)
88 | # -
89 |
90 | # We assume constant material parameters; Young's modulus $E$, Poisson's ratio
91 | # $\nu$, shear-correction factor $\kappa$, and thickness $t$.
92 |
93 | # +
94 | E = 10920.0
95 | nu = 0.3
96 | kappa = 5.0 / 6.0
97 | t = 0.001
98 | # -
99 |
100 | # The overall weak form for the problem can be written as:
101 | #
102 | # Find $(\theta, w, M) \in \mathrm{NED}_k \times \mathrm{CG}_1 \times \mathrm{HHJ}_k$
103 | # such that
104 | #
105 | # $$
106 | # \left( k(M), \tilde{M} \right) + \left< \tilde{M}, \theta \right> + \left< M,
107 | # \tilde{\theta} \right> - \left( \mu \gamma(\theta, w), \gamma(\tilde{\theta},
108 | # \tilde{w}) \right) \\ = -\left(t^3, \tilde{w} \right) \quad \forall (\theta,
109 | # w, M) \in \mathrm{NED}_k \times \mathrm{CG}_1 \times \mathrm{HHJ}_k,
110 | # $$
111 | # where $\left( \cdot, \cdot \right)$ is the usual $L^2$ inner product on the
112 | # mesh $\Omega$, $\gamma(\theta, w) = \nabla w - \theta \in H(\mathrm{rot})$ is
113 | # the shear-strain, $\mu = E \kappa t/(2(1 + \nu))$ the shear modulus. $k(M)$
114 | # are the bending strains $k(\theta) = \mathrm{sym}(\nabla \theta)$ written in terms of
115 | # the bending moments (stresses)
116 | #
117 | # $$
118 | # k(M) = \frac{12}{E t^3} \left[ (1 + \nu) M - \nu \mathrm{tr}\left( M \right) I \right],
119 | # $$
120 | # with $\mathrm{tr}$ the trace operator and $I$ the identity tensor.
121 | #
122 | # The inner product $\left< \cdot, \cdot \right>$ is defined by
123 | #
124 | # $$
125 | # \left< M, \theta \right> = -\left( M, k(\theta) \right) + \int_{\partial K}
126 | # M_{nn} \cdot [[ \theta ]]_n \; \mathrm{d}s,
127 | # $$
128 | # where $M_{nn} = \left(Mn \right) \cdot n$ is the normal-normal component of
129 | # the bending moment, $\partial K$ are the facets of the mesh, $[[ \theta ]]$ is
130 | # the jump in the normal component of the rotations on the facets (reducing to
131 | # simply $\theta \cdot n$ on the exterior facets).
132 | #
133 | # The above equations can be written relatively straightforwardly in UFL as:
134 |
135 | # +
136 | dx = Measure("dx", mesh)
137 | dS = Measure("dS", mesh)
138 | ds = Measure("ds", mesh)
139 |
140 |
141 | def k_theta(theta):
142 | """Bending strain tensor in terms of rotations"""
143 | return sym(grad(theta))
144 |
145 |
146 | def k_M(M):
147 | """Bending strain tensor in terms of bending moments"""
148 | return (12.0 / (E * t**3)) * ((1.0 + nu) * M - nu * Identity(2) * tr(M))
149 |
150 |
151 | def nn(M):
152 | """Normal-normal component of tensor"""
153 | n = FacetNormal(M.ufl_domain())
154 | M_n = M * n
155 | M_nn = ufl.dot(M_n, n)
156 | return M_nn
157 |
158 |
159 | def inner_divdiv(M, theta):
160 | """Discrete div-div inner product"""
161 | n = FacetNormal(M.ufl_domain())
162 | M_nn = nn(M)
163 | result = (
164 | -inner(M, k_theta(theta)) * dx
165 | + inner(M_nn("+"), ufl.jump(theta, n)) * dS
166 | + inner(M_nn, ufl.dot(theta, n)) * ds
167 | )
168 | return result
169 |
170 |
171 | def gamma(theta, w):
172 | """Shear strain"""
173 | return grad(w) - theta
174 |
175 |
176 | a = (
177 | inner(k_M(M), M_t) * dx
178 | + inner_divdiv(M_t, theta)
179 | + inner_divdiv(M, theta_t)
180 | - ((E * kappa * t) / (2.0 * (1.0 + nu))) * inner(gamma(theta, w), gamma(theta_t, w_t)) * dx
181 | )
182 | L = -inner(1.0 * t**3, w_t) * dx
183 |
184 | # -
185 |
186 | # Imposition of boundary conditions requires some care. We reproduce the table
187 | # from Pechstein and Schöberl specifying the different types of boundary condition.
188 | #
189 | # | Essential | Natural | Non-homogeneous term | # noqa: E501
190 | # | ------------------------------------ | ------------------------------------ | ------------------------------------------------------------------- | # noqa: E501
191 | # | $w = \bar{w}$ | $\mu(\partial_n w - \theta_n) = g_w$ | $\int_{\Gamma} g_w \tilde{w} \; \mathrm{d}s$ | # noqa: E501
192 | # | $\theta_\tau = \bar{\theta}_{\tau} $ | $m_{n\tau} = g_{\theta_\tau}$ | $\int_{\Gamma} g_{\theta_\tau} \cdot \tilde{\theta} \; \mathrm{d}s$ | # noqa: E501
193 | # | $m_{nn} = \bar{m}_{nn}$ | $\theta_n = g_{\theta_n}$ | $\int_{\Gamma} g_{\theta_n} \tilde{m}_{nn} \; \mathrm{d}s$ | # noqa: E501
194 | #
195 | # where $\theta_{n} = \theta_n$ is the normal component of the rotation,
196 | # $\theta_{\tau} = \theta \cdot \tau $ is the tangential component of the
197 | # rotation, $m_{n\tau} = m \cdot n - \sigma_{nn} n$ is the normal-tangential
198 | # component of $n$, and $g_{w}$ etc. are known natural boundary data and
199 | # $\bar{w}$ etc. are known essential boundary data.
200 | #
201 | # In the case of an essential boundary condition the values are enforced
202 | # directly in the finite element space using `dolfinx.dirichletbc`. In the case
203 | # of a homogeneous natural boundary condition the corresponding essential
204 | # boundary condition should be dropped. In the case of a non-homogeneous
205 | # condition an extra term must be added to the weak formulation.
206 | #
207 | # For a fully clamped plate we have on the entire boundary $\bar{w} = 0$
208 | # (homogeneous essential), $\bar{\theta_\tau} = 0$ (homogeneous essential), and
209 | # $g_{\theta_n} = 0$ (homogeneous natural).
210 |
211 | # +
212 |
213 |
214 | def all_boundary(x):
215 | return np.full(x.shape[1], True, dtype=bool)
216 |
217 |
218 | boundary_entities = dolfinx.mesh.locate_entities_boundary(mesh, mesh.topology.dim - 1, all_boundary)
219 |
220 | bcs = []
221 | # Transverse displacement
222 | boundary_dofs = dolfinx.fem.locate_dofs_topological(
223 | U.sub(1), mesh.topology.dim - 1, boundary_entities
224 | )
225 | bcs.append(dirichletbc(np.array(0.0, dtype=np.float64), boundary_dofs, U.sub(1)))
226 |
227 | # Fix tangential component of rotation
228 | R = U.sub(0).collapse()[0]
229 | boundary_dofs = dolfinx.fem.locate_dofs_topological(
230 | (U.sub(0), R), mesh.topology.dim - 1, boundary_entities
231 | )
232 |
233 | theta_bc = Function(R)
234 | bcs.append(dirichletbc(theta_bc, boundary_dofs, U.sub(0)))
235 |
236 | # -
237 |
238 | # Finally we solve the problem and output the transverse displacement at the
239 | # centre of the plate.
240 |
241 | # +
242 | problem = LinearProblem(
243 | a,
244 | L,
245 | bcs=bcs,
246 | petsc_options={"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"},
247 | )
248 | u_h = problem.solve()
249 |
250 | bb_tree = dolfinx.geometry.bb_tree(mesh, 2)
251 | point = np.array([[0.5, 0.5, 0.0]], dtype=np.float64)
252 | cell_candidates = dolfinx.geometry.compute_collisions_points(bb_tree, point)
253 | cells = dolfinx.geometry.compute_colliding_cells(mesh, cell_candidates, point)
254 |
255 | theta, w, M = u_h.split()
256 |
257 | if cells.array.shape[0] > 0:
258 | value = w.eval(point, cells.array[0])
259 | print(value[0])
260 |
--------------------------------------------------------------------------------
/demo/demo_reissner-mindlin-clamped.py:
--------------------------------------------------------------------------------
1 | # ---
2 | # jupyter:
3 | # jupytext:
4 | # text_representation:
5 | # extension: .py
6 | # format_name: light
7 | # format_version: '1.5'
8 | # jupytext_version: 1.14.1
9 | # ---
10 |
11 | # # Clamped Reissner-Mindlin plate under uniform load
12 | #
13 | # This demo program solves the out-of-plane Reissner-Mindlin equations on the
14 | # unit square with uniform transverse loading with fully clamped boundary
15 | # conditions. This version does not use the special projected assembly routines
16 | # in FEniCSx-Shells.
17 | #
18 | # It is assumed the reader understands most of the basic functionality of the
19 | # new FEniCSx Project.
20 | #
21 | # This demo illustrates how to:
22 | #
23 | # - Define the Reissner-Mindlin plate equations using UFL.
24 | # - Define the Durán-Liberman (MITC) reduction operator using UFL. This
25 | # procedure eliminates the shear-locking problem.
26 | #
27 | # We begin by importing the necessary functionality from DOLFINx, UFL and
28 | # PETSc.
29 |
30 | from mpi4py import MPI
31 |
32 | import numpy as np
33 |
34 | import dolfinx
35 | import ufl
36 | from basix.ufl import element, mixed_element
37 | from dolfinx.fem import Function, dirichletbc, functionspace
38 | from dolfinx.fem.petsc import LinearProblem
39 | from dolfinx.io.utils import XDMFFile
40 | from dolfinx.mesh import CellType, create_unit_square
41 | from ufl import dx, grad, inner, split, sym, tr
42 |
43 | # We then create a two-dimensional mesh of the mid-plane of the plate $\Omega =
44 | # [0, 1] \times [0, 1]$. `GhostMode.shared_facet` is required as the Form will
45 | # use Nédélec elements and DG-type restrictions.
46 |
47 | mesh = create_unit_square(MPI.COMM_WORLD, 32, 32, CellType.triangle)
48 |
49 | # The Durán-Liberman element [1] for the Reissner-Mindlin plate problem
50 | # consists of:
51 | #
52 | # - second-order vector-valued Lagrange element for the rotation field $\theta
53 | # \in [\mathrm{CG}_2]^2$ and,
54 | # - a first-order scalar valued Lagrange element for the transverse
55 | # displacement field $w \in \mathrm{CG}_1$ and,
56 | # - the reduced shear strain $\gamma_R \in \mathrm{NED}_1$ the vector-valued
57 | # Nédélec elements of the first kind, and
58 | # - a Lagrange multiplier field $p$ that ties together the shear strain
59 | # calculated from the primal variables $\gamma = \nabla w - \theta$ and the
60 | # reduced shear strain $\gamma_R$. Both $p$ and $\gamma_R$ are are discretised
61 | # in the space $\mathrm{NED}_1$, the vector-valued Nédélec elements of the
62 | # first kind.
63 | #
64 | # The final element definition is
65 |
66 | # +
67 | cell = mesh.basix_cell()
68 | U_el = mixed_element(
69 | [
70 | element("Lagrange", cell, 2, shape=(2,)),
71 | element("Lagrange", cell, 1),
72 | element("N1curl", cell, 1),
73 | element("N1curl", cell, 1),
74 | ]
75 | )
76 | U = functionspace(mesh, U_el)
77 |
78 | u_ = Function(U)
79 | u = ufl.TrialFunction(U)
80 | u_t = ufl.TestFunction(U)
81 |
82 | theta_, w_, R_gamma_, p_ = split(u_)
83 | # -
84 |
85 | # We assume constant material parameters; Young's modulus $E$, Poisson's ratio
86 | # $\nu$, shear-correction factor $\kappa$, and thickness $t$.
87 |
88 | E = 10920.0
89 | nu = 0.3
90 | kappa = 5.0 / 6.0
91 | t = 0.001
92 |
93 | # The bending strain tensor $k$ for the Reissner-Mindlin model can be expressed
94 | # in terms of the rotation field $\theta$
95 | #
96 | # $$
97 | # k(\theta) = \dfrac{1}{2}(\nabla \theta + (\nabla \theta)^T)
98 | # $$
99 | #
100 | # The bending energy density $\psi_b$ for the Reissner-Mindlin model is a
101 | # function of the bending strain tensor $k$
102 | #
103 | # $$
104 | # \psi_b(k) = \frac{1}{2} D \left( (1 - \nu) \, \mathrm{tr}\,(k^2)
105 | # + \nu \, (\mathrm{tr} \,k)^2 \right) \qquad
106 | # D = \frac{Et^3}{12(1 - \nu^2)}
107 | # $$
108 | #
109 | # which can be expressed in UFL as
110 |
111 | D = (E * t**3) / (24.0 * (1.0 - nu**2))
112 | k = sym(grad(theta_))
113 | psi_b = D * ((1.0 - nu) * tr(k * k) + nu * (tr(k)) ** 2)
114 |
115 | # Because we are using a mixed variational formulation, we choose to write the
116 | # shear energy density $\psi_s$ is a function of the reduced shear strain
117 | # vector
118 | #
119 | # $$\psi_s(\gamma_R) = \frac{E \kappa t}{4(1 + \nu)}\gamma_R^2,$$
120 | #
121 | # or in UFL:
122 |
123 | psi_s = ((E * kappa * t) / (4.0 * (1.0 + nu))) * inner(R_gamma_, R_gamma_)
124 |
125 | # Finally, we can write out external work due to the uniform loading in the out-of-plane direction
126 | #
127 | # $$
128 | # W_{\mathrm{ext}} = \int_{\Omega} ft^3 \cdot w \; \mathrm{d}x.
129 | # $$
130 |
131 | # where $f = 1$ and $\mathrm{d}x$ is a measure on the whole domain.
132 | # The scaling by $t^3$ is included to ensure a correct limit solution as
133 | # $t \to 0$.
134 | #
135 | # In UFL this can be expressed as
136 |
137 | W_ext = inner(1.0 * t**3, w_) * dx
138 |
139 | # With all of the standard mechanical terms defined, we can turn to defining
140 | # the Duran-Liberman reduction operator. This operator 'ties' our reduced shear
141 | # strain field to the shear strain calculated in the primal space. A partial
142 | # explanation of the thinking behind this approach is given in the Appendix at
143 | # the bottom of this notebook.
144 | #
145 | # The shear strain vector $\gamma$ can be expressed in terms of the rotation
146 | # and transverse displacement field
147 | #
148 | # $$\gamma(\theta, w) = \nabla w - \theta$$
149 | #
150 | # or in UFL
151 |
152 | gamma = grad(w_) - theta_
153 |
154 | # We require that the shear strain calculated using the displacement unknowns
155 | # $\gamma = \nabla w - \theta$ be equal, in a weak sense, to the conforming
156 | # shear strain field $\gamma_R \in \mathrm{NED}_1$ that we used to define the
157 | # shear energy above. We enforce this constraint using a Lagrange multiplier
158 | # field $p \in \mathrm{NED}_1$. We can write the Lagrangian functional of this
159 | # constraint as:
160 | #
161 | # $$\Pi_R(\gamma, \gamma_R, p) =
162 | # \int_{e} \left( \left\lbrace \gamma_R - \gamma \right\rbrace \cdot t \right)
163 | # \cdot \left( p \cdot t \right) \; \mathrm{d}s$$
164 | #
165 | # where $e$ are all of edges of the cells in the mesh and $t$ is the tangent
166 | # vector on each edge.
167 | #
168 | # Writing this operator out in UFL is quite verbose, so `fenicsx_shells`
169 | # includes a special inner product function `inner_e` to help. However, we
170 | # choose to write this function in full here.
171 |
172 | # +
173 | dSp = ufl.Measure("dS", metadata={"quadrature_degree": 1})
174 | dsp = ufl.Measure("ds", metadata={"quadrature_degree": 1})
175 |
176 | n = ufl.FacetNormal(mesh)
177 | t = ufl.as_vector((-n[1], n[0]))
178 |
179 |
180 | def inner_e(x, y):
181 | return (inner(x, t) * inner(y, t))("+") * dSp + (inner(x, t) * inner(y, t)) * dsp
182 |
183 |
184 | Pi_R = inner_e(gamma - R_gamma_, p_)
185 | # -
186 |
187 | # We can now define our Lagrangian for the complete system and derive the
188 | # residual and Jacobian automatically using the standard UFL `derivative`
189 | # function
190 |
191 | Pi = psi_b * dx + psi_s * dx + Pi_R - W_ext
192 | F = ufl.derivative(Pi, u_, u_t)
193 | J = ufl.derivative(F, u_, u)
194 |
195 | # In the following we use standard from `dolfinx` to apply boundary conditions,
196 | # assemble, solve and output the solution.
197 | #
198 | # Note that for a fully clamped plate $\gamma_R \in H_0(\mathrm{rot}; \Omega)$
199 | # which is the Sobolev space of vector-valued functions with square integrable
200 | # whose tangential component $\gamma_R \cdot t$ vanishes on the boundary. So,
201 | # it is also necessary to apply boundary conditions on this space.
202 | #
203 | # For simplicity of implementation we also apply boundary conditions on the
204 | # Lagrange multiplier space but this is not strictly necessary as the Lagrange
205 | # multiplier simply constrains $\gamma_R \cdot t$ to $\gamma = \nabla w -
206 | # \theta$, all of which are enforced to be zero by definition.
207 |
208 | # +
209 |
210 |
211 | def all_boundary(x):
212 | return np.full(x.shape[1], True, dtype=bool)
213 |
214 |
215 | u_boundary = Function(U)
216 | boundary_entities = dolfinx.mesh.locate_entities_boundary(mesh, mesh.topology.dim - 1, all_boundary)
217 | boundary_dofs = dolfinx.fem.locate_dofs_topological(U, mesh.topology.dim - 1, boundary_entities)
218 | bcs = [dirichletbc(u_boundary, boundary_dofs)]
219 |
220 | problem = LinearProblem(
221 | J,
222 | -F,
223 | bcs=bcs,
224 | petsc_options={"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"},
225 | )
226 | u_ = problem.solve()
227 |
228 | bb_tree = dolfinx.geometry.bb_tree(mesh, 2)
229 | point = np.array([[0.5, 0.5, 0.0]], dtype=np.float64)
230 | cell_candidates = dolfinx.geometry.compute_collisions_points(bb_tree, point)
231 | cells = dolfinx.geometry.compute_colliding_cells(mesh, cell_candidates, point)
232 |
233 | theta, w, R_gamma, p = u_.split()
234 |
235 | if cells.array.shape[0] > 0:
236 | value = w.eval(point, cells.array[0])
237 | print(value[0])
238 | # NOTE: FEniCS-Shells (old dolfin) `demo/documented/reissner-mindlin-clamped`
239 | # gives 1.28506469462e-06 on a 32 x 32 mesh and 1.2703580973e-06 on a 64 x 64
240 | # mesh.
241 |
242 | def test_center_displacement():
243 | assert np.isclose(value[0], 1.285e-6, atol=1e-3, rtol=1e-3)
244 |
245 |
246 | with XDMFFile(MPI.COMM_WORLD, "w.xdmf", "w") as f:
247 | f.write_mesh(mesh)
248 | f.write_function(w)
249 |
250 | # -
251 |
252 | # ## Appendix
253 |
254 | # For the clamped problem we have the following regularity for our two fields,
255 | # $\theta \in [H^1_0(\Omega)]^2$ and $w \in [H^1_0(\Omega)]^2$ where
256 | # $H^1_0(\Omega)$ is the usual Sobolev space of functions with square
257 | # integrable first derivatives that vanish on the boundary. If we then take
258 | # $\nabla w$ we have the result $\nabla w \in H_0(\mathrm{rot}; \Omega)$ which
259 | # is the Sobolev space of vector-valued functions with square integrable
260 | # $\mathrm{rot}$ whose tangential component $\nabla w \cdot t$ vanishes on the
261 | # boundary.
262 | #
263 | # Let's look at our expression for the shear strain vector in light of these
264 | # new results. In the thin-plate limit $t \to 0$, we would like to recover our
265 | # the standard Kirchhoff-Love problem where we do not have transverse shear
266 | # strains $\gamma \to 0$ at all. In a finite element context, where we have
267 | # discretised fields $w_h$ and $\theta_h$ we then would like
268 | #
269 | # $$\gamma(\theta_h, w_h) := \nabla w_h - \theta_h = 0 \quad t \to 0 \; \forall x \in \Omega$$
270 | #
271 | # If we think about using first-order piecewise linear polynomial finite
272 | # elements for both fields, then we are requiring that piecewise constant
273 | # functions ($\nabla w_h$) are equal to piecewise linear functions ($\theta_h$)
274 | # # ! This is strong requirement, and is the root of the famous shear-locking
275 | # problem. The trick of the Durán-Liberman approach is recognising that by
276 | # modifying the rotation field at the discrete level by applying a special
277 | # operator $R_h$ that takes the rotations to the conforming space
278 | # $\mathrm{NED}_1 \subset H_0(\mathrm{rot}; \Omega)$ for the shear strains that
279 | # we previously identified:
280 | #
281 | # $$R_h : H_0^1(\Omega) \to H_0(\mathrm{rot}; \Omega)$$
282 | #
283 | # we can 'unlock' the element. With this reduction operator applied as follows:
284 | #
285 | # $$\gamma(\theta_h, w_h) := R_h(\nabla w_h - \theta_h = 0) \quad t \to 0 \; \forall x \in \Omega$$
286 | #
287 | # our requirement of vanishing shear strains can actually hold. This is the
288 | # basic mathematical idea behind all MITC approaches, of which the
289 | # Durán-Liberman approach is a specific implementation.
290 |
--------------------------------------------------------------------------------
/demo/demo_reissner-mindlin-simply-supported.py:
--------------------------------------------------------------------------------
1 | # ---
2 | # jupyter:
3 | # jupytext:
4 | # text_representation:
5 | # extension: .py
6 | # format_name: light
7 | # format_version: '1.5'
8 | # jupytext_version: 1.14.1
9 | # ---
10 |
11 | # # Simply-supported Reissner-Mindlin plate under uniform load
12 | #
13 | # This demo program solves the out-of-plane Reissner-Mindlin equations on the
14 | # unit square with uniform transverse loading and simply supported boundary
15 | # conditions. This version does not use the special projected assembly routines
16 | # in FEniCSx-Shells.
17 | #
18 | # It is assumed the reader understands most of the basic functionality of the
19 | # new FEniCSx Project.
20 | #
21 | # This demo illustrates how to:
22 | #
23 | # - Define the Reissner-Mindlin plate equations using UFL.
24 | # - Define the MITC4 reduction operator using UFL. This procedure eliminates
25 | # the shear-locking problem.
26 | #
27 | # We begin by importing the necessary functionality from DOLFINx, UFL and
28 | # PETSc.
29 |
30 | from mpi4py import MPI
31 |
32 | import numpy as np
33 |
34 | import dolfinx
35 | import ufl
36 | from basix.ufl import element, mixed_element
37 | from dolfinx.fem import Function, dirichletbc, functionspace
38 | from dolfinx.fem.petsc import LinearProblem
39 | from dolfinx.mesh import CellType, create_unit_square
40 | from ufl import dx, grad, inner, split, sym, tr
41 |
42 | # We then create a two-dimensional mesh of the mid-plane of the plate $\Omega =
43 | # [0, 1] \times [0, 1]$. `GhostMode.shared_facet` is required as the Form will
44 | # use Nédélec elements and DG-type restrictions.
45 |
46 | mesh = create_unit_square(MPI.COMM_WORLD, 32, 32, CellType.quadrilateral)
47 |
48 | # The MITC4 element [1] for the Reissner-Mindlin plate problem
49 | # consists of:
50 | #
51 | # - first-order vector-valued Lagrange element for the rotation field $\theta
52 | # \in [\mathrm{CG}_1]^2$ and,
53 | # - a first-order scalar valued Lagrange element for the transverse
54 | # displacement field $w \in \mathrm{CG}_1$ and,
55 | # - the reduced shear strain $\gamma_R \in \mathrm{RTCE}_1$ the vector-valued
56 | # Nédélec elements of the first kind, and
57 | # - a Lagrange multiplier field $p$ that ties together the shear strain
58 | # calculated from the primal variables $\gamma = \nabla w - \theta$ and the
59 | # reduced shear strain $\gamma_R$. Both $p$ and $\gamma_R$ are are discretised
60 | # in the space $\mathrm{RTCE}_1$, the vector-valued Nédélec elements of the
61 | # first kind.
62 | #
63 | # The final element definition is
64 |
65 | # +
66 | cell = mesh.basix_cell()
67 | U_el = mixed_element(
68 | [
69 | element("Lagrange", cell, 1, shape=(2,)),
70 | element("Lagrange", cell, 1),
71 | element("RTCE", cell, 1),
72 | element("RTCE", cell, 1),
73 | ]
74 | )
75 | U = functionspace(mesh, U_el)
76 |
77 | u_ = Function(U)
78 | u = ufl.TrialFunction(U)
79 | u_t = ufl.TestFunction(U)
80 |
81 | theta_, w_, R_gamma_, p_ = split(u_)
82 | # -
83 |
84 | # We assume constant material parameters; Young's modulus $E$, Poisson's ratio
85 | # $\nu$, shear-correction factor $\kappa$, and thickness $t$.
86 |
87 | E = 10920.0
88 | nu = 0.3
89 | kappa = 5.0 / 6.0
90 | t = 0.001
91 |
92 | # The bending strain tensor $k$ for the Reissner-Mindlin model can be expressed
93 | # in terms of the rotation field $\theta$
94 | #
95 | # $$
96 | # k(\theta) = \dfrac{1}{2}(\nabla \theta + (\nabla \theta)^T)
97 | # $$
98 | #
99 | # The bending energy density $\psi_b$ for the Reissner-Mindlin model is a
100 | # function of the bending strain tensor $k$
101 | #
102 | # $$
103 | # \psi_b(k) = \frac{1}{2} D \left( (1 - \nu) \, \mathrm{tr}\,(k^2)
104 | # + \nu \, (\mathrm{tr} \,k)^2 \right) \qquad
105 | # D = \frac{Et^3}{12(1 - \nu^2)}
106 | # $$
107 | #
108 | # which can be expressed in UFL as
109 |
110 | D = (E * t**3) / (24.0 * (1.0 - nu**2))
111 | k = sym(grad(theta_))
112 | psi_b = D * ((1.0 - nu) * tr(k * k) + nu * (tr(k)) ** 2)
113 |
114 | # Because we are using a mixed variational formulation, we choose to write the
115 | # shear energy density $\psi_s$ is a function of the reduced shear strain
116 | # vector
117 | #
118 | # $$\psi_s(\gamma_R) = \frac{E \kappa t}{4(1 + \nu)}\gamma_R^2,$$
119 | #
120 | # or in UFL:
121 |
122 | psi_s = ((E * kappa * t) / (4.0 * (1.0 + nu))) * inner(R_gamma_, R_gamma_)
123 |
124 | # Finally, we can write out external work due to the uniform loading in the out-of-plane direction
125 | #
126 | # $$
127 | # W_{\mathrm{ext}} = \int_{\Omega} ft^3 \cdot w \; \mathrm{d}x.
128 | # $$
129 |
130 | # where $f = 1$ and $\mathrm{d}x$ is a measure on the whole domain.
131 | # The scaling by $t^3$ is included to ensure a correct limit solution as
132 | # $t \to 0$.
133 | #
134 | # In UFL this can be expressed as
135 |
136 | W_ext = inner(1.0 * t**3, w_) * dx
137 |
138 | # With all of the standard mechanical terms defined, we can turn to defining
139 | # the Duran-Liberman reduction operator. This operator 'ties' our reduced shear
140 | # strain field to the shear strain calculated in the primal space. A partial
141 | # explanation of the thinking behind this approach is given in the Appendix at
142 | # the bottom of this notebook.
143 | #
144 | # The shear strain vector $\gamma$ can be expressed in terms of the rotation
145 | # and transverse displacement field
146 | #
147 | # $$\gamma(\theta, w) = \nabla w - \theta$$
148 | #
149 | # or in UFL
150 |
151 | gamma = grad(w_) - theta_
152 |
153 | # We require that the shear strain calculated using the displacement unknowns
154 | # $\gamma = \nabla w - \theta$ be equal, in a weak sense, to the conforming
155 | # shear strain field $\gamma_R \in \mathrm{NED}_1$ that we used to define the
156 | # shear energy above. We enforce this constraint using a Lagrange multiplier
157 | # field $p \in \mathrm{NED}_1$. We can write the Lagrangian functional of this
158 | # constraint as:
159 | #
160 | # $$\Pi_R(\gamma, \gamma_R, p) =
161 | # \int_{e} \left( \left\lbrace \gamma_R - \gamma \right\rbrace \cdot t \right)
162 | # \cdot \left( p \cdot t \right) \; \mathrm{d}s$$
163 | #
164 | # where $e$ are all of edges of the cells in the mesh and $t$ is the tangent
165 | # vector on each edge.
166 | #
167 | # Writing this operator out in UFL is quite verbose, so `fenicsx_shells`
168 | # includes a special inner product function `inner_e` to help. However, we
169 | # choose to write this function in full here.
170 |
171 | # +
172 | dSp = ufl.Measure("dS", metadata={"quadrature_degree": 1})
173 | dsp = ufl.Measure("ds", metadata={"quadrature_degree": 1})
174 |
175 | n = ufl.FacetNormal(mesh)
176 | t = ufl.as_vector((-n[1], n[0]))
177 |
178 |
179 | def inner_e(x, y):
180 | return (inner(x, t) * inner(y, t))("+") * dSp + (inner(x, t) * inner(y, t)) * dsp
181 |
182 |
183 | Pi_R = inner_e(gamma - R_gamma_, p_)
184 | # -
185 |
186 | # We can now define our Lagrangian for the complete system and derive the
187 | # residual and Jacobian automatically using the standard UFL `derivative`
188 | # function
189 |
190 | Pi = psi_b * dx + psi_s * dx + Pi_R - W_ext
191 | F = ufl.derivative(Pi, u_, u_t)
192 | J = ufl.derivative(F, u_, u)
193 |
194 | # In the following we use standard from `dolfinx` to apply boundary conditions,
195 | # assemble, solve and output the solution.
196 | #
197 | # For simplicity of implementation we also apply boundary conditions on the
198 | # Lagrange multiplier space but this is not strictly necessary as the Lagrange
199 | # multiplier simply constrains $\gamma_R \cdot t$ to $\gamma = \nabla w -
200 | # \theta$, all of which are enforced to be zero by definition.
201 |
202 | # +
203 |
204 |
205 | def all_boundary(x):
206 | return np.full(x.shape[1], True, dtype=bool)
207 |
208 |
209 | def left_or_right(x):
210 | return np.logical_or(np.isclose(x[0], 0.0), np.isclose(x[0], 1.0))
211 |
212 |
213 | def top_or_bottom(x):
214 | return np.logical_or(np.isclose(x[1], 0.0), np.isclose(x[1], 1.0))
215 |
216 |
217 | def make_bc(value, V, on_boundary):
218 | boundary_entities = dolfinx.mesh.locate_entities_boundary(
219 | mesh, mesh.topology.dim - 1, on_boundary
220 | )
221 | boundary_dofs = dolfinx.fem.locate_dofs_topological(V, mesh.topology.dim - 1, boundary_entities)
222 | bc = dirichletbc(value, boundary_dofs, V)
223 | return bc
224 |
225 |
226 | bcs = []
227 | # Transverse displacements fixed everywhere
228 | bcs.append(make_bc(np.array(0.0, dtype=np.float64), U.sub(1), all_boundary))
229 |
230 | # First component of rotation fixed on top and bottom
231 | bcs.append(make_bc(np.array(0.0, dtype=np.float64), U.sub(0).sub(0), top_or_bottom))
232 |
233 | # Second component of rotation fixed on left and right
234 | bcs.append(make_bc(np.array(0.0, dtype=np.float64), U.sub(0).sub(1), left_or_right))
235 |
236 |
237 | problem = LinearProblem(
238 | J,
239 | -F,
240 | bcs=bcs,
241 | petsc_options={"ksp_type": "preonly", "pc_type": "lu", "pc_factor_mat_solver_type": "mumps"},
242 | )
243 | u_ = problem.solve()
244 |
245 | bb_tree = dolfinx.geometry.bb_tree(mesh, 2)
246 | point = np.array([[0.5, 0.5, 0.0]], dtype=np.float64)
247 | cell_candidates = dolfinx.geometry.compute_collisions_points(bb_tree, point)
248 | cells = dolfinx.geometry.compute_colliding_cells(mesh, cell_candidates, point)
249 |
250 | theta, w, R_gamma, p = u_.split()
251 |
252 | if cells.array.shape[0] > 0:
253 | value = w.eval(point, cells.array[0])
254 | print(value[0])
255 | # -
256 |
--------------------------------------------------------------------------------
/demo/pytest.ini:
--------------------------------------------------------------------------------
1 | [pytest]
2 | addopts = --strict-markers
3 | markers =
4 | serial
5 | mpi
6 |
--------------------------------------------------------------------------------
/demo/test_demos.py:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2016-2016 Garth N. Wells
2 | #
3 | # This file is part of DOLFINx (https://www.fenicsproject.org)
4 | #
5 | # SPDX-License-Identifier: LGPL-3.0-or-later
6 |
7 | import pathlib
8 | import subprocess
9 | import sys
10 |
11 | import pytest
12 |
13 | # Get directory of this file
14 | path = pathlib.Path(__file__).resolve().parent
15 |
16 | # Build list of demo programs
17 | demos = []
18 | demo_files = list(path.glob("**/demo_*.py"))
19 | for f in demo_files:
20 | demos.append((f.parent, f.name))
21 |
22 | print(demos)
23 |
24 |
25 | @pytest.mark.serial
26 | @pytest.mark.parametrize("path,name", demos)
27 | def test_demos(path, name):
28 | ret = subprocess.run([sys.executable, name], cwd=str(path), check=True)
29 | assert ret.returncode == 0
30 |
31 |
32 | @pytest.mark.mpi
33 | @pytest.mark.parametrize("path,name", demos)
34 | def test_demos_mpi(num_proc, mpiexec, path, name):
35 | cmd = [mpiexec, "-np", str(num_proc), sys.executable, name]
36 | print(cmd)
37 | ret = subprocess.run(cmd, cwd=str(path), check=True)
38 | assert ret.returncode == 0
39 |
--------------------------------------------------------------------------------
/doc/README.md:
--------------------------------------------------------------------------------
1 | # Building documentation
2 |
3 | To build the documentation install Sphinx and run
4 |
5 | python3 -m sphinx -W -b html source/ build/html/
6 |
--------------------------------------------------------------------------------
/doc/source/.gitignore:
--------------------------------------------------------------------------------
1 | demo/
2 |
--------------------------------------------------------------------------------
/doc/source/_static/.placeholder:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FEniCS-Shells/fenicsx-shells/e1bbfd920ed42843720273eebf35aa940ba422c7/doc/source/_static/.placeholder
--------------------------------------------------------------------------------
/doc/source/conf.py:
--------------------------------------------------------------------------------
1 | # Configuration file for the Sphinx documentation builder.
2 | #
3 | # For the full list of built-in configuration values, see the documentation:
4 | # https://www.sphinx-doc.org/en/master/usage/configuration.html
5 |
6 | # -- Project information -----------------------------------------------------
7 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8 |
9 | import os
10 | import sys
11 |
12 | sys.path.insert(0, os.path.abspath("."))
13 | import jupytext_process
14 |
15 | jupytext_process.process()
16 |
17 | project = "FEniCSx-Shells"
18 | copyright = "2022-2024, FEniCSx-Shells Authors"
19 | author = "FEniCSx-Shells Authors"
20 | release = "0.10.0.dev0"
21 |
22 | # -- General configuration ---------------------------------------------------
23 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
24 |
25 | extensions = [
26 | "sphinx.ext.autodoc",
27 | "sphinx.ext.autosummary",
28 | "sphinx.ext.mathjax",
29 | "sphinx.ext.napoleon",
30 | "sphinx.ext.todo",
31 | "sphinx.ext.viewcode",
32 | "myst_parser",
33 | ]
34 |
35 | templates_path = ["_templates"]
36 | exclude_patterns = []
37 |
38 | source_suffix = [".rst", ".md"]
39 |
40 | html_theme = "sphinx_rtd_theme"
41 |
42 | myst_enable_extensions = [
43 | "dollarmath",
44 | ]
45 |
46 | autodoc_default_options = {
47 | "members": True,
48 | "show-inheritance": True,
49 | "imported-members": True,
50 | "undoc-members": True,
51 | }
52 | autosummary_generate = True
53 | autoclass_content = "both"
54 |
55 | # -- Options for HTML output -------------------------------------------------
56 | # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
57 |
58 | html_static_path = ["_static"]
59 |
--------------------------------------------------------------------------------
/doc/source/demos.rst:
--------------------------------------------------------------------------------
1 | Documented demos
2 | ================
3 |
4 | Clamped linear Reissner-Mindlin plate problem using the Duran-Liberman reduction
5 | operator (MITC) to cure shear-locking:
6 |
7 | .. toctree::
8 | :titlesonly:
9 | :maxdepth: 1
10 |
11 | demo/demo_reissner-mindlin-clamped.md
12 |
13 | Clamped linear Reissner-Mindlin plate problem using the Pechstein-Schöberl
14 | TDNNS (tangential displacement normal-normal stress) element to cure
15 | shear-locking:
16 |
17 | .. toctree::
18 | :titlesonly:
19 | :maxdepth: 1
20 |
21 | demo/demo_reissner-mindlin-clamped-tdnns.md
22 |
23 | Simply-supported linear Reissner-Mindlin plate problem using the MITC4
24 | reduction operator to cure shear-locking:
25 |
26 | .. toctree::
27 | :titlesonly:
28 | :maxdepth: 1
29 |
30 | demo/demo_reissner-mindlin-simply-supported.md
31 |
32 | Clamped linear Kirchhoff-Love plate problem using the Hellan-Herrmann-Johnson
33 | finite element.
34 |
35 | .. toctree::
36 | :titlesonly:
37 | :maxdepth: 1
38 |
39 | demo/demo_kirchhoff-love-clamped.md
40 |
41 | Clamped nonlinear Naghdi semi-cylindrical shell under a point load using Partial
42 | Selective Reduced Integration (PSRI) to cure shear and membrane locking:
43 |
44 | .. toctree::
45 | :titlesonly:
46 | :maxdepth: 1
47 |
48 | demo/demo_nonlinear-naghdi-clamped-semicylinder.md
49 |
--------------------------------------------------------------------------------
/doc/source/index.rst:
--------------------------------------------------------------------------------
1 | .. FEniCSx-Shells documentation master file, created by
2 | sphinx-quickstart on Fri Aug 26 15:38:02 2022.
3 | You can adapt this file completely to your liking, but it should at least
4 | contain the root `toctree` directive.
5 |
6 | .. toctree::
7 | :maxdepth: 1
8 | :titlesonly:
9 |
10 | Demos
11 |
12 | .. include:: ../../README.md
13 | :parser: myst_parser.sphinx_
14 |
15 | ..
16 | Indices and tables
17 | ==================
18 |
19 | * :ref:`genindex`
20 | * :ref:`modindex`
21 | * :ref:`search`
22 |
23 |
24 |
--------------------------------------------------------------------------------
/doc/source/jupytext_process.py:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2017-2022 Garth N. Wells, Jack S. Hale
2 | #
3 | # This file is part of DOLFINx (https://www.fenicsproject.org)
4 | #
5 | # SPDX-License-Identifier: LGPL-3.0-or-later
6 |
7 | import os
8 | import pathlib
9 | import shutil
10 |
11 | import jupytext
12 |
13 |
14 | def process():
15 | """Convert light format demo Python files into MyST flavoured markdown and
16 | ipynb using Jupytext. These files can then be included in Sphinx
17 | documentation"""
18 | # Directories to scan
19 | subdirs = [pathlib.Path("../../demo")]
20 |
21 | # Iterate over subdirectories containing demos
22 | for subdir in subdirs:
23 | # Make demo doc directory
24 | demo_dir = pathlib.Path("./demo")
25 | demo_dir.mkdir(parents=True, exist_ok=True)
26 |
27 | # Process each demo using jupytext/myst
28 | for demo in subdir.glob("**/demo*.py"):
29 | # If demo saves matplotlib images, run the demo
30 | if "savefig" in demo.read_text():
31 | here = os.getcwd()
32 | os.chdir(demo.parent)
33 | os.system(f"python3 {demo.name}")
34 | os.chdir(here)
35 |
36 | python_demo = jupytext.read(demo)
37 | myst_text = jupytext.writes(python_demo, fmt="myst")
38 |
39 | # myst-parser does not process blocks with {code-cell}
40 | myst_text = myst_text.replace("{code-cell}", "python")
41 | myst_file = (demo_dir / demo.name).with_suffix(".md")
42 | with open(myst_file, "w") as fw:
43 | fw.write(myst_text)
44 |
45 | ipynb_file = (demo_dir / demo.name).with_suffix(".ipynb")
46 | jupytext.write(python_demo, ipynb_file, fmt="ipynb")
47 |
48 | # Copy python demo files into documentation demo directory
49 | shutil.copy(demo, demo_dir)
50 |
51 | # Copy images used in demos
52 | for file in subdir.glob("**/*.png"):
53 | shutil.copy(file, demo_dir)
54 |
55 |
56 | if __name__ == "__main__":
57 | process()
58 |
--------------------------------------------------------------------------------
/launch-container.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | CONTAINER_ENGINE="podman"
3 | ${CONTAINER_ENGINE} run -ti -v $(pwd):/shared -w /shared dolfinx/dolfinx:nightly
4 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [build-system]
2 | requires = ["setuptools", "wheel"]
3 | build-backend = "setuptools.build_meta"
4 |
5 | [project]
6 | name = "fenicsx-shells"
7 | version = "0.10.0.dev0"
8 | description = "A FEniCSx library for simulating thin structures"
9 | readme = "README.md"
10 | requires-python = ">=3.9.0"
11 | license = { file = "COPYING.LESSER" }
12 | authors = [
13 | { name = "Jack S. Hale", email = "mail@jackhale.co.uk" },
14 | { name = "Tian Yang" }
15 | ]
16 | dependencies = [
17 | "fenics-dolfinx>=0.10.0.dev0,<0.11.0",
18 | ]
19 |
20 | [project.optional-dependencies]
21 | doc = ["jupytext", "myst_parser", "sphinx_rtd_theme", "sphinx"]
22 | demo = ["matplotlib"]
23 | test = ["pytest"]
24 | lint = ["ruff"]
25 | ci = [
26 | "fenicsx-shells[doc]",
27 | "fenicsx-shells[demo]",
28 | "fenicsx-shells[test]",
29 | "fenicsx-shells[lint]",
30 | ]
31 |
32 | [tool.ruff]
33 | line-length = 100
34 | indent-width = 4
35 |
36 | [tool.ruff.lint]
37 | select = [
38 | "E", # pycodestyle
39 | "W", # pycodestyle
40 | "F", # pyflakes
41 | "I", # isort - use standalone isort
42 | "RUF", # Ruff-specific rules
43 | "UP", # pyupgrade
44 | "ICN", # flake8-import-conventions
45 | "NPY", # numpy-specific rules
46 | "FLY", # use f-string not static joins
47 | ]
48 | ignore = ["UP007", "RUF012"]
49 | allowed-confusables = ["σ"]
50 |
51 | [tool.ruff.lint.isort]
52 | known-first-party = ["basix", "dolfinx", "ffcx", "ufl"]
53 | known-third-party = ["gmsh", "numba", "numpy", "pytest", "pyvista"]
54 | section-order = [
55 | "future",
56 | "standard-library",
57 | "mpi",
58 | "third-party",
59 | "first-party",
60 | "local-folder",
61 | ]
62 |
63 | [tool.ruff.lint.isort.sections]
64 | "mpi" = ["mpi4py", "petsc4py"]
65 |
--------------------------------------------------------------------------------
/src/fenicsx_shells/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FEniCS-Shells/fenicsx-shells/e1bbfd920ed42843720273eebf35aa940ba422c7/src/fenicsx_shells/__init__.py
--------------------------------------------------------------------------------
/test/.placeholder:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FEniCS-Shells/fenicsx-shells/e1bbfd920ed42843720273eebf35aa940ba422c7/test/.placeholder
--------------------------------------------------------------------------------