Skip to content

Commit

Permalink
Merge pull request #288 from Morpho-lang/wrapup
Browse files Browse the repository at this point in the history
Wrapup
  • Loading branch information
softmattertheory authored Jan 10, 2025
2 parents feef3a8 + d41ac56 commit 3f89bfd
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 20 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ 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).

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.

**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)*

We expect to update this once the paper is published.

Participation in the morpho community, both as users and developers, is bound by our [Code of Conduct](CODE_OF_CONDUCT.md).

## Contributing
Expand All @@ -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:
Expand All @@ -54,23 +56,26 @@ 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

The second way to install morpho is by compiling the source code directly. Morpho now leverages the [Cmake](https://cmake.org) build system, which enables platform independent builds. Windows users must first install Windows Subsystem for Linux; some instructions to do so are found below.

#### 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):

```
Expand Down Expand Up @@ -178,10 +183,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.
8 changes: 8 additions & 0 deletions src/geometry/functional.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @brief Functionals
*/

#include <float.h>

#include "functional.h"
#include "morpho.h"
#include "classes.h"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions src/geometry/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down
26 changes: 26 additions & 0 deletions test/functionals/volumeenclosed/volencl_zeroelement.morpho
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 3f89bfd

Please sign in to comment.