42 template<
unsigned DIM,
unsigned NNODE_1D,
class PML_ELEMENT>
46 template <
unsigned DIM>
57 template <
unsigned DIM,
class PML_ELEMENT>
64 const unsigned n_node = this->nnode();
67 Shape psi(n_node), test(n_node);
68 DShape dpsidx(n_node,DIM), dtestdx(n_node,DIM);
71 const unsigned n_intpt = integral_pt()->nweight();
74 int local_eqn_real=0, local_unknown_real=0;
75 int local_eqn_imag=0, local_unknown_imag=0;
78 for(
unsigned ipt=0;ipt<n_intpt;ipt++)
81 double w = integral_pt()->weight(ipt);
84 double J = this->dshape_and_dtest_eulerian_at_knot_helmholtz(
85 ipt, psi, dpsidx, test, dtestdx);
92 std::complex<double> interpolated_u(0.0,0.0);
99 for(
unsigned l=0;l<n_node;l++)
102 for(
unsigned j=0;j<DIM;j++)
104 interpolated_x[j] += this->raw_nodal_position(l,j)*psi(l);
108 const std::complex<double>
109 u_value(this->raw_nodal_value(l, this->u_index_helmholtz().real()),
110 this->raw_nodal_value(l, this->u_index_helmholtz().imag()));
113 interpolated_u += u_value*psi(l);
116 for(
unsigned j=0;j<DIM;j++)
118 interpolated_dudx[j] += u_value*dpsidx(l,j);
124 std::complex<double> source(0.0,0.0);
125 this->get_source_helmholtz(ipt,interpolated_x,source);
135 this->pml_transformation_jacobian(ipt, s, interpolated_x, pml_jacobian);
139 std::complex<double> pml_k_squared_factor = std::complex<double>(1.0,0.0);
144 this->compute_laplace_matrix_and_det(pml_jacobian, laplace_matrix,
145 pml_k_squared_factor);
148 std::complex<double> alpha_pml_k_squared_factor = std::complex<double>(
149 pml_k_squared_factor.real() - this->alpha() * pml_k_squared_factor.imag(),
150 this->alpha() * pml_k_squared_factor.real() + pml_k_squared_factor.imag());
155 for(
unsigned l=0;l<n_node;l++)
162 local_eqn_real = this->nodal_local_eqn(l,this->u_index_helmholtz().real());
163 local_eqn_imag = this->nodal_local_eqn(l,this->u_index_helmholtz().imag());
166 if(local_eqn_real >= 0)
169 residuals[local_eqn_real] +=
172 alpha_pml_k_squared_factor.real() * this->k_squared() * interpolated_u.real()
173 -alpha_pml_k_squared_factor.imag() * this->k_squared() * interpolated_u.imag()
178 for(
unsigned k=0;k<DIM;k++)
180 residuals[local_eqn_real] +=
182 laplace_matrix(k,k).real() * interpolated_dudx[k].real()
183 -laplace_matrix(k,k).imag() * interpolated_dudx[k].imag()
192 for(
unsigned l2=0;l2<n_node;l2++)
194 local_unknown_real = this->nodal_local_eqn(l2,this->u_index_helmholtz().real());
195 local_unknown_imag = this->nodal_local_eqn(l2,this->u_index_helmholtz().imag());
198 if(local_unknown_real >= 0)
201 for(
unsigned i=0;
i<DIM;
i++)
203 jacobian(local_eqn_real,local_unknown_real)
204 += laplace_matrix(
i,
i).real() * dpsidx(l2,
i)*dtestdx(l,
i)*
W;
207 jacobian(local_eqn_real,local_unknown_real)
208 += -alpha_pml_k_squared_factor.real() * this->k_squared()*psi(l2)*test(l)*
W;
211 if(local_unknown_imag >= 0)
214 for(
unsigned i=0;
i<DIM;
i++)
216 jacobian(local_eqn_real,local_unknown_imag)
217 -= laplace_matrix(
i,
i).imag() * dpsidx(l2,
i)*dtestdx(l,
i)*
W;
221 jacobian(local_eqn_real,local_unknown_imag)
222 += alpha_pml_k_squared_factor.imag() * this->k_squared()*psi(l2)*test(l)*
W;
232 local_eqn_imag = this->nodal_local_eqn(l,this->u_index_helmholtz().imag());
233 local_eqn_real = this->nodal_local_eqn(l,this->u_index_helmholtz().real());
236 if(local_eqn_imag >= 0)
239 residuals[local_eqn_imag] +=
242 alpha_pml_k_squared_factor.imag() * this->k_squared()*interpolated_u.real()
243 + alpha_pml_k_squared_factor.real() * this->k_squared()*interpolated_u.imag()
248 for(
unsigned k=0;k<DIM;k++)
250 residuals[local_eqn_imag] += (
251 laplace_matrix(k,k).imag() * interpolated_dudx[k].real()
252 +laplace_matrix(k,k).real() * interpolated_dudx[k].imag()
261 for(
unsigned l2=0;l2<n_node;l2++)
263 local_unknown_imag = this->nodal_local_eqn(l2,this->u_index_helmholtz().imag());
264 local_unknown_real = this->nodal_local_eqn(l2,this->u_index_helmholtz().real());
267 if(local_unknown_imag >= 0)
270 for(
unsigned i=0;
i<DIM;
i++)
272 jacobian(local_eqn_imag,local_unknown_imag)
273 += laplace_matrix(
i,
i).real() * dpsidx(l2,
i)*dtestdx(l,
i)*
W;
276 jacobian(local_eqn_imag,local_unknown_imag)
277 += -alpha_pml_k_squared_factor.real()*this->k_squared() * psi(l2)*test(l)*
W;
279 if(local_unknown_real >= 0)
282 for(
unsigned i=0;
i<DIM;
i++)
284 jacobian(local_eqn_imag,local_unknown_real)
285 +=laplace_matrix(
i,
i).imag() * dpsidx(l2,
i)*dtestdx(l,
i)*
W;
288 jacobian(local_eqn_imag,local_unknown_real)
289 += -alpha_pml_k_squared_factor.imag()*this->k_squared() * psi(l2)*test(l)*
W;
302 template <
unsigned DIM>
334 template <
unsigned DIM>
336 const unsigned &nplot)
343 outfile << tecplot_zone_string(nplot);
346 unsigned num_plot_points=nplot_points(nplot);
347 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
351 get_s_plot(iplot,nplot,s);
352 std::complex<double> u(interpolated_u_pml_helmholtz(s));
353 for(
unsigned i=0;
i<DIM;
i++)
355 outfile << interpolated_x(s,
i) <<
" ";
357 outfile << u.real() <<
" " << u.imag() << std::endl;
362 write_tecplot_zone_footer(outfile,nplot);
380 template <
unsigned DIM>
383 const unsigned &nplot)
389 outfile << tecplot_zone_string(nplot);
392 unsigned num_plot_points=nplot_points(nplot);
393 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
396 get_s_plot(iplot,nplot,s);
397 std::complex<double> u(interpolated_u_pml_helmholtz(s));
398 for(
unsigned i=0;
i<DIM;
i++)
400 outfile << interpolated_x(s,
i) <<
" ";
402 outfile << u.real()*cos(phi)+u.imag()*sin(phi) << std::endl;
406 write_tecplot_zone_footer(outfile,nplot);
423 template <
unsigned DIM>
425 std::ostream &outfile,
428 const unsigned &nplot)
440 outfile << tecplot_zone_string(nplot);
443 unsigned num_plot_points=nplot_points(nplot);
444 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
447 get_s_plot(iplot,nplot,s);
448 std::complex<double> u(interpolated_u_pml_helmholtz(s));
454 (*incoming_wave_fct_pt)(x,incoming_soln);
456 for(
unsigned i=0;
i<DIM;
i++)
458 outfile << interpolated_x(s,
i) <<
" ";
461 outfile << (u.real()+incoming_soln[0])*cos(phi)+
462 (u.imag()+incoming_soln[1])*sin(phi) << std::endl;
466 write_tecplot_zone_footer(outfile,nplot);
481 template <
unsigned DIM>
484 const unsigned &nplot)
490 outfile << tecplot_zone_string(nplot);
493 unsigned num_plot_points=nplot_points(nplot);
494 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
497 get_s_plot(iplot,nplot,s);
498 std::complex<double> u(interpolated_u_pml_helmholtz(s));
499 for(
unsigned i=0;
i<DIM;
i++)
501 outfile << interpolated_x(s,
i) <<
" ";
503 outfile << u.imag()*cos(phi)-u.real()*sin(phi) << std::endl;
507 write_tecplot_zone_footer(outfile,nplot);
519 template <
unsigned DIM>
521 const unsigned &nplot)
527 fprintf(file_pt,
"%s",tecplot_zone_string(nplot).c_str());
530 unsigned num_plot_points=nplot_points(nplot);
531 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
534 get_s_plot(iplot,nplot,s);
535 std::complex<double> u(interpolated_u_pml_helmholtz(s));
537 for(
unsigned i=0;
i<DIM;
i++)
539 fprintf(file_pt,
"%g ",interpolated_x(s,
i));
542 for(
unsigned i=0;
i<DIM;
i++)
544 fprintf(file_pt,
"%g ",interpolated_x(s,
i));
546 fprintf(file_pt,
"%g ",u.real());
547 fprintf(file_pt,
"%g \n",u.imag());
552 write_tecplot_zone_footer(file_pt,nplot);
565 template <
unsigned DIM>
577 outfile << tecplot_zone_string(nplot);
583 unsigned num_plot_points=nplot_points(nplot);
584 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
587 get_s_plot(iplot,nplot,s);
593 (*exact_soln_pt)(x,exact_soln);
596 for(
unsigned i=0;
i<DIM;
i++)
598 outfile << x[
i] <<
" ";
600 outfile << exact_soln[0] <<
" " << exact_soln[1] << std::endl;
604 write_tecplot_zone_footer(outfile,nplot);
620 template <
unsigned DIM>
622 std::ostream &outfile,
624 const unsigned &nplot,
634 outfile << tecplot_zone_string(nplot);
640 unsigned num_plot_points=nplot_points(nplot);
641 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
644 get_s_plot(iplot,nplot,s);
650 (*exact_soln_pt)(x,exact_soln);
653 for(
unsigned i=0;
i<DIM;
i++)
655 outfile << x[
i] <<
" ";
657 outfile << exact_soln[0]*cos(phi)+ exact_soln[1]*sin(phi) << std::endl;
661 write_tecplot_zone_footer(outfile,nplot);
675 template <
unsigned DIM>
677 std::ostream &outfile,
679 const unsigned &nplot,
689 outfile << tecplot_zone_string(nplot);
695 unsigned num_plot_points=nplot_points(nplot);
696 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
700 get_s_plot(iplot,nplot,s);
706 (*exact_soln_pt)(x,exact_soln);
709 for(
unsigned i=0;
i<DIM;
i++)
711 outfile << x[
i] <<
" ";
713 outfile << exact_soln[1]*cos(phi) - exact_soln[0]*sin(phi) << std::endl;
717 write_tecplot_zone_footer(outfile,nplot);
730 template <
unsigned DIM>
732 std::ostream &outfile,
749 unsigned n_node = nnode();
754 unsigned n_intpt = integral_pt()->nweight();
757 outfile <<
"ZONE" << std::endl;
763 for(
unsigned ipt=0;ipt<n_intpt;ipt++)
767 for(
unsigned i=0;
i<DIM;
i++)
769 s[
i] = integral_pt()->knot(ipt,
i);
773 double w = integral_pt()->weight(ipt);
776 double J=J_eulerian(s);
785 std::complex<double> u_fe=interpolated_u_pml_helmholtz(s);
788 (*exact_soln_pt)(x,exact_soln);
791 for(
unsigned i=0;
i<DIM;
i++)
793 outfile << x[
i] <<
" ";
795 outfile << exact_soln[0] <<
" " << exact_soln[1] <<
" " 796 << exact_soln[0]-u_fe.real() <<
" " << exact_soln[1]-u_fe.imag()
800 norm+=(exact_soln[0]*exact_soln[0]+exact_soln[1]*exact_soln[1])*W;
801 error+=( (exact_soln[0]-u_fe.real())*(exact_soln[0]-u_fe.real())+
802 (exact_soln[1]-u_fe.imag())*(exact_soln[1]-u_fe.imag()) )*
W;
813 template <
unsigned DIM>
827 unsigned n_node = nnode();
832 unsigned n_intpt = integral_pt()->nweight();
835 for(
unsigned ipt=0;ipt<n_intpt;ipt++)
839 for(
unsigned i=0;
i<2;
i++)
841 s[
i] = integral_pt()->knot(ipt,
i);
845 double w = integral_pt()->weight(ipt);
848 double J=J_eulerian(s);
854 std::complex<double> u_fe=interpolated_u_pml_helmholtz(s);
857 norm+=(u_fe.real()*u_fe.real()+u_fe.imag()*u_fe.imag())*W;
865 template<
unsigned DIM,
class PML_ELEMENT>
void compute_error(std::ostream &outfile, FiniteElement::SteadyExactSolutionFctPt exact_soln_pt, double &error, double &norm)
Get error against and norm of exact solution.
void output(std::ostream &outfile)
Output with default number of plot points.
virtual void fill_in_generic_residual_contribution_helmholtz(Vector< double > &residuals, DenseMatrix< double > &jacobian, const unsigned &flag)
Compute element residual Vector only (if flag=and/or element Jacobian matrix.
void compute_norm(double &norm)
Compute norm of fe solution.
virtual unsigned self_test()
Self-test: Check inversion of element & do self-test for GeneralisedElement. Return 0 if OK...
void output_real(std::ostream &outfile, const double &phi, const unsigned &n_plot)
Output function for real part of full time-dependent solution u = Re( (u_r +i u_i) exp(-i omega t)) a...
void output_fct(std::ostream &outfile, const unsigned &n_plot, FiniteElement::SteadyExactSolutionFctPt exact_soln_pt)
void output_imag(std::ostream &outfile, const double &phi, const unsigned &n_plot)
Output function for imaginary part of full time-dependent solution u = Im( (u_r +i u_i) exp(-i omega ...
void output_real_fct(std::ostream &outfile, const double &phi, const unsigned &n_plot, FiniteElement::SteadyExactSolutionFctPt exact_soln_pt)
Output function for real part of full time-dependent fct u = Re( (u_r +i u_i) exp(-i omega t) at phas...
void(* SteadyExactSolutionFctPt)(const Vector< double > &, Vector< double > &)
Function pointer for function that computes vector-valued steady "exact solution" as ...
static const unsigned Initial_Nvalue
Static int that holds the number of variables at nodes: always the same.
unsigned self_test()
Self-test: Return 0 for OK.
void output_imag_fct(std::ostream &outfile, const double &phi, const unsigned &n_plot, FiniteElement::SteadyExactSolutionFctPt exact_soln_pt)
Output function for imaginary part of full time-dependent fct u = Im( (u_r +i u_i) exp(-i omega t)) a...
static double Default_Physical_Constant_Value
Static default value for the physical constants (initialised to zero)
QPMLHelmholtzElement elements are linear/quadrilateral/ brick-shaped PMLHelmholtz elements with isopa...
void output_total_real(std::ostream &outfile, FiniteElement::SteadyExactSolutionFctPt incoming_wave_fct_pt, const double &phi, const unsigned &nplot)