Re: [firedrake] circles in firedrake?
As in, the gmsh input code that we used to create the circle mesh is being deleted in that commit, at lines 456-463. You could copy those removed lines into a .geo file and run it through gmsh to get the mesh that was being created before (but it has the cell area -> 0 problem). I would expect a user to run gmsh separately (at the command line or through the GUI), rather than from within the Python script. I don't think it's possible to interact with gmsh from Python nowadays without jumping through considerable hoops. Not sure why you're getting that error. It's been a long time since I last used gmsh. Taking a guess from https://github.com/FluidityProject/fluidity/wiki/Gmsh-tutorial, try adding one more line to the .geo: Physical Surface(7) = {6}; On 19 March 2017 at 16:04, Francis Poulin <fpoulin@uwaterloo.ca> wrote:
Thank you Andrew for your help. I am a bit sorry to see CircleMesh go away but if it only gave a structured mesh, then I can see the advantage to using gmsh. Also, I should really learn how to use gmsh better, so this will force me to do just that.
I looked around for circle.geo but couldn't find it in the repo.
I found another version of circle.geo that seems to build a circle. It is copied here
L = 10; dx = 1;
Point(1) = { 0, 0, 0, dx}; Point(2) = { L, 0, 0, dx}; Point(3) = {-L, 0, 0, dx}; Point(4) = { 0, L, 0, dx}; Point(5) = { 0,-L, 0, dx};
Circle(1) = {3,1,5}; Circle(2) = {5,1,2}; Circle(3) = {2,1,4}; Circle(4) = {4,1,3};
Line Loop(5) = {1,2,3,4};
Plane Surface(6) = {5};
I am not sure why the origin needs to be included but it does give the correct shape at least.
Unfortunately, when I try importing this in firedrake using
from firedrake import *
#gmsh -2 circle.geo
mesh = Mesh("circle.msh")
I get the error
Traceback (most recent call last): File "test.py", line 7, in <module> mesh = Mesh("circle.msh") File "<decorator-gen-261>", line 2, in Mesh File "/home/fpoulin/software/firedrake/src/PyOP2/pyop2/profiling.py", line 61, in wrapper return f(*args, **kwargs) File "/home/fpoulin/software/firedrake/src/firedrake/firedrake/mesh.py", line 1259, in Mesh topology = MeshTopology(plex, name=name, reorder=reorder, distribute=distribute) File "<decorator-gen-259>", line 2, in __init__ File "/home/fpoulin/software/firedrake/src/PyOP2/pyop2/profiling.py", line 61, in wrapper return f(*args, **kwargs) File "/home/fpoulin/software/firedrake/src/firedrake/firedrake/mesh.py", line 348, in __init__ dmplex.validate_mesh(plex) File "firedrake/dmplex.pyx", line 1009, in firedrake.dmplex.validate_mesh (firedrake/dmplex.c:14063) ValueError: Provided mesh has some entities not reachable by traversing cells (maybe rogue vertices?)
Can you point out what I'm doing wrong? Or where to find the circle.geo?
Also, I tried use gmsh in firedrake as commented above and that didn't work. Should gmsh work in the latest version?
Cheers, Francis
------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo
email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637 <(519)%20888-4567>
------------------------------ *From:* firedrake-bounces@imperial.ac.uk [firedrake-bounces@imperial.ac.uk] on behalf of Andrew McRae [A.T.T.McRae@bath.ac.uk] *Sent:* Sunday, March 19, 2017 8:07 AM *To:* firedrake@imperial.ac.uk *Subject:* Re: [firedrake] circles in firedrake?
We used to have a CircleMesh in Firedrake, but it was removed in this commit <https://github.com/firedrakeproject/firedrake/commit/54bff6b70e046106ddd4e72c23f48a2999510155>. If I recall correctly, this is because we outsourced the creation of that mesh to gmsh, but the gmsh-from-Python packages are no longer available with newer versions of Ubuntu.
That commit has a small gmsh snippet (.geo). You could manually run this through gmsh to build a mesh (.msh), and load this in to your firedrake script: mesh = Mesh("circle.msh"). Note that this CircleMesh (and, IIRC, FEniCS's equivalent) give a "structured" mesh with radial lines, and correspondingly small cells in the middle. If this is undesirable, you might be better off making a simple unstructured circle mesh in gmsh and loading it in.
Regarding the code you gave in your email, I think this has also worked just fine. However, the built-in Firedrake plotting functionality only seems to support 2D triangle and "unstructured" quadrilateral cells, rather than the "interval x interval" cells created by an extruded mesh. (I suspect this was an accidental omission)
If you instead do File("temp.pvd").write(U) and open the result in Paraview, I'm sure it would look fine. Of course, if you use this to get a circular mesh, it will also have small cells at the centre.
Best, Andrew
On 18 March 2017 at 17:29, Francis Poulin <fpoulin@uwaterloo.ca> wrote:
Hello,
I want to define my mesh to be a circle. In Fenics I know there is a command called CircleMesh that makes this very easy.
Q1) Is there a simple way of doing this in Firedrake?
I looked around and see how circlemanifoldmesh can do this with help for ExtrudedMesh. I found some code that can make a ring and I tried running it myself and defining a function on that mesh. Unfortunately, I get an error, see below.
Q2) If one needs to use CircleManifoldMesh is there something else one needs to do to use a circular geometry as your mesh?
Below are the lines that I tried and the error
from firedrake import * m = CircleManifoldMesh(20, radius=2) mesh = ExtrudedMesh(m, 5, extrusion_type='radial') x = SpatialCoordinate(mesh) V = FunctionSpace(mesh,'CG',1) U = Function(V).interpolate(-(pow(x[0]-0.5,2) + pow(x[1]-0.5,2))) plot(U); Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/fpoulin/software/firedrake/src/firedrake/firedrake/plot.py", line 308, in plot **kwargs) File "/home/fpoulin/software/firedrake/src/firedrake/firedrake/plot.py", line 502, in two_dimension_plot num_sample_points) File "/home/fpoulin/software/firedrake/src/firedrake/firedrake/plot.py", line 457, in _two_dimension_triangle_func_val raise RuntimeError("Unsupported Functionality") RuntimeError: Unsupported Functionality
------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo
email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637 <(519)%20888-4567>
I would expect a user to run gmsh separately (at the command line or through the GUI), rather than from within the Python script. I don't think it's possible to interact with gmsh from Python nowadays without jumping through considerable hoops. Have you tried the (free third-party) PyGmsh? It generates .geo code from Python. From there one calls Gmsh using Python subprocess and reads in the resulting .msh. I've found it handy. https://github.com/nschloe/pygmsh
Thanks for suggesting PyGmsh! I bumped into it a while ago but never really figured it out. Now I'm keen since it should help building and modifying meshes more easily. I installed pygmsh easily using the instructions on the website. It imports correctly. There is even an example that builds a circle, I think. When I try running this, as well as other examples, I get an error because no module named vtk is found. See below. I get this comes from meshio? Traceback (most recent call last): File "circle.py", line 24, in <module> meshio.write('circle.vtu', *out) File "/home/fpoulin/software/firedrake/local/lib/python2.7/site-packages/meshio/__init__.py", line 187, in write field_data=field_data File "/home/fpoulin/software/firedrake/local/lib/python2.7/site-packages/meshio/vtk_io.py", line 204, in write import vtk ImportError: No module named vtk When I do a pip install it tells me that it is already installed and up to date. (firedrake) fpoulin@fpoulin-Gazelle:~/software/pygmsh/test/examples$ pip install -U meshio Requirement already up-to-date: meshio in /home/fpoulin/software/firedrake/lib/python2.7/site-packages Requirement already up-to-date: pipdated in /home/fpoulin/software/firedrake/lib/python2.7/site-packages (from meshio) Requirement already up-to-date: numpy in /home/fpoulin/software/firedrake/lib/python2.7/site-packages (from meshio) Requirement already up-to-date: requests in /home/fpoulin/software/firedrake/lib/python2.7/site-packages (from pipdated->meshio) Requirement already up-to-date: appdirs in /home/fpoulin/software/firedrake/lib/python2.7/site-packages (from pipdated->meshio) I realize this isn't necessarily a firedrake question but if anyone had an idea on how to get this working I would be keen to try it. Cheers, Francis ------------------ Francis Poulin Associate Professor Department of Applied Mathematics University of Waterloo email: fpoulin@uwaterloo.ca Web: https://uwaterloo.ca/poulin-research-group/ Telephone: +1 519 888 4567 x32637 ________________________________ From: firedrake-bounces@imperial.ac.uk [firedrake-bounces@imperial.ac.uk] on behalf of G. D. McBain [gdmcbain@protonmail.com] Sent: Sunday, March 19, 2017 6:16 PM To: firedrake@imperial.ac.uk Subject: Re: [firedrake] circles in firedrake? I would expect a user to run gmsh separately (at the command line or through the GUI), rather than from within the Python script. I don't think it's possible to interact with gmsh from Python nowadays without jumping through considerable hoops. Have you tried the (free third-party) PyGmsh? It generates .geo code from Python. From there one calls Gmsh using Python subprocess and reads in the resulting .msh. I've found it handy. https://github.com/nschloe/pygmsh
participants (3)
- 
                
                Andrew McRae
- 
                
                Francis Poulin
- 
                
                G. D. McBain