GithubHelp home page GithubHelp logo

mingtaoli / ai4emetapse.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ai4energy/ai4emetapse.jl

0.0 0.0 0.0 159 KB

A json parser , from ODE json files to julia solution code

License: MIT License

Julia 100.00%

ai4emetapse.jl's Introduction

Ai4EMetaPSE

Stable Dev Build Status

Ai4EMetaPSE.jl parses a json file that include differential equations and generate julia solution code based on Sciml Ecosystem.

Install

using Pkg
Pkg.add("Ai4EMetaPSE")

Document

see more infomation in docs

Example

JSON File:

{
    "name": "Name",
    "pkgs": [
        "ModelingToolkit",
        "DifferentialEquations"
    ],
    "variables": [
        "x(t) = 1.0",
        "y(t) = 1.0",
        "z(t) = 2.0"
    ],
    "parameters": [
        "σ = 1.0",
        "ρ = 3.0",
        "β = 5.0" 
    ],
    "equations": [
        "der(x) = σ*(y - x)",
        "der(y) = x*(ρ - z) - y",
        "der(z) = x*y - β*z"
    ],
    "u0": [
        "x => 1.0",
        "y => 2.0",
        "z => 3.0"
    ],
    "timespan": [0,1],
    "solver": "Rosenbrock23"
}

Using Ai4EMetaPSE to parse json file:

using Ai4EMetaPSE
str = """{
    "name": "Name",
    "pkgs": [
        "ModelingToolkit",
        "DifferentialEquations"
    ],
    "variables": [
        "x(t) = 1.0",
        "y(t) = 1.0",
        "z(t) = 2.0"
    ],
    "parameters": [
        "σ = 1.0",
        "ρ = 3.0",
        "β = 5.0" 
    ],
    "equations": [
        "der(x) = σ*(y - x)",
        "der(y) = x*(ρ - z) - y",
        "der(z) = x*y - β*z"
    ],
    "u0": [
        "x => 1.0",
        "y => 2.0",
        "z => 3.0"
    ],
    "timespan": [0,1],
    "solver": "Rosenbrock23"
}"""
solution = generatecode(str, CommonJson(); write2File="s.jl")

In current folder, s.jl will be generated and solution codes are:

begin
    begin
        #= d:\postgraduate\project\develop\Ai4EMetaPSE\src\solution.jl:48 =#
        using Pkg
        #= d:\postgraduate\project\develop\Ai4EMetaPSE\src\solution.jl:49 =#
        pkgNeeds = ["ModelingToolkit", "DifferentialEquations"]
        #= d:\postgraduate\project\develop\Ai4EMetaPSE\src\solution.jl:50 =#
        alreadyGet = keys((Pkg.project()).dependencies)
        #= d:\postgraduate\project\develop\Ai4EMetaPSE\src\solution.jl:51 =#
        toAdd = [package for package = pkgNeeds if package  alreadyGet]
        #= d:\postgraduate\project\develop\Ai4EMetaPSE\src\solution.jl:52 =#
        if isempty(toAdd)
            nothing
        else
            Pkg.add(toAdd)
        end
        #= d:\postgraduate\project\develop\Ai4EMetaPSE\src\solution.jl:53 =#
        using ModelingToolkit, DifferentialEquations
    end
    #= none:1 =# @variables begin
            t
            x(t) = begin
                    #= none:1 =#
                    1.0
                end
            y(t) = begin
                    #= none:1 =#
                    1.0
                end
            z(t) = begin
                    #= none:1 =#
                    2.0
                end
        end
    #= none:1 =# @parameters begin
            σ = 1.0
            ρ = 3.0
            β = 5.0
        end
    begin
        der = Differential(t)
        eqs = []
        append!(eqs, [der(x) ~ σ * (y - x)])
        append!(eqs, [der(y) ~ x *- z) - y])
        append!(eqs, [der(z) ~ x * y - β * z])
    end
    init = Dict(x => 1.0, y => 2.0, z => 3.0)
    timespan = (0.0, 1.0)
    Name = solve(ODEProblem(structural_simplify(ODESystem(eqs, t; name = :Model)), init, timespan), Rosenbrock23())
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.