Esempio n. 1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        foreach (Particle2DLink it in linkList)
        {
            it.CreateContacts(particleList[it.id1], particleList[it.id2]);
        }
        ContactResolver resolver = new ContactResolver();

        resolver.resolveContacts(contacts);
        for (int i = 0; i < particleList.Count; i++)
        {
            if (particleList[i] != null)
            {
                if (Vector2.Distance(particleList[i].transform.position, target.transform.position) <= .5)
                {
                    particleList[i].GetComponent <Particle2D>().Remove();
                    target.GetComponent <Target>().GetHit();
                }
                Integrator.Integrate(particleList[i]);
            }
        }
        foreach (int itr in destroyList)
        {
            Destroy(particleList[itr]);
            particleList[itr] = null;
        }
        destroyList.Clear();
    }
Esempio n. 2
0
 protected override double CreateMatrixElement(BoundaryElement <T> elem1, BoundaryElement <T> elem2, ConditionType conditionType)
 {
     switch (conditionType)
     {
     case ConditionType.Dirichlet:
         if (elem1.Bound.IsOuter && elem2.Bound.IsOuter)
         {
             return(Integrator.Integrate(elem1, elem2.Center, FundamentalSolution));
         }
         if (elem1.Bound.IsOuter && !elem2.Bound.IsOuter)
         {
             return(Integrator.IntegratedQdnx(elem1, elem2, Derivates));
         }
         if (!elem1.Bound.IsOuter && elem2.Bound.IsOuter)
         {
             return(Integrator.IntegratedQdny(elem1, elem2, Derivates));
         }
         if (!elem1.Bound.IsOuter && !elem2.Bound.IsOuter)
         {
             return(lambda * Kroneker(elem1, elem2) + Integrator.IntegratedQdnxdny(elem1, elem2, Derivates));
         }
         break;
     }
     return(double.NaN);
 }
Esempio n. 3
0
        private void UpdateIntegrator(Cdn.Integrator integrator)
        {
            bool hasSteppers = OnSteppedProxy != null && OnSteppedProxy.GetInvocationList().Length != 0;

            if (d_integrator != null)
            {
                if (hasSteppers)
                {
                    d_integrator.Stepped -= HandleIntegratorStepped;
                }

                d_integrator.Begun -= HandleIntegratorBegin;
                d_integrator.Ended -= HandleIntegratorEnd;
            }

            d_integrator = integrator;

            if (d_integrator != null)
            {
                d_integrator.Begun += HandleIntegratorBegin;
                d_integrator.Ended += HandleIntegratorEnd;

                if (hasSteppers)
                {
                    d_integrator.Stepped += HandleIntegratorStepped;
                }
            }
        }
Esempio n. 4
0
 void AssetUnitIntegrator.IntegrateAssetUnit(AssetRequestUnit reqUnit, AssetUnitIntegrateListener listener)
 {
     foreach (var Integrator in Integrators)
     {
         Integrator.IntegrateAssetUnit(reqUnit, listener);
     }
 }
Esempio n. 5
0
        public ActionResult <User> Get(string customerID)
        {
            List <User> usersInTheSystem = JsonConvert.DeserializeObject <List <User> >(_cache.Get(Constants.USERS_CACHE_KEY).ToString());
            var         userIndex        = usersInTheSystem.FindIndex(u => u.CustomerID.Equals(customerID));

            if (userIndex < 0)
            {
                return(Ok(new GetAccountResponse
                {
                    CustomerID = customerID,
                    User = null,
                    ReturnDescription = Constants.NO_SUCH_USER_IN_THE_SYSTEM
                }));
            }

            //I need to get transaction details from transaction API.
            var transactions = new Integrator().GetTransactionsFromRemoteAPI(new GetTransactionsRequest
            {
                CustomerID = customerID
            });

            if (null != usersInTheSystem[userIndex].Account)
            {
                usersInTheSystem[userIndex].Account.Transactions = transactions.Transactions;
            }
            return(Ok(new GetAccountResponse
            {
                CustomerID = customerID,
                User = usersInTheSystem[userIndex],
                ReturnDescription = Constants.OK
            }));
        }
            public void Execute()
            {
                float gravityLengthInOneStep = math.length(Gravity * TimeStep);

                for (int i = 0; i < MotionVelocities.Length; i++)
                {
                    var motionData     = MotionDatas[i];
                    var motionVelocity = MotionVelocities[i];

                    // Clip velocities using a simple heuristic:
                    // zero out velocities that are smaller than gravity in one step
                    if (math.length(motionVelocity.LinearVelocity) < motionVelocity.GravityFactor * gravityLengthInOneStep)
                    {
                        // Revert integration
                        Integrator.Integrate(ref motionData.WorldFromMotion, motionVelocity, -TimeStep);

                        // Clip velocity
                        motionVelocity.LinearVelocity  = float3.zero;
                        motionVelocity.AngularVelocity = float3.zero;

                        // Write back
                        MotionDatas[i]      = motionData;
                        MotionVelocities[i] = motionVelocity;
                    }
                }
            }
Esempio n. 7
0
    // Update is called once per frame
    void FixedUpdate()
    {
        foreach (Particle2DLink it in linkList)
        {
            it.CreateContacts(particleManager.GetParticle(it.id1), particleManager.GetParticle(it.id2), contactPrefab);
        }


        resolver.resolveContacts(contacts);
        particleManager.ParticleUpdate();
        for (int i = 0; i < particleManager.GetCount(); i++)
        {
            if (particleManager.GetParticle(i) != null)
            {
                if (Vector2.Distance(particleManager.GetParticle(i).transform.position, target.transform.position) <= .5)
                {
                    particleManager.GetParticle(i).GetComponent <Particle2D>().Remove();
                    target.GetComponent <Target>().GetHit();
                }
                Integrator.Integrate(particleManager.GetParticle(i));
            }
        }
        foreach (int itr in destroyList)
        {
            particleManager.RemoveParticle(itr);
        }
        destroyList.Clear();
        frame += .016f;
        if (frame >= .25)
        {
            MakeRandomProjectile(randomParticle);
            frame = 0;
        }
    }
Esempio n. 8
0
        public SPhysics(Scene scene, Integrator integrator, uint tasks, int targetFPS) : base(scene, tasks)
        {
            Require(typeof(CPosition), typeof(CKinetic));

            target          = 1f / targetFPS;
            this.integrator = integrator;
        }
Esempio n. 9
0
        private void Integrate(CPosition position, CKinetic kinetic, Integrator integrator, float deltaTime)
        {
            switch (integrator)
            {
            case Integrator.SemiImplictEuler:
                SemiImplictEulerIntegration();
                break;

            case Integrator.VelocityVerlet:
                VelocityVerletIntegration();
                break;
            }

            void SemiImplictEulerIntegration()
            {
                kinetic.Velocity += kinetic.Acceleration * deltaTime;

                position.X += kinetic.Velocity.X * deltaTime;
                position.Y += kinetic.Velocity.Y * deltaTime;
            }

            void VelocityVerletIntegration()
            {
                position.X += kinetic.Velocity.X * deltaTime + 0.5f * kinetic.Acceleration.X * deltaTime * deltaTime;
                position.Y += kinetic.Velocity.Y * deltaTime + 0.5f * kinetic.Acceleration.Y * deltaTime * deltaTime;

                kinetic.Velocity += kinetic.Acceleration * deltaTime;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Requesting a Quotation.
        /// Save Quotation information in the local database.
        /// Send the object to the IS to route to the Enterprise
        /// TODO : Authorization
        /// </summary>
        /// <param name="jsonBody"></param>
        /// <returns></returns>
        public IHttpActionResult RequestQuotation(JObject jsonBody)
        {
            using (var dbTransaction = db.Database.BeginTransaction()){
                try
                {
                    // Deserializing the json and gettting Quotation object
                    JObject products = (JObject)jsonBody["ProductsInQuotation"]; // this variable must be present in the javascript
                    jsonBody.Remove("ProductsInQuotation");
                    Quotation quotation = jsonBody.ToObject <Quotation>();
                    quotation.Status = "Request";

                    db.Quotations.Add(quotation);
                    db.SaveChanges();
                    int quotationId = quotation.QuotationId; // saving this in a seperate variable to make the code look simple


                    //Deserializing the object and getting Produts in Quotation
                    JEnumerable <JToken> tokens = (JEnumerable <JToken>)products.Children <JToken>();

                    foreach (JToken token in tokens)
                    {
                        JToken             productJson     = token.Children().First();
                        ProductInQuotation productInstance = productJson.ToObject <ProductInQuotation>();
                        productInstance.QuotationId = quotationId;
                        db.ProductsInQuotations.Add(productInstance);
                    }

                    db.SaveChanges();

                    // lets send this to the IS
                    Integrator integrator = new Integrator();
                    Setting    setting    = db.Settings.Find(1);

                    //reconstructing the jsonBody to send to the IS
                    jsonBody.Add("ProductsInQuotation", products);
                    // adding routing information. Some of these might be usefull at the Enterprise system too.
                    jsonBody.Add("ServiceId", setting.SystemIdNumber);
                    jsonBody.Add("SellingEnterpriseId", jsonBody["SellingEnterpriseId"]);
                    jsonBody.Add("BuyingEnterpriseId", jsonBody["BuyingEnterpriseId"]);


                    HttpWebResponse response = integrator.sendJsonObject(jsonBody, "/api/Enterprises/RequestQuotation");

                    if (response != null && response.StatusCode != HttpStatusCode.Conflict)
                    {
                        dbTransaction.Commit();
                        return(StatusCode(response.StatusCode));
                    }
                    else
                    {
                        dbTransaction.Rollback();
                        return(StatusCode(HttpStatusCode.Conflict));
                    }
                }catch (Exception ex) {
                    System.Diagnostics.Trace.WriteLine(ex);
                    dbTransaction.Rollback();
                    return(StatusCode(HttpStatusCode.Conflict));
                }
            }
        }
Esempio n. 11
0
 protected override double CreateMatrixElement(
     BoundaryElement <T> elem1,
     BoundaryElement <T> elem2,
     ConditionType conditionType)
 {
     if (conditionType == ConditionType.Robin)
     {
         var IsExponental = true;
         if (IsExponental)
         {
             var enumerator = KirghoffTransformation.U0 * KirghoffTransformation.U0 * KirghoffTransformation.LAMDA0 *
                              Integrator.Integrate(elem1, elem2.Center, FundamentalSolution);
             var denumerator = KirghoffTransformation.BETALAMDA * KirghoffTransformation.BETALAMDA
                               * (U(elem2.Center, solution) + 1);
             return(KirghoffTransformation.Nuv(elem2.Center) * enumerator / denumerator
                    - 0.5 * Kroneker(elem1, elem2) + Integrator.IntegratedQdnx(elem1, elem2, Derivates));
         }
         else
         {
             var enumerator  = Integrator.Integrate(elem1, elem2.Center, FundamentalSolution);
             var denumerator =
                 Math.Sqrt(
                     1
                     + 2 * KirghoffTransformation.BETALAMDA * U(elem2.Center, solution)
                     / (KirghoffTransformation.LAMDA0 * KirghoffTransformation.U0));
             return(KirghoffTransformation.Nuv(elem2.Center) * enumerator / (KirghoffTransformation.LAMDA0 * denumerator)
                    - 0.5 * Kroneker(elem1, elem2) + Integrator.IntegratedQdnx(elem1, elem2, Derivates));
         }
     }
     else
     {
         return(0);
     }
 }
Esempio n. 12
0
        public void Initialize()
        {
            _shimsContext  = ShimsContext.Create();
            _testEntity    = new Integrator();
            _privateObject = new PrivateObject(_testEntity);
            _privateType   = new PrivateType(typeof(Integrator));

            _actualLogMessage = new List <string>();
            _integrationLog   = new ShimIntegrationLog()
            {
                LogMessageStringIntegrationLogType = (log, level) => _actualLogMessage.Add(log)
            };

            _properties = new Hashtable()
            {
                { "AllowDeleteInt", "true" },
                { "Username", DummyUsername },
                { "Password", DummyPassword },
                { "SecurityToken", DummySecurityToken }
            };

            _webProperties = new WebProperties()
            {
                Properties = _properties
            };

            ShimWebClient.AllInstances.UploadValuesStringStringNameValueCollection =
                (_, address, method, data) => null;
            ShimSfMedadataService.ConstructorStringStringStringStringBoolean =
                (_, username, password, token, namespaceApp, sandbox) => { };
        }
Esempio n. 13
0
        static void create()
        {
            Console.WriteLine("Creating...");
            var baseDir = new FSODirectory(sourcePath, FSOType.RootDirectory)
            {
                Info = info
            };
            var subObjs = baseDir.trawlRecursively(new NominalRTM(prompt, sourcePath), false);

            baseDir.update();
            var objs = new List <FSOBase>();

            objs.Add(baseDir);
            objs.AddRange(subObjs);
            side1 = new Integrator(integratorTypes, 1, objs.Count);
            for (int i = 0; i < objs.Count; i++)
            {
                side1.set_block(0, i, objs[i].createElements());
            }
            if (serializeIntegration)
            {
                var sav = new BinaryLoaderSaver();
                side1.save(sav);
                File.WriteAllBytes(integrationFile, sav.data);
            }
            else
            {
                var sav = new XMLLoaderSaver();
                side1.save(sav);
                File.WriteAllText(integrationFile, sav.data);
            }
        }
        protected void SeedCollectionFromCsv <TSeedType, TEntityType>() where TEntityType : class where TSeedType : new()
        {
            var dbSet = _context.Set <TEntityType>();

            if (dbSet.Any())
            {
                return;
            }

            var lst = new List <TSeedType>();

            var builder = new InputBuilder()
                          .SetSerializer(new CsvSerializer())
                          .ReadAll(lst);


            var transport = new LocalFileTransport
            {
                FilePath = Path.Combine(_seedDataPath, "DataSeeds", $"{typeof(TEntityType).Name}.csv")
            };
            var integrator = new Integrator();

            integrator.ReceiveData(builder, transport);

            _logger.Information($"{typeof(TEntityType).Name} Table Empty. Seeding...");
            var config = new MapperConfiguration(cfg => { cfg.CreateMap <TSeedType, TEntityType>(); });

            var iMapper = config.CreateMapper();

            dbSet.AddRange(lst.Select(c => iMapper.Map <TSeedType, TEntityType>(c)));
            _context.SaveChanges();
            _logger.Information($"Seeding {typeof(TEntityType).Name} table completed successfully!");
        }
Esempio n. 15
0
        protected override double CreateMatrixElement(
            BoundaryElement <T> elem1,
            BoundaryElement <T> elem2,
            ConditionType conditionType)
        {
            double sum = 1;

            switch (conditionType)
            {
            case ConditionType.Pow:
                var derivate2   = Integrator.Integrate(elem1, elem2.Center, Derivates);
                var enumerator  = Integrator.Integrate(elem1, elem2.Center, FundamentalSolution);
                var denumerator =
                    Math.Sqrt(
                        1
                        + 2 * KirghoffTransformation.BETALAMDA * sum
                        / (KirghoffTransformation.LAMDA0 * KirghoffTransformation.U0));
                return(KirghoffTransformation.Nuv(elem2.Center) * enumerator
                       / (KirghoffTransformation.LAMDA0 * denumerator) - 0.5 * Kroneker(elem1, elem2)
                       + derivate2.ScalarMultiply(elem1.Normal));

            case ConditionType.Exp:
                return(0);
            }
            return(double.NaN);
        }
Esempio n. 16
0
        public SPhysics(MorroFactory factory, uint targetFramerate, Integrator integrator) : base(factory)
        {
            Require(typeof(CPosition), typeof(CKinetic));

            target          = 1f / targetFramerate;
            this.integrator = integrator;
        }
Esempio n. 17
0
        private string ValidateReceivedData(Integrator serviceInfoIntegrator, ServiceInfo serviceInfo)
        {
            string errors = string.Empty;

            switch (serviceInfo.Integrator)
            {
            case Integrator.Uyumsoft:
                break;

            case Integrator.EFinans:
                break;

            case Integrator.ING:
                break;

            case Integrator.DigitalPlanet:
                if (string.IsNullOrEmpty(serviceInfo.ReceiverPostboxName))
                {
                    errors += "Dijital planet üstünden fatura gönderebilmek için ReceiverPostboxName bilgisi gönderilmelidir!";
                }
                break;

            case Integrator.IsNet:
                break;

            default:
                errors = string.Empty;
                break;
            }

            return(errors);
        }
Esempio n. 18
0
        public void TestFixedWidthFormatter()
        {
            var elems = new List <ChemicalElement>()
            {
                new ChemicalElement {
                    Name = "Hydrogen", AtomicNumber = 1, DiscoveryDate = new DateTime(1766, 5, 16), Symbol = "H"
                },
                new ChemicalElement {
                    Name = "Phosporous", AtomicNumber = 15, DiscoveryDate = new DateTime(1669, 7, 17), Symbol = "P"
                },
                new ChemicalElement {
                    Name = "Cobalt", AtomicNumber = 27, DiscoveryDate = new DateTime(1732, 10, 11), Symbol = "Co"
                }
            };


            var serializer = new FixedWidthSerializer();

            var outputBuilder = new OutputBuilder()
                                .SetSerializer(new FixedWidthSerializer());

            File.Delete("chemistry.txt");

            var transport = new LocalFileTransport()
            {
                FilePath = @"chemistry.txt"
            };

            var integ = new Integrator();

            integ.SendData(outputBuilder, transport);


            return;
        }
Esempio n. 19
0
 public IterationNewtonMethod(List <BoundWithCondition <T> > bounds,
                              List <InnerSourceWithFunction <T> > sources,
                              Func <T, T, double> fundamentalSolution,
                              List <Func <T, T, double> > derivates,
                              Integrator <T> integrator)
     : base(bounds, sources, fundamentalSolution, derivates, integrator)
 {
 }
Esempio n. 20
0
        private Color Integrate(Surfel[] surfels)
        {
            var color = surfels
                        .Select(s => Integrator.GetColor(scene, s))
                        .Aggregate(Color.Black, (acc, c) => acc + c);

            return(color / surfels.Length);
        }
            /// <summary>Gets the absolute n-th central moment, i.e. E[|X- E[X]|^n], where E is the expectation operator.
            /// </summary>
            /// <param name="order">The order of the central moment.</param>
            /// <returns>The value of the absolute n-th central moment, i.e. E[|X- E[X]|^n], where E is the expectation operator.</returns>
            /// <remarks>The implementation is based on a numerical integral approach (Gauss-Laguerre).</remarks>
            public override double GetAbsCentralValue(int order)
            {
                var algorithm = Integrator.Create();

                algorithm.FunctionToIntegrate = (xk, k) => DoMath.Pow(Math.Abs(xk - 1.0), order); // |\beta * x - \beta|^n = \beta^n * |x-1.0|^n

                return(algorithm.GetValue() * DoMath.Pow(Distribution.Beta, order));
            }
Esempio n. 22
0
            public IntegratorPredictorCorrector(Integrator predictor, Integrator corrector) : base()
            {
                Predictor = predictor;
                Corrector = corrector;
                Debug.Assert(Predictor.Field.NumVectorDimensions >= Corrector.Field.NumVectorDimensions, "Predictor is " + Predictor.Field.NumVectorDimensions + "D, Corrector is " + Corrector.Field.NumVectorDimensions + "D!");

                Field = Predictor.Field;
            }
 public AirplanePhysicalModel(Airplane airplane, IAirplaneCommands commands)
 {
     _commands = commands;
     _airplane = airplane;
     Tanks = new List<Tank>();
     Thrusters = new List<Thruster>();
     Integrator = new Rk4Integrator<State>(CalculateDerivedState);
 }
 public AirplanePhysicalModel(Airplane airplane, IAirplaneCommands commands)
 {
     _commands  = commands;
     _airplane  = airplane;
     Tanks      = new List <Tank>();
     Thrusters  = new List <Thruster>();
     Integrator = new Rk4Integrator <State>(CalculateDerivedState);
 }
Esempio n. 25
0
        public SPhysics(Scene scene) : base(scene, 4)
        {
            Require(typeof(CPosition), typeof(CPhysicsBody));
            Depend(typeof(SFlocking));

            target     = 1f / 60;
            integrator = Integrator.SemiImplictEuler;
        }
Esempio n. 26
0
 protected override double CreateMatrixElement(BoundaryElement <T> elem1, BoundaryElement <T> elem2, ConditionType conditionType)
 {
     switch (conditionType)
     {
     case ConditionType.Dirichlet:
         return(Integrator.Integrate(elem1, elem2, FundamentalSolution));
     }
     return(double.NaN);
 }
Esempio n. 27
0
 public Generator(IConfiguration configuration)
 {
     _configuration = configuration;
     integrator     = new Integrator
     {
         IntegratorCode = configuration.GetValue <string>("IntegratorCode"),
         SecretCode     = configuration.GetValue <string>("SecretCode")
     };
 }
Esempio n. 28
0
 public Simulation(SoftBodyControl control)
 {
     this.control          = control;
     integrator            = new ForwardEulerIntegrator(control);
     simObjects            = new List <List <SimMass> >();
     globalForceGenerators = new List <ForceGenerator>();
     springList            = new List <List <Spring> >();
     constraintsList       = new List <List <LengthConstraint> >();
 }
Esempio n. 29
0
 public CollocationMethodNearBoundary(
     List <BoundWithCondition <T> > bound,
     List <InnerSourceWithFunction <T> > sources,
     Func <T, T, double> fundamentalSolution,
     List <Func <T, T, double> > derivates,
     Integrator <T> integrator)
     : base(bound, sources, fundamentalSolution, derivates, integrator)
 {
 }
Esempio n. 30
0
    void Update()
    {
        float dt = Time.deltaTime;

        bodies.ForEach(body => body.Step(dt));
        bodies.ForEach(body => Integrator.ExplicitEuler(body, dt));

        bodies.ForEach(body => body.force        = Vector2.zero);
        bodies.ForEach(body => body.acceleration = Vector2.zero);
    }
Esempio n. 31
0
    private Derivative evaluate2(float t, float dt, Derivative d, InputTuple i)
    {
        var p = pos + (d.velocity * dt);
        var m = momentum + (d.force * dt);
        var a = angle + d.torque * dt;
        var s = new Integrator(mass, p, Vector3.zero, m, a);

        s.recalculate();
        return(new Derivative(s.velocity, acceleration(dt, i), torque(dt, i)));
    }
Esempio n. 32
0
        /// <summary>
        /// This method solves first-order ODEs. It is passed an array
        /// of dependent variables in "array" at x, and returns an
        /// array of new values at x + h.
        /// </summary>
        /// <param name="initial">Array of initial values</param>
        /// <param name="x">Initial value of x (usually time)</param>
        /// <param name="h">Increment value for x (usually delta time)</param>
        /// <param name="system">Class containing a method to calculate the
        /// derivatives of the initial values</param>
        /// <param name="integrator">Type of numeric
        /// integration to use</param>
        /// <returns></returns>
        public static float[] Solve(float[] initial, float x, float h,
			CalculateDerivativesHandler calculateDerivatives,
			Integrator integrator)
        {
            switch (integrator)
            {
                case Integrator.Euler :
                    return SolveEuler(initial, x, h, calculateDerivatives);
                case Integrator.RK2 :
                    return SolveRK2(initial, x, h, calculateDerivatives);
                case Integrator.RK4 :
                    goto default;
                default :
                    return SolveRK4(initial, x, h, calculateDerivatives);
            }
        }