# Meshtool from vtk to carp_txt generates vertices far out of original mesh

I generated my own paraboloid mesh using a python script [1] and saving it in .vtk format. I checked the shape of the mesh in Paraview and all seems correct.

Now I want to run a simulation on this mesh, so I converted it to carp_txt using meshtool:

meshtool convert -imsh=surface_mesh -ifmt=vtk -omsh=surface_mesh -ofmt=carp_txt

When I check the output .pts file, I notice that new vertices are created, that are far out of the original bounds of the mesh. the original mesh was situated in (x,y,z) \in [0,40]x[0,40]x[-0.05,20,05]. Some points however have the following coordinate:

0.000000 1.573437 272009238956254653579264.000000
0.000000 1.721875 272007851847569423466496.000000
0.000000 1.924219 -107374232.000000
0.000000 2.090625 -107374160.000000

...

So the z-coordinate is very far off for these points. I additionally do not manage to visualize the output mesh using meshalyzer.

My question is thus:

a) Why does this happen?
b) When trying to run a simulation [2] on this mesh, I get the error
L5 : error: Empty stimulus[0] electrode def! Aborting!
Would this be related to this weird effect in the carp_txt mesh or is something else going on?

For reference, here is

[1] the python script I used to generate the mesh

""" Creates paraboloid surface mesh with small thickness """

import numpy as np
import pyvista as pv

# Define the function for the surface
def surface_func(x, y):
return -0.025*(x-20)**2 - 0.025*(y-20)**2 + 20

# Define grid points
x = np.arange(0, 40.1, 0.25)
y = np.arange(0, 40.1, 0.25)
X, Y = np.meshgrid(x, y)

# Calculate Z coordinates using the surface function
Z_top = surface_func(X, Y) + 0.05
Z_bottom = surface_func(X, Y) - 0.05

# Create PyVista meshes for the top and bottom surfaces
top_surface = pv.StructuredGrid(X, Y, Z_top)
bottom_surface = pv.StructuredGrid(X, Y, Z_bottom)

# Merge the two surfaces to create a thickened mesh
thickened_mesh = top_surface + bottom_surface

# Write the mesh to a VTK file
thickened_mesh.save('surface_mesh.vtk')

[2] the parameters of the stimulus

stim[0].name = "S1"
stim[0].crct.type = 0
stim[0].elec.geom_type = 2
stim[0].elec.p0[0] = 0.
stim[0].elec.p0[1] = 0.
stim[0].elec.p0[2] = 0.
stim[0].elec.p1[0] = 4.
stim[0].elec.p1[1] = 40.
stim[0].elec.p1[2] = 20.
stim[0].elec.dump_vtx_file = 1
stim[0].ptcl.stimlist = 0
stim[0].ptcl.duration = 1.0
stim[0].pulse.strength = 100.0

+1 vote
by (500 points)
selected

Dear Marie, I checked the VTK file written by pyvista. The version was not the problem, it was the data type of the points. We implicitly assume single precision values, but the data type of the values in the file written by pyvista was of double precision. I changed the code in meshtool accordingly.

Cheers, Matthias.
by (200 points)
Dear Matthias,

Thank you for the clarification. With the update of meshtool, I could convert the vtk mesh to openCARP format and visualize it with meshalyzer.

I suppose my second question on the simulation not working with the old mesh, will be solved. I am checking that now. In case not, I will create a new issue, since it will probably unrelated to the meshtool issue.

Cheers, Marie
by (3.6k points)
Hi Marie,

Could you please check whether your vtk file is ascii or binary? Meshtool support both type of files and you can specify it using -ifmt vtk (for ascii files) or -ifmt vtk_binary (for binary files).

Cheers,

Jorge
by (200 points)
Hi Jorge,

Thank you for the suggestion. After the update of meshtool Matthias refers to, I could successfully convert the vtk mesh to openCARP format.

Cheers,
Marie