59static real_t epsilon_ = 1.0;
64int main(
int argc,
char *argv[])
73 const char *mesh_file =
"../data/fichera-mixed.mesh";
74 int ser_ref_levels = 1;
75 int par_ref_levels = 1;
83 bool herm_conv =
true;
84 bool slu_solver =
false;
85 bool visualization = 1;
88 const char *device_config =
"cpu";
91 args.
AddOption(&mesh_file,
"-m",
"--mesh",
93 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
94 "Number of times to refine the mesh uniformly in serial.");
95 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
96 "Number of times to refine the mesh uniformly in parallel.");
98 "Finite element order (polynomial degree).");
100 "Choose between 0: H_1, 1: H(Curl), or 2: H(Div) "
101 "damped harmonic oscillator.");
102 args.
AddOption(&mode,
"-em",
"--eigenmode",
103 "Choose the index of the port eigenmode.");
104 args.
AddOption(&a_coef,
"-a",
"--stiffness-coef",
105 "Stiffness coefficient (spring constant or 1/mu).");
106 args.
AddOption(&epsilon_,
"-b",
"--mass-coef",
107 "Mass coefficient (or epsilon).");
108 args.
AddOption(&sigma_,
"-c",
"--damping-coef",
109 "Damping coefficient (or sigma).");
110 args.
AddOption(&mu_,
"-mu",
"--permeability",
111 "Permeability of free space (or 1/(spring constant)).");
112 args.
AddOption(&epsilon_,
"-eps",
"--permittivity",
113 "Permittivity of free space (or mass constant).");
114 args.
AddOption(&sigma_,
"-sigma",
"--conductivity",
115 "Conductivity (or damping constant).");
117 "Frequency (in Hz).");
118 args.
AddOption(&port_bc_attr,
"-pbc",
"--port-bc-attr",
119 "Attributes of port boundary condition");
120 args.
AddOption(&herm_conv,
"-herm",
"--hermitian",
"-no-herm",
121 "--no-hermitian",
"Use convention for Hermitian operators.");
122#ifdef MFEM_USE_SUPERLU
123 args.
AddOption(&slu_solver,
"-slu",
"--superlu",
"-no-slu",
124 "--no-superlu",
"Use the SuperLU Solver.");
126 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
127 "--no-visualization",
128 "Enable or disable GLVis visualization.");
129 args.
AddOption(&mixed,
"-mixed",
"--mixed-mesh",
"-hex",
130 "--hex-mesh",
"Mixed mesh of hexahedral mesh.");
131 args.
AddOption(&pa,
"-pa",
"--partial-assembly",
"-no-pa",
132 "--no-partial-assembly",
"Enable Partial Assembly.");
133 args.
AddOption(&device_config,
"-d",
"--device",
134 "Device configuration string, see Device::Configure().");
147 mesh_file =
"../data/fichera.mesh";
158 if (port_bc_attr.
Size() == 0 &&
159 (strcmp(mesh_file,
"../data/fichera-mixed.mesh") == 0 ||
160 strcmp(mesh_file,
"../data/fichera.mesh") == 0))
165 port_bc_attr[2] = 11;
166 port_bc_attr[3] = 12;
175 "Unrecognized problem type: " <<
prob);
182 Device device(device_config);
183 if (myid == 0) { device.
Print(); }
188 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
192 for (
int l = 0; l < ser_ref_levels; l++)
200 ParMesh pmesh(MPI_COMM_WORLD, *mesh);
202 for (
int l = 0; l < par_ref_levels; l++)
217 cout <<
"Switching to problem type 0, H1 basis functions, "
218 <<
"for 1 dimensional mesh." << endl;
235 cout <<
"Number of finite element unknowns: " << size << endl;
266 cout <<
"Number of finite element port BC unknowns: " << size_port
281 ostringstream mesh_name, port_name;
282 mesh_name <<
"port_mesh." << setfill(
'0') << setw(6) << myid;
283 port_name <<
"port_mode." << setfill(
'0') << setw(6) << myid;
285 ofstream mesh_ofs(mesh_name.str().c_str());
286 mesh_ofs.precision(8);
287 pmesh_port.
Print(mesh_ofs);
289 ofstream port_ofs(port_name.str().c_str());
290 port_ofs.precision(8);
291 port_bc.
Save(port_ofs);
294 if (visualization &&
dim == 3)
299 port_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
300 port_sock.precision(8);
301 port_sock <<
"solution\n" << pmesh_port << port_bc
302 <<
"window_title 'Port BC'"
303 <<
"window_geometry 0 0 400 350" << flush;
321 b.Vector::operator=(0.0);
335 port_to_full.
Transfer(port_bc, full_bc);
342 full_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
343 full_sock.precision(8);
344 full_sock <<
"solution\n" << pmesh << full_bc
345 <<
"window_title 'Transferred BC'"
346 <<
"window_geometry 400 0 400 350"<< flush;
369 if (pa) {
a.SetAssemblyLevel(AssemblyLevel::PARTIAL); }
402 a.FormLinearSystem(ess_tdof_list,
u,
b, A, U, B);
406 cout <<
"Size of linear system: "
407 << 2 * size << endl << endl;
451 blockTrueOffsets[0] = 0;
452 blockTrueOffsets[1] = A->
Height() / 2;
453 blockTrueOffsets[2] = A->
Height() / 2;
507#ifdef MFEM_USE_SUPERLU
532 ostringstream mesh_name, sol_r_name, sol_i_name;
533 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
534 sol_r_name <<
"sol_r." << setfill(
'0') << setw(6) << myid;
535 sol_i_name <<
"sol_i." << setfill(
'0') << setw(6) << myid;
537 ofstream mesh_ofs(mesh_name.str().c_str());
538 mesh_ofs.precision(8);
539 pmesh.
Print(mesh_ofs);
541 ofstream sol_r_ofs(sol_r_name.str().c_str());
542 ofstream sol_i_ofs(sol_i_name.str().c_str());
543 sol_r_ofs.precision(8);
544 sol_i_ofs.precision(8);
545 u.real().Save(sol_r_ofs);
546 u.imag().Save(sol_i_ofs);
555 sol_sock_r <<
"parallel " << num_procs <<
" " << myid <<
"\n";
556 sol_sock_r.precision(8);
557 sol_sock_r <<
"solution\n" << pmesh <<
u.real()
558 <<
"window_title 'Solution: Real Part'"
559 <<
"window_geometry 800 0 400 350" << flush;
561 MPI_Barrier(MPI_COMM_WORLD);
564 sol_sock_i <<
"parallel " << num_procs <<
" " << myid <<
"\n";
565 sol_sock_i.precision(8);
566 sol_sock_i <<
"solution\n" << pmesh <<
u.imag()
567 <<
"window_title 'Solution: Imaginary Part'"
568 <<
"window_geometry 1200 0 400 350" << flush;
577 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
578 sol_sock.precision(8);
579 sol_sock <<
"solution\n" << pmesh << u_t
580 <<
"window_title 'Harmonic Solution (t = 0.0 T)'"
581 <<
"window_geometry 0 432 600 450"
582 <<
"pause\n" << flush;
584 cout <<
"GLVis visualization paused."
585 <<
" Press space (in the GLVis window) to resume it.\n";
592 oss <<
"Harmonic Solution (t = " <<
t <<
" T)";
594 add(cos( 2.0 * M_PI *
t),
u.real(),
595 sin(-2.0 * M_PI *
t),
u.imag(), u_t);
596 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
597 sol_sock <<
"solution\n" << pmesh << u_t
598 <<
"window_title '" << oss.str() <<
"'" << flush;
617 int nev = std::max(mode + 2, 5);
633 a.EliminateEssentialBCDiag(ess_bdr, 1.0);
675 int nev = std::max(mode + 2, 5);
690 a.EliminateEssentialBCDiag(ess_bdr, 1.0);
733 int nev = std::max(mode + 2, 5);
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
int Size() const
Return the logical size of the array.
void PartialSum()
Fill the entries of the array with the cumulative sum of the entries.
@ GaussLegendre
Open type.
A class to handle Block diagonal preconditioners in a matrix-free implementation.
void SetDiagonalBlock(int iblock, Operator *op)
Add a square block op in the block-entry (iblock, iblock).
Specialization of the ComplexOperator built from a pair of HypreParMatrices.
@ HERMITIAN
Native convention for Hermitian operators.
@ BLOCK_SYMMETRIC
Alternate convention for damping operators.
A coefficient that is constant across space and time.
Integrator for for Nedelec elements.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
for Raviart-Thomas elements
virtual void Mult(const Vector &b, Vector &x) const
Iterative solution of the linear system using the FGMRES method.
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
int GetOrder() const
Return the order (polynomial degree) of the FE collection, corresponding to the order/degree returned...
const FiniteElementCollection * FEColl() const
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
Arbitrary order H1-conforming (continuous) finite elements.
The Auxiliary-space Divergence Solver in hypre.
void SetNumModes(int num_eigs)
void SetPreconditioner(HypreSolver &precond)
void SetPrintLevel(int logging)
void SetMassMatrix(const HypreParMatrix &M)
const HypreParVector & GetEigenvector(unsigned int i) const
Extract a single eigenvector.
void SetOperator(const HypreParMatrix &A)
void Solve()
Solve the eigenproblem.
void SetMaxIter(int max_iter)
The Auxiliary-space Maxwell Solver in hypre.
void SetPrintLevel(int print_lvl)
void SetSingularProblem()
Set this option when solving a curl-curl problem with zero mass term.
The BoomerAMG solver in hypre.
void SetPrintLevel(int print_level)
void SetMassMatrix(Operator &M)
void SetPrintLevel(int logging)
void SetPreconditioner(Solver &precond)
void SetOperator(Operator &A)
void SetNumModes(int num_eigs)
void Solve()
Solve the eigenproblem.
void SetPrecondUsageMode(int pcg_mode)
void SetRandomSeed(int s)
void SetMaxIter(int max_iter)
const HypreParVector & GetEigenvector(unsigned int i) const
Extract a single eigenvector.
Wrapper for hypre's ParCSR matrix class.
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
virtual void SetOperator(const Operator &op) override
Also calls SetOperator for the preconditioner if there is one.
void SetRelTol(real_t rtol)
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
void SetMaxIter(int max_it)
Arbitrary order "L2-conforming" discontinuous finite elements.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
int Dimension() const
Dimension of the reference space used within the elements.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static int WorldSize()
Return the size of MPI_COMM_WORLD.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
Arbitrary order H(curl)-conforming Nedelec finite elements.
Pointer to an Operator of a specified type.
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get().
Operator * Ptr() const
Access the underlying Operator pointer.
Jacobi smoothing for a given bilinear form (no matrix necessary).
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x)
Reconstruct a solution vector x (e.g. a GridFunction) from the solution X of a constrained linear sys...
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
bool Good() const
Return true if the command line options were parsed successfully.
Abstract parallel finite element space.
void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1) const override
HYPRE_BigInt GlobalTrueVSize() const
ParMesh * GetParMesh() const
Class for parallel grid function.
void Save(std::ostream &out) const override
ParFiniteElementSpace * ParFESpace() const
void ProjectCoefficient(Coefficient &coeff) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Class for parallel meshes.
void Print(std::ostream &out=mfem::out, const std::string &comments="") const override
Subdomain representation of a topological parent in another ParMesh.
static ParSubMesh CreateFromBoundary(const ParMesh &parent, Array< int > &boundary_attributes)
Create a surface ParSubMesh from it's parent.
static void Transfer(const ParGridFunction &src, ParGridFunction &dst)
Transfer the dofs of a ParGridFunction.
ParTransferMap represents a mapping of degrees of freedom from a source ParGridFunction to a destinat...
void Transfer(const ParGridFunction &src, ParGridFunction &dst) const
Transfer the source ParGridFunction to the destination ParGridFunction.
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
Scaled Operator B: x -> a A(x).
void SetColumnPermutation(superlu::ColPerm col_perm)
Specify how to permute the columns of the matrix.
void Mult(const Vector &x, Vector &y) const
Factor and solve the linear system .
void SetSymmetricPattern(bool sym)
Specify whether the matrix has a symmetric pattern to avoid extra work (default false)
void SetOperator(const Operator &op)
Set the operator/matrix.
void SetPrintStatistics(bool print_stat)
Specify whether to print the solver statistics (default true)
void SetPortBC(int prob, int dim, int mode, ParGridFunction &port_bc)
void ScalarWaveGuide(int mode, ParGridFunction &x)
void VectorWaveGuide(int mode, ParGridFunction &x)
void PseudoScalarWaveGuide(int mode, ParGridFunction &x_l2)
@ PARMETIS
Sequential ordering on structure of using the PARMETIS package.
real_t u(const Vector &xvec)
void add(const Vector &v1, const Vector &v2, Vector &v)