本文整理汇总了C++中MatrixXf::print方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixXf::print方法的具体用法?C++ MatrixXf::print怎么用?C++ MatrixXf::print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixXf
的用法示例。
在下文中一共展示了MatrixXf::print方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stiffnessTestHelper
void stiffnessTestHelper(StrainEne * ene)
{
float h = 0.001f;
// ElementRegGrid * grid = new ElementRegGrid(1, 1, 1);
ElementMesh * grid = new ElementMesh();
grid->dim = 2;
std::ifstream in("../quads3.txt");
grid->load(in, 0.5f);
int dim = grid->dim;
MaterialQuad * material = new MaterialQuad(ene);
if(dim==2){
material->q = &(Quadrature::Gauss2_2D);
material->e.resize(material->q->x.size(),ene);
}
grid->m.push_back(material);
material->init(grid);
grid->x[1][0] += 0.1f;
grid->x[3][1] += 0.2f;
MatrixXf KAna = grid->getStiffness();
int nVar = (int)grid->X.size();
MatrixXf K(dim*nVar,dim*nVar);
std::cout<<K.mm<<" K size\n";
//check each partial derivative
for(unsigned int ii = 0;ii<grid->x.size();ii++){
for(int jj = 0; jj<dim; jj++){
grid->x[ii][jj] -= h;
std::vector<Vector3f>fminus = grid->getForce();
grid->x[ii][jj] += 2*h;
std::vector<Vector3f>fplus = grid->getForce();
grid->x[ii][jj] -=h;
for(unsigned int kk = 0;kk<fminus.size();kk++){
fplus[kk] -= fminus[kk];
fplus[kk] /= 2*h;
for(int ll = 0;ll<dim;ll++){
K(dim*kk+ll,dim*ii+jj)=-fplus[kk][ll];
}
}
}
}
std::cout<<"Ana K:\n";
KAna.print(std::cout);
std::cout<<"\n";
std::cout<<"Num K:\n";
K.print(std::cout);
std::cout<<"\n";
float maxErr = 0;
for(int ii = 0;ii<K.mm;ii++){
for(int jj =0 ;jj<K.nn;jj++){
float err = (float)std::abs(KAna(ii,jj)-K(ii,jj));
if(err>maxErr){
maxErr = err;
}
}
}
std::cout<<"max err "<<maxErr<<"\n";
delete grid;
delete material;
}