# Read VTK file of an old dolfin 2019's solution

**URL:** <https://fenicsproject.discourse.group/t/read-vtk-file-of-an-old-dolfin-2019s-solution/8109>\
**Category:** dolfinx\
**Created:** [April 21, 2022, 8:25am UTC](https://fenicsproject.discourse.group/t/read-vtk-file-of-an-old-dolfin-2019s-solution/8109 "2022-04-21T08:25:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![reckx\_sanchez](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/reckx_sanchez/32/3532_2.png) [@reckx\_sanchez](https://fenicsproject.discourse.group/u/reckx_sanchez)\
**Post date:** [April 21, 2022, 8:25am UTC](https://fenicsproject.discourse.group/t/read-vtk-file-of-an-old-dolfin-2019s-solution/8109/1 "2022-04-21T08:25:56Z")

</div>

Hello, I’m trying to read a VTK file into dolfinx. In this file I’ve defined a velocity field c which I’ll use in the bilinear form :

```auto
a = fem.form(c*inner(grad(u),grad(v))*dx)

```

This VTK file was generated with dolfin 2019 as a solution.

Dolfinx: 0.3.1.0

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [April 21, 2022, 8:35am UTC](https://fenicsproject.discourse.group/t/read-vtk-file-of-an-old-dolfin-2019s-solution/8109/2 "2022-04-21T08:35:56Z")

</div>

Save the function in xdmf format ( `XDMFFile`, use `write_checkpoint` rather than `write` to ensure the details of the FEM is preserved). Then it may be easier to read the xdmf file from dolfinx.

Disclaimer: I haven’t tried it myself, so I’m not certain if the file formats are completely compatible.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [April 21, 2022, 9:22am UTC](https://fenicsproject.discourse.group/t/read-vtk-file-of-an-old-dolfin-2019s-solution/8109/3 "2022-04-21T09:22:27Z")

</div>

In DOLFINx, we do not have any way of reading in data yet. This is work in progress.

---

<div class="post-metadata">

**Author:** ![reckx\_sanchez](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/reckx_sanchez/32/3532_2.png) [@reckx\_sanchez](https://fenicsproject.discourse.group/u/reckx_sanchez)\
**Post date:** [April 21, 2022, 9:24am UTC](https://fenicsproject.discourse.group/t/read-vtk-file-of-an-old-dolfin-2019s-solution/8109/4 "2022-04-21T09:24:02Z")

</div>

Thank you for your tips and help dparsons and dokken.

---

<div class="post-metadata">

**Author:** ![reckx\_sanchez](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/reckx_sanchez/32/3532_2.png) [@reckx\_sanchez](https://fenicsproject.discourse.group/u/reckx_sanchez)\
**Post date:** [April 21, 2022, 6:31pm UTC](https://fenicsproject.discourse.group/t/read-vtk-file-of-an-old-dolfin-2019s-solution/8109/5 "2022-04-21T18:31:19Z")

</div>

I’m trying to recreate the field I created in dolfin.  
Since I’m new in dolfinx I’ve being having some troubles. My goal is to create a subsection with some markers.  
My problem is that on side I’ve dof indices and on the other cells indices.

```auto
tau.x.array[cells] = np.full(num_cells_ref,tau_value)

```

It’s probably something really easy to fix, but I’m not really familiar with all dolfinx functions.  
Hole code:

```auto
import dolfinx
from mpi4py import MPI
import dolfinx.io
import ufl
import numpy as np

point = [.7, 0.55,0]

msh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 4, 4)
tdim = msh.topology.dim

V = dolfinx.fem.FunctionSpace(msh,('CG',1))
x = V.tabulate_dof_coordinates()

def marker1(x): return x[0] <= 0.5+1e-7

indices1 = dolfinx.mesh.locate_entities(msh, 2, marker1)

num_cells = msh.topology.index_map(tdim).size_local + \
            msh.topology.index_map(tdim).num_ghosts
            
cell_marker = np.zeros(num_cells, dtype=np.int32)
cell_marker[indices1] = 1
cell_tag = dolfinx.mesh.meshtags(msh, dim=tdim, indices=np.arange(num_cells),
                                         values=cell_marker)

tau = dolfinx.fem.Function(V)
tau.x.array[:] = 0

cells=cell_tag.indices[cell_tag.values==1]
num_cells_ref= len(cells)
tau_value=50

tau.x.array[cells] = np.full(num_cells_ref,tau_value)

```

---

<div class="post-metadata">

**Author:** ![reckx\_sanchez](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/reckx_sanchez/32/3532_2.png) [@reckx\_sanchez](https://fenicsproject.discourse.group/u/reckx_sanchez)\
**Post date:** [April 21, 2022, 6:53pm UTC](https://fenicsproject.discourse.group/t/read-vtk-file-of-an-old-dolfin-2019s-solution/8109/6 "2022-04-21T18:53:16Z")

</div>

this did the trick:

```auto
dof=dolfinx.fem.locate_dofs_topological(V,tdim,cells)

```
