First time here? Checkout the FAQ!
x
0 votes
by (630 points)
Hello

My question is about the use of carputils. I would like to import a .vtk file as a mesh. However, I cannot seem to find how to do this in the run.py script. Do I need to use meshtools or just the mesh class?

An example of how to do this in the run.py script would be greatly appreciated!

Thank you very much!

Lore

2 Answers

+1 vote
by (7.8k points)

The command for converting a mesh using meshtool is

meshtool convert -imsh=input_mesh.vtk -omsh=output_mesh.elem

By specifying the .vtk and .elem extensions you implicitly tell meshtool that you want to convert from VTK to CARP formats, thus you dont need to explicitly use the -ifmt / -ofmt options.

Best wishes, Aurel

0 votes
by (3.5k points)
Hi Lore,

You can convert vtk files using meshtool convert mode. Once you have the mesh in the openCARP format you can import the mesh using carputils with meshname = 'nameofyourmesh'.

Best,

Jorge
by (630 points)
Hi Jorge

Thank you  a lot for the quick response! There are a few aspects that are still unclear to me.

1) Which one of the possible output formats is the openCARP format?
" The supported output formats are -- carp_txt, carp_bin, vtk, vtk_bin, vtk_polydata, mmg, stellar"
If I look at the meshes generated by the program , I see a folder with numerous types of files.

2) If I understand the use of meshtool correctly, the I should add in my run.py script the following code:
        imsh = '/home/username/my_mesh.vtk' # path to input file
        ifmt = 'vtk' # format of input file
        omsh = os.path.join(DIR,'meshes') # path to output file
        ofmt = 'carp_bin' # format of output file
        heart = ['convert', '-imsh=' + imsh,
                      '-ifmt=' + ifmt,
                      '-omsh=' + omsh,
                      '-ofmt=' + ofmt]
        cmd += heart
However, how can I then know the name of my mesh (the converted mesh in openCARP format), which I need in the run.py script as well?

Thank you a lot in advance!

Best

Lore
by (3.5k points)
Hi Lore,

You can use either carp_txt which is an ascii file or carp_bin which is a binary file. You can read more about the openCARP file format in our user manual in the documentation section.
Meshtool can be executed directly from the terminal or you can call it from your carputils script using the subprocess module. In your code in omsh you have to append a name for the output mesh. It should look like this /home/username/mesh/my_mesh_converted.  Here is a short example:

subprocess.run(["meshtool", "convert", "-imsh=my_mesh", "-omsh=my_mesh_converted", "-ifmt=vtk","-ofmt=carp_bin"])

after that you can import the mesh with carputils by creating a variable with a name as a string

meshname = 'my_mesh_converted'

and add it to cmd list like this:

cmd += ['-meshname', meshname]

Best,

Jorge
Welcome to openCARP Q&A. Ask questions and receive answers from other members of the community. For best support, please use appropriate TAGS!
architecture, carputils, documentation, experiments, installation-containers-packages, limpet, slimfem, website, governance
...