33#include "meshes/one_d_mesh.h"
51 bool operator()(
const complex<T> &x,
const complex<T> &y)
const
53 return x.real() < y.real();
78 virtual inline double u(
const unsigned& n)
const
79 {
return nodal_value(n,0);}
90 void output(ostream &outfile,
const unsigned &nplot)
96 outfile << tecplot_zone_string(nplot);
99 unsigned num_plot_points=nplot_points(nplot);
100 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
103 get_s_plot(iplot,nplot,s);
105 outfile << interpolated_x(s,0) <<
" " <<
interpolated_u(s) << std::endl;
108 write_tecplot_zone_footer(outfile,nplot);
114 Vector<double> &residuals,
115 DenseMatrix<double> &jacobian, DenseMatrix<double> &mass_matrix)
118 unsigned n_node = nnode();
122 DShape dpsidx(n_node,1);
125 unsigned n_intpt = integral_pt()->nweight();
128 int local_eqn=0, local_unknown=0;
131 for(
unsigned ipt=0;ipt<n_intpt;ipt++)
134 double w = integral_pt()->weight(ipt);
144 for(
unsigned l=0;l<n_node;l++)
152 for(
unsigned l2=0;l2<n_node;l2++)
156 if(local_unknown >= 0)
158 jacobian(local_eqn,local_unknown) += dpsidx(l,0)*dpsidx(l2,0)*W;
159 mass_matrix(local_eqn, local_unknown) += psi(l)*psi(l2)*W;
170 unsigned n_node = nnode();
194 DShape &dpsidx)
const=0;
200 DShape &dpsidx)
const=0;
206 {
return nodal_local_eqn(n,0);}
219template <
unsigned NNODE_1D>
239 void output(ostream &outfile,
const unsigned &Nplot)
248 DShape &dpsidx)
const
249 {
return QElement<1,NNODE_1D>::dshape_eulerian(s,psi,dpsidx);}
256 DShape &dpsidx)
const
257 {
return QElement<1,NNODE_1D>::dshape_eulerian_at_knot(ipt,psi,dpsidx);}
265template<
class ELEMENT,
class EIGEN_SOLVER>
277 void solve(
const unsigned &label);
292template<
class ELEMENT,
class EIGEN_SOLVER>
294 const unsigned& n_element)
297 this->eigen_solver_pt() =
new EIGEN_SOLVER;
303 Problem::mesh_pt() =
new OneDMesh<ELEMENT>(n_element,L);
311 mesh_pt()->boundary_node_pt(0,0)->pin(0);
315 mesh_pt()->boundary_node_pt(1,0)->pin(0);
318 assign_eqn_numbers();
327template<
class ELEMENT,
class EIGEN_SOLVER>
339 snprintf(filename,
sizeof(filename),
"soln%i.dat",label);
340 some_file.open(filename);
341 mesh_pt()->output(some_file,npts);
349template<
class ELEMENT,
class EIGEN_SOLVER>
351solve(
const unsigned& label)
354 Vector<complex<double> > eigenvalue;
356 Vector<DoubleVector> eigenvector_real;
357 Vector<DoubleVector> eigenvector_imag;
362 this->solve_eigenproblem(n_eval,eigenvalue,eigenvector_real,eigenvector_imag);
367 Vector<complex<double> > sorted_eigenvalue = eigenvalue;
368 sort(sorted_eigenvalue.begin(),sorted_eigenvalue.end(),
372 complex<double> temp_evalue = sorted_eigenvalue[1];
373 unsigned second_smallest_index=0;
376 for(
unsigned i=0;i<eigenvalue.size();i++)
380 if(eigenvalue[i] == temp_evalue) {second_smallest_index=i;
break;}
386 unsigned dim = eigenvector_real[second_smallest_index].nrow();
389 for(
unsigned i=0;i<dim;i++)
392 length += std::pow(eigenvector_real[second_smallest_index][i],2.0);
395 length = sqrt(length);
397 if(eigenvector_real[second_smallest_index][0] < 0) {length *= -1.0;}
399 for(
unsigned i=0;i<dim;i++)
401 eigenvector_real[second_smallest_index][i] /= length;
406 this->assign_eigenvector_to_dofs(eigenvector_real[second_smallest_index]);
408 this->doc_solution(label);
411 snprintf(filename,
sizeof(filename),
"eigenvalues%i.dat",label);
414 ofstream evalues(filename);
415 for(
unsigned i=0;i<n_eval;i++)
418 cout << sorted_eigenvalue[i].real() <<
" "
419 << sorted_eigenvalue[i].imag() << std::endl;
421 evalues << sorted_eigenvalue[i].real() <<
" "
422 << sorted_eigenvalue[i].imag() << std::endl;
442 MPI_Helpers::init(argc,argv);
446 unsigned n_element=100;
448 clock_t t_start1 = clock();
456 clock_t t_end1 = clock();
458#ifdef OOMPH_HAS_TRILINOS
459 clock_t t_start2 = clock();
466 clock_t t_end2 = clock();
469 std::cout <<
"LAPACK TIME: " << (double)(t_end1 - t_start1)/CLOCKS_PER_SEC
472#ifdef OOMPH_HAS_TRILINOS
473 std::cout <<
"ANASAZI TIME: " << (double)(t_end2 - t_start2)/CLOCKS_PER_SEC
480 MPI_Helpers::finalize();
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. Are the values identical or not?
A class for all elements that solve the simple one-dimensional eigenvalue 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.
HarmonicEquations()
Empty Constructor.
double interpolated_u(const Vector< double > &s) const
Return FE representation of function value u(s) at local coordinate s.
virtual int u_local_eqn(const unsigned &n)
Access function that returns the local equation number of the unknown in the problem....
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 ...
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 double u(const unsigned &n) const
Access function: Eigenfunction value at local node n Note that solving the eigenproblem does not assi...
void output(ostream &outfile)
Output the eigenfunction with default number of plot points.
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...
1D Harmonic problem in unit interval.
HarmonicProblem(const unsigned &n_element)
Constructor: Pass number of elements and pointer to source function.
~HarmonicProblem()
Destructor (empty)
void doc_solution(const unsigned &label)
Doc the solution, pass the number of the case considered, so that output files can be distinguished.
void solve(const unsigned &label)
Solve the problem.
QHarmonicElement<NNODE_1D> elements are 1D Elements with NNODE_1D nodal points that are used to solve...
QHarmonicElement()
Constructor: Call constructors for QElement and Poisson equations.
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 HarmonicEquations.
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....
unsigned required_nvalue(const unsigned &n) const
Required # of ‘values’ (pinned or dofs) at node n.
void output(ostream &outfile)
Output function overloaded from HarmonicEquations.
int main(int argc, char **argv)
Driver for 1D Poisson problem.