Skip to content

Conversation

@brownbaerchen
Copy link
Contributor

Boundary conditions in these bases are implemented by evaluating the Chebychev T polynomials in the boundary condition. For instance, the boundary condition $u(x=x_b)=v$ with $N$ degrees of freedom is implemented by evaluating all $T_n, 0\leq n<N$ at $x=x_b$, putting the values in one line of the system matrix and putting $v$ in the corresponding spot in the right hand side vector. For special values, this is simple. For instance, $T_n(x=1)=1$, i.e. we would need to add a line of all ones to the system matrix.
Perhaps a better way of understanding this is that you can compute the value on the boundary in physical space by extrapolating from the coefficients in frequency space by a weighted sum of these coefficients. Putting this in the system matrix reverses this process from What is the value at the boundary? to The value at the boundary is $v$.

Neumann BCs are like $\partial_x u(x=x_b)=v$. Here, we need the derivative of the $T_n$. Looking on Wikipedia, we find that $\partial_x T_n(x) = n U_{n-1}(x)$ and $U_n(x=1) = n+1$, therefore $\partial_x T_n(x=1) = n^2$. A similarly easy version exists for the left boundary $x=-1$.

This is exactly what is implemented in this PR. The algorithmic structure of Neumann BCs is exactly the same as for Dirichlet BCs in these spectral methods. All we need to change is the lines we put in the system matrix. This PR allows to populate these lines such that Neumann BCs at either end of the boundary result.

@pancetta pancetta merged commit 5099de8 into Parallel-in-Time:master Aug 26, 2025
47 checks passed
brownbaerchen added a commit to brownbaerchen/pySDC that referenced this pull request Nov 4, 2025
#!!!!!!!!!! WARNING: RUFF FAILED !!!!!!!!!!: 

#pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:298:5: F841 Local variable `data` is assigned to but never used
#    |
Parallel-in-Time#296 |     res = 32
Parallel-in-Time#297 |
Parallel-in-Time#298 |     data = []
#    |     ^^^^ F841
Parallel-in-Time#299 |     labels = []
Parallel-in-Time#300 |     linestyles = []
#    |
#    = help: Remove assignment to unused variable `data`
#
#pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:299:5: F841 Local variable `labels` is assigned to but never used
#    |
Parallel-in-Time#298 |     data = []
Parallel-in-Time#299 |     labels = []
#    |     ^^^^^^ F841
Parallel-in-Time#300 |     linestyles = []
#    |
#    = help: Remove assignment to unused variable `labels`
#
#pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:300:5: F841 Local variable `linestyles` is assigned to but never used
#    |
Parallel-in-Time#298 |     data = []
Parallel-in-Time#299 |     labels = []
Parallel-in-Time#300 |     linestyles = []
#    |     ^^^^^^^^^^ F841
Parallel-in-Time#301 |
Parallel-in-Time#302 |     ref_data = get_pySDC_data(Ra, res=res, dt=0.01, config_name='RBC3DG4R4')
#    |
#    = help: Remove assignment to unused variable `linestyles`
#
#pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:312:9: F841 Local variable `t` is assigned to but never used
#    |
Parallel-in-Time#310 |         ax.set_title(title)
Parallel-in-Time#311 |         Nu_ref = np.array(ref['Nu']['V'])
Parallel-in-Time#312 |         t = ref['t']
#    |         ^ F841
Parallel-in-Time#313 |
Parallel-in-Time#314 |         for dt in dts:
#    |
#    = help: Remove assignment to unused variable `t`
#
#pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:587:9: E722 Do not use bare `except`
#    |
Parallel-in-Time#585 |                 k[_s > 1e-16], _s[_s > 1e-16], color=last_line.get_color(), ls=last_line.get_linestyle(), label=label
Parallel-in-Time#586 |             )
Parallel-in-Time#587 |         except:
#    |         ^^^^^^ E722
Parallel-in-Time#588 |             pass
#    |
#
#pySDC/projects/GPU/analysis_scripts/compare_RBC3D.py:686:5: F841 Local variable `Delta_Nu` is assigned to but never used
#    |
#684 |     t = data['t']
#685 |     avg_Nu = np.array([np.mean(Nu[40 : 40 + i + 1]) for i in range(len(Nu[40:]))])
#686 |     Delta_Nu = np.array([abs(avg_Nu[i + 1] - avg_Nu[i]) for i in range(len(avg_Nu) - 1)])
#    |     ^^^^^^^^ F841
#687 |     # ax.plot(data['t'][40:-1], Delta_Nu / avg_Nu[:-1])
#688 |     # ax.plot(data['t'], np.abs(avg_Nu - avg_Nu[-1]) / avg_Nu[-1])
#    |
#    = help: Remove assignment to unused variable `Delta_Nu`:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants