Hi,

I have a lot (hundred to thoundand) of boundary conditions (each one depends on some calculated array values) and want to factorize my code using a loop.

Is there a way to use a for loop inside a varf/therm definition ?

Best regards.

Hi,

I have a lot (hundred to thoundand) of boundary conditions (each one depends on some calculated array values) and want to factorize my code using a loop.

Is there a way to use a for loop inside a varf/therm definition ?

Best regards.

I am assuming you mean Dirichlet boundary conditions? There is afaik no way to have a loop in your varf, but it should be possible to find a workaround. Instead of using `on()`

you can assemble the system matrix / rhs vector without specifying Dirichlet BC and impose them later on. Use the command setBC (FreeFEM version >= 4.11 required, example code) to modify the matrix and modify the rhs vector manually according to your boundary data.

This requires a bit of bookkeeping (Which degree of freedom (dof) belongs to which boundary and what is the boundary value to be imposed?). For a single boundary you can get a vector (length: number of dofs) which entries are equal to 1, if the dof belongs to the boundary, else 0:

```
fespace Vh(Th, P1);
varf vGamma(u, v) = on(gamma, u = 1);
real[int] marker = vGamma(0, Vh, tgv = -1);
```

To generalize for multilple boundaries, I would iterate over gamma and set up two vectors. One vector that indicates if a dof belongs to any part of the boundary with a Dirichlet BC (1: on boundary, else 0) and one vector that contains the dirichlet boundary data.