51 static double mu_ = 1.0;
52 static double epsilon_ = 1.0;
53 static double sigma_ = 20.0;
54 static double omega_ = 10.0;
67 int main(
int argc,
char *argv[])
70 const char *mesh_file =
"../data/inline-quad.mesh";
76 bool visualization = 1;
77 bool herm_conv =
true;
78 bool exact_sol =
true;
81 args.
AddOption(&mesh_file,
"-m",
"--mesh",
83 args.
AddOption(&ref_levels,
"-r",
"--refine",
84 "Number of times to refine the mesh uniformly.");
86 "Finite element order (polynomial degree).");
87 args.
AddOption(&prob,
"-p",
"--problem-type",
88 "Choose between 0: H_1, 1: H(Curl), or 2: H(Div) "
89 "damped harmonic oscillator.");
90 args.
AddOption(&a_coef,
"-a",
"--stiffness-coef",
91 "Stiffness coefficient (spring constant or 1/mu).");
92 args.
AddOption(&epsilon_,
"-b",
"--mass-coef",
93 "Mass coefficient (or epsilon).");
94 args.
AddOption(&sigma_,
"-c",
"--damping-coef",
95 "Damping coefficient (or sigma).");
96 args.
AddOption(&mu_,
"-mu",
"--permeability",
97 "Permeability of free space (or 1/(spring constant)).");
98 args.
AddOption(&epsilon_,
"-eps",
"--permittivity",
99 "Permittivity of free space (or mass constant).");
100 args.
AddOption(&sigma_,
"-sigma",
"--conductivity",
101 "Conductivity (or damping constant).");
102 args.
AddOption(&freq,
"-f",
"--frequency",
103 "Frequency (in Hz).");
104 args.
AddOption(&herm_conv,
"-herm",
"--hermitian",
"-no-herm",
105 "--no-hermitian",
"Use convention for Hermitian operators.");
106 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
107 "--no-visualization",
108 "Enable or disable GLVis visualization.");
117 MFEM_VERIFY(prob >= 0 && prob <=2,
118 "Unrecognized problem type: " << prob);
126 omega_ = 2.0 * M_PI *
freq;
132 cout <<
"Identified a mesh with known exact solution" << endl;
136 herm_conv ? ComplexOperator::HERMITIAN : ComplexOperator::BLOCK_SYMMETRIC;
141 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
147 for (
int l = 0; l < ref_levels; l++)
155 if (dim == 1 && prob != 0 )
157 cout <<
"Switching to problem type 0, H1 basis functions, "
158 <<
"for 1 dimensional mesh." << endl;
171 cout <<
"Number of finite element unknowns: " << fespace->
GetTrueVSize()
189 b.Vector::operator=(0.0);
208 Vector zeroVec(dim); zeroVec = 0.0;
209 Vector oneVec(dim); oneVec = 0.0; oneVec[(prob==2)?(dim-1):0] = 1.0;
252 if (visualization && exact_sol)
254 char vishost[] =
"localhost";
258 sol_sock_r.precision(8);
259 sol_sock_i.precision(8);
260 sol_sock_r <<
"solution\n" << *mesh << u_exact->
real()
261 <<
"window_title 'Exact: Real Part'" << flush;
262 sol_sock_i <<
"solution\n" << *mesh << u_exact->
imag()
263 <<
"window_title 'Exact: Imaginary Part'" << flush;
361 cout <<
"Size of linear system: "
362 << 2 * Asp->
real().
Width() << endl << endl;
397 (conv == ComplexOperator::HERMITIAN) ?
440 cout <<
"|| Re (u_h - u) ||_{L^2} = " << err_r << endl;
441 cout <<
"|| Im (u_h - u) ||_{L^2} = " << err_i << endl;
448 ofstream mesh_ofs(
"refined.mesh");
449 mesh_ofs.precision(8);
450 mesh->
Print(mesh_ofs);
452 ofstream sol_r_ofs(
"sol_r.gf");
453 ofstream sol_i_ofs(
"sol_i.gf");
454 sol_r_ofs.precision(8);
455 sol_i_ofs.precision(8);
463 char vishost[] =
"localhost";
467 sol_sock_r.precision(8);
468 sol_sock_i.precision(8);
469 sol_sock_r <<
"solution\n" << *mesh << u.
real()
470 <<
"window_title 'Solution: Real Part'" << flush;
471 sol_sock_i <<
"solution\n" << *mesh << u.
imag()
472 <<
"window_title 'Solution: Imaginary Part'" << flush;
474 if (visualization && exact_sol)
478 char vishost[] =
"localhost";
482 sol_sock_r.precision(8);
483 sol_sock_i.precision(8);
484 sol_sock_r <<
"solution\n" << *mesh << u_exact->
real()
485 <<
"window_title 'Error: Real Part'" << flush;
486 sol_sock_i <<
"solution\n" << *mesh << u_exact->
imag()
487 <<
"window_title 'Error: Imaginary Part'" << flush;
493 char vishost[] =
"localhost";
496 sol_sock.precision(8);
497 sol_sock <<
"solution\n" << *mesh << u_t
498 <<
"window_title 'Harmonic Solution (t = 0.0 T)'"
499 <<
"pause\n" << flush;
501 cout <<
"GLVis visualization paused."
502 <<
" Press space (in the GLVis window) to resume it.\n";
507 double t = (double)(i % num_frames) / num_frames;
509 oss <<
"Harmonic Solution (t = " << t <<
" T)";
511 add(cos( 2.0 * M_PI * t), u.
real(),
512 sin(-2.0 * M_PI * t), u.
imag(), u_t);
513 sol_sock <<
"solution\n" << *mesh << u_t
514 <<
"window_title '" << oss.str() <<
"'" << flush;
532 string file(mesh_file);
533 size_t p0 = file.find_last_of(
"/");
534 string s0 = file.substr((p0==string::npos)?0:(p0+1),7);
535 return s0 ==
"inline-";
541 complex<double> i(0.0, 1.0);
542 complex<double>
alpha = (epsilon_ * omega_ - i * sigma_);
543 complex<double>
kappa = std::sqrt(mu_ * omega_* alpha);
544 return std::exp(-i * kappa * x[dim - 1]);
int Size() const
Logical size of the array.
virtual void Print(std::ostream &out=mfem::out) const
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get()...
virtual void ProjectBdrCoefficientTangent(VectorCoefficient &real_coeff, VectorCoefficient &imag_coeff, Array< int > &attr)
Class for grid function - Vector with associated FE space.
Data type for scaled Jacobi-type smoother of sparse matrix.
Subclass constant coefficient.
virtual double ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
void u2_imag_exact(const Vector &, Vector &)
void SetSize(int s)
Resize the vector to size s.
virtual void ProjectCoefficient(Coefficient &real_coeff, Coefficient &imag_coeff)
Integrator for (curl u, curl v) for Nedelec elements.
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
Pointer to an Operator of a specified type.
int Size() const
Returns the size of the vector.
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1)
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)
Data type for Gauss-Seidel smoother of sparse matrix.
virtual void ProjectBdrCoefficientNormal(VectorCoefficient &real_coeff, VectorCoefficient &imag_coeff, Array< int > &attr)
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
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 &)
virtual void ProjectBdrCoefficient(Coefficient &real_coeff, Coefficient &imag_coeff, Array< int > &attr)
void SetMaxIter(int max_it)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
void PrintUsage(std::ostream &out) const
Operator * Ptr() const
Access the underlying Operator pointer.
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
virtual SparseMatrix & real()
Real or imaginary part accessor methods.
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).
Specialization of the ComplexOperator built from a pair of Sparse Matrices.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
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.
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.
bool check_for_inline_mesh(const char *mesh_file)
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 &)