Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,38 @@ on:
# '*' is a special character in YAML, so string must be quoted
- cron: "0 1 * * *"
env:
PETSC_ARCH: linux-gnu-real-32
PETSC_ARCH: linux-gnu-real64-32
jobs:
build:
if: "!(contains(github.event.head_commit.message, '[ci skip]') || contains(github.event.head_commit.message, '[skip ci]'))"
runs-on:
ubuntu-latest
container: fenicsproject/test-env:nightly-mpich

container: ghcr.io/fenics/test-env:v0.7.2-mpich
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4


- name: Get Basix
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: ./basix
repository: FEniCS/basix
ref: main
ref: v0.7.0

- name: Install UFL, Basix, FFCx
run: |
cmake -G Ninja -B build-basix -DCMAKE_BUILD_TYPE="Release" -S ./basix/cpp/
cmake --build build-basix --parallel 3
cmake --install build-basix
BUILD_TYPE="Release" pip3 install ./basix/python
python3 -m pip install git+https://github.com/FEniCS/ufl.git
python3 -m pip install git+https://github.com/FEniCS/ffcx.git
python3 -m pip install git+https://github.com/FEniCS/ufl.git@2023.2.0
python3 -m pip install git+https://github.com/FEniCS/ffcx.git@v0.7.0

- name: Get DOLFINx
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: ./dolfinx
repository: FEniCS/dolfinx
ref: main
ref: v0.7.2

- name: Configure C++ (dolfinx)
run: |
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*build-dir*/**
__pycache__
*.egg-info
*.bp
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Joseph P. Dean

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Problem
create_problem = problems.create_problem_0
# Characteristic element size
hs = [1 / 4, 1 / 8]
hs = [1 / 2, 1 / 4, 1 / 8]
# Polynomial orders
ks = [1, 2, 3, 4]
# Coefficients
Expand Down
44 changes: 39 additions & 5 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,49 @@
## Muelu Trilinos Demo

To compile, first install FEniCS-X dolfinx (real or complex)
and Trilinos (an example build script is in builder.sh)
and [Trilinos](https://github.com/trilinos/Trilinos.git) (an example build script is in builder.sh)

1. Clone trilinos from their github and checkout the correct version:
```bash
git clone https://github.com/trilinos/Trilinos.git
cd Trilinos
git checkout trilinos-release-13-4-1
```
2. Buld trilinos
```bash
cmake -G Ninja -B build-dir-trilinos \
-DTPL_ENABLE_MPI=ON \
-DMPI_BASE_DIR=/usr/x86_64-linux/ \
-DTrilinos_ENABLE_COMPLEX_DOUBLE=ON \
-DTrilinos_ENABLE_MueLu=ON \
-DTrilinos_ENABLE_TrilinosCouplings=ON \
-DTrilinos_ENABLE_Teko=OFF \
-DTpetra_INST_INT_LONG=ON \
-DTpetra_INST_INT_LONG_LONG=OFF \
-DBUILD_SHARED_LIBS=ON \
-DTrilinos_ENABLE_PyTrilinos=OFF \
-DTPL_ENABLE_Netcdf=OFF \
.
ninja -j8 -C build-dir-trilinos

```

3. Compile integration kernels
For real

`ffcx --scalar_type=double maxwell.ufl`
```bash
python3 -m ffcx --scalar_type=double maxwell.py
```

or for complex

`ffcx --scalar_type="double complex" maxwell.ufl`
```bash
python3 -m ffcx --scalar_type="double complex" maxwell.py
```

4. Compile demo

cmake .
make
```bash
cmake -G Ninja -B build-dir -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-fmax-errors=1"
ninja -j8 -C build-dir
```
11 changes: 6 additions & 5 deletions cpp/builder.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/bin/bash
rm -r build
mkdir -p build
cd build
cmake -DTPL_ENABLE_MPI=ON \
# Based on trilinos released: trilinos-release-13.4.1
cmake -B build-dir-trilinos \
-DTPL_ENABLE_MPI=ON \
-DMPI_BASE_DIR=/usr/x86_64-linux/ \
-DTrilinos_ENABLE_COMPLEX_DOUBLE=ON \
-DTrilinos_ENABLE_MueLu=ON \
-DTrilinos_ENABLE_TrilinosCouplings=ON \
-DTpetra_INST_INT_LONG_LONG=OFF \
-DTrilinos_ENABLE_Teko=OFF \
-DTpetra_INST_INT_LONG=ON \
-DTpetra_INST_INT_LONG_LONG=OFF \
-DBUILD_SHARED_LIBS=ON \
-DTrilinos_ENABLE_PyTrilinos=OFF \
-DTPL_ENABLE_Netcdf=OFF \
-DCMAKE_INSTALL_PREFIX=/home/chris/packages/trilinos ..
.
95 changes: 53 additions & 42 deletions cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

#include "lumping.h"
#include "maxwell.h"
#include "tpetra_util.h"

#include <MatrixMarket_Tpetra.hpp>
#include "tpetra_util.h" #include < MatrixMarket_Tpetra.hpp>
#include <MueLu_CreateTpetraPreconditioner.hpp>
#include <MueLu_RefMaxwell.hpp>
#include <Tpetra_Core.hpp>
Expand All @@ -28,7 +26,8 @@
void tpetra_assemble(Teuchos::RCP<Tpetra::CrsMatrix<PetscScalar, std::int32_t,
std::int64_t, Node>>
A_Tpetra,
const fem::Form<PetscScalar> &form) {
const fem::Form<PetscScalar> &form)
{

std::vector<std::int64_t> global_cols; // temp for columns
const std::shared_ptr<const fem::FunctionSpace> V = form.function_spaces()[0];
Expand All @@ -41,36 +40,42 @@ void tpetra_assemble(Teuchos::RCP<Tpetra::CrsMatrix<PetscScalar, std::int32_t,
tpetra_insert = [&A_Tpetra, &global_indices, &global_cols, &nlocalrows](
std::int32_t nr, const std::int32_t *rows,
const std::int32_t nc, const std::int32_t *cols,
const PetscScalar *data) {
for (std::int32_t i = 0; i < nr; ++i) {
Teuchos::ArrayView<const PetscScalar> data_view(data + i * nc, nc);
if (rows[i] < nlocalrows) {
Teuchos::ArrayView<const int> col_view(cols, nc);
int nvalid =
A_Tpetra->sumIntoLocalValues(rows[i], col_view, data_view);
if (nvalid != nc)
throw std::runtime_error("Inserted " + std::to_string(nvalid) +
"/" + std::to_string(nc) + " on row:" +
std::to_string(global_indices[rows[i]]));
} else {
global_cols.resize(nc);
for (int j = 0; j < nc; ++j)
global_cols[j] = global_indices[cols[j]];
int nvalid = A_Tpetra->sumIntoGlobalValues(global_indices[rows[i]],
global_cols, data_view);
if (nvalid != nc)
throw std::runtime_error("Inserted " + std::to_string(nvalid) +
"/" + std::to_string(nc) + " on row:" +
std::to_string(global_indices[rows[i]]));
}
}
return 0;
};
const PetscScalar *data)
{
for (std::int32_t i = 0; i < nr; ++i)
{
Teuchos::ArrayView<const PetscScalar> data_view(data + i * nc, nc);
if (rows[i] < nlocalrows)
{
Teuchos::ArrayView<const int> col_view(cols, nc);
int nvalid =
A_Tpetra->sumIntoLocalValues(rows[i], col_view, data_view);
if (nvalid != nc)
throw std::runtime_error("Inserted " + std::to_string(nvalid) +
"/" + std::to_string(nc) + " on row:" +
std::to_string(global_indices[rows[i]]));
}
else
{
global_cols.resize(nc);
for (int j = 0; j < nc; ++j)
global_cols[j] = global_indices[cols[j]];
int nvalid = A_Tpetra->sumIntoGlobalValues(global_indices[rows[i]],
global_cols, data_view);
if (nvalid != nc)
throw std::runtime_error("Inserted " + std::to_string(nvalid) +
"/" + std::to_string(nc) + " on row:" +
std::to_string(global_indices[rows[i]]));
}
}
return 0;
};

fem::assemble_matrix(tpetra_insert, form, {});
}

int main(int argc, char **argv) {
int main(int argc, char **argv)
{
common::subsystem::init_mpi(argc, argv);
common::subsystem::init_logging(argc, argv);

Expand Down Expand Up @@ -121,7 +126,8 @@ int main(int argc, char **argv) {
create_tpetra_diagonal_matrix<PetscScalar>(Q->dofmap()->index_map);
std::vector<std::int32_t> col(1);
std::vector<PetscScalar> val(1);
for (int i = 0; i < Q->dofmap()->index_map->size_local(); ++i) {
for (int i = 0; i < Q->dofmap()->index_map->size_local(); ++i)
{
col[0] = i;
val[0] = 1.0 / vals[i];
Mg_mat->replaceLocalValues(i, col, val);
Expand All @@ -135,14 +141,16 @@ int main(int argc, char **argv) {
std::function<int(std::int32_t, const std::int32_t *, std::int32_t,
const std::int32_t *, const PetscScalar *)>
mat_set_dg = [&D0_mat](int nr, const int *rows, int nc, const int *cols,
const PetscScalar *data) {
for (int i = 0; i < nr; ++i) {
Teuchos::ArrayView<const PetscScalar> data_view(data + i * nc, nc);
Teuchos::ArrayView<const int> col_view(cols, nc);
D0_mat->replaceLocalValues(rows[i], col_view, data_view);
}
return 0;
};
const PetscScalar *data)
{
for (int i = 0; i < nr; ++i)
{
Teuchos::ArrayView<const PetscScalar> data_view(data + i * nc, nc);
Teuchos::ArrayView<const int> col_view(cols, nc);
D0_mat->replaceLocalValues(rows[i], col_view, data_view);
}
return 0;
};

fem::assemble_discrete_gradient(mat_set_dg, *V, *Q);
D0_mat->fillComplete();
Expand All @@ -153,10 +161,12 @@ int main(int argc, char **argv) {
new Tpetra::MultiVector<double, std::int32_t, std::int64_t, Node>(
Mg_mat->getRowMap(), 3));
fem::Function<double> xcoord(Q);
for (int j = 0; j < 3; ++j) {
for (int j = 0; j < 3; ++j)
{
common::Timer time_interpolate("Interpolate x");
xcoord.interpolate(
[&j](const xt::xtensor<double, 2> &x) -> xt::xarray<double> {
[&j](const xt::xtensor<double, 2> &x) -> xt::xarray<double>
{
return xt::row(x, j);
});
time_interpolate.stop();
Expand All @@ -168,7 +178,8 @@ int main(int argc, char **argv) {

bool write_files = false;

if (write_files) {
if (write_files)
{
common::Timer tw("Tpetra: write files");
Tpetra::MatrixMarket::Writer<
Tpetra::CrsMatrix<PetscScalar, std::int32_t, std::int64_t, Node>>::
Expand Down
28 changes: 22 additions & 6 deletions cpp/maxwell.ufl → cpp/maxwell.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
from ufl import (
VectorElement,
FiniteElement,
Mesh,
SpatialCoordinate,
as_vector,
TrialFunction,
TestFunction,
inner,
curl,
dx,
FunctionSpace,
tetrahedron,
pi,
cos,
)

coord_element = VectorElement("Lagrange", tetrahedron, 1)
mesh = Mesh(coord_element)
Expand All @@ -9,15 +25,15 @@
# T_0 = Coefficient(element)

x = SpatialCoordinate(mesh)
T_0 = as_vector((- pi * cos(x[2] * pi) / mu,
- pi * cos(x[0] * pi) / mu,
- pi * cos(x[1] * pi) / mu))
T_0 = as_vector(
(-pi * cos(x[2] * pi) / mu, -pi * cos(x[0] * pi) / mu, -pi * cos(x[1] * pi) / mu)
)

A = TrialFunction(Q)
v = TestFunction(Q)

Kc = inner(1 / mu * curl(A), curl(v)) * dx + 1e-8 * inner(A, v)*dx
Mc = inner(A, v)*dx
Kc = inner(1 / mu * curl(A), curl(v)) * dx + 1e-8 * inner(A, v) * dx
Mc = inner(A, v) * dx
L = inner(T_0, curl(v)) * dx

Hgrad_element = FiniteElement("Lagrange", tetrahedron, 1)
Expand All @@ -26,4 +42,4 @@
v = TestFunction(V)
Mg = inner(u, v) * dx

forms = [Kc, Mc, Mg, L]
forms = [Kc, Mc, Mg, L]
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[build-system] # Require setuptool version due to https://github.com/pypa/setuptools/issues/2938
requires = ["setuptools>=64.4.0", "wheel", "pip>=22.3"]

[project]
name = "maxwell_problems"
version = "0.7.0"
description = "Implementation for solving Maxwell-problems with DOLFINx"
authors = [
{ name = "Joseph P. Dean", email="jpd62@eng.cam.ac.uk"},
{ name = "Jørgen S. Dokken", email = "dokken@simula.no" }]
license = { file = "LICENSE" }
readme = "README.md"
dependencies = ["fenics-dolfinx>=0.7.0"]

[tool.setuptools]
packages = []

[project.optional-dependencies]
test = ["pytest", "coverage"]
dev = ["pdbpp", "ipython", "mypy", "flake8"]
all = ["adios4dolfinx[test,dev]"]

[tool.pytest.ini_options]
addopts = ["--import-mode=importlib"]
testpaths = ["tests"]

[tool.mypy]
ignore_missing_imports = true
# Folders to exclude
exclude = ["build/"]
# Folder to check with mypy
files = ["src", "tests"]