Ejemplo n.º 1
0
    void GCMarkStack::Clear()
    {
        // Clear out the elements
        while (m_topSegment->m_prev != NULL)
            PopSegment();
        m_top = m_base;

        // Discard the cached segment
        if (m_extraSegment != NULL) {
            FreeStackSegment(m_extraSegment);
            m_extraSegment = NULL;
        }
        GCAssert(Invariants());
    }
Ejemplo n.º 2
0
    GCMarkStack::GCMarkStack()
        : m_base(NULL)
        , m_top(NULL)
        , m_limit(NULL)
        , m_topSegment(NULL)
        , m_hiddenCount(0)
        , m_extraSegment(NULL)
#ifdef MMGC_MARKSTACK_DEPTH
        , m_maxDepth(0)
#endif
    {
        GCAssert(sizeof(GCMarkStack::GCStackSegment) <= GCHeap::kBlockSize);
        PushSegment(true);
        GCAssert(Invariants());
    }
Ejemplo n.º 3
0
CircuitBranch::CircuitBranch(float ElementValue, ElementType element)
{
if (element == CoilElement)
   {
	ItsCoil = ElementValue;
	// Allow the inductive effect to dominate in the branch.
	ItsCapacitor = 0;
	relation = InParallel;
   }
else
   {
	ItsCapacitor = ElementValue;
	// Allow the capacitive effect to dominate in the branch.
	ItsCoil = 0;
	relation = InSeries;
   }
assert(Invariants());
}
Ejemplo n.º 4
0
    bool GCMarkStack::TransferOneFullSegmentFrom(GCMarkStack& other)
    {
        GCAssert(other.EntirelyFullSegments() > 0);
        GCStackSegment* seg;

        if (other.m_topSegment->m_prev == NULL) {
            // Picking off the only segment
            GCAssert(other.m_top == other.m_limit);
            seg = other.m_topSegment;
            other.m_topSegment = NULL;
            other.m_base = NULL;
            other.m_top = NULL;
            other.m_limit = NULL;
            if (!other.PushSegment()) {
                // Oops: couldn't push it, so undo.  We're out of memory but we
                // don't want to signal OOM here, we want to recover, signal failure,
                // and let the caller handle it.
                other.m_topSegment = seg;
                other.m_base = seg->m_items;
                other.m_top = other.m_limit = other.m_base + kMarkStackItems;
                return false;
            }
        }
        else {
            // Picking off the one below the top always
            seg = other.m_topSegment->m_prev;
            other.m_topSegment->m_prev = seg->m_prev;
            other.m_hiddenCount -= kMarkStackItems;
        }

        // Insert it below our top segment
        seg->m_prev = m_topSegment->m_prev;
        m_topSegment->m_prev = seg;
        m_hiddenCount += kMarkStackItems;

        // Special case that occurs if a segment was inserted into an empty stack.
        if (m_top == m_base)
            PopSegment();
        GCAssert(Invariants());
        GCAssert(other.Invariants());
        return true;
    }
Ejemplo n.º 5
0
void
CircuitBranch::Display(char DefaultType[]) const
{
assert(Invariants());
WriteTwice << "\tcircuit " << DefaultType;
Branch::Display();
if (ItsCoil != 0) WriteTwice << "coil=" << ItsCoil << " H";
if (ItsCapacitor != 0)
   {
	if (ItsCoil != 0) cout << '\t';
	WriteTwice << "capacitor=" << ItsCapacitor << " F";
	if (ItsCoil != 0)
	   {
		WriteTwice << "\trelation=";
		if (relation == InSeries) WriteTwice << "in series";
		else WriteTwice << "in parallel";
	   }
   }
WriteTwice << '\n';
}
/*!
 * \param B Any Algebraic number, including *this.
 * \return -1 if *this in less than B. \b
 *          0 if *this is equal to B. \b
 *         +1 if *this is greater than B.
 */
int Algebraic::compare(const Algebraic & B) const
{
    assert(Invariants());

    Algebraic a(*this), b(B);

    if (a.polynomial != b.polynomial)
    {
        while (true)
        {
            if (a.lower() > b.upper())
                return 1;

            if (a.upper() < b.lower())
                return -1;

            a.tightenInterval();
            b.tightenInterval();
        }
    }
    else
    {
        while (true)
        {
            if (a.lower() >= b.lower() && a.upper() <= b.upper())
                return 0;

            if (a.lower() > b.upper())
                return 1;

            if (a.upper() < b.lower())
                return -1;

            a.tightenInterval();
        }
    }

    assert(false);

    return -41;
}
/*!
 * \brief Shrinks the interval around the root.
 */
void Algebraic::tightenInterval() const
{
    assert(Invariants());

    const GiNaC::numeric & l = rootinterval.lower(),
                         & u = rootinterval.upper(); // invoke copy cons?
    const GiNaC::numeric m = (l + u)/2;
    const GiNaC::numeric sample = polynomial.eval(m);

    if (sample.is_zero())
        rootinterval.assign((l+m)/2, (u+m)/2);
    else
    {
        const GiNaC::numeric num = sample * polynomial.eval(u);

        if (!num.is_positive()) // (num <= 0)
            rootinterval.assignLower(m);
        else
            rootinterval.assignUpper(m);
    }
}
Ejemplo n.º 8
0
Branch*
CircuitBranch::Transform(Transformation type, FilterType format,
float RadialFrequency, float impedance, float BandwidthRatio,
float RelativePermittivity, float height, float impedance2)
{
enum Control{RelativeLength, CharacteristicImpedance} choice;
EndType BranchEnd;
StringArray ChoiceMenu = {"tan(Bl)", "characteristic impedance"};
const char DefaultTanBl = 1;
const float ThresholdLength = 0.3e-3;
Branch *NewBranch, *temp;
Connection NewRelation;
float UsedImpedance, length, &LengthMultiplier = impedance2,
TanBl = DefaultTanBl, wavelength;
assert(Invariants());
if ((format == BP || format == BS) && BandwidthRatio == 0) PRINT_ERROR;
if (type == scale)
   {
	switch (format)
	   {
		case LP:
		if (ItsCapacitor != 0) ItsCapacitor /= impedance * RadialFrequency;
		else ItsCoil *= impedance / RadialFrequency;
		break;
		case BP:
		if (ItsCapacitor != 0)
		   {
			ItsCoil = BandwidthRatio * impedance / RadialFrequency /
			ItsCapacitor;
			ItsCapacitor /= impedance * RadialFrequency * BandwidthRatio;
			relation = InParallel;
		   }
		else
		   {
			ItsCapacitor = BandwidthRatio / RadialFrequency / impedance /
			ItsCoil;
			ItsCoil *= impedance / RadialFrequency / BandwidthRatio;
			relation = InSeries;
		   }
		break;
		case HP:
		if (ItsCapacitor != 0)
		   {
			ItsCoil = impedance / RadialFrequency / ItsCapacitor;
			ItsCapacitor = 0;
			relation = InParallel;
		   }
		else
		   {
			ItsCapacitor = 1 / impedance / RadialFrequency / ItsCoil;
			ItsCoil = 0;
			relation = InSeries;
		   }
		break;
		case BS:
		if (ItsCapacitor != 0)
		   {
			ItsCoil = impedance / RadialFrequency / ItsCapacitor /
			BandwidthRatio;
			ItsCapacitor *= BandwidthRatio / impedance / RadialFrequency;
		   }
		else
		   {
			ItsCapacitor = 1 / BandwidthRatio / impedance / RadialFrequency /
			ItsCoil;
			ItsCoil *= impedance * BandwidthRatio / RadialFrequency;
		   }
	   }
   }
else
   {
	switch (type)
	   {
		case microstrip:
		UsedImpedance = ItsCapacitor == 0 ? impedance : impedance2;
		break;
		case shunt:
		UsedImpedance = impedance;
		break;
		case TL:
		// if there is only a capacitor or a capacitor in parallel with a
		// coil,transform the capacitor only.
		if (ItsCapacitor != 0 && (ItsCoil == 0 || relation == InParallel))
		   {
			choice = GetChoice(ChoiceMenu,
			"Please,choose which data you'd like to provide.", 2);
			if (choice == RelativeLength)
			   {
				ReadQuantity("tan(Bl) for capacitor", TanBl, DefaultTanBl);
				UsedImpedance = TanBl / RadialFrequency / ItsCapacitor;
			   }
			else
			   {
				ReadQuantity("capacitor microstrip section impedance",
				UsedImpedance, DefaultImpedance);
				TanBl = UsedImpedance * RadialFrequency * ItsCapacitor;
			   }
			ItsCapacitor = 0;
			relation = InParallel;
			BranchEnd = OpenCircuit;
		   }
		else if (ItsCoil != 0 && ItsCapacitor == 0)
		   {
			choice = GetChoice(ChoiceMenu,
			"Please,choose which data you'd like to provide.", 2);
			if (choice == RelativeLength)
			   {
				ReadQuantity("tan(Bl) for coil", TanBl, DefaultTanBl);
				UsedImpedance = RadialFrequency * ItsCoil / TanBl;
			   }
			else
			   {
				ReadQuantity("coil microstrip section impedance",
				UsedImpedance, DefaultImpedance);
				TanBl = RadialFrequency * ItsCoil / UsedImpedance;
			   }
			ItsCoil = 0;
			BranchEnd = ShortCircuit;
		   }
		else if (ItsCoil != 0 && ItsCapacitor != 0)// This if statement is
		// executed only if the two non-zero elements are in series.
		   {
			UsedImpedance = RadialFrequency * ItsCoil / LengthMultiplier /
			M_PI_4;
			BranchEnd = OpenCircuit;
		   }
		else return NULL;
	   }
	NewBranch = new MicrostripSeriesBranch(UsedImpedance, height,
	RelativePermittivity);// Note that branch is an auxilary section in case
	// of transforming to shunt stubs or transmission line.
	// Calculate the length of the microstrip section.
	RelativePermittivity = (RelativePermittivity + 1) / 2 +
	(RelativePermittivity - 1) / 2 / sqrt(1 + 12 * height /
	NewBranch -> GetWidth());
	length = LightVelocity / sqrt(RelativePermittivity) / RadialFrequency;
	wavelength = 2 * M_PI * length;
	if (type == microstrip)
	   {
		length *= ItsCoil == 0 ? atan(UsedImpedance *
		RadialFrequency * ItsCapacitor) : atan(RadialFrequency * ItsCoil /
		UsedImpedance);
		for (; length < ThresholdLength; length += wavelength / 2);
		NewBranch -> SetLength(length);
	   }
	else
	   {
		delete NewBranch;// Delete the auxilary microstrip section.
		if (type == TL)
		   {
			if (ItsCoil != 0 && ItsCapacitor != 0 && relation == InSeries)
			   {
				length *= LengthMultiplier * M_PI_2;
				ItsCoil = 0;
				ItsCapacitor = 0;
				relation = InParallel;
			   }
			else
			   {
				if (TanBl == 1) length *= M_PI_4;
				else length *= atan(TanBl);
				for (; length < ThresholdLength; length += wavelength / 2);
			   }
			NewBranch = new TLShuntBranch(UsedImpedance, length, BranchEnd);
		   }
		else
		   {
			length *= M_PI_2;
			for (; length < ThresholdLength; length += wavelength / 2);
			NewBranch = new TLSeriesBranch(UsedImpedance, length);
			if (ItsCoil == 0)
			temp = new CircuitShuntBranch(pow(UsedImpedance, 2) *
			ItsCapacitor, CoilElement);
			else if (ItsCapacitor == 0)
			temp = new CircuitShuntBranch(ItsCoil / pow(UsedImpedance, 2),
			CapacitorElement);
			else
			   {
				if (relation == InSeries) NewRelation = InParallel;
				else NewRelation = InSeries;
				temp = new CircuitShuntBranch(pow(UsedImpedance, 2) *
				ItsCapacitor,ItsCoil / pow(UsedImpedance, 2), NewRelation);
			   }
			NewBranch -> SetParallelBranch(temp);
			temp = new TLSeriesBranch(UsedImpedance, length);
			NewBranch -> SetSeriesBranch(temp);
		   }
	   }
   }
assert(Invariants());
if (type == scale) return this;
return NewBranch;
}
Ejemplo n.º 9
0
void
CircuitSeriesBranch::SetSeriesBranch(Branch* NewSeries)
{
SeriesBranch::SetSeriesBranch(NewSeries);
assert(Invariants());
}
Ejemplo n.º 10
0
void
CircuitSeriesBranch::SetParallelBranch(Branch* NewParallel)
{
SeriesBranch::SetParallelBranch(NewParallel);
assert(Invariants());
}
Ejemplo n.º 11
0
Branch*
CircuitSeriesBranch::GetSeriesBranch(void) const
{
assert(Invariants());
return SeriesBranch::GetSeriesBranch();
}
Ejemplo n.º 12
0
CircuitBranch::~CircuitBranch()
{
assert(Invariants());
}