-
Notifications
You must be signed in to change notification settings - Fork 21
Broken FEEC projections on polar domains #576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alisa-kirkinskaia
wants to merge
144
commits into
devel
Choose a base branch
from
polar_splines_alisa
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
144 commits
Select commit
Hold shift + click to select a range
c3c801d
poisson can run in parallel
ad8adad
reorganize
364d64c
only one geometry file is created
04b6e8c
minor changes
5012856
update names in examples/poisson_2d_mapping.py
51d0592
error in plot_2d_decomposition
63f9b65
merge 'devel' into polar_splines_alisa
7354e97
fix an error after merging
2c28462
error in plot_2d_decomposition
a86faf1
Use tight layout
yguclu 6d1304f
Avoid string warnings
yguclu 39d14f4
some changes to visualization
0ca428e
Merge branch 'polar_splines_alisa' of https://github.com/pyccel/psyda…
9d2a618
computing average in parallel
77cd4e4
fixed errors in parallel average
e6c8a1a
Merge branch 'devel' into polar_splines_alisa
dbdf3a1
update plot_2d_decomposition
8ce233f
Changes in disk domain
c4eab7c
Callable exact solution in logical coordinates for plotting
1026b3d
Fix right hand side
ad0a0db
Fix smoothing methods 'None', 'polar-std' and 'polar-spec'
fb2213b
Print info
529897b
remove trick
6feacff
fixed issue with polar-spec and polar-std (cause unknown)
6e74dd0
fix crash with analytical mapping
3682565
it now works with analytical mapping
0e7f56e
typo
573501c
Merge branch 'devel' into polar_splines_alisa
04e9c4b
initial commit for maxwell
bd3e1d5
fixed some errors
850100a
parallelization, fixed mapping
1a722f2
fixed an error with study_L2proj
5d3477f
fix plots at final time
cc500f8
Plotting only for root process
b048929
remove use_logical_solution
1e3e31c
fix error (exporting fields before projecting), remove comments
4687a24
create grid only with root process
516124e
tests for projection
25efc2e
fix P1 for C0
b50640e
fix P1 for C0
858078c
remove prints
e7ef374
fix a bug when use_spline_mapping is False
4051e64
small changes
baf1a32
C1 projections in serial
6894d32
added P0 C1
1262f66
Parallelize C1PolarProjection_V0
4508259
parallelized C1PolarProjection_V1
bedf25d
use only one allreduce
a37ef70
tosparse and unit test for C0 P0
6c7c072
fix a bug in test
d59232f
Merge branch 'devel' into polar_splines_alisa
3baed17
C0 projection P2 and unit tests
bf2b887
some unit tests for P1
463f009
tosparse for C0 P1 and hbc for tests
bda769b
add transposed to tests
fd7b300
fix bug in dot methods
6e97568
tosparse and unit test for C1 projection P0
8865845
refactor unit tests
f429390
get global vector for sparse operators
ccc485e
Merge branch 'devel' into polar_splines_alisa
758139b
add reference matrices to test the tosparse methods
d40e423
make some tests run correctly in parallel
2bf379f
tosparse methods for C1 P1
d5f180c
fixed deadlock in P1 C1
b37c41a
small fix
beaf3c9
Merge branch 'devel' into polar_splines_alisa
yguclu 72864d6
merge polar_splines_alisa into polar_splines_alisa
ed9d75d
fix variable referenced before assignment
2a92569
small fix
4aa2591
changes in maxwell example
48b49e2
atol rtol in unit tests
4b19433
test checking entries of sparse matrices for P0
067ddf8
change allclose to isclose
054900f
test checking entries of sparse matrices for P2
099e586
test checking entries of sparse matrices for P1
f7555b4
change tosparse of C0 to distribution by row
e2a0a71
transpose for P2
3525acc
tosparse methods for C1 distributed by row
7d91955
fix failing test
7994262
revert changes in unrelated file
23525d0
remove unnecessary tests
88d82a1
Merge branch 'devel' into polar_splines_alisa
yguclu 59b84c3
added conversion to coo matrix
551323c
changed atol and rtol to constants
b75b380
whitespaces
e91cbac
added verbose flag for unit tests
84d2848
utility function for gathering arrays of variable len
80a0fbd
specify datatype for cols and rows in tosparse
bdb796e
use Gatherv in the tests
7ae3507
added parameter mpi_root to utility function
2b8cb33
multiple numpy arrays can be passed to gather_vlen_arrays
85bcec6
clean up check_regular_ring_map
4be6872
remove unnecessary flag
99d935b
remove unused variable
8a048a7
change docstring
bf7dc69
remove some comments
487eda0
remove unused variables
a7bde8d
clean up debugging functions
ac3be5e
docstring for Laplacian class
514fb11
clean up Poisson example
501a18b
changed params dict in disk
36357d0
remove coordinates property
71788a6
testing my branch of sympde
be219a6
change mapping params to Rational
6ce62d3
Merge branch 'devel' into polar_splines_alisa
923fa53
change czarny mapping params to Rational
79f70cf
changed domain in Poisson2D to sympde domain
406e708
minor cleanup
edad37c
move plotting to a separate function
2a9b82a
add refine param to plotting
b7903ae
changes in mapping for plotting
9569239
codacy is complaining
b6184cf
codacy is complaining
ba6bca6
define a function compute_errors
47e1bac
moved add_colorbar to utils
7ba6f43
separated plotting objects creation
cde57db
remove some old comments
d456677
uncomment plot_fields_along_s
70ee0b3
remove some old todos
campospinto eaadbe5
Merge branch 'polar_splines_alisa' of https://github.com/pyccel/psyda…
f41754d
remove add_colorbar from Poisson
0659eb7
create space V only when use_spline_mapping
76c0bab
added docstring to Poisson
27dbf60
remove some unused variables
81cb257
remove some unused things
ab097db
rename phi, rho -> phi_log, rho_log in Poisson2D
2ad02db
rename domain -> domain_log
68516f4
some simplifications in Maxwell
880ef94
improvements in plotting logic
d53efb6
fix empty windows
26fc230
Fixed initial solution waveTE
7eabc4b
added utility function create_tensor_spline_space
3d9e4c7
removed basic_fix variable
f6687dc
fix error in L2 errors
f5df0fc
remove unused functions
5820abe
a few small changes in Poisson
21be4da
remove unused things from Maxwell
75e0474
docstring for run_study_L2_proj
ba35ee7
changed names of discrete derham spaces
b28334d
IdentityOperator
234203b
add backend
2dffb86
correct comments
801025f
write matrix vector mul in a better way
fb37885
add comment for BC
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,289 @@ | ||
| from sympde.topology import Square | ||
| from sympde.topology.analytical_mapping import PolarMapping | ||
|
|
||
| from psydac.api.tests.test_api_feec_2d import add_colorbar | ||
| from psydac.feec.pull_push import push_2d_hcurl, push_2d_l2 | ||
| from numpy import pi | ||
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| class CircularCavitySolution: | ||
| """ | ||
| Time-harmonic solution of Maxwell's equations in a disk-like domain with | ||
| perfectly conducting walls. This is a "transverse electric" solution, with | ||
| E = (Ex, Ey) and B = Bz. Domain is [0, R] x [0, 2pi]. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| R : float | ||
| domain radius | ||
|
|
||
| c: float | ||
| Speed of light in arbitrary units | ||
|
|
||
| (m, n): int | ||
| Mode number. Warning: m > 0, n >= 0 | ||
|
|
||
| D: float | ||
| shift of logical center (in "Target" mapping with c0=D*R2, c1=0, k=0, D=D) | ||
|
|
||
| scale: float | ||
| Rescaling the values by a real factor. Default = 1 | ||
|
|
||
| """ | ||
|
|
||
| def __init__(self, R, c, m, n, D=0, scale=1): | ||
| from numpy import pi | ||
| from scipy.special import jnp_zeros | ||
| pnm = jnp_zeros(n, m)[-1] | ||
| kc = pnm / R | ||
| omega = c * kc | ||
|
|
||
| phase = pi / 4 | ||
|
|
||
| self.c = c | ||
| self.scale = scale | ||
| self.n = n | ||
| self.kc = kc | ||
| self.omega = omega | ||
| self.phase = phase | ||
| self._R = R | ||
| assert 0 <= D < .5 | ||
| self._D = D | ||
|
|
||
| # Exact solutions for electric and magnetic field with polar parametrization of disk domain | ||
| def Es_ex(self, t, s, theta): | ||
| from numpy import sin # , cos, sqrt, arctan2 | ||
| from scipy.special import jv | ||
|
|
||
| scale = self.scale | ||
| n = self.n | ||
| kc = self.kc | ||
| omega = self.omega | ||
| phase = self.phase | ||
| c = self.c | ||
|
|
||
| return - scale * c * n / (s * kc + 1e-10) * sin(n * theta) * jv(n, kc * s) * sin(omega * t + phase) | ||
|
|
||
| def Et_ex(self, t, s, theta, s_factor=True): | ||
| """ | ||
| if s_factor: multiply by s (as in logical field) | ||
| """ | ||
| from numpy import sin, cos | ||
| from scipy.special import jvp | ||
|
|
||
| scale = self.scale | ||
| n = self.n | ||
| kc = self.kc | ||
| omega = self.omega | ||
| phase = self.phase | ||
| c = self.c | ||
|
|
||
| val = - scale * c * cos(n * theta) * jvp(n, kc * s) * sin(omega * t + phase) | ||
| if s_factor: | ||
| val *= s | ||
| return val | ||
|
|
||
| def B_ex(self, t, s, theta, s_factor=True): | ||
| """ | ||
| if s_factor: multiply by s (as in logical field) | ||
| """ | ||
| from numpy import cos | ||
| from scipy.special import jv | ||
|
|
||
| scale = self.scale | ||
| n = self.n | ||
| kc = self.kc | ||
| omega = self.omega | ||
| phase = self.phase | ||
|
|
||
| val = scale * cos(n * theta) * jv(n, kc * s) * cos(omega * t + phase) | ||
| if s_factor: | ||
| val *= s | ||
| return val | ||
| # The magnitude of B is approximately equal to scale / 3 | ||
|
|
||
| def dB_dt_ex(self, t, s, theta): | ||
| ''' | ||
| = dB/dt | ||
| ''' | ||
| from numpy import cos, sin | ||
| from scipy.special import jv | ||
|
|
||
| scale = self.scale | ||
| n = self.n | ||
| kc = self.kc | ||
| omega = self.omega | ||
| phase = self.phase | ||
|
|
||
| return scale * omega * s * cos(n * theta) * jv(n, kc * s) * sin(omega * t + phase) | ||
|
|
||
| # physical field | ||
|
|
||
| def get_radius_angle(self, x, y): | ||
| from numpy import sqrt, arctan2 # , sin, cos | ||
| r = sqrt(x * x + y * y) | ||
| alpha = arctan2(y, x) | ||
| return r, alpha | ||
|
|
||
| def Ex_ex(self, t, x, y): | ||
| from numpy import cos, sin | ||
|
|
||
| r, alpha = self.get_radius_angle(x, y) | ||
| return cos(alpha) * self.Es_ex(t, r, alpha) - sin(alpha) * self.Et_ex(t, r, alpha, s_factor=False) | ||
|
|
||
| def Ey_ex(self, t, x, y): | ||
| from numpy import cos, sin | ||
|
|
||
| r, alpha = self.get_radius_angle(x, y) | ||
| return sin(alpha) * self.Es_ex(t, r, alpha) + cos(alpha) * self.Et_ex(t, r, alpha, s_factor=False) | ||
|
|
||
| def Bz_ex(self, t, x, y): | ||
|
|
||
| r, alpha = self.get_radius_angle(x, y) | ||
| return self.B_ex(t, r, alpha, s_factor=False) | ||
|
|
||
|
|
||
| def main(): | ||
| """ | ||
| This function is not currently used. It is kept for possible future development. | ||
| """ | ||
|
|
||
| # Logical domain is rectangle [0, R] x [0, 2pi] | ||
| R = 2.0 | ||
|
|
||
| # Speed of light equal c and scaling of the fields by a scale factor | ||
| c = 1 | ||
| scale = 1 | ||
|
|
||
| # Mode number | ||
| # (m, n) = (1, 0) | ||
| # (m, n) = (2, 1) | ||
| (m, n) = (2, 3) | ||
|
|
||
| # Exact solution | ||
| exact_solution = CircularCavitySolution(R=R, c=c, m=m, n=n, scale=scale) | ||
|
|
||
| # Exact fields, as callable functions of (t, s, theta) | ||
| Es_ex = exact_solution.Es_ex | ||
| Et_ex = exact_solution.Et_ex | ||
| B_ex = exact_solution.B_ex | ||
| dB_dt_ex = exact_solution.dB_dt_ex | ||
|
|
||
| # Logical domain: [0, R] x [0, 2pi] | ||
| logical_domain = Square('Omega', bounds1=[0, R], bounds2=[0, 2 * pi]) | ||
|
|
||
| # Physical domain: disk of radius R obtained as image of the logical_domain | ||
| # with the analytical mapping of a circle | ||
| mapping = PolarMapping('F', c1=0, c2=0, rmin=0, rmax=1) | ||
| domain = mapping(logical_domain) | ||
| F = mapping.get_callable_mapping() | ||
|
|
||
| # Set time | ||
| t = 0 | ||
|
|
||
| Es = lambda x, y: Es_ex(t, x, y) | ||
| Et = lambda x, y: Et_ex(t, x, y) | ||
| B = lambda x, y: B_ex(t, x, y) | ||
| dB_dt = lambda x, y: dB_dt_ex(t, x, y) | ||
|
|
||
| # Plot of fields | ||
| N = 100 | ||
|
|
||
| rho = np.linspace(1e-20, R, N) | ||
| theta = np.linspace(0, 2 * pi, N) | ||
| rho, theta = np.meshgrid(rho, theta, indexing='ij') | ||
| x, y = F(rho, theta) | ||
|
|
||
| Ex_values = np.empty_like(rho) | ||
| Ey_values = np.empty_like(rho) | ||
| B_values = np.empty_like(rho) | ||
|
|
||
| for i, x1i in enumerate(rho[:, 0]): | ||
| for j, x2j in enumerate(theta[0, :]): | ||
| Ex_values[i, j], Ey_values[i, j] = \ | ||
| push_2d_hcurl(Es, Et, x1i, x2j, F) | ||
|
|
||
| B_values[i, j] = push_2d_l2(B, x1i, x2j, F) | ||
|
|
||
| fig, axs = plt.subplots(2, 2, figsize=(12, 12)) | ||
| im0 = axs[0, 0].contourf(x, y, Ex_values, 50) | ||
| im1 = axs[0, 1].contourf(x, y, Ey_values, 50) | ||
| im2 = axs[1, 0].contourf(x, y, np.sqrt(Ex_values ** 2 + Ey_values ** 2), 50) | ||
| im3 = axs[1, 1].contourf(x, y, B_values, 50) | ||
| axs[0, 0].set_title(r'$E_x$') | ||
| axs[0, 1].set_title(r'$E_y$') | ||
| axs[1, 0].set_title(r'$||\mathbf{E}||$') | ||
| axs[1, 1].set_title('$B$') | ||
| add_colorbar(im0, axs[0, 0]) | ||
| add_colorbar(im1, axs[0, 1]) | ||
| add_colorbar(im2, axs[1, 0]) | ||
| add_colorbar(im3, axs[1, 1]) | ||
|
|
||
| # Test: curl E = - d_t B_z with finite Differences | ||
| # on a tensor grid in the square inscribed the disk | ||
| N = 160 | ||
| l = R / np.sqrt(2) # edge length | ||
|
|
||
| x, dx = np.linspace(-l, l, N, retstep=True) | ||
| y, dy = np.linspace(-l, l, N, retstep=True) | ||
| x, y = np.meshgrid(x, y, indexing='ij') | ||
| rho = np.sqrt(x ** 2 + y ** 2) | ||
| theta = np.arctan2(y, x) % (2 * pi) | ||
|
|
||
| Ex_values = np.empty_like(rho) | ||
| Ey_values = np.empty_like(rho) | ||
| Bt_values = np.empty_like(rho) | ||
|
|
||
| ni, nj = rho.shape | ||
| for i in range(ni): | ||
| for j in range(nj): | ||
| x1_ij = rho[i, j] | ||
| x2_ij = theta[i, j] | ||
| Ex_values[i, j], Ey_values[i, j] = \ | ||
| push_2d_hcurl(Es, Et, x1_ij, x2_ij, F) | ||
|
|
||
| Bt_values[i, j] = push_2d_l2(dB_dt, x1_ij, x2_ij, F) | ||
|
|
||
| fig, axs = plt.subplots(2, 3, figsize=(15, 15)) | ||
| im1 = axs[0, 0].contourf(x, y, np.sqrt(Ex_values ** 2 + Ey_values ** 2)) | ||
| im2 = axs[0, 1].contourf(x, y, -Bt_values) | ||
| axs[0, 0].set_title(r'$||\mathbf{E}||$') | ||
| axs[0, 1].set_title(r'$-\partial_t B$') | ||
| for axi in axs.flat: | ||
| axi.set_aspect('equal') | ||
| add_colorbar(im1, axs[0, 0]) | ||
| add_colorbar(im2, axs[0, 1]) | ||
|
|
||
| curlE_values = np.zeros_like(rho) | ||
| valerr = 0 | ||
| for i in range(1, ni - 1): | ||
| for j in range(1, nj - 1): | ||
| curlE_values[i, j] = (Ey_values[i + 1, j] - Ey_values[i - 1, j]) / (2 * dx) \ | ||
| - (Ex_values[i, j + 1] - Ex_values[i, j - 1]) / (2 * dy) | ||
|
|
||
| d = np.abs(Bt_values[i, j] + curlE_values[i, j]) | ||
|
|
||
| if valerr < d: | ||
| valerr = d | ||
|
|
||
| skip = (slice(None, None, int(N / 20)), slice(None, None, int(N / 20))) | ||
| im3 = axs[1, 0].contourf(x, y, curlE_values) | ||
| axs[1, 0].quiver(x[skip], y[skip], Ex_values[skip], Ey_values[skip]) | ||
| add_colorbar(im3, axs[1, 0]) | ||
| axs[1, 0].set_title(r'curl $\mathbf{E}$') | ||
| im4 = axs[1, 1].contourf(x, y, -Bt_values) | ||
| axs[1, 1].quiver(x[skip], y[skip], Ex_values[skip], Ey_values[skip]) | ||
| add_colorbar(im4, axs[1, 1]) | ||
| im5 = axs[0, 2].contourf(x, y, Ex_values) | ||
| im6 = axs[1, 2].contourf(x, y, Ey_values) | ||
| add_colorbar(im5, axs[0, 2]) | ||
| add_colorbar(im6, axs[1, 2]) | ||
| print('|curlE + d_t B| <= ', valerr) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| plt.show() | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @alisa-kirkinskaia, I've started reviewing your PR and will leave some comments throughout the next days. Regarding this particular file: What is its purpose? Are you testing different plotting options?
I've also noticed that the variable
variablesis not used in the__init__ofCircularCavitySolution(What isCircularCavitySolution?). And in themainfunction you first mention that the physical domain is a rectangle, and later that the physical domain is also a disk? Also, thedomainvariable is not used and could be removed.