Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gridap/Gridap.jl into DivConformi…
Browse files Browse the repository at this point in the history
…ngRefFE
  • Loading branch information
santiagobadia committed Sep 13, 2019
2 parents 20080cf + 01e224f commit 60b9021
Show file tree
Hide file tree
Showing 44 changed files with 973 additions and 83 deletions.
84 changes: 84 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# This file is machine-generated - editing it directly is not advised

[[ArrayInterface]]
deps = ["LinearAlgebra", "Requires", "SparseArrays"]
git-tree-sha1 = "981354dab938901c2b607a213e62d9defa50b698"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "1.2.1"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

Expand All @@ -15,6 +21,12 @@ git-tree-sha1 = "c7361ce8a2129f20b0e05a89f7070820cfed6648"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.6"

[[Calculus]]
deps = ["Compat"]
git-tree-sha1 = "bd8bbd105ba583a42385bd6dc4a20dad8ab3dc11"
uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
version = "0.5.0"

[[CodecZlib]]
deps = ["BinaryProvider", "Libdl", "TranscodingStreams"]
git-tree-sha1 = "05916673a2627dd91b4969ff8ba6941bc85a960e"
Expand All @@ -27,6 +39,12 @@ git-tree-sha1 = "50b3ae4d643dc27eaff69fb6be06ee094d5500c9"
uuid = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
version = "0.7.0"

[[CommonSubexpressions]]
deps = ["Test"]
git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0"
uuid = "bbf7d656-a473-5ed7-a52c-81e309532950"
version = "0.2.0"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "84aa74986c5b9b898b0d1acaf3258741ee64754f"
Expand All @@ -47,6 +65,30 @@ uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[DiffEqDiffTools]]
deps = ["ArrayInterface", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays"]
git-tree-sha1 = "21b855cb29ec4594f9651e0e9bdc0cdcfdcd52c1"
uuid = "01453d9d-ee7c-5054-8395-0335cb756afa"
version = "1.3.0"

[[DiffResults]]
deps = ["Compat", "StaticArrays"]
git-tree-sha1 = "34a4a1e8be7bc99bc9c611b895b5baf37a80584c"
uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
version = "0.0.4"

[[DiffRules]]
deps = ["Random", "Test"]
git-tree-sha1 = "dc0869fb2f5b23466b32ea799bd82c76480167f7"
uuid = "b552c78f-8df3-52c6-915a-8e097449b14b"
version = "0.0.10"

[[Distances]]
deps = ["LinearAlgebra", "Statistics"]
git-tree-sha1 = "23717536c81b63e250f682b0e0933769eecd1411"
uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
version = "0.8.2"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand All @@ -57,6 +99,12 @@ git-tree-sha1 = "769ac4057ed875f433372e9a571a2cb86347d1be"
uuid = "442a2c76-b920-505d-bb47-c5924d526838"
version = "0.3.3"

[[ForwardDiff]]
deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"]
git-tree-sha1 = "4c4d727f1b7e0092134fabfab6396b8945c1ea5b"
uuid = "f6369f11-7733-5829-9624-2563aa707210"
version = "0.10.3"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand All @@ -79,6 +127,12 @@ git-tree-sha1 = "aeec7a341652d47bc773475a42952fa78eccd7cc"
uuid = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
version = "0.8.0"

[[LineSearches]]
deps = ["LinearAlgebra", "NLSolversBase", "NaNMath", "Parameters", "Printf", "Test"]
git-tree-sha1 = "54eb90e8dbe745d617c78dee1d6ae95c7f6f5779"
uuid = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
version = "7.0.1"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -93,12 +147,36 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[NLSolversBase]]
deps = ["Calculus", "DiffEqDiffTools", "DiffResults", "Distributed", "ForwardDiff"]
git-tree-sha1 = "c430bd3f2dfcffc30688cf4a9cb61535e8d85f65"
uuid = "d41bc354-129a-5804-8e4c-c37616107c6c"
version = "7.4.1"

[[NLsolve]]
deps = ["DiffEqDiffTools", "Distances", "ForwardDiff", "LineSearches", "LinearAlgebra", "NLSolversBase", "Printf", "Reexport"]
git-tree-sha1 = "c9578878f56f425a2160f5b436c7f79a154d154c"
uuid = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
version = "4.1.0"

[[NaNMath]]
deps = ["Compat"]
git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2"
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
version = "0.3.2"

[[OrderedCollections]]
deps = ["Random", "Serialization", "Test"]
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.1.0"

[[Parameters]]
deps = ["OrderedCollections"]
git-tree-sha1 = "1dfd7cd50a8eb06ef693a4c2bbe945943cd000c5"
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a"
version = "0.11.0"

[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b"
Expand Down Expand Up @@ -139,6 +217,12 @@ git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "0.2.0"

[[Requires]]
deps = ["Test"]
git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "0.5.2"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Now, the `tags` argument is optional when constucting `SkeletonTriangulation` and `BoundaryTriangulation` objects from a `DiscreteModel`. Since commit [e6424a3](https://github.com/gridap/Gridap.jl/commit/e6424a304feb38547241e86de07a821e26344a7e).
- Added `mean` operator for quantities restricted to a `SkeletonTriangulation`. Since commit [83798b4](https://github.com/gridap/Gridap.jl/commit/83798b4f38aaf482b968ffd0359eb75c79a21385).
- Extended `NormalVector` to `SkeletonTriangulations`. Since commit [5fb8487](https://github.com/gridap/Gridap.jl/commit/5fb84871128c4388559cc5052d9ff00f0be19462).
- Now, `TrialFESpaces` can be constructed from values instead of functions if the corresponding Dirichlet conditions are constant. Since commit [bae237e](https://github.com/gridap/Gridap.jl/commit/bae237e881db6569622f3559f82bcc3999560526).
- Added the possibility of adding new tags to a `FaceLabels` object via the function `add_tag_from_tags!` and using it to construct FE spaces. Since commit [e9dfac4](https://github.com/gridap/Gridap.jl/commit/e9dfac4489047c0b7e1c62507f4335e9fc76dfd8).
- Added `BackslashSolver` to facilitate the usage in Gridap of the build-in Julia backslash linear solver. Since commit [8e3a9b7](https://github.com/gridap/Gridap.jl/commit/8e3a9b71c64b032c5a572a7ef696f4cbf875190b).
- Added `JuliaNLSolver` to facilitat the usage in Gridap of the non-linear solvers available in the official Julia package `NLsolve`. Since commit [e5a933f](https://github.com/gridap/Gridap.jl/commit/e5a933f3093faea221a50bdd796d7f02113ed52c).

### Changed
### Removed
### Deprecated
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand Down
66 changes: 66 additions & 0 deletions src/Algebra/JuliaNLSolvers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module JuliaNLSolvers

using Gridap
using NLsolve

export JuliaNLSolver

import Gridap: solve!

mutable struct JuliaNLSolver <: NonLinearSolver
ls::LinearSolver
kwargs::Dict
end

function JuliaNLSolver(ls::LinearSolver;kwargs...)
@assert ! haskey(kwargs,:linsolve) "linsolve cannot be used here. It is managed internally"
JuliaNLSolver(ls,kwargs)
end

function JuliaNLSolver(;kwargs...)
ls = BackslashSolver()
JuliaNLSolver(ls;kwargs...)
end

mutable struct JuliaNLSolversCache
df::OnceDifferentiable
ss::SymbolicSetup
result
end

function solve!(x::AbstractVector,nls::JuliaNLSolver,op::NonLinearOperator)
cache = _setup_cache(x,nls,op)
solve!(x,nls,op,cache)
cache
end

function solve!(
x::AbstractVector,nls::JuliaNLSolver,op::NonLinearOperator,cache::JuliaNLSolversCache)
df = cache.df
ss = cache.ss
kwargs = nls.kwargs
function linsolve!(x,A,b)
ns = numerical_setup(ss,A)
solve!(x,ns,A,b)
end
r = nlsolve(df,x;linsolve=linsolve!,kwargs...)
cache.result = r
x[:] .= r.zero
end

function _setup_cache(x0,nls,op)

f!(r,x) = residual!(r,op,x)
j!(j,x) = jacobian!(j,op,x)

f0 = residual(op,x0)
j0 = jacobian(op,x0)

df = OnceDifferentiable(f!,j!,x0,f0,j0)

ss = symbolic_setup(nls.ls,j0)

JuliaNLSolversCache(df,ss,nothing)
end

end # module
23 changes: 23 additions & 0 deletions src/Algebra/LinearSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export numerical_setup
export numerical_setup!
export test_linear_solver
export LUSolver
export BackslashSolver

abstract type LinearSolver end

Expand Down Expand Up @@ -80,4 +81,26 @@ function solve!(
x .= y
end

"""
Wrapper of the backslash solver available in julia
This is typically faster than LU for a single solve
"""
struct BackslashSolver <: LinearSolver end

struct BackslashSymbolicSetup <: SymbolicSetup end

struct BackslashNumericalSetup <: NumericalSetup end

symbolic_setup(::BackslashSolver,mat::AbstractMatrix) = BackslashSymbolicSetup()

numerical_setup(::BackslashSymbolicSetup,mat::AbstractMatrix) = BackslashNumericalSetup()

function numerical_setup!(ns::BackslashNumericalSetup, mat::AbstractMatrix)
end

function solve!(
x::AbstractVector,ns::BackslashNumericalSetup,A::AbstractMatrix,b::AbstractVector)
copyto!(x, A\b)
end

end
3 changes: 3 additions & 0 deletions src/Algebra/files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ include("LinearSolvers.jl")

include("NonLinearSolvers.jl")
@reexport using Gridap.NonLinearSolvers

include("JuliaNLSolvers.jl")
@reexport using Gridap.JuliaNLSolvers
51 changes: 44 additions & 7 deletions src/FESpaces/CLagrangianFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,26 @@ function CLagrangianFESpace(
end

function CLagrangianFESpace(
::Type{T},model::DiscreteModel,order,diritags=Int[],dirimasks=nothing) where T
::Type{T},
model::DiscreteModel,
order::Integer,
diritags=Int[],
dirimasks=nothing) where T
CLagrangianFESpace(T,model,FaceLabels(model),order,diritags,dirimasks)
end

function CLagrangianFESpace(
::Type{T},
model::DiscreteModel,
facelabels::FaceLabels,
order::Integer,
diritags=Int[],
dirimasks=nothing) where T

_diri_tags = _setup_tags(model,diritags)
_diri_tags = _setup_tags(facelabels,diritags)
_diri_masks = _setup_masks(T,_diri_tags,dirimasks)

grid, node_to_label, tag_to_labels = _setup_grid(model,order)
grid, node_to_label, tag_to_labels = _setup_grid(model,facelabels,order)

CLagrangianFESpace(
T,grid,node_to_label,tag_to_labels,_diri_tags,_diri_masks)
Expand All @@ -111,6 +125,14 @@ apply_constraints_cols(
celldofids(fesp::CLagrangianFESpace) = fesp.cell_to_dofs

function interpolate_values(fesp::CLagrangianFESpace,fun::Function)
_interpolate_values(fesp,fun)
end

function interpolate_values(fesp::CLagrangianFESpace{D,Z,T},val::T) where {D,Z,T}
_interpolate_values(fesp,val)
end

function _interpolate_values(fesp,fun)
zh = zero(fesp)
fdof_to_val = free_dofs(zh)
ddof_to_val = diri_dofs(zh)
Expand All @@ -119,6 +141,14 @@ function interpolate_values(fesp::CLagrangianFESpace,fun::Function)
end

function interpolate_diri_values(fesp::CLagrangianFESpace, funs::Vector{<:Function})
_interpolate_diri_values(fesp, funs)
end

function interpolate_diri_values(fesp::CLagrangianFESpace{D,Z,T},vals::Vector{T}) where {D,Z,T}
_interpolate_diri_values(fesp, vals)
end

function _interpolate_diri_values(fesp, funs)

T = value_type(fesp)
E = eltype(T)
Expand Down Expand Up @@ -359,7 +389,7 @@ end
function _fill_interpolated_vals!(fdof_to_val,ddof_to_val,fesp,fun)

x = points(fesp.grid)
fx = fun.(x)
fx = _eval_bc(fun,x)
T = value_type(fesp)
@assert eltype(fx) == T
z = zero(T)
Expand All @@ -374,6 +404,10 @@ function _fill_interpolated_vals!(fdof_to_val,ddof_to_val,fesp,fun)

end

_eval_bc(fun::Function,x) = fun.(x)

_eval_bc(val,x) = fill(val,length(x))

function _fill_interpolated_vals_kernel!(
fdof_to_val,
ddof_to_val,
Expand Down Expand Up @@ -418,7 +452,7 @@ function _fill_diri_values!(
label = node_to_label[node]
if label in tag_to_labels[diritag]
x = node_to_coords[node]
fx = fun(x)
fx = _eval(fun,x)
comp_to_dof = node_and_comp_to_dof[node]
for comp in eachindex(fx)
mask = dirimask[comp]
Expand All @@ -435,6 +469,10 @@ function _fill_diri_values!(

end

@inline _eval(fun::Function,x) = fun(x)

@inline _eval(val,x) = val

function _same_order(order,co)
@notimplemented
end
Expand All @@ -443,9 +481,8 @@ function _same_order(order,co::ConstantCellValue)
order == co.value
end

function _setup_grid(model,order)
function _setup_grid(model,facelabels,order)

facelabels = FaceLabels(model)
_grid = Grid(model)

if _same_order(order,cellorders(_grid))
Expand Down
Loading

0 comments on commit 60b9021

Please sign in to comment.