From 85b10bc9c1f8cfb4cae466ab57563be4c82dc14d Mon Sep 17 00:00:00 2001 From: softmattertheory Date: Thu, 9 Jan 2025 15:24:14 -0800 Subject: [PATCH 1/6] Raise an error if VolEnclosed takes the gradient of a zero element --- src/geometry/functional.c | 8 ++++++++ src/geometry/functional.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/geometry/functional.c b/src/geometry/functional.c index 8823889a..bdfd4270 100644 --- a/src/geometry/functional.c +++ b/src/geometry/functional.c @@ -4,6 +4,8 @@ * @brief Functionals */ +#include + #include "functional.h" #include "morpho.h" #include "classes.h" @@ -1886,6 +1888,11 @@ bool volumeenclosed_gradient(vm *v, objectmesh *mesh, elementid id, int nv, int functional_veccross(x[0], x[1], cx); dot=functional_vecdot(mesh->dim, cx, x[2]); + if (fabs(dot)<=DBL_MIN) { + morpho_runtimeerror(v, VOLUMEENCLOSED_ZERO); + return false; + } + dot/=fabs(dot); matrix_addtocolumn(frc, vid[2], dot/6.0, cx); @@ -4638,6 +4645,7 @@ void functional_initialize(void) { builtin_addfunction(NORMAL_FUNCTION, integral_normal, BUILTIN_FLAGSEMPTY); builtin_addfunction(GRAD_FUNCTION, integral_gradfn, BUILTIN_FLAGSEMPTY); + morpho_defineerror(VOLUMEENCLOSED_ZERO, ERROR_HALT, VOLUMEENCLOSED_ZERO_MSG); morpho_defineerror(FUNC_INTEGRAND_MESH, ERROR_HALT, FUNC_INTEGRAND_MESH_MSG); morpho_defineerror(FUNC_ELNTFND, ERROR_HALT, FUNC_ELNTFND_MSG); diff --git a/src/geometry/functional.h b/src/geometry/functional.h index d0389f04..b964cc86 100644 --- a/src/geometry/functional.h +++ b/src/geometry/functional.h @@ -107,6 +107,9 @@ #define LINEINTEGRAL_NFLDS "IntgrlNFlds" #define LINEINTEGRAL_NFLDS_MSG "Incorrect number of Fields provided for integrand function." +#define VOLUMEENCLOSED_ZERO "VolEnclZero" +#define VOLUMEENCLOSED_ZERO_MSG "VolumeEnclosed detected an element of zero size. Check that a mesh point is not coincident with the origin." + #define LINEARELASTICITY_REF "LnElstctyRef" #define LINEARELASTICITY_REF_MSG "LinearElasticity requires a mesh as the argument." From e15533f35ae914b70715e3e7ecf0433ba10ac6e2 Mon Sep 17 00:00:00 2001 From: softmattertheory Date: Thu, 9 Jan 2025 15:46:46 -0800 Subject: [PATCH 2/6] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ca60735f..87c9ee6e 100644 --- a/README.md +++ b/README.md @@ -16,16 +16,16 @@ The Morpho language. Morpho is a programmable environment for shape optimization Documentation is available on [readthedocs](https://morpho-lang.readthedocs.io/en/latest/), an extensive [user manual](https://github.com/Morpho-lang/morpho-manual/blob/main/manual.pdf) and a [developer guide](https://github.com/Morpho-lang/morpho-devguide/blob/main/devguide.pdf). A [Slack community](https://join.slack.com/t/morphoco/shared_invite/zt-1o6azavwl-XMtjjFwxW~P6C8rc~YbBlA) is also available for people interested in using morpho and seeking support. -**New!** We now have a sequence of tutorial videos on our [Youtube channel](https://www.youtube.com/@Morpho-lang) to help you learn Morpho: +We now have a sequence of tutorial videos on our [Youtube channel](https://www.youtube.com/@Morpho-lang) to help you learn Morpho: * An [introduction to the Morpho language](https://youtu.be/eVPGWpNDeq4) * Introduction to [shape optimization with Morpho](https://youtu.be/odCkR0PDKa0) In academic publications, please cite morpho as: -*Joshi, C. et al., "Morpho -- A programmable environment for shape optimization and shapeshifting problems", [arXiv:2208.07859](https://arxiv.org/abs/2208.07859) (2022)* +* Joshi, C. et al. ["A programmable environment for shape optimization and shapeshifting problems", Nat Comput Sci (2024). doi.org/10.1038/s43588-024-00749-7](https://doi.org/10.1038/s43588-024-00749-7) -We expect to update this once the paper is published. +A preprint of the paper is also available on the [arXiv preprint server](https://arxiv.org/abs/2208.07859) Participation in the morpho community, both as users and developers, is bound by our [Code of Conduct](CODE_OF_CONDUCT.md). From 20999f01a0caadcf645990cbd181625792877b85 Mon Sep 17 00:00:00 2001 From: softmattertheory Date: Thu, 9 Jan 2025 15:51:51 -0800 Subject: [PATCH 3/6] Update README.md --- README.md | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 87c9ee6e..8cbcba50 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,12 @@ The Morpho language. Morpho is a programmable environment for shape optimization *Morpho is based upon work supported by the National Science Foundation under grants DMR-1654283 and OAC-2003820.* +In academic publications, please cite morpho as: + +* Joshi, C. et al. "A programmable environment for shape optimization and shapeshifting problems", Nat Comput Sci (2024). [doi.org/10.1038/s43588-024-00749-7](https://doi.org/10.1038/s43588-024-00749-7) + +A preprint of the paper is also available on the [arXiv preprint server](https://arxiv.org/abs/2208.07859) + ## Learn and use morpho Documentation is available on [readthedocs](https://morpho-lang.readthedocs.io/en/latest/), an extensive [user manual](https://github.com/Morpho-lang/morpho-manual/blob/main/manual.pdf) and a [developer guide](https://github.com/Morpho-lang/morpho-devguide/blob/main/devguide.pdf). A [Slack community](https://join.slack.com/t/morphoco/shared_invite/zt-1o6azavwl-XMtjjFwxW~P6C8rc~YbBlA) is also available for people interested in using morpho and seeking support. @@ -21,12 +27,6 @@ We now have a sequence of tutorial videos on our [Youtube channel](https://www.y * An [introduction to the Morpho language](https://youtu.be/eVPGWpNDeq4) * Introduction to [shape optimization with Morpho](https://youtu.be/odCkR0PDKa0) -In academic publications, please cite morpho as: - -* Joshi, C. et al. ["A programmable environment for shape optimization and shapeshifting problems", Nat Comput Sci (2024). doi.org/10.1038/s43588-024-00749-7](https://doi.org/10.1038/s43588-024-00749-7) - -A preprint of the paper is also available on the [arXiv preprint server](https://arxiv.org/abs/2208.07859) - Participation in the morpho community, both as users and developers, is bound by our [Code of Conduct](CODE_OF_CONDUCT.md). ## Contributing @@ -54,10 +54,10 @@ The simplest way to install morpho is through the [homebrew package manager](htt ``` brew update brew tap morpho-lang/morpho -brew install morpho morpho-cli morpho-morphoview +brew install morpho morpho-cli morpho-morphoview morpho-morphopm ``` -If you need to uninstall morpho, simply open a terminal and type `brew uninstall morpho-cli morpho-morphoview morpho`. It's very important to uninstall the homebrew morpho in this way before attempting to install from source as below. +If you need to uninstall morpho, simply open a terminal and type `brew uninstall morpho-morphopm morpho-cli morpho-morphoview morpho`. It's very important to uninstall the homebrew morpho in this way before attempting to install from source as below. ### Install from source @@ -65,12 +65,15 @@ The second way to install morpho is by compiling the source code directly. Morph #### Gather dependencies -You can use any appropriate package manager to install morpho's dependencies via the terminal. Using homebrew (preferred on macOS): +You can use any appropriate package manager to install morpho's dependencies via the terminal. + +Using homebrew (preferred on macOS): ``` brew update brew install cmake glfw suite-sparse freetype povray libgrapheme ``` + Using apt (preferred on Ubuntu): ``` @@ -178,10 +181,6 @@ to navigate back out of the morpho-morphoview folder. Windows support is provided through Windows Subsystem for Linux (WSL), which is an environment that enables windows to run linux applications. We highly recommend using WSL2, which is the most recent version and provides better support for GUI applications; some instructions for WSL1 are provided [in the manual](https://github.com/Morpho-lang/morpho-manual/blob/main/manual.pdf). Detailed information on running GUI applications in WSL2 is found on the [Microsoft WSL support page](https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps). -1. Begin by installing the [Ubuntu App](https://ubuntu.com/desktop/wsl) from the Microsoft store. - -2. Once the Ubuntu terminal is working in Windows, you can install morpho either through homebrew or by building from source. +1. Begin by installing the [Ubuntu App](https://ubuntu.com/desktop/wsl) from the Microsoft store. ---- -### Other Tests -[![No NAN Boxing](https://github.com/Morpho-lang/morpho/actions/workflows/nonanboxing.yml/badge.svg)](https://github.com/Morpho-lang/morpho/actions/workflows/nonanboxing.yml) +2. Once the Ubuntu terminal is working in Windows, you can install morpho either through homebrew or by building from source. From acee08d09c62a4dfb68ab601cbdf7181926756e5 Mon Sep 17 00:00:00 2001 From: softmattertheory Date: Thu, 9 Jan 2025 15:55:54 -0800 Subject: [PATCH 4/6] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8cbcba50..d61b74f9 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,15 @@ The Morpho language. Morpho is a programmable environment for shape optimization * **Familiar**. Morpho uses syntax similar to other C-family languages. The syntax fits on a postcard, so it's easy to learn. * **Fast**. Morpho programs run as efficiently as other well-implemented dynamic languages like *wren* or *lua* (Morpho is often significantly faster than Python, for example). Morpho leverages numerical libraries like *BLAS*, *LAPACK* and *SUITESPARSE* to provide high performance. * **Class-based**. Morpho is highly object-oriented, which simplifies coding and enables reusability. -* **Extendable**. Functionality is easy to add via packages, both in Morpho and in C or other compiled languages. +* **Extendable**. Functionality is easy to add via packages, both in Morpho and in C or other compiled languages. Packages can be downloaded, installed and distributed via the [morphopm](https://github.com/Morpho-lang/morpho-morphopm) package manager. *Morpho is based upon work supported by the National Science Foundation under grants DMR-1654283 and OAC-2003820.* In academic publications, please cite morpho as: -* Joshi, C. et al. "A programmable environment for shape optimization and shapeshifting problems", Nat Comput Sci (2024). [doi.org/10.1038/s43588-024-00749-7](https://doi.org/10.1038/s43588-024-00749-7) +* Joshi, C. et al. "A programmable environment for shape optimization and shapeshifting problems", Nat Comput Sci (2024) [doi.org/10.1038/s43588-024-00749-7](https://doi.org/10.1038/s43588-024-00749-7). -A preprint of the paper is also available on the [arXiv preprint server](https://arxiv.org/abs/2208.07859) +A preprint of the paper is also available on the [arXiv preprint server](https://arxiv.org/abs/2208.07859). ## Learn and use morpho @@ -43,6 +43,8 @@ Code in this repository builds morpho as a shared library. Morpho also requires For this release, morpho can be installed on all supported platforms using the homebrew package manager. Alternatively, the program can be installed from source as described below. We are continuously working on improving morpho installation, and hope to provide additional mechanisms for installation in upcoming releases. +Morpho packages to extend the program's capability can be downloaded, installed and distributed via the associated [morphopm](https://github.com/Morpho-lang/morpho-morphopm) package manager. + ### Installation with homebrew The simplest way to install morpho is through the [homebrew package manager](https://brew.sh). To do so: From 75568226e2ad23ffe84ce22cafcf7c0f20950dd2 Mon Sep 17 00:00:00 2001 From: softmattertheory Date: Thu, 9 Jan 2025 16:06:13 -0800 Subject: [PATCH 5/6] Test to lock down error on VolEnclZero --- .../volumeenclosed/volencl_zeroelement.morpho | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/functionals/volumeenclosed/volencl_zeroelement.morpho diff --git a/test/functionals/volumeenclosed/volencl_zeroelement.morpho b/test/functionals/volumeenclosed/volencl_zeroelement.morpho new file mode 100644 index 00000000..840138a3 --- /dev/null +++ b/test/functionals/volumeenclosed/volencl_zeroelement.morpho @@ -0,0 +1,26 @@ +import meshtools +import optimize + +var vertexlist = [[0.5,0.5,0.5], [0.5,1.5,0.5], [1.5,1.5,0.5], [1.5,0.5,0.5], [0.5,0.5,1.5],[0.5,1.5,1.5], [1.5,1.5,1.5], [1.5,0.5,1.5]] + +var facelist = [[0,3,2,1], [0,4,5,1], [0,3,7,4], [2,3,7,6], [4,5,6,7], [1,2,6,5]] + +var m = PolyhedronMesh(vertexlist, facelist) + +for (id in 0...m.count()) { + var x = m.vertexposition(id) + x -= Matrix([1,1,1])/2 + m.setvertexposition(id, x) +} + +var problem = OptimizationProblem(m) + +var la = Area() +var lv = VolumeEnclosed() + +problem.addenergy(la) +problem.addconstraint(lv) + +var opt = ShapeOptimizer(problem, m) + +opt.relax(1) // expect error 'VolEnclZero' \ No newline at end of file From d41ac56a36ea2cd7f0bf5660c76319d0ff3402bc Mon Sep 17 00:00:00 2001 From: Tim Atherton <54725421+softmattertheory@users.noreply.github.com> Date: Fri, 10 Jan 2025 09:53:51 -0800 Subject: [PATCH 6/6] Update CMakeLists to match build.h --- CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b689ef95..d7e26728 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,9 +29,13 @@ if(MORPHO_GCSTRESSTEST) target_compile_definitions(morpho PUBLIC _DEBUG_STRESSGARBAGECOLLECTOR) endif() -# Set resources directory -if(MORPHO_RESOURCESDIR) -target_compile_definitions(morpho PUBLIC MORPHO_RESOURCESDIR=\"${MORPHO_RESOURCESDIR}\") +# Set help directory +if(MORPHO_HELP_BASEDIR) +target_compile_definitions(morpho PUBLIC MORPHO_HELP_BASEDIR=\"${MORPHO_HELP_BASEDIR}\") +endif() + +if(MORPHO_MODULE_BASEDIR) +target_compile_definitions(morpho PUBLIC MORPHO_MODULE_BASEDIR=\"${MORPHO_MODULE_BASEDIR}\") endif() # Create source groups for IDE