Skip to content

Commit 1e85303

Browse files
committed
Document complex and Robin workflows and API migration
1 parent 9c2bc37 commit 1e85303

13 files changed

Lines changed: 530 additions & 2 deletions

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ If you use this software, please consider citing the following work:
181181
journal = {Advances in Engineering Software}
182182
}
183183

184+
## Multiple potentials, complex problems and Robin conditions
185+
186+
See [the usage and API migration guide](docs/complex-robin.md) for runnable
187+
Docker examples, parameter-file changes, component selection, Robin coefficients
188+
and the C++ interfaces introduced by the complex/multiple-potential extension.
189+
184190
# Licence
185191

186192
Please see the file [LICENSE](https://github.com/mathLab/pi-BEM/blob/master/LICENSE) for details

‎docs/complex-robin.md‎

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
# Multiple potentials, complex problems and Robin conditions
2+
3+
## Build and run with deal.II 9.6.0
4+
5+
From the repository root, build both configurations in the supplied container:
6+
7+
```sh
8+
docker run --rm -v "$PWD:/workspace" -w /workspace \
9+
dealii/dealii:v9.6.0-jammy bash -lc '
10+
cmake -S . -B build-docker/9.6.0 -GNinja \
11+
-DCMAKE_BUILD_TYPE=DebugRelease -DCMAKE_CXX_FLAGS=-Werror &&
12+
cmake --build build-docker/9.6.0 -j 4 &&
13+
cd build-docker/9.6.0 && ctest --output-on-failure
14+
'
15+
```
16+
17+
Executables are `bem_fma_2d` and `bem_fma_3d` in the build directory;
18+
Debug executables have the `.g` suffix. The first positional argument is the
19+
number of threads, not a parameter filename. Each program reads
20+
`parameters_bem_2.prm` or `parameters_bem_3.prm` in its working directory and
21+
writes `used_parameters_bem_2.prm` or `used_parameters_bem_3.prm`.
22+
23+
The sphere examples use paths relative to `samples/`. Keep each run's output
24+
separate, and copy both the parameter file and its grid directory:
25+
26+
```sh
27+
mkdir -p build-docker/9.6.0/example-complex
28+
cp -R samples/grids build-docker/9.6.0/example-complex/
29+
cp samples/ref_params_sphere_complex_DR_direct.prm \
30+
build-docker/9.6.0/example-complex/parameters_bem_3.prm
31+
docker run --rm -v "$PWD:/workspace" \
32+
-w /workspace/build-docker/9.6.0/example-complex \
33+
dealii/dealii:v9.6.0-jammy bash -lc '
34+
mpirun -np 2 ../bem_fma_3d 2
35+
'
36+
```
37+
38+
The default container user can run MPI. If running as root, also pass
39+
`-e OMPI_ALLOW_RUN_AS_ROOT=1 -e OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1` to Docker.
40+
The samples cover real/complex potentials, DN (Dirichlet/Neumann), DR
41+
(Dirichlet/Robin), NR (Neumann/Robin), and `direct`/`fma` methods.
42+
`Direct` assembles integral matrices and uses an iterative solver; it does not
43+
mean a dense direct factorization. FMA is supported in 3D only.
44+
45+
## Components and boundary-function slots
46+
47+
`Potential components` counts real-valued storage components. Each complex
48+
potential uses consecutive components: its real part at `i`, imaginary part at
49+
`i+1`. `Complex components` lists the real indices, with no overlapping pairs:
50+
51+
```text
52+
subsection Driver<3>
53+
set Potential components = 3
54+
set Complex components = 0
55+
set Set Global Refinement = true
56+
end
57+
```
58+
59+
This solves one complex potential in components 0 and 1, followed by a real
60+
potential in component 2. Parameter declarations provide up to 14 storage
61+
components. Every component has two boundary-function slots, numbered 0 and 1.
62+
63+
Under `BoundaryConditions<dim>`, old function subsection names must be replaced
64+
by `Potential <component> <slot> <dim>d`, `Wind function <component> <slot> <dim>d`
65+
and `Robin coefficients <component> <slot> <dim>d`. Potential expressions are
66+
scalar; wind expressions have `dim` entries and supply the normal derivative
67+
through their dot product with the outward normal. Functions used by the solve
68+
are evaluated at time zero. Output uses the configured stem for component 0
69+
and appends `_i` for later components.
70+
71+
## Robin conditions and geometry IDs
72+
73+
The 3D Robin function has three entries `a; b; g`, expressing
74+
`a*phi + b*dphi_dn = g`. The solver stores `a/b` and `g/b`, so `b` must be
75+
nonzero at every Robin node. For complex problems, the active component
76+
contains the real parts of all three coefficients and the following component
77+
contains their imaginary parts; the division is complex division.
78+
79+
For example, the condition `(2+3i)*phi + dphi_dn = 4+5i` in slot 0 is:
80+
81+
```text
82+
subsection BoundaryConditions<3>
83+
subsection Robin coefficients 0 0 3d
84+
set Function expression = 2; 1; 4
85+
end
86+
subsection Robin coefficients 1 0 3d
87+
set Function expression = 3; 0; 5
88+
end
89+
end
90+
```
91+
92+
Boundary-type lists select mesh **manifold IDs**. Their names retain the word
93+
"boundary" for compatibility. The three lists must be disjoint. The slot map
94+
is a flat comma-separated list of `manifold, slot` pairs:
95+
96+
```text
97+
subsection ComputationalDomain<3>
98+
subsection Boundary Conditions ID Numbers
99+
set Dirichlet boundary ids = 1
100+
set Neumann boundary ids =
101+
set Robin boundary ids = 2
102+
set Manifold to boundary slot map = 1,0, 2,1
103+
end
104+
end
105+
```
106+
107+
This uses slot 0 on manifold 1 and slot 1 on manifold 2, for every component.
108+
Supply the corresponding potential/wind/Robin functions for each selected slot.
109+
The bundled Robin samples are 3D: the present 2D parser allocates Robin
110+
functions with two entries while Robin preparation requires three. Do not use
111+
2D Robin conditions without resolving that implementation limitation.
112+
113+
## C++ API migration
114+
115+
All distributed operations must be invoked by every rank in the object's
116+
communicator, with compatible vector ownership. The geometric dimension is
117+
`dim`, and the boundary mesh dimension is `dim-1`.
118+
119+
| Interface | Contract and migration |
120+
| --- | --- |
121+
| `Driver(n_components)`, `BEMProblem(domain,comm,n_components)`, `BoundaryConditions(domain,bem,comm,n_components)` | Counts refer to real storage components; defaults preserve a single real potential. Keep referenced objects alive. |
122+
| `n_phi_components()`, `set_n_phi_components(n)` | Query or grow component storage; shrinking is unsupported. Grow before initialization/parameter parsing. |
123+
| `get_current_phi_component()`, `set_current_phi_component(i)` | Select a zero-based storage component. Selecting through `BoundaryConditions` also selects the bound BEM component. A complex solve requires `i+1<n`. |
124+
| `get_phi([i])`, `get_dphi_dn([i])` | Mutable vector references for the current or explicit component replace direct access to single solution fields. Storage growth can invalidate references. |
125+
| `get_wind(i,slot)`, `get_potential(i,slot)`, `get_robin_coeffs(i,slot)` | Parsed-function access requires initialized parameters, valid component and slot. Const public overloads expose the functions; mutable overloads are protected. |
126+
| `get_phi_components([indices])` | Returns an owned block-vector copy collectively. Explicit indices retain their component block numbers; the no-argument overload selects all. |
127+
| `solve_problem(reset_matrix)`, `solve_complex_problem(reset_matrix)` | Prepare data and solve current component/pair. Default `true` assembles the integral operators. Use `false` only while geometry, mapping, quadrature and discretization remain unchanged. |
128+
| `BEMProblem::solve(...)` | Real overload gains `reset_matrix`; complex overload takes `phi, phi_imag, dphi_dn, dphi_dn_imag, rhs, rhs_imag, reset_matrix`. Boundary vectors and Robin data must already be prepared. |
129+
| `prepare_robin_datastructs(...)` | Real overload fills diagonal/RHS; complex overload fills real and imaginary diagonal/RHS from consecutive component functions. |
130+
| `vmult(...)`, `compute_rhs(...)`, `solve_system(...)` | Additional overloads operate on separate real/imaginary vectors. They require previously initialized operators and current boundary data. |
131+
| `assemble_system_tbb()`, `assemble_system_singlethread()` | Explicit threaded/serial direct assembly. The high-level solve selects according to the thread limit. |
132+
| `assemble_preconditioner_complex()`, `get_preconditioner(complex)` | Set up and select configured ILU/AMG storage. Selection returns a reference owned by the BEM problem. |
133+
| `get_vector_gradients_solution([i])`, `get_vector_surface_gradients_solution([i])` | Mutable component-aware gradient access replaces the old single gradient fields. |
134+
| `get_system_matrix()`, `get_system_matrix_complex()` | Collective dense diagnostic copies, size N or 2N, ordered real then imaginary. Require direct matrices, use quadratic memory per rank and omit constrained-row replacement. |
135+
| `compute_errors(complex,current_is_real)` | Replace the old no-argument call: `(false,true)` for real, `(true,true)` for the real part of a pair, `(true,false)` for its imaginary part. |
136+
| `output_results(stem)` | Writes the selected component after errors/gradients have been computed. |
137+
138+
For an initialized boundary object `bc`, component selection is explicit:
139+
140+
```cpp
141+
bc.set_current_phi_component(0);
142+
bc.solve_complex_problem(true);
143+
bc.compute_errors(true, true);
144+
bc.output_results("potential_real");
145+
bc.set_current_phi_component(1);
146+
bc.compute_errors(true, false);
147+
bc.output_results("potential_imag");
148+
```
149+
150+
The old `bem_problem_access.h` adapter and `time_integrator.h` are removed.
151+
Use the component-aware public accessors; no time-integration replacement is
152+
provided. `ComputationalDomain` now exposes `load_cad_objects()` (returns the
153+
largest CAD tolerance), `refine_and_resize_by_aspect_ratio()`,
154+
`refine_and_resize_by_cad_projections(max_tol)` and
155+
`refine_and_resize_wrapup()` (partition and mesh output). Normal applications
156+
should call `refine_and_resize(level)`, which runs these stages in order.
157+
The option for attaching flat manifolds to IDs without CAD data preserves
158+
import of grids whose flags also distinguish boundary conditions.
159+
160+
## Complex operators and FMA APIs
161+
162+
`ConstrainedComplexOperator<VEC,MATRIX>` accepts one flat vector ordered
163+
`[real,imaginary]`. `BlockConstrainedComplexOperator<VEC,MATRIX>` accepts a
164+
two-block vector in the same order. Their constructors take a matrix, real and
165+
imaginary constraints, a constraint-relevant IndexSet and a communicator.
166+
Both constraint objects must describe the same constrained rows with unshifted
167+
indices. The matrix provides `this_cpu_set` and a four-vector `vmult`.
168+
`distribute_rhs()` installs the corresponding inhomogeneities.
169+
`BlockPreconditioner<P>` applies a referenced preconditioner independently to
170+
each block through `vmult`/`Tvmult`. Referenced matrices, constraints and
171+
preconditioners must outlive these adapters. The flat operator keeps mutable
172+
scratch vectors and must not be used concurrently from multiple threads.
173+
174+
`BEMFMA` adds `_tbb` and, when compiled with `PBEM_OPENMP`, `_omp` backends for
175+
direct integrals, multipole matrix-vector products and preconditioning.
176+
Use the dispatching `direct_integrals()`, `multipole_matr_vect_products()` and
177+
`FMA_preconditioner()` interfaces in application code.
178+
`FMA_preconditioner_complex()` provides the complex-solve near-field ILU
179+
preconditioner, with corresponding backend methods. Returned references belong
180+
to the FMA object. TBB is the default; the optional OpenMP configuration is
181+
selected by `PBEM_OPENMP=1` at CMake configure time.
182+
183+
`LocalExpansion` and `MultipoleExpansion` now own coefficient vectors and use
184+
default value copy/assignment. `GetCoeffs()` returns a const vector reference,
185+
not a writable pointer. `MultipoleExpansion::GetA_n_m()` and `GetCoeff()` also
186+
return const references; use `SetCoeff()` or `AddToCoeff()` for coefficient
187+
changes. Coefficients use triangular index `n*(n+1)/2+m`.
188+
`Add()`, `Evaluate()` and `MultipoleExpansion::AddNormDer()` gain overloads with
189+
a trailing `std::vector<std::complex<double>>&` scratch cache. An empty cache
190+
is valid; calls resize/overwrite it. Keep one cache per concurrent operation.
191+
The `AssLegFunction` pointer is non-owning and must outlive the expansion.
192+
193+
```cpp
194+
AssLegFunction legendre;
195+
MultipoleExpansion expansion(6, Point<3>(0, 0, 0), &legendre);
196+
std::vector<std::complex<double>> scratch;
197+
expansion.Add(1.0, Point<3>(0.1, 0, 0), scratch);
198+
const double value = expansion.Evaluate(Point<3>(2, 0, 0), scratch);
199+
const auto coefficients = expansion.GetCoeffs(); // independent snapshot
200+
```
201+
202+
`LocalExpansion::equal(lhs,rhs,tolerance)` compares orders, centers and stored
203+
coefficients with absolute tolerance (default `1e-10`).
204+
`MultipoleExpansion::spherical_coords()` returns relative position, radius,
205+
polar cosine and azimuth through output arguments; distinct points are required.
206+
207+
`OctreeBlock::small_set` is a sorted `boost::container::flat_set` of global IDs.
208+
Node, quadrature and interaction-list getters return const references owned by
209+
the block. Copy explicitly when a snapshot is required; mutation invalidates
210+
iterators as dictated by the underlying container. `GetCenter()` returns the
211+
box center. The custom copy/destructor and `CopyContent()` are removed in favor
212+
of value copying; `NumIntListLevels()`/`NumNonIntListLevels()` are removed.
213+
The complete interaction-list getter can be queried with `.size()`.
214+
215+
## Geometry and error-integration helpers
216+
217+
`QuasiSingularKernelIntegral<3>` searches a mapped quadrilateral for the closest
218+
point to an external point. Its constructor initializes reference coordinates
219+
`eta` and physical `min_distance`; the search considers the interior, edges and
220+
vertices. The referenced iterator object, mapping and finite element must remain
221+
alive. The 2D constructor does not initialize a projection or distance. This
222+
helper currently provides closest-point geometry, not a public quadrature API.
223+
224+
`integrate_difference_based_on_material_id()` and its hp implementation
225+
`do_integrate_difference_based_on_material_id()` select non-owning exact-function
226+
pointers by **material ID**. They return cellwise differences and put zero on
227+
unmapped/non-owned cells. Function component counts must match the finite
228+
element. Compute the global norm separately with
229+
`VectorTools::compute_global_error()`. These helpers depend on deal.II internal
230+
integration interfaces and require checking when updating deal.II.

‎include/bem_fma.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,13 @@ class BEMFMA : public ParameterAcceptor
124124
void
125125
direct_integrals();
126126

127+
/// Compute near-field direct integrals using the TBB backend after octree
128+
/// setup. Normally called through direct_integrals().
127129
void
128130
direct_integrals_tbb();
129131

130132
#ifdef PBEM_OPENMP
133+
/// OpenMP backend for direct_integrals(); available with PBEM_OPENMP.
131134
void
132135
direct_integrals_omp();
133136
#endif
@@ -180,6 +183,8 @@ class BEMFMA : public ParameterAcceptor
180183
TrilinosWrappers::MPI::Vector &matrVectProdN,
181184
TrilinosWrappers::MPI::Vector &matrVectProdD) const;
182185

186+
/// TBB backend applying far-field Neumann/Dirichlet products to the
187+
/// supplied real vectors. Requires initialized multipole integrals.
183188
void
184189
multipole_matr_vect_products_tbb(
185190
const TrilinosWrappers::MPI::Vector &phi_values,
@@ -188,6 +193,8 @@ class BEMFMA : public ParameterAcceptor
188193
TrilinosWrappers::MPI::Vector &matrVectProdD) const;
189194

190195
#ifdef PBEM_OPENMP
196+
/// OpenMP backend for the multipole matrix-vector products; available
197+
/// with PBEM_OPENMP and requiring initialized multipole integrals.
191198
void
192199
multipole_matr_vect_products_omp(
193200
const TrilinosWrappers::MPI::Vector &phi_values,
@@ -227,25 +234,36 @@ class BEMFMA : public ParameterAcceptor
227234
FMA_preconditioner(const TrilinosWrappers::MPI::Vector &alpha,
228235
AffineConstraints<double> &c);
229236

237+
/// Build the real near-field ILU preconditioner with TBB. The returned
238+
/// reference is owned by this FMA object; alpha and constraints must be
239+
/// ready.
230240
TrilinosWrappers::PreconditionILU &
231241
FMA_preconditioner_tbb(const TrilinosWrappers::MPI::Vector &alpha,
232242
AffineConstraints<double> &c);
233243

234244
#ifdef PBEM_OPENMP
245+
/// OpenMP backend for the real near-field ILU preconditioner; available
246+
/// with PBEM_OPENMP. Return a reference owned by this object.
235247
TrilinosWrappers::PreconditionILU &
236248
FMA_preconditioner_omp(const TrilinosWrappers::MPI::Vector &alpha,
237249
AffineConstraints<double> &c);
238250
#endif
239251

252+
/// Build the near-field ILU preconditioner used for each block of a
253+
/// complex solve. Dispatch to the selected threading backend and return
254+
/// a reference owned by this object. alpha and constraints must be ready.
240255
TrilinosWrappers::PreconditionILU &
241256
FMA_preconditioner_complex(const TrilinosWrappers::MPI::Vector &alpha,
242257
AffineConstraints<double> &c);
243258

259+
/// TBB backend for FMA_preconditioner_complex(); return an owned reference.
244260
TrilinosWrappers::PreconditionILU &
245261
FMA_preconditioner_complex_tbb(const TrilinosWrappers::MPI::Vector &alpha,
246262
AffineConstraints<double> &c);
247263

248264
#ifdef PBEM_OPENMP
265+
/// OpenMP backend for FMA_preconditioner_complex(); available with
266+
/// PBEM_OPENMP. The returned reference is owned by this object.
249267
TrilinosWrappers::PreconditionILU &
250268
FMA_preconditioner_complex_omp(const TrilinosWrappers::MPI::Vector &alpha,
251269
AffineConstraints<double> &c);

0 commit comments

Comments
 (0)