Skip to content

Commit 850e47f

Browse files
authored
Merge pull request #60 from mathLab/pbem4wass
Pbem4wass
2 parents 68e55cc + 11fbe0a commit 850e47f

89 files changed

Lines changed: 15127 additions & 5557 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/tests.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
rm -rf build_linux_debug
2323
mkdir build_linux_debug
2424
cd build_linux_debug
25-
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug
25+
cmake .. -GNinja -DCMAKE_CXX_FLAGS=-Werror -DCMAKE_BUILD_TYPE=Debug
2626
ninja
2727
ctest -N
2828
ctest --output-on-failure
@@ -42,7 +42,7 @@ jobs:
4242
rm -rf build_linux_release
4343
mkdir build_linux_release
4444
cd build_linux_release
45-
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release
45+
cmake .. -GNinja -DCMAKE_CXX_FLAGS=-Werror -DCMAKE_BUILD_TYPE=Release
4646
ninja
4747
ctest -N
4848
ctest --output-on-failure

‎.gitignore‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
*~
22
build/
3+
.vscode
4+
*.vtu
5+
*/.ipynb_checkpoints/
6+
tests_regression/robin_bconditions/parameters_bem_3.prm
7+
tests_regression/robin_bconditions/used_parameters_bem_3.prm
8+
9+
build-docker/

‎CMakeLists.txt‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ IF(NOT "${_main}" STREQUAL "")
3535
ENDIF()
3636

3737

38+
3839
CMAKE_MINIMUM_REQUIRED(VERSION 3.13.4)
3940

41+
4042
FIND_PACKAGE(deal.II 9.5.0 REQUIRED
4143
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}
4244
)
@@ -53,7 +55,6 @@ ENDIF()
5355

5456
DEAL_II_INITIALIZE_CACHED_VARIABLES()
5557

56-
5758
PROJECT(${TARGET})
5859

5960
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -64,6 +65,18 @@ OPTION(BEM_ENABLE_TESTING
6465
"Enable deal.II style tests in this application." ON)
6566

6667

68+
IF($ENV{PBEM_OPENMP})
69+
message("compiling with OpenMP threading")
70+
FIND_PACKAGE(OpenMP REQUIRED)
71+
add_definitions("-DPBEM_OPENMP")
72+
ELSE()
73+
message("compiling with TBB threading")
74+
ENDIF()
75+
#-fopenmp was not used in compiling .o files, it was substituted with -fopenmp-simd
76+
IF (OPENMP_FOUND)
77+
add_definitions("-fopenmp")
78+
ENDIF()
79+
6780
# We one library and one target for each type of deal.II library
6881
# we found. If you compiled deal.II with both Release and Debug
6982
# mode, this will generate both Release and Debug programs for you
@@ -91,10 +104,16 @@ FOREACH(_build_type ${_d2_build_types})
91104
SET(_exe "${TARGET}_${_dim}d${${_build_type}_postfix}")
92105
MESSAGE("-- Configuring executable ${_exe}")
93106
ADD_EXECUTABLE(${_exe} ${_main})
94-
target_compile_definitions(${_exe} PUBLIC DEAL_II_DIMENSION=${_dim})
95-
TARGET_LINK_LIBRARIES(${_exe} ${_lib})
107+
108+
109+
IF (OPENMP_FOUND)
110+
TARGET_LINK_LIBRARIES(${_exe} ${_lib} OpenMP::OpenMP_CXX)
111+
ELSE()
112+
TARGET_LINK_LIBRARIES(${_exe} ${_lib})
113+
ENDIF()
114+
target_compile_definitions(${_exe} PUBLIC DEAL_II_DIMENSION=${_dim} )
96115
DEAL_II_SETUP_TARGET(${_exe} ${_BUILD_TYPE})
97-
ENDFOREACH()
116+
ENDFOREACH()
98117

99118

100119

@@ -105,7 +124,7 @@ ENDFOREACH()
105124

106125
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
107126

108-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/tests AND BEM_ENABLE_TESTING)
127+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/tests AND "${BEM_ENABLE_TESTING}")
109128
ADD_SUBDIRECTORY(tests)
110129
ENABLE_TESTING()
111130
endif()

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ If you use this software, please consider citing the following work:
199199
}
200200
```
201201

202+
## Multiple potentials, complex problems and Robin conditions
203+
204+
See [the usage and API migration guide](docs/complex-robin.md) for runnable
205+
Docker examples, parameter-file changes, component selection, Robin coefficients
206+
and the C++ interfaces introduced by the complex/multiple-potential extension.
207+
202208
# Licence
203209

204210
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.

‎grids/coarse_sphere_curves.inp‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
8 18 0 0 0
2+
1 -0.577350269 -0.577350269 -0.577350269
3+
2 0.577350269 -0.577350269 -0.577350269
4+
3 -0.577350269 0.577350269 -0.577350269
5+
4 0.577350269 0.577350269 -0.577350269
6+
5 -0.577350269 -0.577350269 0.577350269
7+
6 0.577350269 -0.577350269 0.577350269
8+
7 -0.577350269 0.577350269 0.577350269
9+
8 0.577350269 0.577350269 0.577350269
10+
1 1 quad 3 4 2 1
11+
2 2 quad 5 6 8 7
12+
3 1 quad 1 2 6 5
13+
4 2 quad 3 7 8 4
14+
5 1 quad 5 7 3 1
15+
6 2 quad 2 4 8 6
16+
7 11 line 1 5
17+
8 12 line 3 7
18+
9 13 line 2 6
19+
10 14 line 4 8
20+
11 15 line 1 3
21+
12 16 line 5 7
22+
13 17 line 2 4
23+
14 18 line 6 8
24+
15 19 line 1 2
25+
16 20 line 5 6
26+
17 21 line 3 4
27+
18 22 line 7 8

0 commit comments

Comments
 (0)