예제 #1
0
 void saveSubMeshFromMarked3Elements()
 {
     auto meshMark1 = createSubmesh( M_mesh, marked3elements(M_mesh,1),EXTRACTION_KEEP_MESH_RELATION, 0, false);
     saveGMSHMesh(_mesh=meshMark1,_filename="submesh-marked3elementsBy1.msh");
     auto meshMark0 = createSubmesh( M_mesh, marked3elements(M_mesh,0),EXTRACTION_KEEP_MESH_RELATION, 0, false);
     saveGMSHMesh(_mesh=meshMark0,_filename="submesh-marked3elementsBy0.msh");
 }
예제 #2
0
boost::shared_ptr<Mesh<Simplex<2> > >
createSubMeshLaplacianBlock(boost::shared_ptr<Mesh<Simplex<2> > > mesh)
{
    auto P0d = Pdh<0>(mesh);
    double r=0.2;
    auto proj = vf::project(_space=P0d,_range=elements(mesh),
                            _expr=vf::chi( (Px()*Px()+Py()*Py()) < r*r ) );
    mesh->updateMarker3( proj );
    auto submesh = createSubmesh( mesh, marked3elements(mesh,1) );
    //saveGMSHMesh(_mesh=submesh,_filename="mysubmesh.msh");
    return submesh;
}
void
TestInterpolationHCurl3D::testInterpolation( std::string one_element_mesh )
{
    //auto myexpr = unitX() + unitY() + unitZ() ; //(1,1,1)
    auto myexpr = vec( cst(1.), cst(1.), cst(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::vector<std::string> faces = {"yzFace","xyzFace","xyFace"};
    std::vector<std::string> edges = {"zAxis","yAxis","yzAxis","xyAxis","xzAxis","xAxis"};

    element_type U_h_int = Xh->element();
    element_type U_h_on = Xh->element();
    element_type U_h_on_boundary = Xh->element();

    submesh1d_ptrtype edgeMesh( new submesh1d_type );
    edgeMesh = createSubmesh(oneelement_mesh, boundaryedges(oneelement_mesh) ); //submesh of edges

    // Tangents on ref element
    auto t0 = vec(cst(0.),cst(0.),cst(-2.));
    auto t1 = vec(cst(0.),cst(2.),cst(0.));
    auto t2 = vec(cst(0.),cst(-2.),cst(2.));
    auto t3 = vec(cst(2.),cst(-2.),cst(0.));
    auto t4 = vec(cst(2.),cst(0.),cst(-2.));
    auto t5 = vec(cst(2.),cst(0.),cst(0.));

    // Jacobian of geometrical transforms
    std::string jac;
    if(mesh_path.stem().string() == "one-elt-ref-3d" || mesh_path.stem().string() == "one-elt-real-h**o-3d" )
        jac = "{1,0,0,0,1,0,0,0,1}:x:y:z";
    else if(mesh_path.stem().string() == "one-elt-real-rotx" )
        jac = "{1,0,0,0,0,-1,0,1,0}:x:y:z";
    else if(mesh_path.stem().string() == "one-elt-real-roty" )
        jac = "{0,0,1,0,1,0,-1,0,0}:x:y:z";
    else if(mesh_path.stem().string() == "one-elt-real-rotz" )
        jac = "{0,-1,0,1,0,0,0,0,1}:x:y:z";

    U_h_int(0) = integrate( markedelements(edgeMesh, edges[0]), trans(expr<3,3>(jac)*t0)*myexpr ).evaluate()(0,0);
    U_h_int(1) = integrate( markedelements(edgeMesh, edges[1]), trans(expr<3,3>(jac)*t1)*myexpr ).evaluate()(0,0);
    U_h_int(2) = integrate( markedelements(edgeMesh, edges[2]), trans(expr<3,3>(jac)*t2)*myexpr ).evaluate()(0,0);
    U_h_int(3) = integrate( markedelements(edgeMesh, edges[3]), trans(expr<3,3>(jac)*t3)*myexpr ).evaluate()(0,0);
    U_h_int(4) = integrate( markedelements(edgeMesh, edges[4]), trans(expr<3,3>(jac)*t4)*myexpr ).evaluate()(0,0);
    U_h_int(5) = integrate( markedelements(edgeMesh, edges[5]), trans(expr<3,3>(jac)*t5)*myexpr ).evaluate()(0,0);

    for(int i=0; i<edges.size(); i++)
        {
            double edgeLength = integrate( markedelements(edgeMesh, edges[i]), cst(1.) ).evaluate()(0,0);
            U_h_int(i) /= edgeLength;
        }

#if 0 //Doesn't work for now
    for(int i=0; i<Xh->nLocalDof(); i++)
        {
            CHECK( edgeMesh->hasMarkers( {edges[i]} ) );
            U_h_int(i) = integrate( markedelements(edgeMesh, edges[i]), trans( print(T(),"T=") )*myexpr ).evaluate()(0,0);
            std::cout << "U_h_int(" << i << ")= " << U_h_int(i) << std::endl;
        }
#endif

    // nedelec interpolant using on keyword
    // interpolate on element
    U_h_on.zero();
    U_h_on.on(_range=elements(oneelement_mesh), _expr=myexpr);
    U_h_on_boundary.on(_range=boundaryfaces(oneelement_mesh), _expr=myexpr);

    auto exporter_proj = exporter( _mesh=mesh, _name=( boost::format( "%1%" ) % this->about().appName() ).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();

    // print coefficient only for reference element
    U_h_int.printMatlab( "U_h_int_" + mesh_path.stem().string() + ".m" );
    U_h_on.printMatlab( "U_h_on_" + mesh_path.stem().string() + ".m" );
    U_h_on_boundary.printMatlab( "U_h_on_boundary_" + 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 (elements) = " << L2error << std::endl;

    auto error_boundary = vf::project(_space=Xh, _range=elements(oneelement_mesh), _expr=idv(U_h_int) - idv(U_h_on_boundary) );
    double L2error_boundary = error_boundary.l2Norm();
    std::cout << "L2 error (boundary) = " << L2error_boundary << std::endl;
    BOOST_CHECK_SMALL( L2error_boundary - L2error, 1e-13 );
}