Difference between revisions of "Complex-valued problems"

From Medusa: Coordinate Free Mehless Method implementation
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
Go back to [[Medusa#Examples|Examples]].
 
Go back to [[Medusa#Examples|Examples]].
  
Our library natively supports complex numbers. To demonstrate this a simple example of Poisson's equation is presented below. For more complicated complex-valued problems see [[Electromagnetic scattering]] and [[Schrödinger equation]].
+
Our library natively supports complex numbers. To demonstrate this a tutorial for solving Poisson's equation is presented below. For more complicated complex-valued problems see [[Electromagnetic scattering]] and [[Schrödinger equation]].
  
 
== 2D Complex Poisson's equation ==
 
== 2D Complex Poisson's equation ==
Line 12: Line 12:
 
\end{align*}
 
\end{align*}
 
\]
 
\]
where $u(x,y)$ is the solution to the problem and $\Omega = [0, 1] \times [0, 1]$ denotes the square domain. We will consider $f(x,y) = 2\pi^2\sin(\pi x)\sin(\pi y)$, as it makes for  
+
where $u(x,y)$ is the solution to the problem and $\Omega = [0, 1] \times [0, 1]$ the square domain. We will consider $f(x,y) = 2\pi^2\sin(\pi x)\sin(\pi y)$, as it makes for  
 
a simple solution $u(x,y) = i\sin(\pi x)\sin(\pi y)$.
 
a simple solution $u(x,y) = i\sin(\pi x)\sin(\pi y)$.
  
We write the equations for our problem by directly translating the mathematical formulation above into code.
+
We write the equations for our problem by directly translating the mathematical formulation above into the code.
  
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
Line 21: Line 21:
 
     double x = domain.pos(i, 0);
 
     double x = domain.pos(i, 0);
 
     double y = domain.pos(i, 1);
 
     double y = domain.pos(i, 1);
     1.0_i * op.lap(i) = -2*PI*PI*sin(PI * x)*sin(PI * y);
+
     1.0_i * op.lap(i) = 2*PI*PI*sin(PI * x)*sin(PI * y);
 
}
 
}
 
for (int i : domain.boundary()) {
 
for (int i : domain.boundary()) {
Line 28: Line 28:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
The solution $u(x,y)$ is plotted below. In our case solution consist only of the imaginary part, the real part is equal to zero.  
+
The solution $u(x,y)$ is plotted below. In our case solution consists only of the imaginary part, the real part is equal to zero.  
  
 
[[File:complex_poisson_2D_real.png|500px]]
 
[[File:complex_poisson_2D_real.png|500px]]

Latest revision as of 16:29, 19 July 2019

Go back to Examples.

Our library natively supports complex numbers. To demonstrate this a tutorial for solving Poisson's equation is presented below. For more complicated complex-valued problems see Electromagnetic scattering and Schrödinger equation.

2D Complex Poisson's equation

We are solving 2D complex Poisson equation, on a unit square with Dirichlet boundary conditions

\[ \begin{align*} i \Delta u &= f &&\text{in } \Omega, \\ u &= 0 &&\text{on } \partial \Omega, \end{align*} \] where $u(x,y)$ is the solution to the problem and $\Omega = [0, 1] \times [0, 1]$ the square domain. We will consider $f(x,y) = 2\pi^2\sin(\pi x)\sin(\pi y)$, as it makes for a simple solution $u(x,y) = i\sin(\pi x)\sin(\pi y)$.

We write the equations for our problem by directly translating the mathematical formulation above into the code.

for (int i : domain.interior()) {
    double x = domain.pos(i, 0);
    double y = domain.pos(i, 1);
    1.0_i * op.lap(i) = 2*PI*PI*sin(PI * x)*sin(PI * y);
}
for (int i : domain.boundary()) {
    op.value(i) = 0.0;
}

The solution $u(x,y)$ is plotted below. In our case solution consists only of the imaginary part, the real part is equal to zero.

Complex poisson 2D real.png Complex poisson 2D imag.png

Go back to Examples.