60static auto SetParMesh = [](
Mesh &mesh) {
return ParMesh(MPI_COMM_WORLD, mesh); };
61static auto SetOrthoSolver = []() {
return OrthoSolver(MPI_COMM_WORLD); };
62static auto SetCGSolver = []() {
return CGSolver(MPI_COMM_WORLD); };
63static auto SetGMRESSolver = []() {
return GMRESSolver(MPI_COMM_WORLD); };
66struct SchrodingerSolver :
public Kernels
72 CrankNicolsonSchrodingerTimeSolver(ParFiniteElementSpace &fes,
81 void Mult(ParComplexGridFunction &psi)
override
83 psi.ParallelProject(PSI);
89 } time_1_solver, time_2_solver;
93 SchrodingerSolver(
Options &config):
94 Kernels(config, SetParMesh, SetOrthoSolver, SetCGSolver),
101 nodes.SetTrueVector();
102 nodes.SetFromTrueVector();
105 void Step() { time_1_solver.Mult(
psi1); time_2_solver.Mult(
psi2); }
109 const auto Grad_nd = [&](ParGridFunction &in_h1, ParGridFunction &out_nd)
111 in_h1.SetTrueVector(), in_h1.SetFromTrueVector();
114 out_nd.SetFromTrueVector();
116 const auto x_dot_Mm1 = [&](ParGridFunction &x, ParGridFunction &y)
118 x.SetTrueVector(), x.SetFromTrueVector();
121 y.SetFromTrueVector();
123 const auto y_dot_Mm1 = [&](ParGridFunction &x, ParGridFunction &y)
125 x.SetTrueVector(), x.SetFromTrueVector();
128 y.SetFromTrueVector();
130 const auto z_dot_Mm1 = [&](ParGridFunction &x, ParGridFunction &y)
132 x.SetTrueVector(), x.SetFromTrueVector();
135 y.SetFromTrueVector();
140 void VelocityOneForm(ParGridFunction &ux, ParGridFunction &uy,
149 const auto diff_Mm1 = [&](ParGridFunction &x, ParGridFunction &y)
151 x.SetTrueVector(), x.SetFromTrueVector();
154 y.SetFromTrueVector();
166 rhs.ParallelAssemble(B);
168 q.SetFromTrueVector();
172 void PressureProject() { ComputeDivU(); PoissonSolve();
GaugeTransform(); }
183int main(
int argc,
char *argv[])
188 Options opt(argc, argv);
189 Device device(opt.device);
190 if (Mpi::Root()) { device.Print(); }
192 SchrodingerSolver schrodinger(opt);
193 IncompressibleFlow flow(opt, schrodinger);
194 const auto glvis_prefix = []()
196 std::ostringstream os;
197 os <<
"parallel " << Mpi::WorldSize() <<
" " << Mpi::WorldRank() <<
"\n";
200 FlowVis vis(opt, schrodinger, flow, glvis_prefix);
202 for (
int ti = 1; ti <= opt.max_steps; ti++)
204 const real_t t = ti * opt.dt;
205 const bool vis_steps = (ti % opt.vis_steps) == 0;
206 if (Mpi::Root() && vis_steps) {
mfem::out <<
"#" << ti << std::endl; }
208 if (opt.visualization && vis_steps) { vis.GLVis(); vis.Save(ti, t); }
void Mult(const Vector &b, Vector &x) const override
Iterative solution of the linear system using the Conjugate Gradient method.
void Mult(const Vector &b, Vector &x) const override
Iterative solution of the linear system using the GMRES method.
Class for simulating incompressible Schrodinger flow.
bool GetConverged() const
Returns true if the last call to Mult() converged successfully.
void Clear()
Clear the contents of the Mesh.
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
Abstract parallel finite element space.
Class for parallel grid function.
Class for parallel meshes.
int GetTrueVSize(const FieldDescriptor &f)
Get the true dof size of a field descriptor.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
SchrodingerBaseKernels< ParMesh, ParFiniteElementSpace, ParComplexGridFunction, ParGridFunction, ParBilinearForm, ParMixedBilinearForm, ParLinearForm > Kernels
CrankNicolsonTimeBaseSolver< ParFiniteElementSpace, ParSesquilinearForm, ParComplexGridFunction > CrankNicolsonSolver
Crank-Nicolson time solver for the Schrodinger equation.
CrankNicolsonTimeBaseSolver(TFiniteElementSpace &fes, real_t hbar, real_t dt, std::function< GMRESSolver()> CreateGMRESSolver, real_t rtol, real_t atol, int maxiter, int print_level)
Options(int argc, char *argv[])
Base class for Schrodinger solver kernels.
TComplexGridFunction psi1
OperatorHandle nd_dot_y_h1_op
void GradPsiVelocity(const real_t hbar, TGridFunction &ux, TGridFunction &uy, TGridFunction &uz)
TComplexGridFunction delta_psi2
TComplexGridFunction psi2
OperatorHandle diff_h1_op
OperatorHandle nd_dot_x_h1_op
void GradPsi(Gfn &Grad_nd, Xfn &x_dot_Mm1, Yfn &y_dot_Mm1, Zfn &z_dot_Mm1)
TFiniteElementSpace h1_fes
OperatorHandle nd_dot_z_h1_op
OperatorHandle grad_nd_op
TComplexGridFunction delta_psi1
Base class for visualization.