52 static double mu_ = 1.0;
53 static double epsilon_ = 1.0;
54 static double sigma_ = 20.0;
55 static double omega_ = 10.0;
68 int main(
int argc,
char *argv[])
72 MPI_Init(&argc, &argv);
73 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
74 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
77 const char *mesh_file =
"../data/inline-quad.mesh";
78 int ser_ref_levels = 1;
79 int par_ref_levels = 1;
84 bool visualization = 1;
85 bool herm_conv =
true;
86 bool exact_sol =
true;
89 args.
AddOption(&mesh_file,
"-m",
"--mesh",
91 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
92 "Number of times to refine the mesh uniformly in serial.");
93 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
94 "Number of times to refine the mesh uniformly in parallel.");
96 "Finite element order (polynomial degree).");
97 args.
AddOption(&prob,
"-p",
"--problem-type",
98 "Choose between 0: H_1, 1: H(Curl), or 2: H(Div) "
99 "damped harmonic oscillator.");
100 args.
AddOption(&a_coef,
"-a",
"--stiffness-coef",
101 "Stiffness coefficient (spring constant or 1/mu).");
102 args.
AddOption(&epsilon_,
"-b",
"--mass-coef",
103 "Mass coefficient (or epsilon).");
104 args.
AddOption(&sigma_,
"-c",
"--damping-coef",
105 "Damping coefficient (or sigma).");
106 args.
AddOption(&mu_,
"-mu",
"--permeability",
107 "Permeability of free space (or 1/(spring constant)).");
108 args.
AddOption(&epsilon_,
"-eps",
"--permittivity",
109 "Permittivity of free space (or mass constant).");
110 args.
AddOption(&sigma_,
"-sigma",
"--conductivity",
111 "Conductivity (or damping constant).");
112 args.
AddOption(&freq,
"-f",
"--frequency",
113 "Frequency (in Hz).");
114 args.
AddOption(&herm_conv,
"-herm",
"--hermitian",
"-no-herm",
115 "--no-hermitian",
"Use convention for Hermitian operators.");
116 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
117 "--no-visualization",
118 "Enable or disable GLVis visualization.");
134 MFEM_VERIFY(prob >= 0 && prob <=2,
135 "Unrecognized problem type: " << prob);
143 omega_ = 2.0 * M_PI *
freq;
147 if (myid == 0 && exact_sol)
149 cout <<
"Identified a mesh with known exact solution" << endl;
153 herm_conv ? ComplexOperator::HERMITIAN : ComplexOperator::BLOCK_SYMMETRIC;
158 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
162 for (
int l = 0; l < ser_ref_levels; l++)
172 for (
int l = 0; l < par_ref_levels; l++)
180 if (dim == 1 && prob != 0 )
184 cout <<
"Switching to problem type 0, H1 basis functions, "
185 <<
"for 1 dimensional mesh." << endl;
202 cout <<
"Number of finite element unknowns: " << size << endl;
220 b.Vector::operator=(0.0);
239 Vector zeroVec(dim); zeroVec = 0.0;
240 Vector oneVec(dim); oneVec = 0.0; oneVec[(prob==2)?(dim-1):0] = 1.0;
283 if (visualization && exact_sol)
285 char vishost[] =
"localhost";
289 sol_sock_r <<
"parallel " << num_procs <<
" " << myid <<
"\n";
290 sol_sock_i <<
"parallel " << num_procs <<
" " << myid <<
"\n";
291 sol_sock_r.precision(8);
292 sol_sock_i.precision(8);
293 sol_sock_r <<
"solution\n" << *pmesh << u_exact->
real()
294 <<
"window_title 'Exact: Real Part'" << flush;
295 sol_sock_i <<
"solution\n" << *pmesh << u_exact->
imag()
296 <<
"window_title 'Exact: Imaginary Part'" << flush;
396 cout <<
"Size of linear system: "
406 blockTrueOffsets[0] = 0;
407 blockTrueOffsets[1] = PCOp.
Ptr()->
Height();
408 blockTrueOffsets[2] = PCOp.
Ptr()->
Height();
437 (conv == ComplexOperator::HERMITIAN) ?
481 cout <<
"|| Re (u_h - u) ||_{L^2} = " << err_r << endl;
482 cout <<
"|| Im (u_h - u) ||_{L^2} = " << err_i << endl;
490 ostringstream mesh_name, sol_r_name, sol_i_name;
491 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
492 sol_r_name <<
"sol_r." << setfill(
'0') << setw(6) << myid;
493 sol_i_name <<
"sol_i." << setfill(
'0') << setw(6) << myid;
495 ofstream mesh_ofs(mesh_name.str().c_str());
496 mesh_ofs.precision(8);
497 pmesh->
Print(mesh_ofs);
499 ofstream sol_r_ofs(sol_r_name.str().c_str());
500 ofstream sol_i_ofs(sol_i_name.str().c_str());
501 sol_r_ofs.precision(8);
502 sol_i_ofs.precision(8);
510 char vishost[] =
"localhost";
514 sol_sock_r <<
"parallel " << num_procs <<
" " << myid <<
"\n";
515 sol_sock_i <<
"parallel " << num_procs <<
" " << myid <<
"\n";
516 sol_sock_r.precision(8);
517 sol_sock_i.precision(8);
518 sol_sock_r <<
"solution\n" << *pmesh << u.
real()
519 <<
"window_title 'Solution: Real Part'" << flush;
520 sol_sock_i <<
"solution\n" << *pmesh << u.
imag()
521 <<
"window_title 'Solution: Imaginary Part'" << flush;
523 if (visualization && exact_sol)
527 char vishost[] =
"localhost";
531 sol_sock_r <<
"parallel " << num_procs <<
" " << myid <<
"\n";
532 sol_sock_i <<
"parallel " << num_procs <<
" " << myid <<
"\n";
533 sol_sock_r.precision(8);
534 sol_sock_i.precision(8);
535 sol_sock_r <<
"solution\n" << *pmesh << u_exact->
real()
536 <<
"window_title 'Error: Real Part'" << flush;
537 sol_sock_i <<
"solution\n" << *pmesh << u_exact->
imag()
538 <<
"window_title 'Error: Imaginary Part'" << flush;
544 char vishost[] =
"localhost";
547 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
548 sol_sock.precision(8);
549 sol_sock <<
"solution\n" << *pmesh << u_t
550 <<
"window_title 'Harmonic Solution (t = 0.0 T)'"
551 <<
"pause\n" << flush;
553 cout <<
"GLVis visualization paused."
554 <<
" Press space (in the GLVis window) to resume it.\n";
559 double t = (double)(i % num_frames) / num_frames;
561 oss <<
"Harmonic Solution (t = " << t <<
" T)";
563 add(cos( 2.0 * M_PI * t), u.
real(),
564 sin(-2.0 * M_PI * t), u.
imag(), u_t);
565 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
566 sol_sock <<
"solution\n" << *pmesh << u_t
567 <<
"window_title '" << oss.str() <<
"'" << flush;
587 string file(mesh_file);
588 size_t p0 = file.find_last_of(
"/");
589 string s0 = file.substr((p0==string::npos)?0:(p0+1),7);
590 return s0 ==
"inline-";
596 complex<double> i(0.0, 1.0);
597 complex<double>
alpha = (epsilon_ * omega_ - i * sigma_);
598 complex<double>
kappa = std::sqrt(mu_ * omega_* alpha);
599 return std::exp(-i * kappa * x[dim - 1]);
int Size() const
Logical size of the array.
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1)
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get()...
The Auxiliary-space Maxwell Solver in hypre.
The Auxiliary-space Divergence Solver in hypre.
Subclass constant coefficient.
virtual void ProjectBdrCoefficient(Coefficient &real_coeff, Coefficient &imag_coeff, Array< int > &attr)
void u2_imag_exact(const Vector &, Vector &)
void SetSize(int s)
Resize the vector to size s.
Integrator for (curl u, curl v) for Nedelec elements.
Pointer to an Operator of a specified type.
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
int Size() const
Returns the size of the vector.
virtual void Save(std::ostream &out) const
Abstract parallel finite element space.
complex< double > u0_exact(const Vector &x)
int main(int argc, char *argv[])
(Q div u, div v) for RT elements
void u1_imag_exact(const Vector &, Vector &)
void add(const Vector &v1, const Vector &v2, Vector &v)
The BoomerAMG solver in hypre.
HYPRE_Int GetGlobalNumRows() const
Return the global number of rows.
void SetPrintLevel(int print_lvl)
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
A class to handle Block diagonal preconditioners in a matrix-free implementation. ...
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
double u0_imag_exact(const Vector &)
void SetMaxIter(int max_it)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
HYPRE_Int GlobalTrueVSize() const
virtual void Print(std::ostream &out=mfem::out) const
void PrintUsage(std::ostream &out) const
Operator * Ptr() const
Access the underlying Operator pointer.
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
virtual void ProjectBdrCoefficientNormal(VectorCoefficient &real_coeff, VectorCoefficient &imag_coeff, Array< int > &attr)
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void SetRelTol(double rtol)
Scaled Operator B: x -> a A(x).
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)
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
void PartialSum()
Partial Sum.
virtual void ProjectBdrCoefficientTangent(VectorCoefficient &real_coeff, VectorCoefficient &imag_coeff, Array< int > &attr)
virtual double ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
Specialization of the ComplexOperator built from a pair of HypreParMatrices.
void PrintOptions(std::ostream &out) const
class for C-function coefficient
Arbitrary order H(curl)-conforming Nedelec finite elements.
void u1_real_exact(const Vector &, Vector &)
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
Arbitrary order H1-conforming (continuous) finite elements.
Class for parallel grid function.
bool check_for_inline_mesh(const char *mesh_file)
Wrapper for hypre's ParCSR matrix class.
Class for parallel meshes.
virtual HypreParMatrix & real()
Real or imaginary part accessor methods.
virtual void ProjectCoefficient(Coefficient &real_coeff, Coefficient &imag_coeff)
void SetDiagonalBlock(int iblock, Operator *op)
Add a square block op in the block-entry (iblock, iblock).
void u2_real_exact(const Vector &, Vector &)
double u0_real_exact(const Vector &)