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();
70class HarmonicEquations :
public virtual FiniteElement
75 HarmonicEquations() {}
80 virtual inline double u(
const unsigned& n)
const
81 {
return nodal_value(n,0);}
84 void output(ostream &outfile)
87 output(outfile,nplot);
92 void output(ostream &outfile,
const unsigned &nplot)
98 outfile << tecplot_zone_string(nplot);
101 unsigned num_plot_points=nplot_points(nplot);
102 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
105 get_s_plot(iplot,nplot,s);
107 outfile << interpolated_x(s,0) <<
" " << interpolated_u(s) << std::endl;
110 write_tecplot_zone_footer(outfile,nplot);
115 void fill_in_contribution_to_jacobian_and_mass_matrix(
116 Vector<double> &residuals,
117 DenseMatrix<double> &jacobian, DenseMatrix<double> &mass_matrix)
120 unsigned n_node = nnode();
124 DShape dpsidx(n_node,1);
127 unsigned n_intpt = integral_pt()->nweight();
130 int local_eqn=0, local_unknown=0;
133 for(
unsigned ipt=0;ipt<n_intpt;ipt++)
136 double w = integral_pt()->weight(ipt);
139 double J = dshape_eulerian_at_knot(ipt,psi,dpsidx);
146 for(
unsigned l=0;l<n_node;l++)
149 local_eqn = u_local_eqn(l);
154 for(
unsigned l2=0;l2<n_node;l2++)
156 local_unknown = u_local_eqn(l2);
158 if(local_unknown >= 0)
160 jacobian(local_eqn,local_unknown) += dpsidx(l,0)*dpsidx(l2,0)*W;
161 mass_matrix(local_eqn, local_unknown) += psi(l)*psi(l2)*W;
170 inline double interpolated_u(
const Vector<double> &s)
const
172 unsigned n_node = nnode();
181 double interpolated_u = 0.0;
184 for(
unsigned l=0;l<n_node;l++) {interpolated_u+=u(l)*psi[l];}
187 return(interpolated_u);
194 virtual double dshape_eulerian(
const Vector<double> &s,
196 DShape &dpsidx)
const=0;
200 virtual double dshape_eulerian_at_knot(
const unsigned &ipt,
202 DShape &dpsidx)
const=0;
207 virtual inline int u_local_eqn(
const unsigned &n)
208 {
return nodal_local_eqn(n,0);}
221template <
unsigned NNODE_1D>
223 public HarmonicEquations
238 {HarmonicEquations::output(outfile);}
241 void output(ostream &outfile,
const unsigned &Nplot)
242 {HarmonicEquations::output(outfile,Nplot);}
250 DShape &dpsidx)
const
251 {
return QElement<1,NNODE_1D>::dshape_eulerian(s,psi,dpsidx);}
258 DShape &dpsidx)
const
259 {
return QElement<1,NNODE_1D>::dshape_eulerian_at_knot(ipt,psi,dpsidx);}
267template<
class ELEMENT,
class EIGEN_SOLVER>
279 void solve(
const unsigned &label);
294template<
class ELEMENT,
class EIGEN_SOLVER>
296 const unsigned& n_element)
299 this->eigen_solver_pt() =
new EIGEN_SOLVER;
302 static_cast<EIGEN_SOLVER*
>(eigen_solver_pt())
303 ->get_eigenvalues_right_of_shift();
309 Problem::mesh_pt() =
new OneDMesh<ELEMENT>(n_element,L);
317 mesh_pt()->boundary_node_pt(0,0)->pin(0);
321 mesh_pt()->boundary_node_pt(1,0)->pin(0);
324 assign_eqn_numbers();
333template<
class ELEMENT,
class EIGEN_SOLVER>
345 sprintf(filename,
"soln%i.dat",label);
346 some_file.open(filename);
347 mesh_pt()->output(some_file,npts);
355template<
class ELEMENT,
class EIGEN_SOLVER>
357solve(
const unsigned& label)
360 Vector<complex<double> > eigenvalues;
362 Vector<DoubleVector> eigenvectors;
367 this->solve_eigenproblem(n_eval,eigenvalues,eigenvectors);
372 Vector<complex<double> > sorted_eigenvalues = eigenvalues;
373 sort(sorted_eigenvalues.begin(),sorted_eigenvalues.end(),
377 complex<double> temp_evalue = sorted_eigenvalues[1];
378 unsigned second_smallest_index=0;
381 for(
unsigned i=0;i<eigenvalues.size();i++)
385 if(eigenvalues[i] == temp_evalue) {second_smallest_index=i;
break;}
391 unsigned dim = eigenvectors[second_smallest_index].nrow();
394 for(
unsigned i=0;i<dim;i++)
397 length += std::pow(eigenvectors[second_smallest_index][i],2.0);
400 length = sqrt(length);
402 if(eigenvectors[second_smallest_index][0] < 0) {length *= -1.0;}
404 for(
unsigned i=0;i<dim;i++)
406 eigenvectors[second_smallest_index][i] /= length;
411 this->assign_eigenvector_to_dofs(eigenvectors[second_smallest_index]);
413 this->doc_solution(label);
416 sprintf(filename,
"eigenvalues%i.dat",label);
419 ofstream evalues(filename);
420 for(
unsigned i=0;i<n_eval;i++)
423 cout << sorted_eigenvalues[i].real() <<
" "
424 << sorted_eigenvalues[i].imag() << std::endl;
426 evalues << sorted_eigenvalues[i].real() <<
" "
427 << sorted_eigenvalues[i].imag() << std::endl;
447 MPI_Helpers::init(argc,argv);
451 unsigned n_element=100;
453 clock_t t_start1 = clock();
459 std::cout <<
"Matrix size " << problem.ndof() << std::endl;
463 clock_t t_end1 = clock();
465 clock_t t_start2 = clock();
473 clock_t t_end2 = clock();
475#ifdef OOMPH_HAS_TRILINOS
476 clock_t t_start3 = clock();
482 clock_t t_end3 = clock();
485 std::cout <<
"ARPACK TIME: " << (double)(t_end1 - t_start1)/CLOCKS_PER_SEC
488 std::cout <<
"LAPACK TIME: " << (double)(t_end2 - t_start2)/CLOCKS_PER_SEC
491#ifdef OOMPH_HAS_TRILINOS
492 std::cout <<
"ANASAZI TIME: " << (double)(t_end3 - t_start3)/CLOCKS_PER_SEC
497 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?
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)
///////////////////////////////////////////////////////////////////// ///////////////////////////////...