# Generate synthetic data!

**URL:** <https://fenicsproject.discourse.group/t/generate-synthetic-data/6673>\
**Category:** Uncategorized\
**Created:** [September 27, 2021, 9:23am UTC](https://fenicsproject.discourse.group/t/generate-synthetic-data/6673 "2021-09-27T09:23:33Z")\
**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:** [September 27, 2021, 11:56am UTC](https://fenicsproject.discourse.group/t/generate-synthetic-data/6673/2 "2021-09-27T11:56:04Z")

</div>

I would strongly suggest that you simplify your problem to a minimal code, following the examples in:

> [@Read before posting: How do I get my question answered?](https://fenicsproject.discourse.group/t/read-before-posting-how-do-i-get-my-question-answered/21/4):
>
> The following is a list of well constructed questions adhering to the guidelines above: [Getting cell dofs for vector valued function space in dolfinx](https://fenicsproject.discourse.group/t/getting-cell-dofs-for-vector-valued-function-space-in-dolfinx/5167)[Problem with 3D nedelec element](https://fenicsproject.discourse.group/t/problem-with-3d-nedelec-element/5423)[What is the “default” linear solver/preconditioner?](https://fenicsproject.discourse.group/t/what-is-the-default-linear-solver-preconditioner/5243)[Setting Dirichlet boundary condition/constraint on 3D edges](https://fenicsproject.discourse.group/t/setting-dirichlet-boundary-condition-constraint-on-3d-edges/5249)

A general issue I see with your current approach is that you use `compute_vertex_values()`

> [@hatem1264](#):
>
> `noise.set_local(noise_level * (1 - 2 * np.random.rand(len(ud.compute_vertex_values()))))`

As your function is not a CG 1 function, but a CG2 function, you should use `ud.vector().get_local()` to get the array of all degrees of freedom.

In general, I would suggest using a function assigner ([Usage of FunctionAssigner - #2 by dokken](https://fenicsproject.discourse.group/t/usage-of-functionassigner/4868/2)) to assign the noise to the mixed solution.

As a last advice, note that you are not using a P2-P1 pair, but a P2-P2 pair:

> [@hatem1264](#):
>
> ```auto
> P2 = VectorElement('P', triangle, 2)
> P1 = FiniteElement('P', triangle, 2)
> TH = MixedElement([P2, P1])
> 
> ```

---

_[View the full topic](https://fenicsproject.discourse.group/t/generate-synthetic-data/6673)._
