Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
	/*! start
	  Starts particle activity sequence
	  \param from		object to derive world position from 

	  */
	void ParticleBehaviour::start(GameObject *from)			// start or restart particle
	{
		elapsed = 0;
		lifeSpan = Math::randRange(lifeSpanMin, lifeSpanMax);

		// Derive world position from gameObject of parent ParticleEmitter
		// Note the particle may or may not be a descendent of the particle emitter
		Vector3 position = from->getTransform()->getWorldPosition();
		position.x += Math::randRangeND(-startDistanceX, startDistanceX);
		position.y += Math::randRangeND(-startDistanceY, startDistanceY);
		position.z += Math::randRangeND(-startDistanceZ, startDistanceZ);
		this->gameObject->getTransform()->setWorldPosition(position);

		Quaternion rotQ(0.0f, dirBaseThetaY + Math::randRange(-directionVar, directionVar), 
							 dirBaseThetaZ + Math::randRange(-directionVar, directionVar));
		Matrix3x3 rotM = (Matrix3x3)rotQ;
		Vector3 unitX(1.0, 0.0, 0.0);
		direction = unitX * rotM;
		speed = Math::randRangeND(speedStartMin, speedStartMax);

				//rotationMatrix = (Matrix3x3)q;


		/*velocity = Vector3(velocityBase.x + Math::randRangeND(-velocityVar.x, velocityVar.x),
							velocityBase.y + Math::randRangeND(-velocityVar.y, velocityVar.y),
							velocityBase.z + Math::randRangeND(-velocityVar.z, velocityVar.z));
		acceleration = Vector3(accelBase.x + Math::randRangeND(-accelVar.x, accelVar.x),
							accelBase.y + Math::randRangeND(-accelVar.y, accelVar.y),
							accelBase.z + Math::randRangeND(-accelVar.z, accelVar.z));
							*/

		gameObject->setVisible(true);
		active = true;
	}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
void
TestInterpolationHCurl::testInterpolation( std::string one_element_mesh )
{
    // expr to interpolate
    auto myexpr = unitX() + unitY(); //(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::vector<std::string> faces, edges; //list of edges
    edges = {"hypo","vert","hor"};

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

    // handly computed interpolant coeff (in hcurl basis)
    for ( int i = 0; i < Xh->nLocalDof(); ++i )
        {
            CHECK( oneelement_mesh->hasMarkers( {edges[i]} ) );
            U_h_int(i) = integrate( markedfaces( oneelement_mesh, edges[i] ), trans( T() )*myexpr ).evaluate()(0,0);
        }

    // nedelec interpolant using on
    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=boundaryfaces(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 );
}
Exemplo n.º 5
0
void DrivenCavity<Dim>::exportResults( element_type const& U )
{
    auto uex=unitX();
    auto u_exact=vf::project(Vh->template functionSpace<0>(), markedfaces(mesh, "wall2"), uex );

    if ( exporter->doExport() )
    {
        exporter->step( 0 )->setMesh( U.functionSpace()->mesh() );
        exporter->step( 0 )->addRegions();
        exporter->step( 0 )->add( "u", U.template element<0>() );
        exporter->step( 0 )->add( "p", U.template element<1>() );
        exporter->step( 0 )->add( "uex", u_exact);
        exporter->save();
    }

}
Exemplo n.º 6
0
void
DrivenCavity<Dim>::Residual(const vector_ptrtype& X, vector_ptrtype& R)
{
    auto U = Vh->element( "(u,p)" );
    auto V = Vh->element( "(v,q)" );
    auto u = U.template element<0>( "u" );
    //auto u_exact = U.template element<0>( "u_exact" );
    auto v = V.template element<0>( "u" );
    auto p = U.template element<1>( "p" );
    auto q = V.template element<1>( "p" );
    //#if defined( FEELPP_USE_LM )
    auto lambda = U.template element<2>();
    auto nu = V.template element<2>();
    //#endif

    auto uex=unitX();
    auto u_exact=vf::project(Vh->template functionSpace<0>(), markedfaces(mesh, "wall2"), uex );


    U=*X;
    auto r = form1( _test=Vh, _vector=R );
    //r += integrate( elements( mesh ),-inner( f,id( v ) ) );
    r = integrate( elements( mesh ), trans(gradv( u )*idv(u))*id(v));//convective term
    r += integrate( elements( mesh ), inner(gradv( u ),grad( v ))/Re );
    r +=  integrate( elements( mesh ),-idv(p)*div(v) + id(q)*divv(u));
    //#if defined( FEELPP_USE_LM )
    r += integrate ( elements( mesh ), +id( q )*idv( lambda )+idv( p )*id( nu ) );
    //#endif


    //Weak Dirichlet
    auto SigmaNv = ( -idv( p )*N() + gradv( u )*N()/Re );
    auto SigmaN = ( -id( q )*N() + grad( v )*N()/Re );
    r +=integrate ( boundaryfaces(mesh), - trans( SigmaNv )*id( v ) - trans( SigmaN )*( idv( u ) -idv(u_exact) ) + penalbc*trans( idv( u ) - idv(u_exact) )*id( v )/hFace() );


}
Exemplo n.º 7
0
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);
		}
	}
}