# Saving output at points selected by user when running the IPCS solver

**URL:** <https://fenicsproject.discourse.group/t/saving-output-at-points-selected-by-user-when-running-the-ipcs-solver/17190>\
**Category:** dolfinx\
**Tags:** io, dolfinx\
**Created:** [March 12, 2025, 4:05am UTC](https://fenicsproject.discourse.group/t/saving-output-at-points-selected-by-user-when-running-the-ipcs-solver/17190 "2025-03-12T04:05:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fontsize](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/fontsize/32/7970_2.png) [@fontsize](https://fenicsproject.discourse.group/u/fontsize)\
**Post date:** [March 12, 2025, 4:05am UTC](https://fenicsproject.discourse.group/t/saving-output-at-points-selected-by-user-when-running-the-ipcs-solver/17190/1 "2025-03-12T04:05:04Z")

</div>

I’m running the code in [jorgensd/dolfinx\_ipcs: Simple IPCS solver for dolfinx](https://github.com/jorgensd/dolfinx_ipcs).

I ran the code as follows:

- download the docker and git clone the repository;
- run `python3 create_and_convert_2D_mesh.py` in command line;
- run `python3 DFG_benchmark.py` in command line.

And I make sure I can save output successfully. I changed the `DFG_benchmark.py` as follows:

```python
def IPCS(outdir: Path, dim: int, degree_u: int,
         jit_options: dict = {"cffi_extra_compile_args": ["-Ofast", "-march=native"], "cffi_libraries": ["m"]}):
    ......
    # Solve problem
    N = int(T / dt)
    if has_tqdm:
        time_range = tqdm(range(N))
    else:
        time_range = range(N)
    
    # Save Velocity and Time.
    velocity = []
    U = uh.x.array[0::2].reshape((-1,1))
    V = uh.x.array[1::2].reshape((-1,1))
    UV = np.hstack((U, V))
    velocity.append(UV)
    time_step = []
    time_step.append(t)

    for i in time_range:
        ......
        with common.Timer("~IO"):
            if i % 5 == 4:
                # print('Current time: ', t)
                # print('Current Iteration: ', i)
                U = uh.x.array[0::2].reshape((-1,1))
                V = uh.x.array[1::2].reshape((-1,1))
                UV = np.hstack((U, V))
                velocity.append(UV)
                time_step.append(t)

    savemat('./DFG-2D3.mat', \
            {'U_star': np.array(velocity), 't': np.array(time_step).reshape((-1,1))}, \
            do_compression=True)
    print('matrix file saved :D')

```

The above code saves the output at the mesh nodes, which is not free.

Now I want to save the output at points selected by user, such as (0,0), (0.1,0.1), …, how can I achieve this?

---

<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:** [March 12, 2025, 7:14am UTC](https://fenicsproject.discourse.group/t/saving-output-at-points-selected-by-user-when-running-the-ipcs-solver/17190/2 "2025-03-12T07:14:16Z")

</div>

See for instance the “microphone” implementation in: [Implementation — FEniCSx tutorial](https://jsdokken.com/dolfinx-tutorial/chapter2/helmholtz_code.html#computing-the-pressure-at-a-given-location)

---

<div class="post-metadata">

**Author:** ![fontsize](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/fontsize/32/7970_2.png) [@fontsize](https://fenicsproject.discourse.group/u/fontsize)\
**Post date:** [March 13, 2025, 3:24am UTC](https://fenicsproject.discourse.group/t/saving-output-at-points-selected-by-user-when-running-the-ipcs-solver/17190/3 "2025-03-13T03:24:43Z")

</div>

Thanks for replying.  
Now I know the function `eval()` can help me to evaluate Function at points x, but the `eval()` has two parameters:

```python
def eval(self, x: npt.ArrayLike, cells: npt.ArrayLike, u=None) -> np.ndarray:
        """Evaluate Function at points x, where x has shape (num_points, 3),
        and cells has shape (num_points,) and cell[i] is the index of the
        cell containing point x[i]. If the cell index is negative the
        point is ignored."""

```

I have two questions:

- My example is 2-dimensional, but x has shape (num\_points, 3), how can I solve this? Can I set the third number = 0?
- How can I get the `cell` for my all points? Can I set `cells=np.ones((num_points, ))`?

* * *

I solved the above questions!!! Just follow the tutorial: [Implementation — FEniCSx tutorial](https://jsdokken.com/dolfinx-tutorial/chapter2/helmholtz_code.html#computing-the-pressure-at-a-given-location)
