Comments (14)
This is my code:
import pygmsh
import numpy as np
import meshio
from math import pow
import string
import sys
import traceback
lcar=pow(10,22)
print(lcar)
Points=dict()
Splines=dict()
Line_loops=dict()
Ruled_surface=dict()
Points_with_lcar=dict()
Points_done=dict()
Points_with_lcar_done=dict()
Splines_done=dict()
Line_loops_done=dict()
Surfaces_done=dict()
def remove_char(s):
if'Point' in s:
s=s[6:]
arr=[]
helper=''
counter=0
for i in s:
if i=='=':
break
else:
counter=counter+1
s=s[counter+1:]
if 'cl__1' in s:
for i in s:
if not i==',' and not i.isdigit() and not i=='.'and not i=='-':
s=s.replace(i,'')
else:
if i==',':
arr.append(float(helper))
helper=''
else:
helper=helper+i
else:
for i in s:
if not i==',' and not i.isdigit() and not i=='.' and not i=='}'and not i=='-':
s=s.replace(i,'')
else:
if i==',' or i=='}':
arr.append(float(helper))
helper=''
else:
helper=helper+i
s=s.replace('}','')
return arr
elif 'Spline' in s:
s=s[7:]
arr=[]
helper=''
counter=0
for i in s:
if i=='=':
break
else:
counter=counter+1
s=s[counter+1:]
for i in s:
if i=='{' or i=='=' or i==';' or i=='\n':
s=s.replace(i,'')
else:
if i==',' or i=='}':
arr.append(helper)
helper=''
else:
helper=helper+i
s=s.replace('}','')
return arr
elif 'Line Loop' in s:
s=s[10:]
arr=[]
helper=''
counter=0
for i in s:
if i=='=':
break
else:
counter=counter+1
s=s[counter+1:]
for i in s:
if i=='{' or i=='=' or i==';' or i=='\n':
s=s.replace(i,'')
else:
if i==',' or i=='}':
arr.append(int(helper)) #maybe this should be changed
helper=''
else:
helper=helper+i
s=s.replace('}','')
return arr
elif 'Surface' in s:
s=s[8:]
arr=[]
helper=''
counter=0
for i in s:
if i=='=':
break
else:
counter=counter+1
s=s[counter+1:]
for i in s:
if i=='{' or i=='}' or i=='\n' or i==';':
s=s.replace(i,'')
else:helper=helper+i
arr.append(helper)
return arr
code part2:
def find_id(s):
string_helper=''
if 'Point' in s:
s=s[6:]
for i in s:
if not i==')':
string_helper=string_helper+i
else:break
elif 'Spline' in s:
s=s[7:]
for i in s:
if not i==')':
string_helper=string_helper+i
else:break
elif 'Line Loop' in s:
s=s[10:]
for i in s:
if not i==')':
string_helper=string_helper+i
else:break
elif 'Surface' in s:
s=s[8:]
for i in s:
if not i==')':
string_helper=string_helper+i
else:break
return string_helper
part3:
with open('proba.txt', 'r') as myfile:
for line in myfile:
text=line
if 'Point'in text and text:
if 'cl__1' in text:
text=remove_char(text)
if text:
s=find_id(line)
Points_with_lcar[s]=text
else:
text=remove_char(text)
if text:
s=find_id(line)
Points[s]=text
elif 'Spline' in text:
text=remove_char(text)
if text:
s=find_id(line)
Splines[s]=text
elif 'Line Loop' in text:
text=remove_char(text)
if text:
s=find_id(line)
Line_loops[s]=text
elif 'Surface' in text:
text=remove_char(text)
if text:
s=find_id(line)
Ruled_surface[s]=text
part4:
myfile.close()
geom = pygmsh.built_in.Geometry()
#adding points
for i in Points:
Points_done[i]=geom.add_point(Points[i],0.1)
for i in Points_with_lcar:
Points_with_lcar_done[i]=geom.add_point(Points_with_lcar[i],lcar)
#adding bsplines
for i in Splines:
helper=[]
for k in Line_loops:
for l in Line_loops[k]:
i=int(i)
if -i==l:
i=str(i)
Splines[i].reverse()
else: i=str(i)
for j in Splines[i]:
j=j[1:] #small mistake but now it's fine
if j in Points_done.keys():
helper.append(Points_done[j])
elif j in Points_with_lcar_done.keys():
helper.append(Points_with_lcar_done[j])
Splines_done[i]=geom.add_bspline(helper)
#print(Splines_done.keys())
#adding line loops
for i in Line_loops:
helper2=[]
for j in Line_loops[i]:
if j<0:
j=j*-1
j=str(j)
else: j=str(j)
helper2.append(Splines_done[j])
Line_loops_done[i]=geom.add_line_loop(helper2)
#adding surfaces
for i in Ruled_surface:
#helper3=[]
#print(i)
#for j in Ruled_surface[i]:
# j=j[1:]
# helper3.append(Line_loops_done[j])
Surfaces_done[i]=geom.add_surface(Line_loops_done[i])
points, cells, point_data, cell_data, field_data = pygmsh.generate_mesh(geom)
meshio.write('test7.vtu', points, cells, cell_data=cell_data)
from pygmsh.
I am sorry, it seems like I have some problems with putting the code, did I do something wrong - is the code to big?
from pygmsh.
No idea, probably. Anyways it's too big for me to review. Best generate a minimal example that highlights your problem.
from pygmsh.
Ok, I will describe what I did and put part of the code that highlights my problem if that would be necessary. I went line by line from geo file and recognize points,splines, line loops or surfaces. After that I would extract data from that line and put it in dictionaries Points, Spline,...where key was id of point,spline or lineloop and values are coordinates or in case of Spline ,for example, values are ids of point which create that Spline. After that I went through all dictionary values and add points to geometry,add splines to geometry(with fuctions geom.add_point etc.) and than I called
points, cells, point_data, cell_data, field_data = pygmsh.generate_mesh(geom) meshio.write('test7.vtu', points, cells, cell_data=cell_data)
.
I can see my structure in paraview with all points,splines,lineloops,...But I don't have the mesh.
How can I make mesh from here? And I copy-paste my previous questions:
Is it possible to make the quadrilateral mesh in pygmsh?How can I manipulate and remember only points on the surface of geometric character and the points which create triangular mesh? I will appreciate all links and examples you have on this too.
Thank you very much.
from pygmsh.
For quad meshes see here: https://github.com/nschloe/pygmsh/blob/master/test/test_quads.py.
For the rest I cannot help you. You'll have to provide a minimal example that fails.
from pygmsh.
Ok, I will create perfect minimal example :)
Cheers
from pygmsh.
Hi , while I was doing minimal example I figured it out. The problem is that I have gmsh2.10 version and for this I have to have gmsh3.0 which I am unable to install on ubuntu. In my minimal example I didn't use Ruled surface and it works perfectly well and creates mesh. So does anyone know how to install gmsh3.0 on ubuntu's latest version?
from pygmsh.
I will put here my minimal example so that anyone who has similar problem(putting data from external geo.file inside of pygmsh python code) can see what I've done. This is data inside of my geo file:
Point(1)={0,0,0,1/10};
Point(2)={1,0,0,1/10};
Point(3)={1,1,0,1/10};
Point(4)={0,1,0,1/10};
Line(5)={1,2};
Line(6)={2,3};
Line(7)={3,4};
Line(8)={4,1};
Line Loop(9)={5,6,7,8};
Plane Surface(10)={9};
And this is my python code:
import pygmsh
import numpy as np
import meshio
import string
from tiz import r_char,f_id
Points=dict()
Points_done=dict()
Line_loops=dict()
Line_loops_done=dict()
Line=dict()
Line_done=dict()
Plane_surface=dict()
with open('nico.txt', 'r') as myfile:
for line in myfile:
text=line
if 'Point'in text and text:
text=r_char(text)
if text:
s=f_id(line)
Points[s]=text
elif 'Line Loop' in text:
text=r_char(text)
if text:
s=f_id(line)
Line_loops[s]=text
elif 'Line' in text:
text=r_char(text)
if text:
s=f_id(line)
Line[s]=text
elif 'Plane Surface' in text:
text=r_char(text)
if text:
s=f_id(line)
Plane_surface[s]=text
myfile.close()
geom = pygmsh.built_in.Geometry()
#adding points
for i in Points:
Points_done[i]=geom.add_point(Points[i],0.1)
#adding lines
for i in Line:
helper=[]
for j in Line[i]:
j=str(j)
helper.append(Points_done[j])
Line_done[i]=geom.add_line(helper[0],helper[1])
#adding line loop
for i in Line_loops:
helper=[]
for j in Line_loops[i]:
j=str(j)
helper.append(Line_done[j])
Line_loops_done[i]=geom.add_line_loop(helper)
#adding surface
for i in Plane_surface:
for j in Plane_surface[i]:
j=str(j)
geom.add_plane_surface(Line_loops_done[j])
points, cells, point_data, cell_data, field_data = pygmsh.generate_mesh(geom)
meshio.write('nico.vtu', points, cells, cell_data=cell_data)
from pygmsh.
Sorry , the code is still to big to be inside of "insert code" space :(
from pygmsh.
You can format block code with triple-backticks. I did that for you now. See https://help.github.com/articles/creating-and-highlighting-code-blocks/.
from pygmsh.
Ok, thank you. I will now know it-for the future conversation :)
Have a nice day
from pygmsh.
As to getting Gmsh 3 on Ubuntu, try downloading the source code and compiling it. I haven't tried that lately under Ubuntu, but this is what I'm doing routinely these days under Debian which is quite similar. It should be fairly straightforward; otherwise ask on the Gmsh list if you get stuck.
from pygmsh.
from pygmsh.
I've got a backports PPA for Gmsh up and running for Ubuntu; check out https://launchpad.net/~nschloe/+archive/ubuntu/gmsh-backports.
from pygmsh.
Related Issues (20)
- Unable to create Second Order Incomplete elements
- Error and warnings in tests
- The example "ball with mesh refinement" prints errors: TypeError: <lambda>() takes 5 positional arguments but 6 were given
- The "Flat shapes" section in the README has some broken links for images
- add_surface with occ geometry kernel broken HOT 1
- How to generate tetrahedron from a mesh?
- Error with set_mesh_size_callback HOT 1
- Removing isolated solid phases
- Supress output console
- Support calling add_physical multiple times with the same label
- Raw code alternative for periodic curve
- How to create a rotationally symmetric geometry HOT 1
- Generate Hexahedral mesh inside complex geometry using gmsh
- py30-pygmsh missing dependencies gmsh (macport installation)
- Alternative for add_raw_code in pygmsh 7.1.17
- Creating Meshes with no Quads
- It is recommended to upgrade to python 3.12
- Several warnings around pytest
- Removing surface and point after creating Volume
- Does the pygmesh installer seem to have stopped being updated?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pygmsh.