PView *elasticitySolver::buildVolumeView(const std::string postFileName)
{
  std::cout << "build Volume View";
  std::map<int, std::vector<double> > data;
  double voltot = 0;
  double length = 0;
  GaussQuadrature Integ_Vol(GaussQuadrature::Val);
  for(std::size_t i = 0; i < elasticFields.size(); ++i) {
    ScalarTermConstant<double> One(1.0);
    for(groupOfElements::elementContainer::const_iterator it =
          elasticFields[i].g->begin();
        it != elasticFields[i].g->end(); ++it) {
      MElement *e = *it;
      double vol;
      IntPt *GP;
      int npts = Integ_Vol.getIntPoints(e, &GP);
      One.get(e, npts, GP, vol);
      voltot += vol;
      std::vector<double> vec;
      vec.push_back(vol);
      data[e->getNum()] = vec;
    }
  }
  for(std::size_t i = 0; i < LagrangeMultiplierFields.size(); ++i) {
    ScalarTermConstant<double> One(1.0);
    for(groupOfElements::elementContainer::const_iterator it =
          LagrangeMultiplierFields[i].g->begin();
        it != LagrangeMultiplierFields[i].g->end(); ++it) {
      MElement *e = *it;
      double l;
      IntPt *GP;
      int npts = Integ_Vol.getIntPoints(e, &GP);
      One.get(e, npts, GP, l);
      length += l;
    }
    std::cout << " : length " << LagrangeMultiplierFields[i]._tag << " = "
              << length;
    length = 0;
  }
  PView *pv = new PView(postFileName, "ElementData", pModel, data, 0.0, 1);
  std::cout << " / total vol = " << voltot << std::endl;
  return pv;
}
Exemple #2
0
void g (N::A *a, M::B *b, O::C *c)
{
  One (a); // ok
  One (a, b); // ok
  One (b); // { dg-error "not declared" }
  // { dg-message "suggested alternatives" "suggested alternative for One" { target *-*-* } 34 }

  Two (c); // ok
  Two (a, c); // ok
  Two (a); // { dg-error "not declared" }
  // { dg-message "suggested alternatives" "suggested alternative for Two" { target *-*-* } 39 }
  Two (a, a); // error masked by earlier error
  Two (b); // error masked by earlier error
  Two (a, b); // error masked by earlier error
  
  Three (b); // ok
  Three (a, b); // ok
  Three (a); // { dg-error "not declared" }
  // { dg-message "suggested alternatives" "suggested alternative for Three" { target *-*-* } 47 }
}
Exemple #3
0
void main(void)
 {
   SomeClass One(1, 999); 
   cout << "One: " << One.my_data << ' ' << One.count << endl ;
   
   // Declare another instance
   SomeClass Two(2);
   cout << "Two: " << Two.my_data << ' ' << Two.count << endl ;
   
   // Declare another instance
   SomeClass Three(3);
   cout << "Three: " << Three.my_data << ' ' << Three.count << endl ;
 }
bool BigInt::isPrime(BigInt N)
{
	ll start = clock();
	BigInt One("1");
	if (N == One)
		return false;
	for (BigInt i("2"); i < sqrt(N); i = i + One)
	{
		if (N%i == BigInt("0"))
			return false;
	}
	ll finish = clock();
	TimeOfLast = static_cast<double>(finish - start) / 1000;
	return true;
}
vector<BigInt> BigInt::PollardP(BigInt N)
{
	ll start = clock();
	vector<BigInt> res;
	BigInt One("1");
	while (!isPrime(N) && N != One)
	{
		res.push_back(PollardP_get_factor(N));
		N = N / res.back();
	}
	if (isPrime(N))
		res.push_back(N);
	ll finish = clock();
	TimeOfLast = static_cast<double>(finish - start) / 1000;
	return res;
}
Exemple #6
0
//位移,如果非平滑SE将加上sevalue,即对应的灰度值
void G_Translation(double *src,double *dst,int width,int height,double SEvalue,Position *d,int istoFindMin){
    double *temp=(double*)malloc(sizeof(double)*height*width);
    if(istoFindMin)
        One(temp,width,height);
    else
        Zero(temp,width,height);
    for(int j=0;j<height;j++){
        for(int i=0;i<width;i++){
            int target_x=i+d->x;
            int target_y=j+d->y;
            if(target_x>=0&&target_y>=0&&
               target_x<width&&target_y<height){
                double value=src[j*width+i]+SEvalue;
                value=(value>=255.0?255.0:value);
                temp[target_y*width+target_x]=value;
            }
        }
    }
    matrixCopy(temp,dst,width,height);
    free(&temp);
}
Exemple #7
0
bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_SlotNum)
{
	cItem One(a_Entity.GetSlot(a_SlotNum).CopyOne());
	for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
	{
		if (m_Contents.IsSlotEmpty(i))
		{
			if (cPluginManager::Get()->CallHookHopperPullingItem(*m_World, *this, i, a_Entity, a_SlotNum))
			{
				// Plugin disagrees with the move
				continue;
			}

			m_Contents.SetSlot(i, One);
			return true;
		}
		else if (m_Contents.GetSlot(i).IsEqual(One))
		{
			if (cPluginManager::Get()->CallHookHopperPullingItem(*m_World, *this, i, a_Entity, a_SlotNum))
			{
				// Plugin disagrees with the move
				continue;
			}

			auto PreviousCount = m_Contents.GetSlot(i).m_ItemCount;
			m_Contents.ChangeSlotCount(i, 1);

			if (PreviousCount + 1 == m_Contents.GetSlot(i).m_ItemCount)
			{
				// Successfully added a new item. (Failure condition consistutes: stack full)
				return true;
			}
		}
	}
	return false;
}
Exemple #8
0
/* In the _vast_ majority of cases this simply checks that your chosen random
 * number is >= KLastSmallPrimeSquared and return EFalse and lets the normal
 * prime generation routines handle the situation.  In the case where it is
 * smaller, it generates a provable prime and returns ETrue.  The algorithm for
 * finding a provable prime < KLastPrimeSquared is not the most efficient in the
 * world, but two points come to mind
 * 1) The two if statements hardly _ever_ evaluate to ETrue in real life.
 * 2) Even when it is, the distribution of primes < KLastPrimeSquared is pretty
 * dense, so you aren't going to have check many.
 * This function is essentially here for two reasons:
 * 1) Ensures that it is possible to generate primes < KLastPrimeSquared (the
 * test code does this)
 * 2) Ensures that if you request a prime of a large bit size that there is an
 * even probability distribution across all integers < 2^aBits
 */
TBool TInteger::SmallPrimeRandomizeL(void)
	{
	TBool foundPrime = EFalse;
	//If the random number we've chosen is less than KLastSmallPrime,
	//testing for primality is easy.
	if(*this <= KLastSmallPrime)
		{
		//If Zero or One, or two, next prime number is two
		if(IsZero() || *this == One() || *this == Two())
			{
			CopyL(TInteger::Two());
			foundPrime = ETrue;
			}
		else
			{
			//Make sure any number we bother testing is at least odd
			SetBit(0);
			//Binary search the small primes.
			while(!IsSmallPrime(ConvertToUnsignedLong()))
				{
				//If not prime, add two and try the next odd number.

				//will never carry as the minimum size of an RInteger is 2
				//words.  Much bigger than KLastSmallPrime on 32bit
				//architectures.
				IncrementNoCarry(Ptr(), Size(), 2);
				}
			assert(IsSmallPrime(ConvertToUnsignedLong()));
			foundPrime = ETrue;
			}
		}
	else if(*this <= KLastSmallPrimeSquared)
		{
		//Make sure any number we bother testing is at least odd
		SetBit(0);

		while(HasSmallDivisorL(*this) && *this <= KLastSmallPrimeSquared)
			{
			//If not prime, add two and try the next odd number.

			//will never carry as the minimum size of an RInteger is 2
			//words.  Much bigger than KLastSmallPrime on 32bit
			//architectures.
			IncrementNoCarry(Ptr(), Size(), 2);
			}
		//If we exited while loop because it had no small divisor then it is
		//prime.  Otherwise, we've exceeded the limit of what we can provably
		//generate.  Therefore the normal prime gen routines will be run on it
		//now.
		if(*this < KLastSmallPrimeSquared)
			{
			foundPrime = ETrue;
			}
		else
			{
			assert(foundPrime == EFalse);
			}
		}
	//This doesn't mean there is no such prime, simply means that the number
	//wasn't less than KSmallPrimeSquared and needs to be handled by the normal
	//prime generation routines.
	return foundPrime;
	}
Exemple #9
0
 typename A::Field CIP(const A& a, const B& b) {
   BOOST_STATIC_ASSERT((in_same_space<A, B>::value));
   return CIP_impl_lin(a, One(), b);
 }
Exemple #10
0
// add using dual numbers
// combine diffeq and incorporation for direct RedTrace computation
void DerivativeRedTrace(float *red_out, float *ival_offset, float *da_offset, float *dk_offset,
                        int npts, float *deltaFrameSeconds, float *deltaFrame,
        float *nuc_rise_ptr, int SUB_STEPS, int my_start,
        Dual A, float SP,
        Dual kr, float kmax, float d,
                        float sens, float gain, float tauB,
                        PoissonCDFApproxMemo *math_poiss)
{
    int i;
    Dual totocc, totgen;
//    mixed_poisson_struct mix_ctrl;
    MixtureMemo mix_memo;

    Dual pact,pact_new;
    Dual  c_dntp_top, c_dntp_bot;
    Dual  hplus_events_sum, hplus_events_current; // mean events per molecule, cumulative and current

    Dual ldt;
    Dual Ival;

    Dual One(1.0);
    Dual Zero(0.0);
    Dual Half(0.5);

    Dual xSP(SP);
    Dual xkmax(kmax);
    Dual xd(d);

    Dual xA = mix_memo.Generate(A,math_poiss);
    //xA.Dump("xA");
    //A = InitializeMixture(&mix_ctrl,A,MAX_HPLEN); // initialize Poisson with correct amplitude which maxes out at MAX_HPLEN
    mix_memo.ScaleMixture(SP);
    //ScaleMixture(&mix_ctrl,SP); // scale mixture fractions to proper number of molecules
    pact = Dual(mix_memo.total_live);  // active polymerases // wrong???
    //pact.Dump("pact");
    //Dual pact_zero = pact;
    totocc = xSP*xA;  // how many hydrogens we'll eventually generate
    //totocc.Dump("totocc");
    totgen = totocc;  // number remaining to generate
    //totgen.Dump("totgen");
    c_dntp_bot = Zero; // concentration of dNTP in the well
    c_dntp_top = Zero; // concentration at top
    hplus_events_sum = hplus_events_current = Zero; // Events per molecule

    memset(ival_offset,0,sizeof(float[my_start]));  // zero the points we don't compute
    memset(da_offset,0,sizeof(float[my_start]));  // zero the points we don't compute
    memset(dk_offset,0,sizeof(float[my_start]));  // zero the points we don't compute

    Dual scaled_kr = kr*Dual(n_to_uM_conv)/xd; // convert molecules of polymerase to active concentraction
    Dual half_kr = kr *Half; // for averaging
   // kr.Dump("kr");
    //scaled_kr.Dump("scaled_kr");
    //half_kr.Dump("half_kr");

    // first non-zero index of the computed [dNTP] array for this nucleotide
    int c_dntp_top_ndx = my_start*SUB_STEPS;
    Dual c_dntp_bot_plus_kmax = Dual(1.0/kmax);
    Dual c_dntp_old_effect = Zero;
    Dual c_dntp_new_effect = Zero;
    Dual cur_gen(0.0);
    Dual equilibrium(0.0);
    int st;

    // trace variables
    Dual old_val = Zero;
    Dual cur_val = Zero;
    Dual run_sum = Zero;
    Dual half_dt = Zero;
    Dual TauB(tauB);
    Dual SENS(sens);

    memset(red_out,0,sizeof(float[my_start]));

    for (i=my_start;i < npts;i++)
    {
        // Do one prediction time step
        if (totgen.a > 0.0)
        {
          // need to calculate incorporation
            ldt = (deltaFrameSeconds[i]/SUB_STEPS); // multiply by half_kr out here, because I'm going to use it twice?
            ldt *= half_kr; // scale time by rate out here
            //ldt.Dump("ldt");
            for (st=1; (st <= SUB_STEPS) && (totgen.a > 0.0);st++)
            {
                c_dntp_bot.a = nuc_rise_ptr[c_dntp_top_ndx];
                c_dntp_top_ndx++;
                // calculate denominator
                equilibrium = c_dntp_bot_plus_kmax;
                equilibrium *= pact;
                equilibrium *= scaled_kr;
                equilibrium += One;
                c_dntp_bot /= equilibrium;
                //c_dntp_bot.Dump("c_dntp_bot");
                // the level at which new nucs are used up as fast as they diffuse in

                c_dntp_bot_plus_kmax.Reciprocal(c_dntp_bot + xkmax); // scale for michaelis-menten kinetics, assuming nucs are limiting factor
                //c_dntp_bot_plus_kmax.Dump("plus_kmax");
                // Now compute effect of concentration on enzyme rate
                c_dntp_old_effect = c_dntp_new_effect;
                c_dntp_new_effect = c_dntp_bot;
                c_dntp_new_effect *= c_dntp_bot_plus_kmax; // current effect of concentration on enzyme rate
                //c_dntp_new_effect.Dump("c_dntp_new");

                // update events per molecule
                hplus_events_current = c_dntp_old_effect;
                hplus_events_current += c_dntp_new_effect;
                hplus_events_current *= ldt;
                //hplus_events_current.Dump("current");  // events per molecule is average rate * time of rate
                hplus_events_sum += hplus_events_current;
                //hplus_events_sum.Dump("sum");


                // how many active molecules left at end of time period given poisson process with total intensity of events
                // exp(-t) * (1+t+t^2/+t^3/6+...) where we interpolate between polynomial lengths by A
                // exp(-t) ( 1+... + frac*(t^k/k!)) where k = ceil(A-1) and frac = A-floor(A), for A>=1
                pact_new = mix_memo.GetStep(hplus_events_sum);
                //pact_new = pact_zero;
                //pact_new.Dump("pact_new");
                // how many hplus were generated
                // reuse pact for average
                // reuse hplus-events_current for total events
                pact += pact_new;
                pact *= Half; // average number of molecules
                //hplus_events_current *= pact; // events/molecule *= molecule is total events
                totgen -= pact*hplus_events_current;  // active molecules * events per molecule
                //totgen.Dump("totgen");
                pact = pact_new; // update to current number of molecules
                //pact.Dump("pact");
            }

            if (totgen.a < 0.0) totgen = Zero;
        }
        Ival =  totocc;
        Ival -= totgen;
        ival_offset[i] = Ival.a;

        Ival *= SENS; // convert from hydrogen to counts

        // Now compute trace
        // trace
        half_dt = deltaFrame[i]*0.5;

        // calculate new value
        Ival *= TauB;
        cur_val = Ival;
        cur_val -= run_sum;
        old_val *= half_dt; // update
        cur_val -= old_val;
        cur_val /= (TauB+half_dt);
        // update run sum
        run_sum += old_val; // reuse update
        run_sum += cur_val*half_dt;
        old_val = cur_val; // set for next value

        //cur_val *= gain;  // gain=1.0 always currently
        
        red_out[i] = cur_val.a;
        da_offset[i] = cur_val.da;
        dk_offset[i] = cur_val.dk;
        // now we have done one prediction time step
    }
}
 *
 *         Author:  Adriaan, 
 *        Company:  Uppsala IT
 *
 * =====================================================================================
 */

#include "unit.h"

#include "module_copy.h"

int tests_run = 0;
int tests_set = 2;

TEST(getModule)
    MODDATA temp = One();
    CHECK("Did not fetch the One module",temp.identifier == 1);
DONE

TEST(getValue)
    DATA temp = Two_value();
    CHECK("Did not fetch Pair form Two.value",temp.t == PAIR);
    CHECK("Pair left hand side is not INT",temp.left->t == INT);
    CHECK("Pair right hand side is not BOOLEAN",temp.right->t == BOOLEAN);
    CHECK("Did not obtain left value == 1",temp.left->value == 1);
    CHECK("Did not obtain right value == 0",temp.right->value == 0);
DONE

LIST
    RUN(getModule);
    RUN(getValue);
void tree::fractalTree(int count, Vertex zero, Vertex one, float angleRight, float angleLeft)
{
	count--;
	if (count > 0) {
		vec4 Zero(zero.coords[0], zero.coords[1],zero.coords[2],1);
		vec4 One(one.coords[0], one.coords[1], one.coords[2],1);

		vec4 Scale = (One - Zero);
		Scale = Scale * 0.8f;
		//float randValue = randomFloat(-rand, rand);
		//float alpha = ((angleRight + randValue)*3.14 / 180);
		////mat3x3 rotMatrix(cos(alpha), sin(alpha), -sin(alpha), cos(alpha));
		//mat3x3 rotMatrixX(1, 0, 0, 0, cos(alpha), sin(alpha), 0, -sin(alpha), cos(alpha));
		//float randValue2 = randomFloat(-rand, rand);
		//float beta = ((angleRight + randValue2)*3.14 / 180);
		//mat3x3 rotMatrixZ(cos(beta), sin(beta), 0, -sin(beta), cos(beta), 0, 0, 0, 1);
		//vec3 Answer = (Scale * rotMatrixZ)*rotMatrixX;
		mat4 rotMatrix = mat4(1);
		rotMatrix = rotate(rotMatrix, randomFloat((-angleRight), angleRight)*3.14f/180.0f, vec3(0, 1, 0));
		rotMatrix = rotate(rotMatrix, randomFloat((-angleRight), angleRight)*3.14f / 180.0f, vec3(0, 0, 1));
		rotMatrix = rotate(rotMatrix, randomFloat((-angleRight), angleRight)*3.14f / 180.0f, vec3(1, 0, 0));
		vec4 Answer = rotMatrix * Scale;
		Answer = Answer + One;

		branches[branchesIterator].zero = one;
		branches[branchesIterator].zero.colors[0] = 0.3f;
		branches[branchesIterator].zero.colors[1] = 0.1f;
		branches[branchesIterator].one.coords[0] = Answer.x;
		branches[branchesIterator].one.coords[1] = Answer.y;
		branches[branchesIterator].one.coords[2] = Answer.z;
		branches[branchesIterator].one.coords[3] = 1;
		branches[branchesIterator].one.coords[3] = 1;
		branches[branchesIterator].one.colors[0] = 0.3f;
		branches[branchesIterator].one.colors[1] = 0.1f;
		if (count == 1)
			branches[branchesIterator].end = true;
		else
			branches[branchesIterator].end = false;
		branchesIterator++;
		depth.push_back(count);
		fractalTree(count, branches[branchesIterator - 1].zero, branches[branchesIterator - 1].one, angleRight, angleLeft);

		////////////////////////////////////////////////

		Zero = vec4(zero.coords[0], zero.coords[1], zero.coords[2],1);
		One = vec4(one.coords[0], one.coords[1], one.coords[2],1);

		Scale = One - Zero;
		Scale = Scale * 0.8f;
		/*randValue = randomFloat(-rand, rand);
		alpha = ((angleLeft +randValue)*3.14 / 180)*-1;
		rotMatrixX = mat3x3(1, 0, 0, 0, cos(alpha), sin(alpha), 0, -sin(alpha), cos(alpha));
		randValue2 = randomFloat(-rand, rand);
		beta = ((angleLeft + randValue2)*3.14 / 180)*-1;
		rotMatrixZ = mat3x3(cos(beta), sin(beta), 0, -sin(beta), cos(beta), 0, 0, 0, 1);
		Answer = (Scale * rotMatrixZ)*rotMatrixX;*/

		rotMatrix = mat4(1);
		rotMatrix = rotate(rotMatrix, (randomFloat((-angleLeft), angleLeft)*3.14f/180.0f), vec3(0, 1, 0));
		rotMatrix = rotate(rotMatrix, randomFloat((-angleLeft), angleLeft)*3.14f / 180.0f, vec3(0, 0, 1));
		rotMatrix = rotate(rotMatrix, randomFloat((-angleLeft), angleLeft)*3.14f / 180.0f, vec3(1, 0, 0));

		Answer = rotMatrix * Scale;
		Answer = Answer + One;

		branches[branchesIterator].zero = one;
		branches[branchesIterator].zero.colors[0] = 0.3f;
		branches[branchesIterator].zero.colors[1] = 0.1f;
		branches[branchesIterator].one.coords[0] = Answer.x;
		branches[branchesIterator].one.coords[1] = Answer.y;
		branches[branchesIterator].one.coords[2] = Answer.z;
		branches[branchesIterator].one.coords[3] = 1;
		branches[branchesIterator].one.coords[3] = 1;
		branches[branchesIterator].one.colors[0] = 0.3f;
		branches[branchesIterator].one.colors[1] = 0.1f;
		if (count == 1)
			branches[branchesIterator].end = true;
		else
			branches[branchesIterator].end = false;
		branchesIterator++;
		depth.push_back(count);
		fractalTree(count, branches[branchesIterator - 1].zero, branches[branchesIterator - 1].one, angleRight,angleLeft);
	}
}
bool Reed_Solomon::decode(const bvec &coded_bits, const ivec &erasure_positions, bvec &decoded_message, bvec &cw_isvalid)
{
  bool decoderfailure, no_dec_failure;
  int j, i, kk, l, L, foundzeros, iterations = floor_i(static_cast<double>(coded_bits.length()) / (n * m));
  bvec mbit(m * k);
  decoded_message.set_size(iterations * k * m, false);
  cw_isvalid.set_length(iterations);

  GFX rx(q, n - 1), cx(q, n - 1), mx(q, k - 1), ex(q, n - 1), S(q, 2 * t), Xi(q, 2 * t), Gamma(q), Lambda(q),
      Psiprime(q), OldLambda(q), T(q), Omega(q);
  GFX dummy(q), One(q, (char*)"0"), Omegatemp(q);
  GF delta(q), tempsum(q), rtemp(q), temp(q), Xk(q), Xkinv(q);
  ivec errorpos;

  if ( erasure_positions.length() ) {
    it_assert(max(erasure_positions) < iterations*n, "Reed_Solomon::decode: erasure position is invalid.");
  }
  
  no_dec_failure = true;
  for (i = 0; i < iterations; i++) {
    decoderfailure = false;
    //Fix the received polynomial r(x)
    for (j = 0; j < n; j++) {
      rtemp.set(q, coded_bits.mid(i * n * m + j * m, m));
      rx[j] = rtemp;
    }
    // Fix the Erasure polynomial Gamma(x)
    // and replace erased coordinates with zeros
    rtemp.set(q, -1);
    ivec alphapow = - ones_i(2);
    Gamma = One;
    for (j = 0; j < erasure_positions.length(); j++) {
      rx[erasure_positions(j)] = rtemp;
      alphapow(1) = erasure_positions(j);
      Gamma *= (One - GFX(q, alphapow));
    }
    //Fix the syndrome polynomial S(x).
    S.clear();
    for (j = 1; j <= 2 * t; j++) {
      S[j] = rx(GF(q, b + j - 1));
    }
    // calculate the modified syndrome polynomial Xi(x) = Gamma * (1+S) - 1
    Xi = Gamma * (One + S) - One;
    // Apply Berlekam-Massey algorithm
    if (Xi.get_true_degree() >= 1) { //Errors in the received word
      // Iterate to find Lambda(x), which hold all error locations
      kk = 0;
      Lambda = One;
      L = 0;
      T = GFX(q, (char*)"-1 0");
      while (kk < 2 * t) {
        kk = kk + 1;
        tempsum = GF(q, -1);
        for (l = 1; l <= L; l++) {
          tempsum += Lambda[l] * Xi[kk - l];
        }
        delta = Xi[kk] - tempsum;
        if (delta != GF(q, -1)) {
          OldLambda = Lambda;
          Lambda -= delta * T;
          if (2 * L < kk) {
            L = kk - L;
            T = OldLambda / delta;
          }
        }
        T = GFX(q, (char*)"-1 0") * T;
      }
      // Find the zeros to Lambda(x)
      errorpos.set_size(Lambda.get_true_degree());
      foundzeros = 0;
      for (j = q - 2; j >= 0; j--) {
        if (Lambda(GF(q, j)) == GF(q, -1)) {
          errorpos(foundzeros) = (n - j) % n;
          foundzeros += 1;
          if (foundzeros >= Lambda.get_true_degree()) {
            break;
          }
        }
      }
      if (foundzeros != Lambda.get_true_degree()) {
        decoderfailure = true;
      }
      else { // Forney algorithm...
        //Compute Omega(x) using the key equation for RS-decoding
        Omega.set_degree(2 * t);
        Omegatemp = Lambda * (One + Xi);
        for (j = 0; j <= 2 * t; j++) {
          Omega[j] = Omegatemp[j];
        }
        //Find the error/erasure magnitude polynomial by treating them the same
        Psiprime = formal_derivate(Lambda*Gamma);
        errorpos = concat(errorpos, erasure_positions);
        ex.clear();
        for (j = 0; j < errorpos.length(); j++) {
          Xk = GF(q, errorpos(j));
          Xkinv = GF(q, 0) / Xk;
          // we calculate ex = - error polynomial, in order to avoid the 
          // subtraction when recunstructing the corrected codeword
          ex[errorpos(j)] = (Xk * Omega(Xkinv)) / Psiprime(Xkinv);
          if (b != 1) { // non-narrow-sense code needs corrected error magnitudes
            int correction_exp = ( errorpos(j)*(1-b) ) % n;
            ex[errorpos(j)] *= GF(q, correction_exp + ( (correction_exp < 0) ? n : 0 ));
          }
        }
        //Reconstruct the corrected codeword.
        // instead of subtracting the error/erasures, we calculated 
        // the negative error with 'ex' above
        cx = rx + ex;
        //Code word validation
        S.clear();
        for (j = 1; j <= 2 * t; j++) {
          S[j] = cx(GF(q, b + j - 1));
        }
        if (S.get_true_degree() >= 1) {
          decoderfailure = true;
        }
      }
    }
    else {
      cx = rx;
      decoderfailure = false;
    }
    //Find the message polynomial
    mbit.clear();
    if (decoderfailure == false) {
      if (cx.get_true_degree() >= 1) { // A nonzero codeword was transmitted
        if (systematic) {
          for (j = 0; j < k; j++) {
            mx[j] = cx[j];
          }
        }
        else {
          mx = divgfx(cx, g);
        }
        for (j = 0; j <= mx.get_true_degree(); j++) {
          mbit.replace_mid(j * m, mx[j].get_vectorspace());
        }
      }
    }
    else { //Decoder failure.
      // for a systematic code it is better to extract the undecoded message
      // from the received code word, i.e. obtaining a bit error
      // prob. p_b << 1/2, than setting all-zero (p_b = 1/2)
      if (systematic) {
        mbit = coded_bits.mid(i * n * m, k * m);
      }
      else {
        mbit = zeros_b(k);
      }
      no_dec_failure = false;
    }
    decoded_message.replace_mid(i * m * k, mbit);
    cw_isvalid(i) = (!decoderfailure);
  }
  return no_dec_failure;
}
Exemple #14
0
static void
doit () throw (Two)			// { dg-warning "deprecated" "" { target { c++11 } } }
{
  throw One ();
}
Exemple #15
0
static void
doit () throw (Two)
{
  throw One ();
}
Vector SchemeRoe(const Cell& Cell1,const Cell& Cell2,const Cell& Cell3,const Cell& Cell4, int AxisNo)
{

		// Local variables

		Vector  V1, V2, V3, V4;                 // Velocities
		real 		rho1, rho2, rho3, rho4;					// Densities
		real		p1, p2, p3, p4;									// Pressures
		real		rhoE1, rhoE2, rhoE3, rhoE4;	    // Energies
		Vector  Result(QuantityNb);

		Vector	F1(QuantityNb);                 // Fluxes
		Vector  F2(QuantityNb);
		Vector  F3(QuantityNb);
		Vector  F4(QuantityNb);

		Vector Q1, Q2, Q3, Q4;									// Conservative quantities

		Vector  FL(QuantityNb),FR(QuantityNb);  // Left and right fluxex
		Vector  QL(QuantityNb),QR(QuantityNb);  // Left and right conservative quantities
		real    rhoL, rhoR;              				// Left and right densities
		real		pL, pR;                         // Left and right pressures
		real		rhoEL, rhoER;                   // Left and right energies
 		Vector	VL(Dimension), VR(Dimension);   // Left and right velocities

		Vector  One(QuantityNb);

		real		rho;														 // central density with Roe's average
		Vector  V(Dimension);										 // central velocity with Roe's average
    		real    H;                               // central enthalpy with Roe's average
    		real    c;                               // central speed of sound with Roe's average
		real		Roe;														 // Coefficient for Roe's average

		Matrix L, R;                              // left and right eigenmatrix
		Matrix Lambda(QuantityNb);								// diagonal matrix containing the eigenvalues
		Matrix A;																	// absolute value of the jacobian matrix

		Vector	 Lim;															// limiter (Van Leer)

	  int i;        														// coutner


		// vector one.

		for(i=1; i<=QuantityNb; i++ )
			One.setValue(i,1.);

 		// --- Get conservative quantities ---

		Q1 = Cell1.average();
		Q2 = Cell2.average();
		Q3 = Cell3.average();
		Q4 = Cell4.average();

		// --- Get primitive variables ---

		// density

    		rho1   = Cell1.density();
    		rho2   = Cell2.density();
    		rho3   = Cell3.density();
    		rho4   = Cell4.density();

		// velocity

 		V1 = Cell1.velocity();
 		V2 = Cell2.velocity();
 		V3 = Cell3.velocity();
 		V4 = Cell4.velocity();

		// energy

		rhoE1 = Cell1.energy();
		rhoE2 = Cell2.energy();
		rhoE3 = Cell3.energy();
		rhoE4 = Cell4.energy();

		// pressure

		p1 = Cell1.pressure();
		p2 = Cell2.pressure();
		p3 = Cell3.pressure();
		p4 = Cell4.pressure();

    // --- Compute Euler fluxes ---

		F1.setValue(1,rho1*V1.value(AxisNo));
		F2.setValue(1,rho2*V2.value(AxisNo));
 		F3.setValue(1,rho3*V3.value(AxisNo));
		F4.setValue(1,rho4*V4.value(AxisNo));

		for(i=1; i<=Dimension; i++)
		{
			F1.setValue(i+1, rho1*V1.value(AxisNo)*V1.value(i) + ((AxisNo == i)? p1 : 0.));
			F2.setValue(i+1, rho2*V2.value(AxisNo)*V2.value(i) + ((AxisNo == i)? p2 : 0.));
 			F3.setValue(i+1, rho3*V3.value(AxisNo)*V3.value(i) + ((AxisNo == i)? p3 : 0.));
			F4.setValue(i+1, rho4*V4.value(AxisNo)*V4.value(i) + ((AxisNo == i)? p4 : 0.));
		}

		F1.setValue(QuantityNb,(rhoE1+p1)*V1.value(AxisNo));
		F2.setValue(QuantityNb,(rhoE2+p2)*V2.value(AxisNo));
 		F3.setValue(QuantityNb,(rhoE3+p3)*V3.value(AxisNo));
		F4.setValue(QuantityNb,(rhoE4+p4)*V4.value(AxisNo));

		// --- Van Leer limiter ---

	 	// Left

	 	Lim = Limiter(Q3-Q2, Q2-Q1);
		FL  = F2 + 0.5*(Lim|(F2-F1)) + 0.5*((One-Lim)|(F3-F2));
		QL  = Q2 + 0.5*(Lim|(Q2-Q1)) + 0.5*((One-Lim)|(Q3-Q2));

		// Right

		Lim = Limiter(Q3-Q2, Q4-Q3);
		FR  = F3 - 0.5*(Lim|(F4-F3)) - 0.5*((One-Lim)|(F3-F2));
		QR  = Q3 - 0.5*(Lim|(Q4-Q3)) - 0.5*((One-Lim)|(Q3-Q2));

/*
		FL = F2;
		FR = F3;
		QL = Q2;
		QR = Q3;
*/

		// --- Extract left and right primitive variables ---

		rhoL = QL.value(1);
		rhoR = QR.value(1);

		for (i=1; i<= Dimension; i++)
		{
			 VL.setValue(i,QL.value(i+1)/rhoL);
			 VR.setValue(i,QR.value(i+1)/rhoR);
		}

		rhoEL=QL.value(QuantityNb);
		rhoER=QR.value(QuantityNb);

		pL = (Gamma-1)*(rhoEL - .5*rhoL*(VL*VL));
		pR = (Gamma-1)*(rhoER - .5*rhoR*(VR*VR));

    		// --- Compute Roe's averages ---

		Roe = sqrt(rhoR/rhoL);

		rho = Roe*rhoL;
		V   = 1./(1.+Roe)*( Roe*VR + VL );
		H   = 1./(1.+Roe)*( Roe*(rhoER+pR)/rhoR + (rhoEL+pL)/rhoL );

		c   = sqrt ( (Gamma-1)*( H - 0.5*(V*V) ) );

    		// --- Compute diagonal matrix containing the absolute value of the eigenvalues ---

		for (i=1;i<=Dimension;i++)
			Lambda.setValue(i,i, fabs(V.value(AxisNo)));

		Lambda.setValue(Dimension+1, Dimension+1, fabs(V.value(AxisNo)+c));
		Lambda.setValue(Dimension+2, Dimension+2, fabs(V.value(AxisNo)-c));

		// --- Set left and right eigenmatrices ---

		L.setEigenMatrix(true, AxisNo, V, c);
		R.setEigenMatrix(false, AxisNo, V, c, H);

		// --- Compute absolute Jacobian matrix ---

  		A = R*Lambda*L;
	
    		// --- Compute Euler Flux ---

		Result = 0.5*(FL+FR) - 0.5*(A*(QR-QL));

		return Result;
}