Thanks.
Now I’m getting:
Info : Running 'gmsh -2 filename.geo' [Gmsh 4.4.1, 1 node, max. 1 thread]
Info : Started on Thu Oct 21 15:18:03 2021
Info : Reading 'filename.geo'...
Info : Done reading 'filename.geo'
Info : Meshing 1D...
Info : Meshing curve 1 (Line)
Info : Meshing curve 2 (Line)
Info : Meshing curve 3 (Line)
Info : Meshing curve 4 (Line)
Info : Done meshing 1D (0.0024824 s)
Info : Meshing 2D...
Info : Meshing surface 1 (transfinite)
Info : Done meshing 2D (0.000872 s)
Info : 121 vertices 244 elements
Info : Writing 'filename.msh'...
Info : Done writing 'filename.msh'
Info : Stopped on Thu Oct 21 15:18:03 2021
Converting from Gmsh format (.msh, .gmsh) to DOLFIN XML format mbseidel@DESKTOP-NPRJ0E1:/mnt/c/users/matheus seidel/documents$
File "/usr/bin/dolfin-convert", line 132, in <module>
main(sys.argv[1:])
File "/usr/bin/dolfin-convert", line 79, in main
meshconvert.convert2xml(ifilename, ofilename, iformat=iformat)
File "/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/meshconvert.py", line 1301, in convert2xml
convert(ifilename, XmlHandler(ofilename), iformat=iformat)
File "/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/meshconvert.py", line 1322, in convert
gmsh2xml(ifilename, handler)
File "/usr/lib/python3/dist-packages/dolfin_utils/meshconvert/meshconvert.py", line 271, in gmsh2xml
num_elements = int(line)
ValueError: invalid literal for int() with base 10: '9 244 1 244\n' Traceback (most recent call last):
File "NS_test.py", line 17, in <module>
mesh = Mesh("filename.xml")
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to read data from XML file.
*** Reason: Not a DOLFIN XML file.
*** Where: This error was encountered inside XMLFile.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.2.0.dev0
*** Git changeset: unknown
*** -------------------------------------------------------------------------
The code is as fallows:
from future import print_function
from fenics import *
import matplotlib.pyplot as plt
from dolfin import *
import os
Mesh and function space definition
#gmsh -2 filename.geo
#dolfin-convert filename.msh filename.xml
#mesh = Mesh(“filename.xml”)
os.system(“gmsh -2 filename.geo”)
os.system(“dolfin-convert filename.msh filename.xml”)
mesh = Mesh(“filename.xml”)
V = FunctionSpace(mesh, ‘Lagrange’, 1)
Trial and test functions in the same space (BC defined separately)
u = TrialFunction(V)
v = TestFunction(V)
Boundary condition
u_D = Expression(‘x[1] <= 0 + DOLFIN_EPS ? 0 : x[0] <= 0 + DOLFIN_EPS && x[1] <= 0.2 + DOLFIN_EPS ? 0 : 1’, degree=1)
def boundary(x):
return x[0] <= 0 + DOLFIN_EPS or x[1] <= 0 + DOLFIN_EPS
bc = DirichletBC(V, u_D, boundary)
Define variational problem
vel = as_vector([0.707, 0.707])
f = Constant(0)
G = (vdot(vel, grad(u)) + dot(grad((0.000001u)), grad(v)))dx - fv*dx
R = dot(vel, grad(u)) - 0.000001*div(grad(u)) - f
modvel = 1
h = 0.1
tal = h/(2*modvel)
G += (dot(vel, grad(v)))talR*dx
a = lhs(G)
L = rhs(G)
Compute solution
u = Function(V)
solve(a == L, u, bc)
Plot solution and mesh
plot(u)
plot(mesh)
Save solution to file in VTK format
vtkfile = File(‘NS_test/solution.pvd’)
vtkfile << u
Hold plot
plt.show()