Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
d830ae1
add non matching conforming projection operators
FrederikSchnack Jul 14, 2023
a27a062
add some plotting utilities
FrederikSchnack Jul 14, 2023
bbad569
make multipatch examples run
FrederikSchnack Jul 14, 2023
ec10dfd
Use SymPDE development version from GitHub
yguclu Jul 17, 2023
a166d02
allow for non-matching grids in postprocessing
FrederikSchnack Jul 17, 2023
87bbef6
add utils
FrederikSchnack Jul 17, 2023
1a41cd0
adds non-matching domain utilities
FrederikSchnack Jul 18, 2023
e84552a
adds curl-curl test case comparisson
FrederikSchnack Jul 18, 2023
548881a
small changes
FrederikSchnack Jul 24, 2023
b0e64c9
Merge remote-tracking branch 'origin/devel' into non_matching_multipatch
FrederikSchnack Jul 24, 2023
4dbc422
Merge branch 'devel' into non_matching_multipatch
yguclu Jul 25, 2023
b3d1451
add time-domain Maxwell
FrederikSchnack Jul 27, 2023
a806b6d
add time harmonic and time domain maxwell examples
FrederikSchnack Jul 28, 2023
26578f6
add new tests and last example
FrederikSchnack Aug 2, 2023
f68c562
Merge branch 'devel' into non_matching_multipatch
FrederikSchnack Sep 20, 2023
7fbaecf
make Codacy happy
FrederikSchnack Sep 20, 2023
b52041f
add pml example
FrederikSchnack Nov 27, 2023
7f5be32
update non_matching operators and add proposal of tests
FrederikSchnack Nov 27, 2023
1692570
adapt files to new projection
FrederikSchnack Nov 27, 2023
544a237
make codacy happy
FrederikSchnack Nov 28, 2023
7b357bb
add some pml experiments
FrederikSchnack Dec 12, 2023
ebaa9f3
Merge branch 'devel' into non_matching_multipatch
FrederikSchnack Mar 1, 2024
a147990
add docs and readability
FrederikSchnack Mar 5, 2024
c7325da
Merge branch 'devel' into non_matching_multipatch
FrederikSchnack Mar 5, 2024
567ce21
move pml experiments to its own branch
FrederikSchnack Mar 5, 2024
2af29a8
adapt tests
FrederikSchnack Mar 5, 2024
d4fbdbf
change Hodge matrix naming conventions
FrederikSchnack Mar 7, 2024
11a9859
Merge branch 'devel' into non_matching_multipatch
FrederikSchnack Mar 7, 2024
ae90d77
Merge branch 'devel' into non_matching_multipatch
yguclu Mar 19, 2024
05bd083
Merge branch 'devel' into non_matching_multipatch
FrederikSchnack Apr 23, 2024
aa4fd8c
functions stencil index to petsc index and viceversa
e-moral-sanchez May 8, 2024
678de4a
efficient conversion to PETSc of StencilVectors
e-moral-sanchez May 8, 2024
bf176a2
works for 1D stencil matrix with multiple processes
e-moral-sanchez May 13, 2024
c7ac7ce
correct indexing for 2D stencilmatrix
e-moral-sanchez May 15, 2024
6579478
works 1d,2d,3d stencilmatrix without periodic BC
e-moral-sanchez May 15, 2024
a9e0315
efficient conversion of stencilmatrix to PETSc.Mat for 1,2,3D and pe…
e-moral-sanchez May 16, 2024
1579d31
Fixed conversion from 2D BlockStencilVector to Petsc.Vec
e-moral-sanchez May 17, 2024
a78bb93
fix general case also for stencilvector 2D
e-moral-sanchez May 17, 2024
bb05e72
fixed petsc_to_psydac for BlockVectors
e-moral-sanchez May 21, 2024
4174b66
PETSc conversion works for StencilVector and BlockStencilVector of 1 …
e-moral-sanchez May 21, 2024
d019388
conversion works for StencilMatrix
e-moral-sanchez May 21, 2024
4066746
works for BlockLinearOperators, the blocks of which are Stencilmatrices
e-moral-sanchez May 21, 2024
988ba35
Clean up, docstrings
e-moral-sanchez May 21, 2024
6e3a348
fix bugs
e-moral-sanchez May 22, 2024
448670b
sequential case, docstrings
e-moral-sanchez May 22, 2024
22b7646
cleaning
e-moral-sanchez May 22, 2024
32a6a13
erase forgotten comments
e-moral-sanchez May 22, 2024
4a60cd9
Merge branch 'devel' into improve_mat_topetsc
e-moral-sanchez May 22, 2024
ff8c1c0
adds revised Hcurl conforming projections and adapts the tests, prior…
FrederikSchnack May 22, 2024
53c1b3c
adapt conforming examples to new projections
FrederikSchnack May 22, 2024
dcc86b1
update non-matching examples
FrederikSchnack May 23, 2024
df34fe9
fix loop stencil
e-moral-sanchez May 23, 2024
a853a47
work in comments
FrederikSchnack May 23, 2024
5371468
update tests
FrederikSchnack May 23, 2024
9357bdd
Merge branch 'devel' into non_matching_multipatch
FrederikSchnack May 23, 2024
c8b4c07
forgotten prints
e-moral-sanchez May 27, 2024
4de21ca
add pyccel kernel
e-moral-sanchez May 29, 2024
ce1126a
string for type annotations
e-moral-sanchez May 29, 2024
1a45700
clean up plus fix serial case
e-moral-sanchez May 29, 2024
ba230ba
stop using create_domain() -- wip
campospinto May 31, 2024
685f4a5
use Domain.join() to build non-matching domains
campospinto Jun 2, 2024
842f7fc
clean time measurements
e-moral-sanchez Jun 3, 2024
a3a5341
using temp function for sympde Domain.join
campospinto Jun 4, 2024
220f1cf
adding ref
campospinto Jun 4, 2024
73019d1
call exposed domain and codomain in linalg/basic.py
campospinto Jun 7, 2024
52fec60
Merge example scripts and get rid of get_source_and_solution_OBSOLETE
FrederikSchnack Jun 10, 2024
4d5f780
clean up multipatch domain utilities
FrederikSchnack Jun 11, 2024
fffe43f
Coarsen test runs and add timedomain dummy run
FrederikSchnack Jun 11, 2024
d417da4
Make codacy happy
FrederikSchnack Jun 12, 2024
a748a4d
fix typo
FrederikSchnack Jun 12, 2024
25c586b
fix version 12 of macos in tests
e-moral-sanchez Jun 12, 2024
2bceaf6
Expose multipatch modules to docs
FrederikSchnack Jun 17, 2024
383d341
minor documentation related fixes
jowezarek Jun 17, 2024
a9da50e
sphinx fix
campospinto Jun 18, 2024
9995e21
Fixes for CI failures caused by new macOS runner version and numpy 2.0
kvrigor Jun 19, 2024
802ab87
CI: Temporarily disabled docs deployment since base repo is a fork
kvrigor Jun 19, 2024
8a8138f
Merge pull request #3 from campospinto/ci-fixes-jun2024
campospinto Jun 20, 2024
c3f380c
Merge branch 'devel' into improve_mat_topetsc
e-moral-sanchez Jun 21, 2024
cec4c7a
Update macos version
e-moral-sanchez Jun 21, 2024
63f3228
Disable deploy_docs in documentation.yml
FrederikSchnack Jun 21, 2024
ed0427f
Merge branch 'ci-fixes-jun2024' into non_matching_multipatch
FrederikSchnack Jun 21, 2024
d1b9cb0
Merge pull request #4 from campospinto/ci-fixes-jun2024
campospinto Jun 21, 2024
37f2b10
Merge branch 'devel' into improve_mat_topetsc
e-moral-sanchez Jun 21, 2024
4db8dca
simple implementation GeneralLinearOperator
e-moral-sanchez Jun 21, 2024
5d5de58
Merge pull request #1 from campospinto/improve_mat_topetsc
campospinto Jun 21, 2024
6265d1c
Merge branch 'devel' into non_matching_multipatch
FrederikSchnack Jun 21, 2024
bdaa788
Merge pull request #5 from campospinto/non_matching_multipatch
campospinto Jun 21, 2024
618020b
Merge branch 'devel' into minor_bug_fix_linalg_basic
campospinto Jun 21, 2024
a94db57
Merge branch 'devel' into general_linear_operator
e-moral-sanchez Jun 21, 2024
2adf6ad
general linear operator needs toarray, tosparse,transpose method
e-moral-sanchez Jun 23, 2024
6e1bc76
Merge pull request #2 from campospinto/minor_bug_fix_linalg_basic
campospinto Jun 23, 2024
41f3373
improve docstrings
e-moral-sanchez Jul 4, 2024
a567199
Merge branch 'devel' into general_linear_operator
e-moral-sanchez Jul 4, 2024
2067c4c
fixed message notimplementederror
e-moral-sanchez Jul 4, 2024
d32bd98
put import outside class
e-moral-sanchez Jul 4, 2024
b85ec76
set tol to rtol in MINRES
e-moral-sanchez Jul 8, 2024
273ec8f
add features and tests to MatrixFree linear ops
campospinto Jul 12, 2024
9163b3f
tests for matrix free linear ops
campospinto Jul 12, 2024
1e53d49
require scipy >= 1.14 in requirements.txt
campospinto Jul 16, 2024
2e898b8
discard tests with python3.8
campospinto Jul 16, 2024
baf0231
avoid minres iteration if converged
campospinto Jul 16, 2024
2dd2d3b
Style cleanup of stencil2IJV_kernels.py
yguclu Jul 31, 2024
b9a64a0
Apply some PEP8 recommendations to topetsc.py
yguclu Aug 1, 2024
8c45fd4
Merge branch 'devel' into general_linear_operator
yguclu Aug 2, 2024
f193766
Revert "Disable deploy_docs in documentation.yml"
yguclu Jul 31, 2024
f07548f
Revert "CI: Temporarily disabled docs deployment since base repo is a…
yguclu Jul 31, 2024
fcd50ca
Require SciPy >= 1.12, hence Python >= 3.9
yguclu Aug 2, 2024
123aa00
Do not skip tests with Python 3.9
yguclu Aug 2, 2024
e8d53e0
Apply some PEP8 recommendations to linalg/basic.py
yguclu Aug 2, 2024
f3c67b6
Add missing newline at end of file
yguclu Jul 31, 2024
e46742c
Use master branch of Igakit once again
yguclu Jul 31, 2024
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
Prev Previous commit
Next Next commit
add new tests and last example
  • Loading branch information
FrederikSchnack committed Aug 2, 2023
commit 26578f6b12d16351a281f27e55f53514815360ea
4 changes: 2 additions & 2 deletions psydac/feec/multipatch/examples/h1_source_pbms_conga_2d.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
from psydac.feec.multipatch.operators import HodgeOperator
from psydac.feec.multipatch.plotting_utilities import plot_field
from psydac.feec.multipatch.multipatch_domain_utilities import build_multipatch_domain
from psydac.feec.multipatch.examples.ppc_test_cases import get_source_and_solution
from psydac.feec.multipatch.examples.ppc_test_cases import get_source_and_solution_OBSOLETE
from psydac.feec.multipatch.utilities import time_count
from psydac.feec.multipatch.non_matching_operators import construct_V0_conforming_projection, construct_V1_conforming_projection

@@ -165,7 +165,7 @@ def lift_u_bc(u_bc):
# (not all the returned functions are useful here)
N_diag = 200
method = 'conga'
f_scal, f_vect, u_bc, ph_ref, uh_ref, p_ex, u_ex, phi, grad_phi = get_source_and_solution(
f_scal, f_vect, u_bc, p_ex, u_ex, phi, grad_phi = get_source_and_solution_OBSOLETE(
source_type=source_type, eta=eta, mu=mu, domain=domain, domain_name=domain_name,
refsol_params=[N_diag, method, source_proj],
)
5 changes: 2 additions & 3 deletions psydac/feec/multipatch/examples/hcurl_source_pbms_conga_2d.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
from psydac.feec.multipatch.operators import HodgeOperator
from psydac.feec.multipatch.plotting_utilities import plot_field
from psydac.feec.multipatch.multipatch_domain_utilities import build_multipatch_domain
from psydac.feec.multipatch.examples.ppc_test_cases import get_source_and_solution
from psydac.feec.multipatch.examples.ppc_test_cases import get_source_and_solution_OBSOLETE
from psydac.feec.multipatch.utilities import time_count
from psydac.linalg.utilities import array_to_psydac
from psydac.fem.basic import FemField
@@ -227,9 +227,8 @@ def lift_u_bc(u_bc):
print('getting the source and ref solution...')
N_diag = 200
method = 'conga'
f_scal, f_vect, u_bc, ph_ref, uh_ref, p_ex, u_ex, phi, grad_phi = get_source_and_solution(
f_scal, f_vect, u_bc, p_ex, u_ex, phi, grad_phi = get_source_and_solution_OBSOLETE(
source_type=source_type, eta=eta, mu=mu, domain=domain, domain_name=domain_name,
refsol_params=[N_diag, method, source_proj],
)

# compute approximate source f_h
278 changes: 278 additions & 0 deletions psydac/feec/multipatch/examples_nc/h1_source_pbms_nc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
# coding: utf-8

from mpi4py import MPI

import os
import numpy as np
from collections import OrderedDict

from sympy import lambdify
from scipy.sparse.linalg import spsolve

from sympde.expr.expr import LinearForm
from sympde.expr.expr import integral, Norm
from sympde.topology import Derham
from sympde.topology import element_of


from psydac.api.settings import PSYDAC_BACKENDS
from psydac.feec.multipatch.api import discretize
from psydac.feec.pull_push import pull_2d_h1

from psydac.feec.multipatch.fem_linear_operators import IdLinearOperator
from psydac.feec.multipatch.operators import HodgeOperator
from psydac.feec.multipatch.plotting_utilities import plot_field
from psydac.feec.multipatch.multipatch_domain_utilities import build_multipatch_domain
from psydac.feec.multipatch.examples.ppc_test_cases import get_source_and_solution_OBSOLETE
from psydac.feec.multipatch.utilities import time_count
from psydac.feec.multipatch.non_matching_operators import construct_V0_conforming_projection, construct_V1_conforming_projection
from psydac.api.postprocessing import OutputManager, PostProcessManager

from psydac.linalg.utilities import array_to_psydac
from psydac.fem.basic import FemField

def solve_h1_source_pbm_nc(
nc=4, deg=4, domain_name='pretzel_f', backend_language=None, source_proj='P_L2', source_type='manu_poisson',
eta=-10., mu=1., gamma_h=10.,
plot_source=False, plot_dir=None, hide_plots=True
):
"""
solver for the problem: find u in H^1, such that

A u = f on \Omega
u = u_bc on \partial \Omega

where the operator

A u := eta * u - mu * div grad u

is discretized as Ah: V0h -> V0h in a broken-FEEC approach involving a discrete sequence on a 2D multipatch domain \Omega,

V0h --grad-> V1h -—curl-> V2h

Examples:

- Helmholtz equation with
eta = -omega**2
mu = 1

- Poisson equation with Laplace operator L = A,
eta = 0
mu = 1

:param nc: nb of cells per dimension, in each patch
:param deg: coordinate degree in each patch
:param gamma_h: jump penalization parameter
:param source_proj: approximation operator for the source, possible values are 'P_geom' or 'P_L2'
:param source_type: must be implemented in get_source_and_solution()
"""

ncells = nc
degree = [deg,deg]

# if backend_language is None:
# if domain_name in ['pretzel', 'pretzel_f'] and nc > 8:
# backend_language='numba'
# else:
# backend_language='python'
# print('[note: using '+backend_language+ ' backends in discretize functions]')

print('---------------------------------------------------------------------------------------------------------')
print('Starting solve_h1_source_pbm function with: ')
print(' ncells = {}'.format(ncells))
print(' degree = {}'.format(degree))
print(' domain_name = {}'.format(domain_name))
print(' source_proj = {}'.format(source_proj))
print(' backend_language = {}'.format(backend_language))
print('---------------------------------------------------------------------------------------------------------')

print('building the multipatch domain...')
domain = build_multipatch_domain(domain_name=domain_name)
mappings = OrderedDict([(P.logical_domain, P.mapping) for P in domain.interior])
mappings_list = list(mappings.values())
ncells_h = {patch.name: [ncells[i], ncells[i]] for (i,patch) in enumerate(domain.interior)}
domain_h = discretize(domain, ncells=ncells_h)

print('building the symbolic and discrete deRham sequences...')
derham = Derham(domain, ["H1", "Hcurl", "L2"])
derham_h = discretize(derham, domain_h, degree=degree)

# multi-patch (broken) spaces
V0h = derham_h.V0
V1h = derham_h.V1
V2h = derham_h.V2
print('dim(V0h) = {}'.format(V0h.nbasis))
print('dim(V1h) = {}'.format(V1h.nbasis))
print('dim(V2h) = {}'.format(V2h.nbasis))

print('broken differential operators...')
# broken (patch-wise) differential operators
bD0, bD1 = derham_h.broken_derivatives_as_operators
bD0_m = bD0.to_sparse_matrix()
# bD1_m = bD1.to_sparse_matrix()

print('building the discrete operators:')
print('commuting projection operators...')
nquads = [4*(d + 1) for d in degree]
P0, P1, P2 = derham_h.projectors(nquads=nquads)

I0 = IdLinearOperator(V0h)
I0_m = I0.to_sparse_matrix()

print('Hodge operators...')
# multi-patch (broken) linear operators / matrices
H0 = HodgeOperator(V0h, domain_h, backend_language=backend_language)
H1 = HodgeOperator(V1h, domain_h, backend_language=backend_language)

dH0_m = H0.get_dual_Hodge_sparse_matrix() # = mass matrix of V0
H0_m = H0.to_sparse_matrix() # = inverse mass matrix of V0
dH1_m = H1.get_dual_Hodge_sparse_matrix() # = mass matrix of V1
# H1_m = H1.to_sparse_matrix() # = inverse mass matrix of V1

print('conforming projection operators...')
# conforming Projections (should take into account the boundary conditions of the continuous deRham sequence)
cP0_m = construct_V0_conforming_projection(V0h, domain_h, hom_bc=True)
# cP1_m = construct_V1_conforming_projection(V1h, domain_h, hom_bc=True)

if not os.path.exists(plot_dir):
os.makedirs(plot_dir)

def lift_u_bc(u_bc):
if u_bc is not None:
print('lifting the boundary condition in V0h... [warning: Not Tested Yet!]')
# note: for simplicity we apply the full P1 on u_bc, but we only need to set the boundary dofs
u_bc = lambdify(domain.coordinates, u_bc)
u_bc_log = [pull_2d_h1(u_bc, m.get_callable_mapping()) for m in mappings_list]
# it's a bit weird to apply P1 on the list of (pulled back) logical fields -- why not just apply it on u_bc ?
uh_bc = P0(u_bc_log)
ubc_c = uh_bc.coeffs.toarray()
# removing internal dofs (otherwise ubc_c may already be a very good approximation of uh_c ...)
ubc_c = ubc_c - cP0_m.dot(ubc_c)
else:
ubc_c = None
return ubc_c

# Conga (projection-based) stiffness matrices:
# div grad:
pre_DG_m = - bD0_m.transpose() @ dH1_m @ bD0_m

# jump penalization:
jump_penal_m = I0_m - cP0_m
JP0_m = jump_penal_m.transpose() * dH0_m * jump_penal_m

pre_A_m = cP0_m.transpose() @ ( eta * dH0_m - mu * pre_DG_m ) # useful for the boundary condition (if present)
A_m = pre_A_m @ cP0_m + gamma_h * JP0_m

print('getting the source and ref solution...')
# (not all the returned functions are useful here)
N_diag = 200
method = 'conga'
f_scal, f_vect, u_bc, p_ex, u_ex, phi, grad_phi = get_source_and_solution_OBSOLETE(
source_type=source_type, eta=eta, mu=mu, domain=domain, domain_name=domain_name,
refsol_params=[N_diag, method, source_proj],
)

# compute approximate source f_h
b_c = f_c = None
if source_proj == 'P_geom':
print('projecting the source with commuting projection P0...')
f = lambdify(domain.coordinates, f_scal)
f_log = [pull_2d_h1(f, m.get_callable_mapping()) for m in mappings_list]
f_h = P0(f_log)
f_c = f_h.coeffs.toarray()
b_c = dH0_m.dot(f_c)

elif source_proj == 'P_L2':
print('projecting the source with L2 projection...')
v = element_of(V0h.symbolic_space, name='v')
expr = f_scal * v
l = LinearForm(v, integral(domain, expr))
lh = discretize(l, domain_h, V0h)
b = lh.assemble()
b_c = b.toarray()
if plot_source:
f_c = H0_m.dot(b_c)
else:
raise ValueError(source_proj)

if plot_source:
plot_field(numpy_coeffs=f_c, Vh=V0h, space_kind='h1', domain=domain, title='f_h with P = '+source_proj, filename=plot_dir+'/fh_'+source_proj+'.png', hide_plot=hide_plots)

ubc_c = lift_u_bc(u_bc)

if ubc_c is not None:
# modified source for the homogeneous pbm
print('modifying the source with lifted bc solution...')
b_c = b_c - pre_A_m.dot(ubc_c)

# direct solve with scipy spsolve
print('solving source problem with scipy.spsolve...')
uh_c = spsolve(A_m, b_c)

# project the homogeneous solution on the conforming problem space
print('projecting the homogeneous solution on the conforming problem space...')
uh_c = cP0_m.dot(uh_c)

if ubc_c is not None:
# adding the lifted boundary condition
print('adding the lifted boundary condition...')
uh_c += ubc_c

print('getting and plotting the FEM solution from numpy coefs array...')
title = r'solution $\phi_h$ (amplitude)'
params_str = 'eta={}_mu={}_gamma_h={}'.format(eta, mu, gamma_h)
plot_field(numpy_coeffs=uh_c, Vh=V0h, space_kind='h1', domain=domain, title=title, filename=plot_dir+params_str+'_phi_h.png', hide_plot=hide_plots)


if u_ex:
u = element_of(V0h.symbolic_space, name='u')
l2norm = Norm(u - u_ex, domain, kind='l2')
l2norm_h = discretize(l2norm, domain_h, V0h)
uh_c = array_to_psydac(uh_c, V0h.vector_space)
l2_error = l2norm_h.assemble(u=FemField(V0h, coeffs=uh_c))
return l2_error

if __name__ == '__main__':

t_stamp_full = time_count()

quick_run = True
# quick_run = False

omega = np.sqrt(170) # source
roundoff = 1e4
eta = int(-omega**2 * roundoff)/roundoff
# print(eta)
# source_type = 'elliptic_J'
source_type = 'manu_poisson'

# if quick_run:
# domain_name = 'curved_L_shape'
# nc = 4
# deg = 2
# else:
# nc = 8
# deg = 4

domain_name = 'pretzel_f'
# domain_name = 'curved_L_shape'
nc = np.array([8, 8, 16, 16, 8, 4, 4, 4, 4, 4, 2, 2, 4, 16, 16, 8, 2, 2, 2])
deg = 2

# nc = 2
# deg = 2

run_dir = '{}_{}_nc={}_deg={}/'.format(domain_name, source_type, nc, deg)
solve_h1_source_pbm_nc(
nc=nc, deg=deg,
eta=eta,
mu=1, #1,
domain_name=domain_name,
source_type=source_type,
backend_language='pyccel-gcc',
plot_source=True,
plot_dir='./plots/h1_tests_source_february/'+run_dir,
hide_plots=True,
)

time_count(t_stamp_full, msg='full program')
2 changes: 1 addition & 1 deletion psydac/feec/multipatch/examples_nc/hcurl_eigen_pbms_dg.py
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
from psydac.feec.multipatch.non_matching_multipatch_domain_utilities import create_square_domain
from psydac.api.postprocessing import OutputManager, PostProcessManager

def hcurl_solve_eigen_pbm_multipatch_dg(ncells=[[2,2], [2,2]], degree=[3,3], domain=[[0, np.pi],[0, np.pi]], domain_name='refined_square', backend_language='pyccel-gcc', mu=1, nu=0, gamma_h=0,
def hcurl_solve_eigen_pbm_dg(ncells=[[2,2], [2,2]], degree=[3,3], domain=[[0, np.pi],[0, np.pi]], domain_name='refined_square', backend_language='pyccel-gcc', mu=1, nu=0, gamma_h=0,
generalized_pbm=False, sigma=None, ref_sigmas=[], nb_eigs_solve=8, nb_eigs_plot=5, skip_eigs_threshold=1e-7,
plot_dir=None, hide_plots=True, m_load_dir="",):

4 changes: 2 additions & 2 deletions psydac/feec/multipatch/examples_nc/hcurl_eigen_pbms_nc.py
Original file line number Diff line number Diff line change
@@ -33,9 +33,9 @@
from psydac.api.postprocessing import OutputManager, PostProcessManager


def hcurl_solve_eigen_pbm_multipatch_nc(ncells=[[2,2], [2,2]], degree=[3,3], domain=[[0, np.pi],[0, np.pi]], domain_name='refined_square', backend_language='pyccel-gcc', mu=1, nu=0, gamma_h=0,
def hcurl_solve_eigen_pbm_nc(ncells=[[2,2], [2,2]], degree=[3,3], domain=[[0, np.pi],[0, np.pi]], domain_name='refined_square', backend_language='pyccel-gcc', mu=1, nu=0, gamma_h=0,
generalized_pbm=False, sigma=None, ref_sigmas=[], nb_eigs_solve=8, nb_eigs_plot=5, skip_eigs_threshold=1e-7,
plot_dir=None, hide_plots=True, m_load_dir="",):
plot_dir=None, hide_plots=True, m_load_dir=None,):

diags = {}

8 changes: 4 additions & 4 deletions psydac/feec/multipatch/examples_nc/hcurl_eigen_testcase.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@
import numpy as np


from psydac.feec.multipatch.examples_nc.hcurl_eigen_pbms_nc import hcurl_solve_eigen_pbm_multipatch_nc
from psydac.feec.multipatch.examples_nc.hcurl_eigen_pbms_dg import hcurl_solve_eigen_pbm_multipatch_dg
from psydac.feec.multipatch.examples_nc.hcurl_eigen_pbms_nc import hcurl_solve_eigen_pbm_nc
from psydac.feec.multipatch.examples_nc.hcurl_eigen_pbms_dg import hcurl_solve_eigen_pbm_dg

from psydac.feec.multipatch.utilities import time_count, get_run_dir, get_plot_dir, get_mat_dir, get_sol_dir, diag_fn
from psydac.feec.multipatch.utils_conga_2d import write_diags_to_file
@@ -235,7 +235,7 @@
# - we look for nb_eigs_solve eigenvalues close to sigma (skip zero eigenvalues if skip_zero_eigs==True)
# - we plot nb_eigs_plot eigenvectors
if method == 'feec':
diags, eigenvalues = hcurl_solve_eigen_pbm_multipatch_nc(
diags, eigenvalues = hcurl_solve_eigen_pbm_nc(
ncells=ncells, degree=degree,
gamma_h=gamma_h,
generalized_pbm=generalized_pbm,
@@ -253,7 +253,7 @@
m_load_dir=m_load_dir,
)
elif method == 'dg':
diags, eigenvalues = hcurl_solve_eigen_pbm_multipatch_dg(
diags, eigenvalues = hcurl_solve_eigen_pbm_dg(
ncells=ncells, degree=degree,
gamma_h=gamma_h,
generalized_pbm=generalized_pbm,
23 changes: 19 additions & 4 deletions psydac/feec/multipatch/examples_nc/hcurl_source_pbms_nc.py
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
from psydac.feec.multipatch.utilities import time_count #, export_sol, import_sol
from psydac.linalg.utilities import array_to_psydac
from psydac.fem.basic import FemField
from psydac.feec.multipatch.examples.ppc_test_cases import get_source_and_solution_OBSOLETE

from psydac.feec.multipatch.non_matching_operators import construct_V0_conforming_projection, construct_V1_conforming_projection
from psydac.api.postprocessing import OutputManager, PostProcessManager
@@ -39,8 +40,8 @@ def solve_hcurl_source_pbm_nc(
project_sol=False,
plot_source=False, plot_dir=None, hide_plots=True, skip_plot_titles=False,
cb_min_sol=None, cb_max_sol=None,
m_load_dir="", sol_filename="", sol_ref_filename="",
ref_nc=None, ref_deg=None,
m_load_dir=None, sol_filename="", sol_ref_filename="",
ref_nc=None, ref_deg=None, test=False
):
"""
solver for the problem: find u in H(curl), such that
@@ -246,9 +247,14 @@ def lift_u_bc(u_bc):
t_stamp = time_count(t_stamp)
print()
print(' -- getting source --')
f_vect, u_bc, u_ex, curl_u_ex, div_u_ex = get_source_and_solution_hcurl(
if source_type == 'manu_maxwell':
f_scal, f_vect, u_bc, p_ex, u_ex, phi, grad_phi = get_source_and_solution_OBSOLETE(
source_type=source_type, eta=eta, mu=mu, domain=domain, domain_name=domain_name,
)
)
else:
f_vect, u_bc, u_ex, curl_u_ex, div_u_ex = get_source_and_solution_hcurl(
source_type=source_type, eta=eta, mu=mu, domain=domain, domain_name=domain_name,
)
# compute approximate source f_h
t_stamp = time_count(t_stamp)
tilde_f_c = f_c = None
@@ -352,5 +358,14 @@ def lift_u_bc(u_bc):

time_count(t_stamp)

if test:
u = element_of(V1h.symbolic_space, name='u')
l2norm = Norm(Matrix([u[0] - u_ex[0],u[1] - u_ex[1]]), domain, kind='l2')
l2norm_h = discretize(l2norm, domain_h, V1h)
uh_c = array_to_psydac(uh_c, V1h.vector_space)
l2_error = l2norm_h.assemble(u=FemField(V1h, coeffs=uh_c))
print(l2_error)
return l2_error


return diags
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
test_case = 'maxwell_hom_eta=170' # used in paper
# test_case = 'maxwell_inhom' # used in paper

compute_ref_sol = False # (not needed for inhomogeneous test-case, as exact solution is known)

#
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
162 changes: 161 additions & 1 deletion psydac/feec/multipatch/tests/test_feec_maxwell_multipatch_2d.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,11 @@
import numpy as np

from psydac.feec.multipatch.examples.hcurl_source_pbms_conga_2d import solve_hcurl_source_pbm
from psydac.feec.multipatch.examples_nc.hcurl_source_pbms_nc import solve_hcurl_source_pbm_nc

from psydac.feec.multipatch.examples.hcurl_eigen_pbms_conga_2d import hcurl_solve_eigen_pbm
from psydac.feec.multipatch.examples_nc.hcurl_eigen_pbms_nc import hcurl_solve_eigen_pbm_nc
from psydac.feec.multipatch.examples_nc.hcurl_eigen_pbms_dg import hcurl_solve_eigen_pbm_dg

def test_time_harmonic_maxwell_pretzel_f():
nc,deg = 10,2
@@ -24,6 +29,161 @@ def test_time_harmonic_maxwell_pretzel_f():

assert abs(l2_error - 0.06246693595198972)<1e-10

def test_time_harmonic_maxwell_pretzel_f_nc():
deg = 2
nc = np.array([20, 20, 20, 20, 20, 10, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 10, 10])

source_type = 'manu_maxwell'
domain_name = 'pretzel_f'
source_proj = 'tilde_Pi'

omega = np.sqrt(170) # source
roundoff = 1e4
eta = int(-omega**2 * roundoff)/roundoff

l2_error = solve_hcurl_source_pbm_nc(
nc=nc, deg=deg,
eta=eta,
nu=0,
mu=1,
domain_name=domain_name,
source_type=source_type,
source_proj=source_proj,
plot_dir='./plots/th_maxell_nc',
backend_language='pyccel-gcc',
test=True)

assert abs(l2_error - 0.04753982587323614)<1e-10

def test_maxwell_eigen_curved_L_shape():
domain_name = 'curved_L_shape'

nc = 10
deg = 2

ref_sigmas = [
0.181857115231E+01,
0.349057623279E+01,
0.100656015004E+02,
0.101118862307E+02,
0.124355372484E+02,
]
sigma = 7
nb_eigs_solve = 7
nb_eigs_plot = 7
skip_eigs_threshold = 1e-7

eigenvalues, eigenvectors = hcurl_solve_eigen_pbm(
nc=nc, deg=deg,
gamma_h=0,
nu=0,
mu=1,
sigma=sigma,
skip_eigs_threshold=skip_eigs_threshold,
nb_eigs=nb_eigs_solve,
nb_eigs_plot=nb_eigs_plot,
domain_name=domain_name,
backend_language='pyccel-gcc',
plot_dir='./plots/eigen_maxell',
)

error = 0
n_errs = min(len(ref_sigmas), len(eigenvalues))
for k in range(n_errs):
error += (eigenvalues[k]-ref_sigmas[k])**2
error = np.sqrt(error)

assert abs(error - 0.023413963252245817)<1e-10

def test_maxwell_eigen_curved_L_shape_nc():
domain_name = 'curved_L_shape'
domain=[[1, 3],[0, np.pi/4]]

ncells = np.array([[None, 10],
[10, 20]])

degree = [2, 2]

ref_sigmas = [
0.181857115231E+01,
0.349057623279E+01,
0.100656015004E+02,
0.101118862307E+02,
0.124355372484E+02,
]
sigma = 7
nb_eigs_solve = 7
nb_eigs_plot = 7
skip_eigs_threshold = 1e-7

diags, eigenvalues = hcurl_solve_eigen_pbm_nc(
ncells=ncells, degree=degree,
gamma_h=0,
generalized_pbm=True,
nu=0,
mu=1,
sigma=sigma,
ref_sigmas=ref_sigmas,
skip_eigs_threshold=skip_eigs_threshold,
nb_eigs_solve=nb_eigs_solve,
nb_eigs_plot=nb_eigs_plot,
domain_name=domain_name, domain=domain,
backend_language='pyccel-gcc',
plot_dir='./plots/eigen_maxell_nc',
)

error = 0
n_errs = min(len(ref_sigmas), len(eigenvalues))
for k in range(n_errs):
error += (eigenvalues[k]-ref_sigmas[k])**2
error = np.sqrt(error)

assert abs(error - 0.004289103786542442)<1e-10

def test_maxwell_eigen_curved_L_shape_dg():
domain_name = 'curved_L_shape'
domain=[[1, 3],[0, np.pi/4]]

ncells = np.array([[None, 10],
[10, 20]])

degree = [2, 2]

ref_sigmas = [
0.181857115231E+01,
0.349057623279E+01,
0.100656015004E+02,
0.101118862307E+02,
0.124355372484E+02,
]
sigma = 7
nb_eigs_solve = 7
nb_eigs_plot = 7
skip_eigs_threshold = 1e-7

diags, eigenvalues = hcurl_solve_eigen_pbm_dg(
ncells=ncells, degree=degree,
gamma_h=0,
generalized_pbm=True,
nu=0,
mu=1,
sigma=sigma,
ref_sigmas=ref_sigmas,
skip_eigs_threshold=skip_eigs_threshold,
nb_eigs_solve=nb_eigs_solve,
nb_eigs_plot=nb_eigs_plot,
domain_name=domain_name, domain=domain,
backend_language='pyccel-gcc',
plot_dir='./plots/eigen_maxell_dg',
)

error = 0
n_errs = min(len(ref_sigmas), len(eigenvalues))
for k in range(n_errs):
error += (eigenvalues[k]-ref_sigmas[k])**2
error = np.sqrt(error)

assert abs(error - 0.004208158031148591)<1e-10

#==============================================================================
# CLEAN UP SYMPY NAMESPACE
@@ -35,4 +195,4 @@ def teardown_module():

def teardown_function():
from sympy.core import cache
cache.clear_cache()
cache.clear_cache()
30 changes: 24 additions & 6 deletions psydac/feec/multipatch/tests/test_feec_poisson_multipatch_2d.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import numpy as np

from psydac.feec.multipatch.examples.h1_source_pbms_conga_2d import solve_h1_source_pbm
from psydac.feec.multipatch.examples_nc.h1_source_pbms_nc import solve_h1_source_pbm_nc

def test_poisson_pretzel_f():

@@ -16,9 +19,27 @@ def test_poisson_pretzel_f():
backend_language='pyccel-gcc',
plot_source=False,
plot_dir='./plots/h1_tests_source_february/'+run_dir)
print(l2_error)
assert abs(l2_error-8.054935880021907e-05)<1e-10

assert abs(l2_error-0.11860734907095004)<1e-10

def test_poisson_pretzel_f_nc():

source_type = 'manu_poisson_2'
domain_name = 'pretzel_f'
nc = np.array([20, 20, 20, 20, 20, 10, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 10, 10])
deg = 2
run_dir = '{}_{}_nc={}_deg={}/'.format(domain_name, source_type, nc, deg)
l2_error = solve_h1_source_pbm_nc(
nc=nc, deg=deg,
eta=0,
mu=1,
domain_name=domain_name,
source_type=source_type,
backend_language='pyccel-gcc',
plot_source=False,
plot_dir='./plots/h1_tests_source_february/'+run_dir)

assert abs(l2_error-0.04324704991715671)<1e-10
#==============================================================================
# CLEAN UP SYMPY NAMESPACE
#==============================================================================
@@ -29,7 +50,4 @@ def teardown_module():

def teardown_function():
from sympy.core import cache
cache.clear_cache()

if __name__ == '__main__':
test_poisson_pretzel_f()
cache.clear_cache()