int
AC3D8HexWithSensitivity::update()
{
  int i;
  double r  = 0.0;
  double s  = 0.0;
  
  Vector epsilon(3);
  Matrix sstrain(3,1);
  
  Matrix trial_disp = this->getTotalDisp();
  
  //opserr<<"trial_disp"<<trial_disp<<endln;
  this->computeDiff();
  
  for(i = 0; i < numGP; i++) {
    const Matrix &dhGlobal = *L[i];
    
    sstrain.addMatrixProduct(0.0, dhGlobal, trial_disp, 1.0);
    epsilon(0) = sstrain(0,0);
    epsilon(1) = sstrain(1,0);
    epsilon(2) = sstrain(2,0);
    
    theMaterial[i]->setTrialStrain(epsilon);
    
    // printf("Integration point: %d\n", i+1);
    // printf("epsilon is <%g,%g,%g>\n", epsilon(0), epsilon(1), epsilon(2));
  }
  
  return 0;
}
Ejemplo n.º 2
0
/**
 * @function fillEq_PLP
 * @brief  Fill PLP equations ( 3 Eq - 2 DOF )
 */
void trifocalTensor::fillEq_PLP( cv::Point3f _A, 
				 cv::Point3f _B,
				 cv::Point3f _C ) {

  Eigen::Vector3f A; A << _A.x, _A.y, _A.z;
  Eigen::Vector3f B; B << _B.x, _B.y, _B.z;
  Eigen::Vector3f C; C << _C.x, _C.y, _C.z;
  std::cout << "Correspondence PLP: " << A.transpose() <<"," <<B.transpose() <<"," <<C.transpose() << std::endl;
  // 3 equations
  for( int s = 0; s < 3; ++s ) {
    // T0, T1, T2
    for( int i = 0; i < 3; ++i ) {
      for( int j = 0; j < 3; ++j ) {
	for( int q = 0; q < 3; ++q ) {
	  for( int k = 0; k < 3; ++k ) {
	    if( epsilon(k,q,s) != 0 ) {
	      mEq( mPointer, 9*i + 3*j + q) = A(i)*B(j)*C(k)*epsilon(k,q,s);
	    }
	  } // k
	} // q
      } // j
    } // i
    
    mPointer++;
  } // s
  
  
}
Ejemplo n.º 3
0
/**
 * @function fillEq_PPP
 * @brief  Fill PPP equations (9 Eq - 4 DOF)
 */
void trifocalTensor::fillEq_PPP( cv::Point3f _A, 
				 cv::Point3f _B,
				 cv::Point3f _C ) {

  Eigen::Vector3f A; A << _A.x, _A.y, _A.z;
  Eigen::Vector3f B; B << _B.x, _B.y, _B.z;
  Eigen::Vector3f C; C << _C.x, _C.y, _C.z;

  printf("[PPP] Correspondence ( %f %f %f ), (%f %f %f) (%f %f %f) \n", A(0), A(1), A(2),  B(0), B(1), B(2), C(0), C(1), C(2));
  // 3x3 equations


  for( int r = 0; r < 3; r++ ) {
    for( int s = 0; s < 3; s++ ) {
      printf("[PPP] rs: (%d %d) Pointer: %d  \n", r, s, mPointer);
      Eigen::MatrixXf T0 = Eigen::MatrixXf::Zero(3,3);
      Eigen::MatrixXf T1 = Eigen::MatrixXf::Zero(3,3);
      Eigen::MatrixXf T2 = Eigen::MatrixXf::Zero(3,3);
      
      std::vector<Eigen::MatrixXf> tempT;
      tempT.push_back(T0);
      tempT.push_back(T1);
      tempT.push_back(T2);
      // T0, T1, T2
      for( int i = 0; i < 3; i++ ) {
	for( int p = 0; p < 3; p++ ) {
	  for( int q = 0; q < 3; q++ ) {
	    for( int j = 0; j < 3; j++ ) {
	      for( int k = 0; k < 3; k++ ) {
		
		if( epsilon(j,p,r) != 0 && epsilon( k, q, s ) != 0 ) {
		  tempT[i](p,q) += A(i)*B(j)*epsilon(j,p,r)*epsilon(k,q,s)*C(k);
		  }
		/*
		float val = A(i)*( (B(j)*epsilon(j,p,r))*(epsilon(k,q,s)*C(k)) );
		float temp = tempT[i](p,q) + val;
		tempT[i](p,q) = temp; */
	      } // k
	    } // j
	  } // q
	} // p
      } // i
      
      // Fill matrix
      int index = 0;
      for( int a = 0; a < 3; ++a ) {
	for( int b = 0; b < 3; ++b ) {
	  for( int c = 0; c < 3; ++c ) {
	    mEq( mPointer, index) = tempT[a](b,c);
	    index++;
	  }
	}
      }

      mPointer++;
    } // s
  } // r
  

}
  int df(const Eigen::VectorXf &x, Eigen::MatrixXf &fjac) const
  {
    Eigen::VectorXf epsilon(1);
    epsilon(0) = 1e-5;

    Eigen::VectorXf fvec1(1);
    operator()(x + epsilon, fvec1);
    Eigen::VectorXf fvec2(1);
    operator()(x - epsilon, fvec2);
    fjac = (fvec1 - fvec2)/2.0f;
    return 0;
  }
Ejemplo n.º 5
0
/**
 * @function fillEq_LLL
 * @brief  Fill LLL equations ( 3 Equations, 2 DOF )
 */
void trifocalTensor::fillEq_LLL( cv::Point3f _A, 
				 cv::Point3f _B,
				 cv::Point3f _C ) {

  Eigen::Vector3f A; A << _A.x, _A.y, _A.z;
  Eigen::Vector3f B; B << _B.x, _B.y, _B.z;
  Eigen::Vector3f C; C << _C.x, _C.y, _C.z;
  
  std::cout << "[LLL] Correspondence: " << A.transpose() <<"," <<B.transpose() <<"," <<C.transpose() << std::endl;
  // 3 equations
  for( int s = 0; s < 3; ++s ) {
    // T0, T1, T2
    for( int i = 0; i < 3; ++i ) {
      for( int j = 0; j < 3; ++j ) {
	for( int k = 0; k < 3; ++k ) {
	  for( int r = 0; r < 3; ++r ) {	      
	    mEq( mPointer, 9*i + 3*j + k) += A(r)*B(j)*C(k)*epsilon(r,i,s);
	  } // r
	} // k
      } // j
    } // i
    
    mPointer++;
  } // s

}
Ejemplo n.º 6
0
// Berechne die kleinste einschliessende Kugel fuer die Punktmenge
Sphere::Sphere(const std::vector<Vector3d>& p,int pointcount) {

  //std::vector<Vector3d> v(p);
  std::vector<Vector3d> p2;
  for(int i=0;i<=pointcount;i++){
      p2.push_back(p[i]);
  }
  std::vector<Vector3d> v(p2);
  std::sort(v.begin(),v.end());
  v.erase(std::unique(v.begin(),v.end(),epsilonEquals),v.end());

  int n = int(v.size());

	//random pertutation!
  for(int i=n-1;i>0;i--) {
    int j = (int) floor(i*double(rand())/RAND_MAX);
    Vector3d d = v[i];//+epsilon;
    v[i] = v[j];//-epsilon; 
    v[j] = d;
  }
   
	/// alter the points to avoid degenerate cases
	Vector3d epsilon(0.00001, -0.00001, 0.0001);
    for(int i=0;i<n;i++)
		if (rand()<0.5*RAND_MAX) v[i] += epsilon;
		else										 v[i] -= epsilon;

	///Hier berechnen wir die Kugel! 
  //Sphere S = ses0 (n,v);
    Sphere S = ses0 (n,v);
    
  center = S.center;
  radius = S.radius;
}
Ejemplo n.º 7
0
//------------------------------------------------------------------------------
void ArcLookAt::autoview(const spire::AABB& bbox, float fov)
{
  if (bbox.isNull()) return;

  glm::vec3 diag(bbox.getDiagonal());
  double w = glm::length(diag);

  if (w < 0.000001)
  {
    spire::AABB bb;
    bb.setNull();
    glm::vec3 epsilon(0.001, 0.001, 0.001);
    bb.extend( bbox.getMin() - epsilon );
    bb.extend( bbox.getMax() + epsilon );
    w = glm::length(bb.getDiagonal());
  }

  mCamLookAt = bbox.getCenter();

  // We are calculating the distance the camera would need to be away from
  // the length of the diagonal of the bbox. See Van Dam, Foley, third edition
  // page 304:

  //    AC = f*tan(O(v)/2)
  // => f = AC / tan(O(v)/2)
  // Where AC is half the size of the diagonal.
  // So, takning into account half the size:
  // => f = AC / (2 * tan(O(v) / 2)

  mCamDistance = w / (2 * tan(fov / 2.0));
}
const Vector&
ElasticIsotropicPlaneStress2D::getStress (void)
{
    double d00 = E/(1.0-v*v);
    double d01 = v*d00;
    double d22 = 0.5*(d00-d01);

    double eps0 = epsilon(0);
    double eps1 = epsilon(1);

    //sigma = D*epsilon;
    sigma(0) = d00*eps0 + d01*eps1;
    sigma(1) = d01*eps0 + d00*eps1;
    sigma(2) = d22*epsilon(2);
	
    return sigma;
}
void AO_COS::getSample(const int& variable, int& value, Double& weight,myRandom& random)
{
	Double epsilon(0.01);
	vector<Double> dist(csp->variables[variable]->domain_size());
	Double norm_const;
	for(int i=0;i<dist.size();i++)
	{
		if(cp_algo->isConsistent(variable,i))
		{
			csp->variables[variable]->addr_value()=i;
			int entry=Variable::getAddress(sampling_functions[variable].variables());
			
			dist[i]=sampling_functions[variable].table()[entry];
			norm_const+=dist[i];
			//dist[i]=Double(1.0);
		}
		
		
	}
	//cout<<"Var = "<<variable<<": ";
	//Double norm_const1;
	//for(int i=0;i<dist.size();i++)
	//{
	//	if(dist[i].isZero())
	//		continue;
	//	if((dist[i]/norm_const) < epsilon);
	//	{
	//		dist[i]=epsilon;
	//	}
	//	norm_const1+=dist[i];
	//	//cout<<dist[i]<<" ";
	//}
	for(int i=0;i<dist.size();i++)
		dist[i]/=norm_const;
	/*for(int i=0;i<dist.size();i++)
	{
		dist[i]/=norm_const1;
		
	}
	*/
	//cout<<endl;
	double sampled_value=random.getDouble();
	double cdf=0.0;
	for(int i=0;i<dist.size();i++)
	{
		cdf+=dist[i].value();
		if(cdf >= sampled_value)
		{
			value=i;
			weight=dist[i];
			return;
		}
	}
	//cerr<<"Should not reach here---Rejection problem\n";
	value=0;
	weight=Double();
}
Ejemplo n.º 10
0
void
b_order( game *aGame, player *P, strlist **s )
{
    group *g;                   /* pointer to named group */
    group *g2;                  /* pointer to new group */
    int i;                      /* int value for number of ships */
    char *ns;                   /* char value for number of ships */

    DBUG_ENTER( "b_order" );

    /* find the named group */
    g = findgroup( P, getstr( 0 ) );
    if ( !g ) {
        mistake( P, INFO, *s, "Group not recognized." );
        DBUG_VOID_RETURN;
    }

    /* check to see if we're detaching from a fleet */
    ns = getstr( 0 );
    if ( noCaseStrncmp( ns, "fleet", 5 ) == 0 ) {
        if ( !epsilon( g->dist, 0.0, 0.0001 ) ) {
            mistake( P, WARNING, *s, "Fleet is in hyperspace." );
            DBUG_VOID_RETURN;
        }
        g->thefleet = 0;
        DBUG_VOID_RETURN;
    }

    /* are there enough ships to detach? */
    i = atoi( ns );
    if ( i > g->ships ) {       /* FS Dec 1998 */
        mistake( P, INFO, *s, "Not enough ships in group." );
        DBUG_VOID_RETURN;
    }

    /* this was an odd problem */
    if ( i < 0 ) {              /* KDW July 1999 */
        mistake( P, WARNING, *s, "Can't have negative number of ships." );
        DBUG_VOID_RETURN;
    }

    /* create a new group for what's being broken off and add it to
     * the list of groups the player owns
     */
    g2 = allocStruct( group );
    *g2 = *g;
    g2->ships = i;
    g->ships -= i;
    g2->thefleet = 0;
    g2->next = NULL;
    numberGroup( P, g2 );
    g2->name = ( char * ) malloc( 8 );
    sprintf( g2->name, "%d", g2->number );
    addList( &P->groups, g2 );

    DBUG_VOID_RETURN;
}
void Foam::backwardDiffusionFvPatchScalarField::updateCoeffs()
{
    if (updated())
    {
        return;
    }

    const label patchi = patch().index();

    // Calculating alfa
    const volVectorField& U = db().lookupObject<volVectorField>("U");
    tmp<vectorField> n = patch().nf();
    alfa() = -(n & U.boundaryField()[patchi]);
    
    // Calculating eta
    const volScalarField& rho = db().lookupObject<volScalarField>("rho");
    eta() = rho0() / rho.boundaryField()[patchi];

    nameInternal_ = dimensionedInternalField().name();
    bool soretEffect  = db().foundObject<volScalarField>("gas::Dsoret_" + nameInternal_);

    // Calculating epsilon
    if (soretEffect == true)
    {
        const volScalarField& Dsoret = db().lookupObject<volScalarField>("gas::Dsoret_" + nameInternal_);
    	const volScalarField& T = db().lookupObject<volScalarField>("T");
    	epsilon() = -T.boundaryField()[patchi].snGrad() / T.boundaryField()[patchi] * Dsoret.boundaryField()[patchi];
    }
    else
    { 
	epsilon() = 0.;
    }

    // Calculating beta
    nameInternal_ = dimensionedInternalField().name();
    const volScalarField& Dmix = db().lookupObject<volScalarField>("gas::Dmix_" + nameInternal_);
    beta() = Dmix.boundaryField()[patchi]*this->patch().deltaCoeffs();

    if (debug)
    {
    }

    mixedUserDefinedFvPatchScalarField::updateCoeffs();
}
const Vector&
ElasticIsotropicPlaneStrain2D::getStress (void)
{
  double mu2 = E/(1.0+v);
  double lam = v*mu2/(1.0-2.0*v);
  double mu = 0.50*mu2;

  double eps0 = epsilon(0);
  double eps1 = epsilon(1);

  mu2 += lam;

  //sigma = D*epsilon;
  sigma(0) = mu2*eps0 + lam*eps1;
  sigma(1) = lam*eps0 + mu2*eps1;
  sigma(2) = mu*epsilon(2);
	
  return sigma;
}
  double MultivariateFNormalSufficient::get_mean_square_residuals() const
{
    //std::cout << "P " << std::endl << P_ << std::endl;
    //std::cout << "epsilon " << std::endl << get_epsilon() << std::endl;
    VectorXd Peps(get_Peps());
    VectorXd epsilon(get_epsilon());
    double dist = epsilon.transpose()*Peps;
    LOG( "MVN:   get_mean_square_residuals = " << dist << std::endl);
    return dist;
}
Ejemplo n.º 14
0
/*
** The GEI to GSE transformation is given by the matrix 
**
**	T2 = <lambdaO,Z>*<epsilon,X>
**
** where the rotation angle lambdaO is the Sun's ecliptic longitude and 
** the angle epsilon is the obliquity of the ecliptic. This transformation 
** is a rotation from the Earth's equator to the plane of the ecliptic
** followed by a rotation in the plane of the ecliptic from the First Point 
** of Aries to the Earth-Sun direction. 
*/
void
mat_T2(const double et, Mat mat)
{
  Mat mat_tmp;

  hapgood_matrix(lambda0(et), Z, mat);

  hapgood_matrix(epsilon(et), X, mat_tmp);
  mat_times_mat(mat, mat_tmp, mat);
}
Ejemplo n.º 15
0
const XC::Vector &XC::ElasticIsotropicPlateFiber::getStress(void) const
  {
    const double d00 = E/(1.0-v*v);
    const double d01 = v*d00;
    const double d22 = 0.5*(d00-d01);

    const double eps0 = epsilon(0);
    const double eps1 = epsilon(1);

    //sigma = D*epsilon;
    sigma(0) = d00*eps0 + d01*eps1;
    sigma(1) = d01*eps0 + d00*eps1;

    sigma(2) = d22*epsilon(2);
    sigma(3) = d22*epsilon(3);
    sigma(4) = d22*epsilon(4);
	
    return sigma;
  }
Ejemplo n.º 16
0
int main(int argc, char** argv)
{
  int matrix_size;
  int silent = 0;
  int optchar;
  elem_t *a, *inv, *prod;
  elem_t eps;
  double error;
  double ratio;

  while ((optchar = getopt(argc, argv, "qt:")) != EOF)
  {
    switch (optchar)
    {
    case 'q': silent = 1; break;
    case 't': s_nthread = atoi(optarg); break;
    default:
      fprintf(stderr, "Error: unknown option '%c'.\n", optchar);
      return 1;
    }
  }

  if (optind + 1 != argc)
  {
    fprintf(stderr, "Error: wrong number of arguments.\n");
  }
  matrix_size = atoi(argv[optind]);

  /* Error checking. */
  assert(matrix_size >= 1);
  assert(s_nthread >= 1);

  eps = epsilon();
  a = new_matrix(matrix_size, matrix_size);
  init_matrix(a, matrix_size, matrix_size);
  inv = invert_matrix(a, matrix_size);
  prod = multiply_matrices(a, matrix_size, matrix_size,
                           inv, matrix_size, matrix_size);
  error = identity_error(prod, matrix_size);
  ratio = error / (eps * matrix_size);
  if (! silent)
  {
    printf("error = %g; epsilon = %g; error / (epsilon * n) = %g\n",
           error, eps, ratio);
  }
  if (isfinite(ratio) && ratio < 100)
    printf("Error within bounds.\n");
  else
    printf("Error out of bounds.\n");
  delete_matrix(prod);
  delete_matrix(inv);
  delete_matrix(a);

  return 0;
}
Ejemplo n.º 17
0
const XC::Vector &XC::ElasticIsotropicAxiSymm::getStress(void) const
{
  double mu2 = E/(1.0+v);
  double lam = v*mu2/(1.0-2.0*v);
  double mu = 0.50*mu2;

  double eps0 = epsilon(0);
  double eps1 = epsilon(1);
  double eps2 = epsilon(2);

  mu2 += lam;

  //sigma = D*epsilon;
  sigma(0) = mu2*eps0 + lam*(eps1+eps2);
  sigma(1) = mu2*eps1 + lam*(eps0+eps2);
  sigma(2) = mu2*eps2 + lam*(eps0+eps1);
  sigma(3) = mu*epsilon(3);
	
  return sigma;
}
Ejemplo n.º 18
0
double three_body_system::calc_sf_channel_summand(int kappa, int nr, int nrho, vector<double> transformed_state, double rP) {
    double u = transformed_state[0];
    double v = transformed_state[2];
    double w = transformed_state[1];

    return
        epsilon(kappa, w) * sqrt(2.0*kappa + 1.0) * fact2[2*nrho] * pow(abs(w), kappa)
        / pow(v, 1.5 + nrho + kappa) * pow(rP, 2 + 2*nr + 2*kappa) * exp(-0.5 * (u - w*w/v) * rP * rP)
        * gsl_sf_laguerre_n(nrho, double(kappa) + 0.5, -rP * rP * w * w / v / 2.0);


}
// greebo: This is called if the window size changes (camera, orthoview)
void RadiantWindowObserver::onSizeChanged(int width, int height)
{
	// Store the new width and height
	_width = width;
	_height = height;

	// Rescale the epsilon accordingly...
	DeviceVector epsilon(_selectEpsilon / _width, _selectEpsilon / _height);
	// ...and pass it to the helper classes
	_selectObserver._epsilon = epsilon;
	_manipulateObserver._epsilon = epsilon;
}
const Vector&
PressureDependentElastic3D::getStress (void)
{
  double p = p_n;
  if (p <= p_cutoff)
    p = p_cutoff;
  double Eo = E * pow(p/p_ref, exp0);

  double mu2 = Eo/(1.0+v);
  double lam = v*mu2/(1.0-2.0*v);
  double mu  = 0.50*mu2;
  
  mu2 += lam;
  
  double eps0 = epsilon(0);
  double eps1 = epsilon(1);
  double eps2 = epsilon(2);
  
  sigma(0) = mu2*eps0 + lam*(eps1+eps2);
  sigma(1) = mu2*eps1 + lam*(eps2+eps0);
  sigma(2) = mu2*eps2 + lam*(eps0+eps1);
  
  p_n1 = (sigma(0)+sigma(1)+sigma(2))/3.0;

  sigma(3) = mu*epsilon(3);
  sigma(4) = mu*epsilon(4);
  sigma(5) = mu*epsilon(5);
  
  return sigma;
}
Ejemplo n.º 21
0
void print_limits (std::ostream &strm, const char *tname, T)
{
#define PRINT_MEMBER(type, member)                     \
    strm << "    static " << type << " " #member " = "            \
         << std::numeric_limits<T>::member << ";\n"

    strm << "struct std::numeric_limits<" << tname << "> {\n";

    PRINT_MEMBER ("const bool", is_specialized);

    PRINT_MEMBER (tname, min ());
    PRINT_MEMBER (tname, max ());

    PRINT_MEMBER ("const int", digits);
    PRINT_MEMBER ("const int", digits10);

    PRINT_MEMBER ("const bool", is_signed);
    PRINT_MEMBER ("const bool", is_integer);
    PRINT_MEMBER ("const bool", is_exact);
    PRINT_MEMBER ("const int", radix);

    PRINT_MEMBER (tname, epsilon ());
    PRINT_MEMBER ("int", round_error ());

    PRINT_MEMBER ("const int", min_exponent);
    PRINT_MEMBER ("const int", min_exponent10);
    PRINT_MEMBER ("const int", max_exponent);
    PRINT_MEMBER ("const int", max_exponent10);

    PRINT_MEMBER ("const bool", has_infinity);
    PRINT_MEMBER ("const bool", has_quiet_NaN);
    PRINT_MEMBER ("const bool", has_signaling_NaN);
    PRINT_MEMBER ("const std::float_denorm_style", has_denorm);

    PRINT_MEMBER ("const bool", has_denorm_loss);

    PRINT_MEMBER (tname, infinity ());
    PRINT_MEMBER (tname, quiet_NaN ());
    PRINT_MEMBER (tname, signaling_NaN ());
    PRINT_MEMBER (tname, denorm_min ());

    PRINT_MEMBER ("const bool", is_iec559);
    PRINT_MEMBER ("const bool", is_bounded);
    PRINT_MEMBER ("const bool", is_modulo);

    PRINT_MEMBER ("const bool", traps);
    PRINT_MEMBER ("const bool", tinyness_before);

    PRINT_MEMBER ("const int", round_style);

    strm << "};\n";
}
atmBoundaryLayerInletEpsilonFvPatchScalarField::
atmBoundaryLayerInletEpsilonFvPatchScalarField
(
    const fvPatch& p,
    const DimensionedField<scalar, volMesh>& iF,
    const dictionary& dict
)
:
    fixedValueFvPatchScalarField(p, iF),
    atmBoundaryLayer(patch().Cf(), dict)
{
    scalarField::operator=(epsilon(patch().Cf()));
}
Ejemplo n.º 23
0
Point3D RayDirectionalLight::transparency(RayIntersectionInfo& iInfo,RayShape* shape,Point3D cLimit){
	Point3D p0 = iInfo.iCoordinate;
	Point3D dir = direction.unit().negate();
	Point3D epsilon(0.00001, 0.00001, 0.00001);
	epsilon = dir*epsilon;
	p0 = p0+epsilon;
	Ray3D ray(p0, dir);
	double dist = shape->intersect(ray, iInfo, -1);
	if (dist > 0) {
		return color*iInfo.material->transparent;
	}
	else return Point3D(1,1,1);
}
Ejemplo n.º 24
0
int RayDirectionalLight::isInShadow(RayIntersectionInfo& iInfo,RayShape* shape,int& isectCount){
	Point3D p0 = iInfo.iCoordinate;
	Point3D dir = direction.unit().negate();
	Point3D epsilon(0.00001, 0.00001, 0.00001);
	epsilon = dir*epsilon;
	p0 = p0+epsilon;
	Ray3D ray(p0, dir);
	double dist = shape->intersect(ray, iInfo, -1);
	if (dist > 0) {
		return 0;
	}
	else return 1;
}
Ejemplo n.º 25
0
Archivo: ci.hpp Proyecto: zasdfgbnm/qc
std::chrono::duration<double> cis(calculation_data &data) {
    std::chrono::duration<double> elapsed_seconds(0);
    auto start = std::chrono::steady_clock::now();

    // build A matrix
    int sz = (data.n_paired/2)*(data.n_baseset-data.n_paired/2);
    hermitian_matrix epsilon(sz);
    hermitian_matrix J(sz);
    hermitian_matrix K(sz);
    std::function<int(int,int)> idx = [&](int i,int a) {
        return (data.n_baseset-data.n_paired/2)*i + (a-data.n_paired/2);
    };
    // build epsilon, J and K
    for(int i=0; i<data.n_paired/2; i++) {
        for(int a=data.n_paired/2; a<data.n_baseset; a++) {
            int ia = idx(i,a);
            for(int j=0; j<data.n_paired/2; j++) {
                for(int b=data.n_paired/2; b<data.n_baseset; b++) {
                    int jb = idx(j,b);
                    epsilon(ia,jb) =  ( i==j&&a==b ? (data.eigenvalues[a]-data.eigenvalues[i]) : 0 );
                    J(ia,jb) = data.mo_2eint(a,j,i,b);
                    K(ia,jb) = data.mo_2eint(a,j,b,i);
                }
            }
        }
    }
    // build A_singlet and A_triplet
    data.A_singlet = epsilon + 2*J - K;
    data.A_triplet = epsilon - K;

    // solve for eigenvalues
    eigen_solver(data.A_singlet, data.ci_singlet_wavefunc, data.ci_singlet_excited);
    eigen_solver(data.A_triplet, data.ci_triplet_wavefunc, data.ci_triplet_excited);

    auto end = std::chrono::steady_clock::now();
    elapsed_seconds = std::chrono::duration_cast<std::chrono::duration<double>>(end-start);
    return elapsed_seconds;
}
Ejemplo n.º 26
0
void testfp(void){
	int i;
	float a, x;
	char buf[30];

	ftoa(epsilon(), buf, 6);
	printf("\nmachine epsilon: %s", buf);

	a = 3.0f / 4.0f;
	for (i = 3; i > -7; i--){
		x = pow(3.0f, i);
		doit(a, x);
	}
}
Ejemplo n.º 27
0
void
BiasSolver::run()
{
    DEBUG_BLOCK

    debug() << "BiasSolver::run in thread:" << QThread::currentThreadId();

    // wait until we get the track collection
    {
        QMutexLocker locker( &m_collectionResultsMutex );
        if( !m_trackCollection )
        {
            debug() << "waiting for collection results";
            m_collectionResultsReady.wait( &m_collectionResultsMutex );
        }
        debug() << "collection has" << m_trackCollection->count()<<"uids";
    }

    /*
     * Two stage solver: Run ga_optimize and feed it's result into sa_optimize.
     *
     * Rationale: Genetic algorithms take better advantage of the heuristic used
     * by generateInitialPlaylist and also have tendency to converge faster
     * initially. How ever, they also tend to get stuck in local minima unless
     * the population size is quite large, which is why we switch over to
     * simulated annealing when that happens.
     */

    /*
     * NOTE: For now I am disabling the ga phase, until I can do more
     * experimentation.
     */
    //Meta::TrackList playlist = ga_optimize( GA_ITERATION_LIMIT, true );

    debug() << "generating playlist";
    SolverList playlist = generateInitialPlaylist();
    debug() << "got playlist with"<<playlist.energy();

    // actually for now the simple optimize finds a perfect solution in many cases
    simpleOptimize( &playlist );
    debug() << "after simple optimize playlist with"<<playlist.energy();

    if( playlist.energy() > epsilon() && !m_abortRequested ) // the playlist is only slightly wrong
    {
        annealingOptimize( &playlist, SA_ITERATION_LIMIT, true );
    }
    debug() << "Found solution with energy"<<playlist.energy();

    m_solution = playlist.m_trackList.mid( m_context.count() );
}
int 
ElasticIsotropicPlaneStress2D::recvSelf(int commitTag, Channel &theChannel, 
				      FEM_ObjectBroker &theBroker)
{
  static Vector data(7);
  
  int res = theChannel.recvVector(this->getDbTag(), commitTag, data);
  if (res < 0) {
    opserr << "ElasticIsotropicPlaneStress2D::sendSelf -- could not send Vector\n";
    return res;
  }

  this->setTag((int)data(0));
  E = data(1);
  v = data(2);
  rho = data(3);
  epsilon(0)=data(4);
  epsilon(1)=data(5);
  epsilon(2)=data(6);
  Cepsilon = epsilon;

  return res;
}
Ejemplo n.º 29
0
/**
 * @function getEq_PPP
 * @brief  Fill PPP equations (9 Eq - 4 DOF)
 */
Eigen::MatrixXd Tensor3D::getEq_PPP( std::vector<Eigen::VectorXd> _ppp ) {

  Eigen::VectorXd A(3), B(3), C(3); 
  A(0) = _ppp[0](0); A(1) = _ppp[0](1); A(2) = _ppp[0](2);
  B(0) = _ppp[1](0); B(1) = _ppp[1](1); B(2) = _ppp[1](2);
  C(0) = _ppp[2](0); C(1) = _ppp[2](1); C(2) = _ppp[2](2);


  int numEq = 9;
  Eigen::MatrixXd ppp = Eigen::MatrixXd::Zero(numEq,27);
  
  int R[] = {0,0,0,1,1,1,2,2,2};
  int S[] = {0,1,2,0,1,2,0,1,2};
  int r; int s;
  
  for( int ind = 0; ind < numEq; ++ind ) {
    r = R[ind];
    s = S[ind];

    for( int i = 0; i < 3; ++i ) {
      for( int p = 0; p < 3; ++p ) {
	for( int q = 0; q < 3; ++q ) {
	  for( int j = 0; j < 3; ++j ) {
	    for( int k = 0; k < 3; ++k ) {
		ppp( ind, 9*i + 3*p + q ) += A(i)*B(j)*epsilon(j, p, r)*C(k)*epsilon(k,q,s); 
	      
	    } // k
	  } // j
	} // q
      } // p
    } // i
    
  } // ind
 
  return ppp;

}
Ejemplo n.º 30
0
 void ApproxPolyDPTest::testAllocate1()
 {
     m_operator->initialize();
     m_operator->activate();
     
     runtime::DataContainer curve(new cvsupport::Matrix("contour_f32.npy"));
     runtime::Float64 epsilon(5.0);
     
     m_operator->setInputData(ApproxPolyDP::INPUT_CURVE, curve);
     m_operator->setParameter(ApproxPolyDP::PARAMETER_EPSILON, epsilon);
     
     runtime::DataContainer outCurveResult = m_operator->getOutputData(ApproxPolyDP::OUTPUT_OUT_CURVE);
     
     runtime::ReadAccess outCurveAccess(outCurveResult);
     cvsupport::Matrix::save("ApproxPolyDPTest_testAllocate1_outCurve.npy", outCurveAccess.get<runtime::Matrix>());
 }