void TestInterpolationHDiv<Dim>::testInterpolation() { // expr to interpolate int is3D = 0; if( Dim == 3 ) is3D = 1; auto myexpr = unitX() + unitY() + is3D*unitZ() ; //(1,1) auto mesh = loadMesh( _mesh=new Mesh<Simplex<Dim>> ); space_ptrtype Xh = space_type::New( mesh ); // RT function space auto u_on = Xh->element(); auto u_proj = Xh->element(); //test on keyword u_on.on(_range=elements(mesh), _expr=myexpr); //test project keyword u_proj = vf::project(_space=Xh, _range=elements(mesh), _expr=myexpr); //L2 norm of error auto error_on = vf::project(_space=Xh, _range=elements(mesh), _expr=myexpr - idv(u_on) ); double L2error_on = error_on.l2Norm(); std::cout << "[on] L2 error = " << L2error_on << std::endl; auto error_proj = vf::project(_space=Xh, _range=elements(mesh), _expr=myexpr - idv(u_proj) ); double L2error_proj = error_proj.l2Norm(); std::cout << "[proj] L2 error = " << L2error_proj << std::endl; }
void TestInterpolationHDiv<Dim>::testInterpolationOneElt( std::string one_element_mesh ) { // expr to interpolate int is3D = 0; if( Dim == 3 ) is3D = 1; auto myexpr = unitX() + unitY() + is3D*unitZ() ; //(1,1) // one element mesh auto mesh_name = one_element_mesh + ".msh"; //create the mesh and load it fs::path mesh_path( mesh_name ); mesh_ptrtype oneelement_mesh = loadMesh( _mesh=new mesh_type, _filename=mesh_name); // refined mesh (export) auto refine_level = std::floor(1 - math::log( 0.1 )); //Deduce refine level from meshSize (option) mesh_ptrtype mesh = loadMesh( _mesh=new mesh_type, _filename=mesh_name, _refine=( int )refine_level); space_ptrtype Xh = space_type::New( oneelement_mesh ); //std::cout << "nb dof = " << Xh->nDof() << std::endl; std::vector<std::string> faces; if(Dim == 2) faces = { "hypo","vert","hor"}; else if (Dim == 3) faces = {"xzFace","xyFace","xyzFace","yzFace"}; element_type U_h_int = Xh->element(); element_type U_h_on = Xh->element(); // handly computed interpolant coeff (in hdiv basis) for ( int i = 0; i < Xh->nLocalDof(); ++i ) { CHECK( mesh->hasMarkers( {faces[i]} ) ); U_h_int(i) = integrate( markedfaces( oneelement_mesh, faces[i] ), trans( N() )*myexpr ).evaluate()(0,0); } // raviart-thomas interpolant using on U_h_on.zero(); U_h_on.on(_range=elements(oneelement_mesh), _expr=myexpr); auto exporter_proj = exporter( _mesh=mesh, _name=( boost::format( "%1%-%2%" ) % this->about().appName() %mesh_path.stem().string() ).str() ); exporter_proj->step( 0 )->add( "U_interpolation_handly-" + mesh_path.stem().string(), U_h_int ); exporter_proj->step( 0 )->add( "U_interpolation_on-" + mesh_path.stem().string(), U_h_on ); exporter_proj->save(); U_h_int.printMatlab( "U_h_int_" + mesh_path.stem().string() + ".m" ); U_h_on.printMatlab( "U_h_on_" + mesh_path.stem().string() + ".m" ); //L2 norm of error auto error = vf::project(_space=Xh, _range=elements(oneelement_mesh), _expr=idv(U_h_int) - idv(U_h_on) ); double L2error = error.l2Norm(); std::cout << "L2 error = " << L2error << std::endl; }
RotationMatrices::RotationMatrices() { matrices[0] = math::mat3(1.0f); math::mat3 rotateZ90 = math::mat3(0, 1, 0, -1, 0, 0, 0, 0, 1); for (int i = 1; i < 4; ++i) matrices[i] = matrices[i - 1] * rotateZ90; math::mat3 rotateXP90 = math::mat3(1, 0, 0, 0, 0, 1, 0, -1, 0); for (int i = 0; i < 4; ++i) { matrices[4 + i] = rotateXP90 * matrices[i]; } math::mat3 rotateYP90 = math::mat3(0, 0, -1, 0, 1, 0, 1, 0, 0); for (int i = 0; i < 4; ++i) { matrices[8 + i] = rotateYP90 * matrices[i]; } math::mat3 rotateXN90 = math::mat3(1, 0, 0, 0, 0, -1, 0, 1, 0); for (int i = 0; i < 4; ++i) { matrices[12 + i] = rotateXN90 * matrices[i]; } math::mat3 rotateYN90 = math::mat3(0, 0, 1, 0, 1, 0, -1, 0, 0); for (int i = 0; i < 4; ++i) { matrices[16 + i] = rotateYN90 * matrices[i]; } math::mat3 rotateXP180 = rotateXP90 * rotateXP90; for (int i = 0; i < 4; ++i) { matrices[20 + i] = rotateXP180 * matrices[i]; } math::mat3 neg = math::mat3(1.0) * (-1.0f); for (int i = 0; i < 24; ++i) { matrices[24 + i] = neg * matrices[i]; } for (int i = 0; i < 48; ++i) { invMatrices[i] = math::inverse(matrices[i]); for (int dir = 0; dir < 6; ++dir) { math::vec3 v = dirToVec((Dir) dir); v = invMatrices[i] * v; invDirs[i * 6 + dir] = vecToDir(v); } } quadRotations[(int) Dir::XN] = 4; quadRotations[(int) Dir::XP] = 0; quadRotations[(int) Dir::YN] = 0; quadRotations[(int) Dir::YP] = 4; quadRotations[(int) Dir::ZN] = 4; quadRotations[(int) Dir::ZP] = 0; const math::mat2 texMat[8] = {math::mat2(1, 0, 0, 1), math::mat2(0, -1, 1, 0), math::mat2(-1, 0, 0, -1), math::mat2(0, 1, -1, 0), math::mat2(-1, 0, 0, 1), math::mat2(0, -1, -1, 0), math::mat2(1, 0, 0, -1), math::mat2(0, 1, 1, 0)}; math::vec3 unitX(1.0f, 0.0f, 0.0f); math::vec3 unitY(0.0f, 1.0f, 0.0f); math::vec3 unitZ(0.0f, 0.0f, 1.0f); for (int i = 1; i < 48; ++i) { for (int dir = 0; dir < 6; ++dir) { quadRotations[i * 6 + dir] = 0; Dir origDir = invDirs[i * 6 + dir]; math::mat3 origMat = textureMatrixToMat3(math::inverse(texMat[quadRotations[(int) origDir]]), origDir); math::vec3 destUnitX = matrices[i] * origMat * unitX; math::vec3 destUnitY = matrices[i] * origMat * unitY; math::vec3 destUnitZ = matrices[i] * origMat * unitZ; math::vec3 destUnit[2]; int j = 0; if (math::length(destUnitX) > 0.9) destUnit[j++] = destUnitX; if (math::length(destUnitY) > 0.9) destUnit[j++] = destUnitY; if (math::length(destUnitZ) > 0.9) destUnit[j++] = destUnitZ; assert(j == 2); int k = 0; for (; k < 8; ++k) { math::vec3 testUnitX = textureMatrixToMat3(math::inverse(texMat[k]), (Dir) dir) * unitX; math::vec3 testUnitY = textureMatrixToMat3(math::inverse(texMat[k]), (Dir) dir) * unitY; math::vec3 testUnitZ = textureMatrixToMat3(math::inverse(texMat[k]), (Dir) dir) * unitZ; math::vec3 testUnit[2]; j = 0; if (math::length(testUnitX) > 0.9) testUnit[j++] = testUnitX; if (math::length(testUnitY) > 0.9) testUnit[j++] = testUnitY; if (math::length(testUnitZ) > 0.9) testUnit[j++] = testUnitZ; assert(j == 2); if (testUnit[0] == destUnit[0] && testUnit[1] == destUnit[1]) { quadRotations[i * 6 + dir] = k; break; } } assert(k < 8); } } }