bool
Stokhos::JacobiBasis<ordinal_type, value_type>::
computeRecurrenceCoefficients(ordinal_type n,
			      Teuchos::Array<value_type>& alpha,
			      Teuchos::Array<value_type>& beta,
			      Teuchos::Array<value_type>& delta,
			      Teuchos::Array<value_type>& gamma) const
{
  value_type a = alphaIndex_;
  value_type b = betaIndex_;

  if (a==0.0 && b==0.0)
  {
    alpha[0] = 0.0;
    beta[0] = 1.0;
    delta[0] = 1.0;
    gamma[0] = 1.0;
  }
  else
  {
    alpha[0] = getB(0)/getA(0);
    beta[0] = 1.0;
    delta[0] = getC(0)/getA(0);
    gamma[0] = 1.0;
  }
  for (ordinal_type i=1; i<n; i++) 
  {
    alpha[i] = getB(i)/getA(i);
    beta[i] = getD(i)/getA(i);
    delta[i] = getC(i)/getA(i);
    gamma[i] = 1.0;
  }

  return false;
}
Exemple #2
0
void initActivationRecord(problem* problem, int* partial, int plant, int used_mask, int cur_cost, volatile int* best_known, call_record** pos, int* partial_store, int* partial_store_index, int cut) {
	
	// cut-off here
	if (cut == 0) {

		// reserve memory in partial solution store
		int partial_pos = *partial_store_index;
		*partial_store_index += problem->size;

		// copy partial solution to store
		memcpy(&(partial_store[partial_pos]), partial, problem->size * sizeof(int));
		
		// add call record
		(**pos) = (call_record){partial_pos, plant, used_mask, cur_cost};
		(*pos)++;
		return;
	}

	// standard body for the rest
	
	// terminal case
	if (plant >= problem->size) {
		return;
	}

	if (cur_cost >= *best_known) {
		return;
	}


	// fix current position
	for(int i=0; i<problem->size; i++) {
		// check whether current spot is a free spot
		if(!(1<<i & used_mask)) {
			// extend solution
			int tmp[problem->size];
			memcpy(tmp, partial, problem->size*sizeof(int));
			tmp[plant] = i;

			// compute additional cost of current assignment
			int new_cost = 0;
			
			for(int j=0; j<plant; j++) {
				int other_pos = tmp[j];

				// add costs between current pair of plants
				new_cost += getA(problem, plant, j) * getB(problem, i, other_pos);
				new_cost += getA(problem, j, plant) * getB(problem, other_pos, i);
			}

			// fill recoreds recursively
			initActivationRecord(problem, tmp, plant+1, used_mask | (1<<i), cur_cost + new_cost, best_known, pos, partial_store, partial_store_index, cut-1);

		}
	}
}
Exemple #3
0
Quaternion::Quaternion(const Dcm &dcm) :
	Vector(4)
{
	setA(0.5f * sqrtf(1 + dcm(0, 0) +
			  dcm(1, 1) + dcm(2, 2)));
	setB((dcm(2, 1) - dcm(1, 2)) /
	     (4 * getA()));
	setC((dcm(0, 2) - dcm(2, 0)) /
	     (4 * getA()));
	setD((dcm(1, 0) - dcm(0, 1)) /
	     (4 * getA()));
}
Exemple #4
0
Vect Triangle::surfaceNormal(Vect dir, Vect pt) {
    (void) pt;

    Vect v = getB() - getA();
    Vect w = getC() - getA();
    Vect N = v.crossProduct(w);
    N.normalize();

    if (N.dotProduct(dir) > 0)
        N = N.linearMult(-1);
    
    return N;
}
Exemple #5
0
int solve_rec(problem* problem, int* partial, int plant, int used_mask, int cur_cost, volatile int* best_known) {
	// terminal case
	if (plant >= problem->size) {
		return cur_cost;
	}

	if (cur_cost >= *best_known) {
		return *best_known;
	}


	// fix current position
	for(int i=0; i<problem->size; i++) {
		// check whether current spot is a free spot
//		#pragma omp task
		if(!(1<<i & used_mask)) {
			// extend solution
			int tmp[problem->size];
			memcpy(tmp, partial, problem->size*sizeof(int));
			tmp[plant] = i;

			// compute additional cost of current assignment
			int new_cost = 0;
			
			for(int j=0; j<plant; j++) {
				int other_pos = tmp[j];

				// add costs between current pair of plants
				new_cost += getA(problem, plant, j) * getB(problem, i, other_pos);
				new_cost += getA(problem, j, plant) * getB(problem, other_pos, i);
			}

			// compute recursive rest
			int cur_best = solve_rec(problem, tmp, plant+1, used_mask | (1<<i), cur_cost + new_cost, best_known);

			// update best known solution
			if (cur_best < *best_known) {
				int best;
				//   |--- read best ---|          |--- check ---|    |------------ update if cur_best is better ------------|
				do { best = *best_known; } while (cur_best < best && __sync_bool_compare_and_swap(best_known, best, cur_best));
			}
		}
	}

//	#pragma omp taskwait

	return *best_known;
}
//按第一行展开计算|A|
double getA(double arcs[3][3],int n)
{
    if(n==1)
    {
        return arcs[0][0];
    }
    double ans = 0;
    double temp[3][3]={0.0};
    int i,j,k;
    for(i=0;i<n;i++){
        for(j=0;j<n-1;j++){
            for(k=0;k<n-1;k++){
                temp[j][k] = arcs[j+1][(k>=i)?k+1:k];

            }
        }
        double t = getA(temp,n-1);
        if(i%2==0){
            ans += arcs[0][i]*t;
        }
        else{
            ans -=  arcs[0][i]*t;
        }
    }
    return ans;
}
Exemple #7
0
int getA(B_t *src) {
 B_t tmp1 = {0, '\0', ELEM0, 0};
 if (src != 0)
  return src->a;

 return getA(&tmp1);
}
Exemple #8
0
	void MCNeuronSim::setupSingleNeuronParms(int grpRowId, int neurId, bool coupledComp){
			for(unsigned int c = 0; c < compCount; c++) // each neuron has compCount compartments
			{
				network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "C", getCm(neurId, c));
				network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "k", getK(neurId, c));
				network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "vr", getVr(neurId));
				network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "vt", getVt(neurId, c));
				network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "a", getA(neurId, c));
				network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "b", getB(neurId, c));
				network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "vpeak", getVpeak(neurId, c));
				network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "c", getVmin(neurId, c));
				network->setIzhikevichParameter(excGroup[grpRowId][c], neurId, "d", getD(neurId, c));

				if(coupledComp){
					if(c>0){
						double G = getG(neurId, c); //parameters[neurId][G_idx[c-1]];
						double P = getP(neurId, c);//parameters[neurId][P_idx[c-1]];
						float fwd = G * P;
						float bwd = G * (1-P);
						/*
						 * generally, fwd is carlsim 'down', bwd is carlsim 'up' for the purpose of coupling constant assignment, but,
						 * when there is a dendrite 'below' soma: ****cases 3c2 and 4c2***
						 * up and down are reversed.
						 */
						if(compCount>2 && c==1 && connLayout[c]==connLayout[c+1]){ //meaning 2 dendrites (dend 1 and dend2 ) connecting to the same point
							network->setCouplingConstant(excGroup[grpRowId][connLayout[c]], neurId, "down", bwd);
							network->setCouplingConstant(excGroup[grpRowId][c], neurId, "up", fwd);
						}else{
							network->setCouplingConstant(excGroup[grpRowId][c], neurId, "down", fwd);
							network->setCouplingConstant(excGroup[grpRowId][connLayout[c]], neurId, "up", bwd);
						}
					}
				}
			}
		}
Exemple #9
0
arc_instance int main() {

	B* b = new B();
	printf("enter local pool\n");
	{
		arc::AutoReleasePool ap;
		getA(2222);
		arc::LocalPool p;
		b->b = new A(111);
		b->b = getA(333);
		printf("leave start\n");
	}
	printf("leave local pool\n");

	return 0;
}
	// get the status string
	string R34HC22::statusString(){
		stringstream stream;
		stream << "Current Program Counter location: " << hex << getProgCounter() << endl;
		stream << "A register value: " << hex << (int)getA() << endl;
		stream << "B register value: " << hex << (int)getB();
		return stream.str();
	}
	// 0x5D
	// Branch if Less than A
	void R34HC22::branchIfLessThanA(int address)
	{
		if((address + 4) < getMemSize())
		{
			// get the value to compare to A
			unsigned char compareValue = getMemoryValueAtLocation(address + 1);

			if(compareValue < getA())
			{
				if(getLocation(address,2,3) != -1)
				{
					// set the program counter to the new address
					setProgCounter(getLocation(address,2,3));
					executeFromLocation(getLocation(address,2,3));
					cout << complete_mess << endl;
				} else {
					cout << invalid_mem << endl;
					haltOpcode();
				}
			} else {
				// set the program counter to the the fourth byte after the opcode
				setProgCounter(address + 4);
				executeFromLocation(address + 4);
				cout << complete_mess << endl;
			}
		} else {
			cerr << error_mess << endl;
			haltOpcode();
		}
	}
	// 0x5B
	// Branch if A < B
	void R34HC22::branchIfALessThanB(int address)
	{
		if((address + 3) < getMemSize())
		{
			// compare the value of A and B
			if(getA() < getB())
			{
				if(getLocation(address,1,2) != -1)
				{
					// set the program counter to the new address
					setProgCounter(getLocation(address,1,2));
					executeFromLocation(getLocation(address,1,2));
					cout << complete_mess << endl;
				} else {
					cout << invalid_mem << endl;
					haltOpcode();
				}
			} else {
				// set the program counter to the third byte after the opcode
				setProgCounter(address + 3);
				executeFromLocation(address + 3);
				cout << complete_mess << endl;
			}
		} else {
			cerr << error_mess << endl;
			haltOpcode();
		}
	}
Exemple #13
0
bool RigidBody::getAtomVel(Vector3d& vel, unsigned int index) {

    //velRot = $(A\cdot skew(I^{-1}j))^{T}refCoor$

    if (index < atoms_.size()) {

        Vector3d velRot;
        Mat3x3d skewMat;;
        Vector3d ref = refCoords_[index];
        Vector3d ji = getJ();
        Mat3x3d I =  getI();

        skewMat(0, 0) =0;
        skewMat(0, 1) = ji[2] /I(2, 2);
        skewMat(0, 2) = -ji[1] /I(1, 1);

        skewMat(1, 0) = -ji[2] /I(2, 2);
        skewMat(1, 1) = 0;
        skewMat(1, 2) = ji[0]/I(0, 0);

        skewMat(2, 0) =ji[1] /I(1, 1);
        skewMat(2, 1) = -ji[0]/I(0, 0);
        skewMat(2, 2) = 0;

        velRot = (getA() * skewMat).transpose() * ref;

        vel =getVel() + velRot;
        return true;
        
    } else {
        std::cerr << index << " is an invalid index, current rigid body contains " 
                      << atoms_.size() << "atoms" << std::endl;
        return false;
    }
}
Exemple #14
0
void  RigidBody::updateAtoms() {
    unsigned int i;
    unsigned int j;
    Vector3d ref;
    Vector3d apos;
    DirectionalAtom* dAtom;
    Vector3d pos = getPos();
    RotMat3x3d A = getA();
    
    for (i = 0; i < atoms_.size(); i++) {
     
        ref = body2Lab(refCoords_[i]);

        apos = pos + ref;

        atoms_[i]->setPos(apos);

        if (atoms_[i]->isDirectional()) {
          
          dAtom = (DirectionalAtom *) atoms_[i];
          dAtom->rotateBy( A );      
        }

    }
  
}
Exemple #15
0
LabColour const LabColour::withMultipliedColour (float amount) const
{
  return LabColour (
    getL (),
    getA () * amount,
    getB () * amount,
    getAlpha ());
}
Exemple #16
0
LabColour const LabColour::withAddedLuminance (float amount) const
{
  return LabColour (
    jlimit (0.f, 100.f, getL() + amount * 100),
    getA (),
    getB (),
    getAlpha ());
}
Exemple #17
0
LabColour const LabColour::withLuminance (float L) const
{
  return LabColour (
    jlimit (0.f, 100.f, L),
    getA (),
    getB (),
    getAlpha ());
}
Exemple #18
0
bool Pyramid::isInside(Point3D point) const {
	return point.getP().getX() >= 0 &&
		   point.getP().getY() >= 0 &&
		   point.getZ() >= 0 &&
		   point.getP().getX() / getA() +
		   point.getP().getY() / getB() +
		   point.getZ() / getC() <= 1;
}
Exemple #19
0
int struct_inside_loop_ok(std::vector<int> numbers) {
  int sum;
  for (auto number : numbers) {
    A a = getA();
    sum += a.f(number);
  }
  return sum;
}
void UserDefinedLiterals() {
    auto c = "42"_cul;
    outHeader("User defined literals");
    outIdent();
    std::cout
        << "member of class, constructed from user defined string: "
        << c.getA()
        << std::endl;
}
Exemple #21
0
 std::string WeibullDeviate::make_repr(bool incl_seed)
 {
     std::ostringstream oss(" ");
     oss << "galsim.WeibullDeviate(";
     if (incl_seed) oss << seedstring(split(serialize(), ' ')) << ", ";
     oss << "a="<<getA()<<", ";
     oss << "b="<<getB()<<")";
     return oss.str();
 }
Exemple #22
0
Vector Quaternion::derivative(const Vector &w)
{
#ifdef QUATERNION_ASSERT
	ASSERT(w.getRows() == 3);
#endif
	float dataQ[] = {
		getA(), -getB(), -getC(), -getD(),
		getB(),  getA(), -getD(),  getC(),
		getC(),  getD(),  getA(), -getB(),
		getD(), -getC(),  getB(),  getA()
	};
	Vector v(4);
	v(0) = 0.0f;
	v(1) = w(0);
	v(2) = w(1);
	v(3) = w(2);
	Matrix Q(4, 4, dataQ);
	return Q * v * 0.5f;
}
Exemple #23
0
float GetCurrAcc(float V0, float V1, float dist, float a0, float a1)
{
	float t10,t11,t0,t1;
	
	t10 = t_xx	(V0, V1, a0, a1, dist, 1.0f);
	t11 = t_xx	(V0, V1, a0, a1, dist, -1.0f);
	t1	= t_1	(t10, t11); 
	t0	= t_0	(V0, V1, a0, a1, t1);
	return getA	(t0, a1, a0);
}
Exemple #24
0
int PointProbe::writeState(double timef) {
   double * valuesBuffer = this->getValuesBuffer();
   if(parent->columnId()==0){
      assert(outputstream && outputstream->fp);

      fprintf(outputstream->fp, "%s t=%.1f V=%6.5f a=%.5f\n", msg, timef, getV(), getA());
      fflush(outputstream->fp);
   }
   return PV_SUCCESS;
}
 std::vector<RealType> DirectionalAtom::getGrad() {
   std::vector<RealType> grad(6, 0.0);
   Vector3d force;
   Vector3d torque;
   Vector3d myEuler;
   RealType phi, theta;
   // RealType psi;
   RealType cphi, sphi, ctheta, stheta;
   Vector3d ephi;
   Vector3d etheta;
   Vector3d epsi;
   
   force = getFrc();
   torque =getTrq();
   myEuler = getA().toEulerAngles();
   
   phi = myEuler[0];
   theta = myEuler[1];
   // psi = myEuler[2];
   
   cphi = cos(phi);
   sphi = sin(phi);
   ctheta = cos(theta);
   stheta = sin(theta);
   
   // get unit vectors along the phi, theta and psi rotation axes
   
   ephi[0] = 0.0;
   ephi[1] = 0.0;
   ephi[2] = 1.0;
   
   //etheta[0] = -sphi;
   //etheta[1] =  cphi;
   //etheta[2] =  0.0;
   
   etheta[0] = cphi;
   etheta[1] = sphi;
   etheta[2] = 0.0;
   
   epsi[0] = stheta * cphi;
   epsi[1] = stheta * sphi;
   epsi[2] = ctheta;
   
   //gradient is equal to -force
   for (int j = 0 ; j<3; j++)
     grad[j] = -force[j];
   
   for (int j = 0; j < 3; j++ ) {      
     grad[3] -= torque[j]*ephi[j];
     grad[4] -= torque[j]*etheta[j];
     grad[5] -= torque[j]*epsi[j];      
   }
   
   return grad;
 }    
Exemple #26
0
void g(B_t *pb, B_t* src, enum Elem c) {
  B_t *cur = src;
  int t;
  if (pb == 0 || src == 0)
    return;

  pb->a = getA(0);
  while (cur->next != 0)
    pb->b = 2;

  pb->b = cur->b;
}
//------------------------------------------------------------------------------
// getRCS() -- Get the RCS
//------------------------------------------------------------------------------
LCreal SigTrihedralCR::getRCS(const Emission* const em)
{
    double rcs = 0.0;
    if (em != 0) {
        double lambda = em->getWavelength();
        if (lambda > 0.0) {
            // If we have lambda and the area of the plate, compute the RCS
            double a = getA();
            rcs = (12.0 * PI * a*a*a*a) / (lambda*lambda); 
        }
    }
    return static_cast<LCreal>(rcs);
}
Exemple #28
0
    void DistanceConstraint::solve(const float dt)
    {
        // get some information that we need
		sf::Vector2f axis = getB()->getPosition() - getA()->getPosition();
		float currentDistance = length(axis);
		sf::Vector2f unitAxis = axis * (1.f/currentDistance);

		// calculate relative velocity in the axis, we want to remove this
		float relVel = dot(getB()->getVelocity() - getA()->getVelocity(), unitAxis);

		float relDist = currentDistance-distance;

		// calculate impulse to solve
		float remove = relVel+relDist/dt;
		float impulse = remove / (getA()->getInverseMass() + getB()->getInverseMass());

		// generate impulse vector
		sf::Vector2f I = unitAxis*impulse;

		// apply
		applyImpulse(I);
    }
	// 0x53
	// Increment Register A
	void R34HC22::incrementRegisterA(int address){

		if((address + 1) < getMemSize()){
			// increare the value of A
			setA(getA() + 1);

			// move the program counter to the next byte
			setProgCounter(address + 1);
			executeFromLocation(address + 1);
			cout << complete_mess << endl;
		} else {
			cerr << error_mess << endl;
			haltOpcode();
		}
	}
Exemple #30
0
Intersection Triangle::intersects(Ray ray) {
    Intersection is(ray, this);

    Vect p = ray.getOrigin();
    Vect d = ray.getDirection();
    Vect v0 = getA();
    Vect v1 = getB();
    Vect v2 = getC();

    Vect e1, e2, h, s, q;
    float a0, f, u, v;

    e1 = v1 - v0;
    e2 = v2 - v0;

    h = d.crossProduct(e2);
    a0 = e1.dotProduct(h);

    if (a0 > -0.00001 && a0 < 0.00001)
        return is;

    f = 1 / a0;
    s = p - v0;
    u = f * (s.dotProduct(h));

    if (u < 0.0 || u > 1.0)
        return is;

    q = s.crossProduct(e1);
    v = f * d.dotProduct(q);

    if (v < 0.0 || u + v > 1.0)
        return is;

    // at this stage we can compute t to find out where
    // the intersection point is on the line
    float t = f * e2.dotProduct(q);

    if (t > 0.00001) { // ray intersection
        is.setIntersectionPoint(t);
        return is;
    }

    else // this means that there is a line intersection
         // but not a ray intersection
         return is;
}