# Inserting Values into RHS Vector

**URL:** <https://fenicsproject.discourse.group/t/inserting-values-into-rhs-vector/13509>\
**Category:** General\
**Created:** [February 5, 2024, 3:18pm UTC](https://fenicsproject.discourse.group/t/inserting-values-into-rhs-vector/13509 "2024-02-05T15:18:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaccandels](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/zaccandels/32/6204_2.png) [@zaccandels](https://fenicsproject.discourse.group/u/zaccandels)\
**Post date:** [February 5, 2024, 3:18pm UTC](https://fenicsproject.discourse.group/t/inserting-values-into-rhs-vector/13509/1 "2024-02-05T15:18:31Z")

</div>

As a motivating example, suppose I want to set up the linear algebra problem for the BVP

-\nabla^2 u = \delta(\mathbf{x} - \mathbf{x}\_0) \tag{1}

where u: \Omega \subset \mathbb{R}^2 \to \mathbb{R}. Choosing test functions from a finite-dimensional function space V\_h = \mathrm{span}\{\phi\_i| i = 1,...,n\}, (1) can be phrased as follows: find u\_h \in V\_h st

\int\_{\Omega}\nabla u\_h \cdot \nabla\phi\_i dx = \int\_{\Omega} \delta \phi\_i dx \tag{2} \\ = \phi\_i(\mathbf{x}\_0)

for each \phi\_i, \; i = 1,...,n. Now, my question is the following - if b denotes the rhs vector of the corresponding linear algebra problem, how do we assemble it? From Delta Implementation we can query the values of basis functions at specific points. However, the important part now is to put these values into b. In a more mathematical form, if \mathbf{x}\_0 \in \mathrm{supp}(\phi\_{i\_n}) for n = 1,2,3, how do we find the entries of b corresponding to each index i\_n and insert \phi\_{i\_n}(\mathbf{x}\_0) into b\_{i\_n}?

---

<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:** [February 5, 2024, 8:09pm UTC](https://fenicsproject.discourse.group/t/inserting-values-into-rhs-vector/13509/3 "2024-02-05T20:09:03Z")

</div>

Closing this thread as it as been answered at:

> [@Point Sources (Redux)](https://fenicsproject.discourse.group/t/point-sources-redux/13496/6):
>
> Following my post above, with a minor adaptations, a point source can be implemented as follows: # Create a point source for Poisson problem # Author: Jørgen S. Dokken # SPDX-License-Identifier: MIT from mpi4py import MPI from petsc4py import PETSc import dolfinx import dolfinx.fem.petsc import numpy as np import ufl def compute\_cell\_contributions(V, points): # Determine what process owns a point and what cells it lies within mesh = V.mesh \_, \_, owning\_points, cells = dolfinx.cp…

---

<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:** [February 5, 2024, 8:09pm UTC](https://fenicsproject.discourse.group/t/inserting-values-into-rhs-vector/13509/4 "2024-02-05T20:09:11Z")

</div>


