# DirichletBC definition on boundary subdomain for component of vector valued function in FEniCS

**URL:** <https://fenicsproject.discourse.group/t/dirichletbc-definition-on-boundary-subdomain-for-component-of-vector-valued-function-in-fenics/2003>\
**Category:** variational formulation\
**Created:** [November 28, 2019, 6:37am UTC](https://fenicsproject.discourse.group/t/dirichletbc-definition-on-boundary-subdomain-for-component-of-vector-valued-function-in-fenics/2003 "2019-11-28T06:37:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tucker](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tucker](https://fenicsproject.discourse.group/u/tucker)\
**Post date:** [November 28, 2019, 6:37am UTC](https://fenicsproject.discourse.group/t/dirichletbc-definition-on-boundary-subdomain-for-component-of-vector-valued-function-in-fenics/2003/1 "2019-11-28T06:37:54Z")

</div>

I am linking to a post that I made on the stack exchange concerning FEniCS. I received a comment that it would be more appropriate to post the question here.

> <https://scicomp.stackexchange.com/questions/33897/dirichletbc-definition-on-boundary-subdomain-for-component-of-vector-valued-func>

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [November 28, 2019, 7:15am UTC](https://fenicsproject.discourse.group/t/dirichletbc-definition-on-boundary-subdomain-for-component-of-vector-valued-function-in-fenics/2003/2 "2019-11-28T07:15:29Z")

</div>

I would suggest to use a lagrange multiplier for the case of non flat surface. You can have a look at my library multiphenics ([https://gitlab.com/multiphenics/multiphenics](https://gitlab.com/multiphenics/multiphenics), see tutorial 3) or at @cdaversin mixed-dimensional branch on the dolfin repo.

---

<div class="post-metadata">

**Author:** ![tucker](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tucker](https://fenicsproject.discourse.group/u/tucker)\
**Post date:** [November 28, 2019, 2:42pm UTC](https://fenicsproject.discourse.group/t/dirichletbc-definition-on-boundary-subdomain-for-component-of-vector-valued-function-in-fenics/2003/3 "2019-11-28T14:42:00Z")

</div>

Fantastic! I will look closer intro the resources you provided and then respond to let you know if I was successful or not.

---

<div class="post-metadata">

**Author:** ![mapengfei-nwpu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/mapengfei-nwpu/32/117_2.png) [@mapengfei-nwpu](https://fenicsproject.discourse.group/u/mapengfei-nwpu)\
**Post date:** [November 17, 2020, 9:19am UTC](https://fenicsproject.discourse.group/t/dirichletbc-definition-on-boundary-subdomain-for-component-of-vector-valued-function-in-fenics/2003/4 "2020-11-17T09:19:08Z")

</div>

I find a way to solve this problem. You can just ignore the unnecessary components of a vector function. Here is a simple example.

```python
# V is a vector function space, we want to apply boundary condition on the first component.
very_large = 100000000000
bc = DirichletBC(V, (1, very_large, very_large), mesh_function, 1)
bv_map = bc.get_boundary_values()
for i in bv_map:
    if bv_map[i] < very_large:
        u.vector()[i] = bv_map[i]

```

---

<div class="post-metadata">

**Author:** ![tucker](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@tucker](https://fenicsproject.discourse.group/u/tucker)\
**Post date:** [November 17, 2020, 4:30pm UTC](https://fenicsproject.discourse.group/t/dirichletbc-definition-on-boundary-subdomain-for-component-of-vector-valued-function-in-fenics/2003/6 "2020-11-17T16:30:02Z")

</div>

I am able to strongly enforce Dirichlet conditions on a component of a vector valued function, e.g., the first component

> bc = DirichletBC(V.sub(0), Constant(1.0), mesh\_function, 1)

but what I was looking for here was to be able to strongly enforce a Dirichlet condition on the normal component of a vector field, where the normal is not aligned with any of the coordinate axes. Do you think that your approach would be applicable for my purposes?

Using a Lagrange multiplier is a great idea but this is a bit complicated since the multiplier would only be defined on the boundary. Since this problem was posted I chose to weakly enforce, by a penalty method, the Dirichlet condition by adding a term to the weak form.

---

<div class="post-metadata">

**Author:** ![mapengfei-nwpu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/mapengfei-nwpu/32/117_2.png) [@mapengfei-nwpu](https://fenicsproject.discourse.group/u/mapengfei-nwpu)\
**Post date:** [November 18, 2020, 5:24am UTC](https://fenicsproject.discourse.group/t/dirichletbc-definition-on-boundary-subdomain-for-component-of-vector-valued-function-in-fenics/2003/7 "2020-11-18T05:24:53Z")

</div>

Thank you very much and it is what I was searching for. My approach is not able to apply Dirichlet boundary condition on normal direction.
