MFEM  v4.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
maxwell_solver.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_MAXWELL_SOLVER
13 #define MFEM_MAXWELL_SOLVER
14 
15 #include "../common/pfem_extras.hpp"
16 #include "electromagnetics.hpp"
17 
18 #ifdef MFEM_USE_MPI
19 
20 #include <string>
21 #include <map>
22 
23 using namespace std;
24 using namespace mfem;
25 
26 namespace mfem
27 {
28 
32 
33 namespace electromagnetics
34 {
35 
37 {
38 public:
39  MaxwellSolver(ParMesh & pmesh, int sOrder,
40  double (*eps )(const Vector&),
41  double (*muInv )(const Vector&),
42  double (*sigma )(const Vector&),
43  void (*j_src )(const Vector&, double, Vector&),
44  Array<int> & abcs, Array<int> & dbcs,
45  void (*dEdt_bc )(const Vector&, double, Vector&));
46 
47  ~MaxwellSolver();
48 
49  int GetLogging() const { return logging_; }
50  void SetLogging(int logging) { logging_ = logging; }
51 
52  HYPRE_Int GetProblemSize();
53 
54  void PrintSizes();
55 
56  void SetInitialEField(VectorCoefficient & EFieldCoef);
57  void SetInitialBField(VectorCoefficient & BFieldCoef);
58 
59  void Mult(const Vector &B, Vector &dEdt) const;
60 
61  void ImplicitSolve(const double dt, const Vector &x, Vector &k);
62 
63  double GetMaximumTimeStep() const;
64 
65  double GetEnergy() const;
66 
67  Operator & GetNegCurl() { return *NegCurl_; }
68 
69  Vector & GetEField() { return *E_; }
70  Vector & GetBField() { return *B_; }
71 
72  void SyncGridFuncs();
73 
74  void RegisterVisItFields(VisItDataCollection & visit_dc);
75 
76  void WriteVisItFields(int it = 0);
77 
78  void InitializeGLVis();
79 
80  void DisplayToGLVis();
81 
82 private:
83 
84  // This method alters mutable member data
85  void setupSolver(const int idt, const double dt) const;
86 
87  void implicitSolve(const double dt, const Vector &x, Vector &k) const;
88 
89  int myid_;
90  int num_procs_;
91  int order_;
92  int logging_;
93 
94  bool lossy_;
95 
96  double dtMax_; // Maximum stable time step
97  double dtScale_; // Used to scale dt before converting to an integer
98 
99  ParMesh * pmesh_;
100 
101  ND_ParFESpace * HCurlFESpace_;
102  RT_ParFESpace * HDivFESpace_;
103 
104  ParBilinearForm * hDivMassMuInv_;
105  ParBilinearForm * hCurlLosses_;
106  ParMixedBilinearForm * weakCurlMuInv_;
107 
108  ParDiscreteCurlOperator * Curl_;
109 
110  ParGridFunction * e_; // Electric Field (HCurl)
111  ParGridFunction * b_; // Magnetic Flux (HDiv)
112  ParGridFunction * j_; // Volumetric Current Density (HCurl)
113  ParGridFunction * dedt_; // Time Derivative of Electric Field (HCurl)
114  ParGridFunction * rhs_; // Dual of displacement current, rhs vector (HCurl)
115  ParLinearForm * jd_; // Dual of current density (HCurl)
116 
117  HypreParMatrix * M1Losses_;
118  HypreParMatrix * M2MuInv_;
119  HypreParMatrix * NegCurl_;
120  HypreParMatrix * WeakCurlMuInv_;
121  HypreParVector * E_; // Current value of the electric field DoFs
122  HypreParVector * B_; // Current value of the magnetic flux DoFs
123  mutable HypreParVector * HD_; // Used in energy calculation
124  mutable HypreParVector * RHS_;
125 
126  Coefficient * epsCoef_; // Electric Permittivity Coefficient
127  Coefficient * muInvCoef_; // Magnetic Permeability Coefficient
128  Coefficient * sigmaCoef_; // Electric Conductivity Coefficient
129  Coefficient * etaInvCoef_; // Admittance Coefficient
130  VectorCoefficient * eCoef_; // Initial Electric Field
131  VectorCoefficient * bCoef_; // Initial Magnetic Flux
132  VectorCoefficient * jCoef_; // Time dependent current density
133  VectorCoefficient * dEdtBCCoef_; // Time dependent boundary condition
134 
135  double (*eps_ )(const Vector&);
136  double (*muInv_ )(const Vector&);
137  double (*sigma_ )(const Vector&);
138  void (*j_src_ )(const Vector&, double, Vector&);
139 
140  // Array of 0's and 1's marking the location of absorbing surfaces
141  Array<int> abc_marker_;
142 
143  // Array of 0's and 1's marking the location of Dirichlet boundaries
144  Array<int> dbc_marker_;
145  void (*dEdt_bc_)(const Vector&, double, Vector&);
146 
147  // Dirichlet degrees of freedom
148  Array<int> dbc_dofs_;
149 
150  // High order symplectic integration requires partial time steps of differing
151  // lengths. If losses are present the system matrix includes a portion scaled
152  // by the time step. Consequently, high order time integration requires
153  // different system matrices. The following maps contain various objects that
154  // depend on the time step.
155  mutable std::map<int, ParBilinearForm *> a1_;
156  mutable std::map<int, HypreParMatrix *> A1_;
157  mutable std::map<int, Coefficient *> dtCoef_;
158  mutable std::map<int, Coefficient *> dtSigmaCoef_;
159  mutable std::map<int, Coefficient *> dtEtaInvCoef_;
160  mutable std::map<int, HypreDiagScale *> diagScale_;
161  mutable std::map<int, HyprePCG *> pcg_;
162 
163  // Data collection used to write VisIt files
164  VisItDataCollection * visit_dc_;
165 
166  // Sockets used to communicate with GLVis
167  std::map<std::string, socketstream*> socks_;
168 };
169 
170 } // namespace electromagnetics
171 
172 } // namespace mfem
173 
174 #endif // MFEM_USE_MPI
175 
176 #endif // MFEM_MAXWELL_SOLVER
Base abstract class for time dependent operators.
Definition: operator.hpp:162
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
Definition: table.cpp:476
Class for parallel linear form.
Definition: plinearform.hpp:26
Data collection with VisIt I/O routines.
double muInv(const Vector &x)
Definition: maxwell.cpp:96
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:73
void j_src(const Vector &x, double t, Vector &j)
Definition: maxwell.cpp:108
Base class Coefficient that may optionally depend on time.
Definition: coefficient.hpp:31
Class for parallel bilinear form using different test and trial FE spaces.
Class for parallel bilinear form.
Vector data type.
Definition: vector.hpp:48
Class for parallel grid function.
Definition: pgridfunc.hpp:32
Abstract operator.
Definition: operator.hpp:21
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:187
Class for parallel meshes.
Definition: pmesh.hpp:32
double sigma(const Vector &x)
Definition: maxwell.cpp:102