# ANSYS Fluent to FEniCSx

**URL:** <https://fenicsproject.discourse.group/t/ansys-fluent-to-fenicsx/10934>\
**Category:** General\
**Created:** [April 13, 2023, 7:40pm UTC](https://fenicsproject.discourse.group/t/ansys-fluent-to-fenicsx/10934 "2023-04-13T19:40:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karlosjusus](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karlosjusus](https://fenicsproject.discourse.group/u/Karlosjusus)\
**Post date:** [April 13, 2023, 7:40pm UTC](https://fenicsproject.discourse.group/t/ansys-fluent-to-fenicsx/10934/1 "2023-04-13T19:40:14Z")

</div>

Hi everyone!  
I have the following problem.  
I have obtained a solution with ANSYS Fluent and I want to analyze it with FEniCSx. The mesh is in Nastran format and I have converted it to XDFM with the following line

```auto
 meshio convert mesh_12_nastran.bdf venturi_coarse.xdmf

```

I get from Fluent a .txt file with 4 columns. (vx.txt)  
the number of the point, the 3 spatial coordinates and the value of the function in these points.

my code in FEniCSx:

```auto
import dolfinx
from mpi4py import MPI
from petsc4py import PETSc
import numpy as np
import math
import ufl
from ufl import (FacetNormal, FiniteElement, Identity, Measure, TestFunction, TrialFunction, VectorElement,
                 as_vector, div, dot, ds, dx, inner, lhs, grad, nabla_grad, rhs, sym)
from dolfinx.fem.petsc import (apply_lifting, assemble_matrix, assemble_vector, 
                               create_vector, create_matrix, set_bc)

from dolfinx.fem import (Constant, Function, FunctionSpace, 
                         assemble_scalar, dirichletbc, form, locate_dofs_topological, set_bc)

with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "venturi_coarse.xdmf", "r") as xdmf:
    domain = xdmf.read_mesh(name="Grid")

s_cg1 = FiniteElement("CG", domain.ufl_cell(), 1)
Q = dolfinx.fem.FunctionSpace(domain, s_cg1)

vx_np = np.loadtxt('vx.txt')
vx_aux = []
vx_aux[:] = vx_np[:,4]

vx = Function(Q)
vx.x.array[:]=vx_aux[:]

with dolfinx.io.XDMFFile(domain.comm, "Plot/vx.xdmf", "w") as file:
    file.write_mesh(domain)
    file.write_function(vx)

```

and obtain

 ![venturi_vx](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/2/28a4913a0a033ff4b8b6e5a1e26593827f7cdfb9.png)

but it should be

 ![MicrosoftTeams-image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/7/7ee159fa3c0fdf587d1055aa3f296dfdbed701dd.png)

Does anyone have any ideas? I think the vertices are not ordered in the same way.  
Besides solving it, I would like to know how I can, given a point, find the nearest vertex (coordinates and mesh number).

In this folder are all the files

> **[136.02 MB folder on MEGA](https://mega.nz/folder/lQUnWa4D#WJhvRPoCgiO_0736IRG6IQ)**
>
> 4 files

---

<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 14, 2023, 5:38am UTC](https://fenicsproject.discourse.group/t/ansys-fluent-to-fenicsx/10934/2 "2023-04-14T05:38:07Z")

</div>

You are making a whole lot of assumptions on the ordering of the mesh vertices-\>dofs here.  
Please see: [I/O from XDMF/HDF5 files in dolfin-x - #32 by dokken](https://fenicsproject.discourse.group/t/i-o-from-xdmf-hdf5-files-in-dolfin-x/3122/32)

What you probably could do would be to read in a vertex marker in DOLFINx based on the function data (xdmf.read\_meshtags) and map that input to a CG-1 function.

---

<div class="post-metadata">

**Author:** ![Karlosjusus](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karlosjusus](https://fenicsproject.discourse.group/u/Karlosjusus)\
**Post date:** [April 14, 2023, 3:42pm UTC](https://fenicsproject.discourse.group/t/ansys-fluent-to-fenicsx/10934/3 "2023-04-14T15:42:20Z")

</div>

I have a couple of questions.

- read\_meshtags

```auto
c = xdmf.read_meshtags(domain , name = 'Grid')
print(len(c.indices))

```

show the number of cells, no the number of vertex.

```auto
print(domain.topology.original_cell_index)
[372552 372567 372553 ... 372758 372761 372760]

```

This means that the cell 0 is the cell 372552 in Fluent?  
Is there something similar with vertices instead of cells?  
I understand that this is your suggestion @dokken

- Function CG-1

```auto
f = Function(Q)
print(f.vector.size)
447100

```

prints the number of vertexs.  
can I define a function with values in the cells?
