# Multipy mesh with coefficient

**URL:** <https://fenicsproject.discourse.group/t/multipy-mesh-with-coefficient/7065>\
**Category:** Uncategorized\
**Created:** [November 12, 2021, 2:03pm UTC](https://fenicsproject.discourse.group/t/multipy-mesh-with-coefficient/7065 "2021-11-12T14:03:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![giannoko](https://avatars.discourse-cdn.com/v4/letter/g/7c8e57/32.png) [@giannoko](https://fenicsproject.discourse.group/u/giannoko)\
**Post date:** [November 12, 2021, 2:03pm UTC](https://fenicsproject.discourse.group/t/multipy-mesh-with-coefficient/7065/1 "2021-11-12T14:03:44Z")

</div>

Hello,

I have an 1D mesh ranging from 0 to 1. How can I multiply all the nodes with a constant coefficient to get a new mesh?

---

<div class="post-metadata">

**Author:** ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)\
**Post date:** [November 12, 2021, 2:47pm UTC](https://fenicsproject.discourse.group/t/multipy-mesh-with-coefficient/7065/2 "2021-11-12T14:47:46Z")

</div>

You can use the `scale` method to multiply all mesh vertex coordinates by a constant:

```python
from dolfin import *
N = 4
factor = 3
mesh = UnitIntervalMesh(N)

# Scale mesh by `factor`:
mesh.scale(factor)

# Equivalent built-in function:
#mesh = IntervalMesh(N,0,factor)

# Check results:
print(FunctionSpace(mesh,"CG",1).tabulate_dof_coordinates())

```

---

<div class="post-metadata">

**Author:** ![giannoko](https://avatars.discourse-cdn.com/v4/letter/g/7c8e57/32.png) [@giannoko](https://fenicsproject.discourse.group/u/giannoko)\
**Post date:** [November 12, 2021, 3:31pm UTC](https://fenicsproject.discourse.group/t/multipy-mesh-with-coefficient/7065/3 "2021-11-12T15:31:14Z")

</div>

Thank you. Works !!!

---

<div class="post-metadata">

**Author:** ![jotelha](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/jotelha/32/6842_2.png) [@jotelha](https://fenicsproject.discourse.group/u/jotelha)\
**Post date:** [June 25, 2024, 3:25pm UTC](https://fenicsproject.discourse.group/t/multipy-mesh-with-coefficient/7065/4 "2024-06-25T15:25:59Z")

</div>

Hello,

How would this be done in dolfinx, i.e. with the Mesh object of dolfinx.mesh? Say, I have solved a problem dimensionless and want to scale solution and mesh back to SI units.

I believe I can scale the solution simply by multiplying with a factor, as discussed here, [How to scale deformation solution by axial directions](https://fenicsproject.discourse.group/t/how-to-scale-deformation-solution-by-axial-directions/5037), and I would like to do the same with the mesh, to eventually write out the scaled solution on the scaled mesh with the standard io methods, e.g. the dolfinx.io.XDMFFile writer.

If “mesh” is a Mesh object, I can access the coordinates with mesh.geometry.x, but these are read-only attributes.

Thanks a lot for suggestions.

---

<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 25, 2024, 3:34pm UTC](https://fenicsproject.discourse.group/t/multipy-mesh-with-coefficient/7065/5 "2024-06-25T15:34:08Z")

</div>

`mesh.geometry.x[:,:] *= c`  
would do it, as you cannot reassigning the `x`-array, But you can modify its entries.

---

<div class="post-metadata">

**Author:** ![jotelha](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/jotelha/32/6842_2.png) [@jotelha](https://fenicsproject.discourse.group/u/jotelha)\
**Post date:** [June 25, 2024, 3:47pm UTC](https://fenicsproject.discourse.group/t/multipy-mesh-with-coefficient/7065/6 "2024-06-25T15:47:50Z")

</div>

Thank you! That was simple enough 🙂
