From 5622c8b0292f874870ab6c9ea49026a96bbce5be Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Sun, 16 Aug 2015 22:48:19 +0300 Subject: [PATCH] Integration. --- .gitignore | 1 + src/math.jl | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 6ad4124..eaebe9c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .DS_Store .ipynb_checkpoints docs/build/html +*.swp diff --git a/src/math.jl b/src/math.jl index c4c45e6..8fbd80c 100644 --- a/src/math.jl +++ b/src/math.jl @@ -103,18 +103,46 @@ el::Element well defined element f::Function Function to integrate -target::ASCIIString - Where to save result (el.attributes[target]) """ -function integrate!(el::Element, f::Function, target::ASCIIString) - # set target to zero - el.attributes[target][:] = 0.0 +function integrate(f::Function, el::JuliaFEM.Element) + target = [] for m = 1:length(el.iweights) w = el.iweights[m] xi = el.ipoints[:, m] - J = interpolate(el, "coordinates", xi; derivative=true) - el.attributes[target] += w*f(el, xi)*det(J) + J = JuliaFEM.interpolate(el, "coordinates", xi; derivative=true) + push!(target, w*f(el, xi)*det(J)) + end + return sum(target) +end + +""" +This version returns a function which must be operated with element e +""" +function integrate(f::Function) + function integrate(el::JuliaFEM.Element) + target = [] + for m = 1:length(el.iweights) + w = el.iweights[m] + xi = el.ipoints[:, m] + J = JuliaFEM.interpolate(el, "coordinates", xi; derivative=true) + push!(target, w*f(el, xi)*det(J)) + end + return sum(target) + end + return integrate +end + +""" +This version saves results inplace to target, garbage collection free +""" +function integrate!(f::Function, el::JuliaFEM.Element, target) + # set target to zero + target[:] = 0.0 + for m = 1:length(el.iweights) + w = el.iweights[m] + xi = el.ipoints[:, m] + J = JuliaFEM.interpolate(el, "coordinates", xi; derivative=true) + target[:,:] += w*f(el, xi)*det(J) end end -