void TestBandMatrixArith_D1()
{
    std::vector<tmv::BandMatrixView<T> > b;
    std::vector<tmv::BandMatrixView<std::complex<T> > > cb;
    MakeBandList(b,cb);

    const int N = b[0].rowsize();

    tmv::Matrix<T> a1(N,N);
    for (int i=0; i<N; ++i) for (int j=0; j<N; ++j) a1(i,j) = T(3+i-5*j);
    tmv::Matrix<std::complex<T> > ca1(N,N);
    for (int i=0; i<N; ++i) for (int j=0; j<N; ++j)
        ca1(i,j) = std::complex<T>(3+i-5*j,4-8*i-j);

    tmv::UpperTriMatrix<T,tmv::NonUnitDiag|tmv::RowMajor> u1(a1);
    tmv::UpperTriMatrix<std::complex<T>,tmv::NonUnitDiag|tmv::RowMajor> cu1(ca1);
    tmv::UpperTriMatrixView<T> u1v = u1.view();
    tmv::UpperTriMatrixView<std::complex<T> > cu1v = cu1.view();
    tmv::UpperTriMatrix<T,tmv::NonUnitDiag> u1x = u1v;
    tmv::UpperTriMatrix<std::complex<T>,tmv::NonUnitDiag> cu1x = cu1v;

#if (XTEST & 2)
    tmv::UpperTriMatrix<T,tmv::UnitDiag|tmv::RowMajor> u2(a1);
    tmv::UpperTriMatrix<T,tmv::NonUnitDiag|tmv::ColMajor> u3(a1);
    tmv::UpperTriMatrix<T,tmv::UnitDiag|tmv::ColMajor> u4(a1);
    tmv::LowerTriMatrix<T,tmv::NonUnitDiag|tmv::RowMajor> l1(a1);
    tmv::LowerTriMatrix<T,tmv::UnitDiag|tmv::RowMajor> l2(a1);
    tmv::LowerTriMatrix<T,tmv::NonUnitDiag|tmv::ColMajor> l3(a1);
    tmv::LowerTriMatrix<T,tmv::UnitDiag|tmv::ColMajor> l4(a1);

    tmv::UpperTriMatrix<std::complex<T>,tmv::UnitDiag|tmv::RowMajor> cu2(ca1);
    tmv::UpperTriMatrix<std::complex<T>,tmv::NonUnitDiag|tmv::ColMajor> cu3(ca1);
    tmv::UpperTriMatrix<std::complex<T>,tmv::UnitDiag|tmv::ColMajor> cu4(ca1);
    tmv::LowerTriMatrix<std::complex<T>,tmv::NonUnitDiag|tmv::RowMajor> cl1(ca1);
    tmv::LowerTriMatrix<std::complex<T>,tmv::UnitDiag|tmv::RowMajor> cl2(ca1);
    tmv::LowerTriMatrix<std::complex<T>,tmv::NonUnitDiag|tmv::ColMajor> cl3(ca1);
    tmv::LowerTriMatrix<std::complex<T>,tmv::UnitDiag|tmv::ColMajor> cl4(ca1);

    tmv::UpperTriMatrixView<T> u2v = u2.view();
    tmv::UpperTriMatrixView<T> u3v = u3.view();
    tmv::UpperTriMatrixView<T> u4v = u4.view();
    tmv::LowerTriMatrixView<T> l1v = l1.view();
    tmv::LowerTriMatrixView<T> l2v = l2.view();
    tmv::LowerTriMatrixView<T> l3v = l3.view();
    tmv::LowerTriMatrixView<T> l4v = l4.view();
    tmv::UpperTriMatrixView<std::complex<T> > cu2v = cu2.view();
    tmv::UpperTriMatrixView<std::complex<T> > cu3v = cu3.view();
    tmv::UpperTriMatrixView<std::complex<T> > cu4v = cu4.view();
    tmv::LowerTriMatrixView<std::complex<T> > cl1v = cl1.view();
    tmv::LowerTriMatrixView<std::complex<T> > cl2v = cl2.view();
    tmv::LowerTriMatrixView<std::complex<T> > cl3v = cl3.view();
    tmv::LowerTriMatrixView<std::complex<T> > cl4v = cl4.view();
#endif

    for(size_t i=START;i<b.size();i++) {
        if (showstartdone) {
            std::cerr<<"Start loop "<<i<<std::endl;
            std::cerr<<"bi = "<<b[i]<<std::endl;
        }
        tmv::BandMatrixView<T> bi = b[i];
        tmv::BandMatrixView<std::complex<T> > cbi = cb[i];

        TestMatrixArith4(bi,cbi,u1v,cu1v,"Band/UpperTri");
        TestMatrixArith5(bi,cbi,u1v,cu1v,"Band/UpperTri");
        TestMatrixArith6x(bi,cbi,u1v,cu1v,"Band/UpperTri");
#if (XTEST & 2)
        TestMatrixArith4(bi,cbi,l1v,cl1v,"Band/LowerTri");
        TestMatrixArith5(bi,cbi,l1v,cl1v,"Band/LowerTri");
        TestMatrixArith6x(bi,cbi,l1v,cl1v,"Band/LowerTri");
        TestMatrixArith4(bi,cbi,u2v,cu2v,"Band/UpperTri");
        TestMatrixArith5(bi,cbi,u2v,cu2v,"Band/UpperTri");
        TestMatrixArith6x(bi,cbi,u2v,cu2v,"Band/UpperTri");
        TestMatrixArith4(bi,cbi,l2v,cl2v,"Band/LowerTri");
        TestMatrixArith5(bi,cbi,l2v,cl2v,"Band/LowerTri");
        TestMatrixArith6x(bi,cbi,l2v,cl2v,"Band/LowerTri");
        TestMatrixArith4(bi,cbi,u3v,cu3v,"Band/UpperTri");
        TestMatrixArith5(bi,cbi,u3v,cu3v,"Band/UpperTri");
        TestMatrixArith6x(bi,cbi,u3v,cu3v,"Band/UpperTri");
        TestMatrixArith4(bi,cbi,l3v,cl3v,"Band/LowerTri");
        TestMatrixArith5(bi,cbi,l3v,cl3v,"Band/LowerTri");
        TestMatrixArith6x(bi,cbi,l3v,cl3v,"Band/LowerTri");
        TestMatrixArith4(bi,cbi,u4v,cu4v,"Band/UpperTri");
        TestMatrixArith5(bi,cbi,u4v,cu4v,"Band/UpperTri");
        TestMatrixArith6x(bi,cbi,u4v,cu4v,"Band/UpperTri");
        TestMatrixArith4(bi,cbi,l4v,cl4v,"Band/LowerTri");
        TestMatrixArith5(bi,cbi,l4v,cl4v,"Band/LowerTri");
        TestMatrixArith6x(bi,cbi,l4v,cl4v,"Band/LowerTri");
#endif
    }
}
Exemple #2
0
void ParticleSystem::Tick( float time ) {
	if( !m_running ) {
		return;
	}

	std::size_t particles_size = m_particles.size();

	for( std::size_t index = 0; index < particles_size; ) {
		m_particles[ index ].life += time;

		if( m_particles[ index ].life >= m_particles[ index ].lifetime ) {
			m_particles.erase( m_particles.begin() );
			particles_size--;
			continue;
		}

		m_particles[ index ].velocity += ( m_particles[ index ].acceleration * time );
		m_particles[ index ].position += ( m_particles[ index ].velocity * time );

		++index;
	}

	if( !m_emitting ) {
		return;
	}

	std::size_t emitters_size = m_emitters.size();

	for( std::size_t index = 0; index < emitters_size; ++index ) {
		m_emitters[ index ].queue += m_emitters[ index ].rate * time;

		while( m_emitters[ index ].queue >= 1.0f ) {
			Particle particle = m_emitters[ index ].prototype;

			particle.life = 0.0f;
			particle.lifetime = m_emitters[ index ].prototype.lifetime;

			particle.size_start = m_emitters[ index ].prototype.size_start;
			particle.size_end = m_emitters[ index ].prototype.size_end;

			particle.color_start.r = m_emitters[ index ].prototype.color_start.r;
			particle.color_start.g = m_emitters[ index ].prototype.color_start.g;
			particle.color_start.b = m_emitters[ index ].prototype.color_start.b;
			particle.color_start.a = m_emitters[ index ].prototype.color_start.a;

			particle.color_end.r = m_emitters[ index ].prototype.color_end.r;
			particle.color_end.g = m_emitters[ index ].prototype.color_end.g;
			particle.color_end.b = m_emitters[ index ].prototype.color_end.b;
			particle.color_end.a = m_emitters[ index ].prototype.color_end.a;

			std::uniform_real_distribution<float> u1( -m_emitters[ index ].spread, m_emitters[ index ].spread );

			float angle = u1( rng );

			float start_dist = 0.0f;

			std::uniform_real_distribution<float> u2( m_emitters[ index ].radius_start, m_emitters[ index ].radius_end );

			start_dist = u2( rng );

			sf::Vector2f acceleration = particle.acceleration;
			sf::Vector2f velocity = particle.velocity;

			sf::Vector2f position = sf::Vector2f( start_dist * static_cast<float>( cos( angle ) ), start_dist * static_cast<float>( sin( angle ) ) );

			velocity = sf::Vector2f( velocity.x * static_cast<float>( cos( angle ) ) -
															 velocity.y * static_cast<float>( sin( angle ) ) ,
															 velocity.x * static_cast<float>( sin( angle ) ) +
															 velocity.y * static_cast<float>( cos( angle ) ) );

			acceleration = sf::Vector2f( acceleration.x * static_cast<float>( cos( angle ) ) -
																	 acceleration.y * static_cast<float>( sin( angle ) ) ,
																	 acceleration.x * static_cast<float>( sin( angle ) ) +
																	 acceleration.y * static_cast<float>( cos( angle ) ) );

			particle.position = position;
			particle.acceleration = acceleration;
			particle.velocity = velocity;

			m_particles.push_back( particle );
			particles_size++;

			m_emitters[ index ].queue -= 1.0f;
		}
	}
}
Exemple #3
0
int
main()
{
  std::cout.setf(std::ios_base::boolalpha);

  std::polynomial<double> P({0.0, 1.0, 2.0, 3.0});
  std::cout << "P = " << P << std::endl;
  std::cout << "+P = " << +P << std::endl;
  std::cout << "-P = " << -P << std::endl;
  std::cout << "P = " << P << std::endl;
  std::cout << "degree(P) = " << P.degree() << std::endl;
  std::polynomial<double> Q({2.0, 1.0});
  std::cout << "Q = " << Q << std::endl;
  std::cout << "degree(Q) = " << Q.degree() << std::endl;
  std::cout << "P + Q = " << P + Q << std::endl;
  std::cout << "P - Q = " << P - Q << std::endl;
  std::cout << "P * Q = " << P * Q << std::endl;
  std::cout << "P / Q = " << P / Q << std::endl;
  std::cout << "P % Q = " << P % Q << std::endl;
  double b = 5.0;
  std::cout << "b = " << b << std::endl;
  std::cout << "P + b = " << P + b << std::endl;
  std::cout << "P - b = " << P - b << std::endl;
  std::cout << "P * b = " << P * b << std::endl;
  std::cout << "P / b = " << P / b << std::endl;
  std::cout << "P % b = " << P % b << std::endl;
  double a = 2.0;
  std::cout << "a = " << a << std::endl;
  std::cout << "a + Q = " << a + Q << std::endl;
  std::cout << "a - Q = " << a - Q << std::endl;
  std::cout << "a * Q = " << a * Q << std::endl;
  std::cout << "a / Q = " << a / Q << std::endl;
  std::cout << "a % Q = " << a % Q << std::endl;

  std::polynomial<double> B;// = b;
  B = b;
  std::cout << "B = " << B << std::endl;
  std::cout << "P % B = " << P % B << std::endl;

  Q = {0.0, -2.0, 4.0, -6.0, 8.0, -12.0};
  std::cout << "Q = " << Q << std::endl;

  std::polynomial<double> P2;
  P2 = P;
  std::cout << "P2 = " << P2 << std::endl;
  std::cout << "P2 == P = " << (P2 == P) << std::endl;

  for (int i = 0; i <= 100; ++i)
  {
    double x = i * 0.1;
    std::cout << "P(" << x << ") = " << P(x) << std::endl;
  }

  std::polynomial<std::complex<double>>
  CP({std::complex<double>(0.0, -1.0),
      std::complex<double>(1.0, -2.0), 
      std::complex<double>(2.0, -3.0), 
      std::complex<double>(3.0, -4.0)});
  std::cout << "CP = " << CP << std::endl;
  std::cout << "CP * CP = " << CP * CP << std::endl;

  std::polynomial<int> IP({0, 1, 2, 3});
  std::cout << "IP = " << IP << std::endl;
  std::cout << "IP * IP = " << IP * IP << std::endl;

  std::array<double, 10> arr;
  P.eval(1.0, arr);
  std::cout << "P(" << 1.0 << ") =";
  for (int i = 0; i < arr.size(); ++i)
    std::cout << " " << arr[i];
  std::cout << std::endl;

  P.eval(1.0, arr.begin(), arr.end());
  std::cout << "P(" << 1.0 << ") =";
  for (auto iarr = arr.cbegin(); iarr != arr.cend(); ++iarr)
    std::cout << " " << *iarr;
  std::cout << std::endl;

  std::istringstream is("(-2.0, -1.0, 0.0)");
  std::polynomial<double> R;
  is >> R;
  std::cout << "R = " << R << std::endl;

  std::istringstream is2("(5.0)");
  std::polynomial<double> S;
  is2 >> S;
  std::cout << "S = " << S << std::endl;

  std::istringstream is3("42.0");
  std::polynomial<double> T;
  is3 >> T;
  std::cout << "T = " << T << std::endl;

  std::polynomial<double> u({1.0, 3.0, 3.0, 1.0});
  std::polynomial<double> v({1.0, 1.0});
  std::polynomial<double> q, r;
  std::divmod(u, v, q, r);
  std::cout << "u = " << u << std::endl;
  std::cout << "v = " << v << std::endl;
  std::cout << "q = " << q << std::endl;
  std::cout << "r = " << r << std::endl;

  std::polynomial<double> u1({1.0, -3.0, 3.0, -1.0});
  std::polynomial<double> v1({1.0, -2.0, 1.0});
  std::polynomial<double> q1, r1;
  std::divmod(u1, v1, q1, r1);
  std::cout << "u1 = " << u1 << std::endl;
  std::cout << "v1 = " << v1 << std::endl;
  std::cout << "q1 = " << q1 << std::endl;
  std::cout << "r1 = " << r1 << std::endl;

  std::polynomial<double> u2({1.0, 1.0});
  std::polynomial<double> v2({1.0, 3.0, 3.0, 1.0});
  std::polynomial<double> q2, r2;
  std::divmod(u2, v2, q2, r2);
  std::cout << "u2 = " << u2 << std::endl;
  std::cout << "v2 = " << v2 << std::endl;
  std::cout << "q2 = " << q2 << std::endl;
  std::cout << "r2 = " << r2 << std::endl;

  std::polynomial<double> u3({1.0, 0.0, 0.0, 1.0});
  std::polynomial<double> v3({1.0, 3.0, 3.0, 1.0});
  std::polynomial<double> q3, r3;
  std::divmod(u3, v3, q3, r3);
  std::cout << "u3 = " << u3 << std::endl;
  std::cout << "v3 = " << v3 << std::endl;
  std::cout << "q3 = " << q3 << std::endl;
  std::cout << "r3 = " << r3 << std::endl;

  std::cout << "P = " << P << std::endl;
  std::cout << "P' = " << P.derivative() << std::endl;
  std::cout << "I = " << P.integral(42.0) << std::endl;

  //std::array<double, 5> aaa{{1.1, 2.2, 3.3, 4.4, 5.5}};
  //std::cout << "aaa = " << std::polynomial_eval(aaa, 3.13149) << std::endl;
}
int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"

  //  simpleControl simple(mesh);

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< "\nCalculating scalar transport\n" << endl;

    //    #include "CourantNo.H"


    //vector lambda(0,0,0); //createfields
    vectorField lambda(1, vector(0,0,0));

    //Info<< "lambda " << lambda << endl;

    scalar theta = 0.6; //0.6;










    //label patchID_to = mesh.boundaryMesh().findPatchID("to");
    //const fvPatchVectorField fvp = U.boundaryField()[patchID_to];



//fileName fvp(runTime.path()/runTime.timeName());
//OFstream os(fvp);


    //while (simple.loop())
    while (runTime.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

	#       include "readSIMPLEControls.H"



         

    //modify processorBC
    //identify patchID
    label patchID_from = mesh.boundaryMesh().findPatchID("from");
    label patchID_to = mesh.boundaryMesh().findPatchID("to");

    


//declaring Field<vector> given size
vectorField u1(1);

//surfaceVectorField second_exchange(vector(0,0,0));
//fvPatchField<vector> second_exchange = U.boundaryField()[patchID_to];
vectorField u2(1);




if (Pstream::myProcNo() == 0) {

    
   

    //receive first_exchange from processor 1    
    IPstream::read(Pstream::blocking, 1,
         reinterpret_cast<char*>(u2.begin()), 
         u2.byteSize());


    //updating velocity at processor patch
    fixedValueFvPatchVectorField& procVel = 
      refCast<fixedValueFvPatchVectorField>(U.boundaryField()[patchID_from]);


     u1 = -(U.boundaryField()[patchID_from]).snGrad();

     OPstream::write(Pstream::nonBlocking, 1,
         reinterpret_cast<char*>(u1.begin()), 
         u1.byteSize());

    
      
      lambda = (theta * u2 ) +
                  (1.0-theta)*lambda;

          
      
        Pout<< "grad(u2): " << u1 << endl;


      forAll(procVel, i)
          {
            procVel[i] = lambda[i];
          }

          //
         

    
}
else if (Pstream::myProcNo() == 1) {
Exemple #5
0
	void testParse1() {

		// Test some valid constructions
		vmime::utility::url u1("", "");

		VASSERT_EQ("1.1", true, parseHelper(u1, "protocol://*****:*****@host:12345/path/"));
		VASSERT_EQ("1.2", "protocol", u1.getProtocol());
		VASSERT_EQ("1.3", "user", u1.getUsername());
		VASSERT_EQ("1.4", "password", u1.getPassword());
		VASSERT_EQ("1.5", "host", u1.getHost());
		VASSERT_EQ("1.6", 12345, u1.getPort());
		VASSERT_EQ("1.7", "/path/", u1.getPath());

		vmime::utility::url u2("", "");

		VASSERT_EQ("2.1", true, parseHelper(u2, "protocol://user@host:12345/path/"));
		VASSERT_EQ("2.2", "protocol", u2.getProtocol());
		VASSERT_EQ("2.3", "user", u2.getUsername());
		VASSERT_EQ("2.4", "", u2.getPassword());
		VASSERT_EQ("2.5", "host", u2.getHost());
		VASSERT_EQ("2.6", 12345, u2.getPort());
		VASSERT_EQ("2.7", "/path/", u2.getPath());

		vmime::utility::url u3("", "");

		VASSERT_EQ("3.1", true, parseHelper(u3, "protocol://host:12345/path/"));
		VASSERT_EQ("3.2", "protocol", u3.getProtocol());
		VASSERT_EQ("3.3", "", u3.getUsername());
		VASSERT_EQ("3.4", "", u3.getPassword());
		VASSERT_EQ("3.5", "host", u3.getHost());
		VASSERT_EQ("3.6", 12345, u3.getPort());
		VASSERT_EQ("3.7", "/path/", u3.getPath());

		vmime::utility::url u4("", "");

		VASSERT_EQ("4.1", true, parseHelper(u4, "protocol://host/path/"));
		VASSERT_EQ("4.2", "protocol", u4.getProtocol());
		VASSERT_EQ("4.3", "", u4.getUsername());
		VASSERT_EQ("4.4", "", u4.getPassword());
		VASSERT_EQ("4.5", "host", u4.getHost());
		VASSERT_EQ("4.6", vmime::utility::url::UNSPECIFIED_PORT, u4.getPort());
		VASSERT_EQ("4.7", "/path/", u4.getPath());

		vmime::utility::url u5("", "");

		VASSERT_EQ("5.1", true, parseHelper(u5, "protocol://host/"));
		VASSERT_EQ("5.2", "protocol", u5.getProtocol());
		VASSERT_EQ("5.3", "", u5.getUsername());
		VASSERT_EQ("5.4", "", u5.getPassword());
		VASSERT_EQ("5.5", "host", u5.getHost());
		VASSERT_EQ("5.6", vmime::utility::url::UNSPECIFIED_PORT, u4.getPort());
		VASSERT_EQ("5.7", "", u5.getPath());

		vmime::utility::url u6("", "");

		VASSERT_EQ("6.1", true, parseHelper(u4, "protocol://host/path/file"));
		VASSERT_EQ("6.2", "protocol", u4.getProtocol());
		VASSERT_EQ("6.3", "", u4.getUsername());
		VASSERT_EQ("6.4", "", u4.getPassword());
		VASSERT_EQ("6.5", "host", u4.getHost());
		VASSERT_EQ("6.6", vmime::utility::url::UNSPECIFIED_PORT, u4.getPort());
		VASSERT_EQ("6.7", "/path/file", u4.getPath());
	}
Exemple #6
0
int compare( const void *arg1, const void *arg2 )
{
	try {

		const I_MapItem *i1 = *reinterpret_cast<I_MapItem**>(const_cast<void*>(arg1));
		const I_MapItem *i2 = *reinterpret_cast<I_MapItem**>(const_cast<void*>(arg2));

		C_TextPtr text1(const_cast<I_MapItem*>(i1));
		C_TextPtr text2(const_cast<I_MapItem*>(i2));

		if (text1 && !text2) {
			return 1;
		}
		else if (text2 && !text1) {
			return -1;
		}

		C_PicturePtr pic1(const_cast<I_MapItem*>(i1));
		C_PicturePtr pic2(const_cast<I_MapItem*>(i2));

		if (pic1 && !pic2) {
			return 1;
		}
		else if (pic2 && !pic1) {
			return -1;
		}

		C_PositionPtr p1(const_cast<I_MapItem*>(i1));
		C_PositionPtr p2(const_cast<I_MapItem*>(i2));

		if (p1 && p2) {

			C_Area area1(p1.GetPoints());
			C_Area area2(p2.GetPoints());

			int n = 0;
			int cnt1 = area1.GetLength();
			int cnt2 = area2.GetLength();

			if (0 == cnt1) {
				return -1;
			}

			if (0 == cnt2) {
				return 1;
			}

			POINT3D *ptr1 = area1[cnt1 - 1];
			POINT3D *ptr2 = area2[cnt2 - 1];

			if (ptr1->x < 0 && ptr2->x > 0) {
				n = -1;
			}
			else if (ptr1->x > 0 && ptr2->x < 0) {
				n = 1;
			}
			else if (ptr1->y < ptr2->y) {
				n = -1;
			}
			else if (ptr1->y > ptr2->y) {
				n = 1;
			}

			if (0 == n) {

				if (cnt1 < cnt2) {
					n = -1;
				}
				else if (cnt1 > cnt2) {
					n = 1;
				}
			}

			if (0 != n) {
				return n;
			}
		}

		C_UniquePtr u1(const_cast<I_MapItem*>(i1));
		C_UniquePtr u2(const_cast<I_MapItem*>(i2));

		if (!u1 && !u2) {
			return 0;
		}
		else if (!u1) {
			return -1;
		}
		else if (!u2) {
			return 1;
		}
		else {

			BSTR bs1 = NULL;
			BSTR bs2 = NULL;

			u1->get_UID(&bs1);
			u2->get_UID(&bs2);

			int n = ::wcscmp(bs1, bs2);

			String::FreeBSTR(&bs1);
			String::FreeBSTR(&bs2);

			return n;
		}
	}
	catch (C_STLNonStackException const &exception) {
		exception.Log(_T("Exception in Items.cpp (compare)"));
	}

	return 0;
}
Exemple #7
0
void test()
{
    //tests
    DRMatrix m1(DRMatrix::identity());
    float mat[] = {1.0f, 0.0f, 0.0f, 0.0f,
                   0.0f, 1.0f, 0.0f, 0.0f,
                   0.0f, 0.0f, 1.0f, 0.0f,
                   0.0f, 0.0f, 0.0f, 1.0f};
    if(memcmp(m1, mat, sizeof(float)*16) != 0)
        LOG_WARNING("matrix identity isn't valid");
    DRMatrix m2 = m1.rotationX(30.0f);
    DRMatrix m3 = DRMatrix::axis(DRVector3(1.0f, 0.0f, 0.0f),
                                 DRVector3(0.0f, 1.0f, 0.0f),
                                 DRVector3(0.0f, 0.0f, 1.0));
    if(memcmp(m1, m3, sizeof(float)*16) != 0)
        LOG_WARNING("matrix axis isn't valid");
    
    DREngineLog.writeMatrixToLog(m1);
    DREngineLog.writeMatrixToLog(m2);
    DREngineLog.writeMatrixToLog(m3);
    
    DRVector3 rot1(1.0f, 0.0f, 0.0f);
    m2 = DRMatrix::rotationY(90.0f);
    rot1 = rot1.transformCoords(m2);
    DREngineLog.writeVector3ToLog(rot1, "1/0/0 90 Grad um y-Achse rotiert");
    rot1 = rot1.transformCoords(m2.invert());
    DREngineLog.writeVector3ToLog(rot1, "zurueckrotiert, 1/0/0 erwartet!");
    
    DREngineLog.writeToLog("RekursionTest: %d", rekursionTest(0));
    
    
    //Speicher test
/*  LOG_INFO("Speichertest");
    std::list<void*> pointer;
    void* t = NULL;
    u32 count = 0;
    do
    {
        t = malloc(16384);
        if(t) pointer.push_back(t);
        count++;
        if(count > 192073)
            break;
    } while(t);
    
    DRLog.writeToLog("count: %d, %u kByte wurden reserviert!", count, count*16384/1024);
    
    for(std::list<void*>::iterator it = pointer.begin(); it != pointer.end(); it++)
        free(*it);
    pointer.clear();
   //* */
    
    // Unit test
    printf("\n");
    Unit parsec(1.0, PARSEC);
    Unit lj = parsec.convertTo(LIGHTYEAR);
    DREngineLog.writeToLog("%s -> %s", parsec.print().data(), lj.print().data());    
    lj = Unit(1.0, LIGHTYEAR);
    parsec = lj.convertTo(PARSEC);
    DREngineLog.writeToLog("%s -> %s", lj.print().data(), parsec.print().data());    
    Unit ae = lj.convertTo(AE);
    DREngineLog.writeToLog("%s -> %s", lj.print().data(), ae.print().data());    
    ae = parsec.convertTo(AE);
    DREngineLog.writeToLog("%s -> %s", parsec.print().data(), ae.print().data());    
    parsec = ae.convertTo(PARSEC);
    DREngineLog.writeToLog("%s -> %s", ae.print().data(), parsec.print().data());    
    Unit m = parsec.convertTo(M);
    DREngineLog.writeToLog("%s -> %s", parsec.print().data(), m.print().data());    
    Unit kpc(1.0, KILOPARSEC);
    m = kpc.convertTo(M);
    DREngineLog.writeToLog("%s -> %s", kpc.print().data(), m.print().data());    
    m = Unit(1.0, M);
    kpc = m.convertTo(KILOPARSEC);
    DREngineLog.writeToLog("%s -> %s", m.print().data(), kpc.print().data());    
    printf("\n");
    
    Unit aes(0.005, AE);
    DREngineLog.writeToLog("%s -> %s", aes.print().data(), aes.convertTo(KM).print().data());
    
    //Vector Unit Test
    Vector3Unit u1(100, 200, 70, M), u2(1, 0, 0, KILOPARSEC), u3(100, 20, 17, LIGHTYEAR);
    u1.print("u1");
    u2.print("u2");
    u3.print("u3");
    
    u1 *= Unit(20, KM);
    u1.print("u1* 20 km");
    
    Vector3Unit(u1 + u2).print("u1+u2");
    Vector3Unit(u2+u3).print("u2+u3");
    Vector3Unit(u1*Unit(1, LIGHTYEAR)).print("u1*1 Lichtjahr");
    
    DRVector3 v(1.0f, 7.0f, 2.0f);
    DREngineLog.writeVector3ToLog(v, "init");
    v = v.normalize();
    DREngineLog.writeVector3ToLog(v, "normalized");
    v *= 7.0f;
    DREngineLog.writeVector3ToLog(v, "multiplikator");
    
    // ----------------------------------  ReferenzHolder Test --------------------------------
    
    DREngineLog.writeToLog("DRIndexReferenzHolder test");
    DRIndexReferenzHolder referenzHolder(10);
    uint tests[10];
    tests[0] = referenzHolder.getFree();
    referenzHolder.add(tests[0]);
    tests[1] = referenzHolder.getFree();
    
    DREngineLog.writeToLog("index1 (0): %d, index2 (1): %d", tests[0], tests[1]);
    referenzHolder.remove(tests[0]);
    tests[2] = referenzHolder.getFree();
    referenzHolder.remove(tests[1]);
    tests[3] = referenzHolder.getFree();
    DREngineLog.writeToLog("index3 (2): %d, index4 (1): %d", tests[2], tests[3]);
    for(int i = 0; i < 5; i++)
        tests[4+i] = referenzHolder.getFree();
    referenzHolder.remove(tests[7]);
    tests[9] = referenzHolder.getFree();
    DREngineLog.writeToLog("index10: (6): %d", tests[9]);
    
    DRTextureManager::Instance().test();
    
    // Random Test
    
}
Exemple #8
0
// ------------------
BigInt::Vin BigInt::Vin::operator+ (const BigInt::Vin& i_arg) const
{
    BigInt::Vin ret;
    const std::size_t maxSize (std::max (m_units.size (), i_arg.m_units.size ()));

    std::vector<BigInt::Ulong> u1 (m_units);
    std::vector<BigInt::Ulong> u2 (i_arg.m_units);

    
    // ---------------------
    try
    {
        u1.reserve(maxSize);
    }
    catch(...)
    {
        std::ostringstream ossThrow;
        std::ostringstream ossErr;
        ossErr  << ""
                << "Unable to to do u1.reserve("
                << maxSize
                << ")"
                << std::endl;

        ERR_MSG (std::cerr, ossErr.str());
        ERR_MSG (ossThrow, ossErr.str());
        throw std::runtime_error (ossThrow.str().c_str());
    }

    // ---------------------
    try
    {
        u2.reserve(maxSize);
    }
    catch(...)
    {
        std::ostringstream ossThrow;
        std::ostringstream ossErr;
        ossErr  << ""
                << "Unable to to do u2.reserve("
                << maxSize
                << ")"
                << std::endl;

        ERR_MSG (std::cerr, ossErr.str());
        ERR_MSG (ossThrow, ossErr.str());
        throw std::runtime_error (ossThrow.str().c_str());
    }

    
    // ---------------------
    try
    {
        ret.m_units.reserve(maxSize + 1);
    }
    catch(...)
    {
        std::ostringstream ossThrow;
        std::ostringstream ossErr;
        ossErr  << ""
                << "Unable to to do ret.m_units.reserve("
                << (maxSize + 1)
                << ")"
                << std::endl;

        ERR_MSG (std::cerr, ossErr.str());
        ERR_MSG (ossThrow, ossErr.str());
        throw std::runtime_error (ossThrow.str().c_str());
    }

    // ---------------------
    try
    {
        u1.resize(maxSize);
    }
    catch(...)
    {
        std::ostringstream ossThrow;
        std::ostringstream ossErr;
        ossErr  << ""
                << "Unable to to do u1.resize("
                << maxSize
                << ")"
                << std::endl;

        ERR_MSG (std::cerr, ossErr.str());
        ERR_MSG (ossThrow, ossErr.str());
        throw std::runtime_error (ossThrow.str().c_str());
    }

    // ---------------------
    try
    {
        u2.resize(maxSize);
    }
    catch(...)
    {
        std::ostringstream ossThrow;
        std::ostringstream ossErr;
        ossErr  << ""
                << "Unable to to do u2.resize("
                << maxSize
                << ")"
                << std::endl;

        ERR_MSG (std::cerr, ossErr.str());
        ERR_MSG (ossThrow, ossErr.str());
        throw std::runtime_error (ossThrow.str().c_str());
    }

    // ---------------------
    try
    {
        ret.m_units.resize(maxSize);
    }
    catch(...)
    {
        std::ostringstream ossThrow;
        std::ostringstream ossErr;
        ossErr  << ""
                << "Unable to to do ret.m_units.resize("
                << maxSize
                << ")"
                << std::endl;

        ERR_MSG (std::cerr, ossErr.str());
        ERR_MSG (ossThrow, ossErr.str());
        throw std::runtime_error (ossThrow.str().c_str());
    }



    s_carry = 0;
    std::transform (&u1[0], &u1[0] + maxSize, &u2[0], &ret.m_units[0], BigInt::Vin::addUnits);
  
    if (s_carry) 
    {
        try
        {
            ret.m_units.push_back (s_carry);
        }
        catch(...)
        {
            std::ostringstream ossThrow;
            std::ostringstream ossErr;
            ossErr  << ""
                    << "Unable to to do ret.m_units.push_back()"
                    << "; "
                    << "ret.m_units.size() = "
                    << ret.m_units.size()
                    << std::endl;

            ERR_MSG (std::cerr, ossErr.str());
            ERR_MSG (ossThrow, ossErr.str());
            throw std::runtime_error (ossThrow.str().c_str());
        }

    }

    return ret;

}
// semi-lagrangian solver
void DogSolverCart2::DogSolveUser(double tstart, double tend)
{

    // this accomodates the maximum number of stages allowed for the
    // split method ... and is a work in progress ...
    const int MAX_STAGES = 13;

    const edge_data& EdgeData = Legendre2d::instance().get_edgeData();
    dTensorBC3& smax = fetch_smax();
    DogStateCart2* dogStateCart2 = &fetch_state();

    dTensorBC4& qnew = fetch_state().fetch_q();
    dTensorBC4& qold = fetch_state_old().fetch_q();
    dTensorBC4& aux  = fetch_state().fetch_aux();

    const int nv = dogParams.get_nv();
    const double* cflv = dogParams.get_cflv();
    // --------------------------------------------------------------
    // define local variables
    int m_accept;
    const int mx   = qnew.getsize(1);
    const int my   = qnew.getsize(2);
    const int maux = aux.getsize(3);
    const int meqn = qnew.getsize(3);
    const int kmax = qnew.getsize(4);
    const int mbc  = qnew.getmbc();

    const int ndims = 2;

    int n_step = 0;
    double t = tstart;
    double tn = t;
    double told = 0.0;
    double dt = get_dt();
    const double CFL_max = cflv[1];
    const double CFL_target = cflv[2];
    double cfl = 0.0;
    double dtmin = dt;
    double dtmax = dt;

    dTensorBC4   qstar(mx,my,meqn,kmax,mbc);    //temporary place holder
    dTensorBC4 aux_old(mx,my,maux,kmax,mbc);

    //////////////////////////////////////////////////////////////////////////
    // Setup for manipulating velocities.  Store 2 arrays, 1 for each velocity
    //////////////////////////////////////////////////////////////////////////
    // array for storing advection speeds in each cell
    const int mpoints   = int((1+4*kmax-int(sqrt(1+8*kmax)))/2);
    const int mpoints1d = int(sqrt(mpoints));
    const int morder = mpoints1d;
    dTensorBC2 u1(my, mpoints1d,  mbc, ndims-1);    // speed, u(y) (ndims == 1 )
    dTensorBC2 u2(mx, mpoints1d,  mbc, ndims-1);    // speed, v(x) (ndims == 1 )

    ////////Set up any extra state variables associated with this problem /////
    SL_state sl_state;
    sl_state.split_time = new dTensor2(MAX_STAGES, 2);
    sl_state.aux1d      = new dTensorBC4( Max(mx,my), 2, 4, mpoints1d, mbc, 1);
    sl_state.node1d     = new dTensor2(mx+1,1);
    for( int i=1; i <=(mx+1); i++)
    { sl_state.node1d->set(i, 1, dogParamsCart2.get_xl(i) ); }

    sl_state.qold = &qold;
    sl_state.qnew = &qnew;

    const double dx = dogParamsCart2.get_dx();
    const double dy = dogParamsCart2.get_dy();

    // sample grid points (gauss points)
    dTensor2* spts = new dTensor2(mpoints, 2);

    //legendre polys evaluated at spts
    dTensor2 phi(mpoints, kmax);
    dTensor1 x1d(mpoints1d);
    dTensor1 wgt(mpoints1d);

    void setGaussPoints1d(dTensor1& w1d, dTensor1& x1d);
    setGaussPoints1d(wgt, x1d);

    // Tensor product Gaussian Quadrature
    //  See note at top of code in how mpoints are arranged here...
    int k=0;
    for (int m1=1; m1<=(mpoints1d); m1++)
    for (int m2=1; m2<=(mpoints1d); m2++)
    {

        k = k+1;

        //save gauss quad grid point location on interval [-1,1]^2
        spts->set(k,2, x1d.get(m1) );
        spts->set(k,1, x1d.get(m2) );
    }

    //evaluate the legendre polynomials at sample points
    for(int m=1; m <= mpoints; m++)
    {

        double xi, xi2,xi3,xi4, eta, eta2,eta3,eta4;

        //find xi and eta (point to be evaluated)
        xi = spts->get(m,1);
        eta = spts->get(m,2);
        xi2 = xi*xi;
        xi3 = xi*xi2;
        xi4 = xi*xi3;
        eta2 = eta*eta;
        eta3 = eta*eta2;
        eta4 = eta*eta3;

        // Legendre basis functions evaluated at (xi,eta) in the
        // interval [-1,1]x[-1,1].
        switch( mpoints1d )
        {
            case 5:  // fifth order
                phi.set( m,15, 105.0/8.0*eta4 - 45.0/4.0*eta2 + 9.0/8.0 );
                phi.set( m,14, 105.0/8.0*xi4  - 45.0/4.0*xi2  + 9.0/8.0 );
                phi.set( m,13, 5.0/4.0*(3.0*xi2 - 1.0)*(3.0*eta2 - 1.0) );
                phi.set( m,12, sq3*sq7*(2.5*eta3 - 1.5*eta)*xi );
                phi.set( m,11, sq3*sq7*(2.5*xi3 - 1.5*xi)*eta );

            case 4:  // fourth order
                phi.set( m,10, sq7*(2.5*eta3 - 1.5*eta) );
                phi.set( m,9,  sq7*(2.5*xi3 - 1.5*xi) );
                phi.set( m,8,  sq3*sq5*xi*(1.5*eta2 - 0.5) );
                phi.set( m,7,  sq3*sq5*eta*(1.5*xi2 - 0.5) );

            case 3:  // third order
                phi.set( m,6,  sq5*(1.5*eta2 - 0.5) );
                phi.set( m,5,  sq5*(1.5*xi2 - 0.5) );
                phi.set( m,4,  3.0*xi*eta );            

            case 2:  // second order            
                phi.set( m,3, sq3*eta );
                phi.set( m,2, sq3*xi  );

            case 1:  // first order
                phi.set( m,1, 1.0 );
        }

    }//end of evaluating legendre polys at sample grid points indexed by spts
    delete spts;
    ///////////////////////////////////////////////////////////////////////////

    double time1, time2;   // running time values
    time1 = GetTime();     //running time for this program (can remove this..)

    // fourth order splitting coefficients
    dTensor1* dt_stages;
    if( dogParams.get_time_order() >= 2 )
    {
        dt_stages = new dTensor1(MAX_STAGES);
        sl_state.dt_stages = dt_stages;
    }

    ///////////////////////////////////////////////////////////////////////////
    // Main Time Stepping Loop
    ///////////////////////////////////////////////////////////////////////////
    while (t<tend)
    {
        // initialize time step
        m_accept = 0;      
        n_step = n_step + 1;

        // check if max number of time steps exceeded
        if (n_step>nv)
        {
            cout << " Error in DogSolveAdvec.cpp: "<< 
                " Exceeded allowed # of time steps " << endl;
            cout << "    n_step = " << n_step << endl;
            cout << "        nv = " << nv << endl;
            cout << endl;
            exit(1);
        }

        // copy qnew and aux in case we reject the step
        CopyQ(qnew,qold);
        CopyQ(qnew,qstar);
        CopyQ(aux,aux_old);

        // keep trying until we get a dt that does not violate CFL condition
        while (m_accept==0)
        {
            // set current time          
            told = t;
            tn = t;
            if (told+dt > tend) { dt = tend - told; }
            t = told + dt;

            // Set initial maximum wave speed to zero (this will be saved in
            // SetAdvecSpeed)
            for (int i=(1-mbc); i<=(mx+mbc); i++)
                for (int j=(1-mbc); j<=(my+mbc); j++)
                {
                    smax.set(i,j,1, 0.0e0 );
                    smax.set(i,j,2, 0.0e0 );
                }

            sl_state.dt = dt;
            sl_state.t  = sl_state.tn = tn;

            void InitSLState( const dTensorBC4& q, const dTensorBC4& aux, 
                    SL_state& sl_state );
            InitSLState( qnew, aux, sl_state );

            CopyQ(qold, qstar);
            /////////////////////////////////////
            // Perform a full time step
            /////////////////////////////////////
            switch ( dogParams.get_time_order() )
            {

                case 0:  // used for testing - dont' take any time steps!
                    BeforeStep (dt, aux, qnew, *this);
                    AfterStep  (dt, aux, qnew, *this);
                    perror( "    case 0: Not taking a time step! " );
                    break;

                case 1: // 1st order in time, no corrections

                    sl_state.t     = tn;

                    BeforeStep(dt, aux, qstar, *this);

                    SetAdvecSpeed(phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    SetAdvecSpeed(phi, qstar, aux, smax, 2, u1, u2, sl_state);

                    StepAdvec(dt, qold, qstar, aux, u1, u2, 1, sl_state); 
                    StepAdvec(dt, qstar, qnew, aux, u1, u2, 2, sl_state);

                    break;

                case 2:  // 2nd order in time (strang split method)

                    SetSplitTime(dt, 2, tn, sl_state, dt_stages );
                    sl_state.stage_num = 1;
                    sl_state.t = tn;
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);  
                    StepAdvec(0.5*dt, qstar, qnew, aux, u1, u2, 1, sl_state ); 

                    // Poisson solve called in BeforeStep for VP system  
                    //                  BeforeStep(dt, aux, qstar );
                    sl_state.stage_num = 2;
                    BeforeStep(dt, aux, qnew, *this);

                    sl_state.t  = tn;
                    SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    StepAdvec(dt, qnew, qstar, aux, u1, u2, 2, sl_state ); 

                    sl_state.stage_num = 3;
                    sl_state.t = tn + 0.5*dt;
                    StepAdvec(0.5*dt, qstar, qnew, aux, u1, u2, 1, sl_state);

                    break;

                case 4: // 4th order method (Yoshida Splitting)		  

                    // initial setup ... Save all appropriate times into SL_state
                    SetSplitTime(dt, 4, tn, sl_state, dt_stages );

                    ///////////////////////////////////////////////////////////
                    ///// There are 7 stages for Yoshida Splitting        /////
                    ///////////////////////////////////////////////////////////


                    ///////// stage 1: A //////////////////////////////////////
                    sl_state.stage_num = 1;
                    sl_state.t         = sl_state.split_time->get(1,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(1), qstar, qnew,  aux, u1, u2,  1, sl_state ); 

                    ///////// stage 2: B //////////////////////////////////////
                    sl_state.stage_num = 2;
                    sl_state.t         = sl_state.split_time->get(2,2);
                    SetAdvecSpeed( phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(2), qnew, qstar,  aux, u1, u2, 2, sl_state); 

                    ///////// stage 3: A //////////////////////////////////////
                    sl_state.stage_num = 3;
                    sl_state.t         = sl_state.split_time->get(3,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(3), qstar , qnew, aux, u1, u2, 1, sl_state);

                    ///////// stage 4: B //////////////////////////////////////
                    sl_state.stage_num = 4;
                    sl_state.t         = sl_state.split_time->get(4,2);
                    SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(4), qnew, qstar,  aux, u1, u2, 2, sl_state); 

                    ///////// stage 5: A //////////////////////////////////////
                    sl_state.stage_num = 5;
                    sl_state.t         = sl_state.split_time->get(5,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(5), qstar, qnew, aux, u1, u2, 1, sl_state);

                    ///////// stage 6: B //////////////////////////////////////
                    sl_state.stage_num = 6;
                    sl_state.t         = sl_state.split_time->get(6,2);
                    SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(6), qnew, qstar, aux, u1, u2, 2, sl_state); 

                    ///////// stage 7: A //////////////////////////////////////
                    sl_state.stage_num = 7;
                    sl_state.t         = sl_state.split_time->get(7,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(7), qstar , qnew, aux, u1, u2, 1, sl_state);

                    //////////////// --- Experimental New Time Stepping --- ///////////////////

                    //                  ///////// stage 1: A //////////////////////////////////////
                    //                  sl_state.stage_num = 1;
                    //                  sl_state.t         = sl_state.split_time->get(1,1);
                    //                  SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    //                  StepAdvec(sl_state.dt_stages->get(1), qstar, qnew,  aux, u1, u2,  1, sl_state ); 

                    //                  ///////// stage 2: B //////////////////////////////////////
                    //                  sl_state.stage_num = 2;
                    //                  sl_state.t         = sl_state.split_time->get(2,2);
                    //                  SetAdvecSpeed( phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    //                  StepAdvec(sl_state.dt_stages->get(2), qnew, qstar,  aux, u1, u2, 2, sl_state); 

                    //                  ///////// stage 3: A //////////////////////////////////////
                    //                  sl_state.stage_num = 3;
                    //                  sl_state.t         = sl_state.split_time->get(3,1);
                    //                  StepAdvec(sl_state.dt_stages->get(3), qstar , qnew, aux, u1, u2, 1, sl_state);

                    //                  ///////// stage 4: B //////////////////////////////////////
                    //                  sl_state.stage_num = 4;
                    //                  sl_state.t         = sl_state.split_time->get(4,2);
                    //                  SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    //                  StepAdvec(sl_state.dt_stages->get(4), qnew, qstar,  aux, u1, u2, 2, sl_state); 

                    //                  ///////// stage 5: A //////////////////////////////////////
                    //                  sl_state.stage_num = 5;
                    //                  sl_state.t         = sl_state.split_time->get(5,1);
                    //                  StepAdvec(sl_state.dt_stages->get(5), qstar, qnew, aux, u1, u2, 1, sl_state);

                    //                  ///////// stage 6: B //////////////////////////////////////
                    //                  sl_state.stage_num = 6;
                    //                  sl_state.t         = sl_state.split_time->get(6,2);
                    //                  SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    //                  StepAdvec(sl_state.dt_stages->get(6), qnew, qstar, aux, u1, u2, 2, sl_state); 

                    //                  ///////// stage 7: A //////////////////////////////////////
                    //                  sl_state.stage_num = 7;
                    //                  sl_state.t         = sl_state.split_time->get(7,1);
                    //                  StepAdvec(sl_state.dt_stages->get(7), qstar , qnew, aux, u1, u2, 1, sl_state);

                    //                  ///////// stage 8: B //////////////////////////////////////
                    //                  sl_state.stage_num = 8;
                    //                  sl_state.t         = sl_state.split_time->get(8,2);
                    //                  SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    //                  StepAdvec(sl_state.dt_stages->get(8), qnew, qstar, aux, u1, u2, 2, sl_state); 

                    //                  ///////// stage 9: A //////////////////////////////////////
                    //                  sl_state.stage_num = 9;
                    //                  sl_state.t         = sl_state.split_time->get(9,1);
                    //                  StepAdvec(sl_state.dt_stages->get(9), qstar , qnew, aux, u1, u2, 1, sl_state);

                    //                  ///////// stage 10: B //////////////////////////////////////
                    //                  sl_state.stage_num = 10;
                    //                  sl_state.t         = sl_state.split_time->get(10,2);
                    //                  SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    //                  StepAdvec(sl_state.dt_stages->get(10), qnew, qstar, aux, u1, u2, 2, sl_state); 

                    //                  ///////// stage 11: A //////////////////////////////////////
                    //                  sl_state.stage_num = 11;
                    //                  sl_state.t         = sl_state.split_time->get(11,1);
                    //                  StepAdvec(sl_state.dt_stages->get(11), qstar , qnew, aux, u1, u2, 1, sl_state);

                    //                  ///////// stage 12: B //////////////////////////////////////
                    //                  sl_state.stage_num = 12;
                    //                  sl_state.t         = sl_state.split_time->get(12,2);
                    //                  SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    //                  StepAdvec(sl_state.dt_stages->get(12), qnew, qstar, aux, u1, u2, 2, sl_state); 

                    //                  ///////// stage 13: A //////////////////////////////////////
                    //                  sl_state.stage_num = 13;
                    //                  sl_state.t         = sl_state.split_time->get(13,1);
                    //                  StepAdvec(sl_state.dt_stages->get(13), qstar , qnew, aux, u1, u2, 1, sl_state);

                    //////////////// --- Experimental New Time Stepping --- ///////////////////

                    break;
					
				case 6: // 6th order method (SRKN Splitting)		  
				
					// Added by Pierson Guthrey 5/22/2015
                    // initial setup ... Save all appropriate times into SL_state
                    SetSplitTime(dt, 6, tn, sl_state, dt_stages );
					
                    ///////// stage 1: A //////////////////////////////////////
                    sl_state.stage_num = 1;
                    sl_state.t         = sl_state.split_time->get(1,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(1), qstar, qnew,  aux, u1, u2,  1, sl_state ); 

                    ///////// stage 2: B //////////////////////////////////////
                    sl_state.stage_num = 2;
                    sl_state.t         = sl_state.split_time->get(2,2);
                    SetAdvecSpeed( phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(2), qnew, qstar,  aux, u1, u2, 2, sl_state); 

                    ///////// stage 3: A //////////////////////////////////////
                    sl_state.stage_num = 3;
                    sl_state.t         = sl_state.split_time->get(3,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(3), qstar , qnew, aux, u1, u2, 1, sl_state);

                    ///////// stage 4: B //////////////////////////////////////
                    sl_state.stage_num = 4;
                    sl_state.t         = sl_state.split_time->get(4,2);
                    SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(4), qnew, qstar,  aux, u1, u2, 2, sl_state); 
					
                    ///////// stage 5: A //////////////////////////////////////
                    sl_state.stage_num = 5;
                    sl_state.t         = sl_state.split_time->get(5,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(5), qstar, qnew,  aux, u1, u2,  1, sl_state ); 

                    ///////// stage 6: B //////////////////////////////////////
                    sl_state.stage_num = 6;
                    sl_state.t         = sl_state.split_time->get(6,2);
                    SetAdvecSpeed( phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(6), qnew, qstar,  aux, u1, u2, 2, sl_state); 

                    ///////// stage 7: A //////////////////////////////////////
                    sl_state.stage_num = 7;
                    sl_state.t         = sl_state.split_time->get(7,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(7), qstar , qnew, aux, u1, u2, 1, sl_state);

                    ///////// stage 8: B //////////////////////////////////////
                    sl_state.stage_num = 8;
                    sl_state.t         = sl_state.split_time->get(8,2);
                    SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(8), qnew, qstar,  aux, u1, u2, 2, sl_state); 					
										
                    ///////// stage 9: A //////////////////////////////////////
                    sl_state.stage_num = 9;
                    sl_state.t         = sl_state.split_time->get(9,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(9), qstar, qnew,  aux, u1, u2,  1, sl_state ); 

                    ///////// stage 10: B //////////////////////////////////////
                    sl_state.stage_num = 10;
                    sl_state.t         = sl_state.split_time->get(10,2);
                    SetAdvecSpeed( phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(10), qnew, qstar,  aux, u1, u2, 2, sl_state); 

                    ///////// stage 11: A //////////////////////////////////////
                    sl_state.stage_num = 11;
                    sl_state.t         = sl_state.split_time->get(11,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(11), qstar , qnew, aux, u1, u2, 1, sl_state);

                    ///////// stage 12: B //////////////////////////////////////
                    sl_state.stage_num = 12;
                    sl_state.t         = sl_state.split_time->get(12,2);
                    SetAdvecSpeed(phi, qnew, aux, smax, 2, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(12), qnew, qstar,  aux, u1, u2, 2, sl_state); 
					
                    ///////// stage 13: A //////////////////////////////////////
                    sl_state.stage_num = 13;
                    sl_state.t         = sl_state.split_time->get(13,1);
                    SetAdvecSpeed( phi, qstar, aux, smax, 1, u1, u2, sl_state);
                    StepAdvec(sl_state.dt_stages->get(13), qstar , qnew, aux, u1, u2, 1, sl_state);

                default:
                    // still here?  too bad!  Pick a valid time stepping
                    // method
                    fprintf(stderr, 
                            "Bad time stepping method chosen in DogSolveAdvec\n");
                    fprintf(stderr, 
                            "dogParams.get_time_order() = %d\n",
                            dogParams.get_time_order());
                    exit(1);

            }// end of taking a full time step

            // compute cfl number
            cfl = GetCFL(dt);

            // output time step information
            if (dogParams.get_verbosity()>0) 
            {
                cout << setprecision(3);
                cout << "DogSolve2D ... Step" << setw(5) << n_step;
                cout << "   CFL =" << setw(6) << fixed << cfl;
                cout << "   dt =" << setw(11) << scientific << dt;
                cout << "   t =" << setw(11) << scientific << t << endl;
            }

            if (cfl>0.0)
            {   dt = Min(dogParams.get_max_dt(),dt*CFL_target/cfl); }
            else
            { dt = dogParams.get_max_dt(); }

            // see whether to accept or reject this step
            if (cfl<=CFL_max)
            {   // accept 
                m_accept = 1;
                dogStateCart2->set_time(t);
                dogParams.set_time(t); // time hack
            }
            else 
            {   //reject
                t = told;
                if (dogParams.get_verbosity()>0)
                {
                    cout<<"DogSolve2D rejecting step...";
                    cout<<"CFL number too large";
                    cout<<endl;
                    // find index of larger value...
                    int imax = 1; int jmax = 1; int dmax = 1;
                    for( int i = 1; i <= smax.getsize(1); i++ )
                        for( int j = 1; j <= smax.getsize(2); j++ )
                            for( int d = 1; d <= ndims; d++ )
                            {
                                if( smax.get(i,j,d) > smax.get(imax,jmax,dmax) )
                                { imax = i;   jmax = j; dmax = d;}
                            }
                    printf("   imax = %d, jmax = %d, dmax = %d\n", imax, jmax, dmax );
                    printf("   smax(imax,jmax,dmax) = %3.2e\n", smax.get(imax, jmax, dmax ) );

                }

                // copy qold into qnew
                CopyQ(qold,qnew);
                CopyQ(aux_old,aux);
            }
        }

        void AfterFullSLTimeStep( dTensorBC4& aux, dTensorBC4& qnew, double t );
        AfterFullSLTimeStep(aux, qnew, t );

        // apply the limiter - This way global integrals stay positive
        void ApplyPosLimiter(const dTensorBC4& aux, dTensorBC4& q);
        if(dogParams.using_moment_limiter())
        { ApplyPosLimiter(aux, qnew); }

        // compute conservation and print to file
        ConSoln(aux,qnew,t);
    }

    void AfterSLFrame(double dt, dTensorBC4& aux, dTensorBC4& q, DogSolverCart2&
            solver, SL_state sl_state );
    AfterSLFrame(dt, aux, qnew, *this, sl_state );

    // set initial time step for next call to DogSolveAdvec
    set_dt(dt);

    // Clock the running time for this call to DogSolveAdvec
    time2 = GetTime();
    if(dogParams.get_verbosity()>0)
    {
        cout << "         DogSolveAdvec Running Time = " 
            << setw(3) << time2 - time1 << "  seconds" << endl << endl;        
    }

    if( dogParams.get_time_order() >= 2 )
    {
        delete dt_stages;
    }
    delete sl_state.split_time;
    delete sl_state.aux1d;
    delete sl_state.node1d;

}
  // Tests mapping from Stieltjes basis to original is correct
  TEUCHOS_UNIT_TEST( Stokhos_StieltjesPCEBasis, ExpMap ) {
   Stokhos::OrthogPolyApprox<int,double> u2(setup.basis);
   setup.st_1d_basis->transformCoeffsFromStieltjes(setup.u_st.coeff(), 
						   u2.coeff());
   success = Stokhos::comparePCEs(setup.u, "u", u2, "u2", setup.rtol, setup.atol, out);
  }
    void loop()
    {
        size_t iter = 0;
        while( (!Lambda.empty()) && (iter < max_iter) )
        {
            if(verbosity >= 2)
                cout<<"Iteration: "<<iter<<endl;
            else if(verbosity == 1 && (iter%10)==0)
                cout<<"Iteration: "<<iter<<endl;

            Undefined u = Lambda.front();
            Lambda.pop();
            double energy2, m2, b2,min_m, min_b, min_energy;
            double energy3, m3, b3;
            //short_array min_x = minimizer->minimize( u.x_l, u.lambda, min_energy, min_m, min_b, true);

            short_array min_x = minimizer->minimize( u.x_l, u.lambda, min_energy, min_m, min_b, false);

            short_array x2 = minimizer->minimize( u.x_r, u.lambda, energy2, m2, b2, false);
            short_array x3 = minimizer->minimize( u.x_r, u.lambda, energy3, m3, b3, true);
            if(min_energy > energy2 && min_energy > energy3)
                e1++;
            else if( energy2 > energy3 && energy2 > min_energy)
                e2++;
            else if( energy3 > energy2 && energy3 > min_energy)
                e3++;

           
            if( energy2 < min_energy)
            {
                min_m = m2;
                min_b = b2;
                min_energy = energy2;
                min_x = x2;
            }

            if(energy3 < min_energy)
            {
                min_m = m3;
                min_b = b3;
                min_energy = energy3;
                min_x = x3;
            }

            //if( !compare( min_x, u.x_l, u.lambda) && !compare(min_x, u.x_r, u.lambda) )
            {
                LineSegment l( min_m, min_b, lambda_min, lambda_max, false );
                kmc.addLineSegment(l);
                if(verbosity >= 2)
                    cout<<"* Adding line segment: "<<l<<endl;
                int num_intersections = kmc.num_intersections;
                if( num_intersections > 1 && (kmc.intersecting_lambda[0] != kmc.intersecting_lambda[num_intersections -1] ) )
                { // had intersections
                    cout.precision(16);
                    if(verbosity >= 1)
                    {
                        cout<<"\t Had intersections at "<< kmc.intersecting_lambda[0]<<", "<<kmc.intersecting_lambda[num_intersections-1]<<endl; 
                        cout<<"\t\t Energies are: "<< fixed << kmc.intersecting_energies[0]<<", "<<fixed<<kmc.intersecting_energies[num_intersections-1]<<endl;
                    }
                    double lambda_l = kmc.intersecting_lambda[0];
                    double lambda_r = kmc.intersecting_lambda[num_intersections - 1];
                    int index_l = kmc.intersecting_indexes[0];
                    int index_r = kmc.intersecting_indexes[num_intersections - 1];
                    if(index_r - index_l > 1 )
                        labelings.erase( labelings.begin() + index_l + 1, labelings.begin() + index_r);
                    Undefined u1( lambda_l, labelings[index_l], min_x );
                    Undefined u2( lambda_r, labelings[index_r], min_x );
                    Lambda.push(u1);
                    Lambda.push(u2);

                    labelings.insert( labelings.begin() + index_l + 1, min_x);
                    
                }
            }
            //else
            //{
            //}

            iter++;
        }
        if(iter == max_iter)
            cout<<"Maximum number of iterations reached"<<endl;
        cout<<"Done in "<<iter<<" iterations."<<endl;
        cout<<KBCYN<<"[e1, e2, e3] = ["<<e1<<", "<<e2<<", "<<e3<<"]"<<KNRM<<endl;
        if(verbosity >= 1)
            cout<<kmc<<endl;
        if(verbosity >= 2)
        {
            /*cout<<"labelings:"<<endl;
            for(size_t i = 0; i < labelings.size(); i++)
            {
                cout<<labelings[i][0]<<" ";
            }
            cout<<endl;*/
        }
    }
Exemple #12
0
template < > ElementMatrix < double > & ElementMatrix < double >::u2(const MeshEntity & ent){
    uint nVerts = ent.nodeCount();
    if (size() != nVerts) resize(nVerts);
    
    for (uint i = 0; i < nVerts; i ++) idx_[i] = ent.node(i).id();

    switch(ent.rtti()){
    case MESH_BOUNDARY_NODE_RTTI:
        mat_[0][0] = 1.0;
    break;
    case MESH_EDGE_CELL_RTTI:
    case MESH_EDGE_RTTI:
    //{
//         double J = ent.shape().jacobianDeterminant();
//         if (J < 0) {
//             std::cerr << WHERE_AM_I << "JacobianDeterminant < 0 (" << J << ")" << std::endl;
//             std::cerr << ent.shape() << std::endl;
//             J = std::fabs(J);
//         }
//         mat_[0][0] = J / 3.0;
//         mat_[1][0] = J / 6.0;
//         mat_[0][1] = J / 6.0;
//         mat_[1][1] = J / 3.0;
//         std::cout << "2 " << *this << std::endl;
/*}
    break;*/
        u2(ent, IntegrationRules::instance().edgWeights(2), IntegrationRules::instance().edgAbscissa(2), false);
        break;
    case MESH_EDGE3_CELL_RTTI:
    case MESH_EDGE3_RTTI:
    //{
//         double J = ent.shape().jacobianDeterminant();
//         if (J < 0) {
//             std::cerr << WHERE_AM_I << "JacobianDeterminant < 0 (" << J << ")" << std::endl;
//             std::cerr << ent.shape() << std::endl;
//             J = std::fabs(J);
//         }
//         mat_[0][0] =   J / 30.0 * 4.0;
//         mat_[1][0] = - J / 30.0;
//         mat_[2][0] =   J / 15.0;
//         mat_[0][1] = - J / 30.0;
//         mat_[1][1] =   J / 30.0 * 4.0;
//         mat_[2][1] =   J / 15.0;
//         mat_[0][2] =   J / 15.0;
//         mat_[1][2] =   J / 15.0;
//         mat_[2][2] =   J / 30.0 * 16.0;
//          std::cout << "2 " << *this << std::endl;
    //} break;
        u2(ent, IntegrationRules::instance().edgWeights(3), IntegrationRules::instance().edgAbscissa(3), false);
        break;
    case MESH_TRIANGLE_RTTI:
    case MESH_TRIANGLEFACE_RTTI:
    //{
//         double J = ent.shape().jacobianDeterminant();
//         if (J < 0) {
//             std::cerr << WHERE_AM_I << "JacobianDeterminant < 0 (" << J << ")" << std::endl;
//             std::cerr << ent.shape() << std::endl;
//             J = std::fabs(J);
//         }
//         double Jl = J / 24.0;
//         mat_[0][0] = Jl * 2.0;
//         mat_[1][0] = Jl;
//         mat_[2][0] = Jl;
//         mat_[0][1] = Jl;
//         mat_[1][1] = Jl * 2.0;
//         mat_[2][1] = Jl;
//         mat_[0][2] = Jl;
//         mat_[1][2] = Jl;
//         mat_[2][2] = Jl * 2.0;
//         std::cout << "2 " << *this << std::endl;
//}break;
        u2(ent, IntegrationRules::instance().triWeights(2), IntegrationRules::instance().triAbscissa(2), false);
        break;
    case MESH_QUADRANGLE_RTTI:
    case MESH_QUADRANGLEFACE_RTTI:
        u2(ent, IntegrationRules::instance().quaWeights(2), IntegrationRules::instance().quaAbscissa(2), false);
        break;
    case MESH_QUADRANGLE8_RTTI:
    case MESH_QUADRANGLEFACE8_RTTI:
        u2(ent, IntegrationRules::instance().quaWeights(3), IntegrationRules::instance().quaAbscissa(3), false);
        break;
    case MESH_TRIANGLE6_RTTI:
    case MESH_TRIANGLEFACE6_RTTI:
    //{
//         double J = ent.shape().jacobianDeterminant();
//         if (J < 0) {
//             std::cerr << WHERE_AM_I << "JacobianDeterminant < 0 (" << J << ")" << std::endl;
//             std::cerr << ent.shape() << std::endl;
//             J = std::fabs(J);
//         }
//         for (uint i = 0; i < nVerts; i++){
//             for (uint j = 0; j < nVerts; j++){
//                 mat_[i][j] = J * (*Tri6_u2)[i][j];//compound[i][j];
//             }
//         }
//         std::cout << "2 " << *this << std::endl;
    //} break;
        return u2(ent, IntegrationRules::instance().triWeights(4), IntegrationRules::instance().triAbscissa(4), false); //ch
    case MESH_TETRAHEDRON_RTTI:
        return u2(ent, IntegrationRules::instance().tetWeights(2), IntegrationRules::instance().tetAbscissa(2), false);
    case MESH_TETRAHEDRON10_RTTI:
        return u2(ent, IntegrationRules::instance().tetWeights(4), IntegrationRules::instance().tetAbscissa(4), false);
    case MESH_HEXAHEDRON_RTTI:
        return u2(ent, IntegrationRules::instance().hexWeights(2), IntegrationRules::instance().hexAbscissa(2), false);
    case MESH_HEXAHEDRON20_RTTI:
        return u2(ent, IntegrationRules::instance().hexWeights(4), IntegrationRules::instance().hexAbscissa(4), false);
    case MESH_TRIPRISM_RTTI:
        return u2(ent, IntegrationRules::instance().priWeights(2), IntegrationRules::instance().priAbscissa(2), false);
    case MESH_TRIPRISM15_RTTI:
        return u2(ent, IntegrationRules::instance().priWeights(4), IntegrationRules::instance().priAbscissa(4), false);
    default:
      std::cerr << ent.rtti() << std::endl;
      THROW_TO_IMPL
    }

    return *this;
}
Exemple #13
0
void Raytracer::render( int width, int height, Point3D eye, Vector3D view, 
		Vector3D up, double fov, char* fileName, int aa, int fl, bool dof ) {
	Matrix4x4 viewToWorld;

	width = width * aa;
	height = height * aa;
	double factor = (double(height)/2)/tan(fov*M_PI/360.0);

	viewToWorld = initInvViewMatrix(eye, view, up);

	initAABuffer(aa, width, height);

	_scrWidth = width / aa;
	_scrHeight = height / aa;

	initPixelBuffer();

	// Construct a ray for each pixel.
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			// Sets up ray origin and direction in view space, 
			// image plane is at z = -1.
			Point3D origin(0, 0, 0);
			Point3D imagePlane;
			imagePlane[0] = (-double(width)/2 + 0.5 + j)/factor;
			imagePlane[1] = (-double(height)/2 + 0.5 + i)/factor;
			imagePlane[2] = -1;
			
			Ray3D ray;

			ray.origin = viewToWorld * origin;
            ray.dir = viewToWorld * imagePlane - ray.origin;
			ray.dir.normalize();
			Colour col(0,0,0);

			//implement depth of field if true
			if (dof == true) {
				//generate a point in the scene as part of the focal plane
				Vector3D pointAimed = (ray.origin + fl * ray.dir) - Point3D(0,0,0);
				float r = 1;
				Colour pc(0,0,0);

				for (int px=0; px < 15; px++) {
					float du = ((float) rand())/(float(RAND_MAX));
					float dv = ((float) rand())/(float(RAND_MAX));
					//x and y axis of camera/eye
					Vector4D u = viewToWorld.getColumn(1);
					Vector4D v = viewToWorld.getColumn(0);
					//convert them to 3d vectors;
					Vector3D u2(u[0],u[1],u[2]);
					Vector3D v2(v[0],v[1],v[2]);
					//convert ray.origin to vector for vector operation;
					Vector3D tempv(ray.origin[0], ray.origin[1], ray.origin[2]);
					//generate random point around the eye (vector is used for operation)
					Vector3D eyev = tempv - (r/2)*u2 - (r/2)*v2 + r*(du)*u2 + r*(dv)*v2;
					//generate a ray from random point to pointAimed
					Ray3D dovr;
					dovr.dir = pointAimed - eyev;
					dovr.origin = Point3D(eyev[0], eyev[1], eyev[2]);
					dovr.dir.normalize();
					//bounce ray into the scene and get its color
					Colour dovCol = shadeRay(dovr, 2);
					pc = pc + dovCol;

				}
				//average the pixel colors to get the blurriness effect
				col = (1/15.0) * pc;
			} else {
				col = shadeRay(ray, 2);
			}
			col.clamp();

			if (aa == 1) {
				_rbuffer[i*width+j] = int(col[0]*255);
				_gbuffer[i*width+j] = int(col[1]*255);
				_bbuffer[i*width+j] = int(col[2]*255);
			} else {
				re[i*width+j] = int(col[0]*255);
				gr[i*width+j] = int(col[1]*255);
				bl[i*width+j] = int(col[2]*255);
			}

		}
	}

	if (aa == 1) {
		flushPixelBuffer(fileName);
	} else {
		aarender(width, height, aa, fileName);
		delete re;
		delete gr;
		delete bl;
	}
}
	HRESULT STDMETHODCALLTYPE Win32WebKitPolicyDelegate::decidePolicyForNavigationAction(
		/*[in]*/ IWebView* /*webView*/,
		/*[in]*/ IPropertyBag* actionInformation,
		/*[in]*/ IWebURLRequest* request,
		/*[in]*/ IWebFrame* frame,
		/*[in]*/ IWebPolicyDecisionListener* listener)
	{
		/*
		BSTR url;
		request->URL(&url);

		int navType = 0;
		VARIANT var;
		if (SUCCEEDED(actionInformation->Read(WebActionNavigationTypeKey, &var, 0))) {
			V_VT(&var) = VT_I4;
			navType = V_I4(&var);
		}

		const char* typeDescription;
		switch (navType) {
			case WebNavigationTypeLinkClicked:
				typeDescription = "link clicked";
				break;
			case WebNavigationTypeFormSubmitted:
				typeDescription = "form submitted";
				break;
			case WebNavigationTypeBackForward:
				typeDescription = "back/forward";
				break;
			case WebNavigationTypeReload:
				typeDescription = "reload";
				break;
			case WebNavigationTypeFormResubmitted:
				typeDescription = "form resubmitted";
				break;
			case WebNavigationTypeOther:
				typeDescription = "other";
				break;
			default:
				typeDescription = "illegal value";
		}

		printf("Policy delegate: attempt to load %S with navigation type '%s'\n", url ? url : TEXT(""), typeDescription);

		SysFreeString(url);

		if (m_permissiveDelegate)
			listener->use();
		else
			listener->ignore();

		return S_OK;
		*/

		BSTR u;
		request->URL(&u);
		std::wstring u2(u);
		std::string url;
		url.assign(u2.begin(), u2.end());

		// if url matches a window config, then modify window as needed
		this->window->UpdateWindowForURL(url);

		SysFreeString(u);

		listener->use();

		return S_OK;
	}
Exemple #15
0
void FakeMDEventData::addFakeRandomData(
    const std::vector<double> &params,
    typename MDEventWorkspace<MDE, nd>::sptr ws) {

  bool RandomizeSignal = getProperty("RandomizeSignal");

  size_t num = size_t(params[0]);
  if (num == 0)
    throw std::invalid_argument(
        " number of distributed events can not be equal to 0");

  Progress prog(this, 0.0, 1.0, 100);
  size_t progIncrement = num / 100;
  if (progIncrement == 0)
    progIncrement = 1;

  boost::mt19937 rng;
  int randomSeed = getProperty("RandomSeed");
  rng.seed((unsigned int)(randomSeed));

  // Unit-size randomizer
  boost::uniform_real<double> u2(0, 1.0); // Random from 0 to 1.0
  boost::variate_generator<boost::mt19937 &, boost::uniform_real<double>>
      genUnit(rng, u2);

  // Make a random generator for each dimensions
  typedef boost::variate_generator<boost::mt19937 &,
                                   boost::uniform_real<double>> gen_t;

  // Inserter to help choose the correct event type
  auto eventHelper =
      MDEvents::MDEventInserter<typename MDEventWorkspace<MDE, nd>::sptr>(ws);

  gen_t *gens[nd];
  for (size_t d = 0; d < nd; ++d) {
    double min = params[d * 2 + 1];
    double max = params[d * 2 + 2];
    if (max <= min)
      throw std::invalid_argument(
          "UniformParams: min must be < max for all dimensions.");

    boost::uniform_real<double> u(min, max); // Range
    gen_t *gen = new gen_t(rng, u);
    gens[d] = gen;
  }

  // Create all the requested events
  for (size_t i = 0; i < num; ++i) {
    coord_t centers[nd];
    for (size_t d = 0; d < nd; d++) {
      centers[d] = static_cast<coord_t>(
          (*gens[d])()); // use a different generator for each dimension
    }

    // Default or randomized error/signal
    float signal = 1.0;
    float errorSquared = 1.0;
    if (RandomizeSignal) {
      signal = float(0.5 + genUnit());
      errorSquared = float(0.5 + genUnit());
    }

    // Create and add the event.
    eventHelper.insertMDEvent(signal, errorSquared, 1, pickDetectorID(),
                              centers); // 1 = run number
    // Progress report
    if ((i % progIncrement) == 0)
      prog.report();
  }

  /// Clean up the generators
  for (size_t d = 0; d < nd; ++d)
    delete gens[d];
}
// Definition of stringsearch() function
void session::stringsearch(){

	// Whole body is in loop
	// Loop ends if the list is empty or a certain number of urls have been parsed
	do{

		// File that stores source code of URLs
		std::ofstream FILE("source.txt");

		std::ofstream wordfile("index.txt", std::ios::app|std::ios::out);

		// Object of url class created
		url u(list.front());

		// Object of Http class (found in SFML) created
		// Http class only takes host names as input, so host name passed
		sf::Http site(u.host());

		//Generate the request, i.e the path within the webpage
		sf::Http::Request request(u.path());

		// Send the request to generate a response
		sf::Http::Response response = site.sendRequest(request);

		// Check the status code and display the result
		sf::Http::Response::Status status = response.getStatus();
		if (status == sf::Http::Response::Ok){
			FILE << response.getBody() << std::endl;
		}
		else{
			std::cout << "Error " << status << std::endl;
			std::cout << "Skipping webpage. " << std::endl;
			list.pop();
			continue;
		}
		FILE.close();

		std::cout << "Popping URL: " << list.front() << std::endl << std::endl;
		Sleep(1000);

		// Condition check to see if file is of html format
		if (check_html() == false){
			std::cout << "\nWebpage not in html format. Skipping... " << std::endl << std::endl;
			list.pop();
			continue;
		}

		// Condition check to ensure URL hasn't been crawled previously. First URL is skipped
		if (count > 1 && check_urls(list.front()) == true){
			std::cout << "\nWebpage has already been crawled. Skipping...\n\n";
			list.pop();
			continue;
		}

		// Opens file for reading
		std::ifstream file("source.txt");

		std::string s1; // String stores lines from html file
		std::string s2 = "href=\""; // Reference string to locate hyperlinks
		char s3[300]; // C string variable to store hyperlink URLs

		// Condition check to ensure file is open
		if (file.is_open()){

			do{
				// Both string storage variables initialised to null
				s1 = "";

				std::getline(file, s1); // Gets line by line information from the page source
				
				std::size_t location = s1.find(s2); // Variable to point to location in string

				int i = 0;
				// Check to see if location is within string, i.e the desired element has been found
				if (location != std::string::npos){
					std::cout << "Hyperlink found: ";

					// Location set to first element of hyperlink
					// Adding 6 accounts for the 6 tag characters, i.e href"
					std::size_t x = location + 6;

					// Loop adds characters to array until quotation mark is reached
					while (s1.at(x) != '\"'){
						s3[i] = s1.at(x);
						x++;
						i++;
					}

					// Last character set to termination character
					s3[i] = '\0';

					std::string s4 = s3; // Converts C string to std::string

					std::cout << s4 << std::endl;

					// Creates url object that takes s4 as constructor argument
					url u2(s4);

					// Condition check to see if hyperlink has a host
					// If it doesn't, it means it is an extension of the current webpage
					// So current webpage is appended to it
					if (u2.host() == ""){
						s4 = u.protocol() + "://" + u.host() + s4;
					}

					std::cout << "Adding URL to queue..." << std::endl;

					// Hyperlink is added to queue
					list.push(s4);

					std::cout << s4 << std::endl << std::endl;
				}

				if (wordfile.is_open()){
					std::string word = "Boost";

					std::size_t point = s1.find(word);
					
					if (point != std::string::npos){

				//		while ()

						wordfile << list.front() << std::endl;
						wordfile << word << std::endl;
					}
				//	else{
					//	std::cout << "word not found" << std::endl;
						//std::cout << "\n";
				//	}
				}
				else{
					std::cout << "index could not be opened" << std::endl;
				}

			} while (!file.eof());

			// Adds current webpage to list of URLs parsed
			urls_parsed(list.front());
			
			// Removes current webpage from queue
			list.pop();
			file.close();
			wordfile.close();

			std::cout << "\n\nCount: " << count << std::endl;
			count++;

			Sleep(1000);			
		}
		else{
			std::cout << "Error in opening file" << std::endl;
			exit(-1);
		}
		//Sleep(1000);
	} while (count <= 10 && list.empty() == false);
	remove("source.txt");
	remove("urls.txt");

	return;
}
Exemple #17
0
void FakeMDEventData::addFakePeak(typename MDEventWorkspace<MDE, nd>::sptr ws) {
  std::vector<double> params = getProperty("PeakParams");
  bool RandomizeSignal = getProperty("RandomizeSignal");
  if (params.empty())
    return;

  if (params.size() != nd + 2)
    throw std::invalid_argument("PeakParams needs to have ndims+2 arguments.");
  if (params[0] <= 0)
    throw std::invalid_argument("PeakParams: number_of_events needs to be > 0");
  size_t num = size_t(params[0]);

  Progress prog(this, 0.0, 1.0, 100);
  size_t progIncrement = num / 100;
  if (progIncrement == 0)
    progIncrement = 1;

  // Width of the peak
  double desiredRadius = params.back();

  boost::mt19937 rng;
  boost::uniform_real<coord_t> u2(0, 1.0); // Random from 0 to 1.0
  boost::variate_generator<boost::mt19937 &, boost::uniform_real<coord_t>>
      genUnit(rng, u2);
  int randomSeed = getProperty("RandomSeed");
  rng.seed((unsigned int)(randomSeed));

  // Inserter to help choose the correct event type
  auto eventHelper =
      MDEvents::MDEventInserter<typename MDEventWorkspace<MDE, nd>::sptr>(ws);

  for (size_t i = 0; i < num; ++i) {
    // Algorithm to generate points along a random n-sphere (sphere with not
    // necessarily 3 dimensions)
    // from http://en.wikipedia.org/wiki/N-sphere as of May 6, 2011.

    // First, points in a hyper-cube of size 1.0, centered at 0.
    coord_t centers[nd];
    coord_t radiusSquared = 0;
    for (size_t d = 0; d < nd; d++) {
      centers[d] = genUnit() - 0.5f; // Distribute around +- the center
      radiusSquared += centers[d] * centers[d];
    }

    // Make a unit vector pointing in this direction
    coord_t radius = static_cast<coord_t>(sqrt(radiusSquared));
    for (size_t d = 0; d < nd; d++)
      centers[d] /= radius;

    // Now place the point along this radius, scaled with ^1/n for uniformity.
    coord_t radPos = genUnit();
    radPos = static_cast<coord_t>(
        pow(radPos, static_cast<coord_t>(1.0 / static_cast<coord_t>(nd))));
    for (size_t d = 0; d < nd; d++) {
      // Multiply by the scaling and the desired peak radius
      centers[d] *= (radPos * static_cast<coord_t>(desiredRadius));
      // Also offset by the center of the peak, as taken in Params
      centers[d] += static_cast<coord_t>(params[d + 1]);
    }

    // Default or randomized error/signal
    float signal = 1.0;
    float errorSquared = 1.0;
    if (RandomizeSignal) {
      signal = float(0.5 + genUnit());
      errorSquared = float(0.5 + genUnit());
    }

    // Create and add the event.
    eventHelper.insertMDEvent(signal, errorSquared, 1, pickDetectorID(),
                              centers); // 1 = run number
    // Progress report
    if ((i % progIncrement) == 0)
      prog.report();
  }

  ws->splitBox();
  Kernel::ThreadScheduler *ts = new ThreadSchedulerFIFO();
  ThreadPool tp(ts);
  ws->splitAllIfNeeded(ts);
  tp.joinAll();
  ws->refreshCache();
}
Exemple #18
0
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	gluLookAt(r*cos(c*du), h, r*sin(c*du), 0, 0, 0, 0, 3, 0); //head position;eye direction(0.0,0.0,0.0),original point;(0.0,1.0,0.0),head above direction¡£
	
	//cylinder a(1, 15, 0, 90, 0, 0, 5, 0); //r,h,xangle yangle zangle, module position(xx yy zz)
	//sphere b(3, 100, 100, 0, 0, 0, 0, 2.5, 0); //r,xangle yangle zangle, module position(xx yy zz)
	//cube c(5, 10, 0, 0, 1, 1, 1); //length xangle yangle zangle, module position(xx yy zz)
	//rectangularpyramid d(4, 0, 0, 0, 0, 2, 0); //length xangle yangle zangle, module position(xx yy zz)
	//triangularpyramid f(2, 0, 0, 0, 8, 8, 8);//length xangle yangle zangle, module position(xx yy zz)						
	//f.draw();
	sphere sp(3, 100, 100, 0, 0, -2, 0, 8, 0);
	cylinder cy(3, 5, 0, 90, 0, -3, 9, -10);
	cube cu(3, 0, 0, 0, 0, 8, 10);
	triangularpyramid tr(2, 0, 0, 0, 0, -6, 8);
	rectangularpyramid rec(2, 0, 0, 0, 0, -6, -8);

	cylinder k1(0.3, 2, 90, 0, 0, 0, 0, 0);
	cylinder k2(0.3, 2, -90, 0, 0, 0, 0, 0);
	cylinder k3(0.3, 2, -45, 0, 0, 0, 0, 0);
	cylinder k4(0.3, 2.5, 45, 0, 0, 0, 0, 0);

	cylinder u1(0.3, 2, 90, 0, 0, 0, 0, 3);
	cylinder u2(0.3, 1.5, -90, 0, 0, 0, 0, 3);
	cylinder u3(0.3, 2, 0, 0, 0, 0, -1.8, 3);
	cylinder u4(0.3, 2, 90, 0, 0, 0, 0, 5);
	cylinder u5(0.3, 1.5, -90, 0, 0, 0, 0, 5);  

	cylinder g1(0.3, 2, -90, 0, 0, 0, -0.5, 6.4);
	cylinder g2(0.3, 1.5, -90, 0, 0, 0, -0.5, 6.4);
	cylinder g3(0.3, 2, 0, 0, 0, 0, -0.3, 6.4);
	cylinder g4(0.3, 2, 0, 0, 0, 0, 1.3, 6.4);
	cylinder g5(0.3, 2, 90, 0, 0, 0, 0, 8.4);
	cylinder g6(0.3, 1.5, -90, 0, 0, 0, 0, 8.4);
	cylinder g7(0.3, 2, 0, 0, 0, 0, -1.8, 6.4);

	cylinder e1(0.3, 1.8, -90, 0, 0, 0, -0.2, 10);
	cylinder e2(0.3, 1.8, 90, 0, 0, 0, -0.2, 10);
	cylinder e3(0.3, 2, 0, 0, 0, 0, -0.3, 10);
	cylinder e4(0.3, 2, 0, 0, 0, 0, 1.3, 10);
	cylinder e5(0.3, 2, 0, 0, 0, 0, -1.8, 10);

	cylinder r1(0.3, 1.8, -90, 0, 0, 0, -0.2, 13.5);
	cylinder r2(0.3, 1.8, 90, 0, 0, 0, -0.2, 13.5);
	cylinder r3(0.3, 2, 0, 0, 0, 0, -0.3, 13.5);
	cylinder r4(0.3, 1.2, 0, 0, 0, 0, 1.3, 13.5);
	cylinder r5(0.3, 1.7, 60, 0, 0, 0, 1.3, 14.5);
	cylinder r6(0.3, 2.5, 45, 0, 0, 0, 0, 13.5);


	cylinder c1(0.3, 2, 90, 0, 0, 0, 0, -15);
	cylinder c2(0.3, 2, -90, 0, 0, 0, 0, -15); 
	cylinder c3(0.3, 3, 0, 0, 0, 0, -1.8, -15);
	cylinder c4(0.3, 3, 0, 0, 0, 0, 1.8, -15);

	cylinder plus1(0.3,3.5, 0, 0, 0, 0, 0, -11);
	cylinder plus2(0.3, 4, 90, 0, 0, 0, 2, -9.2);
	cylinder plus3(0.3, 3.5, 0, 0, 0, 0, 0, -6);
	cylinder plus4(0.3, 4, 90, 0, 0, 0, 2, -4.2);
	cy.draw();
	sp.draw();
	cu.draw();
	tr.draw();
	rec.draw();

	k1.draw();
	k2.draw();
	k3.draw();
	k4.draw();

	u1.draw();
	u2.draw();
	u3.draw();
	u4.draw();
	u5.draw();
	
	g1.draw();
	g2.draw();
	g3.draw();
	g4.draw();
	g5.draw();
	g6.draw();
	g7.draw();

	e1.draw();
	e2.draw();
	e3.draw();
	e4.draw();
	e5.draw();

	r1.draw();
	r2.draw();
	r3.draw();
	r4.draw();
	r5.draw();
	r6.draw();

	c1.draw();
	c2.draw();
	c3.draw();
	c4.draw();
	
	plus1.draw();
	plus2.draw();
	plus3.draw();
	plus4.draw();

	glFlush();
	
}
Exemple #19
0
bool checkCreateDatabaseGrant(const MetaName& userName, const MetaName& trustedRole,
	const MetaName& sqlRole, const char* securityDb)
{
	if (userName == DBA_USER_NAME)
		return true;

	RefPtr<IAttachment> att;
	RefPtr<ITransaction> tra;
	bool hasDb = openDb(securityDb, att, tra);

	FbLocalStatus st;
	MetaName role(sqlRole);
	if (hasDb && role.hasData())
	{
		const UCHAR info[] = { isc_info_db_sql_dialect, isc_info_end };
		UCHAR buffer[BUFFER_TINY];
		att->getInfo(&st, sizeof(info), info, sizeof(buffer), buffer);
		check("IAttachment::getInfo", &st);

		int dialect = SQL_DIALECT_V5;		// reasonable default
		const UCHAR* p = buffer;
		while (*p != isc_info_end && *p != isc_info_truncated && p < buffer + sizeof(buffer))
		{
			const UCHAR item = (UCHAR) *p++;
			const USHORT length = gds__vax_integer(p, sizeof(USHORT));
			p += sizeof(USHORT);

			switch (item)
			{
			case isc_info_db_sql_dialect:
				dialect = gds__vax_integer(p, length);
				break;
			}

			p += length;
		}

		UserId::makeRoleName(role, dialect);

		// We need to check is role granted to userName in security DB
		const char* sql = "select count(*) from RDB$USER_PRIVILEGES "
			"where RDB$USER = ? and RDB$RELATION_NAME = ? and RDB$PRIVILEGE = 'M'";

		Message prm;
		Field<Varying> u(prm, MAX_SQL_IDENTIFIER_LEN);
		Field<Varying> r(prm, MAX_SQL_IDENTIFIER_LEN);
		u = userName.c_str();
		r = role.c_str();

		Message result;
		Field<ISC_INT64> cnt(result);

		att->execute(&st, tra, 0, sql, SQL_DIALECT_V6, prm.getMetadata(), prm.getBuffer(),
			result.getMetadata(), result.getBuffer());

		if (st->getState() & IStatus::STATE_ERRORS)
		{
			// isc_dsql_relation_err when exec SQL - i.e. table RDB$USER_PRIVILEGES
			// is missing due to non-FB security DB
			if (!fb_utils::containsErrorCode(st->getErrors(), isc_dsql_relation_err))
				check("IAttachment::execute", &st);

			role = "";
		}
		else if (cnt == 0)
			role = "";
	}
	else
		role = trustedRole;

	if (role == ADMIN_ROLE)
		return true;

	if (!hasDb)
		return false;

	// check db creators table
	Message gr;
	Field<ISC_SHORT> uType(gr);
	Field<Varying> u(gr, MAX_SQL_IDENTIFIER_LEN);
	Field<ISC_SHORT> rType(gr);
	Field<Varying> r(gr, MAX_SQL_IDENTIFIER_LEN);
	uType = obj_user;
	u = userName.c_str();
	rType = role.hasData() ? obj_sql_role : 255;
	r = role.c_str();

	Message result;
	Field<ISC_INT64> cnt(result);

	att->execute(&st, tra, 0,
		"select count(*) from RDB$DB_CREATORS"
		" where (RDB$USER_TYPE = ? and RDB$USER = ?) or (RDB$USER_TYPE = ? and RDB$USER = ?)",
		SQL_DIALECT_V6, gr.getMetadata(), gr.getBuffer(), result.getMetadata(), result.getBuffer());
	if (st->getState() & IStatus::STATE_ERRORS)
	{
		if (fb_utils::containsErrorCode(st->getErrors(), isc_dsql_relation_err))
		{
			// isc_dsql_relation_err when exec SQL - i.e. table RDB$DB_CREATORS
			// is missing due to non-FB3 security DB
			return false;
		}
		check("IAttachment::execute", &st);
	}

	if (cnt > 0)
		return true;

	if (!role.hasData())
		role = "NONE";

	Message par2;
	Field<ISC_SHORT> uType2(par2);
	Field<Varying> u2(par2, MAX_SQL_IDENTIFIER_LEN);
	Field<Varying> r2(par2, MAX_SQL_IDENTIFIER_LEN);
	uType2 = obj_user;
	u2 = userName.c_str();
	r2 = role.c_str();

	Message res2;
	Field<Text> priv(res2, 8);

	const char* sql =
		"with recursive role_tree as ( "
		"   select rdb$relation_name as nm, 0 as ur from rdb$user_privileges "
		"       where rdb$privilege = 'M' and rdb$field_name = 'D' and rdb$user_type = ? and rdb$user = ? "
		"   union all "
		"   select rdb$role_name as nm, 1 as ur from rdb$roles "
		"       where rdb$role_name = ? "
		"   union all "
		"   select p.rdb$relation_name as nm, t.ur from rdb$user_privileges p "
		"       join role_tree t on t.nm = p.rdb$user "
		"       where p.rdb$privilege = 'M' and (p.rdb$field_name = 'D' or t.ur = 1)) "
		"select r.rdb$system_privileges "
		"   from role_tree t join rdb$roles r on t.nm = r.rdb$role_name ";
	RefPtr<IResultSet> rs(REF_NO_INCR, att->openCursor(&st, tra, 0, sql,
		SQL_DIALECT_V6, par2.getMetadata(), par2.getBuffer(), res2.getMetadata(), NULL, 0));
	check("IAttachment::execute", &st);

	UserId::Privileges privileges, wrk;

	while (rs->fetchNext(&st, res2.getBuffer()) == IStatus::RESULT_OK)
	{
		wrk.load(&priv);
		privileges |= wrk;
	}

	check("IResultSet::fetchNext", &st);

	return wrk.test(CREATE_DATABASE);
}
Exemple #20
0
scalar essential_bc_values_2(int ess_bdy_marker, double x, double y, double z) {
	return u2(x, y, z);
}
void container_test(X& r, T const&)
{
    typedef BOOST_DEDUCED_TYPENAME X::iterator iterator;
    typedef BOOST_DEDUCED_TYPENAME X::const_iterator const_iterator;
    typedef BOOST_DEDUCED_TYPENAME X::difference_type difference_type;
    typedef BOOST_DEDUCED_TYPENAME X::size_type size_type;

    typedef BOOST_DEDUCED_TYPENAME
        boost::iterator_value<iterator>::type iterator_value_type;
    typedef BOOST_DEDUCED_TYPENAME
        boost::iterator_value<const_iterator>::type const_iterator_value_type;
    typedef BOOST_DEDUCED_TYPENAME
        boost::iterator_difference<iterator>::type iterator_difference_type;
    typedef BOOST_DEDUCED_TYPENAME
        boost::iterator_difference<const_iterator>::type
            const_iterator_difference_type;

    typedef BOOST_DEDUCED_TYPENAME X::value_type value_type;
    typedef BOOST_DEDUCED_TYPENAME X::reference reference;
    typedef BOOST_DEDUCED_TYPENAME X::const_reference const_reference;

    // value_type

    BOOST_MPL_ASSERT((boost::is_same<T, value_type>));
    boost::function_requires<boost::CopyConstructibleConcept<X> >();

    // reference_type / const_reference_type

    BOOST_MPL_ASSERT((boost::is_same<T&, reference>));
    BOOST_MPL_ASSERT((boost::is_same<T const&, const_reference>));

    // iterator

    boost::function_requires<boost::InputIteratorConcept<iterator> >();
    BOOST_MPL_ASSERT((boost::is_same<T, iterator_value_type>));
    BOOST_MPL_ASSERT((boost::is_convertible<iterator, const_iterator>));

    // const_iterator

    boost::function_requires<boost::InputIteratorConcept<const_iterator> >();
    BOOST_MPL_ASSERT((boost::is_same<T, const_iterator_value_type>));

    // difference_type

    BOOST_MPL_ASSERT((boost::mpl::bool_<
                std::numeric_limits<difference_type>::is_signed>));
    BOOST_MPL_ASSERT((boost::mpl::bool_<
                std::numeric_limits<difference_type>::is_integer>));
    BOOST_MPL_ASSERT((boost::is_same<difference_type,
                iterator_difference_type>));
    BOOST_MPL_ASSERT((boost::is_same<difference_type,
                const_iterator_difference_type>));

    // size_type

    BOOST_MPL_ASSERT_NOT((boost::mpl::bool_<
                std::numeric_limits<size_type>::is_signed>));
    BOOST_MPL_ASSERT((boost::mpl::bool_<
                std::numeric_limits<size_type>::is_integer>));

    // size_type can represent any non-negative value type of difference_type
    // I'm not sure about either of these tests...
    size_type max_diff((std::numeric_limits<difference_type>::max)());
    difference_type converted_diff(max_diff);
    BOOST_TEST((std::numeric_limits<difference_type>::max)()
            == converted_diff);

    BOOST_TEST(
        static_cast<comparison_type>(
            (std::numeric_limits<size_type>::max)()) >
        static_cast<comparison_type>(
            (std::numeric_limits<difference_type>::max)()));

    // I don't test the runtime post-conditions here.
    X u;
    BOOST_TEST(u.size() == 0);
    BOOST_TEST(X().size() == 0);

    X a,b;

    sink(X(a));
    X u2(a);
    X u3 = a;

    X* ptr = new X();
    X& a1 = *ptr;
    (&a1)->~X();

    X const a_const;
    test::check_return_type<iterator>::equals(a.begin());
    test::check_return_type<const_iterator>::equals(a_const.begin());
    test::check_return_type<const_iterator>::equals(a.cbegin());
    test::check_return_type<const_iterator>::equals(a_const.cbegin());
    test::check_return_type<iterator>::equals(a.end());
    test::check_return_type<const_iterator>::equals(a_const.end());
    test::check_return_type<const_iterator>::equals(a.cend());
    test::check_return_type<const_iterator>::equals(a_const.cend());

    a.swap(b);
    test::check_return_type<X>::equals_ref(r = a);
    test::check_return_type<size_type>::equals(a.size());
    test::check_return_type<size_type>::equals(a.max_size());
    test::check_return_type<bool>::convertible(a.empty());

    // Allocator

    typedef BOOST_DEDUCED_TYPENAME X::allocator_type allocator_type;
    test::check_return_type<allocator_type>::equals(a_const.get_allocator());
    
    // Avoid unused variable warnings:

    sink(u);
    sink(u2);
    sink(u3);
}
 static inline u2   get_native_u2(address p){ 
   return (intptr_t(p) & 1) == 0
            ?   *(u2*)p
            :   ( u2(p[0]) << 8 ) 
              | ( u2(p[1])      );
 }
void
Quad10_2D_SUPG :: updateStabilizationCoeffs(TimeStep *atTime)
{
    double Re, norm_un, mu, mu_min, nu, norm_N, norm_N_d, norm_M_d, norm_LSIC, norm_G_c, norm_M_c, norm_N_c, t_p1, t_p2, t_p3, t_s1, t_s2, t_s3, rho;
    FloatMatrix dn, N, N_d, M_d, LSIC, G_c, M_c, N_c;
    FloatArray dN, s, lcoords_nodes, u, lcn, dn_a(2), n, u1(8), u2(8);
    GaussPoint *gp;
    IntegrationRule *iRule;


    iRule = integrationRulesArray [ 1 ];
    mu_min = 1;
    rho = this->giveMaterial()->give('d', integrationRulesArray [ 0 ]->getIntegrationPoint(0));
    for ( int j = 0; j < iRule->giveNumberOfIntegrationPoints(); j++ ) {
        gp = iRule->getIntegrationPoint(j);
        mu = static_cast< FluidDynamicMaterial* >(this->giveMaterial())->giveEffectiveViscosity(gp, atTime);
        if ( mu_min > mu ) {
            mu_min = mu;
        }

        nu = mu_min / rho;
    }

    nu = mu_min / rho;

    //this->computeVectorOf(EID_MomentumBalance, VM_Total, atTime->givePreviousStep(), un);
    this->computeVectorOf(EID_MomentumBalance, VM_Total, atTime, u);

    norm_un = u.computeNorm();

    this->computeAdvectionTerm(N, atTime);
    this->computeAdvectionDeltaTerm(N_d, atTime);
    this->computeMassDeltaTerm(M_d, atTime);
    this->computeLSICTerm(LSIC, atTime);
    this->computeLinearAdvectionTerm_MC(G_c, atTime);
    this->computeMassEpsilonTerm(M_c, atTime);
    this->computeAdvectionEpsilonTerm(N_c, atTime);


    norm_N = N.computeFrobeniusNorm();
    norm_N_d = N_d.computeFrobeniusNorm();
    norm_M_d = M_d.computeFrobeniusNorm();
    norm_LSIC = LSIC.computeFrobeniusNorm();
    norm_G_c = G_c.computeFrobeniusNorm();
    norm_M_c = M_c.computeFrobeniusNorm();
    norm_N_c = N_c.computeFrobeniusNorm();

    if ( ( norm_N == 0 ) || ( norm_N_d == 0 ) || ( norm_M_d == 0 ) ) {
        t_supg = 0;
    } else {
        Re = ( norm_un / nu ) * ( norm_N / norm_N_d );

        t_s1 = norm_N / norm_N_d;

        t_s2 = atTime->giveTimeIncrement() * ( norm_N / norm_M_d ) * 0.5;

        t_s3 = t_s1 * Re;

        t_supg =  1. / sqrt( 1. / ( t_s1 * t_s1 ) + 1. / ( t_s2 * t_s2 ) + 1. / ( t_s3 * t_s3 ) );
        // t_supg = 0;
    }

    if ( norm_LSIC == 0 ) {
        t_lsic = 0;
    } else {
        t_lsic = norm_N / norm_LSIC;

        // t_lsic = 0;
    }

    if ( ( norm_G_c == 0 ) || ( norm_N_c == 0 ) || ( norm_M_c == 0 ) ) {
        t_pspg = 0;
    } else {
        Re = ( norm_un / nu ) * ( norm_N / norm_N_d );

        t_p1 = norm_G_c / norm_N_c;

        t_p2 = atTime->giveTimeIncrement() * ( norm_G_c / norm_M_c ) * 0.5;

        t_p3 = t_p1 * Re;

        t_pspg =  1. / sqrt( 1. / ( t_p1 * t_p1 ) + 1. / ( t_p2 * t_p2 ) + 1. / ( t_p3 * t_p3 ) );
        // t_pspg = 0;
    }

    //t_pspg = 0;
}
Exemple #24
0
 // This should be compiler dependent. This will do for now.
 static inline u2   swap_u2(u2 x)  {
   address p = (address) &x;
   return  ( (u2(p[0]) << 8 ) | ( u2(p[1])) );
 }
Exemple #25
0
void KFMExec::slotMimeType( const char *_type )
{
    // A dirty hack for passing the character set
    char *typestr=0;
    const char *aType=0;
    const char *aCharset=0;
    if ( _type )
    {
        typestr=new char[strlen(_type)+1];
        strcpy(typestr,_type);
	aType=strtok(typestr," ;\t\n");
	char *tmp;
	while((tmp=strtok(0," ;\t\n"))){
            if ( strncmp(tmp,"charset=",8)==0 ) aCharset=tmp+8;
	}    
	if ( aCharset != 0 )
	{
	    tmp=strpbrk((char*)aCharset," ;\t\n");
	    if ( tmp != 0 ) *tmp=0;
	}    
    }  
    
    // Stop browsing. We need an application
    job->stop();
    // delete job;
    // job = 0L;
    
    // GZIP
    if ( aType && strcmp( aType, "application/x-gzip" ) == 0L )
    {
	job->stop();
	tryURL += "#gzip:/";
	openURL( tryURL );
    }
    // TAR
    else if ( aType && strcmp( aType, "application/x-tar" ) == 0L )
    {
	// Is this tar file perhaps hosted in a gzipped file ?
	KURL u( tryURL );
	// ... then we already have a 'gzip' subprotocol
	if ( u.hasSubProtocol() )
	{
	    KURL u2( u.nestedURL() );
	    if ( strcmp( u2.protocol(), "gzip" ) == 0 )
	    {
		// Remove the 'gzip' protocol. It will only slow down the process,
		// since two subprotocols '#gzip:/#tar:/' are not very fast
		// right now.
		tryURL = u.parentURL();
	    }
	}
	
	job->stop();
	tryURL += "#tar:/";
	openURL( tryURL );
    }
    // No HTML ?
    else if ( aType == 0L || strcmp( aType, "text/html" ) != 0L )
    {
      bool bdone = false;
      // Do we know the mime type ?
      if ( aType != 0L )
      {
	KMimeType *mime = KMimeType::findByName( aType );
	// Try to run the URL if we know the mime type
	if ( mime && mime->run( tryURL ) )
	{
	  // We are a zombie now
	  prepareToDie();
	  bdone = true;
	}
      }
		
      if ( !bdone )
      {    
	// Ask the user what we should do
	OpenWithDlg l( klocale->translate("Open With:"), "", 0L, true );
	if ( l.exec() )
	{
	  KMimeBind *bind = l.mimeBind();
	  if ( bind )
	  {
	    bind->runBinding( tryURL );
	  }
	  else
	  {
	    QString pattern = l.getText();
	    // The user did not something ?
	    if ( !pattern.isEmpty() )
	    {
	      QStrList list;
	      list.append( tryURL );
	      openWithOldApplication( pattern, list );
	    }

	    // We are a zombie now
	    prepareToDie();
	  }	
	}
      }
    }
    // It is HTML
    else
    {
	// Ok, lets open a new window
	KfmGui *m = new KfmGui( 0L, 0L, tryURL );
	if ( aCharset != 0 ) m->setCharset(aCharset);
	if ( dlg )
	  {
	    delete dlg;
	    dlg = 0L;
	  }
	m->show();
	
	// We are a zombie now
	prepareToDie();
    }
    delete typestr;
}