PetscErrorCode PetscDTGaussQuadrature
(PetscInt npoints, PetscReal a, PetscReal b,
PetscReal *x, PetscReal *w)
static char help[] = "Basic gausslegend routines.\n\n";
template<int N>
class gausslegend
{
public:
gausslegend<N>()
{
PetscDTGaussQuadrature(npoints, a, b, x, w);
}
void print()
{
std::cout<<npoints<<" points gauss-legend Quadrature:\n";
std::cout<<"position\n";
for(int i=0;i<N;i++)
{
std::cout<<x[i]<<" ";
}
std::cout<<"\nweight\n";
for(int i=0;i<N;i++)
{
std::cout<<w[i]<<" ";
}
std::cout<<std::endl;
}
private:
PetscInt npoints=N;
PetscReal a=-1,b=1;
PetscReal x[N],w[N];
};
int main(int argc, char **argv)
{
PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
gausslegend<2> g1;
g1.print();
gausslegend<4> g2;
g2.print();
PetscCall(PetscFinalize());
return 0;
}
以上,就是本文的主要内容,感谢您的阅读!