QPointF intersects(const LineWrapper &other)/* const */{
        KisVector2D n0 = m_lineEquation.normal();
        KisVector2D n1 = other.m_lineEquation.normal();

        // Ensure vectors have the same direction
        if((n0(0) > 0) != (n1(0) > 0)) {
            n1 = -n1;
        }

        if(qFuzzyCompare(n0(0), n1(0)) &&
           qFuzzyCompare(n0(1), n1(1))) {

            const KisVector2D nearPoint(0,0);
            const KisVector2D farPoint(1e10,1e10);

            KisVector2D otherPt = other.m_lineEquation.projection(nearPoint);
            KisVector2D otherPtProj = m_lineEquation.projection(otherPt);

            KisVector2D newOffset = otherPt + 0.5 * (otherPtProj - otherPt);
            LineEquation tempLine(n0, newOffset);
            // Just throw it somewhere towards infinity...
            return toQPointF(tempLine.projection(farPoint));
        }

        return toQPointF(m_lineEquation.intersection(other.m_lineEquation));
    }
int main(int argc, char const *argv[])
{
	// 	     0
	// 	    / \
	//     1   2
	//    / \   \
	//   3   4   7
	//        \  /
	//         5 8
	//          \
	//           6
	TreeNode<int> n0(0);
	TreeNode<int> n1(1);
	TreeNode<int> n2(2);
	TreeNode<int> n3(3);
	TreeNode<int> n4(4);
	TreeNode<int> n5(5);
	TreeNode<int> n6(6);
	TreeNode<int> n7(7);
	TreeNode<int> n8(8);
	n0.left = &n1;
	n0.right = &n2;
	n1.left = &n3;
	n1.right = &n4;
	n4.right = &n5;
	n5.right = &n6;
	n2.right = &n7;
	n7.left = &n8;

	bool* matrix = solve(&n0);
	delete[] matrix;

	return 0;
}
Example #3
0
// Computes the point where three planes intersect. Returns whether or not the point exists.
static inline bool PlaneIntersection( SVector3* intersectPt, const SPlane& p0, const SPlane& p1, const SPlane& p2 )
{
	SVector3 n0( p0.a, p0.b, p0.c );
	SVector3 n1( p1.a, p1.b, p1.c );
	SVector3 n2( p2.a, p2.b, p2.c );

	SVector3 n1_n2, n2_n0, n0_n1;  

	D3DXVec3Cross( &n1_n2, &n1, &n2 );
	D3DXVec3Cross( &n2_n0, &n2, &n0 );
	D3DXVec3Cross( &n0_n1, &n0, &n1 );

	float cosTheta = n0.dot(n1_n2);

	if( FLT_ALMOST_ZERO(cosTheta) || FLT_IS_SPECIAL(cosTheta) )
		return false;

	float secTheta = 1.0f / cosTheta;

	n1_n2 = n1_n2 * p0.d;
	n2_n0 = n2_n0 * p1.d;
	n0_n1 = n0_n1 * p2.d;

	*intersectPt = -(n1_n2 + n2_n0 + n0_n1) * secTheta;
	return true;
}
Example #4
0
/** Calculates the normalization constant for the exponential decay
* @param ws :: [input] Workspace containing the spectra to remove exponential
* from
* @return :: Vector containing the normalization constants, N0, for each
* spectrum
*/
std::vector<double>
PhaseQuadMuon::getExponentialDecay(const API::MatrixWorkspace_sptr &ws) {

  size_t nspec = ws->getNumberHistograms();
  size_t npoints = ws->blocksize();

  // Muon life time in microseconds
  double muLife = PhysicalConstants::MuonLifetime * 1e6;

  std::vector<double> n0(nspec, 0.);

  for (size_t h = 0; h < ws->getNumberHistograms(); h++) {

    const auto &X = ws->getSpectrum(h).x();
    const auto &Y = ws->getSpectrum(h).y();
    const auto &E = ws->getSpectrum(h).e();

    double s, sx, sy;
    s = sx = sy = 0;
    for (size_t i = 0; i < npoints; i++) {

      if (Y[i] > 0) {
        double sig = E[i] * E[i] / Y[i] / Y[i];
        s += 1. / sig;
        sx += (X[i] - X[0]) / sig;
        sy += log(Y[i]) / sig;
      }
    }
    n0[h] = exp((sy + sx / muLife) / s);
  }

  return n0;
}
TEST(removeNthFromEnd, caseTest) {
    Solution s;
    
    ListNode n0(0);
    EXPECT_EQ(NULL, s.removeNthFromEnd(&n0, 1));
    
    ListNode n1(1);
    ListNode n2(2);
    n1.next = &n2;
    ListNode* n3 = s.removeNthFromEnd(&n1, 2);
    EXPECT_EQ(&n2, n3);
    EXPECT_EQ(NULL, n3->next);
    
    ListNode n4(4);
    ListNode n5(5);
    ListNode n6(6);
    ListNode n7(7);
    n4.next = &n5;
    n5.next = &n6;
    n6.next = &n7;
    ListNode *n8 = s.removeNthFromEnd(&n4, 4);
    EXPECT_EQ(5, n8->val);
    EXPECT_EQ(6, n8->next->val);
    
}
Example #6
0
bool PNS_DIFF_PAIR::CheckConnectionAngle( const PNS_DIFF_PAIR& aOther, int aAllowedAngles ) const
{
    bool checkP, checkN;

    if( m_p.SegmentCount() == 0 || aOther.m_p.SegmentCount() == 0 )
        checkP = true;
    else
    {
        DIRECTION_45 p0( m_p.CSegment( -1 ) );
        DIRECTION_45 p1( aOther.m_p.CSegment( 0 ) );

        checkP = ( p0.Angle( p1 ) & aAllowedAngles ) != 0;
    }

    if( m_n.SegmentCount() == 0 || aOther.m_n.SegmentCount() == 0 )
        checkN = true;
    else
    {
        DIRECTION_45 n0( m_n.CSegment( -1 ) );
        DIRECTION_45 n1( aOther.m_n.CSegment( 0 ) );

        checkN = ( n0.Angle( n1 ) & aAllowedAngles ) != 0;
    }

    return checkP && checkN;
}
Example #7
0
END_TEST


START_TEST(test_recover_reservation)
  {
  numa_node n0("../../../../test/test_files", 0);
  numa_node n1("../../../../test/test_files", 1);
  std::vector<numa_node> nodes;
  nodes.push_back(n0);
  nodes.push_back(n1);
  node_internals ni(nodes);

  recover_mode = 0;
  recover_called = 0;
  ni.recover_reservation(2, 2048, "1.napali");
  fail_unless(recover_called == 1);

  recover_called = 0;
  reserve_called = 0;
  recover_mode = 1;
  ni.recover_reservation(2, 2048, "1.napali");
  fail_unless(recover_called == 2);
  
  recover_called = 0;
  reserve_called = 0;
  recover_mode = 1;
  char buf[1024];
  fail_unless(reserve_called == 0);
  ni.recover_reservation(3, 2049, "1.napali");
  fail_unless(recover_called == 2);
  snprintf(buf, sizeof(buf), "reserve has been called %d times", reserve_called);
  fail_unless(reserve_called > 0, buf);
  }
Example #8
0
main()
{
P1DIR = 0xFF;
while(1)
	{
	n1();
	delay(65000);
	n2();
	delay(65000);
	n3();
	delay(65000);
	n4();
	delay(65000);
	n5();
	delay(65000);
	n6();
	delay(65000);
	n7();
	delay(65000);
	n8();
	delay(65000);
	n9();
	delay(65000);
	n0();
	delay(65000);
	}
}
TEST_F(P237_DeleteNodeInALinkedList_Test, example_case) {
  ListNode n3(4);
  ListNode n2(3);
  n2.next = &n3;
  ListNode n1(2);
  n1.next = &n2;
  ListNode n0(1);
  n0.next = &n1;
  s.deleteNode(&n2);
  ASSERT_EQ(4, n2.next->val);
}
Example #10
0
int main() {
    // init data
    TreeNode n6(6);
    TreeNode n2(2);
    TreeNode n8(8);
    TreeNode n0(0);
    TreeNode n4(4);
    TreeNode n7(7);
    TreeNode n9(9);
    TreeNode n3(3);
    TreeNode n5(5);

    n6.left = &n2;
    n6.right = &n8;

    n2.left = &n0;
    n2.right = &n4;

    n8.left = &n7;
    n8.right = &n9;

    n4.left = &n3;
    n4.right = &n5;

    // 测试 fillMapParents
    Solution sol;
    map<TreeNode*, TreeNode*> mapParents;
    sol.fillMapParents(&n6, mapParents);
    sol.printMapParents(mapParents);

    // 测试 depth
    sol.printAllNodesDepth(mapParents, &n6);

    // 测试 traverseUpward
    TreeNode* tempNode = &n2;
    sol.traverseUpward(tempNode, 1, mapParents);

    // 测试 lowestCommonAncestor
    TreeNode* v = &n2;
    TreeNode* w = &n4;
    TreeNode* lca = sol.lowestCommonAncestor(&n6, v, w);
    cout << endl << v->val << ", " << w->val << " 的 LCA 是 " << lca->val << endl << endl;

    v = &n2;
    w = &n8;
    lca = sol.lowestCommonAncestor(&n6, v, w);
    cout << endl << v->val << ", " << w->val << " 的 LCA 是 " << lca->val << endl << endl;

    return 0;
}
Example #11
0
int main(){
    TreeNode n0(10);
    TreeNode n1(5);
    TreeNode n2(15);
    TreeNode n3(6);
    TreeNode n4(20);
    n0.left = &n1;
    n0.right = &n2;
    n2.left = &n3;
    n2.right = &n4;
    bool res = isValidBST(&n0);
    printf("%s\n", res?"true":"false");
    return 0;
}
Example #12
0
int main() {

    typedef DAG::Node<const idpair> INode;

    // create a set of nodes
    // the nodes will be kept track of in the Node children and parent collections so
    // shared_ptr is used.
    INode n0(idpair(0, 2));
    INode n1(idpair(1, 3));
    INode n2(idpair(2, 3));
    INode n3(idpair(3, 2));
    INode n4(idpair(4, 2));
    INode n5(idpair(5, 2));
    INode n6(idpair(6, 2));
    // and now define the polytree
    // add the directed (parent -> child) branches of the polytree
    // each link requires an addChild and an addParent
    n0.addChild(n1);  // link between n0 and n1
    n1.addChild(n2);  // link between n0 and n2 etc
    n1.addChild(n3);
    n3.addChild(n6);
    n3.addChild(n4);
    n4.addChild(n5);
    n5.addChild(n6);

    DAG::BFSRecurseVisitor<INode> bfs;
    // Start at node 0 for the following examples

    // Example 1
    // BFSVisitor uses an iterative method to traverse
    // output the Datatype of all children
    std::cout << std::endl << "TRAVERSE CHILDREN (start Node 0)  1 level" << std::endl;
    for (auto n : bfs.traverseChildren(n0, 1)) {
        std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
    }

    std::cout << std::endl << "TRAVERSE UNDIRECTED (start Node 5) 2 levels " << std::endl;
    for (auto n : bfs.traverseUndirected(n5, 2)) {
        std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
    }

    std::cout << std::endl << "TRAVERSE CHILDREN (start Node 0)  all levels" << std::endl;

    for (auto n : bfs.traverseChildren(n0)) {
        std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
    }

    return 0;
}
Example #13
0
Segment Segment::getShortestConnection(const Segment & other) const {

	const Node & n0 = getA();
	const Node & n1 = getB();
	const Node & n2 = other.getA();
	const Node & n3 = other.getB();

	float d0232 = glm::dot(n0() - n2(), n3() - n2());
	float d3210 = glm::dot(n3() - n2(), n1() - n0());
	float d3232 = glm::pow(other.getLength(), 2.f);
	float d0210 = glm::dot(n0() - n2(), n1() - n0());
	float d1010 = glm::pow(getLength(), 2.f);

	float d0 = (d0232 * d3210 - d0210 * d3232) / (d1010 * d3232 - d3210 * d3210);
	float d1 = (d0232 + d0 * d3210) / d3232;
	d0 = glm::clamp(d0, 0.f, 1.f);
	d1 = glm::clamp(d1, 0.f, 1.f);

	Node ni0 = n0 + d0 * (n1 - n0);
	Node ni1 = n2 + d1 * (n3 - n2);

	return Segment(ni0, ni1);

}
void TurbulentMagneticField::initialize() {
	if (lMin >= lMax)
		throw std::runtime_error("crpropa::TurbulentMagneticField: lMin >= lMax");

	double lkMin = log10(2 * M_PI / lMax);
	double lkMax = log10(2 * M_PI / lMin);
	double dlk = (lkMax - lkMin) / (nModes - 1);
	double Lc = getCorrelationLength();

	Mode mode;
	Vector3f ek, e1, e2; // orthogonal base
	Vector3f n0(1, 1, 1); // arbitrary vector to construct orthogonal base

	double sumGk = 0;
	for (int i = 0; i < nModes; i++) {
		// construct an orthogonal base ek, e1, e2
		ek = random.randVector();
		if (ek.getAngleTo(n0) < 1e-3) {
			// ek parallel to (1,1,1)
			e1.setXYZ(-1., 1., 0);
			e2.setXYZ(1., 1., -2.);
		} else {
			// ek not parallel to (1,1,1)
			e1 = n0.cross(ek);
			e2 = ek.cross(e1);
		}
		double k = pow(10, lkMin + i * dlk);
		mode.k = ek * k;

		// amplitude (this seems to be wrong)
		double dk = k * dlk;
		double Gk = k * k * dk / (1 + pow(k * Lc, -spectralIndex));
		sumGk += Gk;
		mode.amplitude = Brms * sqrt(Gk);

		// random orientation of b
		double alpha = random.rand(2 * M_PI);
		mode.e1 = e1 / e1.getR() * cos(alpha);
		mode.e2 = e2 / e2.getR() * sin(alpha);

		// random phase
		mode.phase = random.rand(2 * M_PI);
		modes.push_back(mode);
	}

	for (int i = 0; i < nModes; i++)
		modes[i].amplitude /= sumGk;
}
int main(){
    TreeNode n0(0);
    TreeNode n1(1);
    TreeNode n2(2);
    TreeNode n3(3);
    TreeNode n4(4);
    TreeNode n5(5);
    n0.left = &n1;
    n0.right = &n2;
    n1.left = &n3;
    n1.right = &n4;
    n4.left = &n5;
    int res = maxDepth(&n0);
    printf("%d\n", res);
    return 0;
}
Example #16
0
END_TEST


START_TEST(test_remove)
  {
  numa_node n0("../../../../test/test_files", 0);
  numa_node n1("../../../../test/test_files", 1);
  std::vector<numa_node> nodes;
  nodes.push_back(n0);
  nodes.push_back(n1);
  node_internals ni(nodes);

  remove_called = 0;
  ni.remove_job("1.napali");
  fail_unless(remove_called == 2);
  }
int
DynamicsTrappenberg::initilize_x(
    const arma::Mat< double > u,
    const mxArray *theta,
    const mxArray *ptheta,
    arma::Mat< double >& nx)
{
    mxArray *mx0 = mxGetField(theta, 0, "x0");
    arma::Mat< double > n0(mxGetPr(mx0), mxGetDimensions(mx0)[0], 
        DIM_X_1_TRAPP, 1);
    
    nx = n0;

    return 0;

}
Example #18
0
void tst_model2expr() {
    ast_manager m;
    m.register_decl_plugins();
    arith_util a(m);

    ptr_vector<sort> ints;
    ints.push_back(a.mk_int());
    ints.push_back(a.mk_int());
    ints.push_back(a.mk_int());

    func_decl_ref p(m), q(m), x(m);
    p = m.mk_func_decl(symbol("p"), 2, ints.c_ptr(), a.mk_int());
    q = m.mk_func_decl(symbol("q"), 2, ints.c_ptr(), a.mk_int());
    x = m.mk_const_decl(symbol("x"), a.mk_int());
    expr_ref n0(m), n1(m), n2(m);
    n0 = a.mk_numeral(rational(0), true);
    n1 = a.mk_numeral(rational(1), true);
    n2 = a.mk_numeral(rational(2), true);

    model_ref md = alloc(model, m);
    func_interp* fip = alloc(func_interp, m, 2);
    func_interp* fiq = alloc(func_interp, m, 2);
    expr_ref_vector args(m);
    args.push_back(n1);
    args.push_back(n2);
    fip->insert_entry(args.c_ptr(), n1);
    fiq->insert_entry(args.c_ptr(), n1);
    args[0] = n0;
    args[1] = n1;
    fip->insert_entry(args.c_ptr(), n2);
    fiq->insert_entry(args.c_ptr(), n2);
   
    fip->set_else(n0);

    md->register_decl(x, a.mk_numeral(rational(0), true));
    md->register_decl(p, fip); // full
    md->register_decl(q, fiq); // partial

    expr_ref result(m);
    model2expr(md, result);
    
    model_smt2_pp(std::cout, m, *md,  0);
    std::cout << mk_pp(result, m) << "\n";
}
Example #19
0
void arahant()
{
 aaa(xnxt,ynxt,h,wa);
 rrr(xnxt,ynxt,h,wr);
 aaa(xnxt,ynxt,h,wa);
 hhh(xnxt,ynxt,h,wh);
 aaa(xnxt,ynxt,h,wa);
 nnn(xnxt,ynxt,h,wn);
 ttt(xnxt,ynxt,h,wt);
 xnxt+=s/2;
 aaa(xnxt,ynxt,h,wa);
 xnxt+=s/2;
 n1(xnxt,ynxt,h,w1);
 n1(xnxt,ynxt,h,w1);
 iii(xnxt,ynxt,h,wi);
 ttt(xnxt,ynxt,h,wt);
 n1(xnxt,ynxt,h,w1);
 n0(xnxt,ynxt,h,w0);
}
Example #20
0
END_TEST


START_TEST(test_getting_indices)
  {
  numa_node n0("../../../../test/test_files", 0);
  numa_node n1("../../../../test/test_files", 1);
  std::vector<numa_node> nodes;
  nodes.push_back(n0);
  nodes.push_back(n1);
  node_internals ni(nodes);

  get_job_indices_called = 0;
  ni.get_cpu_indices("1.napali");
  fail_unless(get_job_indices_called == 2);

  get_job_indices_called = 0;
  ni.get_memory_indices("1.napali");
  fail_unless(get_job_indices_called == 2);
  }
Example #21
0
END_TEST


START_TEST(test_reserve)
  {
  numa_node n0("../../../../test/test_files", 0);
  numa_node n1("../../../../test/test_files", 1);
  std::vector<numa_node> nodes;
  nodes.push_back(n0);
  nodes.push_back(n1);
  node_internals ni(nodes);

  does_it_fit = false;
  reserve_called = 0;
  ni.reserve(6, 100000, "1.napali");
  fail_unless(reserve_called == 2);

  does_it_fit = true;
  reserve_called = 0;
  ni.reserve(6, 100000, "1.napali");
  fail_unless(reserve_called == 1);
  }
Example #22
0
PView *GMSH_CVTRemeshPlugin::execute(PView *v)
{
  //TODO normalization

  GModel* m = GModel::current() ;

  std::vector<double> vertices ;
  std::vector<unsigned int> faces ;

  unsigned int offset = 0 ;
  for(GModel::fiter it = m->firstFace(); it != m->lastFace(); ++it) {
    (*it)->buildSTLTriangulation() ;
    for(unsigned int i = 0; i < (*it)->stl_vertices.size(); ++i) {
      GPoint p = (*it)->point((*it)->stl_vertices[i]) ;
      vertices.push_back(p.x()) ;
      vertices.push_back(p.y()) ;
      vertices.push_back(p.z()) ;
    }
    for(unsigned int i = 0; i < (*it)->stl_triangles.size(); ++i) {
      faces.push_back((*it)->stl_triangles[i]+offset) ;
    }
    offset += (*it)->stl_vertices.size() ;
  }

  Revoropt::MeshBuilder<3> mesh ;
  mesh.swap_vertices(vertices) ;
  mesh.swap_faces(faces) ;

  double mesh_center[3] ;
  double mesh_scale ;
  Revoropt::normalize_mesh(&mesh, mesh_center, &mesh_scale) ;

  double nradius = (double)CVTRemeshOptions_Number[5].def ;

  //normals
  std::vector<double> normals(3*mesh.vertices_size()) ;
  Revoropt::full_robust_vertex_normals(&mesh,nradius,normals.data()) ;

  //lifted vertices
  std::vector<double> lifted_vertices(6*mesh.vertices_size(), 0) ;
  for(unsigned int vertex = 0; vertex < mesh.vertices_size(); ++vertex) {
    std::copy( mesh.vertex(vertex),
               mesh.vertex(vertex)+3,
               lifted_vertices.data()+6*vertex
             ) ;
    std::copy( normals.data()+3*vertex,
               normals.data()+3*vertex+3,
               lifted_vertices.data()+6*vertex+3
             ) ;
  }

  //setup lifted mesh
  Revoropt::ROMeshWrapper<3,6> lifted_mesh(
    lifted_vertices.data(),
    lifted_vertices.size()/6,
    &mesh
  ) ;

  //triangle weight factor
  double twfactor = (double)CVTRemeshOptions_Number[3].def ;

  //face ratios
  std::vector<double> triangle_weights(lifted_mesh.faces_size()) ;
  if(twfactor > 0) {
    for(unsigned int f = 0; f < lifted_mesh.faces_size(); ++f) {
      //vertices of the initial triangle
      const unsigned int* fverts = mesh.face(f) ;

      //positions
      const double* x[3] ;
      for(int i=0; i<3; ++i) {
        x[i] = lifted_mesh.vertex(fverts[i]) ;
      }

      //ratio
      double ratio = 1 ;

      //vectors
      typedef Eigen::Matrix<double,3,1> Vector3 ;

      Eigen::Map<const Vector3> v0(x[0]) ;
      Eigen::Map<const Vector3> v1(x[1]) ;
      Eigen::Map<const Vector3> v2(x[2]) ;

      //triangle frame
      Vector3 U = (v1-v0) ;
      const double U_len = U.norm() ;
      if(U_len > 0) {
        U /= U_len ;
        Vector3 H = (v2-v0) ;
        H = H - H.dot(U)*U ;
        const double H_len = H.norm() ;
        if(H_len > 0) {
          //we know that the triangle is not flat
          H /= H_len ;

          //gradient of the barycentric weights in the triangle
          Eigen::Matrix<double,3,2> bar_grads ;
          bar_grads(2,0) = 0 ;
          bar_grads(2,1) = 1/H_len ;

          //gradient norms of every normal component
          for(int i = 0; i < 2; ++i) {
            //reference frame for the vertex
            Eigen::Map<const Vector3> vi0(x[(i+1)%3]) ;
            Eigen::Map<const Vector3> vi1(x[(i+2)%3]) ;
            Eigen::Map<const Vector3> vi2(x[ i     ]) ;

            Vector3 Ui = (vi1-vi0) ;
            Ui /= Ui.norm() ;
            Vector3 Hi = (vi2-vi0) ;
            Hi = Hi - Hi.dot(Ui)*Ui ;
            const double Hi_invlen = 1/Hi.norm() ;
            Hi *= Hi_invlen ;
            bar_grads(i,0) = Hi.dot(U)*Hi_invlen ;
            bar_grads(i,1) = Hi.dot(H)*Hi_invlen ;
          }

          //gradient of each component of the normal
          Eigen::Map<const Vector3> n0(x[0]+3) ;
          Eigen::Map<const Vector3> n1(x[1]+3) ;
          Eigen::Map<const Vector3> n2(x[2]+3) ;

          Eigen::Matrix<double,3,2> n_grads = Eigen::Matrix<double,3,2>::Zero() ;

          n_grads = n0*bar_grads.row(0) ;
          n_grads += n1*bar_grads.row(1) ;
          n_grads += n2*bar_grads.row(2) ;

          //maximal gradient norm
          double g_max = n_grads.row(0).dot(n_grads.row(0)) ;
          double g_other = n_grads.row(1).dot(n_grads.row(1)) ;
          g_max = g_max > g_other ? g_max : g_other ;
          g_other = n_grads.row(2).dot(n_grads.row(2)) ;
          g_max = g_max > g_other ? g_max : g_other ;

          if(g_max == g_max) { //prevent nan
            ratio += g_max ;
          }
        }
      }
      triangle_weights[f] = pow(ratio,twfactor) ;
    }
  }

  //normal factor
  double nfactor = (double)CVTRemeshOptions_Number[2].def ; ;

  //weight the normal component by the provided factor
  for(unsigned int i = 0; i<lifted_mesh.vertices_size(); ++i) {
    double* v = lifted_vertices.data() + 6*i ;
    v[3]*= nfactor ;
    v[4]*= nfactor ;
    v[5]*= nfactor ;
  }

  //number of sites
  unsigned int nsites = (unsigned int)CVTRemeshOptions_Number[0].def ;

  //lifted sites
  std::vector<double> lifted_sites(6*nsites) ;
  if(twfactor > 0) {
    Revoropt::generate_random_sites< Revoropt::ROMesh<3,6> >(
      &lifted_mesh, nsites, lifted_sites.data(), triangle_weights.data()
    ) ;
  } else {
    Revoropt::generate_random_sites< Revoropt::ROMesh<3,6> >(
      &lifted_mesh, nsites, lifted_sites.data()
    ) ;
  }

  //setup the cvt minimizer
  Revoropt::CVT::DirectMinimizer< Revoropt::ROMesh<3,6> > cvt ;
  cvt.set_sites(lifted_sites.data(), nsites) ;
  cvt.set_mesh(&lifted_mesh) ;
  if(twfactor > 0) {
    cvt.set_triangle_weights(triangle_weights.data()) ;
  }

  //setup the callback
  SolverCallback callback ;

  //number of iterations
  unsigned int niter = (unsigned int)CVTRemeshOptions_Number[1].def ; ;
  unsigned int aniso_niter = std::min<unsigned int>(10,niter) ;

  //solver status
  int status = 0 ;

  //isotropic iterations
  if(niter > 10) {
    aniso_niter = std::max(aniso_niter,niter*10/100) ;
    cvt.set_anisotropy(1) ;
    status = cvt.minimize<Revoropt::Solver::AlgLBFGS>(niter-aniso_niter, &callback) ;
  }

  //anisotropic iterations
  if(niter > 0) {
    //tangent space anisotropy
    double tanisotropy = (double)CVTRemeshOptions_Number[4].def ; ;

    //anisotropic iterations
    cvt.set_anisotropy(tanisotropy) ;
    status = cvt.minimize<Revoropt::Solver::AlgLBFGS>(aniso_niter, &callback) ;
  }

  //rdt
  std::vector<unsigned int> rdt_triangles ;
  Revoropt::RDTBuilder< Revoropt::ROMesh<3,6> > build_rdt(rdt_triangles) ;
  Revoropt::RVD< Revoropt::ROMesh<3,6> > rvd ;
  rvd.set_sites(lifted_sites.data(), nsites) ;
  rvd.set_mesh(&lifted_mesh) ;
  rvd.compute(build_rdt) ;

  GFace* res_face = new discreteFace(m, m->getMaxElementaryNumber(2)+1) ;
  m->add(res_face) ;

  //scale back and transfer to gmsh
  std::vector<MVertex*> m_verts(nsites) ;
  for(unsigned int i = 0; i < nsites; ++i) {
    m_verts[i] = new MVertex(
        lifted_sites[6*i  ]*mesh_scale + mesh_center[0],
        lifted_sites[6*i+1]*mesh_scale + mesh_center[1],
        lifted_sites[6*i+2]*mesh_scale + mesh_center[2]
        ) ;
    res_face->addMeshVertex(m_verts[i]) ;
  }
  for(unsigned int i = 0; i < rdt_triangles.size()/3; ++i) {
    res_face->addTriangle(
      new MTriangle(
        m_verts[rdt_triangles[3*i  ]],
        m_verts[rdt_triangles[3*i+1]],
        m_verts[rdt_triangles[3*i+2]]
        )
    ) ;
  }

  res_face->setAllElementsVisible(true) ;

  return v ;
}
Example #23
0
R404AClass::R404AClass()
{
	static const double a[]={
		7.00407,		//[0]
		7.98695,		//[1]
		-18.8664,		//[2]
		0.63078,		//[3]
		3.5979,			//[4]
		5.0335			//[5]
	};

	static const double b[]={
		0,				//[0]
		0,				//[1]
		-0.3,			//[2]
		1.19617,		//[3]
		2.32861,		//[4]
		5.00188			//[5]
	};

	static const double N[]={
		 0.0,			//[0]
		 6.10984,		//[1]
		-7.79453,		//[2]
		 0.0183377,		//[3]
		 0.262270,		//[4]
		-0.00351688,	//[5]
		 0.0116181,		//[6]
		 0.00105992,	//[7]
		 0.850922,		//[8]
		-0.520084,		//[9]
		-0.0464225,		//[10]
		 0.621190,		//[11]
		-0.195505,		//[12]
		 0.336159,		//[13]
		-0.0376062,		//[14]
		-0.00636579,	//[15]
		-0.0758262,		//[16]
		-0.0221041,		//[17]
		 0.0310441,		//[18]
		 0.0132798,		//[19]
		 0.0689437,		//[20]
		-0.0507525,		//[21]
		 0.0161382,		//[22]
	};

	static const double t[]={
		0.0,			//[0]
		0.67,			//[1]
		0.91,			//[2]
		5.96,			//[3]
		0.7,			//[4]
		6.0,			//[5]
		0.3,			//[6]
		0.7,			//[7]
		1.7,			//[8]
		3.3,			//[9]
		7.0,			//[10]
		2.05,			//[11]
		4.3,			//[12]
		2.7,			//[13]
		1.8,			//[14]
		1.25,			//[15]
		12.0,			//[16]
		6.0,			//[17]
		8.7,			//[18]
		11.6,			//[19]
		13.0,			//[20]
		17.0,			//[21]
		16.0			//[22]
	};

	static const int d[]={
		0,				//[0]
		1,				//[1]
		1,				//[2]
		1,				//[3]
		2,				//[4]
		2,				//[5]
		4,				//[6]
		6,				//[7]
		1,				//[8]
		1,				//[9]
		1,				//[10]
		2,				//[11]
		2,				//[12]
		3,				//[13]
		4,				//[14]
		7,				//[15]
		2,				//[16]
		3,				//[17]
		4,				//[18]
		4,				//[19]
		2,				//[20]
		3,				//[21]
		5				//[22]
	};

	static const int l[]={
		0,				//[0]
		0,				//[1]
		0,				//[2]
		0,				//[3]
		0,				//[4]
		0,				//[5]
		0,				//[6]
		0,				//[7]
		1,				//[8]
		1,				//[9]
		1,				//[10]
		1,				//[11]
		1,				//[12]
		1,				//[13]
		1,				//[14]
		1,				//[15]
		2,				//[16]
		2,				//[17]
		2,				//[18]
		2,				//[19]
		3,				//[20]
		3,				//[21]
		3				//[22]
	};

	std::vector<double> n_v(N,N+sizeof(N)/sizeof(double));
	std::vector<double> d_v(d,d+sizeof(d)/sizeof(int));
	std::vector<double> t_v(t,t+sizeof(t)/sizeof(double));
	std::vector<double> l_v(l,l+sizeof(l)/sizeof(int));
	std::vector<double> a0(a,a+sizeof(a)/sizeof(double));
	std::vector<double> n0(b,b+sizeof(b)/sizeof(double));

	phi_BC * phir_ = new phir_power(n_v,d_v,t_v,l_v,1,22);
	phirlist.push_back(phir_);

	/*
	sum=log(delta)-log(tau)+a[0]+a[1]*tau+a[2]*pow(tau,b[2]);
	for(k=3;k<=5;k++)
	{
		sum+=a[k]*log(1.0-exp(-b[k]*tau));
	}
	*/
	phi_BC * phi0_lead_ = new phi0_lead(a0[0],a0[1]);
	phi_BC * phi0_logtau_ = new phi0_logtau(-1.0);
	phi_BC * phi0_power_ = new phi0_power(a0[2],n0[2]);
	phi_BC * phi0_Planck_Einstein_ = new phi0_Planck_Einstein(a0,n0,3,5);

	phi0list.push_back(phi0_lead_);
	phi0list.push_back(phi0_logtau_);
	phi0list.push_back(phi0_power_);
	phi0list.push_back(phi0_Planck_Einstein_);

	// Critical parameters (max condensing temperature)
	crit.rho = 482.162772;
	crit.p = PressureUnit(3734.8,UNIT_KPA);
	crit.T = 345.27;
	crit.v = 1.0/crit.rho;

	// Other fluid parameters
	params.molemass = 97.6038;
	params.Ttriple = 200.0;
	params.ptriple = 21.2656766151;
	params.accentricfactor = 0.293;
	params.R_u = 8.314472;
	isPure = false;

	// Limits of EOS
	limits.Tmin = params.Ttriple;
	limits.Tmax = 500.0;
	limits.pmax = 50000.0;
	limits.rhomax = 14.21*params.molemass;
	
	EOSReference.assign("E.W. Lemmon, \"Pseudo-pure fluid Equations of State for the Refrigerant Blends R410A, R404A, R507C and R407C\"" 
						",Int. J. Thermophys. v. 24, n4, 2003");
	TransportReference.assign("Viscosity: V. Geller, \"Viscosity of Mixed Refrigerants R404A,R407C,"
							"R410A, and R507A\", 2000 Purdue Refrigeration conferences\n\n"
							"Thermal Conductivity: V.Z. Geller, B.Z. Nemzer, and U.V. Cheremnykh \"Thermal Conductivity "
							"of the Refrigerant mixtures R404A,R407C,R410A, and R507A\" "
							"Int. J. Thermophysics, v. 22, n 4 2001\n\n"
							"Surface Tension: R. Heide, \"The surface tension of HFC refrigerants and mixtures\", Int J. Refrig. Vol. 20, No. 7, pp. 496-503, 1997");

	name.assign("R404A");
	aliases.push_back("R404a");

	BibTeXKeys.EOS = "Lemmon-IJT-2003";
	BibTeXKeys.VISCOSITY = "Geller-PURDUE-2000";
	BibTeXKeys.CONDUCTIVITY = "Geller-IJT-2001";
	BibTeXKeys.SURFACE_TENSION ="Heide-IJR-1997";
}
Example #24
0
void test_Polygon(int &failed_test_count, int &disabled_test_count)
{

const std::string GROUP = "Polygon";
const double EQT = 1.0e-15;

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "set_get_my_zone", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *f = new Polygon;
        size_t expected = 7;
        f->set_my_zone(expected);
        size_t actual = f->get_my_zone();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "set_get_my_id", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *f = new Polygon;
        short int expected = 7;
        f->set_my_id(expected);
        short int actual = f->get_my_id();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "ctor_check_my_zone", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        size_t mz = 6;
        short int mi = 9;
        Face *f = new Polygon(mz, mi);
        size_t expected = mz;
        size_t actual = f->get_my_zone();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "ctor_check_my_id", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        size_t mz = 6;
        short int mi = 9;
        Face *f = new Polygon(mz, mi);
        short int expected = mi;
        short int actual = f->get_my_id();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "size0", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *f = new Polygon;
        size_t expected = 0;
        size_t actual = f->size();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "size", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Vector3d v(1.0, 2.0, 3.0);
        Node n0(3, v);
        Node n1(5, v, v);
        Face *f = new Polygon;
        f->add_node(n0.geti());
        f->add_node(n1.geti());
        size_t expected = 2;
        size_t actual = f->size();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "is_curved", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Grid g;
        Face *f = new Polygon;
        Vector3d v(1.0, 2.0, 3.0);
        Node n0(3, v);
        f->add_node(n0.geti());
        f->add_node(n0.geti());
        f->add_node(n0.geti());
        bool expected = false;
        bool actual = f->is_curved(g);

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "is_flat", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Grid g;
        Face *f = new Polygon;
        Vector3d v(1.0, 2.0, 3.0);
        Node n0(3, v);
        f->add_node(n0.geti());
        f->add_node(n0.geti());
        f->add_node(n0.geti());
        bool expected = true;
        bool actual = f->is_flat(g);

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "get_node_id", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Vector3d v(1.0, 2.0, 3.0);
        Node n0(3, v);
        Node n1(5, v, v);
        Face *f = new Polygon;
        f->add_node(n0.geti());
        f->add_node(n1.geti());
        size_t expected = 5;
        size_t actual = f->get_node(1);

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "get_node_id_out_of_range", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Vector3d v(1.0, 2.0, 3.0);
        Node n0(3, v);
        Node n1(5, v, v);
        Face *f = new Polygon;
        f->add_node(n0.geti());
        f->add_node(n1.geti());
        std::string expected = "out of range exception";
        std::string actual = UNCAUGHT_EXCEPTION;
        try
        {
            size_t n = f->get_node(2);
            std::cout << n;
        }
        catch (const std::out_of_range &oor)
        {
            actual = "out of range exception";
        }

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "abs_diff", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *f = new Polygon(3, 1);
        Face *g = new Polygon(4, 5);
        f->add_node(6);
        g->add_node(2);
        g->add_node(9);
        g->add_node(4);
        double expected = 37.0;
        double actual = f->abs_diff(*g);

        failed_test_count += t.check_equal_real_num(expected, actual, EQT);
        delete f;
        delete g;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "to_string", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *f = new Polygon(3, 1);
        f->add_node(98765);
        f->add_node(98766);
        f->add_node(98767);
        f->add_node(98768);
        f->add_node(98769);
        std::string expected = "Polygon\n          5\n";
        expected += "          3          1\n";
        expected += "      98765      98766      98767      98768      98769";
        expected += "\n          neighbors          0";
        std::string actual = f->to_string();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "ctor0", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *expected = new Polygon(0, -2);
        Face *actual = new Polygon;

        failed_test_count += t.check_equal_real_obj(*expected, *actual, EQT);
        delete expected;
        delete actual;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "assignment", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *expected = new Polygon(4, 5);
        expected->add_node(2);
        expected->add_node(9);
        expected->add_node(4);
        Face *actual = new Polygon;
        *actual = *expected;

        failed_test_count += t.check_equal_real_obj(*expected, *actual, EQT);
        delete expected;
        delete actual;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "add_get_neighboring_zone", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *f = new Polygon(3, 1);
        f->add_neighbor(2, 4);
        f->add_neighbor(9, 5);
        size_t expected = 9;
        size_t actual = f->get_neighbor(1).my_zone;

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "add_get_neighboring_Polygon", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *f = new Polygon(3, 1);
        f->add_neighbor(2, 4);
        f->add_neighbor(9, 5);
        short int expected = 5;
        short int actual = f->get_neighbor(1).my_id;

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "neighbor_count", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *f = new Polygon(3, 1);
        f->add_neighbor(2, 4);
        f->add_neighbor(9, 5);
        size_t expected = 2;
        size_t actual = f->num_nbr();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "add_get_neighbor_out_of_range", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        Face *f = new Polygon(3, 1);
        f->add_neighbor(2, 4);
        f->add_neighbor(9, 5);
        std::string expected = "out of range exception";
        std::string actual = UNCAUGHT_EXCEPTION;
        try
        {
            FaceID n = f->get_neighbor(5);
            std::cout << n.my_zone << " " << n.my_id;
        }
        catch (const std::out_of_range &oor)
        {
            actual = "out of range exception";
        }

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "area2_normal_triangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "triangle.inc"
        Vector3d expected(4.0, 3.0, 12.0);
        Vector3d actual = f->area2_normal_center(g, v);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "area2_normal_rectangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        Vector3d expected(0.0, 0.0, 12.0);
        Vector3d actual = f->area2_normal_center(g, v);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "area2_normal_trapezoid", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "trapezoid.inc"
        Vector3d expected(0.0, 0.0, 8.0);
        Vector3d actual = f->area2_normal_center(g, v);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "area2_normal_hexagon", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "hexagon.inc"
        Vector3d expected = Vector3d(0.0, 0.0, -6.0*r*s);
        Vector3d actual = f->area2_normal_center(g, v);

        failed_test_count += t.check_equal_real_obj(expected, actual, 10*EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "center_triangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "triangle.inc"
        Vector3d expected(1.0, 4.0/3.0, 1.0/3.0);
        Vector3d actual;
        f->area2_normal_center(g, actual);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "center_rectangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        Vector3d expected(2.0, 2.5, 5.0);
        Vector3d actual;
        f->area2_normal_center(g, actual);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "center_trapezoid", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "trapezoid.inc"
        Vector3d expected(13.0/12.0, 5.0/6.0, 0.0);
        Vector3d actual;
        f->area2_normal_center(g, actual);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "center_hexagon", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "hexagon.inc"
        Vector3d expected = center;
        Vector3d actual;
        f->area2_normal_center(g, actual);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "normal_triangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "triangle.inc"
        Vector3d expected(4.0/13.0, 3.0/13.0, 12.0/13.0);
        Vector3d actual = f->normal(g);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "normal_rectangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        Vector3d expected(0.0, 0.0, 1.0);
        Vector3d actual = f->normal(g);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "area_triangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "triangle.inc"
        double expected = 6.5;
        double actual = f->area(g);

        failed_test_count += t.check_equal_real_num(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "area_rectangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        double expected = 6.0;
        double actual = f->area(g);

        failed_test_count += t.check_equal_real_num(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "signed_distance_triangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "triangle.inc"
        Vector3d c;
        v = Vector3d(1.0, 4.0/3.0, 1.0/3.0) + f->area2_normal_center(g, c)/5;
        double expected = 2.6;
        double actual = f->distance(g, v);

        failed_test_count += t.check_equal_real_num(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "signed_distance_rectangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        v = Vector3d(7.0, 6.0, -4.0);
        double expected = -9.0;
        double actual = f->distance(g, v);

        failed_test_count += t.check_equal_real_num(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "subpoint_triangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "triangle.inc"
        Vector3d expected = Vector3d(1.0, 4.0/3.0, 1.0/3.0);
        Vector3d c;
        v = expected + f->area2_normal_center(g, c)/5;
        Vector3d actual = f->subpoint(g, v);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "subpoint_rectangle", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        v = Vector3d(7.0, 6.0, -4.0);
        Vector3d expected = Vector3d(7.0, 6.0, 5.0);
        Vector3d actual = f->subpoint(g, v);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_has_point_above", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "triangle.inc"
        Vector3d c;
        v = Vector3d(1.0, 4.0/3.0, 1.0/3.0) + f->area2_normal_center(g, c)/5;
        bool expected = true;
        bool actual = f->has_above(g, v);

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "rectangle_has_point_above", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        v = Vector3d(7.0, 6.0, -4.0);
        bool expected = false;
        bool actual = f->has_above(g, v);

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_has_point_below", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "triangle.inc"
        Vector3d c;
        v = Vector3d(1.0, 4.0/3.0, 1.0/3.0) + f->area2_normal_center(g, c)/5;
        bool expected = false;
        bool actual = f->has_below(g, v);

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "rectangle_has_point_below", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        v = Vector3d(7.0, 6.0, -4.0);
        bool expected = true;
        bool actual = f->has_below(g, v);

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_contains_point", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "triangle.inc"
        v = Vector3d(1.0, 4.0/3.0, 1.0/3.0);
        bool expected = true;
        bool actual = f->contains(g, v);
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "rectangle_contains_point", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        v = Vector3d(2.0, 3.0, 5.0);
        bool expected = true;
        bool actual = f->contains(g, v);
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "rectangle_misses_point", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        v = Vector3d(7.0, 6.0, 5.0);
        bool expected = false;
        bool actual = f->contains(g, v);
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "rectangle_first_edge_contains_point", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        v = Vector3d(2.0, 1.0, 5.0);
        bool expected = true;
        bool actual = f->contains(g, v);
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "rectangle_first_edge_misses_point", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        v = Vector3d(4.0, 1.0, 5.0);
        bool expected = false;
        bool actual = f->contains(g, v);
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "rectangle_another_edge_contains_point", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        v = Vector3d(2.0, 4.0, 5.0);
        bool expected = true;
        bool actual = f->contains(g, v);
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "rectangle_another_edge_misses_point", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "rectangle.inc"
        v = Vector3d(4.0, 4.0, 5.0);
        bool expected = false;
        bool actual = f->contains(g, v);
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_distance", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(1.0, 4.0/3.0, 1.0/3.0);
        Vector3d w;
        double expected = 1.0;
        double actual = f->intercept(g, r, v, EQT, fid).t;

        failed_test_count += t.check_equal_real_num(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_point", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(1.0, 4.0/3.0, 1.0/3.0);
        Vector3d expected = v;
        Vector3d actual = f->intercept(g, r, v, EQT, fid).w;

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_face", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(1.0, 4.0/3.0, 1.0/3.0);
        FaceID expected = FaceID(2, 1);
        FaceID actual = f->intercept(g, r, v, EQT, fid).fid;

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_found", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(1.0, 4.0/3.0, 1.0/3.0);
        bool expected = true;
        bool actual = f->intercept(g, r, v, EQT, fid).is_found;

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_found_same_face", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(2, 1); // difference from triangle_intercept_found
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(1.0, 4.0/3.0, 1.0/3.0);
        bool expected = false; // difference from triangle_intercept_found
        bool actual = f->intercept(g, r, v, EQT, fid).is_found;

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_distance_negative", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(-1.0, -4.0/3.0, -1.0/3.0);
        Vector3d w;
        double expected = -1.0;
        double actual = f->intercept(g, r, v, EQT, fid).t;

        failed_test_count += t.check_equal_real_num(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_point_negative", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(-1.0, -4.0/3.0, -1.0/3.0);
        Vector3d expected = -v;
        Vector3d actual = f->intercept(g, r, v, EQT, fid).w;
        
        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_found_negative", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(-1.0, -4.0/3.0, -1.0/3.0);
        bool expected = false;
        bool actual = f->intercept(g, r, v, EQT, fid).is_found;
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_distance_0", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(1.0, 4.0/3.0, 1.0/3.0);
        v = Vector3d(-1.0, -4.0/3.0, -1.0/3.0);
        Vector3d w;
        double expected = 0.0;
        double actual = f->intercept(g, r, v, EQT, fid).t;

        failed_test_count += t.check_equal_real_num(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_point_0", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(1.0, 4.0/3.0, 1.0/3.0);
        v = Vector3d(-1.0, -4.0/3.0, -1.0/3.0);
        Vector3d expected = -v;
        Vector3d actual = f->intercept(g, r, v, EQT, fid).w;
        
        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_found_0", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(1.0, 4.0/3.0, 1.0/3.0);
        v = Vector3d(-1.0, -4.0/3.0, -1.0/3.0);
        bool expected = false;
        bool actual = f->intercept(g, r, v, EQT, fid).is_found;
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_distance_parallel", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(-3.0, 0.0, 1.0); // parallel to the plane
        Vector3d w;
        double expected = -Vector3d::get_big();
        double actual = f->intercept(g, r, v, EQT, fid).t;

        failed_test_count += t.check_equal_real_num(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_point_parallel", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(-3.0, 0.0, 1.0); // parallel to the plane
        double big = -Vector3d::get_big();
        Vector3d expected(big, big, big);
        Vector3d actual = f->intercept(g, r, v, EQT, fid).w;

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "triangle_intercept_found_parallel", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "triangle.inc"
        Vector3d r(0.0, 0.0, 0.0);
        v = Vector3d(-3.0, 0.0, 1.0); // parallel to the plane
        bool expected = false;
        bool actual = f->intercept(g, r, v, EQT, fid).is_found;

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "rectangle_contains_intercept", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "rectangle.inc"
        Vector3d r(2.0, 2.0, 0.0);
        v = Vector3d(0.0, 0.0, 1.0);
        bool expected = true;
        bool actual = f->intercept(g, r, v, EQT, fid).is_found;
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "rectangle_does_not_contain_intercept", "fast");
    
    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        FaceID fid(9, 8);
        #include "rectangle.inc"
        Vector3d r(-2.0, -2.0, 0.0);
        v = Vector3d(0.0, 0.0, 1.0);
        bool expected = false;
        bool actual = f->intercept(g, r, v, EQT, fid).is_found;
        
        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "velocity_triangle", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "velocity_triangle.inc"
        Vector3d c(1.0, 4.0/3.0, 1.0/3.0);
        Vector3d expected(4.3677256019137740,
                          1.4401036616521570,
                          0.8384202999809531);
        Vector3d actual = f->velocity(g, c);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "velocity_triangle_at_x", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "velocity_triangle.inc"
        Vector3d c(3.0, 0.0, 0.0);
        Vector3d expected(4.0, -3.0, 2.0);
        Vector3d actual = f->velocity(g, c);

        failed_test_count += t.check_equal_real_obj(expected, actual, EQT);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "clear_get_size", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "velocity_triangle.inc"
        f->clear();
        size_t expected = 0;
        size_t actual = f->size();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "clear_get_Node", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "velocity_triangle.inc"
        f->clear();
        std::string expected("out of range exception");
        std::string actual = UNCAUGHT_EXCEPTION;
        try
        {
            f->get_node(0);
        }
        catch (const std::out_of_range &oor)
        {
            actual = "out of range exception";
        }

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "clear_num_nbr", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "velocity_triangle.inc"
        f->clear();
        size_t expected = 0;
        size_t actual = f->num_nbr();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "clear_get_Neighbor", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "velocity_triangle.inc"
        f->clear();
        std::string expected("out of range exception");
        std::string actual = UNCAUGHT_EXCEPTION;
        try
        {
            f->get_neighbor(0);
        }
        catch (const std::out_of_range &oor)
        {
            actual = "out of range exception";
        }

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "clear_get_my_zone", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "velocity_triangle.inc"
        f->clear();
        size_t expected = 0;
        size_t actual = f->get_my_zone();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "clear_get_my_id", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        #include "velocity_triangle.inc"
        f->clear();
        short int expected = -2;
        short int actual = f->get_my_id();

        failed_test_count += t.check_equal(expected, actual);
        delete f;
    }
}

//-----------------------------------------------------------------------------

{
    Test t(GROUP, "load_Hydro1_Mesh0_1st_Polygon", "fast");

    check_to_disable_test(t, disabled_test_count);
    if (t.is_enabled())
    {
        std::string path(cnst::PATH + "UniTest/Hydro1/");
        std::string tlabel("0");
        std::string fname = path + "mesh_" + tlabel + ".txt";
        std::ifstream infile(fname.c_str());
        utils::find_line(infile, "Polygon");
        Polygon f(infile);
        infile.close();
        infile.clear();
        std::string expected("Polygon\n          4\n          0         -1\n");
        expected += "          0          1          5          4\n";
        expected += "          neighbors          1\n          1          0";
        std::string actual = f.to_string();

        failed_test_count += t.check_equal(expected, actual);
    }
}

//-----------------------------------------------------------------------------

}
bool UnitCylinder::intersect( Ray3D& ray, const Matrix4x4& worldToModel,
		const Matrix4x4& modelToWorld ) {

	Ray3D r;
	r.origin = worldToModel * ray.origin;
	r.dir = worldToModel * ray.dir;

	Point3D cylinder(0,0,0);

	double int0, int1, int2, int3, t, t1;
	double a = r.dir[0] * r.dir[0] + r.dir[1] * r.dir[1];
	double b = r.origin[0] * r.dir[0] + r.origin[1] * r.dir[1];
	double c = r.origin[0] * r.origin[0] + r.origin[1] * r.origin[1] - 1;
	double d = b * b - a * c;

	if (d < 0) return false;

	int0 = (-b + sqrt(d)) / a;
	int1 = (-b - sqrt(d)) / a;
	if (int0 < 0 && int1 < 0) return false;
	else if (int0 > 0 && int1 < 0) t = int0;
	else t = int1;

	int2 = ( -0.5 - r.origin[2])/r.dir[2];
	int3 = ( 0.5 - r.origin[2])/r.dir[2];

	t1 = int2 < int3 ? int2 : int3;
	if (t1 * t1 < 0.001) return false;
	if (t * t < 0.001) return false;
	Point3D n0(0,0,1);
	Point3D n1(0,0,-1);
	Vector3D tn0;
	if (int2 < int3) tn0 = n1 - cylinder;
	else tn0 = n0 - cylinder;
	tn0.normalize();

	Point3D pint = r.origin + t1 * r.dir;

	if (pint[0]* pint[0] + pint[1] * pint[1] <= 1) {
		
		if (ray.intersection.none || ray.intersection.t_value > int3) {

			ray.intersection.t_value = t1;
			ray.intersection.point = pint;
			ray.intersection.none = false;
			ray.intersection.normal = tn0;
			return true;
		} 
	}

	pint = r.origin + t * r.dir;

	Vector3D tn1(pint[0], pint[1], 0);
	tn1.normalize();

	if (pint[2] < 0.5 && pint[2] > -0.5) {

		if (ray.intersection.none || ray.intersection.t_value > int3) {

			ray.intersection.t_value = t;
			ray.intersection.point = modelToWorld * pint;
			ray.intersection.none = false;
			ray.intersection.normal = modelToWorld * tn1;
			return true;

		} 	
	}

	return false;

	
}
Example #26
0
R507AClass::R507AClass()
{
	std::vector<double> n_v(N,N+sizeof(N)/sizeof(double));
	std::vector<double> d_v(d,d+sizeof(d)/sizeof(int));
	std::vector<double> t_v(t,t+sizeof(t)/sizeof(double));
	std::vector<double> l_v(l,l+sizeof(l)/sizeof(int));
	std::vector<double> a0(a,a+sizeof(a)/sizeof(double));
	std::vector<double> n0(b,b+sizeof(b)/sizeof(double));

	phi_BC * phir_ = new phir_power(n_v,d_v,t_v,l_v,1,22);
	phirlist.push_back(phir_);

	/*
	sum=log(delta)-log(tau)+a[0]+a[1]*tau+a[2]*pow(tau,b[2]);
	for(k=3;k<=5;k++)
	{
		sum+=a[k]*log(1.0-exp(-b[k]*tau));
	}
	*/
	phi_BC * phi0_lead_ = new phi0_lead(a0[0],a0[1]);
	phi_BC * phi0_logtau_ = new phi0_logtau(-1.0);
	phi_BC * phi0_power_ = new phi0_power(a0[2],n0[2]);
	phi_BC * phi0_Planck_Einstein_ = new phi0_Planck_Einstein(a0,n0,3,5);

	phi0list.push_back(phi0_lead_);
	phi0list.push_back(phi0_logtau_);
	phi0list.push_back(phi0_power_);
	phi0list.push_back(phi0_Planck_Einstein_);

	// Critical parameters (max condensing temperature)
	crit.rho = 490.74;
	crit.p = PressureUnit(3704.9,UNIT_KPA);
	crit.T = 343.765;
	crit.v = 1.0/crit.rho;

	// Other fluid parameters
	params.molemass = 98.8592;
	params.Ttriple = 200.0;
	params.ptriple = 23.2234432758;
	params.accentricfactor = 0.286;
	params.R_u = 8.314472;
	isPure = false;

	// Limits of EOS
	limits.Tmin = params.Ttriple;
	limits.Tmax = 500.0;
	limits.pmax = 50000.0;
	limits.rhomax = 14.13*params.molemass;
	
	EOSReference.assign("E.W. Lemmon, \"Pseudo-pure fluid Equations of State for the Refrigerant Blends R410A, R404A, R507C and R407C\"" 
						",Int. J. Thermophys. v. 24, n4, 2003");
	TransportReference.assign("Viscosity: V. Geller, \"Viscosity of Mixed Refrigerants R404A,R407C,"
							"R410A, and R507A\", 2000 Purdue Refrigeration conferences\n\n"
							"Thermal Conductivity: V.Z. Geller, B.Z. Nemzer, and U.V. Cheremnykh \"Thermal Conductivity "
							"of the Refrigerant mixtures R404A,R407C,R410A, and R507A\" "
							"Int. J. Thermophysics, v. 22, n 4 2001");

	name.assign("R507A");
	aliases.push_back("R507a");

	BibTeXKeys.EOS = "Lemmon-IJT-2003";
	BibTeXKeys.VISCOSITY = "Geller-PURDUE-2000";
	BibTeXKeys.CONDUCTIVITY = "Geller-IJT-2001";
	
}
Example #27
0
void sctensdigit(int a) //ten's place
{
 s=30;
 xnxt=400-45;
 ynxt=100;
 w9=w8=w4=w6=w5=w2=w3=w7=w0=wk=we=wf=wj=wl=wp=wr=ws=s/2;//1/2
 w1=wi=s/4;
 wg=wc=wh=wn=wb=wu=wt=wv=wx=wy=2*s/3;//2/3
 ww=wm=wa=wd=wo=wq=wz=3*s/4;//3/4
 h=s;//1
glColor3f(0,0,0);
glPointSize(2.0);
switch(a)
{
case 0:n0(xnxt,ynxt,h,w0);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 1:n1(xnxt,ynxt,h,w1);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 2: n2(xnxt,ynxt,h,w2);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 3: n3(xnxt,ynxt,h,w3);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 4: n4(xnxt,ynxt,h,w4);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 5: n5(xnxt,ynxt,h,w5);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 6: n6(xnxt,ynxt,h,w6);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 7: n7(xnxt,ynxt,h,w7);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 8: n8(xnxt,ynxt,h,w8);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

case 9: n9(xnxt,ynxt,h,w9);
xnxt-=(w1+sp);
ynxt-=3*s/2;
break;

default: break;
}
glFlush();
return ;
}
Example #28
0
// Collide and edge and polygon. This uses the SAT and clipping to produce up to 2 contact points.
// Edge adjacency is handle to produce locally valid contact points and normals. This is intended
// to allow the polygon to slide smoothly over an edge chain.
//
// Algorithm
// 1. Classify front-side or back-side collision with edge.
// 2. Compute separation
// 3. Process adjacent edges
// 4. Classify adjacent edge as convex, flat, null, or concave
// 5. Skip null or concave edges. Concave edges get a separate manifold.
// 6. If the edge is flat, compute contact points as normal. Discard boundary points.
// 7. If the edge is convex, compute it's separation.
// 8. Use the minimum separation of up to three edges. If the minimum separation
//    is not the primary edge, return.
// 9. If the minimum separation is the primary edge, compute the contact points and return.
void b2CollideEdgeAndPolygon(	b2Manifold* manifold,
								const b2EdgeShape* edgeA, const b2Transform& xfA,
								const b2PolygonShape* polygonB_in, const b2Transform& xfB)
{
	manifold->pointCount = 0;

	b2Transform xf = b2MulT(xfA, xfB);

	// Create a polygon for edge shape A
	b2PolygonShape polygonA;
	polygonA.SetAsEdge(edgeA->m_vertex1, edgeA->m_vertex2);

	// Build polygonB in frame A
	b2PolygonShape polygonB;
	polygonB.m_radius = polygonB_in->m_radius;
	polygonB.m_vertexCount = polygonB_in->m_vertexCount;
	polygonB.m_centroid = b2Mul(xf, polygonB_in->m_centroid);
	for (int32 i = 0; i < polygonB.m_vertexCount; ++i)
	{
		polygonB.m_vertices[i] = b2Mul(xf, polygonB_in->m_vertices[i]);
		polygonB.m_normals[i] = b2Mul(xf.R, polygonB_in->m_normals[i]);
	}

	float32 totalRadius = polygonA.m_radius + polygonB.m_radius;

	// Edge geometry
	b2Vec2 v1 = edgeA->m_vertex1;
	b2Vec2 v2 = edgeA->m_vertex2;
	b2Vec2 e = v2 - v1;
	b2Vec2 edgeNormal(e.y, -e.x);
	edgeNormal.Normalize();

	// Determine side
	bool isFrontSide = b2Dot(edgeNormal, polygonB.m_centroid - v1) >= 0.0f;
	if (isFrontSide == false)
	{
		edgeNormal = -edgeNormal;
	}

	// Compute primary separating axis
	b2EPAxis edgeAxis = b2EPEdgeSeparation(v1, v2, edgeNormal, &polygonB, totalRadius);
	if (edgeAxis.separation > totalRadius)
	{
		// Shapes are separated
		return;
	}

	// Classify adjacent edges
	b2EdgeType types[2] = {b2_isolated, b2_isolated};
	if (edgeA->m_hasVertex0)
	{
		b2Vec2 v0 = edgeA->m_vertex0;
		float32 s = b2Dot(edgeNormal, v0 - v1);

		if (s > 0.1f * b2_linearSlop)
		{
			types[0] = b2_concave;
		}
		else if (s >= -0.1f * b2_linearSlop)
		{
			types[0] = b2_flat;
		}
		else
		{
			types[0] = b2_convex;
		}
	}

	if (edgeA->m_hasVertex3)
	{
		b2Vec2 v3 = edgeA->m_vertex3;
		float32 s = b2Dot(edgeNormal, v3 - v2);
		if (s > 0.1f * b2_linearSlop)
		{
			types[1] = b2_concave;
		}
		else if (s >= -0.1f * b2_linearSlop)
		{
			types[1] = b2_flat;
		}
		else
		{
			types[1] = b2_convex;
		}
	}

	if (types[0] == b2_convex)
	{
		// Check separation on previous edge.
		b2Vec2 v0 = edgeA->m_vertex0;
		b2Vec2 e0 = v1 - v0;

		b2Vec2 n0(e0.y, -e0.x);
		n0.Normalize();
		if (isFrontSide == false)
		{
			n0 = -n0;
		}

		b2EPAxis axis1 = b2EPEdgeSeparation(v0, v1, n0, &polygonB, totalRadius);
		if (axis1.separation > edgeAxis.separation)
		{
			// The polygon should collide with previous edge
			return;
		}
	}

	if (types[1] == b2_convex)
	{
		// Check separation on next edge.
		b2Vec2 v3 = edgeA->m_vertex3;
		b2Vec2 e2 = v3 - v2;

		b2Vec2 n2(e2.y, -e2.x);
		n2.Normalize();
		if (isFrontSide == false)
		{
			n2 = -n2;
		}

		b2EPAxis axis2 = b2EPEdgeSeparation(v2, v3, n2, &polygonB, totalRadius);
		if (axis2.separation > edgeAxis.separation)
		{
			// The polygon should collide with the next edge
			return;
		}
	}

	b2EPAxis polygonAxis = b2EPPolygonSeparation(v1, v2, edgeNormal, &polygonB, totalRadius);
	if (polygonAxis.separation > totalRadius)
	{
		return;
	}

	// Use hysteresis for jitter reduction.
	const float32 k_relativeTol = 0.98f;
	const float32 k_absoluteTol = 0.001f;

	b2EPAxis primaryAxis;
	if (polygonAxis.separation > k_relativeTol * edgeAxis.separation + k_absoluteTol)
	{
		primaryAxis = polygonAxis;
	}
	else
	{
		primaryAxis = edgeAxis;
	}

	b2PolygonShape* poly1;
	b2PolygonShape* poly2;
	b2ClipVertex incidentEdge[2];
	if (primaryAxis.type == b2EPAxis::e_edgeA)
	{
		poly1 = &polygonA;
		poly2 = &polygonB;
		if (isFrontSide == false)
		{
			primaryAxis.index = 1;
		}
		manifold->type = b2Manifold::e_faceA;
	}
	else
	{
		poly1 = &polygonB;
		poly2 = &polygonA;
		manifold->type = b2Manifold::e_faceB;
	}

	int32 edge1 = primaryAxis.index;

	b2FindIncidentEdge(incidentEdge, poly1, primaryAxis.index, poly2);
	int32 count1 = poly1->m_vertexCount;
	const b2Vec2* vertices1 = poly1->m_vertices;

	int32 iv1 = edge1;
	int32 iv2 = edge1 + 1 < count1 ? edge1 + 1 : 0;

	b2Vec2 v11 = vertices1[iv1];
	b2Vec2 v12 = vertices1[iv2];

	b2Vec2 tangent = v12 - v11;
	tangent.Normalize();
	
	b2Vec2 normal = b2Cross(tangent, 1.0f);
	b2Vec2 planePoint = 0.5f * (v11 + v12);

	// Face offset.
	float32 frontOffset = b2Dot(normal, v11);

	// Side offsets, extended by polytope skin thickness.
	float32 sideOffset1 = -b2Dot(tangent, v11) + totalRadius;
	float32 sideOffset2 = b2Dot(tangent, v12) + totalRadius;

	// Clip incident edge against extruded edge1 side edges.
	b2ClipVertex clipPoints1[2];
	b2ClipVertex clipPoints2[2];
	int np;

	// Clip to box side 1
	np = b2ClipSegmentToLine(clipPoints1, incidentEdge, -tangent, sideOffset1, iv1);

	if (np < b2_maxManifoldPoints)
	{
		return;
	}

	// Clip to negative box side 1
	np = b2ClipSegmentToLine(clipPoints2, clipPoints1,  tangent, sideOffset2, iv2);

	if (np < b2_maxManifoldPoints)
	{
		return;
	}

	// Now clipPoints2 contains the clipped points.
	if (primaryAxis.type == b2EPAxis::e_edgeA)
	{
		manifold->localNormal = normal;
		manifold->localPoint = planePoint;
	}
	else
	{
		manifold->localNormal = b2MulT(xf.R, normal);
		manifold->localPoint = b2MulT(xf, planePoint);
	}

	int32 pointCount = 0;
	for (int32 i = 0; i < b2_maxManifoldPoints; ++i)
	{
		float32 separation;
		
		separation = b2Dot(normal, clipPoints2[i].v) - frontOffset;

		if (separation <= totalRadius)
		{
			b2ManifoldPoint* cp = manifold->points + pointCount;

			if (primaryAxis.type == b2EPAxis::e_edgeA)
			{
				cp->localPoint = b2MulT(xf, clipPoints2[i].v);
				cp->id = clipPoints2[i].id;
			}
			else
			{
				cp->localPoint = clipPoints2[i].v;
				cp->id.cf.typeA = clipPoints2[i].id.cf.typeB;
				cp->id.cf.typeB = clipPoints2[i].id.cf.typeA;
				cp->id.cf.indexA = clipPoints2[i].id.cf.indexB;
				cp->id.cf.indexB = clipPoints2[i].id.cf.indexA;
			}

			if (cp->id.cf.typeA == b2ContactFeature::e_vertex && types[cp->id.cf.indexA] == b2_flat)
			{
				continue;
			}

			++pointCount;
		}
	}

	manifold->pointCount = pointCount;
}
Example #29
0
// Compute allowable normal ranges based on adjacency.
// A normal n is allowable iff:
// cross(n, n1) >= 0.0f && cross(n2, n) >= 0.0f
// n points from A to B (edge to polygon)
void b2EPCollider::ComputeAdjacency()
{
	b2Vec2 v0 = m_edgeA.v0;
	b2Vec2 v1 = m_edgeA.v1;
	b2Vec2 v2 = m_edgeA.v2;
	b2Vec2 v3 = m_edgeA.v3;

	// Determine allowable the normal regions based on adjacency.
	// Note: it may be possible that no normal is admissable.
	b2Vec2 centerB = m_proxyB.centroid;
	if (m_edgeA.hasVertex0)
	{
		b2Vec2 e0 = v1 - v0;
		b2Vec2 e1 = v2 - v1;
		b2Vec2 n0(e0.y, -e0.x);
		b2Vec2 n1(e1.y, -e1.x);
		n0.Normalize();
		n1.Normalize();

		bool convex = b2Cross(n0, n1) >= 0.0f;
		bool front0 = b2Dot(n0, centerB - v0) >= 0.0f;
		bool front1 = b2Dot(n1, centerB - v1) >= 0.0f;

		if (convex)
		{
			if (front0 || front1)
			{
				m_limit11 = n1;
				m_limit12 = n0;
			}
			else
			{
				m_limit11 = -n1;
				m_limit12 = -n0;
			}
		}
		else
		{
			if (front0 && front1)
			{
				m_limit11 = n0;
				m_limit12 = n1;
			}
			else
			{
				m_limit11 = -n0;
				m_limit12 = -n1;
			}
		}
	}
	else
	{
		m_limit11.SetZero();
		m_limit12.SetZero();
	}

	if (m_edgeA.hasVertex3)
	{
		b2Vec2 e1 = v2 - v1;
		b2Vec2 e2 = v3 - v2;
		b2Vec2 n1(e1.y, -e1.x);
		b2Vec2 n2(e2.y, -e2.x);
		n1.Normalize();
		n2.Normalize();

		bool convex = b2Cross(n1, n2) >= 0.0f;
		bool front1 = b2Dot(n1, centerB - v1) >= 0.0f;
		bool front2 = b2Dot(n2, centerB - v2) >= 0.0f;

		if (convex)
		{
			if (front1 || front2)
			{
				m_limit21 = n2;
				m_limit22 = n1;
			}
			else
			{
				m_limit21 = -n2;
				m_limit22 = -n1;
			}
		}
		else
		{
			if (front1 && front2)
			{
				m_limit21 = n1;
				m_limit22 = n2;
			}
			else
			{
				m_limit21 = -n1;
				m_limit22 = -n2;
			}
		}
	}
	else
	{
		m_limit21.SetZero();
		m_limit22.SetZero();
	}
}
Example #30
0
//  This is test for onedAST.py
int main(int argc, char** argv)
{
    int     npt     = 20;       // No. points to sample on test printing
    int     k       = 5;        // order of wavelet
    double  thresh  = 1e-12;    // truncation threshold

    // Step. 1          (Done!!!!)
    FunctionAST f1(k, thresh, test1);
    FunctionAST f2(k, thresh, test2);
    FunctionAST f4(k, thresh, sinn);
    
    // Step. 2
    f1.func->compress(0, 0);
    f2.func->compress(0, 0);
   
    //dic_print_tree(f1.func->s, "f1");
    //dic_print_tree(f2.func->s, "f2");
    //dic_print_tree(f4.func->s, "f4");

    // Step. 3
    FunctionAST resultAST(k, thresh, NULL);
    FunctionAST newresult(k, thresh, NULL);
  
    // Step. 4
    Node n0(&f1, 0, 0, 0, 0, 0, 0);
    Node n1(&f2, 0, 0, 0, 0, 0, 0);
    Node n2(&f2, 0, 0, 0, 0, 0, 0);
    Node n4(&f4, 0, 0, 0, 0, 0, 0);
    Node n6(&f4, 0, 0, 0, 0, 0, 0);

    // Step. 5
    // Reconstruct ASTs n1, n2, n22, n3
    AST* ast01 = ast_create_item(2,  NULL,   NULL);
    AST* ast02 = ast_create_item(0,  &n0,    NULL);
    ast_insert_item(ast02, ast01);

    AST* ast11 = ast_create_item(2,  NULL,   NULL);
    AST* ast12 = ast_create_item(0,  &n1,    NULL);
    ast_insert_item(ast12, ast11);

    AST* ast21 = ast_create_item(2, NULL,    NULL);
    AST* ast22 = ast_create_item(0, &n2,     NULL);
    ast_insert_item(ast22, ast21);
    
    // Step. 6
    AST* ast51 = ast_create_item(3,  NULL,   NULL);
    AST* ast52 = ast_create_item(0,  &n6,    NULL);
    ast_insert_item(ast52, ast51);

    // Create a full AST that computes (f1 + f2) * (f2 + f4 + diff(f4))
    // AST_ADD0 = [0, AST0, AST2]
    AST* add01 = ast_create_item(0,  NULL,   NULL);
    AST* add02 = ast_create_item(0,  NULL,   ast01);
    AST* add03 = ast_create_item(0,  NULL,   ast21);
    ast_insert_item(add02, add01);
    ast_insert_item(add03, add01);

    // AST_ADD1 = [0, AST1, n4, AST5]
    AST* add11 = ast_create_item(0,  NULL,   NULL);
    AST* add12 = ast_create_item(0,  NULL,   ast11);
    AST* add13 = ast_create_item(0,  &n4,    NULL);
    AST* add14 = ast_create_item(0,  NULL,   ast51);
    ast_insert_item(add12, add11);
    ast_insert_item(add13, add11);
    ast_insert_item(add14, add11);

    // AST_MUL  = [1, AST_ADD0, AST_ADD1]
    AST* mul1 = ast_create_item(1,  NULL,   NULL);
    AST* mul2 = ast_create_item(0,  NULL,   add01);
    AST* mul3 = ast_create_item(0,  NULL,   add11);
    ast_insert_item(mul2, mul1);
    ast_insert_item(mul3, mul1); 

    // Compute using onsedAST
    resultAST.traverse_tree(mul1, 0, 0);    
    printf ("\nAfter computing using onsedAST\n");
   
    //dic_print_tree_python(resultAST.func->s, 0, 0);

    // Compute (f1 + f2) * (f2 + f4 + diff(f4)) using original madpy without AST
    FunctionAST*    r_add0;
    FunctionAST*    r_add1;
    FunctionAST*    r_diff  = new FunctionAST(k, thresh, NULL);
    FunctionAST*    r_add5;
    FunctionAST*    r_prod;
    FunctionAST*    df;

    //dic_print_tree_python(f4.func->s, 0, 0);

    r_add0          = f1 + &f2;
    r_add1          = f2 + &f4;
    r_diff->func    = f4.func->diff(0, 0, NULL);
    r_add5          = *r_add1 + r_diff;
    r_prod          = *r_add0 * r_add5;
    r_prod->func->reconstruct(0, 0);

    df              = resultAST - r_prod;
    printf ("Norm of Difference is %12.8f\n", df->func->norm2());
}