37 #include "meshes/one_d_mesh.h" 41 using namespace oomph;
55 bool operator()(
const complex<T> &x,
const complex<T> &y)
const 57 return x.real() < y.real();
84 virtual inline double u(
const unsigned& n)
const 85 {
return nodal_value(n,0);}
91 output(outfile,nplot);
96 void output(ostream &outfile,
const unsigned &nplot)
102 outfile << tecplot_zone_string(nplot);
105 unsigned num_plot_points=nplot_points(nplot);
106 for (
unsigned iplot=0;iplot<num_plot_points;iplot++)
109 get_s_plot(iplot,nplot,s);
111 outfile << interpolated_x(s,0) <<
" " << interpolated_u(s) << std::endl;
114 write_tecplot_zone_footer(outfile,nplot);
120 Vector<double> &residuals,
121 DenseMatrix<double> &jacobian, DenseMatrix<double> &mass_matrix)
124 unsigned n_node = nnode();
128 DShape dpsidx(n_node,1);
131 unsigned n_intpt = integral_pt()->nweight();
134 int local_eqn=0, local_unknown=0;
137 for(
unsigned ipt=0;ipt<n_intpt;ipt++)
140 double w = integral_pt()->weight(ipt);
143 double J = dshape_eulerian_at_knot(ipt,psi,dpsidx);
150 for(
unsigned l=0;l<n_node;l++)
153 local_eqn = u_local_eqn(l);
158 for(
unsigned l2=0;l2<n_node;l2++)
160 local_unknown = u_local_eqn(l2);
162 if(local_unknown >= 0)
164 jacobian(local_eqn,local_unknown) += dpsidx(l,0)*dpsidx(l2,0)*W;
165 mass_matrix(local_eqn, local_unknown) += psi(l)*psi(l2)*W;
176 unsigned n_node = nnode();
185 double interpolated_u = 0.0;
188 for(
unsigned l=0;l<n_node;l++) {interpolated_u+=u(l)*psi[l];}
191 return(interpolated_u);
198 virtual double dshape_eulerian(
const Vector<double> &s,
200 DShape &dpsidx)
const=0;
204 virtual double dshape_eulerian_at_knot(
const unsigned &ipt,
206 DShape &dpsidx)
const=0;
212 {
return nodal_local_eqn(n,0);}
225 template <
unsigned NNODE_1D>
245 void output(ostream &outfile,
const unsigned &Nplot)
254 DShape &dpsidx)
const 255 {
return QElement<1,NNODE_1D>::dshape_eulerian(s,psi,dpsidx);}
262 DShape &dpsidx)
const 263 {
return QElement<1,NNODE_1D>::dshape_eulerian_at_knot(ipt,psi,dpsidx);}
271 template<
class ELEMENT,
class EIGEN_SOLVER>
283 void solve(
const unsigned &label);
287 void doc_solution(
const unsigned& label);
298 template<
class ELEMENT,
class EIGEN_SOLVER>
300 const unsigned& n_element)
303 this->eigen_solver_pt() =
new EIGEN_SOLVER;
306 static_cast<EIGEN_SOLVER*
>(eigen_solver_pt())
307 ->get_eigenvalues_right_of_shift();
313 Problem::mesh_pt() =
new OneDMesh<ELEMENT>(n_element,L);
321 mesh_pt()->boundary_node_pt(0,0)->pin(0);
325 mesh_pt()->boundary_node_pt(1,0)->pin(0);
328 assign_eqn_numbers();
337 template<
class ELEMENT,
class EIGEN_SOLVER>
349 sprintf(filename,
"soln%i.dat",label);
350 some_file.open(filename);
351 mesh_pt()->output(some_file,npts);
359 template<
class ELEMENT,
class EIGEN_SOLVER>
364 Vector<complex<double> > eigenvalues;
366 Vector<DoubleVector> eigenvectors;
371 this->solve_eigenproblem(n_eval,eigenvalues,eigenvectors);
376 Vector<complex<double> > sorted_eigenvalues = eigenvalues;
377 sort(sorted_eigenvalues.begin(),sorted_eigenvalues.end(),
381 complex<double> temp_evalue = sorted_eigenvalues[1];
382 unsigned second_smallest_index=0;
385 for(
unsigned i=0;i<eigenvalues.size();i++)
389 if(eigenvalues[i] == temp_evalue) {second_smallest_index=i;
break;}
395 unsigned dim = eigenvectors[second_smallest_index].nrow();
398 for(
unsigned i=0;i<dim;i++)
401 length += std::pow(eigenvectors[second_smallest_index][i],2.0);
404 length = sqrt(length);
406 if(eigenvectors[second_smallest_index][0] < 0) {length *= -1.0;}
408 for(
unsigned i=0;i<dim;i++)
410 eigenvectors[second_smallest_index][i] /= length;
415 this->assign_eigenvector_to_dofs(eigenvectors[second_smallest_index]);
417 this->doc_solution(label);
420 sprintf(filename,
"eigenvalues%i.dat",label);
423 ofstream evalues(filename);
424 for(
unsigned i=0;i<n_eval;i++)
427 cout << sorted_eigenvalues[i].real() <<
" " 428 << sorted_eigenvalues[i].imag() << std::endl;
430 evalues << sorted_eigenvalues[i].real() <<
" " 431 << sorted_eigenvalues[i].imag() << std::endl;
446 int main(
int argc,
char **argv)
451 MPI_Helpers::init(argc,argv);
455 unsigned n_element=100;
457 clock_t t_start1 = clock();
463 std::cout <<
"Matrix size " << problem.ndof() << std::endl;
467 clock_t t_end1 = clock();
469 clock_t t_start2 = clock();
477 clock_t t_end2 = clock();
479 #ifdef OOMPH_HAS_TRILINOS 480 clock_t t_start3 = clock();
486 clock_t t_end3 = clock();
489 std::cout <<
"ARPACK TIME: " << (double)(t_end1 - t_start1)/CLOCKS_PER_SEC
492 std::cout <<
"LAPACK TIME: " << (double)(t_end2 - t_start2)/CLOCKS_PER_SEC
495 #ifdef OOMPH_HAS_TRILINOS 496 std::cout <<
"ANASAZI TIME: " << (double)(t_end3 - t_start3)/CLOCKS_PER_SEC
501 MPI_Helpers::finalize();
QHarmonicElement()
Constructor: Call constructors for QElement and Poisson equations.
void output(ostream &outfile, const unsigned &Nplot)
Output function overloaded from HarmonicEquations.
HarmonicProblem(const unsigned &n_element)
Constructor: Pass number of elements and pointer to source function.
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. Return Jacobian.
bool operator()(const complex< T > &x, const complex< T > &y) const
Comparison. Are the values identical or not?
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)
Output function overloaded from HarmonicEquations.
void solve(const unsigned &label)
Solve the problem.
int main(int argc, char **argv)
Driver for 1D Poisson problem.
void doc_solution(const unsigned &label)
Doc the solution, pass the number of the case considered, so that output files can be distinguished...
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)
Access function that returns the local equation number of the unknown in the problem. Default is to assume that it is the first (only) value stored at the node.
void output(ostream &outfile)
Output the eigenfunction with default number of plot points.
1D Harmonic problem in unit interval.
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.
~HarmonicProblem()
Destructor (empty)
virtual double u(const unsigned &n) const
Access function: Eigenfunction value at local node n Note that solving the eigenproblem does not assi...
double interpolated_u(const Vector< double > &s) const
Return FE representation of function value u(s) at local coordinate s.
unsigned required_nvalue(const unsigned &n) const
Required # of `values' (pinned or dofs) at node n.
HarmonicEquations()
Empty Constructor.