mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-08-06 04:21:33 +00:00
little tuning of test, updated tests, @debug-macro, fixed notebook conversion to pdf
This commit is contained in:
+77
-21
@@ -6,32 +6,63 @@ Here are the basic steps for contributing to JuliaFEM:
|
||||
|
||||
1) Create an account or sign in to `GitHub <https://github.com/>`_.
|
||||
|
||||
2) Go to `Git home page <http://git-scm.com/>`_ and download the Git installer. Run the installer to get Git on your computer. It is a version control system used by GitHub. To learn its basics, go through this `Git tutorial <https://try.github.io/levels/1/challenges/1>`_.
|
||||
2) Go to `Git home page <http://git-scm.com/>`_ and download the Git installer.
|
||||
Run the installer to get Git on your computer. It is a version control system used
|
||||
by GitHub. To learn its basics, go through this
|
||||
`Git tutorial <https://try.github.io/levels/1/challenges/1>`_.
|
||||
|
||||
3) Install Julia (v0.4+) to your computer. At `Julia readme <https://github.com/JuliaLang/julia/blob/master/README.md>`_ you'll find complete instructions for installing it for your platform.
|
||||
3) Install Julia (v0.4+) to your computer. At
|
||||
`Julia readme <https://github.com/JuliaLang/julia/blob/master/README.md>`_
|
||||
you'll find complete instructions for installing it for your platform.
|
||||
|
||||
4) Go to the `JuliaFEM GitHub page <https://github.com/JuliaFEM/JuliaFEM.jl>`_. At the top-right corner, press the ``Fork``-button to fork your own copy of JuliaFEM to your repository.
|
||||
4) Go to the `JuliaFEM GitHub page <https://github.com/JuliaFEM/JuliaFEM.jl>`_.
|
||||
At the top-right corner, press the ``Fork``-button to fork your own copy of
|
||||
JuliaFEM to your repository.
|
||||
|
||||
5) Clone JuliaFEM from your repository to your computer. Navigate to the folder you want to clone it to, and type the following command (inserting your GitHub username to its place): ``git clone https://github.com/your_github_username/JuliaFEM.jl.git``
|
||||
5) Clone JuliaFEM from your repository to your computer. Navigate to the folder
|
||||
you want to clone it to, and type the following command (inserting your GitHub
|
||||
username to its place): ``git clone https://github.com/your_github_username/JuliaFEM.jl.git``
|
||||
|
||||
6) You can now navigate to JuliaFEM in the folder you chose at step 5. There you'll find the same contents as you see in your GitHub JuliaFEM repository. Now, locate the file you want to modify, open it with your desired text editor, make the changes and save the new version. If you type ``git status``, you'll see that the files you've created or modified are listed under ``untracked files``.
|
||||
6) You can now navigate to JuliaFEM in the folder you chose at step 5. There
|
||||
you'll find the same contents as you see in your GitHub JuliaFEM repository.
|
||||
Now, locate the file you want to modify, open it with your desired text
|
||||
editor, make the changes and save the new version. If you type ``git status``,
|
||||
you'll see that the files you've created or modified are listed under ``untracked files``.
|
||||
|
||||
7) Add the files you want to update to the staging area by typing ``git add <file1> <file2>...``. If you type ``git status``, you'll see that the files added to the staging area are listed under ``Changes to be committed``. This process also supports wildcard symbols. If you want to add all the files to the staging area, just type ``git add .``. If you want to remove a file from the staging area, type ``git reset <file>``.
|
||||
7) Add the files you want to update to the staging area by typing
|
||||
``git add <file1> <file2>...``. If you type ``git status``, you'll see that
|
||||
the files added to the staging area are listed under ``Changes to be committed``.
|
||||
This process also supports wildcard symbols. If you want to add all the files
|
||||
to the staging area, just type ``git add .``. If you want to remove a file
|
||||
from the staging area, type ``git reset <file>``.
|
||||
|
||||
8) To store the staged files, commit the files to your repository and add a description message by typing ``git commit -m "your_message_here"``. The message should describe the changes that were made.
|
||||
8) To store the staged files, commit the files to your repository and add a
|
||||
description message by typing ``git commit -m "your_message_here"``. The
|
||||
message should describe the changes that were made.
|
||||
|
||||
9) When you are happy with the commits and want to update them to your repository, type ``git push origin master``.
|
||||
9) When you are happy with the commits and want to update them to your
|
||||
repository, type ``git push origin master``.
|
||||
|
||||
10) Go to your GitHub JuliaFEM repository. You'll notice that the commit you have made and pushed is now visible above the JuliaFEM file branch. If you click the ``latest commit`` link, you can see the changes made to the file. Finally, click ``Pull request`` to create a pull request of the commits you've made, so that other contributors can review it.
|
||||
10) Go to your GitHub JuliaFEM repository. You'll notice that the commit you
|
||||
have made and pushed is now visible above the JuliaFEM file branch. If you
|
||||
click the ``latest commit`` link, you can see the changes made to the file.
|
||||
Finally, click ``Pull request`` to create a pull request of the commits
|
||||
you've made, so that other contributors can review it.
|
||||
|
||||
11) If other contributors ask you to make changes to your pull request, just repeat steps 6-9. Your commits will be updated to your original pull request. Do this until everyone is satisfied and your pull request can be merged to the master branch.
|
||||
11) If other contributors ask you to make changes to your pull request, just
|
||||
repeat steps 6-9. Your commits will be updated to your original pull request.
|
||||
Do this until everyone is satisfied and your pull request can be merged to
|
||||
the master branch.
|
||||
|
||||
There's also some GUI apps to use git if you don't feel command line comfortable. For OSX and Windows a good application is `SourceTree <https://www.sourcetreeapp.com>`_, for Linux, maybe `SmartGit <http://www.syntevo.com/smartgit/>`_
|
||||
There's also some GUI apps to use git if you don't feel command line comfortable.
|
||||
For OSX and Windows a good application is `SourceTree <https://www.sourcetreeapp.com>`_,
|
||||
for Linux, maybe `SmartGit <http://www.syntevo.com/smartgit/>`_ will work.
|
||||
|
||||
Developing on local machine
|
||||
---------------------------
|
||||
|
||||
To set up ready for development, git clone it to your development directory and make symbolic link to julia package directory:
|
||||
To set up ready for development, git clone it to your development directory and
|
||||
make symbolic link to julia package directory:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
@@ -40,39 +71,64 @@ To set up ready for development, git clone it to your development directory and
|
||||
cd ~/.julia/v0.4
|
||||
ln -s ~/dev/JuliaFEM
|
||||
|
||||
Editors: Juno is bundled with Julia. Another option is to use vim after installing
|
||||
`vim support for Julia <https://github.com/JuliaLang/julia-vim>`_.
|
||||
|
||||
Testing is made easy by using our `Makefile`. From there one founds convenient
|
||||
functions `make test`, `make test_file` and `make test_function` to make testing
|
||||
more rapid.
|
||||
|
||||
Use of UTF-8 characters in program code
|
||||
---------------------------------------
|
||||
We have decided not to use them. See issue `#18 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/18>`_.
|
||||
We have decided not to use them. See issue
|
||||
`#18 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/18>`_.
|
||||
|
||||
Supported Julia versions
|
||||
------------------------
|
||||
We support Julia versions 0.4+. See issue `#26 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/26>`_.
|
||||
We support Julia versions 0.4+. See issue
|
||||
`#26 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/26>`_.
|
||||
|
||||
Only pull requests to src folder
|
||||
--------------------------------
|
||||
See issue `#29 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/29>`_. This ensures peer review check for contributors and hopefully will decrease the number of merge conflicts. Before making the pull request runn all test: either type ``julia> Pkg.test("JuliaFEM")`` at REPL or ``julia test/runtests.jl`` at command line.
|
||||
See issue `#29 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/29>`_. This
|
||||
ensures peer review check for contributors and hopefully will decrease the
|
||||
number of merge conflicts. Before making the pull request run all test: either
|
||||
type ``julia> Pkg.test("JuliaFEM")`` at REPL or ``julia test/runtests.jl`` at
|
||||
command line.
|
||||
|
||||
New technology should be introduced through notebooks
|
||||
-----------------------------------------------------
|
||||
See issue `#12 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/12>`_. Idea is to introduce new technology as a notebook for the very beginning. Then when it's get mature the notebook will serve functional test for the matter. All notebooks will be included as examples to the documentation.
|
||||
See issue `#12 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/12>`_. Idea is
|
||||
to introduce new technology as a notebook for the very beginning. Then when it's
|
||||
get mature the notebook will serve functional test for the matter. All notebooks
|
||||
will be included as examples to the documentation.
|
||||
|
||||
FactCheck.jl is used to write test for the JuliaFEM.jl package
|
||||
--------------------------------------------------------------
|
||||
See issue `#27 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/27>`_. Use FactCheck.jl package to write the tests. We believe Test Driven Development thus 100 % test coverage is expected.
|
||||
See issue `#27 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/27>`_. Use
|
||||
`FactCheck.jl` package to write the tests. We believe Test Driven Development
|
||||
thus 100 % test coverage is expected.
|
||||
|
||||
JuliaFEM.jl is using Logging.jl
|
||||
-------------------------------
|
||||
See issue `#25 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/25>`_. We have written a test to check all sources in src folder to find any print statements. Use Logging.jl instead of println().
|
||||
See issue `#25 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/25>`_. We have
|
||||
written a test to check all sources in src folder to find any print statements.
|
||||
Use Logging.jl instead of println().
|
||||
|
||||
Code indentation
|
||||
----------------
|
||||
We use 4 spaces like in Python. See issue `#5 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/5>`_.
|
||||
We use 4 spaces like in Python. See issue
|
||||
`#5 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/5>`_.
|
||||
|
||||
Function docstrings
|
||||
-------------------
|
||||
We use numpy documentation style in our functions. See `guide <https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt>`_. See issue `#5 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/5>`_.
|
||||
We use numpy documentation style in our functions. See
|
||||
`guide <https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt>`_.
|
||||
See issue `#5 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/5>`_.
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
We use restructured text to document this project. Information how to write rst format is described `here <http://sphinx-doc.org/rest.html>`_. See issue `#49 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/49>`_.
|
||||
We use restructured text to document this project. Information how to write rst
|
||||
format is described `here <http://sphinx-doc.org/rest.html>`_. See issue
|
||||
`#49 <https://github.com/JuliaFEM/JuliaFEM.jl/issues/49>`_.
|
||||
|
||||
|
||||
+21
-4
@@ -57,13 +57,30 @@ function run_notebooks()
|
||||
try
|
||||
run(`timeout 180 runipy -o tutorials/$ipynb --kernel=julia-0.4`)
|
||||
status = 0
|
||||
catch
|
||||
println("did not work")
|
||||
catch error
|
||||
warning("running notebook failed")
|
||||
Base.showerror(Base.STDOUT, error)
|
||||
end
|
||||
runtime = toc()
|
||||
bn = "tutorials/$(ipynb[1:end-6])"
|
||||
run(`ipython nbconvert tutorials/$ipynb --to rst --output=$bn`)
|
||||
run(`ipython nbconvert tutorials/$ipynb --to pdf --output=$bn`)
|
||||
try
|
||||
run(`ipython nbconvert tutorials/$ipynb --to rst --output=$bn`)
|
||||
catch error
|
||||
warn("unable to convert notebook to rst format")
|
||||
Base.showerror(Base.STDOUT, error)
|
||||
end
|
||||
try
|
||||
run(`ipython nbconvert tutorials/$ipynb --to pdf --output=$bn`)
|
||||
catch error
|
||||
warn("unable to convert notebook to tex format")
|
||||
Base.showerror(Base.STDOUT, error)
|
||||
end
|
||||
try
|
||||
run(`lualatex $bn.tex`)
|
||||
catch error
|
||||
warn("unable to convert notebook from tex to pdf")
|
||||
Base.showerror(Base.STDOUT, error)
|
||||
end
|
||||
data = Dict("author" => "unknown", "status" => status, "runtime" => runtime,
|
||||
"filename" => ipynb, "last_run" => time(), "description"=>"")
|
||||
res = parse_rst("$bn.rst")
|
||||
|
||||
+17
-2
@@ -10,12 +10,27 @@ module JuliaFEM
|
||||
#@Logging.configure(level=DEBUG)
|
||||
#using Lexicon
|
||||
|
||||
"""
|
||||
A very simple debugging macro. It prints debug message if environment variable
|
||||
JULIAFEM_DEBUG is found.
|
||||
|
||||
Usage: instead of starting session `julia file.jl` do `JULIAFEM_DEBUG=1 julia file.jl`.
|
||||
Or set `export JULIAFEM_DEBUG=1` for your `.bashrc`.
|
||||
"""
|
||||
macro debug(msg)
|
||||
if !haskey(ENV, "JuliaFEM_LOG_LEVEL")
|
||||
return :()
|
||||
if !haskey(ENV, "JULIAFEM_DEBUG")
|
||||
return
|
||||
end
|
||||
return :( println("DEBUG: ", $msg) )
|
||||
end
|
||||
function set_debug_on!()
|
||||
ENV["JULIAFEM_DEBUG"] = 1;
|
||||
end
|
||||
function set_debug_off!()
|
||||
pop!(ENV, "JULIAFEM_DEBUG");
|
||||
end
|
||||
|
||||
export @debug, set_debug_on!, set_debug_off!
|
||||
|
||||
using ForwardDiff
|
||||
autodiffcache = ForwardDiffCache()
|
||||
|
||||
+33
-21
@@ -16,15 +16,15 @@ type Increment{T} <: AbstractVector{T}
|
||||
end
|
||||
|
||||
function Base.size(increment::Increment)
|
||||
size(increment.data)
|
||||
return size(increment.data)
|
||||
end
|
||||
|
||||
function Base.linearindexing(::Type{Increment})
|
||||
LinearFast()
|
||||
return LinearFast()
|
||||
end
|
||||
|
||||
function Base.getindex(increment::Increment, i::Int)
|
||||
increment.data[i]
|
||||
return increment.data[i]
|
||||
end
|
||||
|
||||
function Base.setindex!(increment::Increment, v, i::Int)
|
||||
@@ -32,39 +32,49 @@ function Base.setindex!(increment::Increment, v, i::Int)
|
||||
end
|
||||
|
||||
function Base.dot(k::Number, increment::Increment)
|
||||
k*increment
|
||||
return k*increment
|
||||
end
|
||||
|
||||
function Base.convert(::Type{Increment}, data::Number)
|
||||
Increment([data])
|
||||
return Increment([data])
|
||||
end
|
||||
|
||||
function Base.convert{T}(::Type{Increment}, data::Array{T, 2})
|
||||
Increment([data[:,i] for i=1:size(data, 2)])
|
||||
return Increment([data[:,i] for i=1:size(data, 2)])
|
||||
end
|
||||
|
||||
function Base.convert{T}(::Type{Increment}, data::Array{T, 3})
|
||||
Increment([data[:,:,i] for i=1:size(data, 3)])
|
||||
return Increment([data[:,:,i] for i=1:size(data, 3)])
|
||||
end
|
||||
|
||||
function Base.convert{T}(::Type{Increment}, data::Array{T, 4})
|
||||
Increment([data[:,:,:,i] for i=1:size(data, 4)])
|
||||
return Increment([data[:,:,:,i] for i=1:size(data, 4)])
|
||||
end
|
||||
|
||||
function Base.convert{T}(::Type{Increment}, data::Array{T, 5})
|
||||
Increment([data[:,:,:,:,i] for i=1:size(data, 5)])
|
||||
return Increment([data[:,:,:,:,i] for i=1:size(data, 5)])
|
||||
end
|
||||
|
||||
function Base.zeros(::Type{Increment}, dims...)
|
||||
Increment(zeros(dims...))
|
||||
function Base.zeros(::Type{Increment}, T, dims...)
|
||||
return Increment(zeros(T, dims...))
|
||||
end
|
||||
|
||||
""" Flatten increment to Vector.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
>>> inc = ones(Increment, 2, 4)
|
||||
>>> vec(inc)
|
||||
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
|
||||
|
||||
"""
|
||||
function Base.vec(increment::Increment)
|
||||
[increment...;]
|
||||
return [increment...;]
|
||||
end
|
||||
|
||||
function Base.similar{T}(increment::Increment, data::Vector{T})
|
||||
Increment(reshape(data, round(Int, length(data)/length(increment)), length(increment)))
|
||||
return Increment(reshape(data, round(Int, length(data)/length(increment)), length(increment)))
|
||||
end
|
||||
|
||||
function Base.convert{T}(::Type{Vector{T}}, increment::Increment)
|
||||
@@ -91,7 +101,7 @@ function Base.length(timestep::TimeStep)
|
||||
end
|
||||
|
||||
function Base.linearindexing(::Type{TimeStep})
|
||||
Base.LinearFast()
|
||||
return Base.LinearFast()
|
||||
end
|
||||
|
||||
function Base.getindex(timestep::TimeStep, i::Int)
|
||||
@@ -103,7 +113,7 @@ end
|
||||
#end
|
||||
|
||||
function TimeStep()
|
||||
TimeStep(0.0, [])
|
||||
return TimeStep(0.0, [])
|
||||
end
|
||||
|
||||
function TimeStep{T}(data::T...)
|
||||
@@ -118,6 +128,8 @@ function Base.push!(timestep::TimeStep, increment::Increment)
|
||||
push!(timestep.increments, increment)
|
||||
end
|
||||
|
||||
# FIXME: having some serious problems here to get tuple form working.
|
||||
|
||||
# 3. DefaultDiscreteField
|
||||
type DefaultDiscreteField <: DiscreteField
|
||||
timesteps :: Vector{TimeStep}
|
||||
@@ -163,15 +175,15 @@ function Base.linearindexing(::Type{DefaultDiscreteField})
|
||||
end
|
||||
|
||||
function Base.getindex(field::DefaultDiscreteField, i::Int)
|
||||
field.timesteps[i]
|
||||
return field.timesteps[i]
|
||||
end
|
||||
|
||||
function Base.length(field::DefaultDiscreteField)
|
||||
length(field.timesteps)
|
||||
return length(field.timesteps)
|
||||
end
|
||||
|
||||
function Base.endof(field::DefaultDiscreteField)
|
||||
endof(field.timesteps)
|
||||
return endof(field.timesteps)
|
||||
end
|
||||
|
||||
function Base.first(field::DefaultDiscreteField)
|
||||
@@ -199,7 +211,7 @@ function Base.convert(::Type{DefaultDiscreteField}, data...)
|
||||
timesteps = TimeStep[]
|
||||
for (i, d) in enumerate(data)
|
||||
if isa(d, Tuple)
|
||||
# @debug("is tuple, has time, d = $d")
|
||||
@debug("is tuple, has time, d = $d")
|
||||
# contains time vector
|
||||
increments = Increment[Increment(d[2])]
|
||||
push!(timesteps, TimeStep(d[1], increments))
|
||||
@@ -246,7 +258,7 @@ function Base.convert(::Type{Field}, data::Union{Number, Array, Tuple}...)
|
||||
end
|
||||
|
||||
function Base.convert(::Type{DiscreteField}, data::Union{Number, Array, Tuple}...)
|
||||
convert(DefaultDiscreteField, data...)
|
||||
return convert(DefaultDiscreteField, data...)
|
||||
end
|
||||
|
||||
# 2. given function -> continuous field
|
||||
@@ -256,6 +268,6 @@ function Base.convert(::Type{Field}, data::Function)
|
||||
end
|
||||
|
||||
function Base.convert(::Type{ContinuousField}, data::Function)
|
||||
convert(DefaultContinuousField, data)
|
||||
return convert(DefaultContinuousField, data)
|
||||
end
|
||||
|
||||
|
||||
+25
-8
@@ -71,36 +71,53 @@ end
|
||||
""" Run single test set. """
|
||||
function run_test(test_function::Function)
|
||||
|
||||
allok = true
|
||||
|
||||
function test_handler(r::Base.Test.Success)
|
||||
print(".")
|
||||
result = TestResult(test_function, r)
|
||||
push!(test_results, result)
|
||||
end
|
||||
|
||||
function test_handler(r::Base.Test.Failure)
|
||||
allok = false
|
||||
print(" [\x1b[31mFAIL\x1b[0m]")
|
||||
push!(test_results, TestResult(test_function, r))
|
||||
warn("test failed: $(r.expr)")
|
||||
warn("partially evaluated expression: $(r.resultexpr)")
|
||||
println()
|
||||
println("Test failed: $(r.expr)")
|
||||
#warn("partially evaluated expression: $(r.resultexpr)")
|
||||
end
|
||||
|
||||
function test_handler(r::Base.Test.Error)
|
||||
allok = false
|
||||
println(" [\x1b[31mERROR\x1b[0m]")
|
||||
push!(test_results, TestResult(test_function, r))
|
||||
warn("Error when testing: $(r.expr)")
|
||||
println("Error when testing: $(r.expr)")
|
||||
end
|
||||
|
||||
Base.Test.with_handler(test_handler) do
|
||||
info("$test_function():")
|
||||
print("TEST: $test_function() ")
|
||||
# TODO: print docstring of test function if defined.
|
||||
#@doc($test_function)
|
||||
try
|
||||
test_function()
|
||||
catch error
|
||||
warn("testing $test_function() stopped for critical error $error")
|
||||
allok = false
|
||||
println("[\x1b[31mCRITICAL\x1b[0m]")
|
||||
println("Testing $test_function() stopped for critical error:\n$error")
|
||||
Base.showerror(Base.STDOUT, error)
|
||||
print("\n")
|
||||
warn("cannot continue to test function $test_function")
|
||||
println()
|
||||
println("Cannot continue to test function $test_function()")
|
||||
push!(test_results, TestResult("$test_function", error))
|
||||
end
|
||||
info("$test_function(): done.")
|
||||
|
||||
if allok
|
||||
println(" [\x1b[32mPASS\x1b[0m]")
|
||||
else
|
||||
filename, linenum = Base.functionloc(test_function)
|
||||
println("Test $test_function() failed: file $filename, line $linenum.")
|
||||
println()
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
+126
-108
@@ -4,119 +4,146 @@
|
||||
|
||||
module FieldTests
|
||||
|
||||
using JuliaFEM
|
||||
using JuliaFEM: Increment, TimeStep, Field, DefaultDiscreteField, FieldSet
|
||||
using JuliaFEM: TemporalBasis, SpatialBasis, ContinuousField, DiscreteField
|
||||
using JuliaFEM: DefaultContinuousField
|
||||
|
||||
using JuliaFEM.Test
|
||||
|
||||
""" testing Increment """
|
||||
function test_increment()
|
||||
function test_increment_constant_increment()
|
||||
I = Increment(1)
|
||||
@test isa(I, Increment)
|
||||
@test length(I) == 1
|
||||
@test I == 1
|
||||
end
|
||||
|
||||
# constant increment
|
||||
I3 = Increment(1)
|
||||
@test isa(I3, Increment)
|
||||
@test length(I3) == 1
|
||||
# FIXME: i don't like 1-length arrays
|
||||
@test I3 == [1]
|
||||
|
||||
# two increments with vector data
|
||||
function test_increments_with_vector_data()
|
||||
I1 = Increment([1, 2, 3])
|
||||
I2 = Increment([2, 3, 4])
|
||||
@test length(I1) == 3
|
||||
@test length(I2) == 3
|
||||
@test I1 == [1, 2, 3]
|
||||
@test I2 == [2, 3, 4]
|
||||
end
|
||||
|
||||
# basic math
|
||||
function test_increments_basic_math()
|
||||
I1 = Increment([1, 2, 3])
|
||||
I2 = Increment([2, 3, 4])
|
||||
@test 1/2*(I1+I2) == [1.5, 2.5, 3.5]
|
||||
@test I1 + 1 == [2, 3, 4]
|
||||
@test I1 - 1 == [0, 1, 2]
|
||||
@test I1*3 == [3, 6, 9]
|
||||
@test I1+I2 == [3, 5, 7]
|
||||
end
|
||||
|
||||
# dot product
|
||||
function test_increment_dot_product()
|
||||
I1 = Increment([1, 2, 3])
|
||||
I2 = Increment([2, 3, 4])
|
||||
@test dot(I1, I2) == 20
|
||||
@test dot([1,2,3], I2) == 20
|
||||
@test dot(I1, [2,3,4]) == 20
|
||||
@test dot([1, 2], Increment[I1, I2])
|
||||
end
|
||||
|
||||
# similarity
|
||||
f = zeros(Increment, 2, 4)
|
||||
function test_increment_similarity()
|
||||
f = zeros(Increment, Int, 2, 4)
|
||||
@test length(f) == 4
|
||||
g = similar(f, ones(8))
|
||||
g = similar(f, ones(Int, 8))
|
||||
@test typeof(f) == typeof(g)
|
||||
@test length(f) == length(g)
|
||||
@test size(g) == (2, 4)
|
||||
end
|
||||
|
||||
# vec
|
||||
@test vec(g) == ones(8)
|
||||
function test_increment_vec()
|
||||
g = zeros(Increment, Int, 2, 4)
|
||||
@test vec(g) == ones(Int, 8)
|
||||
end
|
||||
|
||||
# promotion
|
||||
# FIXME: how to do promotion so that modified increment is still increment?
|
||||
function test_increment_promotion()
|
||||
I1 = Increment([1, 2, 3])
|
||||
I2 = Increment([2, 3, 4])
|
||||
@test isa(I1+1, Increment)
|
||||
@test isa(I1-1, Increment)
|
||||
@test isa(3*I1, Increment)
|
||||
@test isa(1/2*I1, Increment)
|
||||
@test isa(I1+I2, Increment)
|
||||
@test isa(I1-I2, Increment)
|
||||
|
||||
end
|
||||
|
||||
""" testing TimeStep """
|
||||
function test_timestep()
|
||||
|
||||
info("test_timestep(): create empty timestep")
|
||||
function test_timestep_empty_timestep()
|
||||
ts = TimeStep()
|
||||
@test length(ts) == 0
|
||||
@test ts.time == 0.0
|
||||
end
|
||||
|
||||
info("create timestep with two increments")
|
||||
function test_timestep_with_two_increments()
|
||||
i1 = Increment([1, 2, 3])
|
||||
i2 = Increment([2, 3, 4])
|
||||
increments = Increment[i1, i2]
|
||||
ts = TimeStep(1.0, increments)
|
||||
@test length(ts) == 2
|
||||
end
|
||||
|
||||
info("create timestep with scalar value")
|
||||
function test_create_timestep_with_scalar_value()
|
||||
ts = TimeStep(1)
|
||||
@test length(ts) == 1
|
||||
@test ts.time == 0.0
|
||||
@test isa(ts[1], Increment)
|
||||
@test ts[1] == [1]
|
||||
end
|
||||
|
||||
info("create timestep compactly for time t=0.0")
|
||||
function test_create_timestep_compactly_for_time_t0()
|
||||
ts = TimeStep([1, 2, 3])
|
||||
@test length(ts) == 1
|
||||
@test ts.time == 0.0
|
||||
@test isa(ts[1], Increment)
|
||||
@test ts[1] == [1, 2, 3]
|
||||
end
|
||||
|
||||
info("create timestep compactly, add three increments compactly for time t=0.0")
|
||||
function test_create_timestep_compactly_add_three_increments_compactly_for_time_t0()
|
||||
ts = TimeStep(1, 2, 3)
|
||||
@test length(ts) == 3
|
||||
@test ts.time == 0.0
|
||||
@test isa(ts[1], Increment)
|
||||
end
|
||||
|
||||
info("create timestep compactly, add two increments compactly for time t=0.0")
|
||||
function test_create_timestep_compactly_add_two_increments()
|
||||
ts = TimeStep([1, 2, 3], [2, 3, 4])
|
||||
@test length(ts) == 2
|
||||
@test ts.time == 0.0
|
||||
@test isa(ts[1], Increment)
|
||||
@test isa(ts[2], Increment)
|
||||
@test ts[1] == [1, 2, 3]
|
||||
@test ts[2] == [2, 3, 4]
|
||||
end
|
||||
|
||||
info("create standard timesteps")
|
||||
info(TimeStep(0.5, Increment([1, 2])))
|
||||
|
||||
function test_create_timesteps_for_different_times()
|
||||
@test TimeStep(0.5, [1, 2]).time == 0.5
|
||||
@test TimeStep(0.5, [1, 2]) == [1, 2]
|
||||
@test TimeStep(0.5, 1).time == 0.5
|
||||
@test TimeStep(0.5, 1) == [1]
|
||||
|
||||
end
|
||||
|
||||
""" testing DefaultDiscreteField """
|
||||
function test_default_discrete_field()
|
||||
function test_default_discrete_field_quick_way_vector()
|
||||
f1 = DefaultDiscreteField([1, 2, 3])
|
||||
@debug("f1 = $f1")
|
||||
@test isa(f1[1], TimeStep)
|
||||
@test isa(f1[1][1], Increment)
|
||||
@test f1[1][1] == [1, 2, 3]
|
||||
@test f1[1].time == 0.0
|
||||
end
|
||||
|
||||
info("test_default_discrete_field(): the traditional way")
|
||||
function test_default_discrete_field_quick_way_scalar()
|
||||
f1 = DefaultDiscreteField(1)
|
||||
@test length(f1) == 1
|
||||
@test isa(f1[1], TimeStep)
|
||||
@test isa(f1[1][1], Increment)
|
||||
@test f1[1][1] == [1]
|
||||
@test f1[1].time == 0.0
|
||||
end
|
||||
|
||||
function test_default_discrete_field_traditional_way()
|
||||
i1 = Increment([1, 2, 3])
|
||||
i2 = Increment([2, 3, 4])
|
||||
t1 = TimeStep(1.0, Increment[i1, i2])
|
||||
@@ -133,16 +160,9 @@ function test_default_discrete_field()
|
||||
@test f1[2][2] == [3, 4, 5]
|
||||
@test f1[1].time == 1.0
|
||||
@test f1[2].time == 2.0
|
||||
end
|
||||
|
||||
info("test_default_discrete_field(): quick way, this creates one timestep with vector value")
|
||||
f1 = DefaultDiscreteField([1, 2, 3])
|
||||
info("f1 = $f1")
|
||||
@test isa(f1[1], TimeStep)
|
||||
@test isa(f1[1][1], Increment)
|
||||
@test f1[1][1] == [1, 2, 3]
|
||||
@test f1[1].time == 0.0
|
||||
|
||||
info("test_default_discrete_field(): quick way, two timesteps with constant value")
|
||||
function test_default_discrete_field_quick_way_two_timesteps_with_constant_value()
|
||||
f1 = DefaultDiscreteField(1, 2)
|
||||
@test length(f1) == 2
|
||||
@test isa(f1[1], TimeStep)
|
||||
@@ -153,16 +173,9 @@ function test_default_discrete_field()
|
||||
@test f1[2][1] == [2]
|
||||
@test f1[1].time == 0.0
|
||||
@test f1[2].time == 1.0
|
||||
end
|
||||
|
||||
info("test_default_discrete_field(): quick way, one timestep with scalar value")
|
||||
f1 = DefaultDiscreteField(1)
|
||||
@test length(f1) == 1
|
||||
@test isa(f1[1], TimeStep)
|
||||
@test isa(f1[1][1], Increment)
|
||||
@test f1[1][1] == [1]
|
||||
@test f1[1].time == 0.0
|
||||
|
||||
info("test_default_discrete_field(): quick way, two timesteps with vector value")
|
||||
function test_default_discrete_field_quick_way_two_timesteps_with_vector_value()
|
||||
f1 = DefaultDiscreteField([1, 2, 3], [3, 4, 5])
|
||||
@test length(f1) == 2
|
||||
@test isa(f1[1], TimeStep)
|
||||
@@ -173,8 +186,9 @@ function test_default_discrete_field()
|
||||
@test f1[2][1] == [3, 4, 5]
|
||||
@test f1[1].time == 0.0
|
||||
@test f1[2].time == 1.0
|
||||
end
|
||||
|
||||
info("test_default_discrete_field(): quick way, set time vector also")
|
||||
function test_default_discrete_field_quick_way_set_time_vector_also()
|
||||
f1 = DefaultDiscreteField( (0.5, [1, 2, 3]), (1.0, [3, 4, 5]) )
|
||||
@test isa(f1[1], TimeStep)
|
||||
@test isa(f1[2], TimeStep)
|
||||
@@ -184,10 +198,8 @@ function test_default_discrete_field()
|
||||
@test f1[2][1] == [3, 4, 5]
|
||||
@test f1[1].time == 0.5
|
||||
@test f1[2].time == 1.0
|
||||
|
||||
end
|
||||
|
||||
""" testing DefaultContinuousField """
|
||||
function test_default_continuous_field()
|
||||
|
||||
function myfield(xi::Vector, time::Float64)
|
||||
@@ -203,70 +215,81 @@ function test_default_continuous_field()
|
||||
|
||||
end
|
||||
|
||||
""" testing FieldSet """
|
||||
function test_fieldset()
|
||||
|
||||
info("test_fieldset(): testing adding discrete field to FieldSet")
|
||||
function test_add_discrete_field_to_fieldset()
|
||||
fs = FieldSet()
|
||||
fs["temperature"] = DefaultDiscreteField([1, 2, 3])
|
||||
@test length(fs) == 1
|
||||
@test fs["temperature"] == [1, 2, 3]
|
||||
end
|
||||
|
||||
info("test_fieldset(): testing adding discrete fields quickly")
|
||||
fs2 = FieldSet()
|
||||
fs2["temperature"] = [1, 2, 3, 4]
|
||||
@test fs2["temperature"][end][end] == [1, 2, 3, 4]
|
||||
@test last(fs2["temperature"]) == [1, 2, 3, 4]
|
||||
function test_adding_discrete_fields_to_fieldset_quickly()
|
||||
fs = FieldSet()
|
||||
fs["temperature"] = [1, 2, 3, 4]
|
||||
@test fs["temperature"][end][end] == [1, 2, 3, 4]
|
||||
@test last(fs["temperature"]) == [1, 2, 3, 4]
|
||||
end
|
||||
|
||||
info("test_fieldset(): testing adding all kind of discrete fields")
|
||||
fs2 = FieldSet()
|
||||
fs2["constant scalar field"] = 1
|
||||
fs2["scalar field"] = [1, 2, 3, 4]
|
||||
fs2["vector field"] = reshape(collect(1:8), 2, 4)
|
||||
fs2["second order tensor field"] = reshape(collect(1:3*3*4), 3, 3, 4)
|
||||
fs2["fourth order tensor field"] = reshape(collect(1:3*3*3*3*4), 3, 3, 3, 3, 4)
|
||||
timestep = fs2["vector field"][end]
|
||||
@test timestep.time == 0.0
|
||||
function test_adding_all_kind_of_fields_to_fieldset()
|
||||
fs = FieldSet()
|
||||
fs["constant scalar field"] = 1
|
||||
fs["scalar field"] = [1, 2, 3, 4]
|
||||
fs["vector field"] = reshape(collect(1:8), 2, 4)
|
||||
fs["second order tensor field"] = reshape(collect(1:3*3*4), 3, 3, 4)
|
||||
fs["fourth order tensor field"] = reshape(collect(1:3*3*3*3*4), 3, 3, 3, 3, 4)
|
||||
timestep = fs["vector field"][end]
|
||||
@test fs["vector field"][end].time == 0.0
|
||||
end
|
||||
|
||||
info("test_fieldset(): testing adding timesteps")
|
||||
function test_adding_timesteps()
|
||||
fs = FieldSet()
|
||||
fs["temperature"] = [1, 2, 3, 4]
|
||||
T0 = last(fs["temperature"]) # last increment of last field
|
||||
info("last temperature T0 = $T0")
|
||||
@debug("last temperature T0 = $T0")
|
||||
T1 = Increment(T0 + 1)
|
||||
info("typeof T1 = $(typeof(T1))")
|
||||
@debug("typeof T1 = $(typeof(T1))")
|
||||
timestep = TimeStep(1.0, Increment[T1]) # new list of increments for timestep
|
||||
push!(fs["temperature"], timestep)
|
||||
T2 = last(fs["temperature"])
|
||||
info("last temperature T2 = $T2")
|
||||
@debug("last temperature T2 = $T2")
|
||||
@test length(fs["temperature"]) == 2
|
||||
@test last(fs["temperature"]) == [2, 3, 4, 5]
|
||||
@test fs["temperature"][end].time == 1.0
|
||||
end
|
||||
|
||||
info("test_fieldset(): testing adding timesteps compactly")
|
||||
timestep = TimeStep(2.0, T1)
|
||||
push!(fs["temperature"], timestep)
|
||||
@test length(fs["temperature"].timesteps) == 3
|
||||
function test_adding_timesteps_compactly()
|
||||
fs = FieldSet()
|
||||
fs["temperature"] = [1, 2, 3, 4]
|
||||
T0 = last(fs["temperature"])
|
||||
T1 = Increment(T0 + 1)
|
||||
push!(fs["temperature"], TimeStep(1.0, T1))
|
||||
@test length(fs["temperature"]) == 2
|
||||
@test last(fs["temperature"]) == [2, 3, 4, 5]
|
||||
@test fs["temperature"][end].time == 1.0
|
||||
end
|
||||
|
||||
info("test_fieldset(): test adding several time steps at once without time vector")
|
||||
fs3 = FieldSet()
|
||||
fs3["time series 2"] = [1, 2, 3, 4], [2, 3, 4, 5]
|
||||
info(fs3)
|
||||
@test fs3["time series 2"][1].time == 0.0
|
||||
@test fs3["time series 2"][2].time == 1.0
|
||||
@test fs3["time series 2"][1][end] == [1, 2, 3, 4]
|
||||
@test fs3["time series 2"][2][end] == [2, 3, 4, 5]
|
||||
function test_add_several_timesteps_without_time_vector()
|
||||
fs = FieldSet()
|
||||
fs["time series"] = [1, 2, 3, 4], [2, 3, 4, 5]
|
||||
@debug("fieldset = $fs")
|
||||
@test fs["time series"][1].time == 0.0
|
||||
@test fs["time series"][2].time == 1.0
|
||||
@test fs["time series"][1][end] == [1, 2, 3, 4]
|
||||
@test fs["time series"][2][end] == [2, 3, 4, 5]
|
||||
end
|
||||
|
||||
info("test_fieldset(): test adding several time steps at once with time vector")
|
||||
fs3 = FieldSet()
|
||||
fs3["time series 1"] = (0.0, [1, 2, 3, 4]), (0.5, [2, 3, 4, 5])
|
||||
@test fs3["time series 1"][1].time == 0.0
|
||||
@test fs3["time series 1"][2].time == 0.5
|
||||
@test fs3["time series 1"][1][end] == [1, 2, 3, 4]
|
||||
@test fs3["time series 1"][2][end] == [2, 3, 4, 5]
|
||||
function test_adding_several_timesteps_at_once_with_time_vector()
|
||||
fs = FieldSet()
|
||||
fs["time series"] = (0.0, [1, 2, 3, 4]), (0.5, [2, 3, 4, 5])
|
||||
@test fs3["time series"][1].time == 0.0
|
||||
@test fs3["time series"][2].time == 0.5
|
||||
@test fs3["time series"][1][end] == [1, 2, 3, 4]
|
||||
@test fs3["time series"][2][end] == [2, 3, 4, 5]
|
||||
end
|
||||
|
||||
info("test_fieldset(): adding continuous field")
|
||||
function test_adding_continuous_field_to_fieldset()
|
||||
fs = FieldSet()
|
||||
fs["continuous field"] = (xi, t) -> xi[1]*xi[2]*t
|
||||
@test fs["continuous field"]([1.0, 2.0], 3.0) == 6.0
|
||||
|
||||
end
|
||||
|
||||
type MyContinuousField <: ContinuousField
|
||||
@@ -275,12 +298,10 @@ type MyContinuousField <: ContinuousField
|
||||
end
|
||||
function Base.call(field::MyContinuousField, xi::Vector, time::Number=1.0)
|
||||
data = last(field.discrete_field) # get the last timestep last increment
|
||||
info("data = $data, typeof data = $(typeof(data))")
|
||||
@debug("data = $data, typeof data = $(typeof(data))")
|
||||
basis = time*field.basis(xi) # evaluate basis at point ξ.
|
||||
sum([basis[i]*data[i] for i=1:length(data)]) # sum results
|
||||
end
|
||||
|
||||
""" testing ContinuousField """
|
||||
function test_continuous_field()
|
||||
fs = FieldSet()
|
||||
fs["discrete field"] = [1, 2, 3, 4]
|
||||
@@ -292,9 +313,8 @@ function test_continuous_field()
|
||||
fs["continuous field"] = MyContinuousField(basis, fs["discrete field"])
|
||||
@test fs["continuous field"]([0.0, 0.0], 1.0) == 1/4*(1+2+3+4)
|
||||
T0 = last(fs["discrete field"])
|
||||
T1 = T0 + 1.0
|
||||
ts = TimeStep(1.0, T1)
|
||||
push!(fs["discrete field"], TimeStep(1.0, T0+1.0))
|
||||
T1 = Increment(T0 + 1)
|
||||
push!(fs["discrete field"], TimeStep(1.0, T1))
|
||||
@test fs["continuous field"]([0.0, 0.0], 1.0) == 1/4*(2+3+4+5)
|
||||
end
|
||||
|
||||
@@ -308,8 +328,6 @@ Base.last(field::MyDiscreteField) = Float64[field[i] for i=1:length(field)]
|
||||
function Base.getindex(field::MyDiscreteField, idx::Int64)
|
||||
field.continuous_field(field.discrete_points[idx])
|
||||
end
|
||||
|
||||
""" testing DiscreteField """
|
||||
function test_discrete_field()
|
||||
fs = FieldSet()
|
||||
fs["discrete field"] = [1, 2, 3, 4]
|
||||
|
||||
Reference in New Issue
Block a user