# Applying different valued matrix according to subdomain

**URL:** <https://fenicsproject.discourse.group/t/applying-different-valued-matrix-according-to-subdomain/12818>\
**Category:** General\
**Created:** [November 21, 2023, 6:23pm UTC](https://fenicsproject.discourse.group/t/applying-different-valued-matrix-according-to-subdomain/12818 "2023-11-21T18:23:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [November 21, 2023, 6:36pm UTC](https://fenicsproject.discourse.group/t/applying-different-valued-matrix-according-to-subdomain/12818/2 "2023-11-21T18:36:19Z")

</div>

Create a tensor function space of cellwise constant variables (DG 0).

> [@Different material properties in subdomains, tensor instead of scalar](https://fenicsproject.discourse.group/t/different-material-properties-in-subdomains-tensor-instead-of-scalar/9887/2):
>
> How do you expect a tensor to be assigned to a scalar function space? The space ("CG", 1) contains one degree of freedom at any point. It does not make sense to try to add a scalar to it. If you want to do so, you need to use a TensorElement or a TensorFunctionSpace as shown for a dummy rho below: import dolfinx from mpi4py import MPI import ufl import numpy as np mesh = dolfinx.mesh.create\_unit\_square(MPI.COMM\_WORLD, 10, 10) el = ufl.TensorElement("Lagrange", mesh.ufl\_cell(), 1, shape=(2, 2…

---

_[View the full topic](https://fenicsproject.discourse.group/t/applying-different-valued-matrix-according-to-subdomain/12818)._
