# Initial conditions for mixed elements with vector and scalar elements

**URL:** <https://fenicsproject.discourse.group/t/initial-conditions-for-mixed-elements-with-vector-and-scalar-elements/14381>\
**Category:** dolfinx\
**Tags:** mesh, manifold\
**Created:** [April 22, 2024, 6:09pm UTC](https://fenicsproject.discourse.group/t/initial-conditions-for-mixed-elements-with-vector-and-scalar-elements/14381 "2024-04-22T18:09:43Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [June 23, 2024, 9:54am UTC](https://fenicsproject.discourse.group/t/initial-conditions-for-mixed-elements-with-vector-and-scalar-elements/14381/8 "2024-06-23T09:54:12Z")

</div>

It is a bit hard for me to decipher your issue.  
However, I think you want something along these lines (no pun intended):

```python
from mpi4py import MPI
import basix.ufl
import dolfinx
import ufl
import numpy as np

nodes = np.array([[.0, 0.], [0.5, 0.], [0.25,0.3],
                  [1., 0.0], [0.75, -0.2]], dtype=np.float64)
connectivity = np.array([[0, 1, 2], [1, 3, 4]], dtype=np.int64)
c_el = ufl.Mesh(basix.ufl.element("Lagrange", "interval", 2, shape=(nodes.shape[1],)))
domain = dolfinx.mesh.create_mesh(MPI.COMM_SELF, connectivity, nodes, c_el)

with dolfinx.io.VTXWriter(domain.comm, "test.bp", domain, engine="BP4") as bp:
    bp.write(0.0)

V1 = domain.ufl_domain().ufl_coordinate_element()
V2 = basix.ufl.element("CG", domain.basix_cell(), 2)

ME2 = dolfinx.fem.functionspace(domain, basix.ufl.mixed_element([V1, V2]))

uv = dolfinx.fem.Function(ME2)
uv.sub(0).interpolate(lambda x: (-0.1+0.2*x[0], +0.3+0.3*x[1]))

# Permute dofmap
V_geom = dolfinx.fem.functionspace(domain, V1)
u_geom = dolfinx.fem.Function(V_geom)
np.testing.assert_allclose(domain.geometry.x, V_geom.tabulate_dof_coordinates(), atol=1e-13)
u_geom.interpolate(uv.sub(0))

with dolfinx.io.VTXWriter(domain.comm, "test2.bp", [u_geom], engine="BP4") as bp:
    bp.write(0.0)

domain.geometry.x[:, :2] += u_geom.x.array.reshape(-1, domain.geometry.dim)

with dolfinx.io.VTXWriter(domain.comm, "test3.bp", domain, engine="BP4") as bp:
    bp.write(0.0)

```

yielding

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

---

_[View the full topic](https://fenicsproject.discourse.group/t/initial-conditions-for-mixed-elements-with-vector-and-scalar-elements/14381)._
