36#include "meshes/one_d_mesh.h"
61 bool operator()(
const complex<T> &x,
const complex<T> &y)
const
65 if(std::abs(std::abs(x) - std::abs(y)) > 1.0e-10 )
66 {
return std::abs(x) < std::abs(y);}
68 else if(std::abs(x.real() - y.real()) > 1.0e-10)
69 {
return x.real() < y.real();}
72 {
return x.imag() < y.imag();}
94 virtual inline double u(
const unsigned& n)
const
95 {
return nodal_value(n,0);}
98 virtual inline double w(
const unsigned& n)
const
99 {
return nodal_value(n,1);}
110 void output(ostream &outfile,
const unsigned &nplot)
116 outfile << tecplot_zone_string(nplot);
119 unsigned num_plot_points=nplot_points(nplot);
120 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
123 get_s_plot(iplot,nplot,s);
129 write_tecplot_zone_footer(outfile,nplot);
135 Vector<double> &residuals,
136 DenseMatrix<double> &jacobian, DenseMatrix<double> &mass_matrix)
139 unsigned n_node = nnode();
143 DShape dpsidx(n_node,1);
146 unsigned n_intpt = integral_pt()->nweight();
149 int local_eqn=0, local_unknown=0;
152 for(
unsigned ipt=0;ipt<n_intpt;ipt++)
155 double w = integral_pt()->weight(ipt);
165 for(
unsigned l=0;l<n_node;l++)
173 for(
unsigned l2=0;l2<n_node;l2++)
177 if(local_unknown >= 0)
180 mass_matrix(local_eqn, local_unknown) += psi(l2)*psi(l)*W;
184 if(local_unknown >= 0)
187 jacobian(local_eqn,local_unknown) += dpsidx(l2,0)*psi(l)*W;
198 for(
unsigned l2=0;l2<n_node;l2++)
202 if(local_unknown >= 0)
205 jacobian(local_eqn,local_unknown) += dpsidx(l2,0)*psi(l)*W;
209 if(local_unknown >= 0)
212 mass_matrix(local_eqn, local_unknown) += psi(l2)*psi(l)*W;
214 jacobian(local_eqn,local_unknown) +=
226 unsigned n_node = nnode();
247 unsigned n_node = nnode();
272 DShape &dpsidx)
const=0;
278 DShape &dpsidx)
const=0;
283 virtual inline int u_local_eqn(
const unsigned &n,
const unsigned &i)
284 {
return nodal_local_eqn(n,i);}
297template <
unsigned NNODE_1D>
318 void output(ostream &outfile,
const unsigned &Nplot)
327 DShape &dpsidx)
const
328 {
return QElement<1,NNODE_1D>::dshape_eulerian(s,psi,dpsidx);}
335 DShape &dpsidx)
const
336 {
return QElement<1,NNODE_1D>::dshape_eulerian_at_knot(ipt,psi,dpsidx);}
344template<
class ELEMENT,
class EIGEN_SOLVER>
354 delete this->eigen_solver_pt();}
357 void solve(
const unsigned &label);
372template<
class ELEMENT,
class EIGEN_SOLVER>
374 const unsigned& n_element)
377 this->eigen_solver_pt() =
new EIGEN_SOLVER;
383 Problem::mesh_pt() =
new OneDMesh<ELEMENT>(n_element,L);
391 mesh_pt()->boundary_node_pt(0,0)->pin(0);
395 mesh_pt()->boundary_node_pt(1,0)->pin(0);
398 assign_eqn_numbers();
407template<
class ELEMENT,
class EIGEN_SOLVER>
409 const unsigned& label)
420 snprintf(filename,
sizeof(filename),
"soln%i.dat",label);
421 some_file.open(filename);
422 mesh_pt()->output(some_file,npts);
430template<
class ELEMENT,
class EIGEN_SOLVER>
432solve(
const unsigned& label)
435 Vector<complex<double> > eigenvalues;
437 Vector<DoubleVector> eigenvector_real;
438 Vector<DoubleVector> eigenvector_imag;
445 this->solve_eigenproblem(n_eval,eigenvalues,eigenvector_real,eigenvector_imag);
450 Vector<complex<double> > sorted_eigenvalues = eigenvalues;
451 sort(sorted_eigenvalues.begin(),sorted_eigenvalues.end(),
455 complex<double> temp_evalue = sorted_eigenvalues[0];
456 unsigned smallest_index=0;
459 for(
unsigned i=0;i<eigenvalues.size();i++)
463 if(eigenvalues[i] == temp_evalue) {smallest_index=i;
break;}
469 unsigned dim = eigenvector_real[smallest_index].nrow();
472 for(
unsigned i=0;i<dim;i++)
475 length += std::pow(eigenvector_real[smallest_index][i],2.0);
478 length = sqrt(length);
480 if(eigenvector_real[smallest_index][0] < 0) {length *= -1.0;}
482 for(
unsigned i=0;i<dim;i++)
484 eigenvector_real[smallest_index][i] /= length;
489 this->assign_eigenvector_to_dofs(eigenvector_real[smallest_index]);
491 this->doc_solution(label);
494 snprintf(filename,
sizeof(filename),
"eigenvalues%i.dat",label);
497 ofstream evalues(filename);
498 for(
unsigned i=0;i<n_eval;i++)
501 cout << sorted_eigenvalues[i].real() <<
" "
502 << sorted_eigenvalues[i].imag() << std::endl;
504 evalues << sorted_eigenvalues[i].real() <<
" "
505 << sorted_eigenvalues[i].imag() << std::endl;
525 MPI_Helpers::init(argc,argv);
529 unsigned n_element=100;
531 clock_t t_start1 = clock();
540 clock_t t_end1 = clock();
542#ifdef OOMPH_HAS_TRILINOS
543 clock_t t_start2 = clock();
549 clock_t t_end2 = clock();
552 std::cout <<
"LAPACK TIME: " << (double)(t_end1 - t_start1)/CLOCKS_PER_SEC
555#ifdef OOMPH_HAS_TRILINOS
556 std::cout <<
"ANASAZI TIME: " << (double)(t_end2 - t_start2)/CLOCKS_PER_SEC
561 MPI_Helpers::finalize();
A class for all elements that solve the eigenvalue problem.
void output(ostream &outfile, const unsigned &nplot)
Output FE representation of soln: x,y,u or x,y,z,u at Nplot plot points.
virtual int u_local_eqn(const unsigned &n, const unsigned &i)
Access function that returns the local equation number of the unknown in the problem....
void fill_in_contribution_to_jacobian_and_mass_matrix(Vector< double > &residuals, DenseMatrix< double > &jacobian, DenseMatrix< double > &mass_matrix)
Assemble the contributions to the jacobian and mass matrices.
virtual double dshape_eulerian(const Vector< double > &s, Shape &psi, DShape &dpsidx) const =0
Shape/test functions and derivs w.r.t. to global coords at local coord. s; return Jacobian of mapping...
virtual double dshape_eulerian_at_knot(const unsigned &ipt, Shape &psi, DShape &dpsidx) const =0
Shape/test functions and derivs w.r.t. to global coords at integration point ipt; return Jacobian of ...
double interpolated_w(const Vector< double > &s) const
Return FE representation of function value w(s) at local coordinate s.
void output(ostream &outfile)
Output the eigenfunction with default number of plot points.
virtual double w(const unsigned &n) const
Second eigenfunction value at local node n.
double interpolated_u(const Vector< double > &s) const
Return FE representation of function value u(s) at local coordinate s.
ComplexHarmonicEquations()
Empty Constructor.
virtual double u(const unsigned &n) const
Access function: First eigenfunction value at local node n Note that solving the eigenproblem does no...
1D ComplexHarmonic problem in unit interval.
~ComplexHarmonicProblem()
Destructor. Clean up the mesh and solver.
void solve(const unsigned &label)
Solve the problem.
void doc_solution(const unsigned &label)
Doc the solution, pass the number of the case considered, so that output files can be distinguished.
ComplexHarmonicProblem(const unsigned &n_element)
Constructor: Pass number of elements and pointer to source function.
Function-type-object to perform comparison of complex data types Needed to sort the complex eigenvalu...
bool operator()(const complex< T > &x, const complex< T > &y) const
Comparison in terms of magnitude of complex number.
QComplexHarmonicElement<NNODE_1D> elements are 1D Elements with NNODE_1D nodal points that are used t...
unsigned required_nvalue(const unsigned &n) const
Required # of ‘values’ (pinned or dofs) at node n. Here there are two (u and w)
double dshape_eulerian_at_knot(const unsigned &ipt, Shape &psi, DShape &dpsidx) const
Shape, test functions & derivs. w.r.t. to global coords. at integration point ipt....
double dshape_eulerian(const Vector< double > &s, Shape &psi, DShape &dpsidx) const
Shape, test functions & derivs. w.r.t. to global coords. Return Jacobian.
void output(ostream &outfile, const unsigned &Nplot)
Output function overloaded from ComplexHarmonicEquations.
void output(ostream &outfile)
Output function overloaded from ComplexHarmonicEquations.
QComplexHarmonicElement()
Constructor: Call constructors for QElement and Poisson equations.
int main(int argc, char **argv)
Driver for 1D Poisson problem.
Namespace for the shift applied to the eigenproblem.