Ejemplo n.º 1
0
void RSA_TestInstantiations()
{
	RSASS<PKCS1v15, SHA1>::Verifier x1(1, 1);
	RSASS<PKCS1v15, SHA1>::Signer x2(NullRNG(), 1);
	RSASS<PKCS1v15, SHA1>::Verifier x3(x2);
	RSASS<PKCS1v15, SHA1>::Verifier x4(x2.GetKey());
	RSASS<PSS, SHA1>::Verifier x5(x3);
#ifndef __MWERKS__
	RSASS<PSSR, SHA1>::Signer x6 = x2;
	x3 = x2;
	x6 = x2;
#endif
	RSAES<PKCS1v15>::Encryptor x7(x2);
#ifndef __GNUC__
	RSAES<PKCS1v15>::Encryptor x8(x3);
#endif
	RSAES<OAEP<SHA1> >::Encryptor x9(x2);
	x4 = x2.GetKey();

	RSASS<PKCS1v15, SHA3_256>::Verifier x10(1, 1);
	RSASS<PKCS1v15, SHA3_256>::Signer x11(NullRNG(), 1);
	RSASS<PKCS1v15, SHA3_256>::Verifier x12(x11);
	RSASS<PKCS1v15, SHA3_256>::Verifier x13(x11.GetKey());
}
Ejemplo n.º 2
0
int main(void)
{
  // 3.4.5 Class member access
  // p 2
  // if the id-expression in a class member access is an
  // unqualified-id, and the type of the object expression is of class
  // type C (or pointer to class type C), the unqualified-id is looked
  // up in the scope of class C. If the type of the object-expression
  // is of pointer to scalar type, the unqualified-id is looked up in
  // the context of the complete postfix-expression.

  // p 3
  // if the unqualitified id is ~type-name, and the type of the object
  // expression is of a class type C (or pointer to class type C), the
  // type-name is looked up in the context of the entire
  // postfix-expression and in the scope of class C. The type-name
  // shall refer to a class-name. If type-name is found in both
  // contexts, the name shall refer to the same class type. If the
  // type of the object expression is of scalar type, the type-name is
  // looked up in the complete postfix-expression.
  
  typedef X localtype;

  //
  // 1 non-templatized, pointer, unqualified
  //
  X x01 ;
  X *px = &x01;
  px->~X(); 

  X x02 (66);
  px = &x02;
  px->~localtype();

  X x03 (68);
  px = &x03;
  px->~classtype(); //-g++  //p3: unqual-id lookup in object and postfix-expr

  X x04 (70);
  px = &x04;
  px->~globaltype();


  // p 1
  // . . . the id-expression is first looked up in the class of the
  // object-expression. If the identifier is not found, itis then
  // looked up in the context of the entier postfix-expression and
  // shall name a class or function template. If the lookup in the
  // class of the object-expression finds a template, the name is also
  // looked up in teh context of the entier postfix-expression and
  // 1 if the name is not found, use the name from the object-expr
  // 2 if the name found in postfix-expr != class template, use object-expr
  // 3 if name found is class template, name must match object-expr or error

  // p 4 

  // if the id-expr in a class member acess is a qualified-id, the
  // id-expression is looked up in both the context of the entire
  // postfix-expr and in the scope of the class of the object-expr. If
  // the name is found in both contexts, the id-expr shall refer to
  // the same entity.


  //
  // 2 non-templatized, pointer, qualified
  //
  X x05 ;
  px = &x05;
  px->X::~X(); 

  X x06 (66);
  px = &x06;
  px->X::~localtype();

  X x07 (68);
  px = &x07;
  px->X::~classtype(); // -edg

  X x08 (70);
  px = &x08;
  px->X::~globaltype();

  X x09 (66);
  px = &x09;
  px->localtype::~localtype();

  X x10 (68);
  px = &x10;
  px->classtype::~classtype();

  X x11 (70);
  px = &x11;
  px->globaltype::~globaltype();

  X x12 (66);
  px = &x12;
  px->classtype::~localtype();

  X x13 (68);
  px = &x13;
  px->globaltype::~localtype();

  X x14 (70);
  px = &x14;
  px->localtype::~globaltype();

  X x15 (70);
  px = &x15;
  px->classtype::~globaltype();

  X x16 (70);
  px = &x16;
  px->localtype::~classtype(); //-edg

  X x17 (70);
  px = &x17;
  px->globaltype::~classtype(); //-edg

#if 0
  //
  // non-templatized, non-pointer
  //
  X xo5 ;
  xo5.~X(); //unqualified

  localtype xo6 (66);
  xo6.~localtype();

  X xo7 (68);
  xo7.~classtype();

  X xo8 (70);
  xo8.~globaltype();


  //
  // templatized, pointer
  //
  X_tem<int> xto1 ;
  X_tem<int> *pxt = &xto1;
  pxt->~X_tem(); //unqualified

  typedef X_tem<int> localtype_tem;
  localtype_tem xto2 (66);
  pxt = &xto2;
  pxt->~localtype_tem();

  //paragraph 2:  unqualitifed id looked up in scope of post-fix expr if object
  X_tem<int> xto3 (68);
  pxt = &xto3;
  pxt->~classtype_tem();

  X_tem<int> xto4 (70);
  pxt = &xto4;
  pxt->~globaltype_tem();

  //
  // templatized, non-pointer
  //
  X_tem<int> xto5 ;
  xto5.~X_tem(); //unqualified

  localtype_tem xto6 (66);
  xto6.~localtype_tem();

  X_tem<int> xto7 (68);
  xto7.~classtype_tem();

  X_tem<int> xto8 (70);
  xto8.~globaltype_tem();
#endif
  return 0;
}
Ejemplo n.º 3
0
void Membrane::ensureStiffnessMatrices(const Real& young, const Real& nu, const Real& thickness,bool bending, const Real& bendThickness){
	assert(hasRefConf());
	// do nothing if both matrices exist already
	if(KKcst.size()==36 && (!bending ||
		#ifdef MEMBRANE_CONDENSE_DKT		
			KKdkt.size()==54
		#else 
			KKdkt.size()==81
		#endif
	)) return; 
	// check thickness
	Real t=(isnan(thickness)?2*this->halfThick:thickness);
	if(/*also covers NaN*/!(t>0)) throw std::runtime_error("Membrane::ensureStiffnessMatrices: Facet thickness is not positive!");

	// plane stress stiffness matrix
	Matrix3r E;
	E<<1,nu,0, nu,1,0,0,0,(1-nu)/2;
	E*=young/(1-pow(nu,2));

	// strain-displacement matrix (CCT element)
	Real area=this->getArea();
	const Real& x1(refPos[0]); const Real& y1(refPos[1]); const Real& x2(refPos[2]); const Real& y2(refPos[3]); const Real& x3(refPos[4]); const Real& y3(refPos[5]);

	// Felippa: Introduction to FEM eq. (15.17), pg. 259
	Eigen::Matrix<Real,3,6> B;
	B<<
		(y2-y3),0      ,(y3-y1),0      ,(y1-y2),0      ,
		0      ,(x3-x2),0      ,(x1-x3),0      ,(x2-x1),
		(x3-x2),(y2-y3),(x1-x3),(y3-y1),(x2-x1),(y1-y2);
	B*=1/(2*area);
	KKcst.resize(6,6);
	KKcst=t*area*B.transpose()*E*B;

	// EBcst=E*B;

	if(!bending) return;

	// strain-displacement matrix (DKT element)

	Real dktT=(isnan(bendThickness)?t:bendThickness);
	assert(!isnan(dktT));

	// [Batoz,Bathe,Ho: 1980], Appendix A: Expansions for the DKT element
	// (using the same notation)
	Real x23=(x2-x3), x31(x3-x1), x12(x1-x2);
	Real y23=(y2-y3), y31(y3-y1), y12(y1-y2);
	Real l23_2=(pow(x23,2)+pow(y23,2)), l31_2=(pow(x31,2)+pow(y31,2)), l12_2=(pow(x12,2)+pow(y12,2));
	Real P4=-6*x23/l23_2, P5=-6*x31/l31_2, P6=-6*x12/l12_2;
	Real t4=-6*y23/l23_2, t5=-6*y31/l31_2, t6=-6*y12/l12_2;
	Real q4=3*x23*y23/l23_2, q5=3*x31*y31/l31_2, q6=3*x12*y12/l12_2;
	Real r4=3*pow(y23,2)/l23_2, r5=3*pow(y31,2)/l31_2, r6=3*pow(y12,2)/l12_2;

	// even though w1, w2, w3 are always zero due to our definition of triangle plane,
	// we need to get the corresponding nodal force, therefore cannot condense those DOFs away.

	auto Hx_xi=[&](const Real& xi, const Real& eta) -> Vector9r { Vector9r ret; ret<<
		P6*(1-2*xi)+(P5-P6)*eta,
		q6*(1-2*xi)-(q5+q6)*eta,
		-4+6*(xi+eta)+r6*(1-2*xi)-eta*(r5+r6),
		-P6*(1-2*xi)+eta*(P4+P6),
		q6*(1-2*xi)-eta*(q6-q4),
		-2+6*xi+r6*(1-2*xi)+eta*(r4-r6),
		-eta*(P5+P4),
		eta*(q4-q5),
		-eta*(r5-r4);
		return ret;
	};

	auto Hy_xi=[&](const Real& xi, const Real &eta) -> Vector9r { Vector9r ret; ret<<
		t6*(1-2*xi)+eta*(t5-t6),
		1+r6*(1-2*xi)-eta*(r5+r6),
		-q6*(1-2*xi)+eta*(q5+q6),
		-t6*(1-2*xi)+eta*(t4+t6),
		-1+r6*(1-2*xi)+eta*(r4-r6),
		-q6*(1-2*xi)-eta*(q4-q6),
		-eta*(t4+t5),
		eta*(r4-r5),
		-eta*(q4-q5);
		return ret;
	};

	auto Hx_eta=[&](const Real& xi, const Real& eta) -> Vector9r { Vector9r ret; ret<<
		-P5*(1-2*eta)-xi*(P6-P5),
		q5*(1-2*eta)-xi*(q5+q6),
		-4+6*(xi+eta)+r5*(1-2*eta)-xi*(r5+r6),
		xi*(P4+P6),
		xi*(q4-q6),
		-xi*(r6-r4),
		P5*(1-2*eta)-xi*(P4+P5),
		q5*(1-2*eta)+xi*(q4-q5),
		-2+6*eta+r5*(1-2*eta)+xi*(r4-r5);
		return ret;
	};

	auto Hy_eta=[&](const Real& xi, const Real& eta) -> Vector9r { Vector9r ret; ret<<
		-t5*(1-2*eta)-xi*(t6-t5),
		1+r5*(1-2*eta)-xi*(r5+r6),
		-q5*(1-2*eta)+xi*(q5+q6),
		xi*(t4+t6),
		xi*(r4-r6),
		-xi*(q4-q6),
		t5*(1-2*eta)-xi*(t4+t5),
		-1+r5*(1-2*eta)+xi*(r4-r5),
		-q5*(1-2*eta)-xi*(q4-q5);
		return ret;
	};

	// return B(xi,eta) [Batoz,Bathe,Ho,1980], (30)
	auto Bphi=[&](const Real& xi, const Real& eta) -> Eigen::Matrix<Real,3,9> {
		Eigen::Matrix<Real,3,9> ret;
		ret<<
			(y31*Hx_xi(xi,eta)+y12*Hx_eta(xi,eta)).transpose(),
			(-x31*Hy_xi(xi,eta)-x12*Hy_eta(xi,eta)).transpose(),
			(-x31*Hx_xi(xi,eta)-x12*Hx_eta(xi,eta)+y31*Hy_xi(xi,eta)+y12*Hy_eta(xi,eta)).transpose()
		;
		return ret/(2*area);
	};

	// bending elasticity matrix (the same as (t^3/12)*E, E being the plane stress matrix above)
	Matrix3r Db;
	Db<<1,nu,0, nu,1,0, 0,0,(1-nu)/2;
	Db*=young*pow(dktT,3)/(12*(1-pow(nu,2)));


	// assemble the matrix here
	// KKdkt0 is 9x9, then w_i dofs are condensed away, and KKdkt is only 9x6
	#ifdef MEMBRANE_CONDENSE_DKT
		MatrixXr KKdkt0(9,9); KKdkt0.setZero();
		// MatrixXr EBdkt0(9,6); EBdkt0.setZero();
	#else
		KKdkt.setZero(9,9);
		// EBdkt.setZero(9,6);
	#endif
	// gauss integration points and their weights
	Vector3r xxi(.5,.5,0), eeta(0,.5,.5);
	Real ww[]={1/3.,1/3.,1/3.};
	for(int i:{0,1,2}){
		for(int j:{0,1,2}){
			auto b=Bphi(xxi[i],eeta[j]); // evaluate B at the gauss point
			#ifdef MEMBRANE_CONDENSE_DKT
				KKdkt0
			#else
				KKdkt
			#endif
				+=(2*area*ww[j]*ww[i])*b.transpose()*Db*b;
			#if 0
				#ifdef MEMBRANE_CONDENSE_DKT
					EBdkt0
				#else
					EBdkt
				#endif
					+=(2*area*ww[j]*ww[i])*Db*b;
			#endif
		}
	}
	#ifdef MEMBRANE_CONDENSE_DKT
		// extract columns [_ 1 2 _ 4 5 _ 7 8]
		KKdkt.setZero(9,6);
		for(int i:{0,1,2}){
			KKdkt.col(2*i)=KKdkt0.col(3*i+1);
			KKdkt.col(2*i+1)=KKdkt0.col(3*i+2);
		}
	#endif
};
Ejemplo n.º 4
0
// Test the DynSysModel class
void test_DynSysModel()
{
	// Make a 4 variable model
	GAParams::SetNumVars( 4 );

	DynSysModel m;

	// Create monomial x1, x2, x3, x4, x1*x2, x3*x4, x1*x2*x3*x4

	Monomial c0(   "0000" );	c0.mCoeff = false;
	Monomial c1(   "0000" );	c1.mCoeff = true;
	Monomial x4(   "0001" );
	Monomial x3(   "0010" );
	Monomial x2(   "0100" );
	Monomial x1(   "1000" );
	Monomial x34(  "0011" );
	Monomial x12(  "1100" );
	Monomial x14(  "1001" );
	Monomial x1234("1111" );

	Polynomial f;
	f.AddTerm( c0 );
	std::cout << "f = " << f.ToString( true ) << std::endl;

	Polynomial g;
	g.AddTerm( c1 );
	std::cout << "g = " << g.ToString( true ) << std::endl;

	// f1(x) = x1 + x2 + x4;
	Polynomial f1;
	f1.AddTerm( x1 );	f1.AddTerm( x2 );	f1.AddTerm( x4 );
	std::cout << "f1 = " << f1.ToString( true ) << std::endl;

	Polynomial::mMaxSupport = 2;
	m.SetFunction( 1, f );
	m.SetFunction( 2, g );
	m.SetFunction( 3, f );
	m.SetFunction( 4, f1 );

	ComplexityMatrix cmplx_mat;
	ComplexityMatrixRow row;
	cmplx_mat.assign( 4, row );

	m.SetPolyComplexities( );
	double s;
	s = m[1].mComplexityScore;
	s = m[2].mComplexityScore;
	s = m[3].mComplexityScore;
	s = m[4].mComplexityScore;


/*
	// f2(x) = x1*x2*x3*x4;
	Polynomial f2;
	f2.AddTerm( x1234 );
	std::cout << "f2 = " << f2.ToString( true ) << std::endl;

	// f3(x) = x1*x2 + x3*x4;
	Polynomial f3;
	f3.AddTerm( x12 );
	f3.AddTerm( x34 );
	std::cout << "f3 = " << f3.ToString( true ) << std::endl;

	// f3'(x) = x1*x4;
	Polynomial f3p;
	f3p.AddTerm( x14 );
	std::cout << "f3p = " << f3p.ToString( true ) << std::endl;

	// f4(x) = x3 + x4;
	Polynomial f4;
	f4.AddTerm( x3 );	f4.AddTerm( x4 );
	std::cout << "f4 = " << f4.ToString( true ) << std::endl;

	// Assign the functions to the model
	m.SetFunction( 1, f1 ); 	m.SetFunction( 2, f2 );
	m.SetFunction( 3, f3p ); 	m.SetFunction( 4, f4 );
*/

	TimeSeries t2;
//	t2.push_back( NTuple("1101" ) );
//	t2.push_back( NTuple("1011" ) );
	t2.push_back( NTuple("1100" ) );
	t2.push_back( NTuple("0010" ) );
	t2.push_back( NTuple("0001" ) );
	t2.push_back( NTuple("1001" ) );
	t2.push_back( NTuple("0001" ) );

	// Better to pass a reference to the time series for the result
	// TimeSeries t3 = m.Iterate( NTuple( "1111" ), 6 );

	// Test iteration for only the k'th variable
	size_t k = 3;
	TimeSeries t4;
	size_t h = m.Iterate( t2, k, t4 );

	TimeSeriesIter iter = t4.begin();
	while( iter != t4.end() )
	{
		std::cout << *iter++ << std::endl;
	}
}