コード例 #1
0
ファイル: Trbdf2.cs プロジェクト: OpenDerivatives/QLCore
        public void setStep(double dt)
        {
            dt_ = dt;

            implicitPart_            = (Operator)L_.add(I_, L_.multiply(0.5 * alpha_ * dt_, L_));
            explicitTrapezoidalPart_ = (Operator)L_.subtract(I_, L_.multiply(0.5 * alpha_ * dt_, L_));
            explicitBDF2PartFull_    = (Operator)I_.multiply(-(1.0 - alpha_) * (1.0 - alpha_) / (alpha_ * (2.0 - alpha_)), I_);
            explicitBDF2PartMid_     = (Operator)I_.multiply(1.0 / (alpha_ * (2.0 - alpha_)), I_);
        }
コード例 #2
0
ファイル: RtlTranslator.cs プロジェクト: xxtxiaofeng/reko
        void translate(object pc_s, object pc_t)
        {
trans:
            // put (pc_s, pc_t) in codemap if not already there

            // get instruction from pc_s
            var I = GetNextInstr();

            RtlInstruction I_;

            switch (I.Class())
            {
            case Class.NCT:
                emit(I.Rtl);
                goto trans;

            case Class.SU:
                emit(goto I.nPC);
                queueForTranslation(I.nPC);

            case Class.SD:
            case Class.DD:
                // get next instruction.
                I_ = GetNextInstr();
                switch (I_.Class())
                {
                case Class.NCT:
                    emit(I.I_c);
                    emit(I_.I_c);
                    emitGoto(I.nPc);
                    queueForTranslation(I.nPC);
                }

            case Class.SCD:
                I_ = GetNextInstr();
                switch (I_.Class())
                {
                case Class.NCT:
                    var bb = newBlock();
                    emit(I_.I_c);
                    emit("if I.b goto bb");

                    // switch to bb.
                    emit(I_.I_c);
                    emitGoto(I.nPC);
                    goto trans;
                }
            }
        }
コード例 #3
0
ファイル: Trbdf2.cs プロジェクト: OpenDerivatives/QLCore
        public void step(ref object a, double t, double theta = 1.0)
        {
            int    i;
            Vector aInit = new Vector((a as Vector).size());

            for (i = 0; i < (a as Vector).size(); i++)
            {
                aInit[i] = (a as Vector)[i];
            }
            aInit_ = aInit;
            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].setTime(t);
            }
            //trapezoidal explicit part
            if (L_.isTimeDependent())
            {
                L_.setTime(t);
                explicitTrapezoidalPart_ = (Operator)I_.subtract(I_, L_.multiply(-0.5 * alpha_ * dt_, L_));
            }
            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].applyBeforeApplying(explicitTrapezoidalPart_);
            }
            a = explicitTrapezoidalPart_.applyTo((a as Vector));
            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].applyAfterApplying((a as Vector));
            }

            // trapezoidal implicit part
            if (L_.isTimeDependent())
            {
                L_.setTime(t - dt_);
                implicitPart_ = (Operator)I_.add(I_, L_.multiply(0.5 * alpha_ * dt_, L_));
            }
            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].applyBeforeSolving(implicitPart_, (a as Vector));
            }
            a = implicitPart_.solveFor((a as Vector));
            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].applyAfterSolving((a as Vector));
            }


            // BDF2 explicit part
            if (L_.isTimeDependent())
            {
                L_.setTime(t);
            }
            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].applyBeforeApplying(explicitBDF2PartFull_);
            }
            Vector b0 = explicitBDF2PartFull_.applyTo(aInit_);

            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].applyAfterApplying(b0);
            }

            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].applyBeforeApplying(explicitBDF2PartMid_);
            }
            Vector b1 = explicitBDF2PartMid_.applyTo((a as Vector));

            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].applyAfterApplying(b1);
            }
            a = b0 + b1;

            // reuse implicit part - works only for alpha=2-sqrt(2)
            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].applyBeforeSolving(implicitPart_, (a as Vector));
            }
            a = implicitPart_.solveFor((a as Vector));
            for (i = 0; i < bcs_.Count; i++)
            {
                bcs_[i].applyAfterSolving((a as Vector));
            }
        }