pax_global_header 0000666 0000000 0000000 00000000064 14157137534 0014524 g ustar 00root root 0000000 0000000 52 comment=6132750a8792ec87518c05e178cccd29dfa1834b
meshzoo-0.9.2/ 0000775 0000000 0000000 00000000000 14157137534 0013220 5 ustar 00root root 0000000 0000000 meshzoo-0.9.2/.codecov.yml 0000664 0000000 0000000 00000000014 14157137534 0015436 0 ustar 00root root 0000000 0000000 comment: no
meshzoo-0.9.2/.flake8 0000664 0000000 0000000 00000000153 14157137534 0014372 0 ustar 00root root 0000000 0000000 [flake8]
ignore = E203, E266, E501, W503
max-line-length = 80
max-complexity = 18
select = B,C,E,F,W,T4,B9
meshzoo-0.9.2/.github/ 0000775 0000000 0000000 00000000000 14157137534 0014560 5 ustar 00root root 0000000 0000000 meshzoo-0.9.2/.github/workflows/ 0000775 0000000 0000000 00000000000 14157137534 0016615 5 ustar 00root root 0000000 0000000 meshzoo-0.9.2/.github/workflows/ci.yml 0000664 0000000 0000000 00000001507 14157137534 0017736 0 ustar 00root root 0000000 0000000 name: ci
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- name: Run pre-commit
uses: pre-commit/action@v2.0.3
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
steps:
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v2
- name: Test with tox
run: |
pip install tox
tox -- --cov meshzoo --cov-report xml --cov-report term
- uses: codecov/codecov-action@v1
if: ${{ matrix.python-version == '3.10' }}
meshzoo-0.9.2/.gitignore 0000664 0000000 0000000 00000000147 14157137534 0015212 0 ustar 00root root 0000000 0000000 *.pyc
*.e
README.rst
dist/
meshzoo.egg-info/
.cache/
build/
.pytest_cache/
.coverage
*.vtu
*.vtk
.tox/
meshzoo-0.9.2/.pre-commit-config.yaml 0000664 0000000 0000000 00000000456 14157137534 0017506 0 ustar 00root root 0000000 0000000 repos:
- repo: https://github.com/PyCQA/isort
rev: 5.9.1
hooks:
- id: isort
- repo: https://github.com/python/black
rev: 21.6b0
hooks:
- id: black
language_version: python3
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
meshzoo-0.9.2/LICENSE.txt 0000664 0000000 0000000 00000104520 14157137534 0015045 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
meshzoo-0.9.2/README.md 0000664 0000000 0000000 00000017561 14157137534 0014511 0 ustar 00root root 0000000 0000000 # meshzoo
[](https://pypi.org/project/meshzoo/)
[](https://pypi.org/project/meshzoo/)
[](https://github.com/nschloe/meshzoo)
[](https://pepy.tech/project/meshzoo)
[](https://discord.gg/PBCCvwHqpv)
[](https://github.com/nschloe/meshzoo/actions?query=workflow%3Aci)
[](https://codecov.io/gh/nschloe/meshzoo)
[](https://lgtm.com/projects/g/nschloe/meshzoo)
[](https://github.com/psf/black)
When generating meshes for FEM/FVM computations, sometimes your geometry is so simple
that you don't need a complex mesh generator (like
[pygmsh](https://github.com/nschloe/pygmsh/),
[MeshPy](https://github.com/inducer/meshpy),
[mshr](https://bitbucket.org/fenics-project/mshr),
[pygalmesh](https://github.com/nschloe/pygalmesh/),
[dmsh](https://github.com/nschloe/dmsh/)),
but something simple and fast that makes use of the structure of the domain. Enter
meshzoo.
### Examples
#### Triangle
```python
import meshzoo
bary, cells = meshzoo.triangle(8)
# corners = numpy.array(
# [
# [0.0, -0.5 * numpy.sqrt(3.0), +0.5 * numpy.sqrt(3.0)],
# [1.0, -0.5, -0.5],
# ]
# )
# points = numpy.dot(corners, bary).T
# Process the mesh, e.g., write it to a file using meshio
# meshio.write_points_cells("triangle.vtk", points, {"triangle": cells})
```
#### Rectangle
 |
 |
```python
import meshzoo
import numpy as np
points, cells = meshzoo.rectangle_tri(
np.linspace(0.0, 1.0, 11),
np.linspace(0.0, 1.0, 11),
variant="zigzag", # or "up", "down", "center"
)
points, cells = meshzoo.rectangle_quad(
np.linspace(0.0, 1.0, 11),
np.linspace(0.0, 1.0, 11),
cell_type="quad4", # or "quad8", "quad9"
)
```
#### Regular polygon
|
|
|
|
| :----------------------------------------------------------------: | :----------------------------------------------------------------: | :----------------------------------------------------------------: |
| `meshzoo.ngon(4, 8)` | `meshzoo.ngon(6, 8)` | `meshzoo.ngon(9, 8)` |
```python
import meshzoo
points, cells = meshzoo.ngon(5, 11)
```
#### Disk
|
|
|
|
| :---------------------------------------------------------------------: | :---------------------------------------------------------------------: | :---------------------------------------------------------------------: |
| `meshzoo.disk(4, 8)` | `meshzoo.disk(6, 8)` | `meshzoo.disk(9, 8)` |
The disk meshes are inflations of regular polygons.
```python
import meshzoo
points, cells = meshzoo.disk(6, 11)
points, cells = meshzoo.disk_quad(10, cell_type="quad4") # or "quad8", "quad9"
```
#### Möbius strip
```python
import meshzoo
points, cells = meshzoo.moebius(num_twists=1, nl=60, nw=11)
```
#### Sphere (surface)
|
|
|
| :---------------------------------------------------------------------: | :----------------------------------------------------------------------: |
```python
import meshzoo
points, cells = meshzoo.uv_sphere(num_points_per_circle=20, num_circles=10, radius=1.0)
points, tri, quad = meshzoo.geo_sphere(
num_points_per_circle=20, num_circles=10, radius=1.0
)
```
Spheres can also be generated by refining the faces of [platonic
solids](https://en.wikipedia.org/wiki/Platonic_solid) and then "inflating" them. meshzoo
implements a few of them. The sphere generated from the icosahedron has the
highest-quality (most equilateral) triangles.
All cells are oriented such that its normals point outwards.
|
|
|
|
| :------------------------------------------------------------------------: | :-----------------------------------------------------------------------: | :------------------------------------------------------------------------: |
| `meshzoo.tetra_sphere(10)` | `meshzoo.octa_sphere(10)` | `meshzoo.icosa_sphere(10)` |
#### Ball (solid)
|
|
|
| :----------------------------------------------------------------------: | :---------------------------------------------------------------------: |
```python
import meshzoo
points, cells = meshzoo.ball_tetra(10)
points, cells = meshzoo.ball_hexa(10)
```
#### Tube
```python
import meshzoo
points, cells = meshzoo.tube(length=1.0, radius=1.0, n=30)
```
#### Cube
|
|
|
| :----------------------------------------------------------------: | :---------------------------------------------------------------------: |
```python
import meshzoo
import numpy as np
points, cells = meshzoo.cube_tetra(
np.linspace(0.0, 1.0, 11), np.linspace(0.0, 1.0, 11), np.linspace(0.0, 1.0, 11)
)
points, cells = meshzoo.cube_hexa(
np.linspace(0.0, 1.0, 11), np.linspace(0.0, 1.0, 11), np.linspace(0.0, 1.0, 11)
)
```
### Extra, extra
In addition to this, the
[`examples/`](https://github.com/nschloe/meshzoo/tree/main/examples) directory
contains a couple of instructive examples for other mesh generators.
### Installation
meshzoo is [available from the Python Package
Index](https://pypi.org/project/meshzoo/), so simply do
```
pip install meshzoo
```
to install.
### Testing
To run the meshzoo unit tests, check out this repository and run
```
pytest
```
### License
This software is published under the [GPLv3
license](https://www.gnu.org/licenses/gpl-3.0.en.html).
meshzoo-0.9.2/examples/ 0000775 0000000 0000000 00000000000 14157137534 0015036 5 ustar 00root root 0000000 0000000 meshzoo-0.9.2/examples/meshpy/ 0000775 0000000 0000000 00000000000 14157137534 0016343 5 ustar 00root root 0000000 0000000 meshzoo-0.9.2/examples/meshpy/__init__.py 0000664 0000000 0000000 00000000515 14157137534 0020455 0 ustar 00root root 0000000 0000000 import ball
import cube
import ellipse
import lshape
import lshape3d
import pacman
import rectangle
import rectangle_with_hole
import tetrahedron
import torus
__all__ = [
"ball",
"cube",
"ellipse",
"lshape",
"lshape3d",
"pacman",
"rectangle",
"rectangle_with_hole",
"tetrahedron",
"torus",
]
meshzoo-0.9.2/examples/meshpy/ball.py 0000664 0000000 0000000 00000002423 14157137534 0017630 0 ustar 00root root 0000000 0000000 import numpy as np
from meshpy.geometry import EXT_OPEN, GeometryBuilder, generate_surface_of_revolution
from meshpy.tet import MeshInfo, build
def create_ball_mesh(num_longi_points=10):
radius = 5.0
radial_subdiv = 2 * num_longi_points
dphi = np.pi / num_longi_points
# Make sure the nodes meet at the poles of the ball.
def truncate(r):
if abs(r) < 1e-10:
return 0
else:
return r
# Compute the volume of a canonical tetrahedron
# with edgelength radius*dphi.
a = radius * dphi
canonical_tet_volume = np.sqrt(2.0) / 12 * a ** 3
# Build outline for surface of revolution.
rz = [
(truncate(radius * np.sin(i * dphi)), radius * np.cos(i * dphi))
for i in range(num_longi_points + 1)
]
geob = GeometryBuilder()
geob.add_geometry(
*generate_surface_of_revolution(
rz, closure=EXT_OPEN, radial_subdiv=radial_subdiv
)
)
mesh_info = MeshInfo()
geob.set(mesh_info)
meshpy_mesh = build(mesh_info, max_volume=canonical_tet_volume)
return np.array(meshpy_mesh.points), np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_ball_mesh()
meshio.write("ball.e", points, {"tetra": cells})
meshzoo-0.9.2/examples/meshpy/cube.py 0000664 0000000 0000000 00000002224 14157137534 0017633 0 ustar 00root root 0000000 0000000 """
Creates meshes on a cube.
"""
import meshpy.tet
import numpy as np
def create_mesh(maxvol):
# get the file name to be written to
# circumcirlce radius
cc_radius = 5.0
lx = 2.0 / np.sqrt(3.0) * cc_radius
ly = lx
lz = lx
# Corner points of the cube
points = [
(-0.5 * lx, -0.5 * ly, -0.5 * lz),
(0.5 * lx, -0.5 * ly, -0.5 * lz),
(0.5 * lx, 0.5 * ly, -0.5 * lz),
(-0.5 * lx, 0.5 * ly, -0.5 * lz),
(-0.5 * lx, -0.5 * ly, 0.5 * lz),
(0.5 * lx, -0.5 * ly, 0.5 * lz),
(0.5 * lx, 0.5 * ly, 0.5 * lz),
(-0.5 * lx, 0.5 * ly, 0.5 * lz),
]
facets = [
[0, 1, 2, 3],
[4, 5, 6, 7],
[0, 4, 5, 1],
[1, 5, 6, 2],
[2, 6, 7, 3],
[3, 7, 4, 0],
]
# create the mesh
info = meshpy.tet.MeshInfo()
info.set_points(points)
info.set_facets(facets)
meshpy_mesh = meshpy.tet.build(info, max_volume=maxvol)
return np.array(meshpy_mesh.points), np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_mesh(0.1)
meshio.write("cube.e", points, {"tetra": cells})
meshzoo-0.9.2/examples/meshpy/ellipse.py 0000664 0000000 0000000 00000003214 14157137534 0020352 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python
import meshpy.triangle
import numpy as np
from scipy import special
def create_mesh(axis0=1, axis1=0.5, num_boundary_points=100):
# lengths of major and minor axes
a = max(axis0, axis1)
b = min(axis0, axis1)
# Choose the maximum area of a triangle equal to the area of
# an equilateral triangle on the boundary.
# For circumference of an ellipse, see
# https://en.wikipedia.org/wiki/Ellipse#Circumference
eccentricity = np.sqrt(1.0 - (b / a) ** 2)
length_boundary = float(4 * a * special.ellipe(eccentricity))
a_boundary = length_boundary / num_boundary_points
max_area = a_boundary ** 2 * np.sqrt(3) / 4
# generate points on the circle
Phi = np.linspace(0, 2 * np.pi, num_boundary_points, endpoint=False)
boundary_points = np.column_stack((a * np.cos(Phi), b * np.sin(Phi)))
info = meshpy.triangle.MeshInfo()
info.set_points(boundary_points)
def _round_trip_connect(start, end):
result = []
for i in range(start, end):
result.append((i, i + 1))
result.append((end, start))
return result
info.set_facets(_round_trip_connect(0, len(boundary_points) - 1))
def _needs_refinement(vertices, area):
return bool(area > max_area)
meshpy_mesh = meshpy.triangle.build(info, refinement_func=_needs_refinement)
# append column
pts = np.array(meshpy_mesh.points)
points = np.c_[pts[:, 0], pts[:, 1], np.zeros(len(pts))]
return points, np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_mesh()
meshio.write("ellipse.e", points, {"triangle": cells})
meshzoo-0.9.2/examples/meshpy/lshape.py 0000664 0000000 0000000 00000002260 14157137534 0020171 0 ustar 00root root 0000000 0000000 import meshpy.triangle
import numpy as np
def create_mesh(maxarea=1.0):
# dimensions of the rectangle
cc_radius = 5.0 # circumcircle radius
lx = np.sqrt(2.0) * cc_radius
ly = lx
# corner points
points = [
(-0.5 * lx, -0.5 * ly),
(0.5 * lx, -0.5 * ly),
(0.5 * lx, 0.0),
(0.0, 0.0),
(0.0, 0.5 * ly),
(-0.5 * lx, 0.5 * ly),
]
info = meshpy.triangle.MeshInfo()
info.set_points(points)
def _round_trip_connect(start, end):
result = []
for i in range(start, end):
result.append((i, i + 1))
result.append((end, start))
return result
info.set_facets(_round_trip_connect(0, len(points) - 1))
def _needs_refinement(vertices, area):
return bool(area > maxarea)
meshpy_mesh = meshpy.triangle.build(info, refinement_func=_needs_refinement)
# append column
pts = np.array(meshpy_mesh.points)
points = np.c_[pts[:, 0], pts[:, 1], np.zeros(len(pts))]
return points, np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_mesh()
meshio.write("lshape.e", points, {"triangle": cells})
meshzoo-0.9.2/examples/meshpy/lshape3d.py 0000664 0000000 0000000 00000002731 14157137534 0020423 0 ustar 00root root 0000000 0000000 """Creates meshes on a 3D L-shape.
"""
import meshpy.tet
import numpy as np
def create_mesh(maxvol):
# circumcirlce radius
cc_radius = 10.0
lx = 2.0 / np.sqrt(3.0) * cc_radius
ly = lx
lz = lx
# create the mesh data structure
# Corner points of the cube
points = [
(-0.5 * lx, -0.5 * ly, -0.5 * lz),
(0.5 * lx, -0.5 * ly, -0.5 * lz),
(0.5 * lx, 0.5 * ly, -0.5 * lz),
(-0.5 * lx, 0.5 * ly, -0.5 * lz),
(-0.5 * lx, -0.5 * ly, 0.5 * lz),
(0.5 * lx, 0.5 * ly, 0.5 * lz),
(-0.5 * lx, 0.5 * ly, 0.5 * lz),
(0.0, -0.5 * ly, 0.5 * lz),
(0.0, -0.5 * ly, 0.0),
(0.5 * lx, -0.5 * ly, 0.0),
(0.5 * lx, 0.0, 0.0),
(0.5 * lx, 0.0, 0.5 * lz),
(0.0, 0.0, 0.5 * lz),
(0.0, 0.0, 0.0),
]
facets = [
[0, 1, 2, 3],
[4, 7, 12, 11, 5, 6],
[0, 1, 9, 8, 7, 4],
[1, 2, 5, 11, 10, 9],
[2, 5, 6, 3],
[3, 6, 4, 0],
[8, 13, 12, 7],
[8, 9, 10, 13],
[10, 11, 12, 13],
]
# create the mesh
# Set the geometry and build the mesh.
info = meshpy.tet.MeshInfo()
info.set_points(points)
info.set_facets(facets)
meshpy_mesh = meshpy.tet.build(info, max_volume=maxvol)
return np.array(meshpy_mesh.points), np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_mesh(0.1)
meshio.write("lshape3d.e", points, {"tetra": cells})
meshzoo-0.9.2/examples/meshpy/pacman.py 0000664 0000000 0000000 00000003414 14157137534 0020156 0 ustar 00root root 0000000 0000000 """
Creates a mesh for a circle with a cut.
"""
import meshpy.triangle
import numpy as np
def create_pacman_mesh(num_boundary_points=50):
n_phi = num_boundary_points
radius = 5.0
# set those to 0.0 for perfect circle
cut_angle = 0.1 * 2 * np.pi
cut_depth = 0.5 * radius
# Choose the maximum area of a triangle equal to the area of
# an equilateral triangle on the boundary.
a_boundary = (2 * np.pi - cut_angle) * radius / n_phi
max_area = a_boundary ** 2 * np.sqrt(3.0) / 4.0
max_area = float(max_area) # meshpy can't deal with np.float64
# generate points on the boundary
Phi = np.linspace(
0.5 * cut_angle, 2 * np.pi - 0.5 * cut_angle, n_phi, endpoint=False
)
boundary_points = []
if abs(cut_angle) > 0.0 or cut_depth != 0.0:
boundary_points.append((radius - cut_depth, 0.0))
for phi in Phi:
boundary_points.append((radius * np.cos(phi), radius * np.sin(phi)))
# create the mesh
info = meshpy.triangle.MeshInfo()
info.set_points(boundary_points)
def _round_trip_connect(start, end):
result = []
for i in range(start, end):
result.append((i, i + 1))
result.append((end, start))
return result
info.set_facets(_round_trip_connect(0, len(boundary_points) - 1))
def _needs_refinement(vertices, area):
return bool(area > max_area)
meshpy_mesh = meshpy.triangle.build(info, refinement_func=_needs_refinement)
# append column
pts = np.array(meshpy_mesh.points)
points = np.c_[pts[:, 0], pts[:, 1], np.zeros(len(pts))]
return points, np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_pacman_mesh()
meshio.write("pacman.vtu", points, {"triangle": cells})
meshzoo-0.9.2/examples/meshpy/rectangle.py 0000664 0000000 0000000 00000002300 14157137534 0020654 0 ustar 00root root 0000000 0000000 """
Creates a mesh on a rectangle in the x-y-plane.
"""
import meshpy.triangle
import numpy as np
def create_mesh(edgelength=1.0, max_area=0.01):
# dimensions of the rectangle
lx = edgelength
ly = edgelength
# corner points
boundary_points = [
(-0.5 * lx, -0.5 * ly),
(0.5 * lx, -0.5 * ly),
(0.5 * lx, 0.5 * ly),
(-0.5 * lx, 0.5 * ly),
]
info = meshpy.triangle.MeshInfo()
info.set_points(boundary_points)
def _round_trip_connect(start, end):
result = []
for i in range(start, end):
result.append((i, i + 1))
result.append((end, start))
return result
info.set_facets(_round_trip_connect(0, len(boundary_points) - 1))
def _needs_refinement(vertices, area):
return bool(area > max_area)
meshpy_mesh = meshpy.triangle.build(info, refinement_func=_needs_refinement)
# append column
pts = np.array(meshpy_mesh.points)
points = np.c_[pts[:, 0], pts[:, 1], np.zeros(len(pts))]
return points, np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_mesh()
meshio.write("rectangle.e", points, {"triangle": cells})
meshzoo-0.9.2/examples/meshpy/rectangle_with_hole.py 0000664 0000000 0000000 00000003063 14157137534 0022725 0 ustar 00root root 0000000 0000000 import meshpy.triangle
import numpy as np
def create_mesh(max_area=1.0):
# dimensions of the rectangle
cc_radius = 15.0 # circumcircle radius
lx = np.sqrt(2.0) * cc_radius
ly = lx
h_radius = 1.0
# corner points
boundary_points = [
(0.5 * lx, 0.0),
(0.5 * lx, 0.5 * ly),
(-0.5 * lx, 0.5 * ly),
(-0.5 * lx, -0.5 * ly),
(0.5 * lx, -0.5 * ly),
(0.5 * lx, 0.0),
]
# create circular boundary on the inside
segments = 100
for k in range(segments + 1):
angle = k * 2.0 * np.pi / segments
boundary_points.append((h_radius * np.cos(angle), h_radius * np.sin(angle)))
# mark the hole by an interior point
holes = [(0, 0)]
info = meshpy.triangle.MeshInfo()
info.set_points(boundary_points)
info.set_holes(holes)
def _round_trip_connect(start, end):
result = []
for i in range(start, end):
result.append((i, i + 1))
result.append((end, start))
return result
info.set_facets(_round_trip_connect(0, len(boundary_points) - 1))
def _needs_refinement(vertices, area):
return bool(area > max_area)
meshpy_mesh = meshpy.triangle.build(info, refinement_func=_needs_refinement)
# append column
pts = np.array(meshpy_mesh.points)
points = np.c_[pts[:, 0], pts[:, 1], np.zeros(len(pts))]
return points, np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_mesh()
meshio.write("rectangle_with_hole.e", points, {"triangle": cells})
meshzoo-0.9.2/examples/meshpy/tetrahedron.py 0000664 0000000 0000000 00000002551 14157137534 0021237 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python
"""
Create irregular mesh on a regular tetrahedron centered at the origin.
"""
import meshpy.tet
import numpy as np
def create_tetrahedron_mesh(maxvol=0.1):
# circumcircle radius
r = 5.0
# boundary points
points = []
points.append((0.0, 0.0, r))
# theta = arccos(-1/3) (tetrahedral angle)
costheta = -1.0 / 3.0
sintheta = 2.0 / 3.0 * np.sqrt(2.0)
# phi = 0.0
sinphi = 0.0
cosphi = 1.0
points.append((r * cosphi * sintheta, r * sinphi * sintheta, r * costheta))
# phi = np.pi * 2.0 / 3.0
sinphi = np.sqrt(3.0) / 2.0
cosphi = -0.5
points.append((r * cosphi * sintheta, r * sinphi * sintheta, r * costheta))
# phi = - np.pi * 2.0 / 3.0
sinphi = -np.sqrt(3.0) / 2.0
cosphi = -0.5
points.append((r * cosphi * sintheta, r * sinphi * sintheta, r * costheta))
# boundary faces
facets = [[0, 1, 2], [0, 2, 3], [0, 3, 1], [1, 2, 3]]
# create the mesh
# Set the geometry and build the mesh.
info = meshpy.tet.MeshInfo()
info.set_points(points)
info.set_facets(facets)
meshpy_mesh = meshpy.tet.build(info, max_volume=maxvol)
return np.array(meshpy_mesh.points), np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_tetrahedron_mesh(10.0)
meshio.write("tetrahedron.vtu", points, {"tetra": cells})
meshzoo-0.9.2/examples/meshpy/torus.py 0000664 0000000 0000000 00000002162 14157137534 0020072 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python
import numpy as np
from meshpy.geometry import (
EXT_CLOSED_IN_RZ,
GeometryBuilder,
generate_surface_of_revolution,
)
from meshpy.tet import MeshInfo, build
def create_mesh(big_r=1.0, small_r=0.5, num_points=10):
dphi = 2 * np.pi / num_points
# Compute the volume of a canonical tetrahedron
# with edgelength radius2*dphi.
a = small_r * dphi
canonical_tet_volume = np.sqrt(2.0) / 12 * a ** 3
radial_subdiv = int(2 * np.pi * big_r / a)
rz = [
(big_r + small_r * np.cos(i * dphi), 0.5 * small_r * np.sin(i * dphi))
for i in range(num_points)
]
geob = GeometryBuilder()
geob.add_geometry(
*generate_surface_of_revolution(
rz, closure=EXT_CLOSED_IN_RZ, radial_subdiv=radial_subdiv
)
)
mesh_info = MeshInfo()
geob.set(mesh_info)
meshpy_mesh = build(mesh_info, max_volume=canonical_tet_volume)
return np.array(meshpy_mesh.points), np.array(meshpy_mesh.elements)
if __name__ == "__main__":
import meshio
points, cells = create_mesh()
meshio.write("torus.e", points, {"tetra": cells})
meshzoo-0.9.2/examples/mshr/ 0000775 0000000 0000000 00000000000 14157137534 0016007 5 ustar 00root root 0000000 0000000 meshzoo-0.9.2/examples/mshr/__init__.py 0000664 0000000 0000000 00000000036 14157137534 0020117 0 ustar 00root root 0000000 0000000 import toy
__all__ = ["toy"]
meshzoo-0.9.2/examples/mshr/toy.py 0000664 0000000 0000000 00000001434 14157137534 0017176 0 ustar 00root root 0000000 0000000 import dolfin
import mshr
def create_toy_mesh():
box = mshr.Box(dolfin.Point(-3, -1, -0.5), dolfin.Point(3, 1, 0.5))
c1 = mshr.Cylinder(dolfin.Point(0, 0, -2), dolfin.Point(0, 0, 2), 0.6, 0.6)
b1 = mshr.Box(dolfin.Point(-2.5, -0.5, -2), dolfin.Point(-1.5, 0.5, 2))
# "triangle"
t1 = mshr.Polygon(
[
dolfin.Point(2.5, -0.5, 0),
dolfin.Point(2.5, 0.5, 0),
dolfin.Point(1.5, -0.5, 0),
]
)
g3d = mshr.Extrude2D(t1, -2)
g3d = mshr.CSGTranslation(g3d, dolfin.Point(0, 0, 1))
m = mshr.generate_mesh(box - c1 - b1 - g3d, 40, "cgal")
return m.coordinates(), m.cells()
if __name__ == "__main__":
import meshio
points, cells = create_toy_mesh()
meshio.write("toy.e", points, {"tetra": cells})
meshzoo-0.9.2/justfile 0000664 0000000 0000000 00000001666 14157137534 0015001 0 ustar 00root root 0000000 0000000 version := `python3 -c "from configparser import ConfigParser; p = ConfigParser(); p.read('setup.cfg'); print(p['metadata']['version'])"`
name := `python3 -c "from configparser import ConfigParser; p = ConfigParser(); p.read('setup.cfg'); print(p['metadata']['name'])"`
default:
@echo "\"just publish\"?"
tag:
@if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then exit 1; fi
curl -H "Authorization: token `cat ~/.github-access-token`" -d '{"tag_name": "v{{version}}"}' https://api.github.com/repos/nschloe/{{name}}/releases
upload: clean
@if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then exit 1; fi
# https://stackoverflow.com/a/58756491/353337
python3 -m build --sdist --wheel .
twine upload dist/*
publish: tag upload
clean:
@find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
@rm -rf src/*.egg-info/ build/ dist/ .tox/
format:
isort .
black .
blacken-docs README.md
lint:
black --check .
flake8 .
meshzoo-0.9.2/pyproject.toml 0000664 0000000 0000000 00000000176 14157137534 0016140 0 ustar 00root root 0000000 0000000 [build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
[tool.isort]
profile = "black"
meshzoo-0.9.2/setup.cfg 0000664 0000000 0000000 00000002312 14157137534 0015037 0 ustar 00root root 0000000 0000000 [metadata]
name = meshzoo
version = 0.9.2
author = Nico Schlömer
author_email = nico.schloemer@gmail.com
description = Collection of explicitly constructed meshes
url = https://github.com/nschloe/meshzoo
project_urls =
Code=https://github.com/nschloe/meshzoo
Issues=https://github.com/nschloe/meshzoo/issues
Funding=https://github.com/sponsors/nschloe
long_description = file: README.md
long_description_content_type = text/markdown
license = GPL-3.0-or-later
classifiers =
Development Status :: 5 - Production/Stable
Intended Audience :: Science/Research
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering :: Mathematics
[options]
package_dir =
=src
packages = find:
install_requires =
numpy
python_requires = >=3.7
[options.packages.find]
where=src
[options.extras_require]
all = matplotlib
plot = matplotlib
meshzoo-0.9.2/src/ 0000775 0000000 0000000 00000000000 14157137534 0014007 5 ustar 00root root 0000000 0000000 meshzoo-0.9.2/src/meshzoo/ 0000775 0000000 0000000 00000000000 14157137534 0015473 5 ustar 00root root 0000000 0000000 meshzoo-0.9.2/src/meshzoo/__init__.py 0000664 0000000 0000000 00000001602 14157137534 0017603 0 ustar 00root root 0000000 0000000 from ._ball import ball_hexa, ball_tetra
from ._cube import cube, cube_hexa, cube_tetra
from ._disk import disk, disk_quad
from ._helpers import create_edges, insert_midpoints_edges, plot2d, save2d, show2d
from ._moebius import moebius
from ._ngon import ngon
from ._rectangle import rectangle, rectangle_quad, rectangle_tri
from ._sphere import geo_sphere, icosa_sphere, octa_sphere, tetra_sphere, uv_sphere
from ._triangle import triangle
from ._tube import tube
__all__ = [
"ball_hexa",
"ball_tetra",
"cube",
"cube_tetra",
"cube_hexa",
"disk",
"disk_quad",
"moebius",
"ngon",
"rectangle",
"rectangle_tri",
"rectangle_quad",
"uv_sphere",
"icosa_sphere",
"octa_sphere",
"tetra_sphere",
"geo_sphere",
"triangle",
"tube",
#
"save2d",
"show2d",
"plot2d",
"create_edges",
"insert_midpoints_edges",
]
meshzoo-0.9.2/src/meshzoo/_ball.py 0000664 0000000 0000000 00000001751 14157137534 0017122 0 ustar 00root root 0000000 0000000 import numpy as np
from ._cube import cube_hexa, cube_tetra
def ball_hexa(n: int):
a = 1 / np.sqrt(3)
ls = np.linspace(-a, a, n + 1)
nodes, cells = cube_hexa(ls, ls, ls)
# Inflate the nodes towards the circle boundary.
# Inflate each point such that the 2-norm of the new point is the max-norm of the
# old.
alpha = np.max(np.abs(nodes), axis=1)
beta = np.linalg.norm(nodes, axis=1)
idx = beta > 1.0e-13
nodes[idx] = (nodes[idx].T * (alpha[idx] / beta[idx])).T
return nodes, cells
def ball_tetra(n: int):
a = 1 / np.sqrt(3)
ls = np.linspace(-a, a, n + 1)
nodes, cells = cube_tetra(ls, ls, ls)
# Inflate the nodes towards the circle boundary.
# Inflate each point such that the 2-norm of the new point is the max-norm of the
# old.
alpha = np.max(np.abs(nodes), axis=1)
beta = np.linalg.norm(nodes, axis=1)
idx = beta > 1.0e-13
nodes[idx] = (nodes[idx].T * (alpha[idx] / beta[idx])).T
return nodes, cells
meshzoo-0.9.2/src/meshzoo/_cube.py 0000664 0000000 0000000 00000010434 14157137534 0017124 0 ustar 00root root 0000000 0000000 from __future__ import annotations
import numpy as np
from numpy.typing import ArrayLike
# backwards compatibility
def cube(
x0: float,
x1: float,
y0: float,
y1: float,
z0: float,
z1: float,
nx: int,
ny: int,
nz: int,
):
return cube_tetra(
np.linspace(x0, x1, nx + 1),
np.linspace(y0, y1, ny + 1),
np.linspace(z0, z1, nz + 1),
)
def cube_hexa(
x_range: ArrayLike, y_range: ArrayLike, z_range: ArrayLike
) -> tuple[np.ndarray, np.ndarray]:
x_range = np.asarray(x_range)
y_range = np.asarray(y_range)
z_range = np.asarray(z_range)
nx1 = len(x_range)
ny1 = len(y_range)
nz1 = len(z_range)
# Create the vertices.
x, y, z = np.meshgrid(x_range, y_range, z_range, indexing="ij")
# Alternative with slightly different order:
# ```
# points = np.stack([x, y, z]).T.reshape(-1, 3)
# ```
points = np.array([x, y, z]).T.reshape(-1, 3)
# Create the cells.
a = np.arange(len(points)).reshape(nz1, ny1, nx1)
a = np.transpose(a, [2, 1, 0])
# `c` contains the indices of each "cube" like
#
#
# c[7] c[6]
# ________
# / /|
# c[4] /_______/ | c[5]
# | | |
# | | |
# | | / c[2]
# |________|/
#
# c[0] c[1]
#
cells = (
np.array(
[
a[:-1, :-1, :-1],
a[1:, :-1, :-1],
a[1:, 1:, :-1],
a[:-1, 1:, :-1],
a[:-1, :-1, 1:],
a[1:, :-1, 1:],
a[1:, 1:, 1:],
a[:-1, 1:, 1:],
]
)
.reshape(8, -1)
.T
)
return points, cells
def cube_tetra(x_range: ArrayLike, y_range: ArrayLike, z_range: ArrayLike):
x_range = np.asarray(x_range)
y_range = np.asarray(y_range)
z_range = np.asarray(z_range)
nx1 = len(x_range)
ny1 = len(y_range)
nz1 = len(z_range)
# Create the vertices.
x, y, z = np.meshgrid(x_range, y_range, z_range, indexing="ij")
# Alternative with slightly different order:
# ```
# points = np.stack([x, y, z]).T.reshape(-1, 3)
# ```
points = np.array([x, y, z]).T.reshape(-1, 3)
# Create the elements (cells).
a = np.arange(len(points)).reshape(nz1, ny1, nx1)
a = np.transpose(a, [2, 1, 0])
#
# `c` contains the indices of each "cube" like
#
#
# c[7] c[6]
# ________
# / /|
# c[4] /_______/ | c[5]
# | | |
# | | |
# | | / c[2]
# |________|/
#
# c[0] c[1]
#
c = [
a[:-1, :-1, :-1],
a[1:, :-1, :-1],
a[1:, 1:, :-1],
a[:-1, 1:, :-1],
a[:-1, :-1, 1:],
a[1:, :-1, 1:],
a[1:, 1:, 1:],
a[:-1, 1:, 1:],
]
# 3D checkers
idx = np.ones((nx1 - 1, ny1 - 1, nz1 - 1), dtype=bool)
idx[::2, 1::2, ::2] = False
idx[::2, ::2, 1::2] = False
idx[1::2, ::2, ::2] = False
idx[1::2, 1::2, 1::2] = False
# There is 1 way to split a cube into 5 tetrahedra,
# and 12 ways to split it into 6 tetrahedra.
# See
#
# Also interesting: .
cells = [
# regular; make sure the order of the points is such that the signed volume is
# positive
[c[0][idx], c[1][idx], c[3][idx], c[4][idx]],
[c[1][idx], c[2][idx], c[3][idx], c[6][idx]],
[c[1][idx], c[3][idx], c[4][idx], c[6][idx]],
[c[1][idx], c[4][idx], c[5][idx], c[6][idx]],
[c[3][idx], c[4][idx], c[6][idx], c[7][idx]],
# the rest rotated such that it fits with the others; basically we change
# "bottom" and "top" of the dice
[c[4][~idx], c[5][~idx], c[0][~idx], c[7][~idx]],
[c[5][~idx], c[6][~idx], c[2][~idx], c[7][~idx]],
[c[5][~idx], c[7][~idx], c[2][~idx], c[0][~idx]],
[c[5][~idx], c[0][~idx], c[2][~idx], c[1][~idx]],
[c[7][~idx], c[0][~idx], c[3][~idx], c[2][~idx]],
]
cells = np.column_stack([np.array(c).reshape(4, -1) for c in cells]).T
return points, cells
meshzoo-0.9.2/src/meshzoo/_disk.py 0000664 0000000 0000000 00000003124 14157137534 0017136 0 ustar 00root root 0000000 0000000 import numpy as np
from ._helpers import _compose_from_faces
from ._rectangle import rectangle_quad
def disk(p: int, n: int, offset: float = np.pi / 2):
x = np.linspace(offset, offset + 2 * np.pi, p, endpoint=False)
corners = np.vstack(
[
[[0.0, 0.0]],
np.array([np.cos(x), np.sin(x)]).T,
]
)
faces = [(0, k + 1, k + 2) for k in range(p - 1)] + [(0, p, 1)]
def edge_adjust(edge, verts):
if 0 in edge:
return verts
dist = np.sqrt(np.einsum("ij,ij->i", verts, verts))
return verts / dist[:, None]
def face_adjust(face, bary, verts, corner_verts):
assert face[0] == 0
z = np.zeros_like(bary[1])
edge_proj_bary = np.array([z, bary[1], bary[2]]) / (bary[1] + bary[2])
edge_proj_cart = np.dot(corner_verts.T, edge_proj_bary).T
dist = np.sqrt(np.einsum("ij,ij->i", edge_proj_cart, edge_proj_cart))
return verts / dist[:, None]
return _compose_from_faces(
corners, faces, n, edge_adjust=edge_adjust, face_adjust=face_adjust
)
def disk_quad(n: int, cell_type: str = "quad4"):
a = 1 / np.sqrt(2)
nodes, cells = rectangle_quad(
np.linspace(-a, a, n + 1), np.linspace(-a, a, n + 1), cell_type
)
# Inflate the nodes towards the circle boundary.
# Inflate each point such that the 2-norm of the new point is the max-norm of the
# old.
alpha = np.max(np.abs(nodes), axis=1)
beta = np.linalg.norm(nodes, axis=1)
idx = beta > 1.0e-13
nodes[idx] = (nodes[idx].T * (alpha[idx] / beta[idx])).T
return nodes, cells
meshzoo-0.9.2/src/meshzoo/_helpers.py 0000664 0000000 0000000 00000020766 14157137534 0017661 0 ustar 00root root 0000000 0000000 import numpy as np
def create_edges(cells_nodes):
"""Setup edge-node and edge-cell relations. Adapted from voropy."""
# Create the idx_hierarchy (nodes->edges->cells), i.e., the value of
# `self.idx_hierarchy[0, 2, 27]` is the index of the node of cell 27, edge
# 2, node 0. The shape of `self.idx_hierarchy` is `(2, 3, n)`, where `n` is
# the number of cells. Make sure that the k-th edge is opposite of the k-th
# point in the triangle.
local_idx = np.array([[1, 2], [2, 0], [0, 1]]).T
# Map idx back to the nodes. This is useful if quantities which are in
# idx shape need to be added up into nodes (e.g., equation system rhs).
nds = cells_nodes.T
idx_hierarchy = nds[local_idx]
s = idx_hierarchy.shape
a = np.sort(idx_hierarchy.reshape(s[0], s[1] * s[2]).T)
b = np.ascontiguousarray(a).view(np.dtype((np.void, a.dtype.itemsize * a.shape[1])))
_, idx, inv, cts = np.unique(
b, return_index=True, return_inverse=True, return_counts=True
)
# No edge has more than 2 cells. This assertion fails, for example, if
# cells are listed twice.
assert all(cts < 3)
edge_nodes = a[idx]
cells_edges = inv.reshape(3, -1).T
return edge_nodes, cells_edges
def show2d(*args, **kwargs):
import matplotlib.pyplot as plt
plot2d(*args, **kwargs)
plt.show()
def save2d(filename, *args, **kwargs):
import matplotlib.pyplot as plt
plot2d(*args, **kwargs)
plt.savefig(filename, transparent=True, bbox_inches="tight")
def plot2d(
points,
cells,
show_axes=False,
# ParaView's default colors
fill: str = "#c8c5bd",
stroke: str = "#000080",
):
"""Plot a 2D mesh using matplotlib."""
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca()
plt.axis("equal")
if not show_axes:
ax.set_axis_off()
assert points.shape[1] == 2
xmin = np.amin(points[:, 0])
xmax = np.amax(points[:, 0])
ymin = np.amin(points[:, 1])
ymax = np.amax(points[:, 1])
width = xmax - xmin
xmin -= 0.1 * width
xmax += 0.1 * width
height = ymax - ymin
ymin -= 0.1 * height
ymax += 0.1 * height
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
for cell in cells:
import matplotlib.patches
poly = matplotlib.patches.Polygon(points[cell], ec=stroke, fc=fill)
ax.add_patch(poly)
# import matplotlib.tri
# tri = matplotlib.tri.Triangulation(points[:,0], points[:,1], triangles=cells)
# ax.triplot(tri, '-', lw=1, color="k")
return fig
def _compose_from_faces(corners, faces, n, edge_adjust=None, face_adjust=None):
# create corner nodes
vertices = [corners]
vertex_count = len(corners)
corner_nodes = np.arange(len(corners))
# create edges
edges = set()
for face in faces:
edges.add(tuple(sorted([face[0], face[1]])))
edges.add(tuple(sorted([face[1], face[2]])))
edges.add(tuple(sorted([face[2], face[0]])))
edges = list(edges)
# create edge nodes:
edge_nodes = {}
t = np.linspace(1 / n, 1.0, n - 1, endpoint=False)
corners = vertices[0]
k = corners.shape[0]
for edge in edges:
i0, i1 = edge
new_vertices = np.outer(1 - t, corners[i0]) + np.outer(t, corners[i1])
if edge_adjust:
new_vertices = edge_adjust(edge, new_vertices)
vertices.append(new_vertices)
vertex_count += len(vertices[-1])
edge_nodes[edge] = np.arange(k, k + len(t))
k += len(t)
# This is the same code as appearing for cell in a single triangle. On each face,
# those indices are translated into the actual indices.
triangle_cells = []
k = 0
for i in range(n):
j = np.arange(n - i)
triangle_cells.append(np.column_stack([k + j, k + j + 1, k + n - i + j + 1]))
j = j[:-1]
triangle_cells.append(
np.column_stack([k + j + 1, k + n - i + j + 2, k + n - i + j + 1])
)
k += n - i + 1
triangle_cells = np.vstack(triangle_cells)
cells = []
for face in faces:
corners = face
edges = [(face[0], face[1]), (face[1], face[2]), (face[2], face[0])]
is_edge_reverted = [False, False, False]
for k, edge in enumerate(edges):
if edge[0] > edge[1]:
edges[k] = (edge[1], edge[0])
is_edge_reverted[k] = True
# First create the interior points in barycentric coordinates
if n == 1:
num_new_vertices = 0
else:
bary = (
np.hstack(
[[np.full(n - i - 1, i), np.arange(1, n - i)] for i in range(1, n)]
)
/ n
)
bary = np.array([1.0 - bary[0] - bary[1], bary[1], bary[0]])
corner_verts = np.array([vertices[0][i] for i in corners])
vertices_cart = np.dot(corner_verts.T, bary).T
if face_adjust:
vertices_cart = face_adjust(face, bary, vertices_cart, corner_verts)
vertices.append(vertices_cart)
num_new_vertices = len(vertices[-1])
# translation table
num_nodes_per_triangle = (n + 1) * (n + 2) // 2
tt = np.empty(num_nodes_per_triangle, dtype=int)
# first the corners
tt[0] = corner_nodes[corners[0]]
tt[n] = corner_nodes[corners[1]]
tt[num_nodes_per_triangle - 1] = corner_nodes[corners[2]]
# then the edges.
# edge 0
tt[1:n] = edge_nodes[edges[0]]
if is_edge_reverted[0]:
tt[1:n] = tt[1:n][::-1]
#
# edge 1
idx = 2 * n
for k in range(n - 1):
if is_edge_reverted[1]:
tt[idx] = edge_nodes[edges[1]][n - 2 - k]
else:
tt[idx] = edge_nodes[edges[1]][k]
idx += n - k - 1
#
# edge 2
idx = n + 1
for k in range(n - 1):
if is_edge_reverted[2]:
tt[idx] = edge_nodes[edges[2]][k]
else:
tt[idx] = edge_nodes[edges[2]][n - 2 - k]
idx += n - k
# now the remaining interior nodes
idx = n + 2
j = vertex_count
for k in range(n - 2):
for _ in range(n - k - 2):
tt[idx] = j
j += 1
idx += 1
idx += 2
cells += [tt[triangle_cells]]
vertex_count += num_new_vertices
vertices = np.concatenate(vertices)
cells = np.concatenate(cells)
return vertices, cells
def insert_midpoints_edges(points, cells, cell_type):
"""Collect all unique edges, calculate and return points including
midpoints on edges as well as the extended cells array."""
number_of_points = {"triangle": 3, "tetra": 4, "quad": 4, "hexahedron": 8}
if cells.shape[1] != number_of_points[cell_type]:
raise ValueError("Mismatch of cell type and shape of cells array.")
if cell_type == "triangle":
# k-th edge between cell points no. (ij[k])
ij = [[0, 1], [1, 2], [2, 0]]
elif cell_type == "tetra":
# k-th edge between cell points no. (ij[k])
ij = [[0, 1], [1, 2], [2, 0], [3, 0], [3, 1], [3, 2]]
elif cell_type == "quad":
# k-th edge between cell points no. (ij[k])
ij = [[0, 1], [1, 2], [2, 3], [3, 0]]
elif cell_type == "hexahedron":
# k-th edge between cell points no. (ij[k])
ij = [
[0, 1],
[1, 2],
[2, 3],
[3, 0],
[4, 5],
[5, 6],
[6, 7],
[7, 4],
[0, 4],
[1, 5],
[2, 6],
[3, 7],
]
else:
raise TypeError("Cell type not implemented.")
# obtain edges from cells (contains duplicates)
edges = cells[:, ij]
# sort points of edges
edges_sorted = np.sort(edges.reshape(-1, 2), axis=1)
# obtain unique edges and inverse mapping
edges_unique, inverse = np.unique(
edges_sorted,
return_index=False,
return_inverse=True,
return_counts=False,
axis=0,
)
# calculate midpoints on edges as mean of edge-based pairs of points
midpoints_on_edges = np.mean(points[edges_unique.T], axis=0)
# create the additional cells array
# add offset to point index for midpoints on edges
cells_edges = inverse.reshape(len(cells), -1) + len(points)
# vertical stack of points and horizontal stack of edges
points_new = np.vstack((points, midpoints_on_edges))
cells_new = np.hstack((cells, cells_edges))
return points_new, cells_new
meshzoo-0.9.2/src/meshzoo/_moebius.py 0000664 0000000 0000000 00000010045 14157137534 0017647 0 ustar 00root root 0000000 0000000 import numpy as np
def moebius(
num_twists: int = 1, # How many twists are there in the 'paper'?
nl: int = 60, # Number of nodes along the length of the strip
nw: int = 11, # Number of nodes along the width of the strip (>= 2)
variant: str = "classical",
):
"""Creates a simplistic triangular mesh on a slightly Möbius strip. The
Möbius strip here deviates slightly from the ordinary geometry in that it
is constructed in such a way that the two halves can be exchanged as to
allow better comparison with the pseudo-Möbius geometry.
The variant is either `'classical'` or `'smooth'`. The first is the classical
Möbius band parametrization, the latter a smoothed variant matching
`'pseudo'`.
"""
# The width of the strip
width = 1.0
scale = 10.0
# radius of the strip when flattened out
r = 1.0
# seam displacement
alpha0 = 0.0 # pi / 2
# How flat the strip will be.
# Positive values result in left-turning Möbius strips, negative in
# right-turning ones.
# Also influences the width of the strip.
flatness = 1.0
# Generate suitable ranges for parametrization
u_range = np.linspace(0.0, 2 * np.pi, num=nl, endpoint=False)
v_range = np.linspace(-0.5 * width, 0.5 * width, num=nw)
# Create the vertices. This is based on the parameterization
# of the Möbius strip as given in
#
sin_u = np.sin(u_range)
cos_u = np.cos(u_range)
alpha = num_twists * 0.5 * u_range + alpha0
sin_alpha = np.sin(alpha)
cos_alpha = np.cos(alpha)
if variant == "classical":
a = cos_alpha
b = sin_alpha
reverse_seam = num_twists % 2 == 1
elif variant == "smooth":
# The fundamental difference with the ordinary Möbius band here are the
# squares.
# It is also possible to to abs() the respective sines and cosines, but
# this results in a non-smooth manifold.
a = np.copysign(cos_alpha ** 2, cos_alpha)
b = np.copysign(sin_alpha ** 2, sin_alpha)
reverse_seam = num_twists % 2 == 1
else:
assert variant == "pseudo"
a = cos_alpha ** 2
b = sin_alpha ** 2
reverse_seam = False
nodes = (
scale
* np.array(
[
np.outer(a * cos_u, v_range) + r * cos_u[:, np.newaxis],
np.outer(a * sin_u, v_range) + r * sin_u[:, np.newaxis],
np.outer(b, v_range) * flatness,
]
)
.reshape(3, -1)
.T
)
cells = _create_elements(nl, nw, reverse_seam)
return nodes, cells
def _create_elements(nl, nw, reverse_seam):
cells = []
for i in range(nl - 1):
for j in range(nw - 1):
if (i + j) % 2 == 0:
cells.append([i * nw + j, (i + 1) * nw + j + 1, i * nw + j + 1])
cells.append([i * nw + j, (i + 1) * nw + j, (i + 1) * nw + j + 1])
else:
cells.append([i * nw + j, i * nw + j + 1, (i + 1) * nw + j])
cells.append([i * nw + j + 1, (i + 1) * nw + j, (i + 1) * nw + j + 1])
# close the geometry
i = nl - 1
if reverse_seam:
# Close the geometry upside down (odd Möbius fold)
for j in range(nw - 1):
if (i + j) % 2 == 0:
cells.append([i * nw + j, (nw - 1) - (j + 1), i * nw + j + 1])
cells.append([i * nw + j, (nw - 1) - j, (nw - 1) - (j + 1)])
else:
cells.append([i * nw + j, i * nw + j + 1, (nw - 1) - j])
cells.append([i * nw + j + 1, (nw - 1) - j, (nw - 1) - (j + 1)])
else:
# Close the geometry upside up (even Möbius fold)
for j in range(nw - 1):
if (i + j) % 2 == 0:
cells.append([i * nw + j, j + 1, i * nw + j + 1])
cells.append([i * nw + j, j, j + 1])
else:
cells.append([i * nw + j, i * nw + j + 1, j])
cells.append([i * nw + j + 1, j, j + 1])
return np.array(cells)
meshzoo-0.9.2/src/meshzoo/_ngon.py 0000664 0000000 0000000 00000000653 14157137534 0017151 0 ustar 00root root 0000000 0000000 import numpy as np
from ._helpers import _compose_from_faces
def ngon(p: int, n: int, offset: float = np.pi / 2):
x = np.linspace(offset, offset + 2 * np.pi, p, endpoint=False)
corners = np.vstack(
[
[[0.0, 0.0]],
np.array([np.cos(x), np.sin(x)]).T,
]
)
faces = [(0, k + 1, k + 2) for k in range(p - 1)] + [(0, p, 1)]
return _compose_from_faces(corners, faces, n)
meshzoo-0.9.2/src/meshzoo/_rectangle.py 0000664 0000000 0000000 00000012114 14157137534 0020147 0 ustar 00root root 0000000 0000000 from __future__ import annotations
import numpy as np
from numpy.typing import ArrayLike
# backwards compatibility
def rectangle(
x0: float,
x1: float,
y0: float,
y1: float,
nx: int,
ny: int,
):
x_range = np.linspace(x0, x1, nx + 1)
y_range = np.linspace(y0, y1, ny + 1)
return rectangle_tri(x_range, y_range)
def rectangle_quad(x_range: ArrayLike, y_range: ArrayLike, cell_type: str = "quad4"):
x_range = np.asarray(x_range)
y_range = np.asarray(y_range)
nx = len(x_range)
ny = len(y_range)
if cell_type == "quad4":
points = np.array(np.meshgrid(x_range, y_range)).reshape(2, -1).T
a = np.arange(nx * ny).reshape(ny, nx).T
cells = (
np.array([a[:-1, :-1], a[1:, :-1], a[1:, 1:], a[:-1, 1:]]).reshape(4, -1).T
)
elif cell_type == "quad8":
k = 0
points_corner = np.array(np.meshgrid(x_range, y_range)).reshape(2, -1).T
a_corner = np.arange(nx * ny).reshape(ny, nx).T
k += a_corner.size
x_mid = (x_range[:-1] + x_range[1:]) / 2
points_xmid = np.array(np.meshgrid(x_mid, y_range)).reshape(2, -1).T
a_xmid = k + np.arange((nx - 1) * ny).reshape(ny, nx - 1).T
k += a_xmid.size
y_mid = (y_range[:-1] + y_range[1:]) / 2
points_ymid = np.array(np.meshgrid(x_range, y_mid)).reshape(2, -1).T
a_ymid = k + np.arange(nx * (ny - 1)).reshape(ny - 1, nx).T
points = np.row_stack([points_corner, points_xmid, points_ymid])
cells = (
np.array(
[
a_corner[:-1, :-1],
a_corner[1:, :-1],
a_corner[1:, 1:],
a_corner[:-1, 1:],
a_xmid[:, :-1],
a_ymid[1:, :],
a_xmid[:, 1:],
a_ymid[:-1, :],
]
)
.reshape(8, -1)
.T
)
else:
assert cell_type == "quad9"
k = 0
points_corner = np.array(np.meshgrid(x_range, y_range)).reshape(2, -1).T
a_corner = np.arange(nx * ny).reshape(ny, nx).T
k += a_corner.size
x_mid = (x_range[:-1] + x_range[1:]) / 2
points_xmid = np.array(np.meshgrid(x_mid, y_range)).reshape(2, -1).T
a_xmid = k + np.arange((nx - 1) * ny).reshape(ny, nx - 1).T
k += a_xmid.size
y_mid = (y_range[:-1] + y_range[1:]) / 2
points_ymid = np.array(np.meshgrid(x_range, y_mid)).reshape(2, -1).T
a_ymid = k + np.arange(nx * (ny - 1)).reshape(ny - 1, nx).T
k += a_ymid.size
points_center = np.array(np.meshgrid(x_mid, y_mid)).reshape(2, -1).T
a_center = k + np.arange((nx - 1) * (ny - 1)).reshape(ny - 1, nx - 1).T
points = np.row_stack([points_corner, points_xmid, points_ymid, points_center])
cells = (
np.array(
[
a_corner[:-1, :-1],
a_corner[1:, :-1],
a_corner[1:, 1:],
a_corner[:-1, 1:],
a_xmid[:, :-1],
a_ymid[1:, :],
a_xmid[:, 1:],
a_ymid[:-1, :],
a_center,
]
)
.reshape(9, -1)
.T
)
return points, cells
def rectangle_tri(x_range: ArrayLike, y_range: ArrayLike, variant: str = "zigzag"):
x_range = np.asarray(x_range)
y_range = np.asarray(y_range)
nx = len(x_range)
ny = len(y_range)
# Create the vertices.
points = np.array(np.meshgrid(x_range, y_range)).reshape(2, -1).T
a = np.arange(nx * ny).reshape(ny, nx).T
# indices of corners
#
# c[3] c[2]
# _____
# | |
# |___|
#
# c[0] c[1]
#
c = [
a[:-1, :-1],
a[1:, :-1],
a[1:, 1:],
a[:-1, 1:],
]
if variant == "up":
cells = [
[c[0], c[1], c[2]],
[c[0], c[2], c[3]],
]
elif variant == "down":
cells = [
[c[0], c[1], c[3]],
[c[1], c[2], c[3]],
]
elif variant == "zigzag":
# https://stackoverflow.com/a/68550456/353337
idx = np.ones((nx - 1, ny - 1), dtype=bool)
idx[1::2, ::2] = False
idx[::2, 1::2] = False
cells = [
# up
[c[0][idx], c[1][idx], c[2][idx]],
[c[0][idx], c[2][idx], c[3][idx]],
# down
[c[0][~idx], c[1][~idx], c[3][~idx]],
[c[1][~idx], c[2][~idx], c[3][~idx]],
]
else:
assert variant == "center"
idx = np.ones(((nx - 1), (ny - 1)), dtype=bool)
idx[: (nx - 1) // 2, : (ny - 1) // 2] = False
idx[(nx - 1) // 2 :, (ny - 1) // 2 :] = False
cells = [
# up
[c[0][idx], c[1][idx], c[2][idx]],
[c[0][idx], c[2][idx], c[3][idx]],
# down
[c[0][~idx], c[1][~idx], c[3][~idx]],
[c[1][~idx], c[2][~idx], c[3][~idx]],
]
cells = np.column_stack([np.array(c).reshape(3, -1) for c in cells]).T
return points, cells
meshzoo-0.9.2/src/meshzoo/_sphere.py 0000664 0000000 0000000 00000015674 14157137534 0017507 0 ustar 00root root 0000000 0000000 import numpy as np
from ._helpers import _compose_from_faces
def uv_sphere(num_points_per_circle: int, num_circles: int, radius: float = 1.0):
# Mesh parameters
n_phi = num_points_per_circle
n_theta = num_circles
# Generate suitable ranges for parametrization
phi_range = np.linspace(0.0, 2 * np.pi, num=n_phi, endpoint=False)
theta_range = np.linspace(
-np.pi / 2 + np.pi / (n_theta - 1),
np.pi / 2 - np.pi / (n_theta - 1),
num=n_theta - 2,
)
# nodes in the circles of latitude (except poles)
nodes = radius * np.array(
[[0.0, 0.0, -1.0]] # south pole
+ [
[
np.cos(theta) * np.sin(phi),
np.cos(theta) * np.cos(phi),
np.sin(theta),
]
for theta in theta_range
for phi in phi_range
]
+ [[0.0, 0.0, 1.0]] # north pole
)
south_pole_index = 0
north_pole_index = len(nodes) - 1
# create the elements (cells)
num_cells = 2 * (n_theta - 2) * n_phi
cells = []
# connections to south pole
for i in range(n_phi - 1):
cells.append([south_pole_index, i + 1, i + 2])
# close geometry
cells.append([south_pole_index, n_phi, 1])
# non-pole elements
for i in range(n_theta - 3):
for j in range(n_phi - 1):
cells += [
[i * n_phi + j + 2, i * n_phi + j + 1, (i + 1) * n_phi + j + 2],
[i * n_phi + j + 1, (i + 1) * n_phi + j + 1, (i + 1) * n_phi + j + 2],
]
# close the geometry
for i in range(n_theta - 3):
cells += [
[i * n_phi + 1, (i + 1) * n_phi, (i + 1) * n_phi + 1],
[(i + 1) * n_phi + 1, (i + 1) * n_phi, (i + 2) * n_phi],
]
# connections to the north pole
for i in range(n_phi - 1):
cells.append(
[
i + 1 + n_phi * (n_theta - 3) + 1,
i + n_phi * (n_theta - 3) + 1,
north_pole_index,
]
)
# close geometry
cells.append(
[
0 + n_phi * (n_theta - 3) + 1,
n_phi - 1 + n_phi * (n_theta - 3) + 1,
north_pole_index,
]
)
cells = np.array(cells)
assert len(cells) == num_cells, "Wrong element count."
return nodes, cells
def geo_sphere(num_points_per_circle: int, num_circles: int, radius=1.0):
# Mesh parameters
n_phi = num_points_per_circle
n_theta = num_circles
# Generate suitable ranges for parametrization
phi_range = np.linspace(0.0, 2 * np.pi, num=n_phi, endpoint=False)
theta_range = np.linspace(
-np.pi / 2 + np.pi / (n_theta - 1),
np.pi / 2 - np.pi / (n_theta - 1),
num=n_theta - 2,
)
# nodes in the circles of latitude (except poles)
nodes = radius * np.array(
[[0.0, 0.0, -1.0]] # south pole
+ [
[
np.cos(theta) * np.sin(phi),
np.cos(theta) * np.cos(phi),
np.sin(theta),
]
for theta in theta_range
for phi in phi_range
]
+ [[0.0, 0.0, 1.0]] # north pole
)
south_pole_index = 0
north_pole_index = len(nodes) - 1
# create the elements (cells)
tri = []
quad = []
# connections to south pole
for i in range(n_phi - 1):
tri.append([south_pole_index, i + 1, i + 2])
# close geometry
tri.append([south_pole_index, n_phi, 1])
# non-pole elements
for i in range(n_theta - 3):
for j in range(n_phi - 1):
quad += [
[
i * n_phi + j + 1,
i * n_phi + j + 2,
(i + 1) * n_phi + j + 2,
(i + 1) * n_phi + j + 1,
],
]
# close the geometry
for i in range(n_theta - 3):
quad += [
[i * n_phi + 1, (i + 1) * n_phi + 1, (i + 2) * n_phi, (i + 1) * n_phi],
]
# connections to the north pole
for i in range(n_phi - 1):
tri.append(
[
i + 1 + n_phi * (n_theta - 3) + 1,
i + n_phi * (n_theta - 3) + 1,
north_pole_index,
]
)
# close geometry
tri.append(
[
0 + n_phi * (n_theta - 3) + 1,
n_phi - 1 + n_phi * (n_theta - 3) + 1,
north_pole_index,
]
)
tri = np.array(tri)
quad = np.array(quad)
return nodes, tri, quad
def tetra_sphere(n):
corners = np.array(
[
[2 * np.sqrt(2) / 3, 0.0, -1.0 / 3.0],
[-np.sqrt(2) / 3, np.sqrt(2.0 / 3.0), -1.0 / 3.0],
[-np.sqrt(2) / 3, -np.sqrt(2.0 / 3.0), -1.0 / 3.0],
[0.0, 0.0, 1.0],
]
)
# make sure the normals are pointing outwards
faces = [(0, 2, 1), (0, 1, 3), (0, 3, 2), (1, 2, 3)]
vertices, cells = _compose_from_faces(corners, faces, n)
# push all nodes to the sphere
norms = np.sqrt(np.einsum("ij,ij->i", vertices, vertices))
vertices = (vertices.T / norms).T
return vertices, cells
def octa_sphere(n: int):
corners = np.array(
[
[1.0, 0.0, 0.0],
[-1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, -1.0, 0.0],
[0.0, 0.0, 1.0],
[0.0, 0.0, -1.0],
]
)
faces = [
(0, 2, 4),
(1, 4, 2),
(1, 3, 4),
(0, 4, 3),
(0, 5, 2),
(1, 2, 5),
(1, 5, 3),
(0, 3, 5),
]
vertices, cells = _compose_from_faces(corners, faces, n)
# push all nodes to the sphere
norms = np.sqrt(np.einsum("ij,ij->i", vertices, vertices))
vertices = (vertices.T / norms).T
return vertices, cells
def icosa_sphere(n: int):
assert n >= 1
# Start off with an isosahedron and refine.
# Construction from
# .
# Create 12 vertices of a icosahedron.
t = (1.0 + np.sqrt(5.0)) / 2.0
corners = np.array(
[
[-1, +t, +0],
[+1, +t, +0],
[-1, -t, +0],
[+1, -t, +0],
#
[+0, -1, +t],
[+0, +1, +t],
[+0, -1, -t],
[+0, +1, -t],
#
[+t, +0, -1],
[+t, +0, +1],
[-t, +0, -1],
[-t, +0, +1],
]
)
faces = [
(0, 11, 5),
(0, 5, 1),
(0, 1, 7),
(0, 7, 10),
(0, 10, 11),
(1, 5, 9),
(5, 11, 4),
(11, 10, 2),
(10, 7, 6),
(7, 1, 8),
(3, 9, 4),
(3, 4, 2),
(3, 2, 6),
(3, 6, 8),
(3, 8, 9),
(4, 9, 5),
(2, 4, 11),
(6, 2, 10),
(8, 6, 7),
(9, 8, 1),
]
vertices, cells = _compose_from_faces(corners, faces, n)
# push all nodes to the sphere
norms = np.sqrt(np.einsum("ij,ij->i", vertices, vertices))
vertices = (vertices.T / norms).T
return vertices, cells
meshzoo-0.9.2/src/meshzoo/_triangle.py 0000664 0000000 0000000 00000001602 14157137534 0020010 0 ustar 00root root 0000000 0000000 import numpy as np
def triangle(n: int):
# Create the mesh in barycentric coordinates
bary = np.hstack(
[
[
np.full(n - i + 1, i / n),
# np.arange(n - i + 1) / n:
np.linspace(0.0, (n - i + 1) / n, n - i + 1, endpoint=False),
]
for i in range(n + 1)
]
)
bary = np.array([1.0 - bary[0] - bary[1], bary[1], bary[0]])
# Some applications don't accept values like -1.4125e-16.
bary[bary < 0.0] = 0.0
bary[bary > 1.0] = 1.0
cells = []
k = 0
for i in range(n):
j = np.arange(n - i)
cells.append(np.column_stack([k + j, k + j + 1, k + n - i + j + 1]))
#
j = j[:-1]
cells.append(np.column_stack([k + j + 1, k + n - i + j + 2, k + n - i + j + 1]))
k += n - i + 1
cells = np.vstack(cells)
return bary, cells
meshzoo-0.9.2/src/meshzoo/_tube.py 0000664 0000000 0000000 00000002324 14157137534 0017144 0 ustar 00root root 0000000 0000000 import numpy as np
def tube(length: float = 1.0, radius: float = 1.0, n: int = 30):
# Number of points along the width of the strip (>= 2)
# Choose it such that we have approximately square boxes.
nw = int(round(length * n / (2 * np.pi * radius)))
# Generate suitable ranges for parametrization
u_range = np.linspace(0.0, 2 * np.pi, num=n, endpoint=False)
v_range = np.linspace(-0.5 * length, 0.5 * length, num=nw)
# Create the vertices.
proto_points = np.dstack(np.meshgrid(u_range, v_range, indexing="ij")).reshape(
-1, 2
)
points = np.column_stack(
[
radius * np.cos(proto_points[:, 0]),
radius * np.sin(proto_points[:, 0]),
proto_points[:, 1],
]
)
# create the elements (cells)
cells = []
for i in range(n - 1):
for j in range(nw - 1):
cells.append([i * nw + j, (i + 1) * nw + j + 1, i * nw + j + 1])
cells.append([i * nw + j, (i + 1) * nw + j, (i + 1) * nw + j + 1])
# close the geometry
for j in range(nw - 1):
cells.append([(n - 1) * nw + j, j + 1, (n - 1) * nw + j + 1])
cells.append([(n - 1) * nw + j, j, j + 1])
return points, np.array(cells)
meshzoo-0.9.2/tests/ 0000775 0000000 0000000 00000000000 14157137534 0014362 5 ustar 00root root 0000000 0000000 meshzoo-0.9.2/tests/__init__.py 0000664 0000000 0000000 00000000000 14157137534 0016461 0 ustar 00root root 0000000 0000000 meshzoo-0.9.2/tests/helpers.py 0000664 0000000 0000000 00000001537 14157137534 0016404 0 ustar 00root root 0000000 0000000 import math
import numpy as np
def is_near_equal(a, b, tol=1.0e-12):
return np.allclose(a, b, rtol=0.0, atol=tol)
def signed_simplex_volumes(coords, cells):
assert len(coords.shape) == 2
assert len(cells.shape) == 2
assert (
coords.shape[1] + 1 == cells.shape[1]
), "Signed areas only make sense for n-simplices in in nD."
# bc = coords[:, cells]
# return np.cross((bc[:, :, 1] - bc[:, :, 0]).T, (bc[:, :, 2] - bc[:, :, 0]).T)
# https://en.wikipedia.org/wiki/Simplex#Volume
cp = coords[cells]
n = coords.shape[1]
# append ones; this appends a column instead of a row as suggested by
# wikipedia, but that doesn't change the determinant
cp1 = np.concatenate([cp, np.ones(cp.shape[:-1] + (1,))], axis=-1)
sign = -1 if n % 2 == 1 else 1
return sign * np.linalg.det(cp1) / math.factorial(n)
meshzoo-0.9.2/tests/test_ball.py 0000664 0000000 0000000 00000001170 14157137534 0016704 0 ustar 00root root 0000000 0000000 import meshzoo
from .helpers import signed_simplex_volumes
def test_ball_hexa():
points, cells = meshzoo.ball_hexa(10)
# import meshio
# meshio.Mesh(points, {"hexahedron": cells}).write("ball-hexa.vtk")
assert len(points) == 1331
assert len(cells) == 1000
def test_ball_tetra():
points, cells = meshzoo.ball_tetra(10)
# import meshio
# meshio.Mesh(points, {"tetra": cells}).write("ball-tetra.vtk")
assert len(points) == 1331
assert len(cells) == 5000
def test_positive_volumes():
points, cells = meshzoo.ball_tetra(2)
assert (signed_simplex_volumes(points, cells) > 0.0).all()
meshzoo-0.9.2/tests/test_cube.py 0000664 0000000 0000000 00000006226 14157137534 0016717 0 ustar 00root root 0000000 0000000 import numpy as np
import meshzoo
from .helpers import signed_simplex_volumes
def test_positive_volumes():
x_range = np.linspace(0.0, 1.0, 5)
y_range = np.linspace(0.0, 1.0, 5)
z_range = np.linspace(0.0, 1.0, 5)
points, cells = meshzoo.cube_tetra(x_range, y_range, z_range)
assert np.all(signed_simplex_volumes(points, cells) > 0.0)
def test_cube_tetra():
x_range = np.linspace(0.0, 1.0, 11)
y_range = np.linspace(0.0, 1.0, 11)
z_range = np.linspace(0.0, 1.0, 11)
points, cells = meshzoo.cube_tetra(x_range, y_range, z_range)
assert len(points) == 1331
assert len(cells) == 5000
def test_cube_tetra2():
x_range = np.linspace(0.0, 1.0, 3)
y_range = np.linspace(0.0, 1.0, 3)
z_range = np.linspace(0.0, 1.0, 3)
points, cells = meshzoo.cube_tetra(x_range, y_range, z_range)
assert len(points) == 27
assert all(np.sum(points, axis=0) == [13.5, 13.5, 13.5])
assert len(cells) == 40
def test_cube_tetra3():
x_range = [0.0, 1.0]
y_range = [0.0, 0.5, 1.0]
z_range = [0.0, 0.3, 0.7, 1.0]
points, cells = meshzoo.cube_tetra(x_range, y_range, z_range)
assert len(points) == 24
assert all(np.sum(points, axis=0) == [12.0, 12.0, 12.0])
assert cells.tolist() == [
[0, 1, 2, 6],
[12, 13, 14, 18],
[8, 9, 10, 14],
[1, 3, 2, 9],
[13, 15, 14, 21],
[9, 11, 10, 17],
[1, 2, 6, 9],
[13, 14, 18, 21],
[9, 10, 14, 17],
[1, 6, 7, 9],
[13, 18, 19, 21],
[9, 14, 15, 17],
[2, 6, 9, 8],
[14, 18, 21, 20],
[10, 14, 17, 16],
[12, 13, 6, 14],
[8, 9, 2, 10],
[20, 21, 14, 22],
[13, 15, 9, 14],
[9, 11, 5, 10],
[21, 23, 17, 22],
[13, 14, 9, 6],
[9, 10, 5, 2],
[21, 22, 17, 14],
[13, 6, 9, 7],
[9, 2, 5, 3],
[21, 14, 17, 15],
[14, 6, 8, 9],
[10, 2, 4, 5],
[22, 14, 16, 17],
]
def test_cube_hexa():
x_range = np.linspace(0.0, 1.0, 11)
y_range = np.linspace(0.0, 1.0, 11)
z_range = np.linspace(0.0, 1.0, 11)
points, cells = meshzoo.cube_hexa(x_range, y_range, z_range)
assert len(points) == 1331
assert len(cells) == 1000
# import meshio
# meshio.Mesh(points, {"hexahedron": cells}).write("cube-hexa.vtk")
def test_cube_hexa2():
x_range = np.linspace(0.0, 1.0, 3)
y_range = np.linspace(0.0, 1.0, 3)
z_range = np.linspace(0.0, 1.0, 3)
points, cells = meshzoo.cube_hexa(x_range, y_range, z_range)
assert len(points) == 27
assert all(np.sum(points, axis=0) == [13.5, 13.5, 13.5])
assert len(cells) == 8
def test_cube_hexa3():
x_range = [0.0, 1.0]
y_range = [0.0, 0.5, 1.0]
z_range = [0.0, 0.3, 0.7, 1.0]
points, cells = meshzoo.cube_hexa(x_range, y_range, z_range)
assert len(points) == 24
assert all(np.sum(points, axis=0) == [12.0, 12.0, 12.0])
assert cells.tolist() == [
[0, 1, 3, 2, 6, 7, 9, 8],
[6, 7, 9, 8, 12, 13, 15, 14],
[12, 13, 15, 14, 18, 19, 21, 20],
[2, 3, 5, 4, 8, 9, 11, 10],
[8, 9, 11, 10, 14, 15, 17, 16],
[14, 15, 17, 16, 20, 21, 23, 22],
]
meshzoo-0.9.2/tests/test_disk.py 0000664 0000000 0000000 00000000725 14157137534 0016731 0 ustar 00root root 0000000 0000000 import meshzoo
from .helpers import signed_simplex_volumes
def test_disk():
points, cells = meshzoo.disk(9, 8)
meshzoo.save2d("4gon_disk.svg", points, cells)
assert len(points) == 325
assert len(cells) == 576
assert (signed_simplex_volumes(points, cells) > 0.0).all()
def test_disk_quad():
points, cells = meshzoo.disk_quad(10)
# meshzoo.save2d("disk-quad.svg", points, cells)
assert len(points) == 121
assert len(cells) == 100
meshzoo-0.9.2/tests/test_midpointsedges.py 0000664 0000000 0000000 00000003203 14157137534 0021007 0 ustar 00root root 0000000 0000000 import numpy as np
import meshzoo
def test_midpoints_edges_tri():
points, cells = meshzoo.rectangle_tri(
np.linspace(0.0, 1.0, 2), np.linspace(0.0, 1.0, 2)
)
assert len(points) == 4
assert cells.shape == (2, 3)
points_new, cells_new = meshzoo.insert_midpoints_edges(
points, cells, cell_type="triangle"
)
assert len(points_new) == 9
assert cells_new.shape == (2, 6)
def test_midpoints_edges_tetra():
ls = np.linspace(0.0, 1.0, 2)
points, cells = meshzoo.cube_tetra(ls, ls, ls)
assert len(points) == 8
assert cells.shape == (5, 4)
points_new, cells_new = meshzoo.insert_midpoints_edges(
points, cells, cell_type="tetra"
)
assert len(points_new) == 26
assert cells_new.shape == (5, 10)
def test_midpoints_edges_quad():
ls = np.linspace(0.0, 1.0, 3)
points, cells = meshzoo.rectangle_quad(ls, ls)
assert len(points) == 9
assert cells.shape == (4, 4)
points_new, cells_new = meshzoo.insert_midpoints_edges(
points, cells, cell_type="quad"
)
assert len(points_new) == 21
assert cells_new.shape == (4, 8)
def test_midpoints_edges_hexa():
ls = np.linspace(0.0, 1.0, 3)
points, cells = meshzoo.cube_hexa(ls, ls, ls)
assert len(points) == 27
assert cells.shape == (8, 8)
points_new, cells_new = meshzoo.insert_midpoints_edges(
points, cells, cell_type="hexahedron"
)
assert len(points_new) == 81
assert cells_new.shape == (8, 20)
if __name__ == "__main__":
test_midpoints_edges_tri()
test_midpoints_edges_tetra()
test_midpoints_edges_quad()
test_midpoints_edges_hexa()
meshzoo-0.9.2/tests/test_moebius.py 0000664 0000000 0000000 00000005120 14157137534 0017434 0 ustar 00root root 0000000 0000000 import numpy as np
import pytest
import meshzoo
from .helpers import is_near_equal
@pytest.mark.parametrize(
"num_twists, num_points, num_cells, ref1, ref2",
[
[1, 5890, 11400, [0, 0, 0], [2753575 / 9.0, 2724125 / 9.0, 58900 / 3.0]],
[2, 5890, 11400, [0, 0, 0], [2797750 / 9.0, 2679950 / 9.0, 58900 / 3.0]],
],
)
def test_moebius(num_twists, num_points, num_cells, ref1, ref2):
points, cells = meshzoo.moebius(num_twists, 190, 31, variant="smooth")
assert len(points) == num_points
assert len(cells) == num_cells
assert is_near_equal(np.sum(points, axis=0), ref1, tol=1.0e-10)
sum_points2 = np.sum(points ** 2, axis=0)
assert np.allclose(sum_points2, ref2, rtol=1.0e-12, atol=0.0)
@pytest.mark.parametrize(
"num_twists, num_points, num_cells, ref1, ref2",
[
[
1,
5700,
11020,
[0, 0, 0],
[[296107.21982759, 292933.72844828, 19040.94827586]],
],
[
2,
5700,
11020,
[0, 0, 0],
[[300867.45689655, 288173.49137931, 19040.94827586]],
],
],
)
def test_moebius2(num_twists, num_points, num_cells, ref1, ref2):
points, cells = meshzoo.moebius(
nl=190, nw=30, num_twists=num_twists, variant="smooth"
)
assert len(points) == num_points
assert len(cells) == num_cells
assert is_near_equal(np.sum(points, axis=0), ref1, tol=1.0e-10)
sum_points2 = np.sum(points ** 2, axis=0)
assert np.allclose(sum_points2, ref2, rtol=1.0e-12, atol=0.0)
@pytest.mark.parametrize(
"num_twists, num_points, num_cells, ref1, ref2",
[
[1, 1000, 1800, [0, 0, 0], [1418750 / 27.0, 1418750 / 27.0, 137500 / 27.0]],
[2, 1000, 1800, [0, 0, 0], [484375 / 9.0, 1384375 / 27.0, 137500 / 27.0]],
],
)
def test_moebius3(num_twists, num_points, num_cells, ref1, ref2):
points, cells = meshzoo.moebius(num_twists, 100, 10, variant="classical")
assert len(points) == num_points
assert len(cells) == num_cells
assert is_near_equal(np.sum(points, axis=0), ref1, tol=1.0e-10)
sum_points2 = np.sum(points ** 2, axis=0)
assert np.allclose(sum_points2, ref2, rtol=1.0e-12, atol=0.0)
def test_pseudomoebius():
points, cells = meshzoo.moebius(nl=190, nw=31, variant="pseudo")
assert len(points) == 5890
assert len(cells) == 11400
assert is_near_equal(np.sum(points, axis=0), [0, 0, 0], tol=1.0e-10)
sum_points2 = np.sum(points ** 2, axis=0)
ref2 = [2753575 / 9.0, 2724125 / 9.0, 58900 / 3.0]
assert np.allclose(sum_points2, ref2, rtol=1.0e-12, atol=0.0)
meshzoo-0.9.2/tests/test_ngon.py 0000664 0000000 0000000 00000000541 14157137534 0016734 0 ustar 00root root 0000000 0000000 import numpy as np
import meshzoo
from .helpers import signed_simplex_volumes
def test_ngon():
points, cells = meshzoo.ngon(9, 8)
# meshzoo.save2d("9gon.svg", points, cells)
assert len(points) == 325
assert len(cells) == 576
assert np.all(signed_simplex_volumes(points, cells) > 0.0)
if __name__ == "__main__":
test_ngon()
meshzoo-0.9.2/tests/test_rectangle.py 0000664 0000000 0000000 00000010632 14157137534 0017741 0 ustar 00root root 0000000 0000000 import numpy as np
import meshzoo
from .helpers import is_near_equal, signed_simplex_volumes
def test_up():
x_range = np.linspace(0.0, 1.0, 11)
y_range = np.linspace(0.0, 1.0, 11)
points, cells = meshzoo.rectangle_tri(x_range, y_range, variant="up")
assert len(points) == 121
assert is_near_equal(np.sum(points, axis=0), [60.5, 60.5])
assert len(cells) == 200
assert np.all(signed_simplex_volumes(points, cells) > 0.0)
def test_up2():
x_range = np.linspace(0.0, 1.0, 3)
y_range = np.linspace(0.0, 1.0, 2)
points, cells = meshzoo.rectangle_tri(x_range, y_range, variant="up")
assert len(points) == 6
assert is_near_equal(np.sum(points, axis=0), [3.0, 3.0])
assert len(cells) == 4
assert list(cells[0]) == [0, 1, 4]
assert list(cells[2]) == [0, 4, 3]
assert np.all(signed_simplex_volumes(points, cells) > 0.0)
def test_zigzag():
x_range = np.linspace(0.0, 1.0, 11)
y_range = np.linspace(0.0, 1.0, 11)
points, cells = meshzoo.rectangle_tri(x_range, y_range, variant="zigzag")
assert len(points) == 121
assert is_near_equal(np.sum(points, axis=0), [60.5, 60.5])
assert len(cells) == 200
assert np.all(signed_simplex_volumes(points, cells) > 0.0)
def test_zigzag2():
x_range = np.linspace(0.0, 1.0, 2)
y_range = np.linspace(0.0, 1.0, 2)
points, cells = meshzoo.rectangle_tri(x_range, y_range, variant="zigzag")
assert len(points) == 4
assert is_near_equal(np.sum(points, axis=0), [2.0, 2.0])
assert len(cells) == 2
assert np.all(signed_simplex_volumes(points, cells) > 0.0)
def test_zigzag3():
x_range = np.linspace(0.0, 1.0, 3)
y_range = np.linspace(0.0, 1.0, 2)
points, cells = meshzoo.rectangle_tri(x_range, y_range, variant="zigzag")
assert len(points) == 6
assert is_near_equal(np.sum(points, axis=0), [3.0, 3.0])
assert len(cells) == 4
assert list(cells[0]) == [0, 1, 4]
assert list(cells[2]) == [1, 2, 4]
assert np.all(signed_simplex_volumes(points, cells) > 0.0)
def test_down():
x_range = np.linspace(0.0, 1.0, 5)
y_range = np.linspace(0.0, 1.0, 4)
points, cells = meshzoo.rectangle_tri(x_range, y_range, variant="down")
assert len(points) == 20
assert len(cells) == 24
assert np.all(signed_simplex_volumes(points, cells) > 0.0)
# meshzoo.show2d(points, cells)
def test_center():
x_range = np.linspace(0.0, 1.0, 11)
y_range = np.linspace(0.0, 1.0, 9)
points, cells = meshzoo.rectangle_tri(x_range, y_range, variant="center")
meshzoo.show2d(points, cells)
assert len(points) == 99
assert len(cells) == 160
assert np.all(signed_simplex_volumes(points, cells) > 0.0)
def test_quad1():
x_range = np.linspace(0.0, 1.0, 11)
y_range = np.linspace(0.0, 1.0, 11)
points, cells = meshzoo.rectangle_quad(x_range, y_range)
assert len(points) == 121
assert is_near_equal(np.sum(points, axis=0), [60.5, 60.5])
assert len(cells) == 100
# meshzoo.save2d("rectangle-quad.svg", points, cells)
def test_quad2():
x_range = np.linspace(0.0, 1.0, 3)
y_range = np.linspace(0.0, 1.0, 2)
points, cells = meshzoo.rectangle_quad(x_range, y_range)
assert len(points) == 6
assert is_near_equal(np.sum(points, axis=0), [3.0, 3.0])
assert np.all(cells == [[0, 1, 4, 3], [1, 2, 5, 4]])
def test_quad3():
x_range = np.linspace(0.0, 1.0, 3)
y_range = np.linspace(0.0, 1.0, 3)
points, cells = meshzoo.rectangle_quad(x_range, y_range)
assert len(points) == 9
assert np.all(cells == [[0, 1, 4, 3], [3, 4, 7, 6], [1, 2, 5, 4], [4, 5, 8, 7]])
def test_quad8():
x_range = np.linspace(0.0, 1.0, 3)
y_range = np.linspace(0.0, 1.0, 2)
points, cells = meshzoo.rectangle_quad(x_range, y_range, cell_type="quad8")
assert len(points) == 13
print(cells.tolist())
assert np.all(cells == [[0, 1, 4, 3, 6, 11, 8, 10], [1, 2, 5, 4, 7, 12, 9, 11]])
def test_quad9():
x_range = np.linspace(0.0, 1.0, 4)
y_range = np.linspace(0.0, 1.0, 3)
points, cells = meshzoo.rectangle_quad(x_range, y_range, cell_type="quad9")
assert len(points) == 35
print(cells.tolist())
assert np.all(
cells
== [
[0, 1, 5, 4, 12, 22, 15, 21, 29],
[4, 5, 9, 8, 15, 26, 18, 25, 32],
[1, 2, 6, 5, 13, 23, 16, 22, 30],
[5, 6, 10, 9, 16, 27, 19, 26, 33],
[2, 3, 7, 6, 14, 24, 17, 23, 31],
[6, 7, 11, 10, 17, 28, 20, 27, 34],
]
)
meshzoo-0.9.2/tests/test_sphere.py 0000664 0000000 0000000 00000005166 14157137534 0017271 0 ustar 00root root 0000000 0000000 import numpy as np
import meshzoo
from .helpers import is_near_equal
def _compute_cells_normals_dir(points, cells):
pc = points[cells]
midpoints = np.sum(pc, axis=1) / 3.0
nrm = np.sqrt(np.einsum("ij,ij->i", midpoints, midpoints))
normals = (midpoints.T / nrm).T
cross = np.cross(
pc[:, 1, :] - pc[:, 0, :],
pc[:, 2, :] - pc[:, 0, :],
)
return np.einsum("ij,ij->i", normals, cross)
def test_uv_sphere(num_points_per_circle=20, num_circles=10):
points, cells = meshzoo.uv_sphere(num_points_per_circle, num_circles)
assert len(points) == 162
assert is_near_equal(np.sum(points, axis=0), [0.0, 0.0, 0.0])
assert len(cells) == 320
assert (_compute_cells_normals_dir(points, cells) > 0.0).all()
assert np.all(np.abs(np.einsum("ij,ij->i", points, points) - 1.0) < 1.0e-10)
def test_geo_sphere(num_points_per_circle=20, num_circles=10):
points, tri, quad = meshzoo.geo_sphere(num_points_per_circle, num_circles)
# import meshio
# meshio.write_points_cells("geo-sphere.vtk", points, {"triangle": tri, "quad": quad})
assert len(points) == 162
assert is_near_equal(np.sum(points, axis=0), [0.0, 0.0, 0.0])
assert len(tri) == 40
assert len(quad) == 140
# assert (_compute_cells_normals_dir(points, cells) > 0.0).all()
assert np.all(np.abs(np.einsum("ij,ij->i", points, points) - 1.0) < 1.0e-10)
def test_tetra_sphere(n=16):
points, cells = meshzoo.tetra_sphere(n)
# import meshio
# meshio.write_points_cells("out.vtk", points, {"triangle": cells})
assert len(points) == 514
assert is_near_equal(np.sum(points, axis=0), [0.0, 0.0, 0.0])
assert len(cells) == 1024
assert (_compute_cells_normals_dir(points, cells) > 0.0).all()
assert np.all(np.abs(np.einsum("ij,ij->i", points, points) - 1.0) < 1.0e-10)
def test_octa_sphere(n=16):
points, cells = meshzoo.octa_sphere(n)
assert len(points) == 1026
assert is_near_equal(np.sum(points, axis=0), [0.0, 0.0, 0.0])
assert len(cells) == 2048
assert (_compute_cells_normals_dir(points, cells) > 0.0).all()
assert np.all(np.abs(np.einsum("ij,ij->i", points, points) - 1.0) < 1.0e-10)
def test_icosa_sphere(n=16):
points, cells = meshzoo.icosa_sphere(n)
# import meshio
# meshio.write_points_cells("out.vtk", points, {"triangle": cells})
assert len(points) == 2562
assert is_near_equal(np.sum(points, axis=0), [0.0, 0.0, 0.0])
assert len(cells) == 5120
assert (_compute_cells_normals_dir(points, cells) > 0.0).all()
assert np.all(np.abs(np.einsum("ij,ij->i", points, points) - 1.0) < 1.0e-10)
if __name__ == "__main__":
test_geo_sphere()
meshzoo-0.9.2/tests/test_triangle.py 0000664 0000000 0000000 00000002413 14157137534 0017600 0 ustar 00root root 0000000 0000000 import numpy as np
import meshzoo
from .helpers import is_near_equal, signed_simplex_volumes
def _get_points(bary):
corners = np.array(
[[0.0, -0.5 * np.sqrt(3.0), +0.5 * np.sqrt(3.0)], [1.0, -0.5, -0.5]]
)
return np.dot(corners, bary).T
def test_triangle():
bary, cells = meshzoo.triangle(4)
assert len(bary.T) == 15
assert is_near_equal(np.sum(_get_points(bary), axis=0), [0.0, 0.0])
assert len(cells) == 16
# make sure the order of the nodes in each cell is counterclockwise
corner_coords = np.array([[0.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
coords = np.dot(corner_coords, bary)
assert np.all(signed_simplex_volumes(coords.T, cells) > 0.0)
def test_plot2d():
bary, cells = meshzoo.triangle(4)
meshzoo.show2d(_get_points(bary), cells)
def test_edges():
_, cells = meshzoo.triangle(2)
edges_nodes, edges_cells = meshzoo.create_edges(cells)
assert np.all(
edges_nodes
== [[0, 1], [0, 3], [1, 2], [1, 3], [1, 4], [2, 4], [3, 4], [3, 5], [4, 5]]
)
assert np.all(edges_cells == [[3, 1, 0], [5, 4, 2], [6, 3, 4], [8, 7, 6]])
if __name__ == "__main__":
points, cells = meshzoo.triangle(5000)
# import meshio
# meshio.write_points_cells('triangle.vtk', points, {'triangle': cells})
meshzoo-0.9.2/tests/test_tube.py 0000664 0000000 0000000 00000000374 14157137534 0016736 0 ustar 00root root 0000000 0000000 import numpy as np
import meshzoo
from .helpers import is_near_equal
def test_tube():
points, cells = meshzoo.tube(n=10)
assert len(points) == 20
assert is_near_equal(np.sum(points, axis=0), [0.0, 0.0, 0.0])
assert len(cells) == 20
meshzoo-0.9.2/tox.ini 0000664 0000000 0000000 00000000272 14157137534 0014534 0 ustar 00root root 0000000 0000000 [tox]
envlist = py3
isolated_build = True
[testenv]
deps =
pytest
pytest-codeblocks
pytest-cov
pytest-randomly
extras = all
commands =
pytest {posargs} --codeblocks