58 static double mu_ = 1.0;
59 static double epsilon_ = 1.0;
60 static double sigma_ = 20.0;
61 static double omega_ = 10.0;
74 int main(
int argc,
char *argv[])
77 const char *mesh_file =
"../data/inline-quad.mesh";
83 bool visualization = 1;
84 bool herm_conv =
true;
85 bool exact_sol =
true;
87 const char *device_config =
"cpu";
90 args.
AddOption(&mesh_file,
"-m",
"--mesh",
92 args.
AddOption(&ref_levels,
"-r",
"--refine",
93 "Number of times to refine the mesh uniformly.");
95 "Finite element order (polynomial degree).");
96 args.
AddOption(&prob,
"-p",
"--problem-type",
97 "Choose between 0: H_1, 1: H(Curl), or 2: H(Div) "
98 "damped harmonic oscillator.");
99 args.
AddOption(&a_coef,
"-a",
"--stiffness-coef",
100 "Stiffness coefficient (spring constant or 1/mu).");
101 args.
AddOption(&epsilon_,
"-b",
"--mass-coef",
102 "Mass coefficient (or epsilon).");
103 args.
AddOption(&sigma_,
"-c",
"--damping-coef",
104 "Damping coefficient (or sigma).");
105 args.
AddOption(&mu_,
"-mu",
"--permeability",
106 "Permeability of free space (or 1/(spring constant)).");
107 args.
AddOption(&epsilon_,
"-eps",
"--permittivity",
108 "Permittivity of free space (or mass constant).");
109 args.
AddOption(&sigma_,
"-sigma",
"--conductivity",
110 "Conductivity (or damping constant).");
111 args.
AddOption(&freq,
"-f",
"--frequency",
112 "Frequency (in Hz).");
113 args.
AddOption(&herm_conv,
"-herm",
"--hermitian",
"-no-herm",
114 "--no-hermitian",
"Use convention for Hermitian operators.");
115 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
116 "--no-visualization",
117 "Enable or disable GLVis visualization.");
118 args.
AddOption(&pa,
"-pa",
"--partial-assembly",
"-no-pa",
119 "--no-partial-assembly",
"Enable Partial Assembly.");
120 args.
AddOption(&device_config,
"-d",
"--device",
121 "Device configuration string, see Device::Configure().");
130 MFEM_VERIFY(prob >= 0 && prob <=2,
131 "Unrecognized problem type: " << prob);
139 omega_ = 2.0 * M_PI *
freq;
145 cout <<
"Identified a mesh with known exact solution" << endl;
149 herm_conv ? ComplexOperator::HERMITIAN : ComplexOperator::BLOCK_SYMMETRIC;
153 Device device(device_config);
159 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
165 for (
int l = 0; l < ref_levels; l++)
173 if (dim == 1 && prob != 0 )
175 cout <<
"Switching to problem type 0, H1 basis functions, "
176 <<
"for 1 dimensional mesh." << endl;
189 cout <<
"Number of finite element unknowns: " << fespace->
GetTrueVSize()
207 b.Vector::operator=(0.0);
226 Vector zeroVec(dim); zeroVec = 0.0;
227 Vector oneVec(dim); oneVec = 0.0; oneVec[(prob==2)?(dim-1):0] = 1.0;
269 if (visualization && exact_sol)
275 sol_sock_r.precision(8);
276 sol_sock_i.precision(8);
277 sol_sock_r <<
"solution\n" << *mesh << u_exact->
real()
278 <<
"window_title 'Exact: Real Part'" << flush;
279 sol_sock_i <<
"solution\n" << *mesh << u_exact->
imag()
280 <<
"window_title 'Exact: Imaginary Part'" << flush;
372 cout <<
"Size of linear system: " << A->
Width() << endl << endl;
380 blockOffsets[1] = A->
Height() / 2;
381 blockOffsets[2] = A->
Height() / 2;
413 double s = (prob != 1) ? 1.0 : -1.0;
415 (conv == ComplexOperator::HERMITIAN) ?
458 cout <<
"|| Re (u_h - u) ||_{L^2} = " << err_r << endl;
459 cout <<
"|| Im (u_h - u) ||_{L^2} = " << err_i << endl;
466 ofstream mesh_ofs(
"refined.mesh");
467 mesh_ofs.precision(8);
468 mesh->
Print(mesh_ofs);
470 ofstream sol_r_ofs(
"sol_r.gf");
471 ofstream sol_i_ofs(
"sol_i.gf");
472 sol_r_ofs.precision(8);
473 sol_i_ofs.precision(8);
485 sol_sock_r.precision(8);
486 sol_sock_i.precision(8);
487 sol_sock_r <<
"solution\n" << *mesh << u.
real()
488 <<
"window_title 'Solution: Real Part'" << flush;
489 sol_sock_i <<
"solution\n" << *mesh << u.
imag()
490 <<
"window_title 'Solution: Imaginary Part'" << flush;
492 if (visualization && exact_sol)
500 sol_sock_r.precision(8);
501 sol_sock_i.precision(8);
502 sol_sock_r <<
"solution\n" << *mesh << u_exact->
real()
503 <<
"window_title 'Error: Real Part'" << flush;
504 sol_sock_i <<
"solution\n" << *mesh << u_exact->
imag()
505 <<
"window_title 'Error: Imaginary Part'" << flush;
514 sol_sock.precision(8);
515 sol_sock <<
"solution\n" << *mesh << u_t
516 <<
"window_title 'Harmonic Solution (t = 0.0 T)'"
517 <<
"pause\n" << flush;
519 cout <<
"GLVis visualization paused."
520 <<
" Press space (in the GLVis window) to resume it.\n";
525 double t = (double)(i % num_frames) / num_frames;
527 oss <<
"Harmonic Solution (t = " << t <<
" T)";
529 add(cos( 2.0 * M_PI * t), u.
real(),
530 sin(-2.0 * M_PI * t), u.
imag(), u_t);
531 sol_sock <<
"solution\n" << *mesh << u_t
532 <<
"window_title '" << oss.str() <<
"'" << flush;
550 string file(mesh_file);
551 size_t p0 = file.find_last_of(
"/");
552 string s0 = file.substr((p0==string::npos)?0:(p0+1),7);
553 return s0 ==
"inline-";
559 complex<double> i(0.0, 1.0);
560 complex<double>
alpha = (epsilon_ * omega_ - i * sigma_);
561 complex<double>
kappa = std::sqrt(mu_ * omega_* alpha);
562 return std::exp(-i * kappa * x[dim - 1]);
int Size() const
Return the 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.
A coefficient that is constant across space and time.
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.
Vector coefficient that is constant in space and time.
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)
Get a list of essential true dofs, ess_tdof_list, corresponding to the boundary attributes marked in ...
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
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.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
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().
Jacobi smoothing for a given bilinear form (no matrix necessary).
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.
Set the diagonal value to one.
void PrintUsage(std::ostream &out) const
Print the usage message.
Operator * Ptr() const
Access the underlying Operator pointer.
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
A general vector function coefficient.
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).
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
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...
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
void PartialSum()
Fill the entries of the array with the cumulative sum of the entries.
void PrintOptions(std::ostream &out) const
Print the options.
A general 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.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
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 &)
bool Good() const
Return true if the command line options were parsed successfully.
double u0_real_exact(const Vector &)