licenses
sequencelengths
1
3
version
stringclasses
677 values
tree_hash
stringlengths
40
40
path
stringclasses
1 value
type
stringclasses
2 values
size
stringlengths
2
8
text
stringlengths
25
67.1M
package_name
stringlengths
2
41
repo
stringlengths
33
86
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
code
4534
""" Controller The controller struct is used to manage the workers and the jobs. It keeps track of the workers' status, the job queue, and the pending jobs. It also keeps track of the last job id that was sent to the workers. """ mutable struct Controller n_workers::Int debug_mode::Bool worker_status::Vector{WorkerStatus} last_job_id::Int job_queue::Vector{Job} pending_jobs::Vector{JobRequest} function Controller(n_workers::Int; debug_mode::Bool = false) return new(n_workers, debug_mode, fill(WORKER_AVAILABLE, n_workers), 0, Vector{Job}(), Vector{JobRequest}()) end end struct TerminationMessage end _is_worker_available(controller::Controller, worker::Int) = controller.worker_status[worker] == WORKER_AVAILABLE is_job_queue_empty(controller::Controller) = isempty(controller.job_queue) any_pending_jobs(controller::Controller) = !isempty(controller.pending_jobs) function any_jobs_left(controller::Controller) return !is_job_queue_empty(controller) || any_pending_jobs(controller) end function _pick_job_to_send!(controller::Controller) if !is_controller_process() error("Only the controller process can pick jobs to send.") end if !is_job_queue_empty(controller) return popfirst!(controller.job_queue) else error("Controller does not have any jobs to send.") end end function _pick_available_workers(controller::Controller) if !is_controller_process() error("Only the controller process can pick available workers.") end available_workers = [] for i in 1:controller.n_workers if _is_worker_available(controller, i) push!(available_workers, i) end end return available_workers end """ add_job_to_queue!(controller::Controller, message::Any) Add a job to the controller's job queue. """ function add_job_to_queue!(controller::Controller, message::Any) if !is_controller_process() error("Only the controller process can add jobs to the queue.") end controller.last_job_id += 1 return push!(controller.job_queue, Job(controller.last_job_id, message)) end """ send_jobs_to_any_available_workers(controller::Controller) Send jobs to any available workers. """ function send_jobs_to_any_available_workers(controller::Controller) if !is_controller_process() error("Only the controller process can send jobs to workers.") end available_workers = _pick_available_workers(controller) for worker in available_workers if !is_job_queue_empty(controller) job = _pick_job_to_send!(controller) controller.worker_status[worker] = WORKER_BUSY request = MPI.isend(job, _mpi_comm(); dest = worker, tag = worker + 32) push!(controller.pending_jobs, JobRequest(worker, request)) end end return nothing end """ send_termination_message(controller::Controller) Send a termination message to all workers. """ function send_termination_message(controller::Controller) if !is_controller_process() error("Only the controller process can send termination messages.") end requests = Vector{JobRequest}() for worker in 1:controller.n_workers request = MPI.isend(Job(controller.last_job_id, TerminationMessage()), _mpi_comm(); dest = worker, tag = worker + 32) controller.worker_status[worker] = WORKER_AVAILABLE push!(requests, JobRequest(worker, request)) end return _wait_all(requests) end """ check_for_job_answers(controller::Controller) Check if any worker has completed a job and return the answer. """ function check_for_job_answers(controller::Controller) if !is_controller_process() error("Only the controller process can check for workers' jobs.") end for j_i in eachindex(controller.pending_jobs) worker_completed_a_job = MPI.Iprobe( _mpi_comm(); source = controller.pending_jobs[j_i].worker, tag = controller.pending_jobs[j_i].worker + 32, ) if worker_completed_a_job job_answer = MPI.recv( _mpi_comm(); source = controller.pending_jobs[j_i].worker, tag = controller.pending_jobs[j_i].worker + 32, ) controller.worker_status[controller.pending_jobs[j_i].worker] = WORKER_AVAILABLE deleteat!(controller.pending_jobs, j_i) return job_answer end end return nothing end
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
code
542
abstract type AbstractJob end Base.@kwdef mutable struct Job{T} <: AbstractJob id::Int = 0 message::T end mutable struct JobAnswer{T} <: AbstractJob job_id::Int message::T end mutable struct JobRequest worker::Int request::MPI.Request end """ get_message(job::AbstractJob) Get the message from a job. """ get_message(job::AbstractJob) = job.message function _wait_all(job_requests::Vector{JobRequest}) requests = [job_request.request for job_request in job_requests] return MPI.Waitall(requests) end
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
code
448
function mpi_init() return MPI.Init() end function mpi_finalize() return MPI.Finalize() end _mpi_comm() = MPI.COMM_WORLD mpi_barrier() = MPI.Barrier(_mpi_comm()) my_rank() = MPI.Comm_rank(_mpi_comm()) world_size() = MPI.Comm_size(_mpi_comm()) is_running_in_parallel() = world_size() > 1 is_controller_process() = my_rank() == 0 controller_rank() = 0 is_worker_process() = !is_controller_process() num_workers() = world_size() - 1
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
code
2675
function _p_map_workers_loop(f, data_defined_in_process) if is_worker_process() worker = Worker() while true job = receive_job(worker) message = get_message(job) if message == TerminationMessage() break end answer_message = if data_defined_in_process === nothing f(message) else f(data_defined_in_process, message) end send_job_answer_to_controller(worker, answer_message) end end return nothing end """ pmap(f, jobs, data_defined_in_process = nothing) Parallel map function that works with MPI. If the function is called in parallel, it will distribute the jobs to the workers and collect the results. If the function is called in serial, it will just map the function to the jobs. The function `f` should take one argument, which is the message to be processed. If `data_defined_in_process` is not `nothing`, the function `f` should take two arguments, the first one being `data_defined_in_process`. The controller process will return the answer in the same order as the jobs were given. The workers will return nothing. """ function pmap(f::Function, jobs::Vector, data_defined_in_process = nothing) result = Vector{Any}(undef, length(jobs)) if is_running_in_parallel() mpi_barrier() if is_controller_process() controller = Controller(num_workers()) for job in jobs add_job_to_queue!(controller, job) end while any_jobs_left(controller) if !is_job_queue_empty(controller) send_jobs_to_any_available_workers(controller) end if any_pending_jobs(controller) job_answer = check_for_job_answers(controller) if !isnothing(job_answer) message = get_message(job_answer) job_id = job_answer.job_id result[job_id] = message end end end send_termination_message(controller) mpi_barrier() return result else _p_map_workers_loop(f, data_defined_in_process) mpi_barrier() return nothing end else for (i, job) in enumerate(jobs) result[i] = if data_defined_in_process === nothing f(job) else f(data_defined_in_process, job) end end return result end return error("Should never get here") end
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
code
1121
@enum WorkerStatus begin WORKER_BUSY = 0 WORKER_AVAILABLE = 1 end """ Worker A worker process. """ mutable struct Worker rank::Int job_id_running::Int Worker() = new(my_rank(), -1) end function has_job(worker::Worker) return MPI.Iprobe(_mpi_comm(); source = controller_rank(), tag = worker.rank + 32) end """ send_job_answer_to_controller(worker::Worker, message) Send a job answer to the controller process. """ function send_job_answer_to_controller(worker::Worker, message) if !is_worker_process() error("Only the controller process can send job answers.") end job = JobAnswer(worker.job_id_running, message) return MPI.isend(job, _mpi_comm(); dest = controller_rank(), tag = worker.rank + 32) end """ receive_job(worker::Worker) Receive a job from the controller process. """ function receive_job(worker::Worker) if !is_worker_process() error("Only the controller process can receive jobs.") end job = MPI.recv(_mpi_comm(); source = controller_rank(), tag = worker.rank + 32) worker.job_id_running = job.id return job end
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
code
440
using Test using JobQueueMPI using MPI ENV["JULIA_PROJECT"] = dirname(Base.active_project()) JQM = JobQueueMPI @testset verbose = true "JobQueueMPI Tests" begin mpiexec(exe -> run(`$exe -n 3 $(Base.julia_cmd()) --project test_1.jl`)) mpiexec(exe -> run(`$exe -n 3 $(Base.julia_cmd()) --project test_2.jl`)) mpiexec(exe -> run(`$exe -n 3 $(Base.julia_cmd()) --project test_pmap_mpi.jl`)) include("test_pmap_serial.jl") end
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
code
2062
using JobQueueMPI using Test JQM = JobQueueMPI mutable struct Message value::Int vector_idx::Int end all_jobs_done(controller) = JQM.is_job_queue_empty(controller) && !JQM.any_pending_jobs(controller) function sum_100(message::Message) message.value += 100 return message end function update_data(new_data, message::Message) idx = message.vector_idx value = message.value return new_data[idx] = value end function workers_loop() if JQM.is_worker_process() worker = JQM.Worker() while true job = JQM.receive_job(worker) message = JQM.get_message(job) if message == JQM.TerminationMessage() break end return_message = sum_100(message) JQM.send_job_answer_to_controller(worker, return_message) end exit(0) end end function job_queue(data) JQM.mpi_init() JQM.mpi_barrier() T = eltype(data) N = length(data) if JQM.is_controller_process() # I am root new_data = Array{T}(undef, N) controller = JQM.Controller(JQM.num_workers()) for i in eachindex(data) message = Message(data[i], i) JQM.add_job_to_queue!(controller, message) end while !all_jobs_done(controller) if !JQM.is_job_queue_empty(controller) JQM.send_jobs_to_any_available_workers(controller) end if JQM.any_pending_jobs(controller) job_answer = JQM.check_for_job_answers(controller) if !isnothing(job_answer) message = JQM.get_message(job_answer) update_data(new_data, message) end end end JQM.send_termination_message(controller) return new_data end workers_loop() JQM.mpi_barrier() JQM.mpi_finalize() return nothing end @testset "Sum 100" begin data = collect(1:10) @test job_queue(data) == [101, 102, 103, 104, 105, 106, 107, 108, 109, 110] end
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
code
2687
using JobQueueMPI using Test JQM = JobQueueMPI mutable struct ControllerMessage value::Int vector_idx::Int end mutable struct WorkerMessage divisors::Array{Int} vector_idx::Int end all_jobs_done(controller) = JQM.is_job_queue_empty(controller) && !JQM.any_pending_jobs(controller) function get_divisors(message::ControllerMessage) number = message.value divisors = [] for i in 1:number if number % i == 0 push!(divisors, i) end end return WorkerMessage(divisors, message.vector_idx) end function update_data(new_data, message::WorkerMessage) idx = message.vector_idx value = message.divisors return new_data[idx] = value end function workers_loop() if JQM.is_worker_process() worker = JQM.Worker() while true job = JQM.receive_job(worker) message = JQM.get_message(job) if message == JQM.TerminationMessage() break end return_message = get_divisors(message) JQM.send_job_answer_to_controller(worker, return_message) end exit(0) end end function divisors(data) JQM.mpi_init() JQM.mpi_barrier() N = length(data) if JQM.is_controller_process() # I am root new_data = Array{Array{Int}}(undef, N) controller = JQM.Controller(JQM.num_workers()) for i in eachindex(data) message = ControllerMessage(data[i], i) JQM.add_job_to_queue!(controller, message) end while !all_jobs_done(controller) if !JQM.is_job_queue_empty(controller) JQM.send_jobs_to_any_available_workers(controller) end if JQM.any_pending_jobs(controller) job_answer = JQM.check_for_job_answers(controller) if !isnothing(job_answer) message = JQM.get_message(job_answer) update_data(new_data, message) end end end JQM.send_termination_message(controller) return new_data end workers_loop() JQM.mpi_barrier() JQM.mpi_finalize() return nothing end @testset "Divisors" begin data = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] values = divisors(data) @test values[1] == [1, 2] @test values[2] == [1, 2, 4] @test values[3] == [1, 2, 3, 6] @test values[4] == [1, 2, 4, 8] @test values[5] == [1, 2, 5, 10] @test values[6] == [1, 2, 3, 4, 6, 12] @test values[7] == [1, 2, 7, 14] @test values[8] == [1, 2, 4, 8, 16] @test values[9] == [1, 2, 3, 6, 9, 18] @test values[10] == [1, 2, 4, 5, 10, 20] end
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
code
710
using JobQueueMPI using Test JQM = JobQueueMPI JQM.mpi_init() function sum_100(value) return value + 100 end function get_divisors(n) divisors = Int[] for i in 1:n if n % i == 0 push!(divisors, i) end end return divisors end sum_100_answer = JQM.pmap(sum_100, collect(1:10)) divisors_answer = JQM.pmap(get_divisors, collect(1:10)) if JQM.is_controller_process() @testset "pmap MPI" begin @test sum_100_answer == [101, 102, 103, 104, 105, 106, 107, 108, 109, 110] @test divisors_answer == [[1], [1, 2], [1, 3], [1, 2, 4], [1, 5], [1, 2, 3, 6], [1, 7], [1, 2, 4, 8], [1, 3, 9], [1, 2, 5, 10]] end end JQM.mpi_finalize()
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
code
657
using JobQueueMPI using Test JQM = JobQueueMPI JQM.mpi_init() function sum_100(value) return value + 100 end function get_divisors(n) divisors = Int[] for i in 1:n if n % i == 0 push!(divisors, i) end end return divisors end sum_100_answer = JQM.pmap(sum_100, collect(1:10)) divisors_answer = JQM.pmap(get_divisors, collect(1:10)) @testset "pmap serial" begin @test sum_100_answer == [101, 102, 103, 104, 105, 106, 107, 108, 109, 110] @test divisors_answer == [[1], [1, 2], [1, 3], [1, 2, 4], [1, 5], [1, 2, 3, 6], [1, 7], [1, 2, 4, 8], [1, 3, 9], [1, 2, 5, 10]] end JQM.mpi_finalize()
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
docs
1924
# JobQueueMPI.jl [build-img]: https://github.com/psrenergy/JobQueueMPI.jl/actions/workflows/test.yml/badge.svg?branch=master [build-url]: https://github.com/psrenergy/JobQueueMPI.jl/actions?query=workflow%3ACI [codecov-img]: https://codecov.io/gh/psrenergy/JobQueueMPI.jl/coverage.svg?branch=master [codecov-url]: https://codecov.io/gh/psrenergy/JobQueueMPI.jl?branch=master | **Build Status** | **Coverage** | |:-----------------:|:-----------------:| | [![Build Status][build-img]][build-url] | [![Codecov branch][codecov-img]][codecov-url] |[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://psrenergy.github.io/JobQueueMPI.jl/dev/) JobQueueMPI.jl is a Julia package that provides a simplified interface for running multiple jobs in parallel using [MPI.jl](https://github.com/JuliaParallel/MPI.jl). It uses the Job Queue concept to manage the jobs and the MPI processes. The user can add jobs to the queue and the package will take care of sending them to the available MPI processes. ## Installation You can install JobQueueMPI.jl using the Julia package manager. From the Julia REPL, type `]` to enter the Pkg REPL mode and run: ```julia pkg> add JobQueueMPI ``` ## How it works First, when running a program using MPI, the user has to set the number of processes that will parallelize the computation. One of these processes will be the controller, and the others will be the workers. We can easily delimit the areas of the code that will be executed only by the controller or the worker. JobQueueMPI.jl has the following components: - `Controller`: The controller is responsible for managing the jobs and the workers. It keeps track of the jobs that have been sent and received and sends the jobs to the available workers. - `Worker`: The worker is responsible for executing the jobs. It receives the jobs from the controller, executes them, and sends the results back to the controller.
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MPL-2.0" ]
0.1.0
f719b0bdb256f5ad4c331549b14f581dd961f95d
docs
1250
# JobQueueMPI.jl ## Installation You can install JobQueueMPI.jl using the Julia package manager. From the Julia REPL, type `]` to enter the Pkg REPL mode and run: ```julia pkg> add JobQueueMPI ``` ## How it works First, when running a program using MPI, the user has to set the number of processes that will parallelize the computation. One of these processes will be the controller, and the others will be the workers. We can easily delimit the areas of the code that will be executed only by the controller or the worker. JobQueueMPI.jl has the following components: - `Controller`: The controller is responsible for managing the jobs and the workers. It keeps track of the jobs that have been sent and received and sends the jobs to the available workers. - `Worker`: The worker is responsible for executing the jobs. It receives the jobs from the controller, executes them, and sends the results back to the controller. ## API ```@docs JobQueueMPI.Controller JobQueueMPI.Worker JobQueueMPI.add_job_to_queue! JobQueueMPI.send_jobs_to_any_available_workers JobQueueMPI.send_termination_message JobQueueMPI.check_for_job_answers JobQueueMPI.send_job_answer_to_controller JobQueueMPI.receive_job JobQueueMPI.get_message JobQueueMPI.pmap ```
JobQueueMPI
https://github.com/psrenergy/JobQueueMPI.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
11389
module Export using MAT function mastan(node, element, material, cross_section, support, connection, uniform_load, filepath, filename) #seed model mastan_model = Dict{String, Any}("sect_info" => Matrix{Float64}(undef, 0, 0), "view_settings" => [0.1 0.1 10.0 2.294558781116753 14.0 14.0 1.0 1382.0 765.0], "normincr_settings" => Matrix{Float64}(undef, 0, 0), "sec_inel_settings" => Matrix{Float64}(undef, 0, 0), "settle_info" => [NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN; NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN; NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN; NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN], "bimom_settings" => Matrix{Float64}(undef, 0, 0), "mat_name" => Matrix{Float64}(undef, 0, 0), "first_el_settings" => Matrix{Float64}(undef, 0, 0), "fixity_info" => [NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN; NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN; NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN; NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN], "axial_settings" => Matrix{Float64}(undef, 0, 0), "sheary_settings" => Matrix{Float64}(undef, 0, 0), "momx_settings" => Matrix{Float64}(undef, 0, 0), "elem_info" => Matrix{Float64}(undef, 0, 0), "shearz_settings" => Matrix{Float64}(undef, 0, 0), "ground_motion_data" => Matrix{Float64}(undef, 0, 0), "periods_info" => Matrix{Float64}(undef, 0, 0), "first_inel_settings" => Matrix{Float64}(undef, 0, 0), "node_info" => [0.0 0.0 0.0 113.000244140625 114.000244140625; 10.0 0.0 0.0 115.000244140625 116.000244140625; 10.0 30.0 0.0 117.000244140625 118.000244140625; 10.0 30.0 40.0 119.000244140625 120.000244140625], "deflect_settings" => Matrix{Float64}(undef, 0, 0), "ibuck_settings" => Matrix{Float64}(undef, 0, 0), "analysis_info" => Matrix{Float64}(undef, 0, 0), "nload_info" => [0.0 0.0 0.0 0.0 0.0 0.0 NaN NaN NaN NaN NaN NaN 0.0 NaN; 0.0 0.0 0.0 0.0 0.0 0.0 NaN NaN NaN NaN NaN NaN 0.0 NaN; 0.0 0.0 0.0 0.0 0.0 0.0 NaN NaN NaN NaN NaN NaN 0.0 NaN; 0.0 0.0 0.0 0.0 0.0 0.0 NaN NaN NaN NaN NaN NaN 0.0 NaN], "ebuck_settings" => Matrix{Float64}(undef, 0, 0), "momy_settings" => Matrix{Float64}(undef, 0, 0), "yldsurfval_settings" => Matrix{Float64}(undef, 0, 0), "period_settings" => Matrix{Float64}(undef, 0, 0), "mat_info" => Matrix{Float64}(undef, 0, 0), "uniload_info" => Matrix{Float64}(undef, 0, 0), "model_title" => Matrix{Float64}(undef, 0, 0), "sect_name" => Matrix{Float64}(undef, 0, 0), "first_elastic_dynamic_settings" => Matrix{Float64}(undef, 0, 0), "sec_elastic_dynamic_settings" => Matrix{Float64}(undef, 0, 0), "momz_settings" => Matrix{Float64}(undef, 0, 0), "sec_el_settings" => Matrix{Float64}(undef, 0, 0)) #add material property info mastan_model["mat_info"] = Matrix{Float64}(undef, size(material.E, 1), 4) mastan_model["mat_name"] = Vector{String}(undef, size(material.E, 1)) for i in eachindex(material.E) mastan_model["mat_name"][i] = material.names[i] mastan_model["mat_info"][i, 1] = material.E[i] mastan_model["mat_info"][i, 2] = material.ν[i] mastan_model["mat_info"][i, 3] = Inf mastan_model["mat_info"][i, 4] = material.ρ[i] end #add section properties mastan_model["sect_info"] = zeros(Float64, size(cross_section.A, 1), 20) mastan_model["sect_name"] = Vector{String}(undef, size(cross_section.A, 1)) for i in eachindex(cross_section.A) mastan_model["sect_name"][i] = cross_section.names[i] mastan_model["sect_info"][i, 1] = cross_section.A[i] mastan_model["sect_info"][i, 2] = cross_section.Iz[i] mastan_model["sect_info"][i, 3] = cross_section.Iy[i] mastan_model["sect_info"][i, 4] = cross_section.J[i] mastan_model["sect_info"][i, 6:9] .= Inf mastan_model["sect_info"][i, 10:13] .= 1 end #add nodes num_nodes = length(node.numbers) node_matrix = Matrix{Float64}(undef, size(node.numbers, 1), 5) node_matrix[:, 1] = [node.coordinates[i][1] for i in eachindex(node.coordinates)] node_matrix[:, 2] = [node.coordinates[i][2] for i in eachindex(node.coordinates)] node_matrix[:, 3] = [node.coordinates[i][3] for i in eachindex(node.coordinates)] node_matrix[:, 4] = range(113.000244140625, 113.000244140625+(num_nodes-1)*2, step=2.0) node_matrix[:, 5] = range(114.000244140625, 114.000244140625+(num_nodes-1)*2, step=2.0) mastan_model["node_info"] = node_matrix #add settlement info mastan_model["settle_info"] = fill(NaN, num_nodes, 12) #add nodal load info mastan_model["nload_info"] = zeros(Float64, num_nodes, 14) mastan_model["nload_info"][:,7:12] .= NaN mastan_model["nload_info"][:,14] .= NaN #add elements num_elem = length(element.numbers) elem_matrix = zeros(Float64, size(element.numbers, 1), 29) elem_matrix[:, 1] = [element.nodes[i][1] for i in eachindex(element.nodes)] elem_matrix[:, 2] = [element.nodes[i][2] for i in eachindex(element.nodes)] start_index = maximum(node_matrix[:,5]) + 1 elem_matrix[:, 6] = range(start_index, start_index +(num_elem-1)*9, step=9.0) start_index = maximum(node_matrix[:,5]) + 2 elem_matrix[:, 7] = range(start_index, start_index +(num_elem-1)*9, step=9.0) elem_matrix[:, 9] = ones(Float64, num_elem) start_index = maximum(node_matrix[:,5]) + 3 elem_matrix[:, 11] = range(start_index, start_index +(num_elem-1)*9, step=9.0) start_index = maximum(node_matrix[:,5]) + 6 elem_matrix[:, 14] = range(start_index, start_index +(num_elem-1)*9, step=9.0) start_index = maximum(node_matrix[:,5]) + 8 elem_matrix[:, 15] = range(start_index, start_index +(num_elem-1)*9, step=9.0) start_index = maximum(node_matrix[:,5]) + 7 elem_matrix[:, 18] = range(start_index, start_index +(num_elem-1)*9, step=9.0) start_index = maximum(node_matrix[:,5]) + 9 elem_matrix[:, 19] = range(start_index, start_index +(num_elem-1)*9, step=9.0) elem_matrix[:, 20:27] .= Inf start_index = maximum(node_matrix[:,5]) + 4 elem_matrix[:, 28] = range(start_index, start_index +(num_elem-1)*9, step=9.0) start_index = maximum(node_matrix[:,5]) + 5 elem_matrix[:, 29] = range(start_index, start_index +(num_elem-1)*9, step=9.0) #attach material and section properties for i in eachindex(element.numbers) index = findfirst(name->name==element.cross_section[i], cross_section.names) elem_matrix[i, 3] = index index = findfirst(name->name==element.material[i], material.names) elem_matrix[i, 4] = index end #update end conditions for i in eachindex(element.connections) start_index = findfirst(name->name==element.connections[i][1], connection.names) end_index = findfirst(name->name==element.connections[i][2], connection.names) if (connection.stiffness.ry[start_index] == 0.0) | (connection.stiffness.rz[start_index] == 0.0) elem_matrix[i, 12] = 1 elseif (connection.stiffness.ry[start_index] < Inf) | (connection.stiffness.rz[start_index] < Inf) elem_matrix[i, 12] = 2 end if (connection.stiffness.ry[end_index] == 0.0) | (connection.stiffness.rz[end_index] == 0.0) elem_matrix[i, 13] = 1 elseif (connection.stiffness.ry[end_index] < Inf) | (connection.stiffness.rz[end_index] < Inf) elem_matrix[i, 13] = 2 end elem_matrix[i, 20] = connection.stiffness.rz[start_index] elem_matrix[i, 21] = connection.stiffness.ry[start_index] elem_matrix[i, 22] = connection.stiffness.rz[end_index] elem_matrix[i, 23] = connection.stiffness.ry[end_index] end mastan_model["elem_info"] = elem_matrix #add fixity info mastan_model["fixity_info"] = fill(NaN, num_nodes, 12) Z_index = elem_matrix[end, 19] #this is the maximum of the mystery index for i in eachindex(support.nodes) index = findfirst(num->num==support.nodes[i], node.numbers) if support.stiffness.uX[i] > 0.0 #fix any dof with stiffness Z_index += 1 mastan_model["fixity_info"][index, 1] = 0 mastan_model["fixity_info"][index, 7] = Z_index end if support.stiffness.uY[i] > 0.0 Z_index += 1 mastan_model["fixity_info"][index, 2] = 0 mastan_model["fixity_info"][index, 8] = Z_index end if support.stiffness.uZ[i] > 0.0 Z_index += 1 mastan_model["fixity_info"][index, 3] = 0 mastan_model["fixity_info"][index, 9] = Z_index end if support.stiffness.rX[i] > 0.0 Z_index += 1 mastan_model["fixity_info"][index, 4] = 0 mastan_model["fixity_info"][index, 10] = Z_index end if support.stiffness.rY[i] > 0.0 Z_index += 1 mastan_model["fixity_info"][index, 5] = 0 mastan_model["fixity_info"][index, 11] = Z_index end if support.stiffness.rZ[i] > 0.0 Z_index += 1 mastan_model["fixity_info"][index, 6] = 0 mastan_model["fixity_info"][index, 12] = Z_index end end #add uniform load info uniload_matrix = zeros(Float64, num_elem, 16) uniload_matrix[:, 7:12] .= NaN uniload_matrix[:, 13] .= 6.50000000000000e-06 for i in eachindex(uniform_load.elements) index = uniform_load.elements[i] if abs(uniform_load.magnitudes.qX[i]) > 0.0 uniload_matrix[index, 1] = uniform_load.magnitudes.qX[i] uniload_matrix[index, 7] = Z_index += 1 end if abs(uniform_load.magnitudes.qY[i]) > 0.0 uniload_matrix[index, 2] = uniform_load.magnitudes.qY[i] uniload_matrix[index, 8] = Z_index += 1 end if abs(uniform_load.magnitudes.qZ[i]) > 0.0 uniload_matrix[index, 3] = uniform_load.magnitudes.qZ[i] uniload_matrix[index, 9] = Z_index += 1 end if abs(uniform_load.magnitudes.mX[i]) > 0.0 uniload_matrix[index, 4] = uniform_load.magnitudes.mX[i] uniload_matrix[index, 10] = Z_index += 1 end if abs(uniform_load.magnitudes.mY[i]) > 0.0 uniload_matrix[index, 5] = uniform_load.magnitudes.mY[i] uniload_matrix[index, 11] = Z_index += 1 end if abs(uniform_load.magnitudes.mZ[i]) > 0.0 uniload_matrix[index, 6] = uniform_load.magnitudes.mZ[i] uniload_matrix[index, 12] = Z_index += 1 end end mastan_model["uniload_info"] = uniload_matrix matwrite(joinpath(filepath, filename), mastan_model) end end #module
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
49979
module InstantFrame using LinearAlgebra, Rotations, Parameters, NonlinearSolve, StaticArrays export PlotTools include("PlotTools.jl") using .PlotTools export Show include("Show.jl") using .Show # export Report # include("Report.jl") # using .Report # export Export # include("Export.jl") # using .Export @with_kw mutable struct Material names::Array{String} E::Array{Float64} ν::Array{Float64} ρ::Array{Float64} end @with_kw mutable struct CrossSection names::Array{String} A::Array{Float64} Iy::Array{Float64} Iz::Array{Float64} J::Array{Float64} end @with_kw mutable struct Connection names::Array{String} stiffness::NamedTuple{(:ux, :uy, :uz, :rx, :ry, :rz), NTuple{6, Vector{Float64}}} end @with_kw mutable struct Node numbers::Array{Int64} coordinates::Array{Tuple{Float64, Float64, Float64}, 1} end @with_kw mutable struct Element types::Array{String} numbers::Array{Int64} nodes::Array{Tuple{Int64, Int64}} orientation::Array{Float64} connections::Array{Tuple{String, String}, 1} cross_section::Array{String} material::Array{String} end @with_kw mutable struct Support nodes::Array{Int64} stiffness::NamedTuple{(:uX, :uY, :uZ, :rX, :rY, :rZ), NTuple{6, Vector{Float64}}} end @with_kw mutable struct UniformLoad labels::Union{Array{String}, Nothing} elements::Union{Array{Int64}, Nothing} magnitudes::Union{NamedTuple{(:qX, :qY, :qZ, :mX, :mY, :mZ), NTuple{6, Vector{Float64}}}, Nothing} end UniformLoad(nothing) = UniformLoad(labels=nothing, elements=nothing, magnitudes=nothing) @with_kw mutable struct PointLoad labels::Union{Array{String}, Nothing} nodes::Union{Array{Int64}, Nothing} magnitudes::Union{NamedTuple{(:FX, :FY, :FZ, :MX, :MY, :MZ), NTuple{6, Vector{Float64}}}, Nothing} end PointLoad(nothing) = PointLoad(labels=nothing, nodes=nothing, magnitudes=nothing) @with_kw mutable struct ElementProperties L::Array{Float64} A::Array{Float64} Iz::Array{Float64} Iy::Array{Float64} Io::Array{Float64} J::Array{Float64} E::Array{Float64} ν::Array{Float64} G::Array{Float64} ρ::Array{Float64} rotation_angles::Array{NamedTuple{(:Y, :Z, :X), NTuple{3, Float64}}} Γ::Array{Array{Float64, 2}} local_axis_directions::Array{NamedTuple{(:x, :y, :z), Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}}}} global_dof::Array{Array{Int64, 1}} start_connection::Array{NamedTuple{(:ux, :uy, :uz, :rx, :ry, :rz), NTuple{6, Float64}}} end_connection::Array{NamedTuple{(:ux, :uy, :uz, :rx, :ry, :rz), NTuple{6, Float64}}} end @with_kw struct ElementConnections elements::Array{Int64, 1} displacements::Array{Array{Float64, 1}} end @with_kw struct ElasticSupport global_dof::Array{Int64} global_stiffness::Array{Float64} end @with_kw struct FirstOrderEquations free_dof::Array{Int64} fixed_dof::Array{Int64} elastic_supports::ElasticSupport ke_local::Array{Array{Float64, 2}} ke_global::Array{Array{Float64, 2}} Ke::Array{Float64, 2} end @with_kw struct SecondOrderEquations free_dof::Array{Int64} fixed_dof::Array{Int64} elastic_supports::ElasticSupport ke_local::Array{Array{Float64, 2}} ke_global::Array{Array{Float64, 2}} Ke::Array{Float64, 2} kg_local::Array{Array{Float64, 2}} kg_global::Array{Array{Float64, 2}} Kg::Array{Float64, 2} end @with_kw struct ModalEquations free_dof::Array{Int64} ke_local::Array{Array{Float64, 2}} ke_global::Array{Array{Float64, 2}} Ke::Array{Float64, 2} m_local::Array{Array{Float64, 2}} m_global::Array{Array{Float64, 2}} M::Array{Float64, 2} end @with_kw struct Reactions nodes::Vector{Int64} magnitudes::Vector{Float64} end @with_kw struct Solution displacements::Array{Array{Float64, 1}} forces::Array{Array{Float64, 1}} connections::ElementConnections reactions::Array{Array{Float64, 1}} u::Vector{Float64} uf::Vector{Float64} end # @with_kw struct SecondOrderSolution # nodal_displacements::Array{Array{Float64, 1}} # element_forces::Array{Array{Float64, 1}} # element_connections::ElementConnections # end @with_kw struct ModalSolution ωn::Array{Float64} ϕ::Array{Array{Float64, 1}} end @with_kw struct Forces global_uniform_nodal::Array{Array{Float64}} local_fixed_end_forces::Array{Array{Float64}} global_dof_nodal_forces_uniform_load::Array{Float64} global_dof_point_loads::Array{Float64} F::Array{Float64} end @with_kw struct Inputs node::Node cross_section::CrossSection material::Material connection::Connection element::Element support::Support uniform_load::UniformLoad point_load::PointLoad analysis_type::String solution_tolerance::Union{Float64, Nothing} end Inputs(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type) = Inputs(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type, nothing) @with_kw struct Model inputs::Inputs properties::ElementProperties forces::Union{Forces, Nothing} equations::Union{FirstOrderEquations, SecondOrderEquations, ModalEquations} solution::Union{Solution, ModalSolution} end function define_local_elastic_stiffness_matrix(Iy, Iz, A, J, E, ν, L) G = E/(2*(1+ν)) ke = zeros(Float64, (12, 12)) ke[1, 1] = E*A/L ke[1, 7] = -E*A/L ke[2, 2] = 12*E*Iz/L^3 ke[2, 6] = 6*E*Iz/L^2 ke[2, 8] = -12*E*Iz/L^3 ke[2, 12] = 6*E*Iz/L^2 ke[3, 3] = 12*E*Iy/L^3 ke[3, 5] = -6*E*Iy/L^2 ke[3, 9] = -12*E*Iy/L^3 ke[3, 11] = -6*E*Iy/L^2 ke[4, 4] = G*J/L ke[4, 10] = -G*J/L ke[5, 5] = 4*E*Iy/L ke[5, 9] = 6*E*Iy/L^2 ke[5, 11] = 2*E*Iy/L ke[6, 6] = 4*E*Iz/L ke[6, 8] = -6*E*Iz/L^2 ke[6, 12] = 2*E*Iz/L ke[7, 7] = E*A/L ke[8, 8] = 12*E*Iz/L^3 ke[8, 12] = -6*E*Iz/L^2 ke[9, 9] = 12*E*Iy/L^3 ke[9, 11] = 6*E*Iy/L^2 ke[10, 10] = G*J/L ke[11, 11] = 4*E*Iy/L ke[12, 12] = 4*E*Iz/L for i = 1:12 for j = 1:12 ke[j, i] = ke[i, j] end end return ke end function define_local_geometric_stiffness_matrix(P, L) kg = zeros(Float64, (12, 12)) kg[1, 1] = P/L kg[1, 7] = -P/L kg[2, 2] = 6/5*P/L kg[2, 6] = P/10 kg[2, 8] = -6/5*P/L kg[2, 12] = P/10 kg[3, 3] = 6/5*P/L kg[3, 5] = -P/10 kg[3, 9] = -6/5*P/L kg[3, 11] = -P/10 kg[5, 5] = 2/15*P*L kg[5, 9] = P/10 kg[5, 11] = -P*L/30 kg[6, 6] = 2/15*P*L kg[6, 8] = -P/10 kg[6, 12] = -P*L/30 kg[7, 7] = P/L kg[8, 8] = 6/5*P/L kg[8, 12] = - P/10 kg[9, 9] = 6/5 * P/L kg[9, 11] = P/10 kg[11, 11] = 2/15*P*L kg[12, 12] = 2/15*P*L for i = 1:12 for j = 1:12 kg[j, i] = kg[i, j] end end return kg end # function define_rotation_matrix(A, B, β) # #ρ is x-z plane, χ is x-y plane , ω is y-z plane # AB = B - A # length_AB = norm(AB) # χ = π/2 - acos(AB[2]/length_AB) # if (AB[3]==0.0) & (AB[1]==0.0) #avoid 0/0 case # ρ = 0.0 # else # ρ = -atan(AB[3]/AB[1]) # end # ω = β # γ = RotXZY(-ω, -χ, -ρ) # Γ = zeros(Float64, (12, 12)) # Γ[1:3, 1:3] .= γ # Γ[4:6, 4:6] .= γ # Γ[7:9, 7:9] .= γ # Γ[10:12, 10:12] .= γ # return Γ # end function define_rotation_matrix(A, B, β) AB = B - A ΔX = AB[1] ΔZ = AB[3] ΔY = AB[2] #Rotation global coordinate system about Y axis ρ = atan(-ΔZ, ΔX) #Rotation revised global coordinate system about Z axis proj_AB_xz = sqrt(ΔX^2 + ΔZ^2) χ = atan(ΔY, proj_AB_xz) #Rotation revised global coordinate system about X axis # current_local_y_axis = RotZ(-χ) * RotY(-ρ) * [0.0, 1.0, 0.0] #where Y is pointing after Y and Z rotations # ω = acos(dot(current_local_y_axis, [0.0, 1.0, 0.0])/ norm(current_local_y_axis)) # # matrix of direction cosines # γ = RotX(-(ω+β)) * RotZ(-χ) * RotY(-ρ) # add β here to rotate local y-axis to orient cross-section in global coordinate system ω = β γ = RotYZX(ρ, χ, ω)' #transpose! Γ = zeros(Float64, (12, 12)) Γ[1:3, 1:3] .= γ Γ[4:6, 4:6] .= γ Γ[7:9, 7:9] .= γ Γ[10:12, 10:12] .= γ angles = (Y=ρ, Z=χ, X=ω) return Γ, angles end function define_element_properties(node, cross_section, material, element, connection) num_elem = length(element.numbers) L = Array{Float64}(undef, num_elem) Γ = Array{Array{Float64, 2}}(undef, num_elem) global_dof = Array{Array{Int64, 1}}(undef, num_elem) Iz = Array{Float64}(undef, num_elem) Iy = Array{Float64}(undef, num_elem) A = Array{Float64}(undef, num_elem) Io = Array{Float64}(undef, num_elem) J = Array{Float64}(undef, num_elem) E = Array{Float64}(undef, num_elem) ν = Array{Float64}(undef, num_elem) G = Array{Float64}(undef, num_elem) ρ = Array{Float64}(undef, num_elem) start_connection = Array{NamedTuple{(:ux, :uy, :uz, :rx, :ry, :rz), NTuple{6, Float64}}}(undef, num_elem) end_connection = Array{NamedTuple{(:ux, :uy, :uz, :rx, :ry, :rz), NTuple{6, Float64}}}(undef, num_elem) rotation_angles = Array{NamedTuple{(:Y, :Z, :X), NTuple{3, Float64}}}(undef, num_elem) local_axis_directions = Array{NamedTuple{(:x, :y, :z), Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}}}}(undef, num_elem) for i in eachindex(element.numbers) #nodal coordinates node_i_index = findfirst(node_num->node_num == element.nodes[i][1], node.numbers) node_j_index = findfirst(node_num->node_num == element.nodes[i][2], node.numbers) node_i = collect(node.coordinates[node_i_index]) node_j = collect(node.coordinates[node_j_index]) #cross section index = findfirst(name->name == element.cross_section[i], cross_section.names) Iz[i] = cross_section.Iz[index] Iy[i] = cross_section.Iy[index] A[i] = cross_section.A[index] J[i] = cross_section.J[index] Io[i] = J[i] #I think this is correct? #material index = findfirst(name->name == element.material[i], material.names) E[i] = material.E[index] ν[i] = material.ν[index] ρ[i] = material.ρ[index] G[i] = E[i]/(2*(1+ν[i])) #element end conditions index = findfirst(name->name == element.connections[i][1], connection.names) start_connection[i] = (ux=connection.stiffness.ux[index], uy=connection.stiffness.uy[index], uz=connection.stiffness.uz[index], rx=connection.stiffness.rx[index], ry=connection.stiffness.ry[index], rz=connection.stiffness.rz[index]) index = findfirst(name->name == element.connections[i][2], connection.names) end_connection[i] = (ux=connection.stiffness.ux[index], uy=connection.stiffness.uy[index], uz=connection.stiffness.uz[index], rx=connection.stiffness.rx[index], ry=connection.stiffness.ry[index], rz=connection.stiffness.rz[index]) #element length L[i] = norm(node_j - node_i) #rotation matrix Γ[i], rotation_angles[i] = define_rotation_matrix(node_i, node_j, element.orientation[i]) #element local axis directions local_axis_directions[i] = calculate_element_local_axis_directions(Γ[i]) #global dof for each element num_dof_per_node = 6 #hard code this for now node_i_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (node_i_index-1) node_j_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (node_j_index-1) global_dof[i] = [node_i_dof; node_j_dof] end element_properties = ElementProperties(L, A, Iz, Iy, Io, J, E, ν, G, ρ, rotation_angles, Γ, local_axis_directions, global_dof, start_connection, end_connection) return element_properties end function assemble_global_matrix(k, dof) total_dof = maximum([maximum(dof[i]) for i in eachindex(dof)]) K = zeros(Float64, (total_dof , total_dof)) for i in eachindex(k) K[dof[i], dof[i]] += k[i] end return K end function calculate_element_internal_forces(properties, ke_local, element, uniform_load, local_fixed_end_forces, u) P_element_local = Array{Array{Float64, 1}}(undef, length(properties.L)) for i in eachindex(properties.L) u_element_global = u[properties.global_dof[i]] u_element_local = properties.Γ[i] * u_element_global P_element_local[i] = ke_local[i] * u_element_local elem_num = element.numbers[i] if !isnothing(uniform_load.elements) index = findall(num->num==elem_num, uniform_load.elements) if !isnothing(index) #add in fixed end forces for j in eachindex(index) #if there are multiple load assignments on one member, need a loop P_element_local[i][1] += local_fixed_end_forces[index[j]][1] P_element_local[i][2] += local_fixed_end_forces[index[j]][2] P_element_local[i][3] += local_fixed_end_forces[index[j]][3] P_element_local[i][4] += local_fixed_end_forces[index[j]][4] #deal with internal moment sign switch for partially rigid connections # if properties.start_connection[i].ry != Inf # P_element_local[i][5] -= local_fixed_end_forces[index[j]][5] # else P_element_local[i][5] += local_fixed_end_forces[index[j]][5] # end # if properties.start_connection[i].rz != Inf # P_element_local[i][6] -= local_fixed_end_forces[index[j]][6] # else P_element_local[i][6] += local_fixed_end_forces[index[j]][6] # end P_element_local[i][7] += local_fixed_end_forces[index[j]][7] P_element_local[i][8] += local_fixed_end_forces[index[j]][8] P_element_local[i][9] += local_fixed_end_forces[index[j]][9] P_element_local[i][10] += local_fixed_end_forces[index[j]][10] # if properties.end_connection[i].ry != Inf # P_element_local[i][11] -= local_fixed_end_forces[index[j]][11] # else P_element_local[i][11] += local_fixed_end_forces[index[j]][11] # end # if properties.end_connection[i].rz != Inf # P_element_local[i][12] -= local_fixed_end_forces[index[j]][12] # else P_element_local[i][12] += local_fixed_end_forces[index[j]][12] # end end end end end return P_element_local end function residual(u, p) Kff, Ff = p Kff * u - Ff end function nonlinear_solution(Kff, Ff, u1f) p = [Kff, Ff] u1f = SVector{length(u1f)}(u1f) # u1f_S = zeros(Float64, length(u1f)) # u1fSS = [u1f_S[i] for i in eachindex(u1f)] probN = NonlinearSolve.NonlinearProblem{false}(residual, u1f, p) u2f = NonlinearSolve.solve(probN, NewtonRaphson(), tol = 1e-9) return u2f end function define_nodal_displacements(node, u) nodal_displacements = Array{Array{Float64, 1}}(undef, length(node.numbers)) # nodal_displacements = Vector{Vector{Float64, 1}}(undef, length(node.numbers)) num_dof_per_node = 6 #hard code this for now for i in eachindex(node.numbers) nodal_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (i-1) nodal_displacements[i] = u[nodal_dof] end return nodal_displacements end function first_order_analysis(node, cross_section, material, connection, element, support, uniform_load, point_load) element_properties = InstantFrame.define_element_properties(node, cross_section, material, element, connection) ke_local = [InstantFrame.define_local_elastic_stiffness_matrix(element_properties.Iy[i], element_properties.Iz[i], element_properties.A[i], element_properties.J[i], element_properties.E[i], element_properties.ν[i], element_properties.L[i]) for i in eachindex(element_properties.L)] ke_local = InstantFrame.modify_element_local_connection_stiffness(element_properties, ke_local, element) ke_global = [element_properties.Γ[i]'*ke_local[i]*element_properties.Γ[i] for i in eachindex(element_properties.L)] Ke = InstantFrame.assemble_global_matrix(ke_global, element_properties.global_dof) free_global_dof, fixed_global_dof, elastic_supports = InstantFrame.define_free_global_dof(node, support) for i in eachindex(elastic_supports.global_dof) #add springs Ke[elastic_supports.global_dof[i], elastic_supports.global_dof[i]] += elastic_supports.global_stiffness[i] end equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load = InstantFrame.calculate_nodal_forces_from_uniform_loads(uniform_load, element, node, element_properties) global_dof_point_loads = InstantFrame.define_global_dof_point_loads(node, point_load) F = global_dof_point_loads .+ global_dof_nodal_forces_uniform_load forces = InstantFrame.Forces(equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load, global_dof_point_loads, F) #calculate nodal displacements Ff = F[free_global_dof] Ke_ff = Ke[free_global_dof, free_global_dof] uf = Ke_ff \ Ff u = zeros(Float64, size(Ke,1)) u[free_global_dof] = uf nodal_displacements = define_nodal_displacements(node, u) #### calculate reaction #### reactions = zeros(Float64, length(node.numbers)*6) #get reactions from rigid supports Ke_sf = Ke[fixed_global_dof, free_global_dof] R = Ke_sf * uf reactions[fixed_global_dof] = R #get reactions from elastic supports elastic_support_reactions = -u[elastic_supports.global_dof] .* elastic_supports.global_stiffness reactions[elastic_supports.global_dof] = elastic_support_reactions #add point loads to rigid support reactions reactions[fixed_global_dof] += -forces.global_dof_point_loads[fixed_global_dof] #add uniform load equivalent nodal forces to rigid support reactions reactions[fixed_global_dof] += -forces.global_dof_nodal_forces_uniform_load[fixed_global_dof] # print(fixed_global_dof) # reactions[fixed_global_dof] -= -forces.global_dof_nodal_forces_uniform_load[fixed_global_dof] # reactions[fixed_global_dof] = reactions[fixed_global_dof] - #package up reactions at each node, these are reactions from elastic supports and rigid supports nodal_reactions = Array{Array{Float64, 1}}(undef, length(support.nodes)) num_dof_per_node = 6 #hard code this for now for i in eachindex(support.nodes) nodal_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (support.nodes[i]-1) nodal_reactions[i] = reactions[nodal_dof] end ###### #calculate element internal forces element_forces = InstantFrame.calculate_element_internal_forces(element_properties, ke_local, element, uniform_load, local_fixed_end_forces, u) #calculate connection deformations element_connections = calculate_element_connection_deformations(element_properties, element, node, nodal_displacements, element_forces) equations = FirstOrderEquations(free_global_dof, fixed_global_dof, elastic_supports, ke_local, ke_global, Ke) solution = Solution(nodal_displacements, element_forces, element_connections, nodal_reactions, u, uf) inputs = Inputs(node, cross_section, material, connection, element, support, uniform_load, point_load, "1st order") model = Model(inputs, element_properties, forces, equations, solution) return model end function second_order_analysis(node, cross_section, material, connection, element, support, uniform_load, point_load, solution_tolerance) element_properties = InstantFrame.define_element_properties(node, cross_section, material, element, connection) ke_local = [InstantFrame.define_local_elastic_stiffness_matrix(element_properties.Iy[i], element_properties.Iz[i], element_properties.A[i], element_properties.J[i], element_properties.E[i], element_properties.ν[i], element_properties.L[i]) for i in eachindex(element_properties.L)] ke_local = InstantFrame.modify_element_local_connection_stiffness(element_properties, ke_local, element) ke_global = [element_properties.Γ[i]'*ke_local[i]*element_properties.Γ[i] for i in eachindex(element_properties.L)] Ke = InstantFrame.assemble_global_matrix(ke_global, element_properties.global_dof) free_global_dof, fixed_global_dof, elastic_supports = InstantFrame.define_free_global_dof(node, support) for i in eachindex(elastic_supports.global_dof) #add springs Ke[elastic_supports.global_dof[i], elastic_supports.global_dof[i]] += elastic_supports.global_stiffness[i] end equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load = InstantFrame.calculate_nodal_forces_from_uniform_loads(uniform_load, element, node, element_properties) global_dof_point_loads = InstantFrame.define_global_dof_point_loads(node, point_load) F = global_dof_point_loads .+ global_dof_nodal_forces_uniform_load forces = InstantFrame.Forces(equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load, global_dof_point_loads, F) Ff = F[free_global_dof] Ke_ff = Ke[free_global_dof, free_global_dof] u1f = Ke_ff \ Ff u1 = zeros(Float64, size(Ke,1)) u1[free_global_dof] = u1f # P1 = InstantFrame.calculate_element_internal_forces(element_properties, ke_local, u1) #calculate element internal forces P1 = InstantFrame.calculate_element_internal_forces(element_properties, ke_local, element, uniform_load, local_fixed_end_forces, u1) P1_axial = [P1[i][7] for i in eachindex(P1)] kg_local = [InstantFrame.define_local_geometric_stiffness_matrix(P1_axial[i], element_properties.L[i]) for i in eachindex(element_properties.L)] kg_global = [element_properties.Γ[i]'*kg_local[i]*element_properties.Γ[i] for i in eachindex(element_properties.L)] Kg = InstantFrame.assemble_global_matrix(kg_global, element_properties.global_dof) Kg_ff = Kg[free_global_dof, free_global_dof] Kff = Ke_ff + Kg_ff p = [Kff, Ff] u1f = SVector{length(u1f)}(u1f) probN = NonlinearSolve.NonlinearProblem{false}(residual, u1f, p) u2f = NonlinearSolve.solve(probN, NewtonRaphson(), reltol = solution_tolerance) u2 = zeros(Float64, size(Ke,1)) u2[free_global_dof] = u2f nodal_displacements = define_nodal_displacements(node, u2) #### calculate reaction #### reactions = zeros(Float64, length(node.numbers)*6) #get reactions from rigid supports Ke_sf = Ke[fixed_global_dof, free_global_dof] R = Ke_sf * u2f reactions[fixed_global_dof] = R #get reactions from elastic supports elastic_support_reactions = -u2[elastic_supports.global_dof] .* elastic_supports.global_stiffness reactions[elastic_supports.global_dof] = elastic_support_reactions #add point loads to rigid support reactions reactions[fixed_global_dof] += -forces.global_dof_point_loads[fixed_global_dof] #add uniform load equivalent nodal forces to rigid support reactions reactions[fixed_global_dof] += -forces.global_dof_nodal_forces_uniform_load[fixed_global_dof] #package up reactions at each node, these are reactions from elastic supports and rigid supports nodal_reactions = Array{Array{Float64, 1}}(undef, length(support.nodes)) num_dof_per_node = 6 #hard code this for now for i in eachindex(support.nodes) nodal_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (support.nodes[i]-1) nodal_reactions[i] = reactions[nodal_dof] end ###### #calculate element internal forces element_forces = InstantFrame.calculate_element_internal_forces(element_properties, ke_local, element, uniform_load, local_fixed_end_forces, u2) #calculate connection deformations element_connections = calculate_element_connection_deformations(element_properties, element, node, nodal_displacements, element_forces) equations = SecondOrderEquations(free_global_dof, fixed_global_dof, elastic_supports, ke_local, ke_global, Ke, kg_local, kg_global, Kg) solution = Solution(nodal_displacements, element_forces, element_connections, nodal_reactions, u2, u2f) inputs = Inputs(node, cross_section, material, connection, element, support, uniform_load, point_load, "2st order") model = Model(inputs, element_properties, forces, equations, solution) return model end function modal_vibration_analysis(node, cross_section, material, connection, element, support) element_properties = InstantFrame.define_element_properties(node, cross_section, material, element, connection) # free_global_dof = InstantFrame.define_free_global_dof(node, support) free_global_dof, fixed_global_dof, elastic_supports = InstantFrame.define_free_global_dof(node, support) ke_local = [InstantFrame.define_local_elastic_stiffness_matrix(element_properties.Iy[i], element_properties.Iz[i], element_properties.A[i], element_properties.J[i], element_properties.E[i], element_properties.ν[i], element_properties.L[i]) for i in eachindex(element_properties.L)] ke_local = InstantFrame.modify_element_local_connection_stiffness(element_properties, ke_local, element) ke_global = [element_properties.Γ[i]'*ke_local[i]*element_properties.Γ[i] for i in eachindex(element_properties.L)] Ke = InstantFrame.assemble_global_matrix(ke_global, element_properties.global_dof) m_local = [InstantFrame.define_local_3D_mass_matrix(element_properties.A[i], element_properties.L[i], element_properties.Io[i], element_properties.ρ[i]) for i in eachindex(element_properties.L)] m_global = [element_properties.Γ[i]'*m_local[i]*element_properties.Γ[i] for i in eachindex(element_properties.L)] M = InstantFrame.assemble_global_matrix(m_global, element_properties.global_dof) Ke_ff = Ke[free_global_dof, free_global_dof] Mff = M[free_global_dof, free_global_dof] ωn_squared = real.(eigvals(Ke_ff, Mff)) ωn = sqrt.(ωn_squared) ϕff = eigvecs(Ke_ff, Mff) ϕ = [zeros(Float64, size(M, 1)) for i in eachindex(ωn)] for i in eachindex(ωn) ϕ[i][free_global_dof] .= real.(ϕff[:, i]) end equations = ModalEquations(free_global_dof, ke_local, ke_global, Ke, m_local, m_global, M) solution = ModalSolution(ωn, ϕ) model = Model(element_properties, nothing, equations, solution) return model end function solve(node, cross_section, material, connection, element, support, uniform_load, point_load; analysis_type, solution_tolerance) if analysis_type == "first order" model = first_order_analysis(node, cross_section, material, connection, element, support, uniform_load, point_load) elseif analysis_type == "modal vibration" model = modal_vibration_analysis(node, cross_section, material, connection, element, support) elseif analysis_type == "second order" model = second_order_analysis(node, cross_section, material, connection, element, support, uniform_load, point_load, solution_tolerance) end return model end # function solve(node, cross_section, material, connection, element, support, uniform_load, point_load; analysis_type, solution_tolerance) # if analysis_type == "second order" # model = second_order_analysis(node, cross_section, material, connection, element, support, uniform_load, point_load, solution_tolerance) # end # return model # end function calculate_local_element_fixed_end_forces_partial_restraint(wx_local, wy_local, wz_local, L, k1z, k2z, k1y, k2y, E, Iy, Iz) local_fixed_end_forces = calculate_local_element_fixed_end_forces(wx_local, wy_local, wz_local, L) k1z, k2z = InstantFrame.connection_zeros_and_inf(k1z, k2z, E, Iz) M_fixed = [local_fixed_end_forces[6], local_fixed_end_forces[12]] F_fixed = [local_fixed_end_forces[2], local_fixed_end_forces[8]] M_spring, F_spring = fixed_end_forces_partial_restraint(k1z, k2z, E, Iz, L, M_fixed, F_fixed) local_fixed_end_forces[6] = M_spring[1] local_fixed_end_forces[12] = -M_spring[2] local_fixed_end_forces[2] = F_spring[2] #tricky here local_fixed_end_forces[8] = F_spring[1] #tricky here k1y, k2y = InstantFrame.connection_zeros_and_inf(k1y, k2y, E, Iy) M_fixed = [local_fixed_end_forces[5], local_fixed_end_forces[11]] F_fixed = [local_fixed_end_forces[3], local_fixed_end_forces[9]] M_spring, F_spring = fixed_end_forces_partial_restraint(k1y, k2y, E, Iy, L, M_fixed, F_fixed) local_fixed_end_forces[3] = F_spring[1] local_fixed_end_forces[5] = -M_spring[1] local_fixed_end_forces[9] = F_spring[2] local_fixed_end_forces[11] = M_spring[2] return local_fixed_end_forces end function calculate_local_element_fixed_end_forces_partial_restraint_xy(local_fixed_end_forces, L, k1z, k2z, E, Iz) k1z, k2z = InstantFrame.connection_zeros_and_inf(k1z, k2z, E, Iz) M_fixed = [local_fixed_end_forces[6], local_fixed_end_forces[12]] F_fixed = [local_fixed_end_forces[2], local_fixed_end_forces[8]] M_spring, F_spring = fixed_end_forces_partial_restraint(k1z, k2z, E, Iz, L, M_fixed, F_fixed) local_fixed_end_forces[6] = M_spring[1] local_fixed_end_forces[12] = -M_spring[2] local_fixed_end_forces[2] = F_spring[2] #tricky here local_fixed_end_forces[8] = F_spring[1] #tricky here return local_fixed_end_forces end function calculate_local_element_fixed_end_forces_partial_restraint_xz(local_fixed_end_forces, L, k1y, k2y, E, Iy) k1y, k2y = InstantFrame.connection_zeros_and_inf(k1y, k2y, E, Iy) M_fixed = [local_fixed_end_forces[5], local_fixed_end_forces[11]] F_fixed = [local_fixed_end_forces[3], local_fixed_end_forces[9]] M_spring, F_spring = fixed_end_forces_partial_restraint(k1y, k2y, E, Iy, L, M_fixed, F_fixed) local_fixed_end_forces[3] = F_spring[1] local_fixed_end_forces[5] = -M_spring[1] local_fixed_end_forces[9] = F_spring[2] local_fixed_end_forces[11] = M_spring[2] return local_fixed_end_forces end function calculate_local_element_fixed_end_forces(wx_local, wy_local, wz_local, L) local_fixed_end_forces = zeros(Float64, 12) local_fixed_end_forces[1] = -wx_local*L/2 local_fixed_end_forces[7] = -wx_local*L/2 local_fixed_end_forces[2] = -wy_local*L/2 local_fixed_end_forces[6] = -wy_local*L^2/12 local_fixed_end_forces[8] = -wy_local*L/2 local_fixed_end_forces[12] = +wy_local*L^2/12 local_fixed_end_forces[3] = -wz_local*L/2 local_fixed_end_forces[5] = +wz_local*L^2/12 local_fixed_end_forces[9] = -wz_local*L/2 local_fixed_end_forces[11] = -wz_local*L^2/12 return local_fixed_end_forces end function fixed_end_forces_partial_restraint(k1, k2, E, I, L, M_fixed, F_fixed) α1 = k1/(E*I/L) α2 = k2/(E*I/L) #MGZ Example 13.7 k_moment = E*I/L*([4+α1 2.0 2.0 4+α2]) θi = k_moment^-1*M_fixed # M_spring = θi .* [k1, k2] M_spring = abs.(θi) .* [k1, k2] k_shear = (E*I/L)*[6/L 6/L -6/L -6/L] # F_spring = F_fixed - k_shear * θi F_spring = F_fixed + k_shear * θi return M_spring, F_spring end function calculate_nodal_forces_from_uniform_loads(uniform_load, element, node, element_properties) nodal_forces_uniform_load = zeros(Float64, length(node.numbers) * 6) #hard coded for now if !isnothing(uniform_load.elements) element_global_nodal_forces_uniform_load = Array{Array{Float64}}(undef, length(uniform_load.elements)) local_fixed_end_forces = Array{Array{Float64}}(undef, length(uniform_load.elements)) for i in eachindex(uniform_load.elements) elem_num = uniform_load.elements[i] elem_index = findfirst(num->num==elem_num, element.numbers) global_element_uniform_loads = [uniform_load.magnitudes.qX[i], uniform_load.magnitudes.qY[i], uniform_load.magnitudes.qZ[i], uniform_load.magnitudes.mX[i], uniform_load.magnitudes.mY[i], uniform_load.magnitudes.mZ[i]] local_element_uniform_loads = element_properties.Γ[elem_index][1:6, 1:6] * global_element_uniform_loads wx_local = local_element_uniform_loads[1] wy_local = local_element_uniform_loads[2] wz_local = local_element_uniform_loads[3] k1z = element_properties.start_connection[elem_index].rz k2z = element_properties.end_connection[elem_index].rz k1y = element_properties.start_connection[elem_index].ry k2y = element_properties.end_connection[elem_index].ry local_fixed_end_forces[i] = calculate_local_element_fixed_end_forces(wx_local, wy_local, wz_local, element_properties.L[elem_index]) #now modify fixed end forces if there are partial end restraints # partial_restraint_index = findall(x->x!=Inf, [k1z, k2z]) if (k1z < Inf) | (k2z < Inf) local_fixed_end_forces[i] = calculate_local_element_fixed_end_forces_partial_restraint_xy(local_fixed_end_forces[i], element_properties.L[elem_index], k1z, k2z, element_properties.E[elem_index], element_properties.Iz[elem_index]) end # partial_restraint_index = findall(x->x!=Inf, [k1y, k2y]) if (k1y < Inf) | (k2y < Inf) local_fixed_end_forces[i] = calculate_local_element_fixed_end_forces_partial_restraint_xz(local_fixed_end_forces[i], element_properties.L[elem_index], k1y, k2y, element_properties.E[elem_index], element_properties.Iy[elem_index]) end global_fixed_end_forces = element_properties.Γ[elem_index]' * local_fixed_end_forces[i] element_global_nodal_forces_uniform_load[i] = -global_fixed_end_forces nodal_forces_uniform_load[element_properties.global_dof[elem_index]] += element_global_nodal_forces_uniform_load[i] end else element_global_nodal_forces_uniform_load = Array{Array{Float64}}(undef, 0) local_fixed_end_forces = Array{Array{Float64}}(undef, 0) end return element_global_nodal_forces_uniform_load, local_fixed_end_forces, nodal_forces_uniform_load end function define_local_elastic_element_torsional_stiffness_matrix_partially_restrained(J, G, L, k1, k2) k1, k2 = connection_zeros_and_inf(k1, k2, G, J) α1 = k1/(G*J/L) α2 = k2/(G*J/L) α = 1 + 1/α1 + 1/α2 kt = G*J/L * [1/α -1/α -1/α 1/α] return kt end function define_local_elastic_element_axial_stiffness_matrix_partially_restrained(A, E, L, k1, k2) k1, k2 = connection_zeros_and_inf(k1, k2, E, A) α1 = k1/(A*E/L) α2 = k2/(A*E/L) α = 1 + 1/α1 + 1/α2 ka = A*E/L * [1/α -1/α -1/α 1/α] return ka end function modify_element_local_connection_stiffness(element_properties, ke_local, element) for i in eachindex(ke_local) start_index = findall(u->u!=Inf, element_properties.start_connection[i]) end_index = findall(u->u!=Inf, element_properties.end_connection[i]) if (!isempty(start_index)) | (!isempty(end_index)) index = findfirst(elem_num->elem_num==element.numbers[i], element.numbers) ke_local_xy = InstantFrame.define_local_elastic_element_stiffness_matrix_partially_restrained(element_properties.Iz[index], element_properties.E[index], element_properties.L[index], element_properties.start_connection[index][6], element_properties.end_connection[index][6]) ke_local_xz = InstantFrame.define_local_elastic_element_stiffness_matrix_partially_restrained(element_properties.Iy[index], element_properties.E[index], element_properties.L[index], element_properties.start_connection[index][5], element_properties.end_connection[index][5]) #signs are opposite in xz plane for these terms ke_local_xz[1, 2] = -ke_local_xz[1, 2] ke_local_xz[1, 4] = -ke_local_xz[1, 4] ke_local_xz[2, 1] = -ke_local_xz[2, 1] ke_local_xz[2, 3] = -ke_local_xz[2, 3] ke_local_xz[3, 2] = -ke_local_xz[3, 2] ke_local_xz[3, 4] = -ke_local_xz[3, 4] ke_local_xz[4, 1] = -ke_local_xz[4, 1] ke_local_xz[4, 3] = -ke_local_xz[4, 3] ke_local_torsion = define_local_elastic_element_torsional_stiffness_matrix_partially_restrained(element_properties.J[index], element_properties.G[index], element_properties.L[index], element_properties.start_connection[index][4], element_properties.end_connection[index][4]) ke_local_axial = define_local_elastic_element_axial_stiffness_matrix_partially_restrained(element_properties.A[index], element_properties.E[index], element_properties.L[index], element_properties.start_connection[index][1], element_properties.end_connection[index][1]) #flexural dof dof = [2, 6, 8, 12] for i in eachindex(dof) for j in eachindex(dof) ke_local[index][dof[i], dof[j]] = ke_local_xy[i,j] end end dof = [3, 5, 9, 11] for i in eachindex(dof) for j in eachindex(dof) ke_local[index][dof[i], dof[j]] = ke_local_xz[i,j] end end # ke_local[index][dof, dof] .= ke_local_xz #torsion dof dof = [4, 10] for i in eachindex(dof) for j in eachindex(dof) ke_local[index][dof[i], dof[j]] = ke_local_torsion[i,j] end end dof = [1, 7] for i in eachindex(dof) for j in eachindex(dof) ke_local[index][dof[i], dof[j]] = ke_local_axial[i,j] end end # ke_local[index][dof, dof] .= ke_local_torsion end end return ke_local end function connection_zeros_and_inf(k1, k2, E, I) if k1 == Inf #need big number instead of Inf because 0.0*Inf = NaN k1 = E*I*10.0^20 elseif k1 == 0.0 k1 = E*I*10.0^-30 end if k2 == Inf #need big number instead of Inf k2 = E*I*10.0^20 elseif k2 == 0.0 k2 = E*I*10.0^-30 end return k1, k2 end function define_local_elastic_element_stiffness_matrix_partially_restrained(I, E, L, k1, k2) #from McGuire et al. (2000) Example 13.6 k1, k2 = connection_zeros_and_inf(k1, k2, E, I) α1 = k1/(E*I/L) #start node α2 = k2/(E*I/L) #end node α = (α1*α2)/(α1*α2 + 4*α1 + 4*α2 + 12) ke = zeros(Float64, 4, 4) ke[1,1] = 12/L^2*(1 + (α1+α2)/(α1*α2)) ke[1,2] = 6/L * (1+2/α2) ke[1,3] = -12/L^2*(1+(α1+α2)/(α1*α2)) ke[1,4] = 6/L*(1+2/α1) ke[2,2] = 4*(1+3/α2) ke[2,3] = -6/L*(1+2/α2) ke[2,4] = 2 ke[3,3] = 12/L^2*(1+(α1+α2)/(α1*α2)) ke[3,4] = -6/L*(1+2/α1) ke[4,4] = 4*(1+3/α1) for i = 1:4 for j = 1:4 ke[j, i] = ke[i, j] end end ke = α * (E * I / L) .* ke return ke end function define_local_3D_mass_matrix(A, L, Io, ρ) #https://pdfs.semanticscholar.org/2361/90b717f2b950078e8c1ddc7da16080d601eb.pdf m = zeros(Float64, (12, 12)) m[1, 1] = 140 m[1, 7] = 70 m[2, 2] = 156 m[2, 6] = 22L m[2, 8] = 54 m[2, 12] = -13L m[3, 3] = 156 m[3, 5] = -22L m[3, 9] = 54 m[3, 11] = 13L m[4, 4] = 140Io/A m[4, 10] = 70Io/A m[5, 5] = 4L^2 m[5, 9] = -13L m[5, 11] = -3L^2 m[6, 6] = 4L^2 m[6, 8] = 13L m[6, 12] = -3L^2 m[7, 7] = 140 m[8, 8] = 156 m[8, 12] = -22L m[9, 9] = 156 m[9, 11] = 22L m[10, 10] = 140Io/A m[11, 11] = 4L^2 m[12, 12] = 4L^2 for i = 1:12 for j = 1:12 m[j, i] = m[i, j] end end m = m .* (ρ*A*L)/420 return m end function define_free_global_dof(node, support) num_dof_per_node = 6 dof_support_stiffness = zeros(Float64, length(node.numbers)*num_dof_per_node) nodal_support_stiffness = reduce(hcat, collect(support.stiffness)) for i in eachindex(support.nodes) node_index = findfirst(node_num->node_num == support.nodes[i], node.numbers) node_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (node_index-1) dof_support_stiffness[node_dof] = nodal_support_stiffness[i, :] end free_global_dof = vec(findall(dof->dof!=Inf, dof_support_stiffness)) fixed_global_dof = vec(findall(dof->dof==Inf, dof_support_stiffness)) elastic_support_dof = vec(findall(dof->(dof!=Inf)&(dof!=0.0), dof_support_stiffness)) elastic_support_dof = vec(findall(dof->(dof!=Inf)&(dof!=0.0), dof_support_stiffness)) elastic_support_stiffness = dof_support_stiffness[elastic_support_dof] elastic_support = ElasticSupport(global_dof=elastic_support_dof, global_stiffness = elastic_support_stiffness) return free_global_dof, fixed_global_dof, elastic_support end function define_global_dof_point_loads(node, point_load) num_dof_per_node = 6 global_dof_point_loads = zeros(Float64, length(node.numbers)*num_dof_per_node) if !isnothing(point_load.nodes) nodal_point_loads = reduce(hcat, collect(point_load.magnitudes)) for i in eachindex(point_load.nodes) node_index = findfirst(node_num->node_num == point_load.nodes[i], node.numbers) node_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (node_index-1) global_dof_point_loads[node_dof] = nodal_point_loads[i, :] end end return global_dof_point_loads end function calculate_element_local_axis_directions(Γ) unit_vector_X = [1.0, 0.0, 0.0] local_x = Γ[1:3,1:3]' * unit_vector_X unit_vector_Y = [0.0, 1.0, 0.0] local_y = Γ[1:3,1:3]' * unit_vector_Y unit_vector_Z = [0.0, 0.0, 1.0] local_z = Γ[1:3,1:3]' * unit_vector_Z element_local_axes = (x=local_x, y=local_y, z=local_z) return element_local_axes end function calculate_element_connection_deformations(properties, element, node, nodal_displacements, element_forces) u_element_connection = Array{Array{Float64, 1}}(undef, 0) elements_with_connections = Array{Int64}(undef, 0) #go through each element with a connection for i in eachindex(properties.L) start_index = findall(u->u!=Inf, properties.start_connection[i]) end_index = findall(u->u!=Inf, properties.end_connection[i]) if (!isempty(start_index)) | (!isempty(end_index)) u_connection_local = zeros(Float64, 12) index = findfirst(elem_num->elem_num==element.numbers[i], element.numbers) push!(elements_with_connections, element.numbers[i]) E = properties.E[index] A = properties.A[index] I = properties.Iz[index] L = properties.L[index] G = properties.G[index] J = properties.J[index] node_i_num = element.nodes[index][1] node_j_num = element.nodes[index][2] node_i_index = findfirst(num->num==node_i_num, node.numbers) node_j_index = findfirst(num->num==node_j_num, node.numbers) u_global_element = [nodal_displacements[node_i_index]; nodal_displacements[node_j_index]] u_local_element = properties.Γ[index] * u_global_element #x-y plane k1 = properties.start_connection[index][6] k2 = properties.end_connection[index][6] k1, k2 = connection_zeros_and_inf(k1, k2, E, I) v1 = u_local_element[2] θ1 = u_local_element[6] v2 = u_local_element[8] θ2 = u_local_element[12] Mi = element_forces[index][6] Mj = element_forces[index][12] θij = calculate_connection_rotation(k1, k2, E, I, L, v1, θ1, v2, θ2, Mi, Mj) u_connection_local[6] = θij[1] u_connection_local[12] = θij[2] #x-z plane k1 = properties.start_connection[index][5] k2 = properties.end_connection[index][5] k1, k2 = connection_zeros_and_inf(k1, k2, E, I) v1 = u_local_element[3] θ1 = u_local_element[5] v2 = u_local_element[9] θ2 = u_local_element[11] Mi = element_forces[index][5] Mj = element_forces[index][11] θij = calculate_connection_rotation(k1, k2, E, I, L, v1, θ1, v2, θ2, Mi, Mj) u_connection_local[5] = θij[1] u_connection_local[11] = θij[2] #torsion k1 = properties.start_connection[index][4] k2 = properties.end_connection[index][4] k1, k2 = connection_zeros_and_inf(k1, k2, G, J) θx1 = u_local_element[4] θx2 = u_local_element[10] Ti = element_forces[index][4] Tj = element_forces[index][10] θij = calculate_connection_rotation_torsion(k1, k2, G, J, L, θx1, θx2, Ti, Tj) u_connection_local[4] = θij[1] u_connection_local[10] = θij[2] #axial k1 = properties.start_connection[index][1] k2 = properties.end_connection[index][1] k1, k2 = connection_zeros_and_inf(k1, k2, E, A) Δx1 = u_local_element[1] Δx2 = u_local_element[7] Pi = element_forces[index][1] Pj = element_forces[index][7] Δij = calculate_connection_deformation_axial(k1, k2, E, A, L, Δx1, Δx2, Pi, Pj) u_connection_local[1] = Δij[1] u_connection_local[7] = Δij[2] u_connection_global = properties.Γ[index]' * u_connection_local #convert from local to global push!(u_element_connection, u_connection_global) end end element_connections = ElementConnections(elements_with_connections, u_element_connection) return element_connections end function calculate_connection_rotation(k1, k2, E, I, L, v1, θ1, v2, θ2, Mi, Mj) #Use MZG Example 13.7 equations to solve for rotation at a partially rigid or hinged connection. α1 = k1/(E*I/L) α2 = k2/(E*I/L) kB = (E*I/L)*[4+α1 2 2 4+α2] kC = (E*I/L)*[6/L -α1 -6/L 0 6/L 0 -6/L -α2] u = [v1, θ1, v2, θ2] M = [Mi, Mj] θ = kB^-1*(M - kC*u) return θ end function calculate_connection_rotation_torsion(k1, k2, G, J, L, θ1, θ2, Ti, Tj) α1 = k1/(G*J/L) α2 = k2/(G*J/L) kB = (G*J/L)*[(1-α1)/2 -1/2 -1/2 (1-α2)/2] kC = (G*J/L)*[α1/2 0 0 α2/2] u = [θ1, θ2] T = [Ti, Tj] θ = kB^-1*(T - kC*u) return θ end function calculate_connection_deformation_axial(k1, k2, E, A, L, Δ1, Δ2, Pi, Pj) α1 = k1/(E*A/L) α2 = k2/(E*A/L) kB = (E*A/L)*[(1-α1)/2 -1/2 -1/2 (1-α2)/2] kC = (E*A/L)*[α1/2 0 0 α2/2] u = [Δ1, Δ2] P = [Pi, Pj] Δ = kB^-1*(P - kC*u) return Δ end end # module # ke = zeros(Float64, 6, 6) # c = [2;3;5;6] # ke[c, c] = ke_condensed # ke[1, 1] = E*A/L # ke[1, 4] = -E*A/L # ke[4, 1] = -E*A/L # ke[4, 4] = E*A/L # return ke # end # # α = (α1 * α2) / (α1*α2 + 4*α1 + 4*α2 + 12) # # ke = zeros(Float64, 6, 6) # # ke[1, 1] = E*A/L # # ke[1, 4] = E*A/L # # ke[2, 2] = α*E*I/L * 12/L^2 * (1 + (α1 + α2)/(α1*α2)) # # ke[2, 3] = α*E*I/L * 6/L * (1 + 2/α2) # # ke[2, 5] = α*E*I/L * -12/L^2 * (1 + (α1 + α2)/(α1*α2)) # # ke[2, 6] = α*E*I/L * 6/L * (1 + 2/α1) # # ke[3, 3] = α*E*I/L * 4 * (1 + 3/α2) # # ke[3, 5] = α*E*I/L * -6/L * (1 + 2/α2) # # ke[3, 6] = α*E*I/L * 2 # # ke[5, 5] = α*E*I/L * 12/L^2 * (1 + (α1 + α2)/(α1*α2)) # # ke[5, 6] = α*E*I/L * -6/L * (1 + 2/α1) # # ke[6, 6] = α*E*I/L * 4 * (1 + 3/α1) # # for i = 1:6 # # for j = 1:6 # # ke[j, i] = ke[i, j] # # end # # end # # return ke # # end # function define_local_3D_mass_matrix(A, L, ρ) # m = zeros(Float64, (12, 12)) # m[1, 1] = 140 # m[1, 7] = 70 # m[2, 2] = 156 # m[2, 6] = 22L # m[2, 8] = 54 # m[2, 12] = -13L # m[3, 3] = 156 # m[3, 5] = -22L # m[3, 9] = 54 # m[3, 11] = 13L # m[4, 4] = 140Io/A # m[4, 10] = 70Io/A # m[5, 5] = 4L^2 # m[5, 9] = -13L # m[5, 11] = -3L^2 # m[6, 6] = 4L^2 # m[6, 8] = 13L # m[6, 12] = -3L^2 # m[7, 7] = 140 # m[8, 8] = 156 # m[8, 12] = -22L # m[9, 9] = 156 # m[9, 11] = 22L # m[10, 10] = 140Io/A # m[11, 11] = 4L^2 # m[12, 12] = 4L^2 # for i = 1:12 # for j = 1:12 # m[j, i] = m[i, j] # end # end # m = m .* (ρ*A*L)/420 # return m # end
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
6915
module PlotTools using CairoMakie function beam_shape_function(q1, q2, q3, q4, L, x) a0 = q1 a1 = q2 a2 = 1/L^2*(-3*q1-2*q2*L+3*q3-q4*L) a3 = 1/L^3*(2*q1+q2*L-2*q3+q4*L) w = a0 + a1*x + a2*x^2 + a3*x^3 return w end function column_shape_function(a1, a2, L, x) a_x = a1 + (a2-a1)/L * x return a_x end function get_element_deformed_shape(u_local_e, L, Γ, n) x = range(0.0, L, n) #local x-y plane dof = [2, 6, 8, 12] q1, q2, q3, q4 = u_local_e[dof] w_xy = beam_shape_function.(q1, q2, q3, q4, L, x) #local x-z plane dof = [3, 5, 9, 11] q1, q2, q3, q4 = u_local_e[dof] w_xz = beam_shape_function.(q1, q2, q3, q4, L, x) #axial deformation along local x-axis dof = [1, 7] a1, a2 = u_local_e[dof] a_x = column_shape_function.(a1, a2, L, x) #local element deformation δ = [zeros(Float64, 6) for i in eachindex(x)] for i in eachindex(x) δ[i][1] = a_x[i] δ[i][2] = w_xy[i] δ[i][3] = w_xz[i] end #global element deformation Δ = [Γ'[1:6,1:6] * δ[i] for i in eachindex(x)] return δ, Δ, x end function discretized_element_global_coords(node_i_coords, Γ, x) local_element_discretized_coords = [zeros(Float64, 3) for i in eachindex(x)] [local_element_discretized_coords[i][1] = x[i] for i in eachindex(x)] global_element_discretized_coords = [Γ'[1:3, 1:3] * (local_element_discretized_coords[i]) .+ node_i_coords for i in eachindex(x)] return global_element_discretized_coords end function get_display_coords_element(u_local_e, node_i_coords, L, Γ, n) δe, Δe, x = get_element_deformed_shape(u_local_e, L, Γ, n) discretized_element_global_coords = Show.discretized_element_global_coords(node_i_coords, Γ, x) return discretized_element_global_coords, Δe end function get_display_coords(element, node, properties, u_local_e, n) display_coords = Array{Array{Array{Float64, 1}, 1}}(undef, length(properties.L)) display_Δ = Array{Array{Array{Float64, 1}}}(undef, length(properties.L)) for i=1:length(properties.L) index = findfirst(num->num==element.nodes[i][1], node.numbers) node_i_coords = node.coordinates[index] display_coords[i], display_Δ[i] = get_display_coords_element(u_local_e[i], node_i_coords, properties.L[i], properties.Γ[i], n[i]) # get_display_coords_element(u_local_e[i], node_i_coords, properties.L[i], properties.Γ[i], n[i]) end return display_coords, display_Δ end function show_element_deformed_shape!(ax, element_XYZ, Δ, scale, color) X = [element_XYZ[i][1] for i in eachindex(element_XYZ)] Y = [element_XYZ[i][2] for i in eachindex(element_XYZ)] Z = [element_XYZ[i][3] for i in eachindex(element_XYZ)] ΔX = [Δ[i][1] for i in eachindex(element_XYZ)] ΔY = [Δ[i][2] for i in eachindex(element_XYZ)] ΔZ = [Δ[i][3] for i in eachindex(element_XYZ)] for i=1:(length(X)-1) # scatterlines!(ax, [X[i], X[i+1]], [Y[i], Y[i+1]], [Z[i], Z[i+1]], markersize = 5) lines!(ax, [X[i] + scale[1] * ΔX[i], X[i+1] + scale[1] * ΔX[i+1]], [Y[i] + scale[2] * ΔY[i], Y[i+1] + scale[2] * ΔY[i+1]], [Z[i] + scale[3] * ΔZ[i], Z[i+1] + scale[3] * ΔZ[i+1]], linestyle=:dash, color=color, linewidth=2) end # return ax end function define_global_element_displacements(u, global_dof, element, element_connections) u_global_e = [zeros(Float64, 12) for i in eachindex(global_dof)] for i in eachindex(global_dof) u_global_e[i] = u[global_dof[i]] #update element deformations to consider partially restrained connections index = findfirst(num->num==element.numbers[i], element_connections.elements) if !isnothing(index) u_global_e[i][[5, 6, 11, 12]] .= element_connections.displacements[index][[5, 6, 11, 12]] end end return u_global_e end # function show_model_deformed_shape(nodal_displacements, element_connections, element, node, properties, scale) # n = vec(ones(Int64, size(properties.L, 1)) * 11) # u = Array{Float64}(undef, 0) # for i in eachindex(nodal_displacements) # u = [u; nodal_displacements[i]] # end # u_global_e = define_global_element_displacements(u, properties.global_dof, element, element_connections) # u_local_e = [properties.Γ[i]*u_global_e[i] for i in eachindex(u_global_e)] # element_display_coords, element_display_Δ = InstantFrame.UI.get_display_coords(element, node, properties, u_local_e, n) # figure = Figure() # ax = Axis3(figure[1,1]) # for i in eachindex(element_display_coords) # ax = show_element_deformed_shape(element_display_coords[i], element_display_Δ[i], scale, ax) # end # # ax.azimuth[] = 3π/2 # # ax.elevation[] = π/2 # # ax.aspect = (1.0, Y_range/X_range, Z_range/X_range) # return figure # end function define_element_nodal_start_end_coordinates(element, node) element_nodal_coords = Vector{NamedTuple{(:start_node, :end_node), Tuple{Tuple{Float64, Float64, Float64}, Tuple{Float64, Float64, Float64}}}}(undef, length(element.numbers)) for i in eachindex(element.numbers) start_node_index = findfirst(num->num==element.nodes[i][1], node.numbers) end_node_index = findfirst(num->num==element.nodes[i][2], node.numbers) element_nodal_coords[i] = (start_node=node.coordinates[start_node_index], end_node=node.coordinates[end_node_index]) end return element_nodal_coords end function get_node_XYZ(node) X = [node.coordinates[i][1] for i in eachindex(node.coordinates)] Y = [node.coordinates[i][2] for i in eachindex(node.coordinates)] Z = [node.coordinates[i][3] for i in eachindex(node.coordinates)] return X, Y, Z end function get_XYZ_element_ij(element_nodal_coords) Xij=Float64[] Yij=Float64[] Zij=Float64[] for i in eachindex(element_nodal_coords) Xij = push!(Xij, element_nodal_coords[i].start_node[1]) Xij = push!(Xij, element_nodal_coords[i].end_node[1]) Yij = push!(Yij, element_nodal_coords[i].start_node[2]) Yij = push!(Yij, element_nodal_coords[i].end_node[2]) Zij = push!(Zij, element_nodal_coords[i].start_node[3]) Zij = push!(Zij, element_nodal_coords[i].end_node[3]) end return Xij, Yij, Zij end function get_text_location_on_elements(element, node) text_location = Vector{Tuple{Float64, Float64, Float64}}(undef, size(element.numbers, 1)) for i in eachindex(element.numbers) start_index = findfirst(num->num==element.nodes[i][1], node.numbers) end_index = findfirst(num->num==element.nodes[i][2], node.numbers) Δ = node.coordinates[end_index] .- node.coordinates[start_index] text_location[i] = node.coordinates[start_index] .+ Δ./2 end return text_location end end #module
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
14066
module Report using DataFrames, CSV using ..InstantFrame function nodal_inputs(node, support; filename) #add node numbers report = DataFrame(node_numbers=node.numbers) #nodal coordinates nodal_coords = Matrix{Float64}(undef, size(node.coordinates, 1), 3) for i in eachindex(node.coordinates) nodal_coords[i,:] = [node.coordinates[i][1], node.coordinates[i][2], node.coordinates[i][3]] end report[!, :X] = nodal_coords[:,1] report[!, :Y] = nodal_coords[:,2] report[!, :Z] = nodal_coords[:,3] #add support info report[!, :uX] = zeros(size(node.numbers, 1)) report[!, :uY] = zeros(size(node.numbers, 1)) report[!, :uZ] = zeros(size(node.numbers, 1)) report[!, :rX] = zeros(size(node.numbers, 1)) report[!, :rY] = zeros(size(node.numbers, 1)) report[!, :rZ] = zeros(size(node.numbers, 1)) for i in eachindex(support.nodes) index = findfirst(num->num==support.nodes[i], node.numbers) report[index, :uX] = support.stiffness.uX[i] report[index, :uY] = support.stiffness.uY[i] report[index, :uZ] = support.stiffness.uZ[i] report[index, :rX] = support.stiffness.rX[i] report[index, :rY] = support.stiffness.rY[i] report[index, :rZ] = support.stiffness.rZ[i] end # #add point loads # report[!, :FX] = zeros(size(node.numbers, 1)) # report[!, :FY] = zeros(size(node.numbers, 1)) # report[!, :FZ] = zeros(size(node.numbers, 1)) # report[!, :MX] = zeros(size(node.numbers, 1)) # report[!, :MY] = zeros(size(node.numbers, 1)) # report[!, :MZ] = zeros(size(node.numbers, 1)) # if point_load != InstantFrame.PointLoad(nothing) # for i in eachindex(point_load.nodes) # index = findfirst(num->num==point_load.nodes[i], node.numbers) # report[index, :FX] = point_load.magnitudes.FX[i] # report[index, :FY] = point_load.magnitudes.FY[i] # report[index, :FZ] = point_load.magnitudes.FZ[i] # report[index, :MX] = point_load.magnitudes.MX[i] # report[index, :MY] = point_load.magnitudes.MY[i] # report[index, :MZ] = point_load.magnitudes.MZ[i] # end # end CSV.write(filename, report) return report end function element_inputs(element, properties; filename) #add element numbers report = DataFrame(element_numbers=element.numbers) #add element info node_i = [element.nodes[i][1] for i in eachindex(element.nodes)] node_j = [element.nodes[i][2] for i in eachindex(element.nodes)] report[!, :node_i] = node_i report[!, :node_j] = node_j report[!, :L] = properties.L report[!, :local_axis_rotation] = element.orientation #add local element axes unit vectors local_xX = [properties.local_axis_directions[i].x[1] for i in eachindex(properties.local_axis_directions)] local_xY = [properties.local_axis_directions[i].x[2] for i in eachindex(properties.local_axis_directions)] local_xZ = [properties.local_axis_directions[i].x[3] for i in eachindex(properties.local_axis_directions)] local_yX = [properties.local_axis_directions[i].y[1] for i in eachindex(properties.local_axis_directions)] local_yY = [properties.local_axis_directions[i].y[2] for i in eachindex(properties.local_axis_directions)] local_yZ = [properties.local_axis_directions[i].y[3] for i in eachindex(properties.local_axis_directions)] local_zX = [properties.local_axis_directions[i].z[1] for i in eachindex(properties.local_axis_directions)] local_zY = [properties.local_axis_directions[i].z[2] for i in eachindex(properties.local_axis_directions)] local_zZ = [properties.local_axis_directions[i].z[3] for i in eachindex(properties.local_axis_directions)] report[!, :xX] = local_xX report[!, :xY] = local_xY report[!, :xZ] = local_xZ report[!, :yX] = local_yX report[!, :yY] = local_yY report[!, :yZ] = local_yZ report[!, :zX] = local_zX report[!, :zY] = local_zY report[!, :zZ] = local_zZ #add material properties report[!, :E] = properties.E report[!, :Poissons_ratio] = properties.ν report[!, :G] = properties.G report[!, :mass_density] = properties.ρ #add section properties report[!, :A] = properties.A report[!, :Iyy] = properties.Iy report[!, :Izz] = properties.Iz report[!, :Io] = properties.Io report[!, :J] = properties.J #add element end conditions report[!, :ux_i] = fill(Inf, size(element.numbers, 1)) report[!, :uy_i] = fill(Inf, size(element.numbers, 1)) report[!, :uz_i] = fill(Inf, size(element.numbers, 1)) report[!, :rx_i] = fill(Inf, size(element.numbers, 1)) report[!, :ry_i] = fill(Inf, size(element.numbers, 1)) report[!, :rz_i] = fill(Inf, size(element.numbers, 1)) report[!, :ux_j] = fill(Inf, size(element.numbers, 1)) report[!, :uy_j] = fill(Inf, size(element.numbers, 1)) report[!, :uz_j] = fill(Inf, size(element.numbers, 1)) report[!, :rx_j] = fill(Inf, size(element.numbers, 1)) report[!, :ry_j] = fill(Inf, size(element.numbers, 1)) report[!, :rz_j] = fill(Inf, size(element.numbers, 1)) for i in eachindex(properties.start_connection) report.ux_i[i] = properties.start_connection[i].ux report.uy_i[i] = properties.start_connection[i].uy report.uz_i[i] = properties.start_connection[i].uz report.rx_i[i] = properties.start_connection[i].rx report.ry_i[i] = properties.start_connection[i].ry report.rz_i[i] = properties.start_connection[i].rz end for i in eachindex(properties.end_connection) report.ux_j[i] = properties.end_connection[i].ux report.uy_j[i] = properties.end_connection[i].uy report.uz_j[i] = properties.end_connection[i].uz report.rx_j[i] = properties.end_connection[i].rx report.ry_j[i] = properties.end_connection[i].ry report.rz_j[i] = properties.end_connection[i].rz end # #add element uniform loads # report[!, :qX] = zeros(size(element.numbers, 1)) # report[!, :qY] = zeros(size(element.numbers, 1)) # report[!, :qZ] = zeros(size(element.numbers, 1)) # report[!, :mX] = zeros(size(element.numbers, 1)) # report[!, :mY] = zeros(size(element.numbers, 1)) # report[!, :mZ] = zeros(size(element.numbers, 1)) # if uniform_load != InstantFrame.UniformLoad(nothing) # for i in eachindex(uniform_load.elements) # index = findfirst(num->num==uniform_load.elements[i], element.numbers) # report[index, :qX] = uniform_load.magnitudes.qX[i] # report[index, :qY] = uniform_load.magnitudes.qY[i] # report[index, :qZ] = uniform_load.magnitudes.qZ[i] # report[index, :mX] = uniform_load.magnitudes.mX[i] # report[index, :mY] = uniform_load.magnitudes.mY[i] # report[index, :mZ] = uniform_load.magnitudes.mZ[i] # end # end CSV.write(filename, report) return report end function nodal_output(node, support, displacements, reactions; filename) #add node numbers report = DataFrame(node_numbers=node.numbers) #add nodal displacements report[!, :uX] = zeros(Float64, size(node.numbers, 1)) report[!, :uY] = zeros(Float64, size(node.numbers, 1)) report[!, :uZ] = zeros(Float64, size(node.numbers, 1)) report[!, :rX] = zeros(Float64, size(node.numbers, 1)) report[!, :rY] = zeros(Float64, size(node.numbers, 1)) report[!, :rZ] = zeros(Float64, size(node.numbers, 1)) for i in eachindex(displacements) report[i, :uX] = displacements[i][1] report[i, :uY] = displacements[i][2] report[i, :uZ] = displacements[i][3] report[i, :rX] = displacements[i][4] report[i, :rY] = displacements[i][5] report[i, :rZ] = displacements[i][6] end #add nodal reactions report[!, :RX] = zeros(Float64, size(node.numbers, 1)) report[!, :RY] = zeros(Float64, size(node.numbers, 1)) report[!, :RZ] = zeros(Float64, size(node.numbers, 1)) report[!, :MX] = zeros(Float64, size(node.numbers, 1)) report[!, :MY] = zeros(Float64, size(node.numbers, 1)) report[!, :MZ] = zeros(Float64, size(node.numbers, 1)) for i in eachindex(support.nodes) index = findfirst(num-> num==support.nodes[i], node.numbers) report[index, :RX] = reactions[i][1] report[index, :RY] = reactions[i][2] report[index, :RZ] = reactions[i][3] report[index, :MX] = reactions[i][4] report[index, :MY] = reactions[i][5] report[index, :MZ] = reactions[i][6] end CSV.write(filename, report) return report end function element_output(element, forces, connections; filename) #add element numbers report = DataFrame(element_numbers=element.numbers) #add element forces report[!, :Px_i] = zeros(Float64, size(element.numbers, 1)) report[!, :Py_i] = zeros(Float64, size(element.numbers, 1)) report[!, :Pz_i] = zeros(Float64, size(element.numbers, 1)) report[!, :Mx_i] = zeros(Float64, size(element.numbers, 1)) report[!, :My_i] = zeros(Float64, size(element.numbers, 1)) report[!, :Mz_i] = zeros(Float64, size(element.numbers, 1)) report[!, :Px_j] = zeros(Float64, size(element.numbers, 1)) report[!, :Py_j] = zeros(Float64, size(element.numbers, 1)) report[!, :Pz_j] = zeros(Float64, size(element.numbers, 1)) report[!, :Mx_j] = zeros(Float64, size(element.numbers, 1)) report[!, :My_j] = zeros(Float64, size(element.numbers, 1)) report[!, :Mz_j] = zeros(Float64, size(element.numbers, 1)) for i in eachindex(element.numbers) report[i, :Px_i] = forces[i][1] report[i, :Py_i] = forces[i][2] report[i, :Pz_i] = forces[i][3] report[i, :Mx_i] = forces[i][4] report[i, :My_i] = forces[i][5] report[i, :Mz_i] = forces[i][6] report[i, :Px_j] = forces[i][7] report[i, :Py_j] = forces[i][8] report[i, :Pz_j] = forces[i][9] report[i, :Mx_j] = forces[i][10] report[i, :My_j] = forces[i][11] report[i, :Mz_j] = forces[i][12] end #add element end displacements for partially restrained connections if isempty(connections.elements) report[!, :ux_i] = fill("", size(element.numbers, 1)) report[!, :uy_i] = fill("", size(element.numbers, 1)) report[!, :uz_i] = fill("", size(element.numbers, 1)) report[!, :rx_i] = fill("", size(element.numbers, 1)) report[!, :ry_i] = fill("", size(element.numbers, 1)) report[!, :rz_i] = fill("", size(element.numbers, 1)) report[!, :ux_j] = fill("", size(element.numbers, 1)) report[!, :uy_j] = fill("", size(element.numbers, 1)) report[!, :uz_j] = fill("", size(element.numbers, 1)) report[!, :rx_j] = fill("", size(element.numbers, 1)) report[!, :ry_j] = fill("", size(element.numbers, 1)) report[!, :rz_j] = fill("", size(element.numbers, 1)) else report[!, :ux_i] = fill(0.0, size(element.numbers, 1)) report[!, :uy_i] = fill(0.0, size(element.numbers, 1)) report[!, :uz_i] = fill(0.0, size(element.numbers, 1)) report[!, :rx_i] = fill(0.0, size(element.numbers, 1)) report[!, :ry_i] = fill(0.0, size(element.numbers, 1)) report[!, :rz_i] = fill(0.0, size(element.numbers, 1)) report[!, :ux_j] = fill(0.0, size(element.numbers, 1)) report[!, :uy_j] = fill(0.0, size(element.numbers, 1)) report[!, :uz_j] = fill(0.0, size(element.numbers, 1)) report[!, :rx_j] = fill(0.0, size(element.numbers, 1)) report[!, :ry_j] = fill(0.0, size(element.numbers, 1)) report[!, :rz_j] = fill(0.0, size(element.numbers, 1)) for i in eachindex(connections.elements) index = findfirst(num->num==connections.elements[i], element.numbers) report[index, :ux_i] = connections.displacements[i][1] report[index, :uy_i] = connections.displacements[i][2] report[index, :uz_i] = connections.displacements[i][3] report[index, :rx_i] = connections.displacements[i][4] report[index, :ry_i] = connections.displacements[i][5] report[index, :rz_i] = connections.displacements[i][6] report[index, :ux_j] = connections.displacements[i][7] report[index, :uy_j] = connections.displacements[i][8] report[index, :uz_j] = connections.displacements[i][9] report[index, :rx_j] = connections.displacements[i][10] report[index, :ry_j] = connections.displacements[i][11] report[index, :rz_j] = connections.displacements[i][12] end end CSV.write(filename, report) return report end function uniform_loads(uniform_load; filename) #add element numbers report = DataFrame(element_numbers=uniform_load.elements) #add load case labels report[!, :load_case] = uniform_load.labels #add element uniform loads report[!, :qX] = uniform_load.magnitudes.qX report[!, :qY] = uniform_load.magnitudes.qY report[!, :qZ] = uniform_load.magnitudes.qZ report[!, :mX] = uniform_load.magnitudes.mX report[!, :mY] = uniform_load.magnitudes.mY report[!, :mZ] = uniform_load.magnitudes.mZ CSV.write(filename, report) return report end function point_loads(point_load; filename) #add node numbers report = DataFrame(element_numbers=point_load.nodes) #add load case labels report[!, :load_case] = point_load.labels #add nodal point loads report[!, :FX] = point_load.magnitudes.FX report[!, :FY] = point_load.magnitudes.FY report[!, :FZ] = point_load.magnitudes.FZ report[!, :MX] = point_load.magnitudes.MX report[!, :MY] = point_load.magnitudes.MY report[!, :MZ] = point_load.magnitudes.MZ CSV.write(filename, report) return report end end #module
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
10852
module Show using CairoMakie, LinearAlgebra using ..PlotTools #3D function elements!(ax, element_nodal_coords, color) for i in eachindex(element_nodal_coords) lines!(ax, [element_nodal_coords[i].start_node[1], element_nodal_coords[i].end_node[1]], [element_nodal_coords[i].start_node[2], element_nodal_coords[i].end_node[2]], [element_nodal_coords[i].start_node[3], element_nodal_coords[i].end_node[3]], color = color) end end #2D function elements!(ax, Xij, Yij, attributes) linesegments!(ax, Xij, Yij, color = attributes.color, linewidth = attributes.linewidth) end function nodes!(ax, X, Y, Z, markersize, color) scatter!(ax, X, Y, Z, markersize=markersize, color = color) end function nodes!(ax, X, Y, attributes) scatter!(ax, X, Y, markersize=attributes.size, color = attributes.color) end function point_loads!(ax, point_load, node, arrow_scale, arrow_head_scale, unit_arrow_head_size, arrowcolor, linecolor, linewidth) if !isnothing(point_load.nodes) for i in eachindex(point_load.nodes) index = findfirst(num->num==point_load.nodes[i], node.numbers) tail_location = node.coordinates[index] FX = point_load.magnitudes.FX[i] FY = point_load.magnitudes.FY[i] FZ = point_load.magnitudes.FZ[i] unit_arrow_vector = [FX, FY, FZ] / norm([FX, FY, FZ]) arrow_vector = unit_arrow_vector .* arrow_scale arrow_head_size = unit_arrow_head_size * arrow_head_scale arrow_size_vector = arrow_head_scale * unit_arrow_vector arrows!(ax, [tail_location[1]-arrow_vector[1] - arrow_size_vector[1]], [tail_location[2]-arrow_vector[2] - arrow_size_vector[2]], [tail_location[3]-arrow_vector[3]-arrow_size_vector[3]], [arrow_vector[1]], [arrow_vector[2]], [arrow_vector[3]], arrowsize = arrow_head_size, linewidth=linewidth, arrowcolor = arrowcolor, linecolor = linecolor) end end end function uniform_loads!(ax, uniform_load, element, node, unit_arrow_head_size, arrow_head_scale, arrow_scale, linewidth, arrowcolor, linecolor) for i in eachindex(uniform_load.elements) index = findfirst(num->num==uniform_load.elements[i], element.numbers) element_nodes = element.nodes[index] qX = uniform_load.magnitudes.qX[i] qY = uniform_load.magnitudes.qY[i] qZ = uniform_load.magnitudes.qZ[i] #start node index = findfirst(num->num==element_nodes[1], node.numbers) tail_location = node.coordinates[index] if qX != 0.0 unit_arrow_vector = [qX, 0.0, 0.0] / norm([qX, 0.0, 0.0]) arrow_vector = unit_arrow_vector .* arrow_scale define_load_arrow!(ax, unit_arrow_head_size, arrow_head_scale, unit_arrow_vector, arrow_vector, tail_location, linewidth, arrowcolor, linecolor) end if qY != 0.0 unit_arrow_vector = [0.0, qY, 0.0] / norm([0.0, qY, 0.0]) arrow_vector = unit_arrow_vector .* arrow_scale define_load_arrow!(ax, unit_arrow_head_size, arrow_head_scale, unit_arrow_vector, arrow_vector, tail_location, linewidth, arrowcolor, linecolor) end if qZ != 0.0 unit_arrow_vector = [0.0, 0.0, qZ] / norm([0.0, 0.0, qZ]) arrow_vector = unit_arrow_vector .* arrow_scale define_load_arrow!(ax, unit_arrow_head_size, arrow_head_scale, unit_arrow_vector, arrow_vector, tail_location, linewidth, arrowcolor, linecolor) end #end node index = findfirst(num->num==element_nodes[2], node.numbers) tail_location = node.coordinates[index] if qX != 0.0 unit_arrow_vector = [qX, 0.0, 0.0] / norm([qX, 0.0, 0.0]) arrow_vector = unit_arrow_vector .* arrow_scale define_load_arrow!(ax, unit_arrow_head_size, arrow_head_scale, unit_arrow_vector, arrow_vector, tail_location, linewidth, arrowcolor, linecolor) end if qY != 0.0 unit_arrow_vector = [0.0, qY, 0.0] / norm([0.0, qY, 0.0]) arrow_vector = unit_arrow_vector .* arrow_scale define_load_arrow!(ax, unit_arrow_head_size, arrow_head_scale, unit_arrow_vector, arrow_vector, tail_location, linewidth, arrowcolor, linecolor) end if qZ != 0.0 unit_arrow_vector = [0.0, 0.0, qZ] / norm([0.0, 0.0, qZ]) arrow_vector = unit_arrow_vector .* arrow_scale define_load_arrow!(ax, unit_arrow_head_size, arrow_head_scale, unit_arrow_vector, arrow_vector, tail_location, linewidth, arrowcolor, linecolor) end end end function define_load_arrow!(ax, unit_arrow_head_size, arrow_head_scale, unit_arrow_vector, arrow_vector, tail_location, linewidth, arrowcolor, linecolor) arrow_head_size = unit_arrow_head_size * arrow_head_scale arrow_size_vector = arrow_head_scale * unit_arrow_vector arrows!(ax, [tail_location[1]-arrow_vector[1] - arrow_size_vector[1]], [tail_location[2]-arrow_vector[2] - arrow_size_vector[2]], [tail_location[3]-arrow_vector[3]-arrow_size_vector[3]], [arrow_vector[1]], [arrow_vector[2]], [arrow_vector[3]], arrowsize = arrow_head_size, linewidth=linewidth, arrowcolor = arrowcolor, linecolor = linecolor) end function element_local_axes!(ax, element, node, model, unit_arrow_head_size, arrow_head_scale, arrow_scale, arrowcolor, linecolor, linewidth) for i in eachindex(element.numbers) element_nodes = element.nodes[i] #start node start_index = findfirst(num->num==element_nodes[1], node.numbers) end_index = findfirst(num->num==element_nodes[2], node.numbers) Δ = node.coordinates[end_index] .- node.coordinates[start_index] tail_location = node.coordinates[start_index] .+ Δ./2 unit_vector_Y = [0.0, 1.0, 0.0] local_Y = model.properties.Γ[i][1:3,1:3]' * unit_vector_Y # unit_arrow_vector = global_Y arrow_vector = local_Y .* arrow_scale arrow_head_size = unit_arrow_head_size * arrow_head_scale arrows!(ax, [tail_location[1]], [tail_location[2]], [tail_location[3]], [arrow_vector[1]], [arrow_vector[2]], [arrow_vector[3]], arrowsize = arrow_head_size, linewidth=linewidth, arrowcolor = arrowcolor, linecolor = linecolor) unit_vector_X = [1.0, 0.0, 0.0] local_X = model.properties.Γ[i][1:3,1:3]' * unit_vector_X arrow_vector = local_X .* arrow_scale arrow_head_size = unit_arrow_head_size * arrow_head_scale arrows!(ax, [tail_location[1]], [tail_location[2]], [tail_location[3]], [arrow_vector[1]], [arrow_vector[2]], [arrow_vector[3]], arrowsize = arrow_head_size, linewidth=linewidth, arrowcolor = arrowcolor, linecolor = linecolor) end end function deformed_shape!(ax, nodal_displacements, global_dof, element, node, properties, element_connections, n, scale, linecolor) u = Array{Float64}(undef, 0) for i in eachindex(nodal_displacements) u = [u; nodal_displacements[i]] end u_global_e = InstantFrame.PlotTools.define_global_element_displacements(u, global_dof, element, element_connections) u_local_e = [properties.Γ[i]*u_global_e[i] for i in eachindex(u_global_e)] element_display_coords, element_display_Δ = InstantFrame.PlotTools.get_display_coords(element, node, properties, u_local_e, n) for i in eachindex(element_display_coords) InstantFrame.PlotTools.show_element_deformed_shape!(ax, element_display_coords[i], element_display_Δ[i], scale, linecolor) end end function node_numbers!(ax, node, fontsize, color) text!(ax, [Point3f(node.coordinates[i][1], node.coordinates[i][2], node.coordinates[i][3]) for i in eachindex(node.coordinates)], text = [string(node.numbers[i]) for i in eachindex(node.numbers)], # rotation = [i / 7 * 1.5pi for i in 1:7], color = color, # align = (:left, :baseline), fontsize = fontsize, # markerspace = :data ) end function element_numbers!(ax, element, node, fontsize, color) text_location = Vector{Tuple{Float64, Float64, Float64}}(undef, size(element.numbers, 1)) for i in eachindex(element.numbers) start_index = findfirst(num->num==element.nodes[i][1], node.numbers) end_index = findfirst(num->num==element.nodes[i][2], node.numbers) Δ = node.coordinates[end_index] .- node.coordinates[start_index] text_location[i] = node.coordinates[start_index] .+ Δ./2 end text!(ax, [Point3f(text_location[i][1], text_location[i][2], text_location[i][3]) for i in eachindex(text_location)], text = [string(element.numbers[i]) for i in eachindex(element.numbers)], # rotation = [i / 7 * 1.5pi for i in 1:7], color = color, # align = (:left, :baseline), fontsize = fontsize, # markerspace = :data ) end #2D function axial_force!(ax, Xij, Yij, axial_forces, attributes) num_elements = Int(size(Xij)[1]/2) force_color = Vector{String}(undef, num_elements) linewidths = Vector{Float64}(undef, num_elements) max_force = maximum(abs.(axial_forces)) for i=1:num_elements if axial_forces[i] >= 0.0 force_color[i] = attributes.tension_color else force_color[i] = attributes.compression_color end linewidths[i] = abs(axial_forces[i])/max_force * attributes.scale end linesegments!(ax, Xij, Yij, color = force_color, linewidth = linewidths) end function axial_force_magnitude!(ax, element, node, axial_forces, active_element_index, attributes) text_location = PlotTools.get_text_location_on_elements(element, node) three_dimensional = isempty(findall(coord->coord == 0.0, [text_location[i][3] for i in eachindex(text_location)])) if three_dimensional text!(ax, [Point3f(text_location[i][1], text_location[i][2], text_location[i][3]) for i in eachindex(text_location)], text = [string(axial_forces[i]) for i in eachindex(axial_forces)], # rotation = [i / 7 * 1.5pi for i in 1:7], color = attributes.color, # align = (:left, :baseline), fontsize = attributes.fontsize, # markerspace = :data) ) else text!(ax, [Point2f(text_location[active_element_index[i]][1], text_location[active_element_index[i]][2]) for i in eachindex(active_element_index)], text = [string(axial_forces[active_element_index[i]]) for i in eachindex(active_element_index)], # rotation = [i / 7 * 1.5pi for i in 1:7], color = attributes.color, # align = (:left, :baseline), fontsize = attributes.fontsize, # markerspace = :data) ) end end end #module
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1882
using InstantFrame, GLMakie #Chopra Example 18.4 - 2D portal frame vibration modes material = InstantFrame.Material(names=["steel"], E=[29E6], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam", "column"], A=[10.0, 5.0], Iy=[100.0, 50.0], Iz=[100.0, 50.0], J=[0.001, 0.0005]) connection = InstantFrame.Connection(names=["rigid", "hinge"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2, 3, 4], coordinates=[(0.0, 0.0, 0.0), (0.0, 120.0, 0.0), (240.0, 120.0, 0.0), (240.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2, 3], nodes=[(1,2), (2,3), (3, 4)], orientation=[0.0, 0.0, 0.0], connections=[("rigid", "rigid"), ("rigid", "rigid"), ("rigid", "rigid")], cross_section=["column", "beam", "column"], material=["steel", "steel", "steel"]) support = InstantFrame.Support(nodes=[1, 2, 3, 4], stiffness=(uX=[Inf,0.0,0.0,Inf], uY=[Inf,0.0,0.0,Inf], uZ=[Inf,Inf, Inf,Inf], rX=[Inf,Inf, Inf, Inf], rY=[Inf,Inf, Inf,Inf], rZ=[Inf,0.0, 0.0, Inf])) uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(nothing) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "modal vibration") #Chopra modal frequencies E = 29000000.0 I = 50.0 h = 120.0 A = 5.0 m = material.ρ[1] * A ω1 = 1.9004*sqrt(E*I/(m*h^4)) ω2 = 4.6609*sqrt(E*I/(m*h^4)) ω3 = 14.5293*sqrt(E*I/(m*h^4)) #Chopra mode shape for mode 1 ϕ1 = [0.4636, -0.2741/h, -0.2741/h] #test #small differences from including axial stiffness? isapprox(model.solution.ωn[1], ω1, rtol=0.01) isapprox(model.solution.ωn[2], ω2, rtol=0.02) isapprox(model.solution.ωn[3], ω3, rtol=0.04) isapprox(model.solution.ϕ[1, ][[7, 12, 18]] .* 0.4636, ϕ1, atol = 0.01)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1628
using InstantFrame #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (180.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0], connections=[("rigid", "rigid")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,Inf], uZ=[Inf,0.0], rX=[Inf,Inf], rY=[Inf,0.0], rZ=[Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], magnitudes=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], magnitudes=(FX=[-50.0], FY=[0.0], FZ=[1.0], MX=[0.0], MY=[0.0], MZ=[0.0])) analysis_type = "first order" model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type) ##tests #deflection isapprox(model.solution.nodal_displacements[2][3], 1.807, rtol=0.05) #cantilever moment isapprox(model.solution.element_forces[1][5], 180.0, rtol=0.05)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1770
using InstantFrame #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (180.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0], connections=[("rigid", "rigid")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,0.0], uZ=[Inf,0.0], rX=[Inf,Inf], rY=[Inf,0.0], rZ=[Inf,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], magnitudes=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], magnitudes=(FX=[-50.0], FY=[1.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "second order", solution_tolerance = 1e-9) ##tests #deflection isapprox(model.solution.displacements[2][2], 0.765, rtol=0.05) #cantilever moment isapprox(-model.solution.forces[1][6], 218.3, rtol=0.05) # scale = (1.0, 1.0, 1.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1705
using InstantFrame #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (180.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0], connections=[("rigid", "rigid")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,Inf], uZ=[Inf,0.0], rX=[Inf,Inf], rY=[Inf,0.0], rZ=[Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], magnitudes=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], magnitudes=(FX=[-50.0], FY=[0.0], FZ=[1.0], MX=[0.0], MY=[0.0], MZ=[0.0])) solution_tolerance = 1.0E-8 analysis_type = "second order" model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type, solution_tolerance) ##tests #deflection isapprox(model.solution.displacements[2][3], 4.597, rtol=0.05) #cantilever moment isapprox(model.solution.element_forces[1][5], 409.8, rtol=0.08) #tolerance is a little loose here
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
6954
using InstantFrame, StaticArrays, NLsolve #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (180.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0], connections=[("rigid", "rigid")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,Inf], uZ=[Inf,0.0], rX=[Inf,Inf], rY=[Inf,0.0], rZ=[Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], magnitudes=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], magnitudes=(FX=[-50.0], FY=[0.0], FZ=[1.0], MX=[0.0], MY=[0.0], MZ=[0.0])) # model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "second order") ######### properties = InstantFrame.define_element_properties(node, cross_section, material, element, connection) ke_local = [InstantFrame.define_local_elastic_stiffness_matrix(properties.Iy[i], properties.Iz[i], properties.A[i], properties.J[i], properties.E[i], properties.ν[i], properties.L[i]) for i in eachindex(properties.L)] ke_local = InstantFrame.modify_element_local_connection_stiffness(properties, ke_local, element) ke_global = [properties.Γ[i]'*ke_local[i]*properties.Γ[i] for i in eachindex(properties.L)] Ke = InstantFrame.assemble_global_matrix(ke_global, properties.global_dof) free_global_dof, fixed_global_dof, elastic_supports = InstantFrame.define_free_global_dof(node, support) for i in eachindex(elastic_supports.global_dof) #add springs Ke[elastic_supports.global_dof[i], elastic_supports.global_dof[i]] += elastic_supports.global_stiffness[i] end equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load = InstantFrame.calculate_nodal_forces_from_uniform_loads(uniform_load, element, node, properties) global_dof_point_loads = InstantFrame.define_global_dof_point_loads(node, point_load) F = global_dof_point_loads .+ global_dof_nodal_forces_uniform_load forces = InstantFrame.Forces(equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load, global_dof_point_loads, F) Ff = F[free_global_dof] Ke_ff = Ke[free_global_dof, free_global_dof] u1f = Ke_ff \ Ff u1 = zeros(Float64, size(Ke,1)) u1[free_global_dof] = u1f # P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, u1) #calculate element internal forces P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, element, uniform_load, local_fixed_end_forces, u1) P1_axial = [P1[i][7] for i in eachindex(P1)] kg_local = [InstantFrame.define_local_geometric_stiffness_matrix(P1_axial[i], properties.L[i]) for i in eachindex(properties.L)] kg_global = [properties.Γ[i]'*kg_local[i]*properties.Γ[i] for i in eachindex(properties.L)] Kg = InstantFrame.assemble_global_matrix(kg_global, properties.global_dof) Kg_ff = Kg[free_global_dof, free_global_dof] Kff = Ke_ff + Kg_ff # u = fill(0.0, 100) # u[free_global_dof] = convert(Vector{Float64}, u1f) # length(node.numbers)*6 # u_all = SVector{num_dof}(zeros(Float64, num_dof)) # function residual(uf, p) # Ke_ff, Kg_ff, Ff, node, element, properties, free_global_dof, fixed_global_dof = p # num_dof = length(node.numbers)*6 # u = Vector{Any}(undef, num_dof) # u[free_global_dof] = uf # u[fixed_global_dof] .= 0.0 # # u = zeros(Any, num_dof) # # u_all = MVector{num_dof}(zeros(Float64, num_dof)) # # u_all = deepcopy(uf[1]) # #convert(Vector{Float64}, uf) # print("type is " * string(typeof(uf))) # print(" ") # Ke_ff = update_Ke(node, element, properties, u) # Kff = Ke_ff + Kg_ff # Kff * uf - Ff # end # p = [Ke_ff, Kg_ff, Ff, node, element, properties, free_global_dof, fixed_global_dof] # u1f = SVector{length(u1f)}(u1f) # probN = NonlinearSolve.NonlinearProblem{false}(residual, u1f, p) # solution_tolerance = 0.01 # u2f = NonlinearSolve.solve(probN, NewtonRaphson(), reltol = solution_tolerance) solution = nlsolve((R,uf) ->residual!(R, uf, Kg_ff, Ff, free_global_dof, ke_local), u1f, method = :newton) function residual!(R, uf, Kg_ff, Ff, free_global_dof, ke_local) num_dof = length(node.numbers) * 6 u = zeros(Float64, num_dof) u[free_global_dof] = uf Ke_ff = update_Ke(node, element, properties, ke_local, u) # print(Ke_ff) # print(" ") Kff = Ke_ff + Kg_ff for i in eachindex(Ff) R[i] = transpose(Kff[i,:]) * uf - Ff[i] end return R end function update_Ke(node, element, properties, ke_local, u) num_elem = length(properties.L) Γ = Array{Array{Float64, 2}}(undef, num_elem) rotation_angles = Array{NamedTuple{(:Y, :Z, :X), NTuple{3, Float64}}}(undef, num_elem) # num_nodes = length(node.numbers) * 6 # u = zeros(Float64, num_nodes) # u[free_global_dof] = uf nodal_displacements = InstantFrame.define_nodal_displacements(node, u) # print(nodal_displacements) # print(" ") node_i = collect(node.coordinates[1]) for i in eachindex(element.numbers) #nodal coordinates node_i_index = findfirst(node_num->node_num == element.nodes[i][1], node.numbers) node_j_index = findfirst(node_num->node_num == element.nodes[i][2], node.numbers) node_i = collect(node.coordinates[node_i_index]) + nodal_displacements[node_i_index][1:3] #update geometry node_j = collect(node.coordinates[node_j_index]) + nodal_displacements[node_j_index][1:3] #update geometry #rotation matrix Γ[i], rotation_angles[i] = InstantFrame.define_rotation_matrix(node_i, node_j, element.orientation[i]) end print(" ") ke_global = [Γ[i]' * ke_local[i] * Γ[i] for i in eachindex(properties.L)] Ke = InstantFrame.assemble_global_matrix(ke_global, properties.global_dof) Ke_ff = Ke[free_global_dof, free_global_dof] # print(Ke_ff) # print(" ") return Ke_ff end ############################## ##tests #deflection isapprox(model.solution.nodal_displacements[2][3], 4.597, rtol=0.05) #cantilever moment isapprox(model.solution.element_forces[1][5], 409.8, rtol=0.08) #tolerance is a little loose here
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
7700
using InstantFrame, StaticArrays, NLsolve, LineSearches #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (180.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0], connections=[("rigid", "rigid")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,Inf], uZ=[Inf,0.0], rX=[Inf,Inf], rY=[Inf,0.0], rZ=[Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], magnitudes=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], magnitudes=(FX=[-50.0], FY=[0.0], FZ=[1.0], MX=[0.0], MY=[0.0], MZ=[0.0])) analysis_type = "second order" solution_tolerance = 1E-9 model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type, solution_tolerance) ######### properties = InstantFrame.define_element_properties(node, cross_section, material, element, connection) ke_local = [InstantFrame.define_local_elastic_stiffness_matrix(properties.Iy[i], properties.Iz[i], properties.A[i], properties.J[i], properties.E[i], properties.ν[i], properties.L[i]) for i in eachindex(properties.L)] ke_local = InstantFrame.modify_element_local_connection_stiffness(properties, ke_local, element) ke_global = [properties.Γ[i]'*ke_local[i]*properties.Γ[i] for i in eachindex(properties.L)] Ke = InstantFrame.assemble_global_matrix(ke_global, properties.global_dof) free_global_dof, fixed_global_dof, elastic_supports = InstantFrame.define_free_global_dof(node, support) for i in eachindex(elastic_supports.global_dof) #add springs Ke[elastic_supports.global_dof[i], elastic_supports.global_dof[i]] += elastic_supports.global_stiffness[i] end equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load = InstantFrame.calculate_nodal_forces_from_uniform_loads(uniform_load, element, node, properties) global_dof_point_loads = InstantFrame.define_global_dof_point_loads(node, point_load) F = global_dof_point_loads .+ global_dof_nodal_forces_uniform_load forces = InstantFrame.Forces(equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load, global_dof_point_loads, F) Ff = F[free_global_dof] Ke_ff = Ke[free_global_dof, free_global_dof] u1f = Ke_ff \ Ff u1 = zeros(Float64, size(Ke,1)) u1[free_global_dof] = u1f # P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, u1) #calculate element internal forces P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, element, uniform_load, local_fixed_end_forces, u1) P1_axial = [P1[i][7] for i in eachindex(P1)] kg_local = [InstantFrame.define_local_geometric_stiffness_matrix(P1_axial[i], properties.L[i]) for i in eachindex(properties.L)] kg_global = [properties.Γ[i]'*kg_local[i]*properties.Γ[i] for i in eachindex(properties.L)] Kg = InstantFrame.assemble_global_matrix(kg_global, properties.global_dof) Kg_ff = Kg[free_global_dof, free_global_dof] Kff = Ke_ff + Kg_ff # u = fill(0.0, 100) # u[free_global_dof] = convert(Vector{Float64}, u1f) # length(node.numbers)*6 # u_all = SVector{num_dof}(zeros(Float64, num_dof)) # function residual(uf, p) # Ke_ff, Kg_ff, Ff, node, element, properties, free_global_dof, fixed_global_dof = p # num_dof = length(node.numbers)*6 # u = Vector{Any}(undef, num_dof) # u[free_global_dof] = uf # u[fixed_global_dof] .= 0.0 # # u = zeros(Any, num_dof) # # u_all = MVector{num_dof}(zeros(Float64, num_dof)) # # u_all = deepcopy(uf[1]) # #convert(Vector{Float64}, uf) # print("type is " * string(typeof(uf))) # print(" ") # Ke_ff = update_Ke(node, element, properties, u) # Kff = Ke_ff + Kg_ff # Kff * uf - Ff # end # p = [Ke_ff, Kg_ff, Ff, node, element, properties, free_global_dof, fixed_global_dof] # u1f = SVector{length(u1f)}(u1f) # probN = NonlinearSolve.NonlinearProblem{false}(residual, u1f, p) # solution_tolerance = 0.01 # u2f = NonlinearSolve.solve(probN, NewtonRaphson(), reltol = solution_tolerance) u1f = 0.01*u1f solution = nlsolve((R,uf) ->residual!(R, uf, Ke_ff, Ff, free_global_dof, ke_local, uniform_load, local_fixed_end_forces, properties, node), u1f, method = :newton) function residual!(R, uf, Ke_ff, Ff, free_global_dof, ke_local, uniform_load, local_fixed_end_forces, properties, node) num_dof = length(node.numbers) * 6 u = zeros(Float64, num_dof) u[free_global_dof] = uf Kg_ff = update_Kg(element, properties, ke_local, uniform_load, local_fixed_end_forces, u) # print(Ke_ff) # print(" ") Kff = Ke_ff + Kg_ff for i in eachindex(Ff) R[i] = transpose(Kff[i,:]) * uf - Ff[i] end return R end function update_Kg(element, properties, ke_local, uniform_load, local_fixed_end_forces, u) Γ = update_rotation_angles(node, element, properties, u) properties.Γ = deepcopy(Γ) # properties.Γ = [0.0] P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, element, uniform_load, local_fixed_end_forces, u) P1_axial = [P1[i][7] for i in eachindex(P1)] # P1_axial = [-50.0] kg_local = [InstantFrame.define_local_geometric_stiffness_matrix(P1_axial[i], properties.L[i]) for i in eachindex(properties.L)] kg_global = [Γ[i]'*kg_local[i]*Γ[i] for i in eachindex(properties.L)] Kg = InstantFrame.assemble_global_matrix(kg_global, properties.global_dof) Kg_ff = Kg[free_global_dof, free_global_dof] print(P1_axial) print(" ") return Kg_ff end function update_rotation_angles(node, element, properties, u) num_elem = length(properties.L) Γ = Array{Array{Float64, 2}}(undef, num_elem) rotation_angles = Array{NamedTuple{(:Y, :Z, :X), NTuple{3, Float64}}}(undef, num_elem) nodal_displacements = InstantFrame.define_nodal_displacements(node, u) node_i = collect(node.coordinates[1]) for i in eachindex(element.numbers) #nodal coordinates node_i_index = findfirst(node_num->node_num == element.nodes[i][1], node.numbers) node_j_index = findfirst(node_num->node_num == element.nodes[i][2], node.numbers) node_i = collect(node.coordinates[node_i_index]) + nodal_displacements[node_i_index][1:3] #update geometry node_j = collect(node.coordinates[node_j_index]) + nodal_displacements[node_j_index][1:3] #update geometry #rotation matrix Γ[i], rotation_angles[i] = InstantFrame.define_rotation_matrix(node_i, node_j, element.orientation[i]) # print(Γ[i]) # print(" ") end return Γ end ############################## ##tests #deflection isapprox(model.solution.nodal_displacements[2][3], 4.597, rtol=0.05) #cantilever moment isapprox(model.solution.element_forces[1][5], 409.8, rtol=0.08) #tolerance is a little loose here α = 1/50 L = 180.0 P = 50.0 E = 29000.0 I = 37.1 Δ = α*L * (tan(sqrt(P/(E*I))*L)/(sqrt(P/(E*I))*L) - 1)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
8620
using InstantFrame, StaticArrays, NLsolve, LineSearches #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (180.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0], connections=[("rigid", "rigid")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,Inf], uZ=[Inf,0.0], rX=[Inf,Inf], rY=[Inf,0.0], rZ=[Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], magnitudes=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], magnitudes=(FX=[-50.0], FY=[0.0], FZ=[1.0], MX=[0.0], MY=[0.0], MZ=[0.0])) analysis_type = "second order" solution_tolerance = 1E-9 model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type, solution_tolerance) #global to local node.coordinates = [node.coordinates[i] .+ tuple(model.solution.displacements[i][1:3]...) for i in eachindex(node.coordinates)] analysis_type = "first order" model_update = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type) u_elem_g = model.solution.u InstantFrame.define_nodal_displacements(node, model.solution.u) rotation_angles, Γ = update_rotation_angles(node, element, model.properties, model.solution.u) u_elem_l = model.properties.Γ[1] * model.solution.u u_elem_l = Γ[1]' * u_elem_l P_rotated = model.equations.ke_local[1] * u_elem_l #convert local to new local model.properties.Γ = Γ P = InstantFrame.calculate_element_internal_forces(model.properties, model.equations.ke_local, element, uniform_load, model.forces.local_fixed_end_forces, model.solution.u) ######### properties = InstantFrame.define_element_properties(node, cross_section, material, element, connection) ke_local = [InstantFrame.define_local_elastic_stiffness_matrix(properties.Iy[i], properties.Iz[i], properties.A[i], properties.J[i], properties.E[i], properties.ν[i], properties.L[i]) for i in eachindex(properties.L)] ke_local = InstantFrame.modify_element_local_connection_stiffness(properties, ke_local, element) ke_global = [properties.Γ[i]'*ke_local[i]*properties.Γ[i] for i in eachindex(properties.L)] Ke = InstantFrame.assemble_global_matrix(ke_global, properties.global_dof) free_global_dof, fixed_global_dof, elastic_supports = InstantFrame.define_free_global_dof(node, support) for i in eachindex(elastic_supports.global_dof) #add springs Ke[elastic_supports.global_dof[i], elastic_supports.global_dof[i]] += elastic_supports.global_stiffness[i] end equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load = InstantFrame.calculate_nodal_forces_from_uniform_loads(uniform_load, element, node, properties) global_dof_point_loads = InstantFrame.define_global_dof_point_loads(node, point_load) F = global_dof_point_loads .+ global_dof_nodal_forces_uniform_load forces = InstantFrame.Forces(equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load, global_dof_point_loads, F) Ff = F[free_global_dof] Ke_ff = Ke[free_global_dof, free_global_dof] u1f = Ke_ff \ Ff u1 = zeros(Float64, size(Ke,1)) u1[free_global_dof] = u1f # P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, u1) #calculate element internal forces P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, element, uniform_load, local_fixed_end_forces, u1) P1_axial = [P1[i][7] for i in eachindex(P1)] kg_local = [InstantFrame.define_local_geometric_stiffness_matrix(P1_axial[i], properties.L[i]) for i in eachindex(properties.L)] kg_global = [properties.Γ[i]'*kg_local[i]*properties.Γ[i] for i in eachindex(properties.L)] Kg = InstantFrame.assemble_global_matrix(kg_global, properties.global_dof) Kg_ff = Kg[free_global_dof, free_global_dof] Kff = Ke_ff + Kg_ff # u = fill(0.0, 100) # u[free_global_dof] = convert(Vector{Float64}, u1f) # length(node.numbers)*6 # u_all = SVector{num_dof}(zeros(Float64, num_dof)) # function residual(uf, p) # Ke_ff, Kg_ff, Ff, node, element, properties, free_global_dof, fixed_global_dof = p # num_dof = length(node.numbers)*6 # u = Vector{Any}(undef, num_dof) # u[free_global_dof] = uf # u[fixed_global_dof] .= 0.0 # # u = zeros(Any, num_dof) # # u_all = MVector{num_dof}(zeros(Float64, num_dof)) # # u_all = deepcopy(uf[1]) # #convert(Vector{Float64}, uf) # print("type is " * string(typeof(uf))) # print(" ") # Ke_ff = update_Ke(node, element, properties, u) # Kff = Ke_ff + Kg_ff # Kff * uf - Ff # end # p = [Ke_ff, Kg_ff, Ff, node, element, properties, free_global_dof, fixed_global_dof] # u1f = SVector{length(u1f)}(u1f) # probN = NonlinearSolve.NonlinearProblem{false}(residual, u1f, p) # solution_tolerance = 0.01 # u2f = NonlinearSolve.solve(probN, NewtonRaphson(), reltol = solution_tolerance) # u1f = 0.01*u1f solution = nlsolve((R,uf) ->residual!(R, uf, Ke_ff, Kg_ff, Ff, free_global_dof, ke_local, uniform_load, local_fixed_end_forces, properties, node), u1f, method = :newton) function residual!(R, uf, Ke_ff, Kg_ff, Ff, free_global_dof, ke_local, uniform_load, local_fixed_end_forces, properties, node) # num_dof = length(node.numbers) * 6 # u = zeros(Float64, num_dof) # u[free_global_dof] = uf # Kg_ff = update_Kg(element, properties, ke_local, uniform_load, local_fixed_end_forces, u) # print(Ke_ff) # print(" ") Kff = Ke_ff + Kg_ff for i in eachindex(Ff) R[i] = transpose(Kff[i,:]) * uf - Ff[i] end return R end function update_Kg(element, properties, ke_local, uniform_load, local_fixed_end_forces, u) Γ = update_rotation_angles(node, element, properties, u) properties.Γ = deepcopy(Γ) # properties.Γ = [0.0] P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, element, uniform_load, local_fixed_end_forces, u) P1_axial = [P1[i][7] for i in eachindex(P1)] # P1_axial = [-50.0] kg_local = [InstantFrame.define_local_geometric_stiffness_matrix(P1_axial[i], properties.L[i]) for i in eachindex(properties.L)] kg_global = [Γ[i]'*kg_local[i]*Γ[i] for i in eachindex(properties.L)] Kg = InstantFrame.assemble_global_matrix(kg_global, properties.global_dof) Kg_ff = Kg[free_global_dof, free_global_dof] print(P1_axial) print(" ") return Kg_ff end function update_rotation_angles(node, element, properties, u) num_elem = length(properties.L) Γ = Array{Array{Float64, 2}}(undef, num_elem) rotation_angles = Array{NamedTuple{(:Y, :Z, :X), NTuple{3, Float64}}}(undef, num_elem) nodal_displacements = InstantFrame.define_nodal_displacements(node, u) node_i = collect(node.coordinates[1]) for i in eachindex(element.numbers) #nodal coordinates node_i_index = findfirst(node_num->node_num == element.nodes[i][1], node.numbers) node_j_index = findfirst(node_num->node_num == element.nodes[i][2], node.numbers) node_i = collect(node.coordinates[node_i_index]) + nodal_displacements[node_i_index][1:3] #update geometry node_j = collect(node.coordinates[node_j_index]) + nodal_displacements[node_j_index][1:3] #update geometry #rotation matrix Γ[i], rotation_angles[i] = InstantFrame.define_rotation_matrix(node_i, node_j, element.orientation[i]) # print(Γ[i]) # print(" ") end return rotation_angles, Γ end ############################## ##tests #deflection isapprox(model.solution.nodal_displacements[2][3], 4.597, rtol=0.05) #cantilever moment isapprox(model.solution.element_forces[1][5], 409.8, rtol=0.08) #tolerance is a little loose here α = 1/50 L = 180.0 P = 50.0 E = 29000.0 I = 37.1 Δ = α*L * (tan(sqrt(P/(E*I))*L)/(sqrt(P/(E*I))*L) - 1)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
9258
using InstantFrame, StaticArrays, NLsolve, LineSearches #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) tip_disp = Vector{Float64}(undef, 10) base_moment = Vector{Float64}(undef, 10) for i =2:11 num_nodes = i x_range = range(0.0, 180.0, num_nodes) node = InstantFrame.Node(numbers=range(1, num_nodes, num_nodes), coordinates=[(x_range[i], 0.0, 0.0) for i in eachindex(x_range)]) num_elem = num_nodes - 1 element = InstantFrame.Element(numbers=range(1, num_elem, num_elem), nodes=[(i,i+1) for i=1:num_elem], orientation=fill(0.0, num_elem), connections=fill(("rigid", "rigid"), num_elem), cross_section=fill("beam", num_elem), material=fill("steel", num_elem)) support = InstantFrame.Support(nodes=[1, num_nodes], stiffness=(uX=[Inf,0.0], uY=[Inf,Inf], uZ=[Inf,0.0], rX=[Inf,Inf], rY=[Inf,0.0], rZ=[Inf,Inf])) # uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], magnitudes=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[num_nodes], magnitudes=(FX=[-50.0], FY=[0.0], FZ=[1.0], MX=[0.0], MY=[0.0], MZ=[0.0])) analysis_type = "second order" solution_tolerance = 1E-9 model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type, solution_tolerance) tip_disp[i-1] = model.solution.displacements[end][3] base_moment[i-1] = model.solution.reactions[1][5] end using Plots plot(1:10, tip_disp, markershape = :o) plot(1:10, base_moment, markershape = :o) #global to local node.coordinates = [node.coordinates[i] .+ tuple(model.solution.displacements[i][1:3]...) for i in eachindex(node.coordinates)] analysis_type = "first order" model_update = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type) u_elem_g = model.solution.u InstantFrame.define_nodal_displacements(node, model.solution.u) rotation_angles, Γ = update_rotation_angles(node, element, model.properties, model.solution.u) u_elem_l = model.properties.Γ[1] * model.solution.u u_elem_l = Γ[1]' * u_elem_l P_rotated = model.equations.ke_local[1] * u_elem_l #convert local to new local model.properties.Γ = Γ P = InstantFrame.calculate_element_internal_forces(model.properties, model.equations.ke_local, element, uniform_load, model.forces.local_fixed_end_forces, model.solution.u) ######### properties = InstantFrame.define_element_properties(node, cross_section, material, element, connection) ke_local = [InstantFrame.define_local_elastic_stiffness_matrix(properties.Iy[i], properties.Iz[i], properties.A[i], properties.J[i], properties.E[i], properties.ν[i], properties.L[i]) for i in eachindex(properties.L)] ke_local = InstantFrame.modify_element_local_connection_stiffness(properties, ke_local, element) ke_global = [properties.Γ[i]'*ke_local[i]*properties.Γ[i] for i in eachindex(properties.L)] Ke = InstantFrame.assemble_global_matrix(ke_global, properties.global_dof) free_global_dof, fixed_global_dof, elastic_supports = InstantFrame.define_free_global_dof(node, support) for i in eachindex(elastic_supports.global_dof) #add springs Ke[elastic_supports.global_dof[i], elastic_supports.global_dof[i]] += elastic_supports.global_stiffness[i] end equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load = InstantFrame.calculate_nodal_forces_from_uniform_loads(uniform_load, element, node, properties) global_dof_point_loads = InstantFrame.define_global_dof_point_loads(node, point_load) F = global_dof_point_loads .+ global_dof_nodal_forces_uniform_load forces = InstantFrame.Forces(equiv_global_nodal_forces_uniform_load, local_fixed_end_forces, global_dof_nodal_forces_uniform_load, global_dof_point_loads, F) Ff = F[free_global_dof] Ke_ff = Ke[free_global_dof, free_global_dof] u1f = Ke_ff \ Ff u1 = zeros(Float64, size(Ke,1)) u1[free_global_dof] = u1f # P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, u1) #calculate element internal forces P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, element, uniform_load, local_fixed_end_forces, u1) P1_axial = [P1[i][7] for i in eachindex(P1)] kg_local = [InstantFrame.define_local_geometric_stiffness_matrix(P1_axial[i], properties.L[i]) for i in eachindex(properties.L)] kg_global = [properties.Γ[i]'*kg_local[i]*properties.Γ[i] for i in eachindex(properties.L)] Kg = InstantFrame.assemble_global_matrix(kg_global, properties.global_dof) Kg_ff = Kg[free_global_dof, free_global_dof] Kff = Ke_ff + Kg_ff # u = fill(0.0, 100) # u[free_global_dof] = convert(Vector{Float64}, u1f) # length(node.numbers)*6 # u_all = SVector{num_dof}(zeros(Float64, num_dof)) # function residual(uf, p) # Ke_ff, Kg_ff, Ff, node, element, properties, free_global_dof, fixed_global_dof = p # num_dof = length(node.numbers)*6 # u = Vector{Any}(undef, num_dof) # u[free_global_dof] = uf # u[fixed_global_dof] .= 0.0 # # u = zeros(Any, num_dof) # # u_all = MVector{num_dof}(zeros(Float64, num_dof)) # # u_all = deepcopy(uf[1]) # #convert(Vector{Float64}, uf) # print("type is " * string(typeof(uf))) # print(" ") # Ke_ff = update_Ke(node, element, properties, u) # Kff = Ke_ff + Kg_ff # Kff * uf - Ff # end # p = [Ke_ff, Kg_ff, Ff, node, element, properties, free_global_dof, fixed_global_dof] # u1f = SVector{length(u1f)}(u1f) # probN = NonlinearSolve.NonlinearProblem{false}(residual, u1f, p) # solution_tolerance = 0.01 # u2f = NonlinearSolve.solve(probN, NewtonRaphson(), reltol = solution_tolerance) # u1f = 0.01*u1f solution = nlsolve((R,uf) ->residual!(R, uf, Ke_ff, Kg_ff, Ff, free_global_dof, ke_local, uniform_load, local_fixed_end_forces, properties, node), u1f, method = :newton) function residual!(R, uf, Ke_ff, Kg_ff, Ff, free_global_dof, ke_local, uniform_load, local_fixed_end_forces, properties, node) # num_dof = length(node.numbers) * 6 # u = zeros(Float64, num_dof) # u[free_global_dof] = uf # Kg_ff = update_Kg(element, properties, ke_local, uniform_load, local_fixed_end_forces, u) # print(Ke_ff) # print(" ") Kff = Ke_ff + Kg_ff for i in eachindex(Ff) R[i] = transpose(Kff[i,:]) * uf - Ff[i] end return R end function update_Kg(element, properties, ke_local, uniform_load, local_fixed_end_forces, u) Γ = update_rotation_angles(node, element, properties, u) properties.Γ = deepcopy(Γ) # properties.Γ = [0.0] P1 = InstantFrame.calculate_element_internal_forces(properties, ke_local, element, uniform_load, local_fixed_end_forces, u) P1_axial = [P1[i][7] for i in eachindex(P1)] # P1_axial = [-50.0] kg_local = [InstantFrame.define_local_geometric_stiffness_matrix(P1_axial[i], properties.L[i]) for i in eachindex(properties.L)] kg_global = [Γ[i]'*kg_local[i]*Γ[i] for i in eachindex(properties.L)] Kg = InstantFrame.assemble_global_matrix(kg_global, properties.global_dof) Kg_ff = Kg[free_global_dof, free_global_dof] print(P1_axial) print(" ") return Kg_ff end function update_rotation_angles(node, element, properties, u) num_elem = length(properties.L) Γ = Array{Array{Float64, 2}}(undef, num_elem) rotation_angles = Array{NamedTuple{(:Y, :Z, :X), NTuple{3, Float64}}}(undef, num_elem) nodal_displacements = InstantFrame.define_nodal_displacements(node, u) node_i = collect(node.coordinates[1]) for i in eachindex(element.numbers) #nodal coordinates node_i_index = findfirst(node_num->node_num == element.nodes[i][1], node.numbers) node_j_index = findfirst(node_num->node_num == element.nodes[i][2], node.numbers) node_i = collect(node.coordinates[node_i_index]) + nodal_displacements[node_i_index][1:3] #update geometry node_j = collect(node.coordinates[node_j_index]) + nodal_displacements[node_j_index][1:3] #update geometry #rotation matrix Γ[i], rotation_angles[i] = InstantFrame.define_rotation_matrix(node_i, node_j, element.orientation[i]) # print(Γ[i]) # print(" ") end return rotation_angles, Γ end ############################## ##tests #deflection isapprox(model.solution.nodal_displacements[2][3], 4.597, rtol=0.05) #cantilever moment isapprox(model.solution.element_forces[1][5], 409.8, rtol=0.08) #tolerance is a little loose here α = 1/50 L = 180.0 P = 50.0 E = 29000.0 I = 37.1 Δ = α*L * (tan(sqrt(P/(E*I))*L)/(sqrt(P/(E*I))*L) - 1)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
933
using InstantFrame I = 0.55967 L = 48.0 E = 29000000.0 k1 = 230000.0 k2 = Inf ke_left_spring = InstantFrame.define_local_elastic_element_stiffness_matrix_partially_restrained(I, E, L, k1, k2) using InstantFrame I = 0.55967 L = 48.0 E = 29000000.0 k1 = Inf k2 = 230000.0 ke_right_spring = InstantFrame.define_local_elastic_element_stiffness_matrix_partially_restrained(I, E, L, k1, k2) I = 0.55967 L = 48.0 E = 29000000.0 k1 = 230000.0 k2 = 230000.0 * 10^30 α1 = k1/(E*I/L) #start node α2 = k2/(E*I/L) #end node Kbb = E*I/L* [4 + α1 2 2 4+α2] Kbc = E*I/L * [6/L -α1 -6/L 0.0 6/L 0 -6/L -α2] Kcb = Kbc' Kcc = E*I/L * [12/L^2 0 -12/L^2 0 0 α1 0 0 -12/L^2 0 12/L^2 0 0 0 0 α2 ] Kcc_hat = Kcc - Kcb*Kbb^-1*Kbc α = (α1*α2)/(α1*α2 + 4*α1 + 4*α2 + 12) k34 = α*E*I/L * (-6/L * (1 + 2/α1)) k44 = α*E*I/L * 4 * (1 + 3/α1)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1960
using InstantFrame #McGuire et. al(2000) Example 4.8 material = InstantFrame.Material(names=["steel"], E=[200.0], ν=[0.3], ρ=[8000/1000^3]) #ρ = kg/mm^3 cross_section = InstantFrame.CrossSection(names=["beam ab", "beam bc"], A=[6E3, 4E3], Iy=[700E6, 540E6], Iz=[200E6, 50E6], J=[300E3, 100E3]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (8000.0, 0.0, 0.0), (13000.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0], connections=[("rigid", "rigid"), ("rigid", "rigid")], cross_section=["beam ab", "beam bc"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 2, 3], stiffness=(uX=[Inf,0.0, 0.0], uY=[Inf,Inf,0.0], uZ=[Inf,Inf,0.0], rX=[Inf,Inf,Inf], rY=[Inf,Inf,0.0], rZ=[Inf,0.0,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1, 2], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[3], loads=(FX=[5cos(-π/4)], FY=[5sin(-π/4)], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") # dof=[1, 2, 4, 6, 7, 8, 10, 12] # model.equations.ke_local[2][dof, dof] ./ 200 ##tests #deflections and rotations isapprox(model.solution.u1[7], 0.024, rtol=0.05) isapprox(model.solution.u1[13], 0.046, rtol=0.05) isapprox(model.solution.u1[12], -0.00088, rtol=0.05) isapprox(model.solution.u1[18], -0.00530, rtol=0.05) isapprox(model.solution.u1[14], -19.15, rtol=0.05) scale = (1.0, 1.0, 1.0) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1815
using InstantFrame #Sennett Example 3.1 - fixed-fixed beam with two elements, 2D material = InstantFrame.Material(names=["steel"], E=[10^7], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[1.0], Iz=[1.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (2.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0], connections=[("rigid", "rigid"), ("rigid", "rigid")], cross_section=["beam", "beam"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 3], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1, 2], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[-1.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") scale = (1.0, 1.0, 1.0) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale) ##tests P = point_load.loads.FY[1] #deflections model.solution.u1[8]≈P/24E7 #midspan deflection model.solution.u1[12]≈0.0 #midspan rotation #internal forces dof = [2, 6, 8, 12] model.solution.P1[1][dof] == [-P/2,-P/4, P/2, -P/4] model.solution.P1[2][dof] == [P/2,P/4, -P/2, P/4]
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
2021
using InstantFrame #Sennett Example 7.4 - portal frame with corner hinge, 2D, 1st order material = InstantFrame.Material(names=["steel"], E=[29E6], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[10.0], Iy=[100.0], Iz=[100.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "hinge"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2, 3, 4], coordinates=[(0.0, 0.0, 0.0), (0.0, 120.0, 0.0), (120.0, 120.0, 0.0), (120.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2, 3], nodes=[(1,2), (2,3), (3, 4)], orientation=[0.0, 0.0, 0.0], connections=[("rigid", "rigid"), ("hinge", "rigid"), ("rigid", "rigid")], cross_section=["beam", "beam", "beam"], material=["steel", "steel", "steel"]) support = InstantFrame.Support(nodes=[1, 2, 3, 4], stiffness=(uX=[Inf,0.0,0.0,Inf], uY=[Inf,0.0,0.0,Inf], uZ=[Inf,Inf, Inf,Inf], rX=[Inf,Inf, Inf, Inf], rY=[Inf,Inf, Inf,Inf], rZ=[0.0,0.0, 0.0, 0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1, 2], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[1000.0], FY=[0.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") scale = (30.0, 30.0, 30.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.nodal_displacements, element, node, model.properties, scale) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.nodal_displacements, model.solution.element_connections, element, node, model.properties, scale) ##tests #rotation at hinge isapprox(model.solution.element_connections.end_displacements[1][6], 0.0008, rtol=0.05) #hinge rotation using Sennett Eq. 7.33
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
3631
using InstantFrame #Sennett Example 7.2 #Elastic support at the center of a fixed-fixed beam material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[8.0], Iy=[100.0], Iz=[100.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) beam_span = 240.0 x = range(0.0, beam_span, 3) coordinates = [(x[i], 0.0, 0.0) for i in eachindex(x)] node = InstantFrame.Node(numbers=1:length(x), coordinates=coordinates) num_elem = length(x)-1 element_connectivity = [(i, i+1) for i=1:num_elem] element = InstantFrame.Element(numbers=1:length(element_connectivity), nodes=element_connectivity, orientation=zeros(Float64, length(element_connectivity)), connections=[("rigid", "rigid") for i in eachindex(element_connectivity)], cross_section=["beam" for i in eachindex(element_connectivity)], material=["steel" for i in eachindex(element_connectivity)]) support = InstantFrame.Support(nodes=[1, 2, length(x)], stiffness=(uX=[Inf, 0.0, Inf], uY=[Inf,20000.0,Inf], uZ=[Inf,0.0,Inf], rX=[Inf,0.0,Inf], rY=[Inf,0.0,Inf], rZ=[Inf,0.0,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[2], loads=(qX=zeros(Float64, 1), qY=ones(Float64, 1)*-1000.0/12, qZ=zeros(Float64, 1), mX=zeros(Float64, 1), mY=zeros(Float64, 1), mZ=zeros(Float64, 1))) point_load = InstantFrame.PointLoad(nothing) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") ###### Ke_sf = model.equations.Ke[model.equations.fixed_dof, model.equations.free_dof] R = Ke_sf * model.solution.uf nodal_displacements = Array{Array{Float64, 1}}(undef, length(node.numbers)) num_dof_per_node = 6 #hard code this for now for i in eachindex(node.numbers) nodal_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (i-1) nodal_displacements[i] = u[nodal_dof] end #####test isapprox(model.solution.nodal_displacements[2][3], -0.082949, rtol=0.01) isapprox(model.solution.nodal_displacements[2][5], 0.000517, rtol=0.01) #sign is different here than Sennett, incorrect in Sennett? ###### element_nodal_coords = InstantFrame.UI.define_element_nodal_start_end_coordinates(element, node) X, Y, Z = InstantFrame.UI.get_node_XYZ(node) X_range = abs(maximum(X) - minimum(X)) Y_range = abs(maximum(Y) - minimum(Y)) Z_range = abs(maximum(Z) - minimum(Z)) Y_range = 100.0 Z_range = 100.0 using GLMakie, LinearAlgebra figure = Figure() ax = Axis3(figure[1,1]) ax.aspect = (1.0, Y_range/X_range, Z_range/X_range) ax.yticks = WilkinsonTicks(2) ylims!(ax, -50.0, 50.0) zlims!(ax, -50.0, 50.0) color = :gray InstantFrame.UI.show_elements!(ax, element_nodal_coords, color) figure markersize = 10 color = :blue InstantFrame.UI.show_nodes!(ax, X, Y, Z, markersize, color) figure unit_arrow_head_size = [1.0, 1.0, 1.0] arrow_head_scale = 3.0 arrow_scale = 10.0 linewidth = 1.0 arrowcolor = :green linecolor = :green InstantFrame.UI.show_uniform_loads!(ax, uniform_load, element, node, unit_arrow_head_size, arrow_head_scale, arrow_scale, linewidth, arrowcolor, linecolor) figure ####plot deformed shape n = vec(ones(Int64, size(model.properties.L, 1)) * 11) scale = (100.0, 100.0, 100.0) linecolor = :pink InstantFrame.UI.show_deformed_shape!(ax, model.solution.nodal_displacements, model.properties.global_dof, element, node, model.properties, model.solution.element_connections, n, scale, linecolor) figure
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
4259
using InstantFrame #Sennett Example 7.2 #Elastic support at the center of a fixed-fixed beam material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[8.0], Iy=[100.0], Iz=[100.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) beam_span = 240.0 x = range(0.0, beam_span, 3) coordinates = [(x[i], 0.0, 0.0) for i in eachindex(x)] node = InstantFrame.Node(numbers=1:length(x), coordinates=coordinates) num_elem = length(x)-1 element_connectivity = [(i, i+1) for i=1:num_elem] element = InstantFrame.Element(numbers=1:length(element_connectivity), nodes=element_connectivity, orientation=zeros(Float64, length(element_connectivity)), connections=[("rigid", "rigid") for i in eachindex(element_connectivity)], cross_section=["beam" for i in eachindex(element_connectivity)], material=["steel" for i in eachindex(element_connectivity)]) support = InstantFrame.Support(nodes=[1, 2, length(x)], stiffness=(uX=[Inf, 0.0, Inf], uY=[Inf,0.0,Inf], uZ=[Inf,0.0,Inf], rX=[Inf,0.0,Inf], rY=[Inf,0.0,Inf], rZ=[Inf,0.0,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1,2], loads=(qX=zeros(Float64, 2), qY=zeros(Float64, 2), qZ=ones(Float64, 2)*-1000.0/12, mX=zeros(Float64, 2), mY=zeros(Float64, 2), mZ=zeros(Float64, 2))) point_load = InstantFrame.PointLoad(nothing) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") ###### Ke_sf = model.equations.Ke[model.equations.fixed_dof, model.equations.free_dof] R = Ke_sf * model.solution.uf reactions = zeros(Float64, length(node.numbers)*6) reactions[model.equations.fixed_dof] = R elastic_support_reactions = -model.solution.u[model.equations.elastic_supports.global_dof] .* model.equations.elastic_supports.global_stiffness reactions[model.equations.elastic_supports.global_dof] = elastic_support_reactions #add point loads to reactions reactions[model.equations.fixed_dof] += -model.forces.global_dof_point_loads[model.equations.fixed_dof] #add uniform load equivalent nodal forces to reactions reactions[model.equations.fixed_dof] += -model.forces.global_dof_nodal_forces_uniform_load[model.equations.fixed_dof] nodal_reactions = Array{Array{Float64, 1}}(undef, length(support.nodes)) num_dof_per_node = 6 #hard code this for now for i in eachindex(support.nodes) nodal_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (support.nodes[i]-1) nodal_reactions[i] = reactions[nodal_dof] end #####test isapprox(model.solution.nodal_displacements[2][3], -0.082949, rtol=0.01) isapprox(model.solution.nodal_displacements[2][5], 0.000517, rtol=0.01) #sign is different here than Sennett, incorrect in Sennett? ###### element_nodal_coords = InstantFrame.UI.define_element_nodal_start_end_coordinates(element, node) X, Y, Z = InstantFrame.UI.get_node_XYZ(node) X_range = abs(maximum(X) - minimum(X)) Y_range = abs(maximum(Y) - minimum(Y)) Z_range = abs(maximum(Z) - minimum(Z)) Y_range = 100.0 Z_range = 100.0 using GLMakie, LinearAlgebra figure = Figure() ax = Axis3(figure[1,1]) ax.aspect = (1.0, Y_range/X_range, Z_range/X_range) ax.yticks = WilkinsonTicks(2) ylims!(ax, -50.0, 50.0) zlims!(ax, -50.0, 50.0) color = :gray InstantFrame.UI.show_elements!(ax, element_nodal_coords, color) figure markersize = 10 color = :blue InstantFrame.UI.show_nodes!(ax, X, Y, Z, markersize, color) figure unit_arrow_head_size = [1.0, 1.0, 1.0] arrow_head_scale = 3.0 arrow_scale = 10.0 linewidth = 1.0 arrowcolor = :green linecolor = :green InstantFrame.UI.show_uniform_loads!(ax, uniform_load, element, node, unit_arrow_head_size, arrow_head_scale, arrow_scale, linewidth, arrowcolor, linecolor) figure ####plot deformed shape n = vec(ones(Int64, size(model.properties.L, 1)) * 11) scale = (100.0, 100.0, 100.0) linecolor = :pink InstantFrame.UI.show_deformed_shape!(ax, model.solution.nodal_displacements, model.properties.global_dof, element, node, model.properties, model.solution.element_connections, n, scale, linecolor) figure
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1911
using InstantFrame #Apply a point torsion at midspan of a beam that is twist fixed. The beam is discretized with two elements. The first element has a torsion release at its right end (midspan). material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[1.0], Iz=[1.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, 0.0], ry=[Inf, Inf], rz=[Inf, Inf])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (12.0, 0.0, 0.0), (24.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0, 0.0], connections=[("rigid", "end release"), ("rigid", "rigid")], cross_section=["beam", "beam"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 3], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,Inf])) # uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], loads=(qX=[0.0], qY=[10.0], qZ=[0.0], mX=[0.0], mY=[0.0], mZ=[0.0])) uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[0.0], FZ=[0.0], MX=[1000.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") ##test #Twist at the right end of the first element should be zero. isapprox(model.solution.element_connections.end_displacements[1][4], 0.0, atol=0.0001) #Twist at the left end of the second element should be Θ = TL/GJ where L=12.0 in. isapprox(model.solution.nodal_displacements[2][4], (1000.0*12.0)/(model.properties.G[1]*model.properties.J[1]), rtol=0.01)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
2243
using InstantFrame, LinearAlgebra #McGuire et. al(2000) Example 4.9 with end release at point 'a'. material = InstantFrame.Material(names=["steel"], E=[200.0], ν=[0.3], ρ=[8000/1000^3]) #ρ = kg/mm^3 cross_section = InstantFrame.CrossSection(names=["beam ab", "beam bc"], A=[6E3, 4E3], Iy=[700E6, 540E6], Iz=[200E6, 50E6], J=[300E3, 100E3]) connection = InstantFrame.Connection(names=["rigid", "hinge"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (8000.0, 0.0, 0.0), (13000.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0], connections=[("hinge", "rigid"), ("rigid", "rigid")], cross_section=["beam ab", "beam bc"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 2, 3], stiffness=(uX=[Inf,0.0, 0.0], uY=[Inf,Inf,0.0], uZ=[Inf,Inf,Inf], rX=[Inf,Inf,Inf], rY=[Inf,Inf,Inf], rZ=[Inf,0.0,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1, 2], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[3], loads=(FX=[5cos(-π/4)], FY=[5sin(-π/4)], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") scale = (30.0, 30.0, 30.0) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.nodal_displacements, model.solution.element_connections, element, node, model.properties, scale) ##tests #element local stiffness matrix with hinge #Use Sennett Eq. 7.39 E = model.properties.E[1] I = model.properties.Iz[1] L = model.properties.L[1] ke = zeros(Float64, 4, 4) #define upper triangular portion of stiffness matrix with Eq. 7.39 ke[1, 1] = 3*E*I/L^3 ke[1, 2] = 0.0 ke[1, 3] = -3*E*I/L^3 ke[1, 4] = 3*E*I/L^2 ke[2, 2] = 0.0 ke[2, 3] = 0.0 ke[2, 4] = 0.0 ke[3, 3] = 3*E*I/L^3 ke[3, 4] = -3*E*I/L^2 ke[4, 4] = 3*E*I/L #compare to local stiffness matrix from model dof = [2, 6, 8, 12] isapprox(triu(ke), triu(model.equations.ke_local[1])[dof, dof])
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
2505
using InstantFrame, LinearAlgebra #McGuire et. al(2000) Example 4.9 with partial restraint in member ab, b side. material = InstantFrame.Material(names=["steel"], E=[200.0], ν=[0.3], ρ=[8000/1000^3]) #ρ = kg/mm^3 cross_section = InstantFrame.CrossSection(names=["beam ab", "beam bc"], A=[6E3, 4E3], Iy=[700E6, 540E6], Iz=[200E6, 50E6], J=[300E3, 100E3]) connection = InstantFrame.Connection(names=["rigid", "partial restraint"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 1.0])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (8000.0, 0.0, 0.0), (13000.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0], connections=[("rigid", "partial restraint"), ("rigid", "rigid")], cross_section=["beam ab", "beam bc"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 2, 3], stiffness=(uX=[Inf,0.0, 0.0], uY=[Inf,Inf,0.0], uZ=[Inf,Inf,Inf], rX=[Inf,Inf,Inf], rY=[Inf,Inf,Inf], rZ=[Inf,0.0,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1, 2], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[3], loads=(FX=[5cos(-π/4)], FY=[5sin(-π/4)], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") scale = (30.0, 30.0, 30.0) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.nodal_displacements, model.solution.element_connections, element, node, model.properties, scale) ##tests #element local stiffness matrix with partial restrained connection #Use McGuire et al. (2000) Eq. 13.31 E = model.properties.E[1] I = model.properties.Iz[1] L = model.properties.L[1] k1 = E*I*10E20 k2 = connection.stiffness.rz[2] α1 = k1/(E*I/L) #start node α2 = k2*(E*I/L) #end node α = (α1*α2)/(α1*α2 + 4*α1 + 4*α2 + 12) ke = zeros(Float64, 4, 4) ke[1,1] = 12/L^2*(1 + (α1+α2)/(α1*α2)) ke[1,2] = 6/L * (1+2/α2) ke[1,3] = -12/L^2*(1+(α1+α2)/(α1*α2)) ke[1,4] = 6/L*(1+2/α1) ke[2,2] = 4*(1+3/α2) ke[2,3] = -6/L*(1+2/α2) ke[2,4] = 2 ke[3,3] = 12/L^2*(1+(α1+α2)/(α1*α2)) ke[3,4] = -6/L*(1+2/α1) ke[4,4] = 4*(1+3/α1) ke = α * (E * I / L) .* ke #compare to local stiffness matrix from model dof = [2, 6, 8, 12] isapprox(triu(ke), triu(model.equations.ke_local[1])[dof, dof])
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
3077
using InstantFrame #Apply a uniform load to a fixed-fixed beam. #Discretize it with 2 elements. material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[1.0], Iz=[1.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 0.0])) beam_span = 120.0 x = range(0.0, beam_span, 9) coordinates = [(x[i], 0.0, 0.0) for i in eachindex(x)] node = InstantFrame.Node(numbers=1:length(x), coordinates=coordinates) num_elem = length(x)-1 element_connectivity = [(i, i+1) for i=1:num_elem] element = InstantFrame.Element(numbers=1:length(element_connectivity), nodes=element_connectivity, orientation=zeros(Float64, length(element_connectivity)), connections=[("rigid", "rigid") for i in eachindex(element_connectivity)], cross_section=["beam" for i in eachindex(element_connectivity)], material=["steel" for i in eachindex(element_connectivity)]) support = InstantFrame.Support(nodes=[1, length(x)], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=1:num_elem, loads=(qX=zeros(Float64, num_elem), qY=ones(Float64, num_elem)*10.0, qZ=zeros(Float64, num_elem), mX=zeros(Float64, num_elem), mY=zeros(Float64, num_elem), mZ=zeros(Float64, num_elem))) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[0.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") scale = (1000.0, 1000.0, 1000.0) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.nodal_displacements, model.solution.element_connections, element, node, model.properties, scale) ##test #Calculate deflection at the center of the beam. wY = uniform_load.loads.qY[1] L = sum(model.properties.L) E = material.E[1] Iz = cross_section.Iz[1] Δ_midspan = wY*L^4/(384*E*Iz) #midspan beam deflection Δ_midspan ≈ model.solution.nodal_displacements[Int(num_elem/2)+1][2] elem_num = 1 start_node = element.nodes[elem_num][1] end_node = element.nodes[elem_num][2] element_global_disp = [model.solution.nodal_displacements[start_node]; model.solution.nodal_displacements[end_node]] element_local_disp = model.properties.Γ[elem_num] * element_global_disp #local x-z plane q1 = element_local_disp[2] q2 = element_local_disp[6] q3 = element_local_disp[8] q4 = element_local_disp[12] L = model.properties.L[elem_num] E = material.E[1] I = cross_section.Iz[1] x = range(0.0, L, 5) function calculate_local_element_moment(q1, q2, q3, q4, L, x, E, I) a2 = 1/L^2*(-3*q1-2*q2*L+3*q3-q4*L) a3 = 1/L^3*(2*q1+q2*L-2*q3+q4*L) w_xx = 2*a2 + 6*a3*x M = E * I * w_xx return M end M = calculate_local_element_moment.(q1, q2, q3, q4, L, x, E, I)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
3226
using InstantFrame #Apply a point load to a fixed-fixed beam with partial restraint (rotational springs) at each end. #Discretize it with 2 elements. material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[0.627], Iz=[0.55967], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "PR"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 230000.0])) beam_span = 96.0 x = range(0.0, beam_span, 3) coordinates = [(x[i], 0.0, 0.0) for i in eachindex(x)] node = InstantFrame.Node(numbers=1:length(x), coordinates=coordinates) num_elem = length(x)-1 element_connectivity = [(i, i+1) for i=1:num_elem] element = InstantFrame.Element(numbers=1:length(element_connectivity), nodes=element_connectivity, orientation=zeros(Float64, length(element_connectivity)), connections=[("PR", "rigid"), ("rigid", "PR")], cross_section=["beam" for i in eachindex(element_connectivity)], material=["steel" for i in eachindex(element_connectivity)]) support = InstantFrame.Support(nodes=[1, length(x)], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,Inf])) # uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=1:num_elem, loads=(qX=zeros(Float64, num_elem), qY=ones(Float64, num_elem)*10.0, qZ=zeros(Float64, num_elem), mX=zeros(Float64, num_elem), mY=zeros(Float64, num_elem), mZ=zeros(Float64, num_elem))) uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[-1000.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") # scale = (1000.0, 1000.0, 1000.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.nodal_displacements, model.solution.element_connections, element, node, model.properties, scale) # ##test # #Calculate deflection at the center of the beam. # wY = uniform_load.loads.qY[1] # L = sum(model.properties.L) # E = material.E[1] # Iz = cross_section.Iz[1] # Δ_midspan = wY*L^4/(384*E*Iz) # #midspan beam deflection # Δ_midspan ≈ model.solution.nodal_displacements[Int(num_elem/2)+1][2] # elem_num = 1 # start_node = element.nodes[elem_num][1] # end_node = element.nodes[elem_num][2] # element_global_disp = [model.solution.nodal_displacements[start_node]; model.solution.nodal_displacements[end_node]] # element_local_disp = model.properties.Γ[elem_num] * element_global_disp # #local x-z plane # q1 = element_local_disp[2] # q2 = element_local_disp[6] # q3 = element_local_disp[8] # q4 = element_local_disp[12] # L = model.properties.L[elem_num] # E = material.E[1] # I = cross_section.Iz[1] # x = range(0.0, L, 5) # function calculate_local_element_moment(q1, q2, q3, q4, L, x, E, I) # a2 = 1/L^2*(-3*q1-2*q2*L+3*q3-q4*L) # a3 = 1/L^3*(2*q1+q2*L-2*q3+q4*L) # w_xx = 2*a2 + 6*a3*x # M = E * I * w_xx # return M # end # M = calculate_local_element_moment.(q1, q2, q3, q4, L, x, E, I)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
4143
using InstantFrame #Apply a point load to a fixed-fixed beam with partial restraint (rotational springs) at each end. #Discretize it with 2 elements. material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[0.627], Iz=[0.55967], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "PR"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 230000.0])) beam_span = 96.0 x = range(0.0, beam_span, 3) coordinates = [(x[i], 0.0, 0.0) for i in eachindex(x)] node = InstantFrame.Node(numbers=1:length(x), coordinates=coordinates) num_elem = length(x)-1 element_connectivity = [(i, i+1) for i=1:num_elem] element = InstantFrame.Element(numbers=1:length(element_connectivity), nodes=element_connectivity, orientation=zeros(Float64, length(element_connectivity)), connections=[("PR", "rigid"), ("rigid", "PR")], cross_section=["beam" for i in eachindex(element_connectivity)], material=["steel" for i in eachindex(element_connectivity)]) support = InstantFrame.Support(nodes=[1, length(x)], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,Inf])) # uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=1:num_elem, loads=(qX=zeros(Float64, num_elem), qY=ones(Float64, num_elem)*10.0, qZ=zeros(Float64, num_elem), mX=zeros(Float64, num_elem), mY=zeros(Float64, num_elem), mZ=zeros(Float64, num_elem))) uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[-1000.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") element_nodal_coords = InstantFrame.UI.define_element_nodal_start_end_coordinates(element, node) X, Y, Z = InstantFrame.UI.get_node_XYZ(node) X_range = abs(maximum(X) - minimum(X)) Y_range = abs(maximum(Y) - minimum(Y)) Z_range = abs(maximum(Z) - minimum(Z)) using GLMakie, LinearAlgebra figure = Figure() ax = Axis3(figure[1,1]) ax.aspect = (1.0, 1.0, 1.0) ax.yticks = WilkinsonTicks(2) # ylims!(ax, 0.0, 10.0) color = :gray InstantFrame.UI.show_elements!(ax, element_nodal_coords, color) figure markersize = 1000 color = :blue InstantFrame.UI.show_nodes!(ax, X, Y, Z, markersize, color) figure unit_arrow_head_size = [1.0, 1.0, 1.0] arrow_head_scale = 0.01 arrow_scale = 5.0 arrowcolor = :orange linecolor = :orange linewidth = 0.01 InstantFrame.UI.show_element_local_y_axis!(ax, element, node, model, unit_arrow_head_size, arrow_head_scale, arrow_scale, arrowcolor, linecolor, linewidth) figure # scale = (1000.0, 1000.0, 1000.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.nodal_displacements, model.solution.element_connections, element, node, model.properties, scale) # ##test # #Calculate deflection at the center of the beam. # wY = uniform_load.loads.qY[1] # L = sum(model.properties.L) # E = material.E[1] # Iz = cross_section.Iz[1] # Δ_midspan = wY*L^4/(384*E*Iz) # #midspan beam deflection # Δ_midspan ≈ model.solution.nodal_displacements[Int(num_elem/2)+1][2] # elem_num = 1 # start_node = element.nodes[elem_num][1] # end_node = element.nodes[elem_num][2] # element_global_disp = [model.solution.nodal_displacements[start_node]; model.solution.nodal_displacements[end_node]] # element_local_disp = model.properties.Γ[elem_num] * element_global_disp # #local x-z plane # q1 = element_local_disp[2] # q2 = element_local_disp[6] # q3 = element_local_disp[8] # q4 = element_local_disp[12] # L = model.properties.L[elem_num] # E = material.E[1] # I = cross_section.Iz[1] # x = range(0.0, L, 5) # function calculate_local_element_moment(q1, q2, q3, q4, L, x, E, I) # a2 = 1/L^2*(-3*q1-2*q2*L+3*q3-q4*L) # a3 = 1/L^3*(2*q1+q2*L-2*q3+q4*L) # w_xx = 2*a2 + 6*a3*x # M = E * I * w_xx # return M # end # M = calculate_local_element_moment.(q1, q2, q3, q4, L, x, E, I)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
3255
using InstantFrame #Apply a point load to a fixed-fixed beam with partial restraint (rotational springs) at each end. #Discretize it with 2 elements. material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[0.627], Iz=[0.627], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "PR"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 230000.0])) beam_span = 96.0 x = range(0.0, beam_span, 3) coordinates = [(x[i], 0.0, 0.0) for i in eachindex(x)] node = InstantFrame.Node(numbers=1:length(x), coordinates=coordinates) num_elem = length(x)-1 element_connectivity = [(i, i+1) for i=1:num_elem] element = InstantFrame.Element(numbers=1:length(element_connectivity), nodes=element_connectivity, orientation=zeros(Float64, length(element_connectivity)), connections=[("PR", "rigid"), ("rigid", "PR")], cross_section=["beam" for i in eachindex(element_connectivity)], material=["steel" for i in eachindex(element_connectivity)]) support = InstantFrame.Support(nodes=[1, length(x)], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,Inf])) # uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=1:num_elem, loads=(qX=zeros(Float64, num_elem), qY=ones(Float64, num_elem)*10.0, qZ=zeros(Float64, num_elem), mX=zeros(Float64, num_elem), mY=zeros(Float64, num_elem), mZ=zeros(Float64, num_elem))) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1,2], loads=(qX=[0.0, 0.0], qY=[-12.5, -12.5], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(nothing) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") # scale = (1000.0, 1000.0, 1000.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.nodal_displacements, model.solution.element_connections, element, node, model.properties, scale) # ##test # #Calculate deflection at the center of the beam. # wY = uniform_load.loads.qY[1] # L = sum(model.properties.L) # E = material.E[1] # Iz = cross_section.Iz[1] # Δ_midspan = wY*L^4/(384*E*Iz) # #midspan beam deflection # Δ_midspan ≈ model.solution.nodal_displacements[Int(num_elem/2)+1][2] # elem_num = 1 # start_node = element.nodes[elem_num][1] # end_node = element.nodes[elem_num][2] # element_global_disp = [model.solution.nodal_displacements[start_node]; model.solution.nodal_displacements[end_node]] # element_local_disp = model.properties.Γ[elem_num] * element_global_disp # #local x-z plane # q1 = element_local_disp[2] # q2 = element_local_disp[6] # q3 = element_local_disp[8] # q4 = element_local_disp[12] # L = model.properties.L[elem_num] # E = material.E[1] # I = cross_section.Iz[1] # x = range(0.0, L, 5) # function calculate_local_element_moment(q1, q2, q3, q4, L, x, E, I) # a2 = 1/L^2*(-3*q1-2*q2*L+3*q3-q4*L) # a3 = 1/L^3*(2*q1+q2*L-2*q3+q4*L) # w_xx = 2*a2 + 6*a3*x # M = E * I * w_xx # return M # end # M = calculate_local_element_moment.(q1, q2, q3, q4, L, x, E, I)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
283
using NonlinearSolve p = 2.0 function residual(u, p) p = 1.0*u u .* u .- 2.0*p end u0 = 1.5 probB = NonlinearProblem(f, u0, p) cache = init(probB, NewtonRaphson()); # Can iterate the solver object solver = solve!(cache) step!(cache) for i in take(cache,3) end
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1850
using InstantFrame #Fixed-fixed beam, 2D, two elements, point load at midspan material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[1.0], Iz=[1.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (60.0, 0.0, 0.0), (120.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0], connections=[("rigid", "rigid"), ("rigid", "rigid")], cross_section=["beam", "beam"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 3], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1, 2], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[100.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") #classical equation, midspan deflection P = point_load.loads.FY[1] L = sum(model.properties.L) E = material.E[1] I = cross_section.Iz[1] Δ = P*L^3/(192*E*I) #test isapprox(model.solution.u1[8], Δ, rtol=0.20) #rtol is high here, maybe more elements are needed scale = (1.0, 1.0, 1.0) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1850
using InstantFrame #Fixed-fixed beam, 2D, two elements, point load at midspan material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[1.0], Iz=[1.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (60.0, 0.0, 0.0), (120.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0], connections=[("rigid", "rigid"), ("rigid", "rigid")], cross_section=["beam", "beam"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 3], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[0.0,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1, 2], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[100.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") #classical equation, midspan deflection P = point_load.loads.FY[1] L = sum(model.properties.L) E = material.E[1] I = cross_section.Iz[1] Δ = P*L^3/(192*E*I) #test isapprox(model.solution.u1[8], Δ, rtol=0.20) #rtol is high here, maybe more elements are needed scale = (1.0, 1.0, 1.0) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1704
using InstantFrame material = InstantFrame.Material(names=["steel"], E=[29500.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000]) ##ρ = kips * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["top chord", "bottom chord", "post"], A=[1.0, 2.0, 3.0], Iy=[3.1, 4.2, 2.3], Iz= [2.4, 6.5, 4.6], J=[0.001, 0.002, 0.005]) connection = InstantFrame.Connection(names=["rigid", "pinned"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, 0.0], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2, 3, 4], coordinates=[(0.0, 0.0, 0.0), (300.0, 0.0, 0.0), (600.0, 0.0, 0.0), (300.0, -30.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2, 3, 4, 5], nodes = [(1,2), (2,3), (1,4), (3,4), (2,4)], orientation = [0.0, 0.0, 0.0, 0.0, 0.0], connections=[("rigid", "rigid"), ("rigid", "rigid"), ("pinned", "pinned"), ("pinned", "pinned"), ("rigid", "pinned")], cross_section= ["top chord", "top chord", "bottom chord", "bottom chord", "post"], material = ["steel", "steel", "steel", "steel", "steel"], types=["frame", "frame", "frame", "frame", "frame"]) support = InstantFrame.Support(nodes=[1, 3], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[0.0,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["snow", "snow"], elements=[1, 2], magnitudes=(qX=[0.0, 0.0], qY=[-0.100, -0.100], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["lights"], nodes=[4], magnitudes=(FX=[0.0], FY=[-0.500], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type="first order")
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
2386
using InstantFrame, LinearAlgebra #McGuire et al. (2000) Example 5.5 material = InstantFrame.Material(names=["steel"], E=[200.0], ν=[0.3], ρ=[8000/1000^3]) #ρ = kg/mm^3 cross_section = InstantFrame.CrossSection(names=["beam ab"], A=[6E3], Iy=[700E6], Iz=[200E6], J=[300E3]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (10.0, 5.0, 3.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[π/6], connections=[("rigid", "rigid")], cross_section=["beam ab"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], loads=(qX=[0.0], qY=[0.0], qZ=[0.0], mX=[0.0], mY=[0.0], mZ=[0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[5cos(-π/4)], FY=[5sin(-π/4)], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") ##test #compare MGZ rotation matrix from Eq. 5.7 to model. γ_MGZ = [0.8638 0.4319 0.2591 -0.5019 0.7811 0.3714 -0.0420 -0.4510 0.8915] Γ_MGZ = zeros(Float64, 12, 12) Γ_MGZ[1:3, 1:3] = γ_MGZ Γ_MGZ[4:6, 4:6] = γ_MGZ Γ_MGZ[7:9, 7:9] = γ_MGZ Γ_MGZ[10:12, 10:12] = γ_MGZ isapprox(Γ_MGZ, model.properties.Γ[1], rtol=0.01) A = [0.0, 0.0, 0.0] B = [10.0, 5.0, 3.0] β = 0.0 # AB = B - A # ΔX = AB[1] # ΔZ = AB[3] # ΔY = AB[2] # ρ = atan(-ΔZ, ΔX) # rad2deg(ρ) # proj_AB_xz = sqrt(ΔX^2 + ΔZ^2) # χ = atan(ΔY, proj_AB_xz) # rad2deg(χ) # current_local_y_axis = RotZ(-χ) * RotY(-ρ) * [0.0, 1.0, 0.0] #where y-local is pointing after Y and Z rotations # ω = acos(dot(current_local_y_axis, [0.0, 1.0, 0.0])/ norm(current_local_y_axis)) # rad2deg(ω) AB = B - A ΔX = AB[1] ΔZ = AB[3] ΔY = AB[2] ρ = atan(-ΔZ, ΔX) proj_AB_xz = sqrt(ΔX^2 + ΔZ^2) χ = atan(ΔY, proj_AB_xz) RotY(ρ)' RotZ(χ)' RotX(π/2 - π/3)' RotYZX(ρ, χ, π/2 - π/3)' ω = β x_axis = RotYZX(ρ, χ, ω) * [1.0, 0.0, 0.0] y_axis = RotYZX(ρ, χ, ω) * [0.0, 1.0, 0.0] z_axis = RotYZX(ρ, χ, ω) * [0.0, 0.0, 1.0] RotYZX(ρ, χ, ω)' * [1.0, 0.0, 0.0]
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
2899
using LinearAlgebra, Rotations #Sennett Example 6.4 function rotation_matrix(A, B, β) AB = B - A # A_prime = [A[1], A[2]+1.0, A[3]] # AA_prime = A_prime - A # AK = RotX(β) * AA_prime # AK = K - A x_cosines = AB/norm(AB) # AK = A + x_cosines * norm(AB)/2 + [0.0, 1.0, 0.0] AK = x_cosines * norm(AB)/2 + RotX(-β) * [0.0, 1.0, 0.0] z_cosines = cross(AB, AK) / norm(cross(AB, AK)) y_cosines = cross(z_cosines, x_cosines)/norm(cross(z_cosines, x_cosines)) ℓ = [x_cosines' y_cosines' z_cosines'] return ℓ end #Member 1 A = [180.0, 0.0, 180.0] B = [0.0, 0.0, 180.0] β = π/2 AB = B - A ΔX = AB[1] ΔZ = AB[3] ΔY = AB[2] ρ = atan(-ΔZ, ΔX) proj_AB_xz = sqrt(ΔX^2 + ΔZ^2) χ = atan(ΔY, proj_AB_xz) RotYZ(ρ, χ) x_axis = RotYZ(ρ, χ) * [1.0, 0.0, 0.0] y_axis = RotYZ(ρ, χ) * [0.0, 1.0, 0.0] z_axis = RotYZ(ρ, χ) * [0.0, 0.0, 1.0] ω = π RotYZ(-ρ, -χ) # RotZY(ρ, χ) * [1.0, 0.0, 0.0] # RotZY(ρ, χ) * [0.0, 1.0, 0.0] # current_local_y_axis = RotZ(-χ) * RotY(-ρ) * [0.0, 1.0, 0.0] #where y-local is pointing after Y and Z rotations # ω = acos(dot(current_local_y_axis, [0.0, 1.0, 0.0])/ norm(current_local_y_axis)) RotX(-ω) * RotZ(-χ) * RotY(-ρ) * [0.0, 0.0, 1.0] #Member 2 A = [180.0, 0.0, 180.0] B = [180.0, 180.0, 180.0] β = -π/2 AB = B - A ΔX = AB[1] ΔZ = AB[3] ΔY = AB[2] ρ = atan(-ΔZ, ΔX) proj_AB_xz = sqrt(ΔX^2 + ΔZ^2) χ = atan(ΔY, proj_AB_xz) RotYZX(ρ, χ, β) ω = β x_axis = RotYZX(ρ, χ, ω) * [1.0, 0.0, 0.0] y_axis = RotYZX(ρ, χ, ω) * [0.0, 1.0, 0.0] z_axis = RotYZX(ρ, χ, ω) * [0.0, 0.0, 1.0] RotYZX(ρ, χ, ω)' # x_axis = RotYZ(ρ, χ) * [1.0, 0.0, 0.0] # y_axis = RotYZ(ρ, χ) * [0.0, 1.0, 0.0] # z_axis = RotYZ(ρ, χ) * [0.0, 0.0, 1.0] # current_local_y_axis = RotZ(-χ) * RotY(-ρ) * [0.0, 1.0, 0.0] #where y-local is pointing after Y and Z rotations # ω = acos(dot(current_local_y_axis, [0.0, 1.0, 0.0])/ norm(current_local_y_axis)) # proj_AB_xy = sqrt(ΔX^2 + ΔY^2) # ω = atan(ΔZ, proj_AB_xy) # ω = π/2 # ρ = 0.0 # χ = π/2 # ω = π/2 # RotX(-ω) * RotZ(-χ) * RotY(-ρ) * [0.0, 0.0, 1.0] #Member 3 A = [180.0, 0.0, 180.0] B = [180.0, 0.0, 0.0] β = -π/2 AB = B - A ΔX = AB[1] ΔZ = AB[3] ΔY = AB[2] ρ = atan(-ΔZ, ΔX) proj_AB_xz = sqrt(ΔX^2 + ΔZ^2) χ = atan(ΔY, proj_AB_xz) RotYZX(ρ, χ, β) ω = β x_axis = RotYZX(ρ, χ, ω) * [1.0, 0.0, 0.0] y_axis = RotYZX(ρ, χ, ω) * [0.0, 1.0, 0.0] z_axis = RotYZX(ρ, χ, ω) * [0.0, 0.0, 1.0] RotYZX(ρ, χ, ω)' * [1.0, 0.0, 0.0] RotYZX(ρ, χ, ω)' * [0.0, 1.0, 0.0] RotYZX(ρ, χ, ω)' * [0.0, 0.0, 1.0] RotYZX(ρ, χ, ω)' * [1.0, 0.0, 0.0] # current_local_y_axis = RotZ(-χ) * RotY(-ρ) * [0.0, 1.0, 0.0] #where y-local is pointing after Y and Z rotations # ω = acos(dot(current_local_y_axis, [0.0, 1.0, 0.0])/ norm(current_local_y_axis)) # ω = 0.0 # # ρ = π/2 # # χ = 0.0 # # ω = 0.0 # RotX(-ω) * RotZ(-χ) * RotY(-ρ) * [0.0, 0.0, 1.0]
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1911
using InstantFrame #Apply a point torsion at midspan of a beam that is twist fixed. The beam is discretized with two elements. The first element has a torsion release at its right end (midspan). material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[1.0], Iz=[1.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, 0.0], ry=[Inf, Inf], rz=[Inf, Inf])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (12.0, 0.0, 0.0), (24.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0, 0.0], connections=[("rigid", "end release"), ("rigid", "rigid")], cross_section=["beam", "beam"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 3], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,Inf])) # uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], loads=(qX=[0.0], qY=[10.0], qZ=[0.0], mX=[0.0], mY=[0.0], mZ=[0.0])) uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[0.0], FZ=[0.0], MX=[1000.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") ##test #Twist at the right end of the first element should be zero. isapprox(model.solution.element_connections.end_displacements[1][4], 0.0, atol=0.0001) #Twist at the left end of the second element should be Θ = TL/GJ where L=12.0 in. isapprox(model.solution.nodal_displacements[2][4], (1000.0*12.0)/(model.properties.G[1]*model.properties.J[1]), rtol=0.01)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1762
using InstantFrame #Apply a uniform load to a simply-supported frame element. material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[1.0], Iz=[1.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (120.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0, 0.0], connections=[("rigid", "rigid")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,0.0], rY=[0.0,0.0], rZ=[0.0,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], loads=(qX=[0.0], qY=[10.0], qZ=[0.0], mX=[0.0], mY=[0.0], mZ=[0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[0.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") # scale = (1.0, 1.0, 1.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale) ##test #Calculate rotation at the left end of the beam. wY = uniform_load.loads.qY[1] L = sum(model.properties.L) E = material.E[1] Iz = cross_section.Iz[1] θ_start = wY*L^3/(24*E*Iz) #rotation at left end of beam θ_start ≈ model.solution.nodal_displacements[1][6]
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1924
using InstantFrame #Apply a uniform load to a simply-supported frame element. material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[1.0], Iz=[1.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (120.0, 0.0, 0.0), (240.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0], connections=[("rigid", "rigid"), ("rigid", "rigid")], cross_section=["beam", "beam"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 3], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1, 2], loads=(qX=[0.0, 0.0], qY=[-10.0,-10.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[0.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") # scale = (1.0, 1.0, 1.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale) w=-10.0 L = 240.0 E = 29000000.0 I = 1.0 Δ = w*L^4/(384*E*I) ##test #Calculate rotation at the left end of the beam. wY = uniform_load.loads.qY[1] L = sum(model.properties.L) E = material.E[1] Iz = cross_section.Iz[1] θ_start = wY*L^3/(24*E*Iz) #rotation at left end of beam θ_start ≈ model.solution.nodal_displacements[1][6]
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
4596
using InstantFrame #Apply a uniform load to a simply-supported frame element. material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[0.627], Iz=[0.627], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 230000.0])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (96.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0, 0.0], connections=[("end release", "end release")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], loads=(qX=[0.0], qY=[-12.5], qZ=[0.0], mX=[0.0], mY=[0.0], mZ=[0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[0.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") # scale = (1.0, 1.0, 1.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale) # E*I/L # ke_pr = InstantFrame.define_local_elastic_element_stiffness_matrix_partially_restrained(I, E, L, k1, k2) # dof = [2; 6; 8; 12] # ke = model.equations.ke_local[1][dof, dof] # free_dof = [1; 3] # u = [1.0, -1.0] # ke_ff = ke[free_dof, free_dof] # M_fixed = ke_ff * u # ke_pr_ff = ke_pr[free_dof, free_dof] # M_pr = ke_pr_ff * u # 41.5118 1992.56 -41.5118 1992.56 # 1992.56 1.67198e5 -1992.56 24088.3 # -41.5118 -1992.56 41.5118 -1992.56 # 1992.56 24088.3 -1992.56 1.67198e5 # 246.623 11837.9 -246.623 11837.9 # 11837.9 757625.0 -11837.9 3.78812e5 # -246.623 -11837.9 246.623 -11837.9 # 11837.9 3.78812e5 -11837.9 757625.0 I = 0.627 E = 29000000.0 L = 96.0 k1 = 230000.0 k2 = 230000.0 M_fixed = [9600.0, -9600.0] F_fixed = [600.0, 600.0] # function fixed_end_forces_partial_restraint(k1, k2, E, I, L, M_fixed, F_fixed) α1 = k1/(E*I/L) α2 = k2/(E*I/L) #MGZ Example 13.7 k_moment = E*I/L*([4+α1 2.0 2.0 4+α2]) θi = k_moment^-1*M_fixed M_spring = θi .* [k1, k2] k_shear = (E*I/L)*[6/L 6/L -6/L -6/L] F_spring = F_fixed - k_shear * θi # return M_spring, F_spring # end wx_local = 0.0 wy_local = -12.5 wz_local = -12.5 k1z = 230000.0 k2z = 2000.0 k1y = 230000.0 k2y = 230000.0 local_fixed_end_forces = zeros(Float64, 12) local_fixed_end_forces[1] = -wx_local*L/2 local_fixed_end_forces[7] = -wx_local*L/2 # local_fixed_end_forces[3] = -wy_local*L/2 # local_fixed_end_forces[6] = -wy_local*L^2/12 # local_fixed_end_forces[9] = -wy_local*L/2 # local_fixed_end_forces[12] = wy_local*L^2/12 local_fixed_end_forces[2] = -wy_local*L/2 local_fixed_end_forces[6] = -wy_local*L^2/12 local_fixed_end_forces[8] = -wy_local*L/2 local_fixed_end_forces[12] = +wy_local*L^2/12 k1z, k2z = InstantFrame.connection_zeros_and_inf(k1z, k2z, E, I) M_fixed = [local_fixed_end_forces[6], local_fixed_end_forces[12]] F_fixed = [local_fixed_end_forces[2], local_fixed_end_forces[8]] M_spring, F_spring = fixed_end_forces_partial_restraint(k1z, k2z, E, I, L, M_fixed, F_fixed) local_fixed_end_forces[6] = M_spring[1] local_fixed_end_forces[12] = M_spring[2] local_fixed_end_forces[2] = F_spring[1] local_fixed_end_forces[8] = F_spring[2] local_fixed_end_forces[3] = -wz_local*L/2 local_fixed_end_forces[5] = +wz_local*L^2/12 local_fixed_end_forces[9] = -wz_local*L/2 local_fixed_end_forces[11] = -wz_local*L^2/12 k1y, k2y = InstantFrame.connection_zeros_and_inf(k1y, k2y, E, I) M_fixed = [local_fixed_end_forces[5], local_fixed_end_forces[11]] F_fixed = [local_fixed_end_forces[3], local_fixed_end_forces[9]] M_spring, F_spring = fixed_end_forces_partial_restraint(k1y, k2y, E, I, L, M_fixed, F_fixed) local_fixed_end_forces[5] = M_spring[1] local_fixed_end_forces[11] = M_spring[2] local_fixed_end_forces[3] = F_spring[1] local_fixed_end_forces[9] = F_spring[2]
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
4850
using InstantFrame #Apply a uniform load to a simply-supported frame element. material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[0.627], Iy=[0.627], Iz=[0.627], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 230000.0])) node = InstantFrame.Node(numbers=[1, 2, 3, 4, 5, 6], coordinates=[(0.0, 0.0, 0.0), (96.0, 0.0, 0.0), (0.0, 48.0, 0.0), (0.0, -48.0, 0.0), (96.0, 48.0, 0.0), (96.0, -48.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2, 3, 4, 5], nodes=[(1,2), (1, 3), (1, 4), (2, 5), (2, 6)], orientation=[0.0, 0.0, 0.0, 0.0, 0.0], connections=[("end release", "end release"), ("rigid", "rigid"), ("rigid", "rigid"), ("rigid", "rigid"), ("rigid", "rigid")], cross_section=["beam", "beam", "beam", "beam", "beam"], material=["steel", "steel", "steel", "steel", "steel"]) support = InstantFrame.Support(nodes=[3, 4, 5, 6], stiffness=(uX=[Inf,Inf,Inf,Inf], uY=[Inf,Inf,Inf,Inf], uZ=[Inf,Inf,Inf,Inf], rX=[Inf,Inf,Inf,Inf], rY=[Inf,Inf,Inf,Inf], rZ=[Inf,Inf,Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], loads=(qX=[0.0], qY=[-12.5], qZ=[0.0], mX=[0.0], mY=[0.0], mZ=[0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(nothing) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") # scale = (1.0, 1.0, 1.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale) # E*I/L # ke_pr = InstantFrame.define_local_elastic_element_stiffness_matrix_partially_restrained(I, E, L, k1, k2) # dof = [2; 6; 8; 12] # ke = model.equations.ke_local[1][dof, dof] # free_dof = [1; 3] # u = [1.0, -1.0] # ke_ff = ke[free_dof, free_dof] # M_fixed = ke_ff * u # ke_pr_ff = ke_pr[free_dof, free_dof] # M_pr = ke_pr_ff * u # 41.5118 1992.56 -41.5118 1992.56 # 1992.56 1.67198e5 -1992.56 24088.3 # -41.5118 -1992.56 41.5118 -1992.56 # 1992.56 24088.3 -1992.56 1.67198e5 # 246.623 11837.9 -246.623 11837.9 # 11837.9 757625.0 -11837.9 3.78812e5 # -246.623 -11837.9 246.623 -11837.9 # 11837.9 3.78812e5 -11837.9 757625.0 I = 0.627 E = 29000000.0 L = 96.0 k1 = 230000.0 k2 = 2000.0 M_fixed = [9600.0, -9600.0] F_fixed = [600.0, 600.0] function fixed_end_forces_partial_restraint(k1, k2, E, I, L, M_fixed, F_fixed) α1 = k1/(E*I/L) α2 = k2/(E*I/L) #MGZ Example 13.7 k_moment = E*I/L*([4+α1 2.0 2.0 4+α2]) θi = k_moment^-1*M_fixed M_spring = θi .* [k1, k2] k_shear = (E*I/L)*[6/L 6/L -6/L -6/L] F_spring = F_fixed - k_shear * θi return M_spring, F_spring end wx_local = 0.0 wy_local = -12.5 wz_local = -12.5 k1z = 230000.0 k2z = 2000.0 k1y = 230000.0 k2y = 230000.0 local_fixed_end_forces = zeros(Float64, 12) local_fixed_end_forces[1] = -wx_local*L/2 local_fixed_end_forces[7] = -wx_local*L/2 # local_fixed_end_forces[3] = -wy_local*L/2 # local_fixed_end_forces[6] = -wy_local*L^2/12 # local_fixed_end_forces[9] = -wy_local*L/2 # local_fixed_end_forces[12] = wy_local*L^2/12 local_fixed_end_forces[2] = -wy_local*L/2 local_fixed_end_forces[6] = -wy_local*L^2/12 local_fixed_end_forces[8] = -wy_local*L/2 local_fixed_end_forces[12] = +wy_local*L^2/12 k1z, k2z = InstantFrame.connection_zeros_and_inf(k1z, k2z, E, I) M_fixed = [local_fixed_end_forces[6], local_fixed_end_forces[12]] F_fixed = [local_fixed_end_forces[2], local_fixed_end_forces[8]] M_spring, F_spring = fixed_end_forces_partial_restraint(k1z, k2z, E, I, L, M_fixed, F_fixed) local_fixed_end_forces[6] = M_spring[1] local_fixed_end_forces[12] = M_spring[2] local_fixed_end_forces[2] = F_spring[1] local_fixed_end_forces[8] = F_spring[2] local_fixed_end_forces[3] = -wz_local*L/2 local_fixed_end_forces[5] = +wz_local*L^2/12 local_fixed_end_forces[9] = -wz_local*L/2 local_fixed_end_forces[11] = -wz_local*L^2/12 k1y, k2y = InstantFrame.connection_zeros_and_inf(k1y, k2y, E, I) M_fixed = [local_fixed_end_forces[5], local_fixed_end_forces[11]] F_fixed = [local_fixed_end_forces[3], local_fixed_end_forces[9]] M_spring, F_spring = fixed_end_forces_partial_restraint(k1y, k2y, E, I, L, M_fixed, F_fixed) local_fixed_end_forces[5] = M_spring[1] local_fixed_end_forces[11] = M_spring[2] local_fixed_end_forces[3] = F_spring[1] local_fixed_end_forces[9] = F_spring[2]
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
4848
using InstantFrame #Apply a uniform load to a simply-supported frame element. material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[0.627], Iy=[0.627], Iz=[0.627], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, 230000], rz=[Inf, Inf])) node = InstantFrame.Node(numbers=[1, 2, 3, 4, 5, 6], coordinates=[(0.0, 0.0, 0.0), (96.0, 0.0, 0.0), (0.0, 0.0, 48.0), (0.0, 0.0, -48.0), (96.0, 0.0, 48.0), (96.0, 0.0, -48.0)]) element = InstantFrame.Element(numbers=[1, 2, 3, 4, 5], nodes=[(1,2), (1, 3), (1, 4), (2, 5), (2, 6)], orientation=[0.0, 0.0, 0.0, 0.0, 0.0], connections=[("end release", "end release"), ("rigid", "rigid"), ("rigid", "rigid"), ("rigid", "rigid"), ("rigid", "rigid")], cross_section=["beam", "beam", "beam", "beam", "beam"], material=["steel", "steel", "steel", "steel", "steel"]) support = InstantFrame.Support(nodes=[3, 4, 5, 6], stiffness=(uX=[Inf,Inf,Inf,Inf], uY=[Inf,Inf,Inf,Inf], uZ=[Inf,Inf,Inf,Inf], rX=[Inf,Inf,Inf,Inf], rY=[Inf,Inf,Inf,Inf], rZ=[Inf,Inf,Inf,Inf])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], loads=(qX=[0.0], qY=[0.0], qZ=[-12.5], mX=[0.0], mY=[0.0], mZ=[0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(nothing) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") # scale = (1.0, 1.0, 1.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale) # E*I/L # ke_pr = InstantFrame.define_local_elastic_element_stiffness_matrix_partially_restrained(I, E, L, k1, k2) # dof = [2; 6; 8; 12] # ke = model.equations.ke_local[1][dof, dof] # free_dof = [1; 3] # u = [1.0, -1.0] # ke_ff = ke[free_dof, free_dof] # M_fixed = ke_ff * u # ke_pr_ff = ke_pr[free_dof, free_dof] # M_pr = ke_pr_ff * u # 41.5118 1992.56 -41.5118 1992.56 # 1992.56 1.67198e5 -1992.56 24088.3 # -41.5118 -1992.56 41.5118 -1992.56 # 1992.56 24088.3 -1992.56 1.67198e5 # 246.623 11837.9 -246.623 11837.9 # 11837.9 757625.0 -11837.9 3.78812e5 # -246.623 -11837.9 246.623 -11837.9 # 11837.9 3.78812e5 -11837.9 757625.0 I = 0.627 E = 29000000.0 L = 96.0 k1 = 230000.0 k2 = 2000.0 M_fixed = [9600.0, -9600.0] F_fixed = [600.0, 600.0] function fixed_end_forces_partial_restraint(k1, k2, E, I, L, M_fixed, F_fixed) α1 = k1/(E*I/L) α2 = k2/(E*I/L) #MGZ Example 13.7 k_moment = E*I/L*([4+α1 2.0 2.0 4+α2]) θi = k_moment^-1*M_fixed M_spring = θi .* [k1, k2] k_shear = (E*I/L)*[6/L 6/L -6/L -6/L] F_spring = F_fixed - k_shear * θi return M_spring, F_spring end wx_local = 0.0 wy_local = -12.5 wz_local = -12.5 k1z = 230000.0 k2z = 2000.0 k1y = 230000.0 k2y = 230000.0 local_fixed_end_forces = zeros(Float64, 12) local_fixed_end_forces[1] = -wx_local*L/2 local_fixed_end_forces[7] = -wx_local*L/2 # local_fixed_end_forces[3] = -wy_local*L/2 # local_fixed_end_forces[6] = -wy_local*L^2/12 # local_fixed_end_forces[9] = -wy_local*L/2 # local_fixed_end_forces[12] = wy_local*L^2/12 local_fixed_end_forces[2] = -wy_local*L/2 local_fixed_end_forces[6] = -wy_local*L^2/12 local_fixed_end_forces[8] = -wy_local*L/2 local_fixed_end_forces[12] = +wy_local*L^2/12 k1z, k2z = InstantFrame.connection_zeros_and_inf(k1z, k2z, E, I) M_fixed = [local_fixed_end_forces[6], local_fixed_end_forces[12]] F_fixed = [local_fixed_end_forces[2], local_fixed_end_forces[8]] M_spring, F_spring = fixed_end_forces_partial_restraint(k1z, k2z, E, I, L, M_fixed, F_fixed) local_fixed_end_forces[6] = M_spring[1] local_fixed_end_forces[12] = M_spring[2] local_fixed_end_forces[2] = F_spring[1] local_fixed_end_forces[8] = F_spring[2] local_fixed_end_forces[3] = -wz_local*L/2 local_fixed_end_forces[5] = +wz_local*L^2/12 local_fixed_end_forces[9] = -wz_local*L/2 local_fixed_end_forces[11] = -wz_local*L^2/12 k1y, k2y = InstantFrame.connection_zeros_and_inf(k1y, k2y, E, I) M_fixed = [local_fixed_end_forces[5], local_fixed_end_forces[11]] F_fixed = [local_fixed_end_forces[3], local_fixed_end_forces[9]] M_spring, F_spring = fixed_end_forces_partial_restraint(k1y, k2y, E, I, L, M_fixed, F_fixed) local_fixed_end_forces[5] = M_spring[1] local_fixed_end_forces[11] = M_spring[2] local_fixed_end_forces[3] = F_spring[1] local_fixed_end_forces[9] = F_spring[2]
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1763
using InstantFrame #Apply a uniform load to a simply-supported frame element. material = InstantFrame.Material(names=["steel"], E=[29000000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4]) #ρ = lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[1.0], Iy=[1.0], Iz=[1.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid", "end release"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, Inf], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (120.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0, 0.0], connections=[("rigid", "rigid")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,0.0], rY=[0.0,0.0], rZ=[0.0,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], loads=(qX=[0.0], qY=[0.0], qZ=[-10.0], mX=[0.0], mY=[0.0], mZ=[0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[0.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") # scale = (1.0, 1.0, 1.0) # figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale) ##test #Calculate rotation at the left end of the beam. wY = uniform_load.loads.qY[1] L = sum(model.properties.L) E = material.E[1] Iz = cross_section.Iz[1] θ_start = wY*L^3/(24*E*Iz) #rotation at left end of beam θ_start ≈ model.solution.nodal_displacements[1][6]
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1342
using InstantFrame, NonlinearSolve, Plots, LinearAlgebra, BenchmarkTools, StaticArrays, LinearAlgebra, BenchmarkTools #McGuire, W., Gallagher, R. H., & Ziemian, R. D. (2000). Matrix Structural Analysis, John Wiley and Sons. Inc., New York. #Consider the study summarized in Example 4.13 of McGuire et al. (2000), a 2D rigid frame. #Define structural system. nodes = [[0.0, 0.0], [8000.0, 0.0], [8000.0, -5000.0]] cross_sections = InstantFrame.CrossSections(["member_ab", "member_bc"], [6E3, 4E3], [200E6, 50E6], [], []) materials = InstantFrame.Materials(["steel"], [200000.], [0.3]) connections = InstantFrame.Connections(["semi-rigid", "rigid"], [30000.0, Inf], [Inf, Inf], [Inf, Inf]) members = InstantFrame.Members(["frame", "frame"], [1, 2], [2, 3], [0.0, 0.0], ["rigid", "rigid"], ["rigid", "rigid"], ["member_ab", "member_bc"], ["steel", "steel"]) #Calculate global elastic stiffness matrix. Ke = InstantFrame.define_global_elastic_stiffness_matrix(nodes, cross_sections, materials, members) #Define the frame loading as an external force vector. F = [0., 0., 0., 100000.0/sqrt(2), -100000.0/sqrt(2), 50000000., 0., 0., 0.] #Define the frame boundary conditions. free_dof = [4; 5; 6] #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] #Solution u = Ke_ff \ Ff
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
2260
using InstantFrame, NonlinearSolve, Plots, LinearAlgebra, BenchmarkTools, StaticArrays, LinearAlgebra, BenchmarkTools #McGuire, W., Gallagher, R. H., & Ziemian, R. D. (2000). Matrix Structural Analysis, John Wiley and Sons. Inc., New York. #Consider the study summarized in Example 4.13 of McGuire et al. (2000), a 2D rigid frame. #Define structural system. nodes = [[0.0, 0.0], [8000.0, 0.0], [8000.0, -5000.0]] cross_sections = InstantFrame.CrossSections(["member_ab", "member_bc"], [6E3, 4E3], [200E6, 50E6], [], []) materials = InstantFrame.Materials(["steel"], [200000.], [0.3]) connections = InstantFrame.Connections(["semi-rigid", "rigid"], [30000.0, Inf], [Inf, Inf], [Inf, Inf]) members = InstantFrame.Members(["frame", "frame"], [1, 2], [2, 3], [0.0, 0.0], ["rigid", "rigid"], ["rigid", "rigid"], ["member_ab", "member_bc"], ["steel", "steel"]) #Calculate global elastic stiffness matrix. Ke = InstantFrame.define_global_elastic_stiffness_matrix(nodes, cross_sections, materials, members) #Define the frame loading as an external force vector. F = [0., 0., 0., 100000.0/sqrt(2), -100000.0/sqrt(2), 50000000., 0., 0., 0.] #Define the frame boundary conditions. free_dof = [4; 5; 6] #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] #First order solution u_1f = Ke_ff \ Ff #Define global system displacement vector for the first order analysis. num_nodes = size(nodes, 1) num_dof_per_node = 3 u_1 = zeros(Float64, num_nodes * num_dof_per_node) u_1[free_dof] .= u_1f #Solve for first order internal forces. Need axial forces for second order analysis. @btime P = InstantFrame.calculate_internal_forces(nodes, cross_sections, materials, members, u_1) #Calculate global geometric stiffness matrix. @btime Kg = InstantFrame.define_global_geometric_stiffness_matrix(nodes, members, P) #Partition the geometric stiffness matrix. Kg_ff = Kg[free_dof, free_dof] #Get the total stiffness matrix, elastic + geometric. Kff = Ke_ff + Kg_ff p = [Kff, Ff] function residual(u, p) Kff, Ff = p Kff * u - Ff end u0 = u_1f u0 = @SVector [u0[i] for i in eachindex(u0)] probN = NonlinearProblem{false}(residual, u0, p) @btime u_2f = solve(probN, NewtonRaphson(), tol = 1e-9)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1339
using InstantFrame, NonlinearSolve, Plots, LinearAlgebra, BenchmarkTools, StaticArrays, LinearAlgebra, BenchmarkTools #Sennett, R. E. (2000). Matrix analysis of structures. Waveland Press. #Consider the study summarized in Example 7-4 of Sennett (2000), a 2D portal frame with a hinge. #Define structural system. nodes = [[0.0, 0.0], [0.0, 120.0], [120.0, 120.0], [120.0, 0.0]] cross_sections = InstantFrame.CrossSections(["beam"], [10.0], [100.0], [], []) materials = InstantFrame.Materials(["steel"], [29e6], [0.3]) connections = InstantFrame.Connections(["rigid", "hinge"], [Inf, 0.0], [], []) members = InstantFrame.Members(["frame", "frame", "frame"], [1, 2, 3], [2, 3, 4], [0.0, 0.0, 0.0], ["rigid", "hinge", "rigid"], ["hinge", "rigid", "rigid"], ["beam", "beam", "beam"], ["steel", "steel", "steel"]) #Calculate global elastic stiffness matrix. Ke = InstantFrame.define_global_elastic_stiffness_matrix(nodes, cross_sections, materials, members) #Define the frame loading as an external force vector. F = [0., 0., 0., 1000.0, 0., 0., 0., 0., 0., 0., 0., 0.] #Define the frame boundary conditions. free_dof = [3; 4; 5; 6; 7; 8; 9; 12] #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] #Solution uf = Ke_ff \ Ff u = zeros(Float64, 12) u[free_dof] = uf
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1687
using InstantFrame, NonlinearSolve, Plots, LinearAlgebra, BenchmarkTools, StaticArrays, LinearAlgebra, BenchmarkTools #McGuire, W., Gallagher, R. H., & Ziemian, R. D. (2000). Matrix Structural Analysis, John Wiley and Sons. Inc., New York. #Consider the study summarized in Example 5.4 of McGuire et al. (2000), a 3D space truss. #Define structural system. nodes = [[2000.0, 4000.0, 8000.0], [0.0, 0.0, 0.0], [8000.0, 0.0, 0.0], [8000.0, 6000.0, 0.0], [0.0, 6000.0, 0.0]] cross_sections = InstantFrame.CrossSections(["member_ab", "member_ac", "member_ad", "member_ae"], [20E3, 30E3, 40E3, 30E3], [], [], []) materials = InstantFrame.Materials(["steel"], [200000.], [0.3]) connections = InstantFrame.Connections(["semi-rigid", "rigid", "pinned, twist fixed"], [30000.0, Inf, Inf], [Inf, Inf, 0.0], [Inf, Inf, 0.0]) members = InstantFrame.Members(["frame", "frame"], [1, 1, 1, 1], [2, 3, 4, 5], [0.0, 0.0, 0.0, 0.0, 0.0], ["pinned, twist fixed", "pinned, twist fixed", "pinned, twist fixed", "pinned, twist fixed"], ["pinned, twist fixed", "pinned, twist fixed", "pinned, twist fixed", "pinned, twist fixed"], ["member_ab", "member_ac", "member_ad", "member_ae"], ["steel", "steel", "steel", "steel"]) #Calculate global elastic stiffness matrix. Ke = InstantFrame.define_global_elastic_stiffness_matrix(nodes, cross_sections, materials, members) #Define the frame loading as an external force vector. F = [0., 0., 0., 100000.0/sqrt(2), -100000.0/sqrt(2), 50000000., 0., 0., 0.] #Define the frame boundary conditions. free_dof = [4; 5; 6] #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] #Solution u = Ke_ff \ Ff
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
607
using Rotations #Consider Zeimian and McGuire Example 5.5 #global A = [0, 0, 0] B = [10, 5, 3] AB = B - A ρ = deg2rad(-16.699) χ = deg2rad(25.589) ω = deg2rad(30.0) RotY(-ρ) RotZ(-χ) RotX(-ω) RotXZY(-ω, -χ, -ρ) RotX(0.1) * RotY(0.2) * RotZ(0.3) === RotXYZ(0.1, 0.2, 0.3) #local # A_prime = [0, 0, 0] # B_prime = [length_AB, 0.0, 0.0] using LinearAlgebra, Rotations #[x'] = [β][x] β = deg2rad(30.0) A = [0, 0, 0] B = [10, 5, 3] AB = B - A length_AB = norm(AB) χ = π/2 - acos(AB[2]/length_AB) ρ = -atan(AB[3]/AB[1]) ω = β rad2deg(χ) rad2deg(ρ) rad2deg(ω) RotXZY(-ω, -χ, -ρ)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1732
using InstantFrame #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf #First order analysis material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (180.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0], connections=[("rigid", "rigid")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,0.0], uZ=[Inf,0.0], rX=[Inf,Inf], rY=[Inf,0.0], rZ=[Inf,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[-50.0], FY=[1.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "first order") ##tests #deflection isapprox(model.solution.u1[8], 0.609, rtol=0.05) #cantilever moment isapprox(-model.solution.P1[1][6], 180.0, rtol=0.05) scale = (1.0, 1.0, 1.0) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1865
using InstantFrame #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (90.0, 0.0, 0.0), (180.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0], connections=[("rigid", "rigid"), ("rigid", "rigid")], cross_section=["beam", "beam"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 2, 3], stiffness=(uX=[Inf,0.0,0.0], uY=[Inf,0.0,0.0], uZ=[Inf,0.0,0.0], rX=[Inf,Inf,Inf], rY=[Inf,0.0,0.0], rZ=[Inf,0.0,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1, 2], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[3], loads=(FX=[-50.0], FY=[1.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "second order") ##tests #deflection isapprox(model.solution.u2[8], 0.765, rtol=0.05) #cantilever moment isapprox(-model.solution.P2[1][6], 218.3, rtol=0.05) scale = (1.0, 1.0, 1.0) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1865
using InstantFrame #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2, 3], coordinates=[(0.0, 0.0, 0.0), (90.0, 0.0, 0.0), (180.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2], nodes=[(1,2), (2,3)], orientation=[0.0, 0.0], connections=[("rigid", "rigid"), ("rigid", "rigid")], cross_section=["beam", "beam"], material=["steel", "steel"]) support = InstantFrame.Support(nodes=[1, 2, 3], stiffness=(uX=[Inf,0.0,0.0], uY=[Inf,0.0,0.0], uZ=[Inf,0.0,0.0], rX=[Inf,Inf,Inf], rY=[Inf,0.0,0.0], rZ=[Inf,0.0,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1, 2], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) # uniform_load = InstantFrame.UniformLoad(nothing) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[3], loads=(FX=[-50.0], FY=[1.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "second order") ##tests #deflection isapprox(model.solution.u2[8], 0.765, rtol=0.05) #cantilever moment isapprox(-model.solution.P2[1][6], 218.3, rtol=0.05) scale = (1.0, 1.0, 1.0) figure = InstantFrame.UI.display_model_deformed_shape(model.solution.u1, element, node, model.properties, scale)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1941
using InstantFrame #Denavit and Hajjar (2013) Figure 5 #http://www1.coe.neu.edu/~jfhajjar/home/Denavit%20and%20Hajjar%20-%20Geometric%20Nonlinearity%20in%20OpenSees%20-%20Report%20No.%20NEU-CEE-2013-02%202013.pdf #Vibration modes material = InstantFrame.Material(names=["steel"], E=[29000.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000.0]) ##ρ = kilo-lbs * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["beam"], A=[9.12], Iy=[37.1], Iz=[110.0], J=[0.001]) connection = InstantFrame.Connection(names=["rigid"], stiffness=(ux=[Inf], uy=[Inf], uz=[Inf], rx=[Inf], ry=[Inf], rz=[Inf])) node = InstantFrame.Node(numbers=[1, 2], coordinates=[(0.0, 0.0, 0.0), (180.0, 0.0, 0.0)]) element = InstantFrame.Element(numbers=[1], nodes=[(1,2)], orientation=[0.0], connections=[("rigid", "rigid")], cross_section=["beam"], material=["steel"]) support = InstantFrame.Support(nodes=[1, 2], stiffness=(uX=[Inf,0.0], uY=[Inf,0.0], uZ=[Inf,0.0], rX=[Inf,0.0], rY=[Inf,0.0], rZ=[Inf,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["test"], elements=[1], loads=(qX=[0.0, 0.0], qY=[0.0, 0.0], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["test"], nodes=[2], loads=(FX=[0.0], FY=[0.0], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type = "modal vibration") ##tests #first mode natural frequency for a cantilever #https://roymech.org/Useful_Tables/Vibrations/Natural_Vibrations.html A = cross_section.A[1] E = material.E[1] I_weak = cross_section.Iy[1] I_strong = cross_section.Iz[1] L = 180.0 ρ = material.ρ[1] m = ρ * A #mass per unit length ωn_weak = 1.875^2 * sqrt((E*I_weak)/(m*L^4)) ωn_strong = 1.875^2 * sqrt((E*I_strong)/(m*L^4)) isapprox(model.solution.ωn[1], ωn_weak, rtol=0.05) isapprox(model.solution.ωn[2], ωn_strong, rtol=0.05)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
3188
using InstantFrame, NLsolve, Plots, LinearAlgebra, BenchmarkTools #Denavit, M. D., & Hajjar, J. F. (2013). Description of geometric nonlinearity for beam-column analysis in OpenSees. #Consider the study summarized in Figure 5 of Denavit and Hajjar (2013), a cantilever under axial and transverse loading. #Define frame inputs. E = 29000.0 #ksi I = 37.1 #in^4 A = 9.12 #in^2 L = 180.0 #in P = -50.0 #kips H = -1.0 #kips ρ = 492.0 / 32.17 / 1000.0 / 12^4 #kips * s^2 / in^4 #Define the frame loading as an external force vector. There is an axial load of 50 kips and a lateral load of 1 kip. F = [0., 0., 0., P, H, 0.0] #Define the frame boundary conditions. free_dof = [4; 5; 6] #Define the frame elastic stiffness. Ke = InstantFrame.define_local_elastic_stiffness_matrix(I, A, E, L) Kg = InstantFrame.define_local_geometric_stiffness_matrix(P, L) #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] Kg_ff = Kg[free_dof, free_dof] #Get the total stiffness matrix, elastic + geometric. Kff = Ke_ff + Kg_ff #Define the deformation initial guess for the nonlinear solver. deformation_guess = Ke_ff \ Ff #Solve for the beam deformations. @btime solution = nlsolve((R,U) ->InstantFrame.second_order_analysis_residual!(R, U, Kff, Ff), deformation_guess, method=:newton) #Newton-Raphson is faster here, than trust region... #Get the frame deformed shape. u = zeros(Float64, 6) u[free_dof] .= solution.zero #Show the frame deformed shape. x = range(0., L, 20) offset = 0. w = beam_shape_function(u[2],u[3],u[5],u[6], L, x, offset) plot(x, w, linewidth = 10, linecolor = :gray, legend=false) #Plot load-deformation response. num_steps = 20 P_range = range(0., P, num_steps) H_range = range(0., H, num_steps) u_range = Array{Array}(undef, num_steps) for i = 1:num_steps F = [0., 0., 0., P_range[i], H_range[i], 0.0] u_range[i] = get_load_deformation_response(I, A, E, L, P_range[i], F, free_dof) end u_load = [u_range[i][5] for i = 1:num_steps] plot(-u_load, -P_range ./ -P, markershape = :o, xlabel="cantilever disp. [in.]", ylabel="load factor", label="varying P") u_range_constant_P = Array{Array}(undef, num_steps) for i = 1:num_steps F = [0., 0., 0., P, H_range[i], 0.0] u_range_constant_P[i] = get_load_deformation_response(I, A, E, L, P, F, free_dof) end u_load_constant_P = [u_range_constant_P[i][5] for i = 1:num_steps] plot!(-u_load_constant_P, -P_range ./ -P, markershape = :o, xlabel="cantilever disp. [in.]", ylabel="load factor", label="constant P", legend=:bottomright) #Calculate the vibration natural frequencies and mode shapes. M = InstantFrame.define_local_element_mass_matrix(A,L,ρ) Mff = m[free_dof, free_dof] ωn_squared=eigvals(Ke_ff, Mff) ωn=sqrt.(ωn_squared) f = ωn/(2π) #And the natural periods of vibration... T = 1 ./ f mode_shapes=eigvecs(Ke_ff,Mff) #And show the vibration modes. mode_shape = zeros(Float64, 6) mode = 3 mode_shape[free_dof] .= modeshapes[:, mode] ./ maximum(abs.(modeshapes[:, mode])) w = beam_shape_function(mode_shape[2],mode_shape[3],mode_shape[5],mode_shape[6], L, x, offset) plot(x, w, linewidth = 10, linecolor = :gray, legend=false)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1733
using ApproxFun, Plots E = 29000 #ksi I = 37.1 #in^4 A = 9.12 #in^2 L = 180.0 #in P = -50.0 #kips H = 1.0 #kips x = Fun(identity, 0..L) # x = Fun(Taylor(), [1,2,3]) y₀ = 0.0x # initial guess N = y -> [y(0), y'(0), y''(L), y'''(L) - H/(E*I), E*I*y'''' + P*y''] y = newton(N, y₀) plot(y, legend = false) rad2deg(y'(L)) s = Fun(identity, 0..L) θ₀ = 0.0s # initial guess N = θ -> [θ(0), θ'(L), E*I*θ'' + P*sin(θ) + H*L - H*x] θ = newton(N, θ₀) plot(θ, legend = false) y(L) x = Fun(identity, 0..L) y₀ = 0.0x # initial guess N = y -> [y(0), y'(0), E*I*y'' + P*y + H*L - H*x] y = newton(N, y₀) plot(y, legend = false) α = sqrt(-P*L^2/(E*I)) y_theor = H*L^3/(3*E*I) * (3 * (tan(α) - α))/α^3 plot(y''') plot(y''', legend=false) H/(E*I) y(L) L, E, Iy, P, qx = 12.0, 1.0, 1.0, 2.0, 0.0001 d = 0..L z = Fun(identity, d) B = [[Evaluation(d,leftendpoint,k) for k=0:1]... ; [Evaluation(d,rightendpoint,k) for k=2:3]... ;] v = [B; E*Iy*Derivative()^4 + P*Derivative()^2] \ [ zeros(4)..., qx*one(z)] func_name = zip([v, v', v'', v'''], ["Deflection", "Angle", "Moment", "Shear"]) plot([plot(z, f, title=n, label="") for (f,n) in func_name]..., lw=3) x = Fun() B = Evaluation(Chebyshev(),-1) A = [B 0; B*𝒟 0; 0 B; 𝒟^2-I 2I; I 𝒟+I] u,v = A\[0;0;0;exp(x);cos(x)] u(-1),u'(-1),v(-1) Δ = qx * L^4/(8 * E * Iy) maximum(u) u.(0:0.1:12) x = Fun(identity, 0..1) N = (u1,u2) -> [u1'(0) - 0.5*u1(0)*u2(0); u2'(0) + 1; u1(1) - 1; u2(1) - 1; u1'' + u1*u2; u2'' - u1*u2] u10 = one(x) u20 = one(x) u1,u2 = newton(N, [u10,u20]) plot(u1, label="u1") plot!(u2, label="u2")
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
3489
using InstantFrame, NonlinearSolve, Plots, LinearAlgebra, BenchmarkTools, StaticArrays #Denavit, M. D., & Hajjar, J. F. (2013). Description of geometric nonlinearity for beam-column analysis in OpenSees. #Consider the study summarized in Figure 5 of Denavit and Hajjar (2013), a cantilever under axial and transverse loading. #Define frame inputs. E = 29000.0 #ksi I = 37.1 #in^4 A = 9.12 #in^2 L = 180.0 #in P = -50.0 #kips H = -1.0 #kips ρ = 492.0 / 32.17 / 1000.0 / 12^4 #kips * s^2 / in^4 #Define the frame loading as an external force vector. There is an axial load of 50 kips and a lateral load of 1 kip. F = [0., 0., 0., P, H, 0.0] #Define the frame boundary conditions. free_dof = [4; 5; 6] #Define the frame elastic stiffness. Ke = InstantFrame.define_local_elastic_stiffness_matrix(I, A, E, L) Kg = InstantFrame.define_local_geometric_stiffness_matrix(P, L) K=Ke+Kg Ku=F Ku-F = 0 #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] Kg_ff = Kg[free_dof, free_dof] #Get the total stiffness matrix, elastic + geometric. Kff = Ke_ff + Kg_ff #Define the deformation initial guess for the nonlinear solver. deformation_guess = Ke_ff \ Ff p = [Kff, Ff] function residual(u, p) Kff, Ff = p Kff * u - Ff end u0 = deformation_guess u0 = @SVector [u0[i] for i in eachindex(u0)] probN = NonlinearProblem{false}(residual, u0, p) @btime solver = solve(probN, NewtonRaphson(), tol = 1e-9) #Solve for the beam deformations. @btime solution = nlsolve((R,U) ->InstantFrame.second_order_analysis_residual!(R, U, Kff, Ff), deformation_guess) #Newton-Raphson is faster here, than trust region... #Get the frame deformed shape. u = zeros(Float64, 6) u[free_dof] .= solution.zero #Show the frame deformed shape. x = range(0., L, 20) offset = 0. w = beam_shape_function(u[2],u[3],u[5],u[6], L, x, offset) plot(x, w, linewidth = 10, linecolor = :gray, legend=false) #Plot load-deformation response. num_steps = 20 P_range = range(0., P, num_steps) H_range = range(0., H, num_steps) u_range = Array{Array}(undef, num_steps) for i = 1:num_steps F = [0., 0., 0., P_range[i], H_range[i], 0.0] u_range[i] = get_load_deformation_response(I, A, E, L, P_range[i], F, free_dof) end u_load = [u_range[i][5] for i = 1:num_steps] plot(-u_load, -P_range ./ -P, markershape = :o, xlabel="cantilever disp. [in.]", ylabel="load factor", label="varying P") u_range_constant_P = Array{Array}(undef, num_steps) for i = 1:num_steps F = [0., 0., 0., P, H_range[i], 0.0] u_range_constant_P[i] = get_load_deformation_response(I, A, E, L, P, F, free_dof) end u_load_constant_P = [u_range_constant_P[i][5] for i = 1:num_steps] plot!(-u_load_constant_P, -P_range ./ -P, markershape = :o, xlabel="cantilever disp. [in.]", ylabel="load factor", label="constant P", legend=:bottomright) #Calculate the vibration natural frequencies and mode shapes. M = InstantFrame.define_local_element_mass_matrix(A,L,ρ) Mff = m[free_dof, free_dof] ωn_squared=eigvals(Ke_ff, Mff) ωn=sqrt.(ωn_squared) f = ωn/(2π) #And the natural periods of vibration... T = 1 ./ f mode_shapes=eigvecs(Ke_ff,Mff) #And show the vibration modes. mode_shape = zeros(Float64, 6) mode = 3 mode_shape[free_dof] .= modeshapes[:, mode] ./ maximum(abs.(modeshapes[:, mode])) w = beam_shape_function(mode_shape[2],mode_shape[3],mode_shape[5],mode_shape[6], L, x, offset) plot(x, w, linewidth = 10, linecolor = :gray, legend=false)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
3379
using InstantFrame, NonlinearSolve, Plots, LinearAlgebra, BenchmarkTools, StaticArrays #Denavit, M. D., & Hajjar, J. F. (2013). Description of geometric nonlinearity for beam-column analysis in OpenSees. #Consider the study summarized in Figure 5 of Denavit and Hajjar (2013), a cantilever under axial and transverse loading. #Define frame inputs. E = 29000.0 #ksi J = 10.0 #in^4 ν = 0.30 Iy = 37.1 #in^4 Ix = 110.0 #in^4 A = 9.12 #in^2 L = 180.0 #in P = -50.0 #kips H = -1.0 #kips ρ = 492.0 / 32.17 / 1000.0 / 12^4 #kips * s^2 / in^4 #Define the frame loading as an external force vector. There is an axial load of 50 kips and a lateral load of 1 kip. F = [0., 0., 0., 0., 0., 0., P, H, -H, 0., 0., 0.] #Define the frame boundary conditions. free_dof = [7; 8; 9; 10; 11; 12] #Define the frame elastic stiffness. Ke = InstantFrame.define_local_elastic_stiffness_matrix(Ix, Iy, A, J, E, ν, L) #Define frame geometric stiffness. Kg = InstantFrame.define_local_3D_geometric_stiffness_matrix(P, L) #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] Kg_ff = Kg[free_dof, free_dof] #Get the total stiffness matrix, elastic + geometric. Kff = Ke_ff + Kg_ff #Define the deformation initial guess for the nonlinear solver. deformation_guess = Ke_ff \ Ff p = [Kff, Ff] function residual(u, p) Kff, Ff = p Kff * u - Ff end u0 = deformation_guess u0 = @SVector [u0[i] for i in eachindex(u0)] probN = NonlinearProblem{false}(residual, u0, p) @benchmark solver = solve(probN, NewtonRaphson(), tol = 1e-9) #Get the frame deformed shape. u = zeros(Float64, 6) u[free_dof] .= solution.zero #Show the frame deformed shape. x = range(0., L, 20) offset = 0. w = beam_shape_function(u[2],u[3],u[5],u[6], L, x, offset) plot(x, w, linewidth = 10, linecolor = :gray, legend=false) #Plot load-deformation response. num_steps = 20 P_range = range(0., P, num_steps) H_range = range(0., H, num_steps) u_range = Array{Array}(undef, num_steps) for i = 1:num_steps F = [0., 0., 0., P_range[i], H_range[i], 0.0] u_range[i] = get_load_deformation_response(I, A, E, L, P_range[i], F, free_dof) end u_load = [u_range[i][5] for i = 1:num_steps] plot(-u_load, -P_range ./ -P, markershape = :o, xlabel="cantilever disp. [in.]", ylabel="load factor", label="varying P") u_range_constant_P = Array{Array}(undef, num_steps) for i = 1:num_steps F = [0., 0., 0., P, H_range[i], 0.0] u_range_constant_P[i] = get_load_deformation_response(I, A, E, L, P, F, free_dof) end u_load_constant_P = [u_range_constant_P[i][5] for i = 1:num_steps] plot!(-u_load_constant_P, -P_range ./ -P, markershape = :o, xlabel="cantilever disp. [in.]", ylabel="load factor", label="constant P", legend=:bottomright) #Calculate the vibration natural frequencies and mode shapes. M = InstantFrame.define_local_element_mass_matrix(A,L,ρ) Mff = m[free_dof, free_dof] ωn_squared=eigvals(Ke_ff, Mff) ωn=sqrt.(ωn_squared) f = ωn/(2π) #And the natural periods of vibration... T = 1 ./ f mode_shapes=eigvecs(Ke_ff,Mff) #And show the vibration modes. mode_shape = zeros(Float64, 6) mode = 3 mode_shape[free_dof] .= modeshapes[:, mode] ./ maximum(abs.(modeshapes[:, mode])) w = beam_shape_function(mode_shape[2],mode_shape[3],mode_shape[5],mode_shape[6], L, x, offset) plot(x, w, linewidth = 10, linecolor = :gray, legend=false)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
3473
using InstantFrame, NonlinearSolve, Plots, LinearAlgebra, BenchmarkTools, StaticArrays, SparseArrays #Denavit, M. D., & Hajjar, J. F. (2013). Description of geometric nonlinearity for beam-column analysis in OpenSees. #Consider the study summarized in Figure 5 of Denavit and Hajjar (2013), a cantilever under axial and transverse loading. #Define frame inputs. E = 29000.0 #ksi I = 37.1 #in^4 A = 9.12 #in^2 L = 180.0 #in P = -50.0 #kips H = -1.0 #kips ρ = 492.0 / 32.17 / 1000.0 / 12^4 #kips * s^2 / in^4 #Define the frame loading as an external force vector. There is an axial load of 50 kips and a lateral load of 1 kip. F = [0., 0., 0., P, H, 0.0] #Define the frame boundary conditions. free_dof = [4; 5; 6] #Define the frame elastic stiffness. Ke = InstantFrame.define_local_elastic_stiffness_matrix(I, A, E, L) Kg = InstantFrame.define_local_geometric_stiffness_matrix(P, L) #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] Kg_ff = Kg[free_dof, free_dof] #Get the total stiffness matrix, elastic + geometric. Kff = Ke_ff + Kg_ff #Define the deformation initial guess for the nonlinear solver. deformation_guess = Ke_ff \ Ff p = [Kff, Ff] function residual(u, p) Kff, Ff = p Kff * u - Ff end u0 = deformation_guess u0 = @SVector [u0[i] for i in eachindex(u0)] probN = NonlinearProblem{false}(residual, u0, p) @btime solver = solve(probN, NewtonRaphson(), tol = 1e-9) #Solve for the beam deformations. @btime solution = nlsolve((R,U) ->InstantFrame.second_order_analysis_residual!(R, U, Kff, Ff), deformation_guess) #Newton-Raphson is faster here, than trust region... #Get the frame deformed shape. u = zeros(Float64, 6) u[free_dof] .= solution.zero #Show the frame deformed shape. x = range(0., L, 20) offset = 0. w = beam_shape_function(u[2],u[3],u[5],u[6], L, x, offset) plot(x, w, linewidth = 10, linecolor = :gray, legend=false) #Plot load-deformation response. num_steps = 20 P_range = range(0., P, num_steps) H_range = range(0., H, num_steps) u_range = Array{Array}(undef, num_steps) for i = 1:num_steps F = [0., 0., 0., P_range[i], H_range[i], 0.0] u_range[i] = get_load_deformation_response(I, A, E, L, P_range[i], F, free_dof) end u_load = [u_range[i][5] for i = 1:num_steps] plot(-u_load, -P_range ./ -P, markershape = :o, xlabel="cantilever disp. [in.]", ylabel="load factor", label="varying P") u_range_constant_P = Array{Array}(undef, num_steps) for i = 1:num_steps F = [0., 0., 0., P, H_range[i], 0.0] u_range_constant_P[i] = get_load_deformation_response(I, A, E, L, P, F, free_dof) end u_load_constant_P = [u_range_constant_P[i][5] for i = 1:num_steps] plot!(-u_load_constant_P, -P_range ./ -P, markershape = :o, xlabel="cantilever disp. [in.]", ylabel="load factor", label="constant P", legend=:bottomright) #Calculate the vibration natural frequencies and mode shapes. M = InstantFrame.define_local_element_mass_matrix(A,L,ρ) Mff = m[free_dof, free_dof] ωn_squared=eigvals(Ke_ff, Mff) ωn=sqrt.(ωn_squared) f = ωn/(2π) #And the natural periods of vibration... T = 1 ./ f mode_shapes=eigvecs(Ke_ff,Mff) #And show the vibration modes. mode_shape = zeros(Float64, 6) mode = 3 mode_shape[free_dof] .= modeshapes[:, mode] ./ maximum(abs.(modeshapes[:, mode])) w = beam_shape_function(mode_shape[2],mode_shape[3],mode_shape[5],mode_shape[6], L, x, offset) plot(x, w, linewidth = 10, linecolor = :gray, legend=false)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1108
using InstantFrame nodes = InstantFrame.Nodes([0.0, 10.0, 20.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]) cross_sections = InstantFrame.CrossSections(["W16x26"], [7.68], [301.0], [9.59], [0.262]) materials = InstantFrame.Materials(["steel"], [29000.0], [0.3]) connections = InstantFrame.Connections(["semi-rigid", "rigid"], [30000.0, Inf], [Inf, Inf], [Inf, Inf]) members = InstantFrame.Members(["frame", "frame"], [1, 2], [2, 3], ["rigid", "rigid"], ["rigid", "rigid"], ["W16x26", "W16x26"], ["steel", "steel"]) using ApproxFun, Plots L, E, I = 12.0, 1.0, 1.0 d = 0..L z = Fun(identity, d) B = [[Evaluation(d,leftendpoint,k) for k=0:1]... ; [Evaluation(d,rightendpoint,k) for k=2:3]... ;] v = [B; E*I*Derivative()^4] \ [ zeros(4)..., one(z)] func_name = zip([v, v', v'', v'''], ["Deflection", "Angle", "Moment", "Shear"]) plot([plot(z, f, title=n, label="") for (f,n) in func_name]..., lw=3) x = Fun() B = Evaluation(Chebyshev(),-1) A = [B 0; B*𝒟 0; 0 B; 𝒟^2-I 2I; I 𝒟+I] u,v = A\[0;0;0;exp(x);cos(x)] u(-1),u'(-1),v(-1)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1268
using InstantFrame using ApproxFun, Plots L, E, Iy, P, qx = 12.0, 1.0, 1.0, 2.0, 0.0001 d = 0..L z = Fun(identity, d) B = [[Evaluation(d,leftendpoint,k) for k=0:1]... ; [Evaluation(d,rightendpoint,k) for k=2:3]... ;] v = [B; E*Iy*Derivative()^4 + P*Derivative()^2] \ [ zeros(4)..., qx*one(z)] func_name = zip([v, v', v'', v'''], ["Deflection", "Angle", "Moment", "Shear"]) plot([plot(z, f, title=n, label="") for (f,n) in func_name]..., lw=3) x = Fun() B = Evaluation(Chebyshev(),-1) A = [B 0; B*𝒟 0; 0 B; 𝒟^2-I 2I; I 𝒟+I] u,v = A\[0;0;0;exp(x);cos(x)] u(-1),u'(-1),v(-1) x = Fun(identity, 0..L) u₀ = 0.1x # initial guess L, E, Iy, P, qx = 12.0, 1.0, 2.0, -0.1, 0.0001 N = u -> [u(0), u'(0), u''(L), u'''(L), E*Iy*u'''' + P*u'' - qx] u = newton(N, u₀) # perform Newton iteration in function space plot(u, legend = false) Δ = qx * L^4/(8 * E * Iy) maximum(u) u.(0:0.1:12) x = Fun(identity, 0..1) N = (u1,u2) -> [u1'(0) - 0.5*u1(0)*u2(0); u2'(0) + 1; u1(1) - 1; u2(1) - 1; u1'' + u1*u2; u2'' - u1*u2] u10 = one(x) u20 = one(x) u1,u2 = newton(N, [u10,u20]) plot(u1, label="u1") plot!(u2, label="u2")
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1098
using InstantFrame nodes = InstantFrame.Nodes([0.0, 10.0, 20.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]) cross_sections = InstantFrame.CrossSections(["W16x26"], [7.68], [301.0], [9.59], [0.262]) materials = InstantFrame.Materials(["steel"], [29000.0], [0.3]) connections = InstantFrame.Connections(["semi-rigid", "rigid"], [30000.0, Inf], [Inf, Inf], [Inf, Inf]) members = InstantFrame.Members(["frame", "frame"], [1, 2], [2, 3], ["rigid", "rigid"], ["rigid", "rigid"], ["W16x26", "W16x26"], ["steel", "steel"]) using ApproxFun, Plots L, E, I = 12.0, 1.0, 1.0 d = 0..L z = Fun(identity, d) B = [[Evaluation(d,leftendpoint,k) for k=0:1]... ; [Evaluation(d,rightendpoint,k) for k=2:3]... ;] v = [B; E*I*Derivative()^4] \ [ zeros(4)..., one(z)] func_name = zip([v, v', v'', v'''], ["Deflection", "Angle", "Moment", "Shear"]) plot([plot(z, f, title=n, label="") for (f,n) in func_name]..., lw=3) x = Fun() B = Evaluation(Chebyshev(),-1) A = [B 0; B*𝒟 0; 0 B; 𝒟^2-I 2I; I 𝒟+I] u,v = A\[0;0;0;exp(x);cos(x)] u(-1),u'(-1),v(-1)
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
8212
using SparseArrays, StaticArrays, LinearAlgebra, Rotations, Parameters, NonlinearSolve # export UI # include("UI.jl") # using .UI @with_kw struct Node list::Array{Int64} coordinates::Array{Array{Float64}} end @with_kw struct CrossSection names::Array{String} A::Array{Float64} Iy::Array{Float64} Iz::Array{Float64} J::Array{Float64} end @with_kw struct Material names::Array{String} E::Array{Float64} ν::Array{Float64} end @with_kw struct Connection names::Array{String} rx::Array{Float64} ry::Array{Float64} rz::Array{Float64} end @with_kw struct Element list::Array{Int64} start_node::Array{Int64} end_node::Array{Int64} β::Array{Float64} start_connection::Array{String} end_connection::Array{String} cross_section::Array{String} material::Array{String} end @with_kw struct Properties L::Array{Float64} A::Array{Float64} Iz::Array{Float64} Iy::Array{Float64} J::Array{Float64} E::Array{Float64} ν::Array{Float64} Γ::Array{Array{Float64, 2}} global_dof::Array{Array{Int64, 1}} end @with_kw struct Equations free_dof::Array{Int64} ke_local::Array{Array{Float64, 2}} ke_global::Array{Array{Float64, 2}} Ke::Array{Float64, 2} kg_local::Array{Array{Float64, 2}} kg_global::Array{Array{Float64, 2}} Kg::Array{Float64, 2} end @with_kw struct Solution u1::Array{Float64} P1::Array{Float64} u2::Array{Float64} P2::Array{Float64} end @with_kw struct Model properties::Properties equations::Equations solution::Solution end function define_local_elastic_stiffness_matrix(Iy, Iz, A, J, E, ν, L) G = E/(2*(1+ν)) ke = zeros(Float64, (12, 12)) ke[1, 1] = E*A/L ke[1, 6] = -E*A/L ke[2, 2] = 12*E*Iz/L^3 ke[2, 6] = 6*E*Iz/L^3 ke[2, 8] = -12*E*Iz/L^3 ke[2, 12] = 6*E*Iz/L^2 ke[3, 3] = 12*E*Iy/L^3 ke[3, 5] = -6*E*Iy/L^2 ke[3, 9] = -12*E*Iy/L^3 ke[3, 11] = -6*E*Iy/L^2 ke[4, 4] = G*J/L ke[4, 10] = -G*J/L ke[5, 5] = 4*E*Iy/L ke[5, 9] = 6*E*Iy/L^2 ke[5, 11] = 2*E*Iy/L ke[6, 6] = 4*E*Iz/L ke[6, 8] = -6*E*Iz/L^2 ke[6, 12] = 2*E*Iz/L ke[7, 7] = E*A/L ke[8, 8] = 12*E*Iz/L^3 ke[8, 12] = -6*E*Iz/L^2 ke[9, 9] = 12*E*Iy/L^3 ke[9, 11] = 6*E*Iy/L^2 ke[10, 10] = G*J/L ke[11, 11] = 4*E*Iy/L ke[12, 12] = 4*E*Iz/L for i = 1:12 for j = 1:12 ke[j, i] = ke[i, j] end end return ke end function define_local_geometric_stiffness_matrix(P, L) kg = zeros(Float64, (12, 12)) kg[1, 1] = P/L kg[1, 7] = -P/L kg[2, 2] = 6/5*P/L kg[2, 6] = P/10 kg[2, 8] = -6/5*P/L kg[2, 12] = P/10 kg[3, 3] = 6/5*P/L kg[3, 5] = -P/10 kg[3, 9] = -6/5*P/L kg[3, 11] = -P/10 kg[5, 5] = 2/15*P*L kg[5, 9] = P/10 kg[5, 11] = -P*L/30 kg[6, 6] = 2/15*P*L kg[6, 8] = -P/10 kg[6, 12] = -P*L/30 kg[7, 7] = P/L kg[8, 8] = 6/5*P/L kg[8, 12] = - P/10 kg[9, 9] = 6/5 * P/L kg[9, 11] = P/10 kg[11, 11] = 2/15*P*L kg[12, 12] = 2/15*P*L for i = 1:12 for j = 1:12 kg[j, i] = kg[i, j] end end return kg end function define_rotation_matrix(A, B, β) #ρ is x-z plane, χ is x-y plane , ω is y-z plane AB = B - A length_AB = norm(AB) χ = π/2 - acos(AB[2]/length_AB) if (AB[3]==0.0) & (AB[1]==0.0) #avoid 0/0 case ρ = 0.0 else ρ = -atan(AB[3]/AB[1]) end ω = β γ = RotXZY(-ω, -χ, -ρ) Γ = zeros(Float64, (12, 12)) Γ[1:3, 1:3] .= γ Γ[4:6, 4:6] .= γ Γ[7:9, 7:9] .= γ Γ[10:12, 10:12] .= γ return Γ end function define_element_properties(node, cross_section, material, element) num_elem = length(element.list) L = Array{Float64}(undef, num_elem) Γ = Array{Array{Float64, 2}}(undef, num_elem) global_dof = Array{Array{Int64, 1}}(undef, num_elem) Iz = Array{Float64}(undef, num_elem) Iy = Array{Float64}(undef, num_elem) A = Array{Float64}(undef, num_elem) J = Array{Float64}(undef, num_elem) E = Array{Float64}(undef, num_elem) ν = Array{Float64}(undef, num_elem) for i in eachindex(element.list) #nodal coordinates node_i_index = findfirst(node_num->node_num == element.start_node[i], node.list) node_j_index = findfirst(node_num->node_num == element.end_node[i], node.list) node_i = node.coordinates[node_i_index] node_j = node.coordinates[node_j_index] #cross section index = findfirst(name->name == element.cross_section[i], cross_section.names) Iz[i] = cross_section.Iz[index] Iy[i] = cross_section.Iy[index] A[i] = cross_section.A[index] J[i] = cross_section.J[index] #material index = findfirst(name->name == element.material[i], material.names) E[i] = material.E[index] ν[i] = material.ν[index] #element length L[i] = norm(node_j - node_i) #global dof for each element num_dof_per_node = Int(size(ke_local[i], 1)/2) node_i_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (node_i_index-1) node_j_dof = range(1, num_dof_per_node) .+ num_dof_per_node * (node_j_index-1) global_dof[i] = [node_i_dof; node_j_dof] end properties = FrameProperties(L, A, Iz, Iy, J, E, ν, Γ, global_dof) return properties end function assemble_stiffness_matrix(k, dof) total_dof = sum([Int(size(k[i], 1)/2) for i in eachindex(k)]) K = zeros(Float64, (total_dof , total_dof)) for i in eachindex(k) K[dof[i], dof[i]] += k[i] end return K end function calculate_element_internal_forces(properties, u) P_element_local = Array{Array{Float64, 1}}(undef, length(properties.L)) for i in eachindex(properties.L) u_element_global = u[properties.global_dof[i]] u_element_local = properties.Γ[i] * u_element_global P_element_local[i] = properties.ke_local[i] * u_element_local end return P_element_local end function residual(u, p) Kff, Ff = p Kff * u - Ff end function nonlinear_solution(Kff, Ff, u1f) p = [Kff, Ff] u1f = @SVector [u1f[i] for i in eachindex(u1f)] probN = NonlinearSolve.NonlinearProblem{false}(residual, u1fs, p) u2f = NonlinearSolve.solve(probN, NewtonRaphson(), tol = 1e-9) return u2f end function solve(node, cross_section, material, element, supports, loads) properties = InstantFrame.define_element_properties(node, cross_section, material, element) free_dof = vec(findall(dof->dof==0, supports)) ke_local = [InstantFrame.InstantFrame.define_local_elastic_stiffness_matrix(properties.Iy[i], properties.Iz[i], properties.A[i], properties.J[i], properties.E[i], properties.ν[i], properties.L[i]) for i in eachindex(properties.L)] ke_global = [properties.Γ[i]'*ke_local[i]*properties.Γ[i] for i in eachindex(properties.L)] Ke = InstantFrame.assemble_stiffness_matrix(ke_global, properties.global_dof) Ff = loads[free_dof] Ke_ff = Ke[free_dof, free_dof] u1f = Ke_ff \ Ff u1 = zeros(Float64, size(Ke,1)) u1[free_dof] = u1f P1 = InstantFrame.calculate_element_internal_forces(properties, u1) P1_axial = [P_local_1[i][7] for i in eachindex(P1)] kg_local = [InstantFrame.define_local_geometric_stiffness_matrix(P1_axial[i], properties.L[i]) for i in eachindex(properties.L)] kg_global = [properties.Γ[i]'*kg_local[i]*properties.Γ[i] for i in eachindex(properties.L)] Kg = InstantFrame.assemble_stiffness_matrix(kg_global, properties.global_dof) Kg_ff = Kg[free_dof, free_dof] Kff = Ke_ff + Kg_ff # u2f = nonlinear_solution(Kff, Ff, u1f) # u2 = zeros(Float64, size(Ke,1)) # u2[free_dof] = u2f # P2 = InstantFrame.calculate_element_internal_forces(properties, u2) # equations = Equations(free_dof, ke_local, ke_global, Ke, kg_local, kg_global, Kg) # solution = Solution(u1, P1, u2, P2) # model = Model(properties, equations, solution) return Kff end
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
494
using InstantFrame #use Sennett Eq. 7-54 to obtain element stiffness matrix including a hinge at the left end. I = 100.0 A = 10.0 E = 29E6 L = 120.0 ke = InstantFrame.define_local_elastic_element_stiffness_matrix(I, A, E, L) p = [1; 2; 4; 5; 6] s = [3] #hinge at left end k_pp = ke[p, p] k_ps = ke[p, s] k_ss = ke[s, s] k_sp = ke[s, p] ke_condensed = k_pp - k_ps*k_ss^-1*k_sp ke_updated = zeros(Float64, 6, 6) ke_updated[p, p] = ke_condensed #This matches Sennett book Eq. 7-38.
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
976
using InstantFrame #use modified version of Sennett Eq. 7-54 to obtain element stiffness matrix including partial restraint at the left end. I = 100.0 A = 10.0 E = 29E6 L = 120.0 ke = InstantFrame.define_local_elastic_element_stiffness_matrix(I, A, E, L) k1 = 0.0 #lb-in./rad this is consistent with a typical rack connection. k2 = 3000000000000000000000.0 #lb-in./rad ke = InstantFrame.define_local_elastic_element_stiffness_matrix_condensed(I, A, E, L, k1, k2) #From Zeimian Example 13.7 α1 = k1/(E*I/L) α2 = k2/(E*I/L) Kbb = E*I/L*[4+α1 2 2 4+α2] Kbc = E*I/L * [6/L -α1 -6/L 0 6/L 0 -6/L -α2] Kcc = E*I/L*[12/L^2 0 -12/L^2 0 0 α1 0 0 -12/L^2 0 12/L^2 0 0 0 0 α2] Kcc_bar = Kcc - Kbc'*Kbb^-1*Kbc #Check against Sennett Eq. 7.37 3*E*I/L^3 #Kcc_bar[1,1] matches
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1769
using InstantFrame #use modified version of Sennett Eq. 7-54 to obtain element stiffness matrix including partial restraint at the left end. I = 100.0 A = 10.0 E = 29E6 L = 120.0 ke = InstantFrame.define_local_elastic_element_stiffness_matrix(I, A, E, L) #Insert a rotational spring at the left end of the frame element. # p = [1; 2; 4; 5; 6] # s = [3] #spring at left end kϕ1 = 300000.0 #lb-in./rad this is consistent with a typical rack connection. k_spring_left = zeros(Float64, 6, 6) k_spring_left[3, 3] = kϕ1 k_spring_left[3, 6] = -kϕ1 k_spring_left[6, 3] = -kϕ1 k_spring_left[6, 6] = kϕ1 k_sys = zeros(Float64, 9 ,9) k_sys[4:9, 4:9] = ke k_sys[1:6, 1:6] = k_sys[1:6, 1:6] + k_spring_left s = [4;5;6] p = [1;2;3;7;8;9] # k_spring = zeros(Float64, 6, 6) # k_spring[s, s] .= kϕ_left k_pp = k_sys[p, p] k_ps = k_sys[p, s] k_ss = k_sys[s, s] k_sp = k_sys[s, p] # k_spring_s = k_spring[s, s] ke_condensed = k_pp - k_ps*k_ss^-1*k_sp ke_updated = zeros(Float64, 6, 6) ke_updated[p, p] = ke_condensed #From Zeimian 13.31... k1 = kϕ_left α1 = k1/(E*I/L) α2 = k1*1000000000000.0 α = (α1 * α2) / (α1*α2 + 4*α1 + 4*α2 + 12) α*E*I/L * 12/L^2*(1 + (α1 + α2)/(α1*α2)) #This matches the Sennett static condensation, 5081=5081. #Now analyze a beam with a hinge and vertical roller at the left end, and fixed at the right end. Apply a vertical force at the left end. Ke = ke_updated #Define the frame loading as an external force vector. F = [0., 1000.0, 0., 0., 0., 0.] #Define the frame boundary conditions. free_dof = [2] #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] #Solution uf = Ke_ff \ Ff u = zeros(Float64, 12) u[free_dof] = uf #This matches Mastan2, 0.1968 in.
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1236
using InstantFrame #use modified version of Sennett Eq. 7-54 to obtain element stiffness matrix including partial restraint at the left end. I = 100.0 A = 10.0 E = 29E6 L = 120.0 ke = InstantFrame.define_local_elastic_element_stiffness_matrix(I, A, E, L) k1 = 300000.0 #lb-in./rad this is consistent with a typical rack connection. k2 = 300000.0 #lb-in./rad this is consistent with a typical rack connection. ke = InstantFrame.define_local_elastic_element_stiffness_matrix_condensed(I, A, E, L, k1, k2) #From Zeimian 13.31... α1 = k1/(E*I/L) α2 = k2/(E*I/L) α = (α1 * α2) / (α1*α2 + 4*α1 + 4*α2 + 12) α*E*I/L * 12/L^2*(1 + (α1 + α2)/(α1*α2)) #This matches the Sennett static condensation, 5081=5081. #Now analyze a beam with a hinge and vertical roller at the left end, and fixed at the right end. Apply a vertical force at the left end. Ke = ke_updated #Define the frame loading as an external force vector. F = [0., 1000.0, 0., 0., 0., 0.] #Define the frame boundary conditions. free_dof = [2] #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] #Solution uf = Ke_ff \ Ff u = zeros(Float64, 12) u[free_dof] = uf #This matches Mastan2, 0.1968 in.
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1045
using InstantFrame #use modified version of Sennett Eq. 7-54 to obtain element stiffness matrix including partial restraint at the left end. I = 100.0 A = 10.0 E = 29E6 L = 120.0 ke = InstantFrame.define_local_elastic_element_stiffness_matrix(I, A, E, L) k1 = 300000.0 #lb-in./rad this is consistent with a typical rack connection. k2 = 300000.0 #lb-in./rad this is consistent with a typical rack connection. ke = InstantFrame.define_local_elastic_element_stiffness_matrix_condensed(I, A, E, L, k1, k2) #From Zeimian Example 13.7 α1 = k1/(E*I/L) α2 = k2/(E*I/L) Kbb = E*I/L*[4+α1 2 2 4+α2] Kbc = E*I/L * [6/L -α1 -6/L 0 6/L 0 -6/L -α2] Kcc = E*I/L*[12/L^2 0 -12/L^2 0 0 α1 0 0 -12/L^2 0 12/L^2 0 0 0 0 α2] Kcc_bar = Kcc - Kbc'*Kbb^-1*Kbc #Check against Zeimian Eq. 13.31 α = (α1 * α2) / (α1*α2 + 4*α1 + 4*α2 + 12) α*E*I/L * 12/L^2*(1 + (α1 + α2)/(α1*α2)) #Kcc_bar[1,1] matches
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
code
1482
using InstantFrame #use modified version of Sennett Eq. 7-54 to obtain element stiffness matrix including partial restraint at the left end. I = 100.0 A = 10.0 E = 29E6 L = 120.0 ke = InstantFrame.define_local_elastic_element_stiffness_matrix(I, A, E, L) #Insert a rotational spring at the left and right ends of the frame element. p = [1; 2; 4; 5] s = [3; 6] #spring at left end kϕ = 300000.0 #lb-in./rad this is consistent with a typical rack connection. k_spring = zeros(Float64, 6, 6) k_spring[s, s] .= kϕ k_pp = ke[p, p] k_ps = ke[p, s] k_ss = ke[s, s] k_sp = ke[s, p] k_spring_s = k_spring[s, s] ke_condensed = k_pp - k_ps*(k_ss+k_spring_s)^-1*k_sp ke_updated = zeros(Float64, 6, 6) ke_updated[p, p] = ke_condensed #From Zeimian 13.31... k1 = kϕ α1 = k1/(E*I/L) k2 = kϕ α2 = k2/(E*I/L) α = (α1 * α2) / (α1*α2 + 4*α1 + 4*α2 + 12) α*E*I/L * 12/L^2*(1 + (α1 + α2)/(α1*α2)) #This matches the Sennett static condensation, 5081=5081. #Now analyze a beam with a hinge and vertical roller at the left end, and fixed at the right end. Apply a vertical force at the left end. Ke = ke_updated #Define the frame loading as an external force vector. F = [0., 1000.0, 0., 0., 0., 0.] #Define the frame boundary conditions. free_dof = [2] #Partition external force vector and elastic stiffness matrix. Ff = F[free_dof] Ke_ff = Ke[free_dof, free_dof] #Solution uf = Ke_ff \ Ff u = zeros(Float64, 12) u[free_dof] = uf #This matches Mastan2, 0.1968 in.
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
8bbc6c27396367515c9a7c2c19a4a08adf301cbb
docs
2371
InstantFrame.jl ============= Perform fast structural analysis of 3D frames. **Installation**: at the Julia REPL, `using Pkg; Pkg.add(url="https://github.com/runtosolve/InstantFrame.jl.git")` **Features**: * first and second order analysis * vibration modal analysis * pinned and semi-rigid connections and supports **Formulations and Algorithms**: Element formulations and solution algorithms are inspired by and validated with [MASTAN2](https://www.mastan2.com/about.html) and the supporting textbook [Matrix Structural Analysis, 2nd Edition, by McGuire, Gallagher, and Ziemian](https://www.mastan2.com/textbook.html). **Example**: ```julia using InstantFrame material = InstantFrame.Material(names=["steel"], E=[29500.0], ν=[0.3], ρ=[492.0 / 32.17 / 12^4 / 1000]) ##ρ = kips * s^2 / in^4 cross_section = InstantFrame.CrossSection(names=["top chord", "bottom chord", "post"], A=[1.0, 2.0, 3.0], Iy=[3.1, 4.2, 2.3], Iz= [2.4, 6.5, 4.6], J=[0.001, 0.002, 0.005]) connection = InstantFrame.Connection(names=["rigid", "pinned"], stiffness=(ux=[Inf, Inf], uy=[Inf, Inf], uz=[Inf, Inf], rx=[Inf, Inf], ry=[Inf, 0.0], rz=[Inf, 0.0])) node = InstantFrame.Node(numbers=[1, 2, 3, 4], coordinates=[(0.0, 0.0, 0.0), (300.0, 0.0, 0.0), (600.0, 0.0, 0.0), (300.0, -30.0, 0.0)]) element = InstantFrame.Element(numbers=[1, 2, 3, 4, 5], nodes = [(1,2), (2,3), (1,4), (3,4), (2,4)], orientation = [0.0, 0.0, 0.0, 0.0, 0.0], connections=[("rigid", "rigid"), ("rigid", "rigid"), ("pinned", "pinned"), ("pinned", "pinned"), ("rigid", "pinned")], cross_section= ["top chord", "top chord", "bottom chord", "bottom chord", "post"], material = ["steel", "steel", "steel", "steel", "steel"], types=["frame", "frame", "frame", "frame", "frame"]) support = InstantFrame.Support(nodes=[1, 3], stiffness=(uX=[Inf,Inf], uY=[Inf,Inf], uZ=[Inf,Inf], rX=[Inf,Inf], rY=[Inf,Inf], rZ=[0.0,0.0])) uniform_load = InstantFrame.UniformLoad(labels=["snow", "snow"], elements=[1, 2], magnitudes=(qX=[0.0, 0.0], qY=[-0.100, -0.100], qZ=[0.0, 0.0], mX=[0.0,0.0], mY=[0.0,0.0], mZ=[0.0,0.0])) point_load = InstantFrame.PointLoad(labels = ["lights"], nodes=[4], magnitudes=(FX=[0.0], FY=[-0.500], FZ=[0.0], MX=[0.0], MY=[0.0], MZ=[0.0])) model = InstantFrame.solve(node, cross_section, material, connection, element, support, uniform_load, point_load, analysis_type="first order") ```
InstantFrame
https://github.com/runtosolve/InstantFrame.jl.git
[ "MIT" ]
0.1.0
f57516a005066f06c522b66f7fa74b94a2e43ee0
code
596
using PyFortran90Namelists using Documenter makedocs(; modules = [PyFortran90Namelists], authors = "Qi Zhang <[email protected]>", repo = "https://github.com/singularitti/PyFortran90Namelists.jl/blob/{commit}{path}#L{line}", sitename = "PyFortran90Namelists.jl", format = Documenter.HTML(; prettyurls = get(ENV, "CI", "false") == "true", canonical = "https://singularitti.github.io/PyFortran90Namelists.jl", assets = String[], ), pages = ["Home" => "index.md"], ) deploydocs(; repo = "github.com/singularitti/PyFortran90Namelists.jl")
PyFortran90Namelists
https://github.com/singularitti/PyFortran90Namelists.jl.git
[ "MIT" ]
0.1.0
f57516a005066f06c522b66f7fa74b94a2e43ee0
code
129
module PyFortran90Namelists include("init.jl") include("convert.jl") include("tokenizer.jl") include("parser.jl") end # module
PyFortran90Namelists
https://github.com/singularitti/PyFortran90Namelists.jl.git
[ "MIT" ]
0.1.0
f57516a005066f06c522b66f7fa74b94a2e43ee0
code
1858
export fparse, fstring function fparse(::Type{T}, s::AbstractString) where {T<:Integer} return parse(T, s) end function fparse(::Type{T}, s::AbstractString) where {T<:Float32} return parse(T, replace(lowercase(s), r"(?<=[^e])(?=[+-])" => "f")) end function fparse(::Type{T}, s::AbstractString) where {T<:Float64} return parse(T, replace(lowercase(s), r"d"i => "e")) end function fparse(::Type{Complex{T}}, str::AbstractString) where {T<:AbstractFloat} if first(str) == '(' && last(str) == ')' && length(split(str, ',')) == 2 re, im = split(str[2:end-1], ',', limit = 2) return Complex(parse(T, re), parse(T, im)) else throw(Meta.ParseError("$str must be in complex number form (x, y).")) end end function fparse(::Type{Bool}, s::AbstractString) str = lowercase(s) if str in (".true.", ".t.", "true", 't') return true elseif str in (".false.", ".f.", "false", 'f') return false else throw(Meta.ParseError("$str is not a valid logical constant.")) end end function fparse(::Type{String}, str::AbstractString) m = match(r"([\"'])((?:\\\1|.)*?)\1", str) if m === nothing throw(Meta.ParseError("$str is not a valid string!")) else quotation_mark, content = m.captures # Replace escaped strings return string(replace(content, repeat(quotation_mark, 2) => quotation_mark)) end end fstring(v::Integer) = string(v) function fstring(v::Float32; scientific::Bool = false) str = string(v) return scientific ? replace(str, r"f"i => "e") : str end function fstring(v::Float64, scientific::Bool = false) str = string(v) return scientific ? replace(str, r"e"i => "d") : str end fstring(v::Bool) = v ? ".true." : ".false." fstring(v::Union{AbstractString,AbstractChar}) = "'" * v * "'" # fstring(::Namelist) # TODO:
PyFortran90Namelists
https://github.com/singularitti/PyFortran90Namelists.jl.git
[ "MIT" ]
0.1.0
f57516a005066f06c522b66f7fa74b94a2e43ee0
code
1993
__precompile__() # this module is safe to precompile using Conda: add_channel using PyCall: PyNULL, PyError, PyObject, PyAny, pyimport_conda, pycall using VersionParsing: vparse # Extending methods import PyCall export f90nml const f90nml = PyNULL() add_channel("conda-forge") function __init__() copy!(f90nml, pyimport_conda("f90nml", "f90nml", "conda-forge")) # Code from https://github.com/JuliaPy/PyPlot.jl/blob/caf7f89/src/init.jl#L168-L173 vers = f90nml.__version__ global version = try vparse(vers) catch v"0.0.0" # fallback end end macro pyinterface(T) T = esc(T) return quote # Code from https://github.com/JuliaPy/PyPlot.jl/blob/6b38c75/src/PyPlot.jl#L54-L62 PyCall.PyObject(f::$T) = getfield(f, :o) Base.convert(::Type{$T}, o::PyObject) = $T(o) Base.:(==)(f::$T, g::$T) = PyObject(f) == PyObject(g) Base.:(==)(f::$T, g::PyObject) = PyObject(f) == g Base.:(==)(f::PyObject, g::$T) = f == PyObject(g) Base.hash(f::$T) = hash(PyObject(f)) PyCall.pycall(f::$T, args...; kws...) = pycall(PyObject(f), args...; kws...) (f::$T)(args...; kws...) = pycall(PyObject(f), PyAny, args...; kws...) Base.Docs.doc(f::$T) = Base.Docs.doc(PyObject(f)) # Code from https://github.com/JuliaPy/PyPlot.jl/blob/6b38c75/src/PyPlot.jl#L65-L71 Base.getproperty(f::$T, s::Symbol) = getproperty(PyObject(f), s) Base.getproperty(f::$T, s::AbstractString) = getproperty(PyObject(f), s) Base.setproperty!(f::$T, s::Symbol, x) = setproperty!(PyObject(f), s, x) Base.setproperty!(f::$T, s::AbstractString, x) = setproperty!(PyObject(f), s, x) PyCall.hasproperty(f::$T, s::Symbol) = hasproperty(PyObject(f), s) Base.propertynames(f::$T) = propertynames(PyObject(f)) Base.haskey(f::$T, x) = haskey(PyObject(f), x) # Common methods Base.close(f::$T) = PyObject(f).close() end end # macro pyinterface
PyFortran90Namelists
https://github.com/singularitti/PyFortran90Namelists.jl.git
[ "MIT" ]
0.1.0
f57516a005066f06c522b66f7fa74b94a2e43ee0
code
423
using PyCall: PyObject using PyFortran90Namelists: f90nml, @pyinterface export Parser, reads mutable struct Parser o::PyObject end Parser() = Parser(f90nml.Parser()) Base.read( p::Parser, nml_fname::AbstractString, nml_patch_in = nothing, patch_fname = nothing, ) = p.read(nml_fname, nml_patch_in, patch_fname) reads(p::Parser, nml_string::AbstractString) = p.reads(nml_string) @pyinterface Parser
PyFortran90Namelists
https://github.com/singularitti/PyFortran90Namelists.jl.git
[ "MIT" ]
0.1.0
f57516a005066f06c522b66f7fa74b94a2e43ee0
code
326
using PyCall: PyObject using PyFortran90Namelists: f90nml, @pyinterface export Tokenizer, update_chars, lex mutable struct Tokenizer o::PyObject end Tokenizer() = Tokenizer(f90nml.tokenizer.Tokenizer()) update_chars(tk::Tokenizer) = tk.update_chars() lex(tk::Tokenizer, line) = tk.parse(line) @pyinterface Tokenizer
PyFortran90Namelists
https://github.com/singularitti/PyFortran90Namelists.jl.git
[ "MIT" ]
0.1.0
f57516a005066f06c522b66f7fa74b94a2e43ee0
code
112
using PyFortran90Namelists using Test @testset "PyFortran90Namelists.jl" begin include("tokenizer.jl") end
PyFortran90Namelists
https://github.com/singularitti/PyFortran90Namelists.jl.git
[ "MIT" ]
0.1.0
f57516a005066f06c522b66f7fa74b94a2e43ee0
code
50364
using Test using PyFortran90Namelists: Tokenizer, lex @testset "Test bcast" begin benchmark = [ ["&", "bcast_nml"], [" ", "x", " ", "=", " ", "2", "*", "2.0"], [" ", "y", " ", "=", " ", "3", "*"], [" ", "z", " ", "=", " ", "4", "*", ".true."], ["/"], [], ["&", "bcast_endnull_nml"], [" ", "x", " ", "=", " ", "2", "*", "2.0"], [" ", "y", " ", "=", " ", "3", "*"], ["/"], [], ["&", "bcast_mixed_nml"], [ " ", "x", " ", "=", " ", "3", "*", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [" ", "y", " ", "=", " ", "3", "*", "1", ",", " ", "2", "*", "2", ",", " ", "3"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/bcast.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test bcast target" begin benchmark = [ ["&", "bcast_nml"], [" ", "x", " ", "=", " ", "2.0", ",", " ", "2.0"], [" ", "y", " ", "=", " ", ",", " ", ",", " ", ","], [ " ", "z", " ", "=", " ", ".true.", ",", " ", ".true.", ",", " ", ".true.", ",", " ", ".true.", ], ["/"], [], ["&", "bcast_endnull_nml"], [" ", "x", " ", "=", " ", "2.0", ",", " ", "2.0"], [" ", "y", " ", "=", " ", ",", " ", ",", " ", ","], ["/"], [], ["&", "bcast_mixed_nml"], [ " ", "x", " ", "=", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [ " ", "y", " ", "=", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "2", ",", " ", "2", ",", " ", "3", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/bcast_target.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test string" begin benchmark = [ ["&", "string_nml"], [" ", "str_basic", " ", "=", " ", "'hello'"], [" ", "str_no_delim", " ", "=", " ", "hello"], [" ", "str_no_delim_no_esc", " ", "=", " ", "a''b"], [" ", "single_esc_delim", " ", "=", " ", "'a ''single'' delimiter'"], [" ", "double_esc_delim", " ", "=", " ", "\"a \"\"double\"\" delimiter\""], [" ", "double_nested", " ", "=", " ", "\"''x'' \"\"y\"\"\""], [" ", "str_list", " ", "=", " ", "'a'", ",", " ", "'b'", ",", " ", "'c'"], [" ", "slist_no_space", " ", "=", " ", "'a'", ",", "'b'", ",", "'c'"], [" ", "slist_no_quote", " ", "=", " ", "a", ",", "b", ",", "c"], [" ", "slash", " ", "=", " ", "'back\\slash'"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/string.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test dollar" begin benchmark = [[raw"$", "dollar_nml"], [" ", "v", " ", "=", " ", "1.00"], [raw"$"]] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/dollar.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test dollar target" begin benchmark = [["&", "dollar_nml"], [" ", "v", " ", "=", " ", "1.0"], ["/"]] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/dollar_target.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test comment argument" begin benchmark = [ ["&", "comment_alt_nml"], [" ", "x", " ", "=", " ", "1"], [" ", "#y = 2"], [" ", "z", " ", "=", " ", "3"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/comment_alt.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test comment patch" begin benchmark = [ ["! This is an external comment"], ["&", "comment_nml"], [" ", "v_cmt_inline", " ", "=", " ", "456", " ", "! This is an inline comment"], [" ", "! This is a separate comment"], [" ", "v_cmt_in_str", " ", "=", " ", "'This token ! is not a comment'"], [ " ", "v_cmt_after_str", " ", "=", " ", "'This ! is not a comment'", " ", "! But this is", ], ["/"], ["! This is a post-namelist comment"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/comment_patch.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test comment target" begin benchmark = [ ["&", "comment_nml"], [" ", "v_cmt_inline", " ", "=", " ", "123"], [" ", "v_cmt_in_str", " ", "=", " ", "'This token ! is not a comment'"], [" ", "v_cmt_after_str", " ", "=", " ", "'This ! is not a comment'"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/comment_target.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test comment" begin benchmark = [ ["! This is an external comment"], ["&", "comment_nml"], [" ", "v_cmt_inline", " ", "=", " ", "123", " ", "! This is an inline comment"], [" ", "! This is a separate comment"], [" ", "v_cmt_in_str", " ", "=", " ", "'This token ! is not a comment'"], [ " ", "v_cmt_after_str", " ", "=", " ", "'This ! is not a comment'", " ", "! But this is", ], ["/"], ["! This is a post-namelist comment"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/comment.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test default index" begin benchmark = [ ["&", "default_index_nml"], [ " ", "v", "(", "3", ":", "5", ")", " ", "=", " ", "3", ",", " ", "4", ",", " ", "5", ], [" ", "v", " ", "=", " ", "1", ",", " ", "2"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/default_index.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test empty namelist" begin benchmark = [["&", "empty_nml"], ["/"]] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/empty.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test external token" begin benchmark = [ ["a"], ["123"], ["&", "ext_token_nml"], [" ", "x", " ", "=", " ", "1"], ["/"], ["456"], ["z"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/ext_token.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset # FIXME: # @testset "Test external comment" begin # benchmark = [[], # ["&", "efitin"], # ["abc", " ", "=", " ", "0"], # ["/"]] # tk = Tokenizer() # open(joinpath(dirname(@__FILE__), "data/extern_cmt.nml"), "r") do io # for (i, line) in enumerate(eachline(io)) # @test lex(tk, line) == benchmark[i] # end # end # end # testset @testset "Test float" begin benchmark = [ ["&", "float_nml"], [" ", "v_float", " ", "=", " ", "1.0"], [" ", "v_decimal_start", " ", "=", " ", ".1"], [" ", "v_decimal_end", " ", "=", " ", "1."], [" ", "v_negative", " ", "=", " ", "-1."], [], [" ", "v_single", " ", "=", " ", "1.0e0"], [" ", "v_double", " ", "=", " ", "1.0d0"], [], [" ", "v_single_upper", " ", "=", " ", "1.0E0"], [" ", "v_double_upper", " ", "=", " ", "1.0D0"], [], [" ", "v_positive_index", " ", "=", " ", "1.0e+01"], [" ", "v_negative_index", " ", "=", " ", "1.0e-01"], [], [" ", "v_no_exp_pos", " ", "=", " ", "1+0"], [" ", "v_no_exp_neg", " ", "=", " ", "1-0"], [" ", "v_no_exp_pos_dot", " ", "=", " ", "1.+0"], [" ", "v_no_exp_neg_dot", " ", "=", " ", "1.-0"], [" ", "v_neg_no_exp_pos", " ", "=", " ", "-1+0"], [" ", "v_neg_no_exp_neg", " ", "=", " ", "-1-0"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/float.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test float target" begin benchmark = [ ["&", "float_nml"], [" ", "v_float", " ", "=", " ", "1.0"], [" ", "v_decimal_start", " ", "=", " ", "0.1"], [" ", "v_decimal_end", " ", "=", " ", "1.0"], [" ", "v_negative", " ", "=", " ", "-1.0"], [" ", "v_single", " ", "=", " ", "1.0"], [" ", "v_double", " ", "=", " ", "1.0"], [" ", "v_single_upper", " ", "=", " ", "1.0"], [" ", "v_double_upper", " ", "=", " ", "1.0"], [" ", "v_positive_index", " ", "=", " ", "10.0"], [" ", "v_negative_index", " ", "=", " ", "0.1"], [" ", "v_no_exp_pos", " ", "=", " ", "1.0"], [" ", "v_no_exp_neg", " ", "=", " ", "1.0"], [" ", "v_no_exp_pos_dot", " ", "=", " ", "1.0"], [" ", "v_no_exp_neg_dot", " ", "=", " ", "1.0"], [" ", "v_neg_no_exp_pos", " ", "=", " ", "-1.0"], [" ", "v_neg_no_exp_neg", " ", "=", " ", "-1.0"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/float_target.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test float format" begin benchmark = [ ["&", "float_nml"], [" ", "v_float", " ", "=", " ", "1.000"], [" ", "v_decimal_start", " ", "=", " ", "0.100"], [" ", "v_decimal_end", " ", "=", " ", "1.000"], [" ", "v_negative", " ", "=", " ", "-1.000"], [" ", "v_single", " ", "=", " ", "1.000"], [" ", "v_double", " ", "=", " ", "1.000"], [" ", "v_single_upper", " ", "=", " ", "1.000"], [" ", "v_double_upper", " ", "=", " ", "1.000"], [" ", "v_positive_index", " ", "=", " ", "10.000"], [" ", "v_negative_index", " ", "=", " ", "0.100"], [" ", "v_no_exp_pos", " ", "=", " ", "1.000"], [" ", "v_no_exp_neg", " ", "=", " ", "1.000"], [" ", "v_no_exp_pos_dot", " ", "=", " ", "1.000"], [" ", "v_no_exp_neg_dot", " ", "=", " ", "1.000"], [" ", "v_neg_no_exp_pos", " ", "=", " ", "-1.000"], [" ", "v_neg_no_exp_neg", " ", "=", " ", "-1.000"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/float_format.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test global index" begin benchmark = [ ["&", "global_index_nml"], [ " ", "v_zero", "(", "0", ":", "3", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [ " ", "v_neg", "(", "-2", ":", "1", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [ " ", "v_pos", "(", "2", ":", "5", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/global_index.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test group repeat" begin benchmark = [ ["&", "grp_repeat_nml"], [" ", "x", " ", "=", " ", "1"], ["/"], ["&", "grp_repeat_nml"], [" ", "x", " ", "=", " ", "2"], ["/"], ["&", "CASE_CHECK_nml"], [" ", "y", " ", "=", " ", "1"], ["/"], ["&", "CASE_CHECK_nml"], [" ", "y", " ", "=", " ", "2"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/grp_repeat.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test group repeat target" begin benchmark = [ ["&", "grp_repeat_nml"], [" ", "x", " ", "=", " ", "1"], ["/"], [], ["&", "grp_repeat_nml"], [" ", "x", " ", "=", " ", "2"], ["/"], [], ["&", "case_check_nml"], [" ", "y", " ", "=", " ", "1"], ["/"], [], ["&", "case_check_nml"], [" ", "y", " ", "=", " ", "2"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/grp_repeat_target.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test index bad end" begin benchmark = [ ["&", "bad_index_nml"], [ " ", "y", "(", "1", ":", "~", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/index_bad_end.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test index bad start" begin benchmark = [ ["&", "bad_index_nml"], [" ", "y", "(", "1", "~", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/index_bad_start.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test index bad stride" begin benchmark = [ ["&", "bad_index_nml"], [ " ", "y", "(", "1", ":", "3", ":", "~", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/index_bad_stride.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test index bad" begin benchmark = [ ["&", "bad_index_nml"], [" ", "y", "(", "~", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/index_bad.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test index empty end" begin benchmark = [ ["&", "empty_index_nml"], [ " ", "x", "(", "1", ":", ":", "2", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/index_empty_end.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test index empty stride" begin benchmark = [ ["&", "empty_index_nml"], [ " ", "x", "(", "1", ":", "3", ":", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/index_empty_stride.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test index empty" begin benchmark = [ ["&", "empty_index_nml"], [" ", "x", "(", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/index_empty.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test index zero stride" begin benchmark = [ ["&", "bad_index_nml"], [ " ", "y", "(", "1", ":", "3", ":", "0", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/index_zero_stride.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test logical representation" begin benchmark = [ ["&", "logical_nml"], [" ", "a", " ", "=", " ", "T"], [" ", "b", " ", "=", " ", "F"], [" ", "c", " ", "=", " ", "T"], [" ", "d", " ", "=", " ", "F"], [" ", "e", " ", "=", " ", "T"], [" ", "f", " ", "=", " ", "F"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/logical_repr.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test logical" begin benchmark = [ ["&", "logical_nml"], [" ", "a", " ", "=", " ", ".true."], [" ", "b", " ", "=", " ", ".false."], [" ", "c", " ", "=", " ", "t"], [" ", "d", " ", "=", " ", "f"], [" ", "e", " ", "=", " ", ".t"], [" ", "f", " ", "=", " ", ".f"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/logical.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test multidimensional target" begin benchmark = [ ["&", "multidim_ooo_nml"], [" ", "a", "(", "1", ",", "1", ")", " ", "=", " ", "1"], [" ", "a", "(", "1", ":", "2", ",", "2", ")", " ", "=", " ", ",", " ", "2"], [" ", "b", "(", "1", ",", "1", ")", " ", "=", " ", "1"], [ " ", "b", "(", "1", ":", "3", ",", "2", ")", " ", "=", " ", ",", " ", ",", " ", "3", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/multidim_ooo_target.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test multidimensional" begin benchmark = [ ["&", "multidim_ooo_nml"], [" ", "a", "(", "2", ",", "2", ")", " ", "=", " ", "2"], [" ", "a", "(", "1", ",", "1", ")", " ", "=", " ", "1"], [], [" ", "b", "(", "3", ",", "2", ")", " ", "=", " ", "3"], [" ", "b", "(", "1", ",", "1", ")", " ", "=", " ", "1"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/multidim_ooo.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test multidimensional space" begin benchmark = [ ["&", "multidim_nml"], [ " ", "v2d", "(", "1", ":", "2", ",", " ", "1", ")", " ", "=", " ", "1", ",", " ", "2", ], [ " ", "v2d", "(", "1", ":", "2", ",", " ", "2", ")", " ", "=", " ", "3", ",", " ", "4", ], [ " ", "v3d", "(", "1", ":", "2", ",", " ", "1", ",", " ", "1", ")", " ", "=", " ", "1", ",", " ", "2", ], [ " ", "v3d", "(", "1", ":", "2", ",", " ", "2", ",", " ", "1", ")", " ", "=", " ", "3", ",", " ", "4", ], [ " ", "v3d", "(", "1", ":", "2", ",", " ", "1", ",", " ", "2", ")", " ", "=", " ", "5", ",", " ", "6", ], [ " ", "v3d", "(", "1", ":", "2", ",", " ", "2", ",", " ", "2", ")", " ", "=", " ", "7", ",", " ", "8", ], [ " ", "w3d", "(", "1", ":", "4", ",", " ", "1", ",", " ", "1", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [ " ", "w3d", "(", "1", ":", "4", ",", " ", "2", ",", " ", "1", ")", " ", "=", " ", "5", ",", " ", "6", ",", " ", "7", ",", " ", "8", ], [ " ", "w3d", "(", "1", ":", "4", ",", " ", "3", ",", " ", "1", ")", " ", "=", " ", "9", ",", " ", "10", ",", " ", "11", ",", " ", "12", ], [ " ", "w3d", "(", "1", ":", "4", ",", " ", "1", ",", " ", "2", ")", " ", "=", " ", "13", ",", " ", "14", ",", " ", "15", ",", " ", "16", ], [ " ", "w3d", "(", "1", ":", "4", ",", " ", "2", ",", " ", "2", ")", " ", "=", " ", "17", ",", " ", "18", ",", " ", "19", ",", " ", "20", ], [ " ", "w3d", "(", "1", ":", "4", ",", " ", "3", ",", " ", "2", ")", " ", "=", " ", "21", ",", " ", "22", ",", " ", "23", ",", " ", "24", ], [ " ", "v2d_explicit", "(", "1", ":", "2", ",", " ", "1", ")", " ", "=", " ", "1", ",", " ", "2", ], [ " ", "v2d_explicit", "(", "1", ":", "2", ",", " ", "2", ")", " ", "=", " ", "3", ",", " ", "4", ], [" ", "v2d_outer", "(", "1", ",", " ", "1", ")", " ", "=", " ", "1"], [" ", "v2d_outer", "(", "1", ",", " ", "2", ")", " ", "=", " ", "2"], [" ", "v2d_outer", "(", "1", ",", " ", "3", ")", " ", "=", " ", "3"], [" ", "v2d_outer", "(", "1", ",", " ", "4", ")", " ", "=", " ", "4"], [ " ", "v2d_inner", "(", ":", ",", " ", "1", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [ " ", "v2d_sparse", "(", ":", ",", " ", "1", ")", " ", "=", " ", "1", ",", " ", "2", ], [" ", "v2d_sparse", "(", ":", ",", " ", "2", ")", " ", "=", " ", ",", " ", ","], [ " ", "v2d_sparse", "(", ":", ",", " ", "3", ")", " ", "=", " ", "5", ",", " ", "6", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/multidim_space.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test multidimensional target" begin benchmark = [ ["&", "multidim_nml"], [ " ", "v2d", "(", "1", ":", "2", ",", "1", ")", " ", "=", " ", "1", ",", " ", "2", ], [ " ", "v2d", "(", "1", ":", "2", ",", "2", ")", " ", "=", " ", "3", ",", " ", "4", ], [ " ", "v3d", "(", "1", ":", "2", ",", "1", ",", "1", ")", " ", "=", " ", "1", ",", " ", "2", ], [ " ", "v3d", "(", "1", ":", "2", ",", "2", ",", "1", ")", " ", "=", " ", "3", ",", " ", "4", ], [ " ", "v3d", "(", "1", ":", "2", ",", "1", ",", "2", ")", " ", "=", " ", "5", ",", " ", "6", ], [ " ", "v3d", "(", "1", ":", "2", ",", "2", ",", "2", ")", " ", "=", " ", "7", ",", " ", "8", ], [ " ", "w3d", "(", "1", ":", "4", ",", "1", ",", "1", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [ " ", "w3d", "(", "1", ":", "4", ",", "2", ",", "1", ")", " ", "=", " ", "5", ",", " ", "6", ",", " ", "7", ",", " ", "8", ], [ " ", "w3d", "(", "1", ":", "4", ",", "3", ",", "1", ")", " ", "=", " ", "9", ",", " ", "10", ",", " ", "11", ",", " ", "12", ], [ " ", "w3d", "(", "1", ":", "4", ",", "1", ",", "2", ")", " ", "=", " ", "13", ",", " ", "14", ",", " ", "15", ",", " ", "16", ], [ " ", "w3d", "(", "1", ":", "4", ",", "2", ",", "2", ")", " ", "=", " ", "17", ",", " ", "18", ",", " ", "19", ",", " ", "20", ], [ " ", "w3d", "(", "1", ":", "4", ",", "3", ",", "2", ")", " ", "=", " ", "21", ",", " ", "22", ",", " ", "23", ",", " ", "24", ], [ " ", "v2d_explicit", "(", "1", ":", "2", ",", "1", ")", " ", "=", " ", "1", ",", " ", "2", ], [ " ", "v2d_explicit", "(", "1", ":", "2", ",", "2", ")", " ", "=", " ", "3", ",", " ", "4", ], [" ", "v2d_outer", "(", "1", ",", "1", ")", " ", "=", " ", "1"], [" ", "v2d_outer", "(", "1", ",", "2", ")", " ", "=", " ", "2"], [" ", "v2d_outer", "(", "1", ",", "3", ")", " ", "=", " ", "3"], [" ", "v2d_outer", "(", "1", ",", "4", ")", " ", "=", " ", "4"], [ " ", "v2d_inner", "(", ":", ",", "1", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [" ", "v2d_sparse", "(", ":", ",", "1", ")", " ", "=", " ", "1", ",", " ", "2"], [" ", "v2d_sparse", "(", ":", ",", "2", ")", " ", "=", " ", ",", " ", ","], [" ", "v2d_sparse", "(", ":", ",", "3", ")", " ", "=", " ", "5", ",", " ", "6"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/multidim_target.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test multidimensional" begin benchmark = [ ["&", "multidim_nml"], [ " ", "v2d", "(", "1", ":", "2", ",", " ", "1", ":", "2", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [], [ " ", "v3d", "(", "1", ":", "2", ",", " ", "1", ":", "2", ",", " ", "1", ":", "2", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ",", " ", "5", ",", " ", "6", ",", " ", "7", ",", " ", "8", ], [], [ " ", "w3d", "(", "1", ":", "4", ",", " ", "1", ":", "3", ",", " ", "1", ":", "2", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ",", " ", "5", ",", " ", "6", ",", " ", "7", ",", " ", "8", ",", " ", "9", ",", " ", "10", ",", " ", "11", ",", " ", "12", ",", ], [ " ", "13", ",", " ", "14", ",", " ", "15", ",", " ", "16", ",", " ", "17", ",", " ", "18", ",", " ", "19", ",", " ", "20", ",", " ", "21", ",", " ", "22", ",", " ", "23", ",", " ", "24", ], [], [" ", "v2d_explicit", "(", "1", ",", " ", "1", ")", " ", "=", " ", "1"], [" ", "v2d_explicit", "(", "2", ",", " ", "1", ")", " ", "=", " ", "2"], [" ", "v2d_explicit", "(", "1", ",", " ", "2", ")", " ", "=", " ", "3"], [" ", "v2d_explicit", "(", "2", ",", " ", "2", ")", " ", "=", " ", "4"], [], [ " ", "v2d_outer", "(", "1", ",", " ", ":", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [ " ", "v2d_inner", "(", ":", ",", " ", "1", ")", " ", "=", " ", "1", ",", " ", "2", ",", " ", "3", ",", " ", "4", ], [], [ " ", "v2d_sparse", "(", ":", ",", " ", "1", ")", " ", "=", " ", "1", ",", " ", "2", ], [ " ", "v2d_sparse", "(", ":", ",", " ", "3", ")", " ", "=", " ", "5", ",", " ", "6", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/multidim.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test multidimensional column width" begin benchmark = [ ["&", "multiline_nml"], [ " ", "x", " ", "=", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", ], [ " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", ], [ " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", ], [ " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", ], [" ", "1", ",", " ", "1", ",", " ", "1"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/multiline_colwidth.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test multiline index" begin benchmark = [ ["&", "multiline_nml"], [ " ", "x", "(", "1", ":", "47", ")", " ", "=", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", ], [ " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", ], [ " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/multiline_index.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset @testset "Test multiline" begin benchmark = [ ["&", "multiline_nml"], [ " ", "x", " ", "=", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", ], [ " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", " ", "1", ",", ], [" ", "1", ",", " ", "1", ",", " ", "1"], ["/"], ] tk = Tokenizer() open(joinpath(dirname(@__FILE__), "data/multiline.nml"), "r") do io for (i, line) in enumerate(eachline(io)) @test lex(tk, line) == benchmark[i] end end end # testset
PyFortran90Namelists
https://github.com/singularitti/PyFortran90Namelists.jl.git
[ "MIT" ]
0.1.0
f57516a005066f06c522b66f7fa74b94a2e43ee0
docs
1448
# PyFortran90Namelists [![Build Status](https://github.com/singularitti/PyFortran90Namelists.jl/workflows/CI/badge.svg)](https://github.com/singularitti/PyFortran90Namelists.jl/actions) [![Build Status](https://travis-ci.com/singularitti/PyFortran90Namelists.jl.svg?branch=master)](https://travis-ci.com/singularitti/PyFortran90Namelists.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/singularitti/PyFortran90Namelists.jl?svg=true)](https://ci.appveyor.com/project/singularitti/PyFortran90Namelists-jl) [![Build Status](https://cloud.drone.io/api/badges/singularitti/PyFortran90Namelists.jl/status.svg)](https://cloud.drone.io/singularitti/PyFortran90Namelists.jl) [![Build Status](https://api.cirrus-ci.com/github/singularitti/PyFortran90Namelists.jl.svg)](https://cirrus-ci.com/github/singularitti/PyFortran90Namelists.jl) [![Coverage](https://codecov.io/gh/singularitti/PyFortran90Namelists.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/singularitti/PyFortran90Namelists.jl) [![Coverage](https://coveralls.io/repos/github/singularitti/PyFortran90Namelists.jl/badge.svg?branch=master)](https://coveralls.io/github/singularitti/PyFortran90Namelists.jl?branch=master) [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://singularitti.github.io/PyFortran90Namelists.jl/stable) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://singularitti.github.io/PyFortran90Namelists.jl/dev)
PyFortran90Namelists
https://github.com/singularitti/PyFortran90Namelists.jl.git
[ "MIT" ]
0.1.0
f57516a005066f06c522b66f7fa74b94a2e43ee0
docs
140
```@meta CurrentModule = PyFortran90Namelists ``` # PyFortran90Namelists ```@index ``` ```@autodocs Modules = [PyFortran90Namelists] ```
PyFortran90Namelists
https://github.com/singularitti/PyFortran90Namelists.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
184
using Documenter, JetPackTransforms makedocs(sitename = "JetPackTransforms", modules=[JetPackTransforms]) deploydocs( repo = "github.com/ChevronETC/JetPackTransforms.jl.git", )
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
233
module JetPackTransforms using FFTW, JetPack, Jets, LinearAlgebra, Wavelets include("jop_dct.jl") include("jop_dwt.jl") include("jop_fft.jl") include("jop_sft.jl") include("jop_slantstack.jl") # requires JopTaper from JetPack end
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
1591
""" A = JopDct(T, n...[;dims=()]) where `A` is a type II discrete cosine transfrom (DCT), T is the element type of the domain and range if A, and n is the size of A. If `dims` is not set, then `A` is the N-dimensional DCT and where `N=length(n)`. Otherwise, `A` is a DCT over the dimensions specified by `dims`. # Examples ## 1D ```julia A = JopDct(Float64, 128) m = rand(domain(A)) d = A*m ``` ## 2D ```julia A = JopDct(Float64, 128, 64) m = rand(domain(A)) d = A*m ``` ## 2D transform over 3D array ```julia A = JopDct(Float64,128,64,32;dims=(1,2)) m = rand(domain(A)) d = A*m ``` # Notes * the adjoint pair is achieved by application `sqrt(2/N)` and `sqrt(2)` factors. See: * https://en.wikipedia.org/wiki/Discrete_cosine_transform * http://www.fftw.org/fftw3_doc/1d-Real_002deven-DFTs-_0028DCTs_0029.html#g_t1d-Real_002deven-DFTs-_0028DCTs_0029 """ function JopDct(T, n...; dims=()) dims = dims == () ? ntuple(i->i, length(n)) : dims JopLn(df! = JopDct_df!, df′! = JopDct_df′!, dom = JetSpace(T, n), rng = JetSpace(T, n), s = (dims=dims,)) end export JopDct function JopDct_df!(d::AbstractArray{T}, m::AbstractArray{T}; dims, kwargs...) where {T} d .= m dct!(d, dims) sc1, sc = dctscale(dims, size(m), T) d[1] *= sc1 d .*= sc end function JopDct_df′!(m::AbstractArray{T}, d::AbstractArray{T}; dims, kwargs...) where {T} m .= d sc1, sc = dctscale(dims, size(m), T) m[1] *= sc1 idct!(m, dims) m .*= sc end dctscale(dims, n, ::Type{T}) where {T} = length(dims)*sqrt(T(2)), T(sqrt(1.0/mapreduce(dim->n[dim], *, dims)))
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
1904
""" A = JopDwt(T, n...[, wt=wavelet(WT.haar, WT.Lifting)]) `A` is the N-D (N=1,2 or 3) wavelet transform operator, operating on the domain of type `T` and dimensions `n`. The optional argument `wt` is the wavelet type. The supported wavelet types are `WT.haar` and `WT.db` (Daubechies). # Notes * For 2 and 3 dimensional transforms the domain must be square. In other-words, `size(dom,1)==size(dom,2)==size(dom,3)`. * If your domain is rectangular, please consider using 1D wavelet transforms in combination wih the kronecker product (`JopKron`). * The wavelet transform is provide by the Wavelets.jl package: `http://github.com/JuliaDSP/Wavelets.jl` * You may try other wavelet classes supported by `Wavelets.jl`; however, these have yet to be tested for correctness with respect to the transpose. # Example ```julia A = JopDwt(Float64, 64, 64; wt=wavelet(WT.db5)) d = A*rand(domain(A)) ``` """ function JopDwt(sp::JetSpace; wt=wavelet(WT.haar, WT.Lifting)) n = size(sp) @assert length(n) <= 3 map(i->@assert(n[i]==n[1]), 2:length(n)) @assert n[1] == nextpow(2, n[1]) wt.name != "haar" && startswith(wt.name, "db") != true && error("JopDwt only supports Haar and Daubechies wavelet functions") JopLn(dom = sp, rng = sp, df! = JopDwt_df!, df′! = JopDwt_df′!, s = (wt=wt,)) end JopDwt(::Type{T}, n::Vararg{N}; kwargs...) where {T,N} = JopDwt(JetSpace(T,n); kwargs...) export JopDwt function JopDwt_df!(d::AbstractArray, m::AbstractArray; wt, kwargs...) # dwt! does not work without copy for all wt # if ok with copy and gc copyto!(d, dwt(m, wt)) #copyto!(d, m) #dwt!(d, op.wt, maxtransformlevels(m)) end function JopDwt_df′!(m::AbstractArray, d::AbstractArray; wt, kwargs...) # idwt! does not work without copy for all wt # if ok with copy and gc copyto!(m, idwt(d, wt)) #copyto!(m, d) #idwt!(m, op.wt, maxtransformlevels(d)) end
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
3950
""" A = JopFft(T, n...[; dims=()]) where `A` is a Fourier transform, the domain of A is (T,n). If `dims` is not set, then `A` is an N-dimensional Fourier transform and where `N=ndims(dom)`. Otherwise, `A` is a Fourier transform over the dimensions specifed by `dims`. For a complex-to-complex transform: `range(A)::JetSpace`. For a real-to-complex transform: `range(A)::JetSpaceSymmetric`. Normally, JopFft is responsible for constructing range(A). In the event that you need to manually construct this space, we provide a convenience method: R = symspace(JopLn{JopFft_df!}, T, symdim, n...) where `T` is the precision (generally `Float32` or `Float64`), `n...` is the dimensions of the domain of `A`, and `symdim` is the first dimension begin Fourier transformed. # Examples ## 1D, real to complex ```julia A = JopFft(Float64,128) m = rand(domain(A)) d = A*m ``` ## 1D, complex to complex ```julia A = JopFft(ComplexF64,128) m = rand(domain(A)) d = A*m ``` ## 2D, real to complex ```julia A = JopFft(Float64,128,256) m = rand(domain(A)) d = A*m ``` ## 3D, real to complex, transforming over only the first dimension ```julia A = JopFft(Float64,128,256; dims=(1,)) m = rand(domain(A)) d = A*m ``` """ function JopFft(::Type{T},n::Vararg{Int,N};dims=()) where {T<:Real,N} dims = isempty(dims) ? ntuple(i->i, N) : dims JopLn(dom = JetSpace(T,n), rng = symspace(typeof(JopFft_df!),T,dims[1],n...), df! = JopFft_df!, df′! = JopFft_df′!, s = (dims=dims,)) end function JopFft(::Type{T},n::Vararg{Int,N};dims=()) where {T<:Complex,N} dims = isempty(dims) ? ntuple(i->i, N) : dims JopLn(dom = JetSpace(T,n), rng = JetSpace(T,n), df! = JopFft_df!, df′! = JopFft_df′!, s = (dims=dims,)) end JopFft(R::JetSpace; dims=()) = JopFft(eltype(R), size(R)...; dims=dims) export JopFft function JopFft_df!(d::Jets.SymmetricArray{Complex{T}}, m::AbstractArray{T}; kwargs...) where {T} JopFft_df!(parent(d), m; kwargs...) d end function JopFft_df!(d::Array{Complex{T}}, m::AbstractArray{T}; dims, kwargs...) where {T<:Real} P = plan_rfft(m, dims) JopFft_mul!(d, P, m, dims) d end function JopFft_df!(d::AbstractArray{T}, m::AbstractArray{T}; dims, kwargs...) where {T<:Complex} P = plan_fft(m, dims) JopFft_mul!(d, P, m, dims) d end function JopFft_mul!(d::AbstractArray{T}, P::FFTW.FFTWPlan, m::AbstractArray, dims) where {T} mul!(d, P, m) sc = fftscale(T, size(m), dims) d .*= sc end JopFft_df′!(m::AbstractArray{T}, d::Jets.SymmetricArray{Complex{T}}; kwargs...) where {T} = JopFft_df′!(m, parent(d); kwargs...) function JopFft_df′!(m::AbstractArray{T}, d::Array{Complex{T}}; dims, kwargs...) where {T<:Real} P = plan_brfft(d, size(m, dims[1]), dims) JopFft_mul_adjoint!(m, P, copy(parent(d)), dims) # in-place version of brfft modifies the input buffer m end function JopFft_df′!(m::AbstractArray{T}, d::AbstractArray; dims, kwargs...) where {T<:Complex} P = plan_bfft(d, dims) JopFft_mul_adjoint!(m, P, d, dims) m end function JopFft_mul_adjoint!(m::AbstractArray{T}, P::FFTW.FFTWPlan, d::AbstractArray, dims) where {T} mul!(m, P, d) sc = fftscale(T, size(m), dims) m .*= sc end fftscale(::Type{T}, n, dims) where {T} = T(1.0/sqrt(mapreduce(dim->n[dim], *, dims))) function _JopFft_symspace_map(idim, I, symdim, n) if idim == symdim return 2 + n[idim] - I[idim] else return I[idim] end end function JopFft_symspace_map(I, symdim::Int, n::NTuple{N,Int}, _n::NTuple{N,Int}) where {N} if I[symdim] > _n[symdim] J = ntuple(idim->_JopFft_symspace_map(idim, I, symdim, n), N) return CartesianIndex(J) else return CartesianIndex(I) end end function Jets.symspace(JopFft, ::Type{T}, symdim::Int, n::Vararg{Int,N}) where {T,N} _n = ntuple(idim->idim == symdim ? div(n[idim], 2) + 1 : n[idim], N) Jets.JetSSpace(Complex{T}, n, _n, I->JopFft_symspace_map(I, symdim, n, _n)) end
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
1972
""" op = JopSft(dom,freqs,dt) Polychromatic slow Fourier transforms for a specified list of frequencies. Tranform along the fast dimension of `dom::JetSpace{<:Real}`. Notes: - it is expected that the domain is 2D real of size [nt,ntrace] - the range will be 2D complex of size [length(freqs),ntrace] - regarding the factor of (2/n): the factor "1/n" is from the Fourier transform, and the "2" is from Hermittian symmetry. """ function JopSft(dom::JetSpace{T}, freqs::Vector, dt) where {T<:Real} @assert length(size(dom)) == 2 nf = length(freqs) n2 = size(dom,2) JopLn(dom = dom, rng = JetSpace(Complex{T}, nf, n2), df! = JopSft_df!, df′! = JopSft_df′!, s = (freqs=freqs, dt=dt)) end export JopSft function JopSft_df!(rngvec::AbstractArray{Complex{T},N}, domvec::AbstractArray{T,N}; freqs, dt, kwargs...) where {T,N} nf = length(freqs) n1 = size(domvec,1) _domvec = reshape(domvec, n1, :) _rngvec = reshape(rngvec, nf, :) @assert size(_domvec,2) == size(rngvec,2) n2 = size(_domvec,2) _rngvec .= 0 for kfreq = 1:nf for k2 = 1:n2 for k1 = 1:n1 t = dt * (k1 - 1) phs = exp(-im * 2 * pi * freqs[kfreq] * t) _rngvec[kfreq,k2] += _domvec[k1,k2] * phs end end end _rngvec .*= (2/n1) end function JopSft_df′!(domvec::AbstractArray{T,N}, rngvec::AbstractArray{Complex{T},N}; freqs, dt, kwargs...) where {T,N} nf = length(freqs) n1 = size(domvec,1) _domvec = reshape(domvec, n1, :) _rngvec = reshape(rngvec, nf, :) @assert size(_domvec,2) == size(rngvec,2) n2 = size(_domvec,2) _domvec .= 0 for kfreq = 1:nf for k2 = 1:n2 for k1 = 1:n1 t = dt * (k1 - 1) phs = exp(-im * 2 * pi * freqs[kfreq] * t) _domvec[k1,k2] += real(_rngvec[kfreq,k2] * conj(phs)) end end end _domvec .*= (2/n1) end
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
5478
""" A = JopSlantStack(dom[; dz=10.0, dh=10.0, h0=-1000.0, ...]) where `A` is the 2D slant-stack operator mapping for `z-h` to `tau-p`. The domain of the operator is `nz` x `nh` with precision T, `dz` is the depth spacing, `dh` is the half-offset spacing, and `h0` is the origin of the half-offset axis. The additional named optional arguments along with their default values are, * `theta=-60:1.0:60` - range of opening angles. The ray parameter is: p=sin(theta/2)/c * `padz=0.0,padh=0.0` - padding in depth and offset to apply before applying the Fourier transfrom * `taperz=(0,0)` - beginning and end taper in the z-direction before transforming from `z-h` to `kz-kh` * `taperh=(0,0)` - beginning and end taper in the h-direction before transforming from `z-h` to `kz-kh` * `taperkz=(0,0)` - beginning and end taper in the kz-direction before transforming from `kz-kh` to `z-h` * `taperkh=(0,0)` - beginning and end taper in the kh-direction before transforming from `kz-kh` to `z-h` # Notes * It should be possible to extend this operator to 3D * If your domain is t-h rather than z-h, you can still use this operator """ function JopSlantStack( dom::JetAbstractSpace{T}; theta = collect(-60.0:1.0:60.0), dz = -1.0, dh = -1.0, h0 = NaN, padz = 0.0, padh = 0.0, taperz = (0,0), taperh = (0,0), taperkz = (0,0), taperkh = (0,0)) where {T} dz < 0.0 && error("expected dz>0.0, got dz=$(dz)") dh < 0.0 && error("expected dh>0.0, got dh=$(dh)") isnan(h0) && error("expected finite h0, got h0=$(h0)") nz,nh = size(dom) # kz nzfft = nextprod([2,3,5,7], round(Int, nz*(1 + padz))) kn = pi/dz dk = kn/nzfft kz = dk*[0:div(nzfft,2)+1;] # kh nhfft = nextprod([2,3,5,7], round(Int, nh*(1+padh))) kn = pi/dh dk = kn/nhfft local kh if rem(nhfft,2) == 0 kh = 2*dk*[ [0:div(nhfft,2);] ; [-div(nhfft,2)+1:1:-1;] ] # factor of 2 is for kg+ks with kg=ks -- i.e. go from (kg,ks)->kh else kh = 2*dk*[ [0:div(nhfft,2);] ; [-div(nhfft,2)+0:1:-1;] ] # factor of 2 is for kg+ks with kg=ks -- i.e. go from (kg,ks)->kh end # c*p cp = sin.(.5*theta*pi/180) # factor of .5 is to make theta the opening angle -- i.e. go from (theta_s, theta_g)->theta # conversions kz,kh,cp = map(x->convert(Array{T,1}, x), (kz,kh,cp)) nzfft,nhfft = map(x->convert(Int64, x), (nzfft,nhfft)) h0 = T(h0) # tapers TX = JopTaper(dom, (1,2), (taperz[1],taperh[1]), (taperz[2],taperh[2])) TK = JopTaper(JetSpace(Complex{eltype(dom)},div(nzfft,2)+1,length(cp)), (1,2), (taperkz[1], taperkh[1]), (taperkz[2], taperkh[2]), mode=(:normal,:fftshift)) JopLn(dom = dom, rng = JetSpace(T, nz, length(cp)), df! = JopSlantStack_df!, df′! = JopSlantStack_df′!, s = (nzfft=nzfft, nhfft=nhfft, kz=kz, kh=kh, cp=cp, h0=h0, TX=TX, TK=TK)) end export JopSlantStack function JopSlantStack_df!(d::AbstractArray{T,2}, m::AbstractArray{T,2}; nzfft, nhfft, kz, kh, cp, h0, TX, TK, kwargs...) where {T} nz, nh, np, dh = size(m)..., length(cp), abs(kh[2]-kh[1]) mpad = zeros(T, nzfft, nhfft) mpad[1:nz,1:nh] = TX*m M = rfft(mpad) dtmp = similar(d) D = zeros(eltype(M), size(M,1), np) for ikz = 1:div(nzfft,2)+1, ip = 1:np ikh_m1, ikh_p1, _kh = slantstack_compute_kh(ikz, ip, cp, kz, kh, nhfft) ikh_m1 < 1 && continue if ikh_m1 == ikh_p1 D[ikz,ip] = M[ikz,ikh_p1]*exp(-im*kh[ikh_p1]*h0) continue end local d_p1, a_p1 if 1 <= ikh_p1 <= nhfft d_p1 = M[ikz,ikh_p1]*exp(-im*kh[ikh_p1]*h0) a_p1 = abs(kh[ikh_p1] - _kh)/dh else a_p1 = 0.0 end local d_m1, a_m1 if 1 <= ikh_m1 <= nhfft d_m1 = M[ikz,ikh_m1]*exp(-im*kh[ikh_m1]*h0) a_m1 = abs(_kh - kh[ikh_m1])/dh else a_m1 = 0.0 end D[ikz,ip] = a_m1*d_m1 + a_p1*d_p1 end d .= brfft(TK*D, nzfft, 1)[1:nz,1:np] ./ nzfft end function JopSlantStack_df′!(m::AbstractArray{T,2}, d::AbstractArray{T,2}; nzfft, nhfft, kz, kh, cp, h0, TX, TK, kwargs...) where {T} nz, nh, np, dh = size(m)..., length(cp), abs(kh[2]-kh[1]) dpad = zeros(T, nzfft, np) dpad[1:nz,:] = d D = TK * (rfft(dpad, 1) ./ nzfft) M = zeros(Complex{T}, div(nzfft,2)+1, nhfft) for ikz = 1:div(nzfft,2)+1, ip = 1:np ikh_m1, ikh_p1, _kh = slantstack_compute_kh(ikz, ip, cp, kz, kh, nhfft) ikh_m1 < 1 && continue if ikh_m1 == ikh_p1 M[ikz,ikh_p1] += D[ikz,ip]*exp(im*kh[ikh_p1]*h0) continue end if 1 <= ikh_p1 <= nhfft m_p1 = D[ikz,ip]*exp(im*kh[ikh_p1]*h0) a_p1 = (kh[ikh_p1] - _kh)/dh M[ikz,ikh_p1] += a_p1*m_p1 end if 1 <= ikh_m1 <= nhfft m_m1 = D[ikz,ip]*exp(im*kh[ikh_m1]*h0) a_m1 = (_kh - kh[ikh_m1])/dh M[ikz,ikh_m1] += a_m1*m_m1 end end m .= TX * (brfft(M, nzfft)[1:nz,1:nh]) end @inline function slantstack_compute_kh(ikz::Int64, ip::Int64, cp, kz, kh, nhfft) _kh = 1/(1-cp[ip]^2) - 1 _kh < 0 && return -1,-1,1.0 _kh = 2*kz[ikz]*sqrt(_kh) ikh_m1 = floor(Int64, _kh/kh[2]) + 1 ikh_p1 = ceil(Int64, _kh/kh[2]) + 1 ikh_m1 = ikh_m1 < 1 ? nhfft + ikh_m1 : ikh_m1 ikh_p1 = ikh_p1 < 1 ? nhfft + ikh_p1 : ikh_p1 ikh_m1, ikh_p1, _kh end
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
1908
using FFTW, Jets, JetPackTransforms, Test @testset "DCT, 1D" begin A = JopDct(Float64, 128) lhs, rhs = dot_product_test(A, rand(domain(A)), rand(range(A))) @test lhs ≈ rhs m = rand(domain(A)) d = A*m d_check = dct(m) d_check[1] *= sqrt(2) d_check[:] *= sqrt(1/length(m)) @test d ≈ d_check end @testset "DCT, 2D" begin A = JopDct(Float64, 128, 64) lhs, rhs = dot_product_test(A, rand(domain(A)), rand(range(A))) @test lhs ≈ rhs m = rand(domain(A)) d = A*m d_check = dct(m) d_check[1] *= 2*sqrt(2) d_check[:] *= sqrt(1/length(m)) @test d_check ≈ d A = JopDct(Float64, 128, 64; dims=(1,)) lhs, rhs = dot_product_test(A, rand(domain(A)), rand(range(A))) @test lhs ≈ rhs m = rand(domain(A)) d = A*m d_check = dct(m,1) d_check[1] *= sqrt(2) d_check[:] *= sqrt(1/size(m,1)) @test d ≈ d_check A = JopDct(Float64, 128, 64; dims=(2,)) lhs, rhs = dot_product_test(A, rand(domain(A)), rand(range(A))) @test lhs ≈ rhs m = rand(domain(A)) d = A*m d_check = dct(m,2) d_check[1] *= sqrt(2) d_check .*= sqrt(1/size(m,2)) @test d ≈ d_check end @testset "DCT, 3D" begin A = JopDct(Float64, 128, 64, 32) lhs, rhs = dot_product_test(A, rand(domain(A)), rand(range(A))) @test lhs ≈ rhs m = rand(domain(A)) d = A*m d_check = dct(m) d_check[1] *= 3*sqrt(2) d_check[:] *= sqrt(1/length(m)) @test d ≈ d_check for dims in ((1,2), (1,3), (2,1), (2,3), (1,), (2,), (3,)) A = JopDct(Float64, 128, 64, 32; dims=dims) lhs, rhs = dot_product_test(A, rand(domain(A)), rand(range(A))) @test lhs ≈ rhs m = rand(domain(A)) d = A*m d_check = dct(m,dims) d_check[1] *= length(dims)*sqrt(2) d_check[:] *= sqrt(1/mapreduce(dim->size(m,dim), *, dims)) @test d ≈ d_check end end
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
2831
using Jets, JetPackTransforms, Test, Wavelets # warning! This only tests the default Haar wavelet @testset "dwt" begin # 1D transform Haar println("1D Haar") A = JopDwt(Float64, 128) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # 2D transform Haar println("2D Haar") A = JopDwt(JetSpace(Float64, 128, 128)) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # 3D transform HAar println("3D Haar") A = JopDwt(Float64, 128, 128, 128) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # db1 wt = wavelet(WT.db1) # 1D transform println("1D $(wt.name)") A = JopDwt(Float64, 128; wt=wt) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # 2D transform println("2D $(wt.name)") A = JopDwt(Float64, 128, 128; wt=wt) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # 3D transform println("3D $(wt.name)") A = JopDwt(Float64, 128, 128, 128; wt=wt) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # db6 wt = wavelet(WT.db6) # 1D transform println("1D $(wt.name)") A = JopDwt(Float64, 128; wt=wt) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # 2D transform println("2D $(wt.name)") A = JopDwt(Float64, 128, 128; wt=wt) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # 3D transform println("3D $(wt.name)") A = JopDwt(Float64, 128, 128, 128; wt=wt) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # db10 wt = wavelet(WT.db10) # 1D transform println("1D $(wt.name)") A = JopDwt(Float64, 128; wt=wt) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # 2D transform println("2D $(wt.name)") A = JopDwt(Float64, 128, 128; wt=wt) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) # 3D transform println("3D $(wt.name)") A = JopDwt(Float64, 128, 128, 128; wt=wt) m = rand(domain(A)) d = rand(range(A)) lhs, rhs = dot_product_test(A, m, d) @test isapprox(lhs, rhs, rtol=1e-7) end
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
4593
using FFTW, Jets, JetPackTransforms, Test @testset "fft, 1D, complex" begin n = 512 m = rand(n) + im * rand(n) d = rand(n) + im * rand(n) A = JopFft(ComplexF64, n) lhs, rhs = dot_product_test(A, m, d) @test lhs ≈ rhs expected = fft(m) / sqrt(n) observed = A * m @test expected ≈ observed expected = bfft(d) / sqrt(n) observed = A' * d @test expected ≈ observed end @testset "fft, alternative constructor" begin R = JetSpace(Float64,512) A = JopFft(R) B = JopFft(Float64,512) m = rand(R) @test A*m ≈ B*m end @testset "fft, 1D, real" begin n = 512 spDom = JetSpace(Float64, n) spRng = symspace(JopFft, Float64, 1, n) m = rand(spDom) d = rand(spRng) d[1] = real(d[1]) d[length(spRng)] = d[1] A = JopFft(Float64, n) @test range(A) == spRng lhs, rhs = dot_product_test(A, m, d) @test lhs ≈ rhs end @testset "fft, 2D" begin n1, n2 = 128, 256 A = JopFft(ComplexF64, n1, n2) m = rand(domain(A)) d = rand(range(A)) #= On windows causes a segfault... presumably a bug in BLAS? =# if !Sys.iswindows() lhs, rhs = dot_product_test(A, m, d) @test lhs ≈ rhs end end @testset "fft, 2D, real->complex" begin n1, n2 = 128, 256 spDom = JetSpace(Float64, n1, n2) spRng = symspace(JopFft, Float64, 1, n1, n2) m = rand(spDom) d = rand(spRng) A = JopFft(Float64,n1,n2) @test spRng == range(A) lhs, rhs = dot_product_test(A, m, d) @test lhs ≈ rhs m = rand(spDom) m_roundtrip = A' * (A * m) @test m ≈ m_roundtrip d = A * m d_check = rfft(m) / sqrt(length(m)) @test parent(d) ≈ d_check d_copy = copy(d) mm = A' * d @test d_copy ≈ d mm_check = brfft(parent(d), n1) / sqrt(length(m)) @test mm_check ≈ mm @test mm_check ≈ m @test mm ≈ m end @testset "fft, 1D transform of 2D array" begin n1, n2 = 128, 256 A = JopFft(ComplexF64, n1, n2; dims=(1,)) m = rand(domain(A)) d = A*m d_expected = similar(d) for i2 = 1:n2 d_expected[:,i2] = fft(vec(m[:,i2])) / sqrt(n1) end @test d ≈ d_expected a = A'*d a_expected = similar(a) for i2 = 1:n2 a_expected[:,i2] = bfft(vec(d[:,i2])) / sqrt(n1) end @test a ≈ a_expected if !Sys.iswindows() lhs, rhs = dot_product_test(A,rand(domain(A)),rand(range(A))) @test lhs ≈ rhs end end @testset "fft, 1D transform of 2D array, real->complex" begin n1, n2 = 128, 256 A = JopFft(Float64, n1, n2; dims=(1,)) m = rand(domain(A)) d = A*m d_expected = similar(parent(d)) for i2 = 1:n2 d_expected[:,i2] = rfft(vec(m[:,i2])) / sqrt(n1) end @test parent(d) ≈ d_expected a = A'*d a_expected = similar(a) for i2 = 1:n2 a_expected[:,i2] = brfft(vec(parent(d)[:,i2]),n1) / sqrt(n1) end @test a ≈ a_expected lhs, rhs = dot_product_test(A,rand(domain(A)),rand(range(A))) @test lhs ≈ rhs end @testset "fft, 1D transform of 2D array, 2nd dim" begin n1, n2 = 128, 256 A = JopFft(ComplexF64, n1, n2; dims=(2,)) m = rand(domain(A)) d = A*m d_expected = similar(d) for i1 = 1:n1 d_expected[i1,:] = fft(vec(m[i1,:])) / sqrt(n2) end @test d ≈ d_expected a = A'*d a_expected = similar(a) for i1 = 1:n1 a_expected[i1,:] = bfft(vec(d_expected[i1,:])) / sqrt(n2) end @test a ≈ a_expected if !Sys.iswindows() lhs, rhs = dot_product_test(A,rand(domain(A)),rand(range(A))) @test lhs ≈ rhs end end @testset "fft, 1D transform of 2D array, 2nd dim, real->complex" begin n1, n2 = 128, 256 A = JopFft(Float64, n1, n2; dims=(2,)) m = rand(domain(A)) d = A*m d_expected = similar(parent(d)) for i1 = 1:n1 d_expected[i1,:] = rfft(vec(m[i1,:])) / sqrt(n2) end @test parent(d) ≈ d_expected a = A'*d a_expected = similar(a) for i1 = 1:n1 a_expected[i1,:] = brfft(vec(d_expected[i1,:]), n2) / sqrt(n2) end @test a ≈ a_expected lhs, rhs = dot_product_test(A,rand(domain(A)),rand(range(A))) @test lhs ≈ rhs end @testset "fft, 2D of 3D array, real to complex along first two dims" begin n1,n2,n3 = 128,256,10 A = JopFft(Float64,n1,n2,n3;dims=(1,2)) m = rand(domain(A)) d = A*m d_expected = similar(parent(d)) for i3=1:n3 d_expected[:,:,i3] = rfft(m[:,:,i3]) / sqrt(n1*n2) end @test parent(d) ≈ d_expected lhs, rhs = dot_product_test(A,rand(domain(A)),rand(range(A))) @test lhs ≈ rhs end
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
2416
using Jets, JetPackTransforms, LinearAlgebra, Test, FFTW n1,n2 = 500,5 dt = 0.001 @testset "JopSft correctness test, T=$(T)" for T in (Float64,Float32) global n1,n2,dt f = fftfreq(n1) ./ dt freqs = T[f[5],f[9],f[13]] nfreq = length(freqs) dt = convert(T,dt) dom = JetSpace(T,n1,n2) rng = JetSpace(Complex{T},nfreq,n2) op = JopSft(dom,freqs,dt) x = zeros(domain(op)) amp1 = 15.2873 amp2 = 49.39874 amp3 = 97.298743 phs1 = 0.54321 phs2 = 0.7654321 phs3 = 1.87654321 for k2 = 1:n2 for k1 = 1:n1 t = dt * (k1 - 1) x1 = amp1 * exp(im * (2 * pi * freqs[1] * t + phs1)) x2 = amp2 * exp(im * (2 * pi * freqs[2] * t + phs2)) x3 = amp3 * exp(im * (2 * pi * freqs[3] * t + phs3)) x[k1,k2] = real(x1 + x2 + x3) end end y = op * x # actual amplitude and phase a1 = abs.(y[1,:]) a2 = abs.(y[2,:]) a3 = abs.(y[3,:]) p1 = atan.(imag.(y[1,:]),real.(y[1,:])) p2 = atan.(imag.(y[2,:]),real.(y[2,:])) p3 = atan.(imag.(y[3,:]),real.(y[3,:])) rmsa1 = sqrt(norm(a1 .- amp1)^2/length(a1)) rmsa2 = sqrt(norm(a2 .- amp2)^2/length(a2)) rmsa3 = sqrt(norm(a3 .- amp3)^2/length(a3)) rmsp1 = sqrt(norm(p1 .- phs1)^2/length(p1)) rmsp2 = sqrt(norm(p2 .- phs2)^2/length(p2)) rmsp3 = sqrt(norm(p3 .- phs3)^2/length(p3)) @test rmsa1 < 1000 * eps(T) @test rmsa2 < 1000 * eps(T) @test rmsa3 < 1000 * eps(T) @test rmsp1 < 1000 * eps(T) @test rmsp2 < 1000 * eps(T) @test rmsp3 < 1000 * eps(T) end @testset "JopSft dot product test, T=$(T)" for T in (Float64,Float32) global n1,n2,dt f = fftfreq(n1) ./ dt freqs = T[f[5],f[9],f[13]] nfreq = length(freqs) dt = convert(T,dt) dom = JetSpace(T,n1,n2) rng = JetSpace(Complex{T},nfreq,n2) op = JopSft(dom,freqs,dt) x1 = rand(dom) y1 = rand(rng) y1 = op * rand(dom) lhs, rhs = dot_product_test(op, x1, y1) diff = abs((lhs - rhs) / (lhs + rhs)) @test lhs ≈ rhs end @testset "JopSft linearity test, T=$(T)" for T in (Float64,Float32) global n1,n2,dt f = fftfreq(n1) ./ dt freqs = T[f[5],f[9],f[13]] nfreq = length(freqs) dt = convert(T,dt) dom = JetSpace(T,n1,n2) rng = JetSpace(Complex{T},nfreq,n2) op = JopSft(dom,freqs,dt) lhs,rhs = linearity_test(op) @test lhs ≈ rhs end nothing
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
855
using JetPackTransforms, Jets, Test @testset "JetSlantStack, dot product test" for T in (Float32, Float64) A = JopSlantStack(JetSpace(T, 64, 128); dz=10.0, dh=10.0, h0=-1000.0) m = rand(domain(A)) d = A*m lhs, rhs = dot_product_test(A,rand(domain(A)),rand(range(A))) @test isapprox(lhs,rhs,rtol=1e-4) A = JopSlantStack(JetSpace(T, 64, 128); dz=10.0, dh=10.0, h0=-1000.0, taperz=(0.3,0.3), taperh=(0.3,0.3), taperkz=(0.3,0.3), taperkh=(0.3,0.3)) lhs, rhs = dot_product_test(A,rand(domain(A)),rand(range(A))) @test isapprox(lhs,rhs,rtol=1e-4) end @testset "JetSlantStack, correctness" begin A = JopSlantStack(JetSpace(Float64, 64, 128); dz=10.0, dh=10.0, h0=-1000.0) m = zeros(domain(A)) m[32,:] .= 1 d = A*m v,i = findmax(d) @test i[1] == 32 @test i[2] == findfirst(x->x≈0, state(A).cp) end
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
code
245
# set random seed to promote repeatability in CI unit tests using Random Random.seed!(101) for file in ( "jop_dct.jl", "jop_dwt.jl", "jop_fft.jl", "jop_sft.jl", "jop_slantstack.jl") include(file) end
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git
[ "MIT" ]
0.1.2
391a62e72e22c580c675b403009c74e93792ee14
docs
1368
# JetPackTransforms.jl contributor guidelines ## Issue reporting If you have found a bug in JetPackTransforms.jl or have any suggestions for changes to JetPackTransforms.jl functionality, please consider filing an issue using the GitHub isssue tracker. Please do not forget to search for an existing issue which may already cover your suggestion. ## Contributing We try to follow GitHub flow (https://guides.github.com/introduction/flow/) for making changes to JetPackTransforms.jl. Contributors retain copyright on their contributions, and the MIT license (https://opensource.org/licenses/MIT) applies to the contribution. The basic steps to making a contribution are as follows, and assume some knowledge of git: 1. fork the JetPackTransforms.jl repository 2. create an appropriately titled branch for your contribution 3. if applicable, add a unit-test to ensure the functionality of your contribution (see the `test` subfolder). 4. run `]test JetPackTransforms` in the `test` folder 5. make a pull-request 6. have fun ## Coding conventions We try to follow the same coding conventions as https://github.com/JuliaLang/julia. This primarily means using 4 spaces to indent (no tabs). In addition, we make a best attempt to follow the guidelines in the style guide chapter of the julia manual: https://docs.julialang.org/en/v1/manual/style-guide/
JetPackTransforms
https://github.com/ChevronETC/JetPackTransforms.jl.git