Skip to content

Commit 60b9021

Browse files
committed
Merge branch 'master' of github.com:gridap/Gridap.jl into DivConformingRefFE
2 parents 20080cf + 01e224f commit 60b9021

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+973
-83
lines changed

Manifest.toml

+84
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# This file is machine-generated - editing it directly is not advised
22

3+
[[ArrayInterface]]
4+
deps = ["LinearAlgebra", "Requires", "SparseArrays"]
5+
git-tree-sha1 = "981354dab938901c2b607a213e62d9defa50b698"
6+
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
7+
version = "1.2.1"
8+
39
[[Base64]]
410
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
511

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

24+
[[Calculus]]
25+
deps = ["Compat"]
26+
git-tree-sha1 = "bd8bbd105ba583a42385bd6dc4a20dad8ab3dc11"
27+
uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
28+
version = "0.5.0"
29+
1830
[[CodecZlib]]
1931
deps = ["BinaryProvider", "Libdl", "TranscodingStreams"]
2032
git-tree-sha1 = "05916673a2627dd91b4969ff8ba6941bc85a960e"
@@ -27,6 +39,12 @@ git-tree-sha1 = "50b3ae4d643dc27eaff69fb6be06ee094d5500c9"
2739
uuid = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
2840
version = "0.7.0"
2941

42+
[[CommonSubexpressions]]
43+
deps = ["Test"]
44+
git-tree-sha1 = "efdaf19ab11c7889334ca247ff4c9f7c322817b0"
45+
uuid = "bbf7d656-a473-5ed7-a52c-81e309532950"
46+
version = "0.2.0"
47+
3048
[[Compat]]
3149
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
3250
git-tree-sha1 = "84aa74986c5b9b898b0d1acaf3258741ee64754f"
@@ -47,6 +65,30 @@ uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
4765
deps = ["Mmap"]
4866
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
4967

68+
[[DiffEqDiffTools]]
69+
deps = ["ArrayInterface", "LinearAlgebra", "Requires", "SparseArrays", "StaticArrays"]
70+
git-tree-sha1 = "21b855cb29ec4594f9651e0e9bdc0cdcfdcd52c1"
71+
uuid = "01453d9d-ee7c-5054-8395-0335cb756afa"
72+
version = "1.3.0"
73+
74+
[[DiffResults]]
75+
deps = ["Compat", "StaticArrays"]
76+
git-tree-sha1 = "34a4a1e8be7bc99bc9c611b895b5baf37a80584c"
77+
uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
78+
version = "0.0.4"
79+
80+
[[DiffRules]]
81+
deps = ["Random", "Test"]
82+
git-tree-sha1 = "dc0869fb2f5b23466b32ea799bd82c76480167f7"
83+
uuid = "b552c78f-8df3-52c6-915a-8e097449b14b"
84+
version = "0.0.10"
85+
86+
[[Distances]]
87+
deps = ["LinearAlgebra", "Statistics"]
88+
git-tree-sha1 = "23717536c81b63e250f682b0e0933769eecd1411"
89+
uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
90+
version = "0.8.2"
91+
5092
[[Distributed]]
5193
deps = ["Random", "Serialization", "Sockets"]
5294
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
@@ -57,6 +99,12 @@ git-tree-sha1 = "769ac4057ed875f433372e9a571a2cb86347d1be"
5799
uuid = "442a2c76-b920-505d-bb47-c5924d526838"
58100
version = "0.3.3"
59101

102+
[[ForwardDiff]]
103+
deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "InteractiveUtils", "LinearAlgebra", "NaNMath", "Random", "SparseArrays", "SpecialFunctions", "StaticArrays", "Test"]
104+
git-tree-sha1 = "4c4d727f1b7e0092134fabfab6396b8945c1ea5b"
105+
uuid = "f6369f11-7733-5829-9624-2563aa707210"
106+
version = "0.10.3"
107+
60108
[[InteractiveUtils]]
61109
deps = ["Markdown"]
62110
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
@@ -79,6 +127,12 @@ git-tree-sha1 = "aeec7a341652d47bc773475a42952fa78eccd7cc"
79127
uuid = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
80128
version = "0.8.0"
81129

130+
[[LineSearches]]
131+
deps = ["LinearAlgebra", "NLSolversBase", "NaNMath", "Parameters", "Printf", "Test"]
132+
git-tree-sha1 = "54eb90e8dbe745d617c78dee1d6ae95c7f6f5779"
133+
uuid = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
134+
version = "7.0.1"
135+
82136
[[LinearAlgebra]]
83137
deps = ["Libdl"]
84138
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -93,12 +147,36 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
93147
[[Mmap]]
94148
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
95149

150+
[[NLSolversBase]]
151+
deps = ["Calculus", "DiffEqDiffTools", "DiffResults", "Distributed", "ForwardDiff"]
152+
git-tree-sha1 = "c430bd3f2dfcffc30688cf4a9cb61535e8d85f65"
153+
uuid = "d41bc354-129a-5804-8e4c-c37616107c6c"
154+
version = "7.4.1"
155+
156+
[[NLsolve]]
157+
deps = ["DiffEqDiffTools", "Distances", "ForwardDiff", "LineSearches", "LinearAlgebra", "NLSolversBase", "Printf", "Reexport"]
158+
git-tree-sha1 = "c9578878f56f425a2160f5b436c7f79a154d154c"
159+
uuid = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
160+
version = "4.1.0"
161+
162+
[[NaNMath]]
163+
deps = ["Compat"]
164+
git-tree-sha1 = "ce3b85e484a5d4c71dd5316215069311135fa9f2"
165+
uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
166+
version = "0.3.2"
167+
96168
[[OrderedCollections]]
97169
deps = ["Random", "Serialization", "Test"]
98170
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
99171
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
100172
version = "1.1.0"
101173

174+
[[Parameters]]
175+
deps = ["OrderedCollections"]
176+
git-tree-sha1 = "1dfd7cd50a8eb06ef693a4c2bbe945943cd000c5"
177+
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a"
178+
version = "0.11.0"
179+
102180
[[Parsers]]
103181
deps = ["Dates", "Test"]
104182
git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b"
@@ -139,6 +217,12 @@ git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0"
139217
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
140218
version = "0.2.0"
141219

220+
[[Requires]]
221+
deps = ["Test"]
222+
git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1"
223+
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
224+
version = "0.5.2"
225+
142226
[[SHA]]
143227
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
144228

NEWS.md

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88

99
### Added
10+
- 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).
11+
- Added `mean` operator for quantities restricted to a `SkeletonTriangulation`. Since commit [83798b4](https://github.com/gridap/Gridap.jl/commit/83798b4f38aaf482b968ffd0359eb75c79a21385).
12+
- Extended `NormalVector` to `SkeletonTriangulations`. Since commit [5fb8487](https://github.com/gridap/Gridap.jl/commit/5fb84871128c4388559cc5052d9ff00f0be19462).
13+
- 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).
14+
- 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).
15+
- 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).
16+
- 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).
17+
1018
### Changed
1119
### Removed
1220
### Deprecated

Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
88
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
99
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1010
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
11+
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
1112
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
1213
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1314
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

src/Algebra/JuliaNLSolvers.jl

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
module JuliaNLSolvers
2+
3+
using Gridap
4+
using NLsolve
5+
6+
export JuliaNLSolver
7+
8+
import Gridap: solve!
9+
10+
mutable struct JuliaNLSolver <: NonLinearSolver
11+
ls::LinearSolver
12+
kwargs::Dict
13+
end
14+
15+
function JuliaNLSolver(ls::LinearSolver;kwargs...)
16+
@assert ! haskey(kwargs,:linsolve) "linsolve cannot be used here. It is managed internally"
17+
JuliaNLSolver(ls,kwargs)
18+
end
19+
20+
function JuliaNLSolver(;kwargs...)
21+
ls = BackslashSolver()
22+
JuliaNLSolver(ls;kwargs...)
23+
end
24+
25+
mutable struct JuliaNLSolversCache
26+
df::OnceDifferentiable
27+
ss::SymbolicSetup
28+
result
29+
end
30+
31+
function solve!(x::AbstractVector,nls::JuliaNLSolver,op::NonLinearOperator)
32+
cache = _setup_cache(x,nls,op)
33+
solve!(x,nls,op,cache)
34+
cache
35+
end
36+
37+
function solve!(
38+
x::AbstractVector,nls::JuliaNLSolver,op::NonLinearOperator,cache::JuliaNLSolversCache)
39+
df = cache.df
40+
ss = cache.ss
41+
kwargs = nls.kwargs
42+
function linsolve!(x,A,b)
43+
ns = numerical_setup(ss,A)
44+
solve!(x,ns,A,b)
45+
end
46+
r = nlsolve(df,x;linsolve=linsolve!,kwargs...)
47+
cache.result = r
48+
x[:] .= r.zero
49+
end
50+
51+
function _setup_cache(x0,nls,op)
52+
53+
f!(r,x) = residual!(r,op,x)
54+
j!(j,x) = jacobian!(j,op,x)
55+
56+
f0 = residual(op,x0)
57+
j0 = jacobian(op,x0)
58+
59+
df = OnceDifferentiable(f!,j!,x0,f0,j0)
60+
61+
ss = symbolic_setup(nls.ls,j0)
62+
63+
JuliaNLSolversCache(df,ss,nothing)
64+
end
65+
66+
end # module

src/Algebra/LinearSolvers.jl

+23
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export numerical_setup
1515
export numerical_setup!
1616
export test_linear_solver
1717
export LUSolver
18+
export BackslashSolver
1819

1920
abstract type LinearSolver end
2021

@@ -80,4 +81,26 @@ function solve!(
8081
x .= y
8182
end
8283

84+
"""
85+
Wrapper of the backslash solver available in julia
86+
This is typically faster than LU for a single solve
87+
"""
88+
struct BackslashSolver <: LinearSolver end
89+
90+
struct BackslashSymbolicSetup <: SymbolicSetup end
91+
92+
struct BackslashNumericalSetup <: NumericalSetup end
93+
94+
symbolic_setup(::BackslashSolver,mat::AbstractMatrix) = BackslashSymbolicSetup()
95+
96+
numerical_setup(::BackslashSymbolicSetup,mat::AbstractMatrix) = BackslashNumericalSetup()
97+
98+
function numerical_setup!(ns::BackslashNumericalSetup, mat::AbstractMatrix)
99+
end
100+
101+
function solve!(
102+
x::AbstractVector,ns::BackslashNumericalSetup,A::AbstractMatrix,b::AbstractVector)
103+
copyto!(x, A\b)
104+
end
105+
83106
end

src/Algebra/files.jl

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ include("LinearSolvers.jl")
44

55
include("NonLinearSolvers.jl")
66
@reexport using Gridap.NonLinearSolvers
7+
8+
include("JuliaNLSolvers.jl")
9+
@reexport using Gridap.JuliaNLSolvers

src/FESpaces/CLagrangianFESpaces.jl

+44-7
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,26 @@ function CLagrangianFESpace(
8181
end
8282

8383
function CLagrangianFESpace(
84-
::Type{T},model::DiscreteModel,order,diritags=Int[],dirimasks=nothing) where T
84+
::Type{T},
85+
model::DiscreteModel,
86+
order::Integer,
87+
diritags=Int[],
88+
dirimasks=nothing) where T
89+
CLagrangianFESpace(T,model,FaceLabels(model),order,diritags,dirimasks)
90+
end
91+
92+
function CLagrangianFESpace(
93+
::Type{T},
94+
model::DiscreteModel,
95+
facelabels::FaceLabels,
96+
order::Integer,
97+
diritags=Int[],
98+
dirimasks=nothing) where T
8599

86-
_diri_tags = _setup_tags(model,diritags)
100+
_diri_tags = _setup_tags(facelabels,diritags)
87101
_diri_masks = _setup_masks(T,_diri_tags,dirimasks)
88102

89-
grid, node_to_label, tag_to_labels = _setup_grid(model,order)
103+
grid, node_to_label, tag_to_labels = _setup_grid(model,facelabels,order)
90104

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

113127
function interpolate_values(fesp::CLagrangianFESpace,fun::Function)
128+
_interpolate_values(fesp,fun)
129+
end
130+
131+
function interpolate_values(fesp::CLagrangianFESpace{D,Z,T},val::T) where {D,Z,T}
132+
_interpolate_values(fesp,val)
133+
end
134+
135+
function _interpolate_values(fesp,fun)
114136
zh = zero(fesp)
115137
fdof_to_val = free_dofs(zh)
116138
ddof_to_val = diri_dofs(zh)
@@ -119,6 +141,14 @@ function interpolate_values(fesp::CLagrangianFESpace,fun::Function)
119141
end
120142

121143
function interpolate_diri_values(fesp::CLagrangianFESpace, funs::Vector{<:Function})
144+
_interpolate_diri_values(fesp, funs)
145+
end
146+
147+
function interpolate_diri_values(fesp::CLagrangianFESpace{D,Z,T},vals::Vector{T}) where {D,Z,T}
148+
_interpolate_diri_values(fesp, vals)
149+
end
150+
151+
function _interpolate_diri_values(fesp, funs)
122152

123153
T = value_type(fesp)
124154
E = eltype(T)
@@ -359,7 +389,7 @@ end
359389
function _fill_interpolated_vals!(fdof_to_val,ddof_to_val,fesp,fun)
360390

361391
x = points(fesp.grid)
362-
fx = fun.(x)
392+
fx = _eval_bc(fun,x)
363393
T = value_type(fesp)
364394
@assert eltype(fx) == T
365395
z = zero(T)
@@ -374,6 +404,10 @@ function _fill_interpolated_vals!(fdof_to_val,ddof_to_val,fesp,fun)
374404

375405
end
376406

407+
_eval_bc(fun::Function,x) = fun.(x)
408+
409+
_eval_bc(val,x) = fill(val,length(x))
410+
377411
function _fill_interpolated_vals_kernel!(
378412
fdof_to_val,
379413
ddof_to_val,
@@ -418,7 +452,7 @@ function _fill_diri_values!(
418452
label = node_to_label[node]
419453
if label in tag_to_labels[diritag]
420454
x = node_to_coords[node]
421-
fx = fun(x)
455+
fx = _eval(fun,x)
422456
comp_to_dof = node_and_comp_to_dof[node]
423457
for comp in eachindex(fx)
424458
mask = dirimask[comp]
@@ -435,6 +469,10 @@ function _fill_diri_values!(
435469

436470
end
437471

472+
@inline _eval(fun::Function,x) = fun(x)
473+
474+
@inline _eval(val,x) = val
475+
438476
function _same_order(order,co)
439477
@notimplemented
440478
end
@@ -443,9 +481,8 @@ function _same_order(order,co::ConstantCellValue)
443481
order == co.value
444482
end
445483

446-
function _setup_grid(model,order)
484+
function _setup_grid(model,facelabels,order)
447485

448-
facelabels = FaceLabels(model)
449486
_grid = Grid(model)
450487

451488
if _same_order(order,cellorders(_grid))

0 commit comments

Comments
 (0)