Skip to content

Commit

Permalink
Update to meshgen
Browse files Browse the repository at this point in the history
Update meshgen to improve documentation, improve benchmarking and add in a unit test
  • Loading branch information
softmattertheory committed Feb 26, 2022
1 parent b449725 commit c4e9114
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 8 deletions.
10 changes: 10 additions & 0 deletions benchmark/MeshGen/square.morpho
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Square domain with a hole
import meshgen
import plot

var e0 = Domain(fn (x) ((x[0])^2+x[1]^2-1))
var mg = MeshGen(e0, [-2..2:0.2, -2..2:0.2], quiet=true)
var m = mg.build()

print m

4 changes: 4 additions & 0 deletions benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from colored import stylize
import subprocess

"""
languages = { "morpho": "morpho5",
"m3": "morpho3",
"fe": "evolver",
Expand All @@ -18,6 +19,9 @@
"rb": "ruby",
"dart": "dart"
}
"""

languages = { "morpho": "morpho5" }

# Gets the output generated
def getoutput(filepath):
Expand Down
2 changes: 1 addition & 1 deletion examples/meshgen/ellipse.morpho
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import meshgen
import plot

var e0 = Domain(fn (x) -((x[0]/2)^2+x[1]^2-1))
var mg = MeshGen(e0, [-2..2:0.2, -1..1:0.2], quiet=false)
var mg = MeshGen(e0, [-2..2:0.2, -1..1:0.2])
var m = mg.build()
Show(plotmesh(m, grade=1))
2 changes: 1 addition & 1 deletion examples/tactoid/tactoid.morpho
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bnd.addgrade(0)
var sigma=5.0*0.04 // Surface tension
var W=3.0 // Anchoring

var itermax = 8
var itermax = 4

// Set up the optimization problem
var problem = OptimizationProblem(m)
Expand Down
18 changes: 12 additions & 6 deletions morpho5/docs/meshgen.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,25 @@ There are also a number of properties of a `MeshGen` object that can be set prio

[showsubtopics]: # (subtopics)

## Domain
## Domain
[tagdomain]: # (domain)

The `Domain` class is used to conveniently build a
The `Domain` class is used to conveniently build a domain by composing simpler elements.

var a = CircularDomain([-0.5,0], 1)
var b = CircularDomain([0.5,0], 1)
Create a `Domain` from a scalar function that is positive in the region of interest:

var dom = a.union(b).difference(c)
var dom = Domain(fn (x) -(x[0]^2+x[1]^2-1))

You can pass it to `MeshGen` to specify the region to mesh:

var mg = MeshGen(dom, [-1..1:0.2, -1..1:0.2])

You can combine `Domain` objects using set operations `union`, `intersection` and `difference`:

var a = (s1.intersection(s2)).union(s3)
var a = CircularDomain(Matrix([-0.5,0]), 1)
var b = CircularDomain(Matrix([0.5,0]), 1)
var c = CircularDomain(Matrix([0,0]), 0.3)
var dom = a.union(b).difference(c)

## CircularDomain
[tagcirculardomain]: # (circulardomain)
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions test/modules/meshgen/disk.morpho
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Domain composed of a single disk
import meshgen
import plot

var dom = fn (x) -(x[0]^2+x[1]^2-1)
var mg = MeshGen(dom, [-1..1:0.2, -1..1:0.2], quiet=true)
var m = mg.build()

print ismesh(m)
// expect: true
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c4e9114

Please sign in to comment.