Can I edit mesh points after a solution, in order to rotate the solution.

More
5 years 3 months ago #1870 by jameslowman
Cheers,

I am attempting to solve a simple PDE on a defined mesh, then I wish to rotate that solution (the mesh is centered around the origin) so that it may be interpolated onto another mesh.

I know I have access to the points by means of:

for v in mesh.vertices:
print(v.point)

but unfortunately, I am unable to edit the points in the same manner.

Is there a way to edit a meshes domain location after a solution is saved on a gridfunction?
More
5 years 3 months ago #1871 by mneunteufel
Hi jameslowman,

it is possible to copy the mesh and to interpolate the old GridFunction into a new one.
Maybe the attached code can help.

Best,
Michael

File Attachment:

File Name: movingmesh.py
File Size:0 KB
Attachments:
The following user(s) said Thank You: jameslowman
More
5 years 3 months ago - 5 years 3 months ago #1872 by jameslowman
Thanks so much for your quick reply, and code. I think you may have solved my problem.
Last edit: 5 years 3 months ago by jameslowman.
More
5 years 3 months ago - 5 years 3 months ago #1873 by jameslowman
For all who encounter this problem in the future: mneunteufel has the answer in his code generously shared in his response. You can edit mesh points directly (and at any point in execution) via the ngmesh.Points function:

for p in mesh.ngmesh.Points():
px,py = p[0], p[1]
p[0] = func1(px,py)
p[1] = func2(px,py)

where func1, func2 are whatever you choose to mutate your mesh.

Thanks again mneuteufel.
Last edit: 5 years 3 months ago by jameslowman.
More
2 years 8 months ago #4322 by walker_tr9
The last post gives an ok method, but is there a way to update the mesh points as a numpy array?  The solution above assumes we have explicit functions to give new mesh coordinates.  It would be more convenient to pass in my own array.  And yes, I already know about the mesh deformation method.
More
2 years 8 months ago #4324 by joachim
within the latest nightly you find a 

mesh.Coordinates()

which returns a numpy view of the point coordinates
 
Time to create page: 0.103 seconds