213int main(
int argc,
char *argv[])
219 const char *mesh_file =
"../../data/inline-quad.mesh";
224 bool static_cond =
false;
229 bool with_pml =
false;
230 bool visualization =
true;
232 bool paraview =
false;
235 args.
AddOption(&mesh_file,
"-m",
"--mesh",
236 "Mesh file to use.");
238 "Finite element order (polynomial degree)");
239 args.
AddOption(&rnum,
"-rnum",
"--number-of-wavelengths",
240 "Number of wavelengths");
242 "Permeability of free space (or 1/(spring constant)).");
244 "Permittivity of free space (or mass constant).");
245 args.
AddOption(&iprob,
"-prob",
"--problem",
"Problem case"
246 " 0: plane wave, 1: Fichera 'oven', "
247 " 2: Generic PML problem with point source given as a load "
248 " 3: Scattering of a plane wave, "
249 " 4: Point source given on the boundary");
250 args.
AddOption(&delta_order,
"-do",
"--delta-order",
251 "Order enrichment for DPG test space.");
252 args.
AddOption(&theta,
"-theta",
"--theta",
253 "Theta parameter for AMR");
254 args.
AddOption(&sr,
"-sref",
"--serial-ref",
255 "Number of parallel refinements.");
256 args.
AddOption(&pr,
"-pref",
"--parallel-ref",
257 "Number of parallel refinements.");
258 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
259 "--no-static-condensation",
"Enable static condensation.");
260 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
261 "--no-visualization",
262 "Enable or disable GLVis visualization.");
263 args.
AddOption(¶view,
"-paraview",
"--paraview",
"-no-paraview",
265 "Enable or disable ParaView visualization.");
266 args.
AddOption(&visport,
"-p",
"--send-port",
"Socket for GLVis.");
277 if (iprob > 4) { iprob = 0; }
279 omega = 2.*M_PI*rnum;
287 mesh_file =
"meshes/fichera-waveguide.mesh";
289 rnum =
omega/(2.*M_PI);
298 mesh_file =
"meshes/scatter.mesh";
306 Mesh mesh(mesh_file, 1, 1);
308 MFEM_VERIFY(
dim > 1,
"Dimension = 1 is not supported in this example");
312 for (
int i = 0; i<sr; i++)
327 ParMesh pmesh(MPI_COMM_WORLD, mesh);
360 int test_order = order+delta_order;
381 trial_fes.
Append(hatE_fes);
382 trial_fes.
Append(hatH_fes);
396 rot_mat(0,0) = 0.; rot_mat(0,1) = 1.;
397 rot_mat(1,0) = -1.; rot_mat(1,1) = 0.;
424 epsomeg_cf = &epsomeg;
425 negepsomeg_cf = &negepsomeg;
426 eps2omeg2_cf = &eps2omeg2;
428 negmuomeg_cf = &negmuomeg;
429 mu2omeg2_cf = &mu2omeg2;
431 negepsrot_cf = &negepsrot;
458 abs_detJ_Jt_J_inv_2);
460 abs_detJ_Jt_J_inv_2);
467 epsomeg_detJ_Jt_J_inv_i,attrPML);
469 epsomeg_detJ_Jt_J_inv_r,attrPML);
471 negepsomeg_detJ_Jt_J_inv_r,attrPML);
475 negmuomeg_detJ_Jt_J_inv_i,attrPML);
477 negmuomeg_detJ_Jt_J_inv_r,attrPML);
479 mu2omeg2_detJ_Jt_J_inv_2,attrPML);
481 eps2omeg2_detJ_Jt_J_inv_2,attrPML);
493 epsomeg_detJ_Jt_J_inv_i, rot);
495 epsomeg_detJ_Jt_J_inv_r, rot);
497 negepsomeg_detJ_Jt_J_inv_r, rot);
499 *epsomeg_detJ_Jt_J_inv_i_rot, attrPML);
501 *epsomeg_detJ_Jt_J_inv_r_rot, attrPML);
503 *negepsomeg_detJ_Jt_J_inv_r_rot, attrPML);
511 nullptr,TrialSpace::E_space, TestSpace::F_space);
513 a->AddTrialIntegrator(
nullptr,
515 TrialSpace::E_space,TestSpace::G_space);
518 nullptr,TrialSpace::H_space, TestSpace::G_space);
521 TrialSpace::hatH_space, TestSpace::G_space);
525 TestSpace::G_space,TestSpace::G_space);
528 TestSpace::G_space,TestSpace::G_space);
535 TrialSpace::H_space,TestSpace::F_space);
538 TrialSpace::hatE_space, TestSpace::F_space);
543 TestSpace::F_space, TestSpace::F_space);
546 TestSpace::F_space,TestSpace::F_space);
549 TestSpace::F_space, TestSpace::F_space);
552 TestSpace::F_space, TestSpace::G_space);
555 TestSpace::F_space, TestSpace::G_space);
558 TestSpace::G_space, TestSpace::F_space);
561 TestSpace::G_space, TestSpace::F_space);
564 TestSpace::G_space, TestSpace::G_space);
570 TrialSpace::H_space, TestSpace::F_space);
573 TrialSpace::hatE_space, TestSpace::F_space);
577 TestSpace::F_space, TestSpace::F_space);
580 TestSpace::F_space, TestSpace::F_space);
583 TestSpace::F_space, TestSpace::F_space);
585 a->AddTestIntegrator(
nullptr,
587 TestSpace::F_space, TestSpace::G_space);
590 TestSpace::F_space, TestSpace::G_space);
593 TestSpace::G_space, TestSpace::F_space);
595 a->AddTestIntegrator(
nullptr,
598 TestSpace::G_space, TestSpace::F_space);
601 TestSpace::G_space, TestSpace::G_space);
608 a->AddTrialIntegrator(
610 epsomeg_detJ_Jt_J_inv_i_restr)),
612 negepsomeg_detJ_Jt_J_inv_r_restr)),
613 TrialSpace::E_space,TestSpace::G_space);
619 a->AddTrialIntegrator(
621 negmuomeg_detJ_Jt_J_inv_i_restr)),
623 muomeg_detJ_Jt_J_inv_r_restr)),
624 TrialSpace::H_space, TestSpace::F_space);
627 a->AddTestIntegrator(
629 TestSpace::F_space, TestSpace::F_space);
634 negmuomeg_detJ_Jt_J_inv_i_restr),
636 TestSpace::F_space,TestSpace::G_space);
640 epsomeg_detJ_Jt_J_inv_i_restr),
642 TestSpace::F_space,TestSpace::G_space);
646 negmuomeg_detJ_Jt_J_inv_i_restr),
648 TestSpace::G_space, TestSpace::F_space);
652 epsomeg_detJ_Jt_J_inv_i_restr),
654 TestSpace::G_space, TestSpace::F_space);
657 eps2omeg2_detJ_Jt_J_inv_2_restr),
nullptr,
658 TestSpace::G_space, TestSpace::G_space);
665 a->AddTrialIntegrator(
668 TrialSpace::H_space, TestSpace::F_space);
671 a->AddTestIntegrator(
new MassIntegrator(mu2omeg2_detJ_2_restr),
nullptr,
672 TestSpace::F_space, TestSpace::F_space);
675 a->AddTestIntegrator(
678 TestSpace::F_space, TestSpace::G_space);
682 *epsomeg_detJ_Jt_J_inv_i_rot_restr),
684 TestSpace::F_space, TestSpace::G_space);
689 TestSpace::G_space, TestSpace::F_space);
692 a->AddTestIntegrator(
694 *epsomeg_detJ_Jt_J_inv_i_rot_restr)),
696 *epsomeg_detJ_Jt_J_inv_r_rot_restr)),
697 TestSpace::G_space, TestSpace::F_space);
700 eps2omeg2_detJ_Jt_J_inv_2_restr),
nullptr,
701 TestSpace::G_space, TestSpace::G_space);
727 std::cout <<
"\n Ref |"
732 std::cout <<
" L2 Error |"
735 std::cout <<
" Residual |"
737 <<
" PCG it |" << endl;
738 std::cout << std::string((
exact_known) ? 82 : 60,
'-')
767 if (static_cond) {
a->EnableStaticCondensation(); }
768 for (
int it = 0; it<=pr; it++)
787 for (
int j = 0; j < ess_tdof_list.
Size(); j++)
821 a->FormLinearSystem(ess_tdof_list,x,Ah, X,B);
832 int skip = (static_cond) ? 0 : 2;
833 int k = (static_cond) ? 2 : 0;
834 for (
int i=0; i<num_blocks; i++)
836 tdof_offsets[i+1] = trial_fes[i+k]->GetTrueVSize();
837 tdof_offsets[num_blocks+i+1] = trial_fes[i+k]->GetTrueVSize();
842 for (
int i = 0; i<num_blocks; i++)
844 for (
int j = 0; j<num_blocks; j++)
846 blockA.
SetBlock(i,j,&BlockA_r->GetBlock(i,j));
848 blockA.
SetBlock(i+num_blocks,j+num_blocks,&BlockA_r->GetBlock(i,j));
859 BlockA_r->GetBlock(0,0));
863 BlockA_r->GetBlock(1,1));
887 dynamic_cast<HypreAMS*
>(solver_hatH)->SetPrintLevel(0);
903 for (
int i = 0; i<num_blocks; i++)
910 a->RecoverFEMSolution(X,x);
912 Vector & residuals =
a->ComputeResidual(x);
916 real_t globalresidual = residual * residual;
918 MPI_MAX, MPI_COMM_WORLD);
919 MPI_Allreduce(MPI_IN_PLACE, &globalresidual, 1,
922 globalresidual = sqrt(globalresidual);
927 H_r.
MakeRef(H_fes,x, offsets[1]);
931 for (
int i = 0; i<trial_fes.
Size(); i++)
933 dofs += trial_fes[i]->GlobalTrueVSize();
949 L2Error = sqrt( E_err_r*E_err_r + E_err_i*E_err_i
950 + H_err_r*H_err_r + H_err_i*H_err_i );
951 rate_err = (it) ?
dim*log(err0/L2Error)/log((
real_t)dof0/dofs) : 0.0;
955 real_t rate_res = (it) ?
dim*log(res0/globalresidual)/log((
958 res0 = globalresidual;
963 std::ios oldState(
nullptr);
964 oldState.copyfmt(std::cout);
965 std::cout << std::right << std::setw(5) << it <<
" | "
966 << std::setw(10) << dof0 <<
" | "
967 << std::setprecision(1) << std::fixed
968 << std::setw(4) << 2.0*rnum <<
" π | "
969 << std::setprecision(3);
972 std::cout << std::setw(10) << std::scientific << err0 <<
" | "
973 << std::setprecision(2)
974 << std::setw(6) << std::fixed << rate_err <<
" | " ;
976 std::cout << std::setprecision(3)
977 << std::setw(10) << std::scientific << res0 <<
" | "
978 << std::setprecision(2)
979 << std::setw(6) << std::fixed << rate_res <<
" | "
980 << std::setw(6) << std::fixed << num_iter <<
" | "
982 std::cout.copyfmt(oldState);
987 const char * keys = (it == 0 &&
dim == 2) ?
"jRcml\n" :
nullptr;
990 "Numerical Electric field (real part)", 0, 0, 500, 500, keys);
992 "Numerical Magnetic field (real part)", 501, 0, 500, 500, keys);
1009 elements_to_refine.
SetSize(0);
1010 for (
int iel = 0; iel<pmesh.
GetNE(); iel++)
1012 if (residuals[iel] > theta * maxresidual)
1014 elements_to_refine.
Append(iel);
1024 for (
int i =0; i<trial_fes.
Size(); i++)
1026 trial_fes[i]->Update(
false);
1031 if (pml &&
dim == 2)
1033 delete epsomeg_detJ_Jt_J_inv_i_rot;
1034 delete epsomeg_detJ_Jt_J_inv_r_rot;
1035 delete negepsomeg_detJ_Jt_J_inv_r_rot;
1036 delete epsomeg_detJ_Jt_J_inv_i_rot_restr;
1037 delete epsomeg_detJ_Jt_J_inv_r_rot_restr;
1038 delete negepsomeg_detJ_Jt_J_inv_r_rot_restr;