morpho-lang / morpho Goto Github PK
View Code? Open in Web Editor NEWThe Morpho language 🦋. Morpho is a small embeddable language for scientific computing applications.
License: MIT License
The Morpho language 🦋. Morpho is a small embeddable language for scientific computing applications.
License: MIT License
From Amine Missaoui:
"I wanted to calculate the director field for a simple case of an achiral 5CB. So I set the pitch to a large value (about 200 because the "lnem.pitch = inf" command does not work)."
The pitch
attribute for the Nematic
functional is confusing for the user, since it actually means 2*Pi / pitch (= q).
Don't know whether we want to keep pitch
or introduce the q
, or keep both.
Describe the bug
A typo in the constructor for FloryHuggins
results in a segfault
To Reproduce
var m = Mesh("tetrahedron.mesh") // Can be found under test/functionals/floryhuggins
var mref = m.clone()
var lfh = FloryHuggins(mref. // This "." should be a ","
a = 1.0,
b = 1.0,
c = 1.0,
phi0=0.5
)
print lfh
Expected behavior
Some error indicating that the period is incorrect
Adding
m.addgrade(0)
to line 7 of equielement.morpho results in the failure of the test, specifically in the gradient
, and hence the optimization.
Here is a screenshot of before and after:
I am not sure whether this is a bug or my lack of understanding of how EquiElement
works. I was having some issue with EquiElement in a separate code, which is why I dug into the test example. While trying to visualize the vertices by adding grade 0 elements, the test failed and the vertex positions were quite off ([ 8.02753 4.31376 3.00688 ]
as opposed to [ 0 0.500034 1 ]
).
Describe the bug
print "2" and print 2 both output 2
print [2,"2"] gives [2,2]
var a = [2,"2"]
print a[0]+a[1]
Error 'InvldOp': Invalid operands. Failed to Add 2 and 2
this is confusing
ATTEMPT 1:
make install
cc -o morpho5 main.o builtin/builtin.o builtin/file.o builtin/functions.o builtin/veneer.o datastructures/dictionary.o datastructures/matrix.o datastructures/object.o datastructures/sparse.o datastructures/syntaxtree.o datastructures/value.o datastructures/varray.o geometry/discretization.o geometry/field.o geometry/functional.o geometry/integrate.o geometry/mesh.o geometry/selection.o interface/cli.o interface/help.o interface/linedit.o utils/common.o utils/debug.o utils/error.o utils/memory.o utils/parse.o utils/random.o vm/compile.o vm/vm.o -lm -lcblas -llapack -lcxsparse -std=c99 -O3 -I. -I./datastructures -I./geometry -I./interface -I./utils -I./vm -I./builtin
ld: warning: ignoring file /usr/local/lib/libcxsparse.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
"_cs_di_add", referenced from:
_sparse_add in sparse.o
"_cs_di_lusol", referenced from:
_sparse_div in sparse.o
"_cs_di_multiply", referenced from:
_sparse_mul in sparse.o
"_cs_di_qrsol", referenced from:
_sparse_div in sparse.o
"_cs_di_transpose", referenced from:
_sparse_transpose in sparse.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [morpho5] Error 1
ATTEMPT 2:
arch -x86_64 make install
cc -o morpho5 main.o builtin/builtin.o builtin/file.o builtin/functions.o builtin/veneer.o datastructures/dictionary.o datastructures/matrix.o datastructures/object.o datastructures/sparse.o datastructures/syntaxtree.o datastructures/value.o datastructures/varray.o geometry/discretization.o geometry/field.o geometry/functional.o geometry/integrate.o geometry/mesh.o geometry/selection.o interface/cli.o interface/help.o interface/linedit.o utils/common.o utils/debug.o utils/error.o utils/memory.o utils/parse.o utils/random.o vm/compile.o vm/vm.o -lm -lcblas -llapack -lcxsparse -std=c99 -O3 -I. -I./datastructures -I./geometry -I./interface -I./utils -I./vm -I./builtin
ld: warning: ignoring file builtin/builtin.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file main.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file builtin/file.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file builtin/functions.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/dictionary.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file builtin/veneer.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/object.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/matrix.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/sparse.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/syntaxtree.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64ld: warning: ignoring file geometry/discretization.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/varray.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/value.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file geometry/field.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file geometry/functional.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file geometry/mesh.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file geometry/selection.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file interface/help.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ld: warning: ignoring file utils/common.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file utils/memory.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ignoring file interface/cli.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ld: warning: ignoring file utils/parse.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64ld: warning: ignoring file interface/linedit.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ld: warning: ld: warning: ignoring file utils/random.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64ld: warning: ignoring file vm/vm.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ignoring file geometry/integrate.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ignoring file utils/debug.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file utils/error.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64ignoring file vm/compile.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [morpho5] Error 1
ATTEMPT 3:
arch -x86_64 /bin/bash -c "$(make install)"
ld: warning: ignoring file /usr/local/lib/libcxsparse.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
"_cs_di_add", referenced from:
_sparse_add in sparse.o
"_cs_di_lusol", referenced from:
_sparse_div in sparse.o
"_cs_di_multiply", referenced from:
_sparse_mul in sparse.o
"_cs_di_qrsol", referenced from:
_sparse_div in sparse.o
"_cs_di_transpose", referenced from:
_sparse_transpose in sparse.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [morpho5] Error 1
ld: warning: ignoring file main.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file builtin/builtin.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file builtin/file.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file builtin/functions.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file builtin/veneer.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/dictionary.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/matrix.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/object.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/sparse.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/syntaxtree.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/value.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file geometry/discretization.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file datastructures/varray.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ld: warning: ignoring file geometry/mesh.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file geometry/selection.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ignoring file geometry/integrate.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file geometry/functional.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file geometry/field.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file interface/cli.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ld: warning: ignoring file interface/linedit.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ignoring file interface/help.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file utils/common.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file utils/random.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file vm/compile.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file utils/parse.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file utils/error.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file utils/debug.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file utils/memory.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
ld: warning: ignoring file vm/vm.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Describe the bug
Caught a segfault that occurred in linecurvsq_integrand functional.c:1694
In my case nbrs.count = 4 but the size of s is only 2 so a segfault occurs trying to access the 3rd element of it (s is only ever size 2)
To Reproduce
This is the full repro script, I'll work on getting a minimal one
import functionals
import meshtools
import symmetry
import constants
import optimize
fn addSymmetryToKnit(m,h,k,N,M,fix_ends = false){
/* List the x-y coordinates of the end-points.
The end points are labeled like so:
c e
_ |_ _| _
| | | |
d---\-' '-/---f
\ /
a b
Thus, for the periodicity,
a <-> c
b <-> e
d <-> f
d a b are alway taken to be on the bottom/left of the knit
c e f are ont the top/right
*/
// loop over units in X direction adding bottom/top symmetry
// I.E. a <-> c, b <-> e
var dx = (1 + 2*k)
var dy = h
var disp_x = Matrix([(1+2*k)*N, 0, 0]) // This is the discrete period of the knit in the x direction
var disp_y = Matrix([0, h*M, 0]) // This is the discrete period of the knit in the y direction
for (i in 0...N){
var xa = -0.5 + i * dx
var ya = -0.5*h
var xb = 0.5 + i * dx
var yb = -0.5*h
var xc = -0.5 + i * dx
var yc = 0.5*h + dy * M
var xe = 0.5 + i * dx
var ye = 0.5*h + dy * M
var a = Selection(m, fn (x,y,z) abs(x-xa)<0.01 && abs(y-ya)<0.01)
a.addgrade(0)
var b = Selection(m, fn (x,y,z) abs(x-xb)<0.01 && abs(y-yb)<0.01)
b.addgrade(0)
var c = Selection(m, fn (x,y,z) abs(x-xc)<0.01 && abs(y-yc)<0.01)
c.addgrade(0)
var e = Selection(m, fn (x,y,z) abs(x-xe)<0.01 && abs(y-ye)<0.01)
e.addgrade(0)
// Impose discrete translation symmetry in y direction for points a, c, b and e
var ty = Translate(disp_y)
var ends_y = a.union(c.union(b.union(e)))
m.addsymmetry(ty, ends_y)
}
for (j in 0...M){
var xd = -(k+0.5)
var yd = 0.5*h-1 + dy * j
var xf = (k+0.5) + dx * N
var yf = 0.5*h-1 + dy * j
// Select the end-points on the mesh
var d = Selection(m, fn (x,y,z) abs(x-xd)<0.01 && abs(y-yd)<0.01)
d.addgrade(0)
var f = Selection(m, fn (x,y,z) abs(x-xf)<0.01 && abs(y-yf)<0.01)
f.addgrade(0)
// Add symmetries
// Impose discrete translation symmetry in x direction for points d and f
var tx = Translate(disp_x)
var ends_x = d.union(f)
m.addsymmetry(tx, ends_x)
}
return m
}
fn knitStart(h = 1.2, k = 0.5, dx = 0.05, N = 10, M = 10){
// N Number of unit cells in x dir
// M Number of unit cells in y dir
// var h = 1.2 // Decides the vertical spacing between the knits. This number is eye-balled right now
// var k = 0.5 // ratio of the minor axis to the major axis of the ellipse
// var dx = 0.05*Pi
dx = dx * Pi
var m1 = LineMesh(fn (t) [k*sin(t)-(k+0.5), 0.5*h+cos(t), 0], 0.5*Pi..Pi:dx, closed=false) // Left thread of the ellipse
var m2 = LineMesh(fn (t) [k*sin(t)+(k+0.5), 0.5*h+cos(t), 0], -0.5*Pi..-Pi:(-dx), closed=false) // Right thread of the ellipse
var m3 = LineMesh(fn (t) [sin(t)*(0.5 + cos(t)^2), cos(t)-0.5*h, 0.5*cos(3*t)], -0.5*Pi..0.5*Pi:dx, closed=false) // Part of the dumbbell curve
var merge = MeshMerge([m1])
merge.addmesh([m2])
merge.addmesh([m3])
var merge = MeshMerge([m1,m2,m3])
var m = merge.merge()
// now we have the unit cell make an NxM grid of them
var unitCellMerge = MeshMerge([m])
for (i in 0...N){
for (j in 0...M){
var newM = m.clone()
for (mi in 0...newM.count()) {
newM.setvertexposition(mi,newM.vertexposition(mi) + Matrix([2*(0.5+k)*i,h*j,0]))
}
unitCellMerge.addmesh([newM])
}
}
var finalM = unitCellMerge.merge()
finalM.addgrade(1)
addSymmetryToKnit(finalM,h,k,N,M)
return finalM
}
var knit = knitStart(N = 1, M = 1)
var problem = OptimizationProblem(knit)
// Add Hertzian sphere potential
// define the cutoff for the Hertzian potential
var sigma = 0.05*Pi
var lv = PairwisePotential(fn (r) (1-r/sigma)^(5/2), fn (r) -5/(2*sigma)*(1-r/sigma)^(3/2), cutoff=sigma)
problem.addenergy(lv, prefactor=100) // Using a large prefactor to ensure impenetrability
// Add line curvature and length energies
var lc = LineCurvatureSq()
var len = Length()
problem.addenergy(len)
problem.addenergy(lc)
var opt = ShapeOptimizer(problem, knit)
opt.stepsize = 0.0001 // 0.00001 works
opt.conjugategradient(100)
Describe the bug
If we give a 2D vector to the mesh constructor, it throws a MtrxBnds': Matrix index out of bounds.
error, where instead, it should either silently generate a 2D mesh setting z=0 or give an error asking for a 3D vector explicitly.
To Reproduce
import meshtools
import plot
var m1 = LineMesh(fn (t) [cos(t),sin(t)], 0..2*Pi:0.1*Pi) // As opposed to [cos(t),sin(t),0]
Show(plotmesh(m1))
Describe the bug
Error 'IndxBnds': Index out of bounds.
in AreaMesh at line 82
from global at line 9
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Error should not be there or the error should say that the mesh has an upper bound.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
for (i in 0..3)
Internal consistency error: Please contact developer. [Explanation: compiling an unexpectedly blank node [run with debugger]].
Describe the bug
String interpolation of builtin functions doesn't work.
To Reproduce
print "${cos}"
Expected behavior
Should give
cos
or
var A = [1,2,3]
var B = A.sets(4)
causes morpho to hang followed by being killed :-(
Describe the bug
There are two related bugs:
Mesh
constructor is initialized with nothing, like var m = Mesh()
, then at least some operations on this object result in segfault (see below)Mesh
constructor is initialized with an existing mesh, like var m2 = Mesh(m)
, then it creates an empty mesh like above, resulting in the same behavior.To Reproduce
Run the following code:
import meshtools
var m = Mesh()
print m // shows empty mesh
m.setvertexposition(0, Matrix([-5,0,0])) // Segfaults
or
var m = LineMesh(fn (t) [t,0,0], -1..1:0.2)
m.setvertexposition(0, Matrix([-5,0,0])) // works
var m2 = Mesh(m)
print m2 // shows empty mesh
m2.setvertexposition(0, Matrix([-5,0,0])) // Segfaults
Expected behavior
In the case of empty mesh, maybe an error message? In the case of initializing with another mesh, perhaps an output of the deepcopy of the input mesh would make sense.
running povray in quiet mode doesn't silence it, instead it run it in a new process
Working on adding minimal example
Describe the bug
AreaIntegral needs more arguments if we are integrating fields. But the constructor doesn't check if sufficient / more than sufficient arguments are provided
To Reproduce
import meshtools
var m = AreaMesh(fn (u,v) [u,v,0], -2..2:0.2, -2..2:0.2)
var vol = AreaIntegral(fn (x,y,) y) // Needs two more arguments for what fields y and z are
print vol.total(m)
Expected behavior
Should give error on the line where we initialize AreaIntegral
itself. Instead, it checks for this on the next line while running total
.
Also, passing more arguments than needed also is funky (e.g. AreaIntegral(fn (x,y,) y, a, b)
)
Describe the bug
Don't know if this is a bug, but the vertexmatrix
method for the mesh doesn't raise any error upon providing an argument (I think the default required arguments are 0)
To Reproduce
import meshtools
var m = LineMesh(fn (t) [t,0,0], -1..1:0.1)
print m.vertexmatrix() // Normal output
print m.vertexmatrix(0) // still normal output
print m.vertexmatrix(325235) // still normal output
print m.vertexmatrix(a=25) // still normal output
var s = Selection(m, fn(x,y,z) abs(x)<0.5)
print m.vertexmatrix(selection=s) // still normal output
Expected behavior
InvldArgs error
Describe the bug
When using a list to index morpho quits with:
Internal consistency error: Please contact developer. [Explanation: getindex called with noninteger args!].
To Reproduce
var a = [1,2,3]
a[[1]]
Expected behavior
I would expect this to either throw an error or to do return a sub-list of the original list.
Describe the bug
max is not coping with random arguments
To Reproduce
print max(-120) // segfault
print max([]) // returns uninitialized value
print max([cos, sin]) // returns last value
Expected behavior
Max should check its arguments
Describe the bug
This test segfaults.
Describe the bug
In the CLI after an error occurs typing help if the error has a help associated with it that, text will display.
Typing help again repeats that process
To Reproduce
ls
help
help
Expected behavior
After typing help once it should clear out the error and produce the original help dialog
Compiling the following gives a consistency error
import meshtools
import constants
fn mobius(r = 1, ratio = 0.5) {
var L = 2*r*ratio // Separation
var m = AreaMesh(fn(u,v) mobiusfn(u,v,r=r,ntwist=-1), -Pi..Pi:Pi/20,-L/2..L/2:L/10, closed=[false,false])
return m
}
fn mobiusfn(u,v, r = 1, ntwist=1){
var th = Matrix([cos(u), 0, sin(u)])
var twist = (cos(0.5*ntwist*u)*th + sin(0.5*ntwist*u)*Matrix([0,1,0]))
return r*th + v*twist
}
--Registers (7 in use)
r0 mobius [0]
r1 r [0] (captured)
r2 ratio [0]
r3 L [1]
r4 m [1]
r5 temporary [1]
r6 mobiusfn [1]
--End registers
Internal consistency error: Please contact developer. [Explanation: Incorrectly freed registers in compiling argument list.].
Reproduction script:
newconsitency.zip
Describe the bug
randomint handles invalid arguments poorly.
To Reproduce
print randomint("Hello") // Throws inconsistency error
print randomint(-5) // Returns very large negative integers...
Expected behavior
randomint should throw errors for these inputs
var A = [1,2,3]
print A[[2].2]
--Registers (4 in use)
r0 temporary [0]
r1 temporary [0]
r2 temporary [0]
r3 unallocated
--End registers
Internal consistency error: Please contact developer. [Explanation: Incorrectly freed registers in compiling argument list.].
Describe the bug
A clear and concise description of what the bug is.
Archive.zip
To Reproduce
import optimize
var m = Mesh("circlesquare.mesh")
//Circle boundary & area
var bndCirc = Selection(m, fn(x,y,z) x^2+y^2<1.0001 && x^2+y^2>0.9999)
bndCirc.addgrade(1)
// Set up a regularization problem
var reg = OptimizationProblem(m)
// Create shape and field optimizers
var ropt = ShapeOptimizer(reg, m)
// Must ensure boundary remains correctly fixed
ropt.fix(Selection(bndCirc, boundary=true))
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
Description of the bug:
When trying to plot a field that has a few inf values, morpho outputs the message:
morphoview: Unrecognized token.
and generates a blank plot. It would be nicer if it gives an error indicating that inf values are being asked to be plotted.
To Reproduce
import meshtools
import plot
var m = AreaMesh(fn (u, v) [u, v, 0], -0.5..0.5:0.1, -0.5..0.5:0.1
var S = Field(m, fn(x,y,z) exp(-x^2 - y^2))
S[10] = 1/0 // Setting a random point to inf. Commenting out this line results in normal behavior
Show(plotfield(S, style="interpolate"))
Expected behavior
Error message saying something along the lines of "Cannot plot inf values"
Describe the bug
The integrators use morpho_call to [e.g. in integral_integrandfn] to call a morpho function; if this raises an error, the integrator is presently ignoring the error and continues.
To Reproduce
import meshtools
import plot
import functionals
var L = 1.0
var dx = 0.1
var m = AreaMesh(fn (u, v) [u, v, 0], -L/2..L/2:dx, -L/2..L/2:dx)
m.addgrade(1)
fn mhdgrad(x,y,z,x0,y0,varphi){
return Matrix([(y-y0)/((x-x0)^2+(y-y0)^2)/2,-(x-x0)/((x-x0)^2+(y-y0)^2)/2])
}
fn phdgrad(x,y,z,x0,y0,varphi){
return Matrix([-(y-y0)/((x-x0)^2+(y-y0)^2)/2,(x-x0)/((x-x0)^2+(y-y0)^2)/2])
}
var defectsGrad = Field(m, fn(x,y,z) phdgrad(x, y, z, 0.25, 0, 0)+mhdgrad(x, y, z, -0.25, 0, 0) )
var directorIntegral = LineIntegral(fn (x,n) 1/(2*Pi) * n.inner(tangent()), defectsGrad)
//segv here
var fe = directorIntegral.integrand(m)
Expected behavior
Should report the error that occurs inside the user function and halt.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
The state of the virtual machine after an error is presently undefined, and hence if morpho_call returns false, it's essential that a C function quit as quickly as possible to the CLI so that the error can be reported. It may not be a bad idea to have morpho_call restore the frame pointer after a call to morpho_interpret to help protect against this type of error.
We need a way to translate images in morphoveiw
The Q-tensor needs some clean up see #42 for comments
Describe the bug
Trying to negate a Field object is causing InvldOp
To Reproduce
Steps to reproduce the behavior:
var ff = Field(mesh, grade = 0)
print -ff
Expected behavior
Should return the negation of the Field.
Additional context
Field needs a subr method to handle this (I think).
I think it would be worth having the option to use CMake for building Morpho. This might make it easier for new users to get up and running without needing to worry (too much) about whether they're using the right linker flags for the various dependencies, regardless of the system they're running. This has the potential to also make Windows builds easier, though that will need some testing.
I have a minimal working example that can compile on my Linux system, but I'll need to do some more testing before I make a PR. The goal of this Issue is to have a place to discuss what needs to go into making this happen, as well as to discuss other relevant aspects of the build process.
From Saul Sun
Typos in manual
usage of '''code''' font is not consistent thought manual
4.9 "el.update(refmap) // Update the problem" Indentation
5.8 Peren instead of brakets
5.13 use code font for first IF
5.17 space between 1,2 (also use code font for break)
5.18 1,2 need space
5.28 input isn't an angle, what is the range? Why use one arguement instead of two
5.43 should be titled isnan
6.3 lookup should probably be two words
6.4 lookup should probably be two words
6.5 and 6.6 need var
6.8 what order does it get sorted in also that its in place, provide an example
7.2 (grade 1) elements vs (grade 2 elements)
7.4 Additional Field objects may BE supplied
7.5 import ‘functionals‘ (don't need ')
7.6 length of a line elements
7.9 and 7.10 AN
7.9 "An VolumeEnclosed functional calculates the volume enclosed by a surface of line elements" is unclear and may not be correct
7.11 level set constraints is not a well known term
7.18 it might be nice to define what grad of higher d objects are
Describe the bug
Two positive infinities are not treated equal in the code, so there isn't a way to look for inf
values
To Reproduce
var x = 1/0 // generates inf
var y = x + 2 // also generates inf
print x==y // Expect true, but get false
Since this doesn't output true
, there is no way to look for infinities in a field or another object. Also, since nan
's cannot be compared, this method cannot be used to identify nan
's.
An inbuilt function isinf
and also isnan
would be great to have!
Describe the bug
There are two things going on here:
isinf
function returns true
if a value is infinite or false
otherwise, but in reality, it returns 1
if it's +inf
, 0
if it's finite and -1
if it's -inf
. andif
doesn't treat 0
as false
and anything non-zero as true
.So something like
if (isinf(1)) print "Welp!"
outputs "Welp!"
Describe the bug
If the MeshMerge
object is initialized with just a mesh (like var merger = MeshMerge(m)
) instead of a list (like var merger = MeshMerge([m])
), then the final object doesn't contain the initial mesh, and the code runs with no error.
To Reproduce
import meshtools
import plot
var m1 = LineMesh(fn (t) [t,0,0], 0..1:0.2) // Straight line along x axis
var m2 = LineMesh(fn (t) [0,t,0], 0..1:0.2) // Straight line along y axis
var merger = MeshMerge(m1)
merger.addmesh([m2])
var mf = merger.merge()
Show(plotmesh(mf))
Note
This code works even if [m2]
is replaced with m2
. The additional mesh didn't have to be a list.
Also, a simplified version as follows also works:
var merger = MeshMerge([m1,m2])
var mf = merger.merge()
Describe the bug
Some very terse function definitions with anonymous functions are not compiled correctly.
To Reproduce
fn f (a) { return fn () a }
print f(1)() // expect: 1
Expected behavior
f(a) should return a closure that is then called and returns 1 (so we should see 1)
Additional context
From the disassembly, it looks like a is not being read as an upvalue inside the anonymous function declaration:
0 : b 6
fn f:
1 : b 1
2 : return r0
fn f:
3 : lct r2, c0 ; c0=
4 : closure r2, p0 ;
5 : return r2 ;
6 : return r0 ;
7 : lct r0, c0 ; c0=
8 : sgl r0, g0 ;
-> 9 : lgl r0, g0 ;
10 : lct r1, c1 ; c1=1
11 : call r0, 1 ;
12 : print r0 ;
13 : end
Describe the bug
for -x^2 inside an exponential the result is as x^2
fn(x,y){return exp(-x^2 -y^2)} instead yields fn(x,y){return exp((-x)^2 -y^2}
To Reproduce
import meshtools
import plot
var mesh = AreaMesh(fn (x, y) [x, y, exp(-x^2 - y^2)], -1..1:0.2, -1..1:0.2) # Does not look Gaussian
Show(plotmesh(mesh))
var mesh = AreaMesh(fn (x, y) [x, y, exp(-(x^2 + y^2))], -1..1:0.2, -1..1:0.2) # Does look Gaussian
Show(plotmesh(mesh))
Describe the bug
A 1D mesh can only contain vertices (grade 0) and lines (grade 1) (I think!)
So, upon trying to add faces (grade 2) to a 1D mesh, the program should give an error. Instead, it segfaults.
To Reproduce
import meshtools
var m = LineMesh(fn (t) [cos(t), sin(t), 0], 0..2*Pi:0.2, closed=true)
m.addgrade(2)
Expected behavior
Some error message, saying faces cannot be added to a 1D mesh.
Describe the bug
The Field constructor allows for initializing a field with a constant numerical value, but when supplied one without an anonymous function, it produces zeros instead.
To Reproduce
import meshtools
var m = LineMesh(fn (t) [t,0,0], 0..1:0.2)
var f = Field(m, 2.0)
print f // Expected output: <Field> [2] [2] ...
// What we get: <Field> [ 0 ] [ 0 ]...
// It works with an anonymous function
var f = Field(m, fn(x,y,z) 2.0)
print f // Works correctly
// Also works with Matrix objects
var f = Field(m, Matrix([2.0]))
print f // Works correctly
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
fn anchoring(x, q) {
var t = tangent()
var wxx = t[0]t[0]-0.5
var wxy = t[0][1]
//return (q[0]-wxx)^2+(q[1]-wxy)^2
return 0
}
morpho5 indexing.morpho doesn't throw a complication error despite *[1]
Trying to use this fn results in a segfault
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
indexing.zip
Describe the bug
Performing the split operation on strings a bunch of times results in a Segmentation Fault
To Reproduce
var str = "a b c d e"
var w
for (i in 1..10) {
w = str.split(" ")
print w
}
Output:
[ a, b, c, d, e ]
[ a, b, c, d, e ]
[ a, b, c, d, e ]
[ a, b, c, d, e ]
Segmentation fault (core dumped)
A number of things change the behavior of this segfault, including
w
,print "${str}"
before the splitHere is the gdb
output with the backtrace:
Describe the bug
Error 'MshAddGrdOutOfBnds': Cannot add elements of grade 1 to mesh with max grade 2
in global at line 10
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Screenshots
NA
Additional context
NA
print min([1,0.1,0.2,0.5,0.3])
"1"
expected "0.1"
I think this is because there is no in common.h:33 NOTEQUAL and BIGGER are defined the same morpho_ofsametype will tell us that 1 is a int and 0.1 is a float so everything will come up as bigger than 1 because they are not of the same type (edited)
perhaps a solution here is to have a morpho_ofcomparible type which returns true for int and float
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
for (i in 1..2)
for (j in 1..2)
print i+j
generates Internal consistency error: Please contact developer. [Explanation: compiling an unexpectedly blank node [run with debugger]].
Expected behavior
Should either generate a warning:
"For loop with blank body"
Or compile as nested for loop.
Additional context
This is an edge case for semicolon suppression. Normally, morpho accepts an end of line as a semicolon anywhere it would be valid.
for loops with blank bodies are occasionally useful (tho not for..in loops?)
Describe the bug
There is some issue with >0
. Comparing with 0.0
works just fine, and <0
also works (see below)
To Reproduce
Simplest way to reproduce is to run
print 0.4>0 // Returns false
To get statistics, I ran the following
var count = 0
var n = 10000000
for (i in 1..n){
if ((random(1)>0)==false) {
count = count + 1
}
}
print "${count} / ${n} numbers compared incorrectly!"
Which consistently returns a number around 1250000, thus failing ~12.5% (=1/8? Binary?) of the time. Scaling the random number by 10, e.g., also doesn't work.
Now, if we do -random(1)<0
instead, it works just fine.
Describe the bug
import meshtools
import plot
import functionals
var L = 1.0
var dx = 0.1
var m = AreaMesh(fn (u, v) [u, v, 0], -L/2..L/2:dx, -L/2..L/2:dx)
m.addgrade(1)
fn mhdgrad(x,y,z,x0,y0,varphi){
return [(y-y0)/((x-x0)^2+(y-y0)^2)/2,-(x-x0)/((x-x0)^2+(y-y0)^2)/2]
}
fn phdgrad(x,y,z,x0,y0,varphi){
return [-(y-y0)/((x-x0)^2+(y-y0)^2)/2,(x-x0)/((x-x0)^2+(y-y0)^2)/2]
}
var defectsGrad = Field(m, fn(x,y,z) phdgrad(x, y, z, 0.25, 0, 0)+mhdgrad(x, y, z, -0.25, 0, 0) )
var directorIntegral = LineIntegral(fn (x,n) 1/(2*Pi) * n.inner(tangent()),defectsGrad)
//segv here
var fe = directorIntegral.integrand(m)
generates a segfault
To Reproduce
Steps to reproduce the behavior:
Run above code
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
Describe the bug
If an input to the command line starts with "quit" the CLI will quit. This can cause commands that are not quit commands to be read as such
To Reproduce
> var quite = 4
> quite = quite + 2
Right addition on matrices throws a internal consistency error
var a = 2
var B = Matrix([1,2,3])
print a+B
Internal consistency error: Please contact developer. [Explanation: Right addition to non-zero value.].
I'll take a crack at this today while I'm finishing up the complex class.
We should add sign(x) as a builtin
var A = Matrix([[0,1,2,3],[4,5,6,7],[8,9,10,11]])
print A[-1..2,1..2]
Error 'IndxBnds' : Index out of bounds.
A[1,2,3,4]
*** stack smashing detected ***: terminated
Aborted (core dumped)
Working on this with the slicing changes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.