Created
June 24, 2017 09:18
-
-
Save shivin9/9cc1b745742d885b0e8e58af748f4fc4 to your computer and use it in GitHub Desktop.
Testing Neumann BCs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"using PDEOperators" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"100-element Array{Float64,1}:\n", | |
" -48.7525 \n", | |
" 1.08247e-15\n", | |
" -2.15106e-16\n", | |
" -2.70617e-16\n", | |
" 1.59595e-16\n", | |
" -3.1225e-16 \n", | |
" 9.36751e-17\n", | |
" -5.89806e-17\n", | |
" -5.89806e-17\n", | |
" 9.36751e-17\n", | |
" -9.02056e-17\n", | |
" -6.76542e-17\n", | |
" 1.17961e-16\n", | |
" ⋮ \n", | |
" 3.07046e-16\n", | |
" -6.17562e-16\n", | |
" 5.20417e-16\n", | |
" -7.56339e-16\n", | |
" 6.73073e-16\n", | |
" -5.75928e-16\n", | |
" -1.59595e-16\n", | |
" 0.158912 \n", | |
" -6.76542e-16\n", | |
" -6.76542e-16\n", | |
" -6.76542e-16\n", | |
" -52.5 " | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"A = LinearOperator{Float64}(4,4,100,:Neumann,:Neumann;bndry_fn=(2,3)); # 1st derivative values at the boundaries\n", | |
"x = collect(0 : 1/(100-1) : 1);\n", | |
"u0 = -(x - 0.5).^2 + 1/12;\n", | |
"res = A*u0" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"8-element Array{Float64,1}:\n", | |
" -2.59286 \n", | |
" 7.0 \n", | |
" -10.5 \n", | |
" 11.6667 \n", | |
" -8.75 \n", | |
" 4.2 \n", | |
" -1.16667 \n", | |
" 0.142857" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"aorder = A.boundary_length - 1;\n", | |
"T = Float64;\n", | |
"grid_step = one(T);\n", | |
"first_order_coeffs = PDEOperators.calculate_weights(1, (0)*grid_step, collect(zero(T) : grid_step : aorder* grid_step))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"126.4083333333333" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sum(first_order_coeffs.*res[1:8]) # the first derivative at x1, should be equal to 2?" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Julia 0.6.0", | |
"language": "julia", | |
"name": "julia-0.6" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "0.6.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment