Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] VolumeEnclosed give NaNs when it has a point coincident with its origin #133

Open
ConduitDan opened this issue Apr 26, 2022 · 4 comments
Labels
bug Something isn't working functionals This issue is with a functional good first issue Good for newcomers

Comments

@ConduitDan
Copy link
Collaborator

import meshtools
import plot
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)

//Show(plotmesh(m, grade=[0,1,2]))

print(m)

var problem = OptimizationProblem(m)

var la = Area()
var lv = VolumeEnclosed()

problem.addenergy(la)
problem.addconstraint(lv)

var opt = ShapeOptimizer(problem, m)

var mr=MeshRefiner([m])
var refmap = mr.refine()
for (el in [problem, opt]) el.update(refmap)
m = refmap[m]

opt.relax(100)

Show(plotmesh(m, grade=[0,1,2]))

@ConduitDan ConduitDan added the bug Something isn't working label Apr 26, 2022
@joshichaitanya3
Copy link
Collaborator

Hmm, interesting. The Polyhedronmesh looks fine.

I noticed that
print lv.total(m)
returns 2 in this case, while it should return 1.

The cube in the cube.morpho file returns 1 correctly.

@softmattertheory
Copy link
Contributor

@ConduitDan move all the vertices so that (0,0,0) lies in the cube. Does it still fail then?

The problem I think is that VolumeEnclosed isn't guaranteed to work if (0,0,0) isn't in the volume (until we've done Mesh orientation)

@ConduitDan ConduitDan changed the title [Bug] Cube->Sphere give odd result? [Bug] VolumeEnclosed give NaNs when it has a point coincident with its origin Jun 28, 2022
@ConduitDan
Copy link
Collaborator Author

VolumeEnclosed should probably throw and error if it encounters a point coincident with the origin that it is measuring volume from

@ConduitDan
Copy link
Collaborator Author

Alternatively we should protect from divide by zero by adding eps to the denominator

@ConduitDan ConduitDan added good first issue Good for newcomers functionals This issue is with a functional labels Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working functionals This issue is with a functional good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants