-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Non-linear multi field problems working
- Loading branch information
Showing
6 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
include("../../src/MultiField/MultiFEOperators.jl") | ||
|
||
module MultiFEOperatorsTests | ||
|
||
using Gridap.FESpaces | ||
using Gridap.Assemblers | ||
using Gridap.FEOperators | ||
using Gridap.LinearSolvers | ||
using Gridap.NonLinearSolvers | ||
|
||
using Test | ||
using Gridap | ||
using Gridap.Geometry | ||
using Gridap.CellMaps | ||
using Gridap.Geometry.Cartesian | ||
using Gridap.FieldValues | ||
using Gridap.CellQuadratures | ||
using Gridap.CellIntegration | ||
using Gridap.Vtkio | ||
|
||
import Gridap: gradient | ||
|
||
# Define manufactured functions | ||
u1fun(x) = x[1] + x[2] | ||
u2fun(x) = x[1] - x[2] | ||
|
||
u1fun_grad(x) = VectorValue(1.0,1.0) | ||
u2fun_grad(x) = VectorValue(1.0,-1.0) | ||
|
||
gradient(::typeof(u1fun)) = u1fun_grad | ||
gradient(::typeof(u2fun)) = u2fun_grad | ||
|
||
b1fun(x) = u2fun(x) -(3.0*x[1]+x[2]+1.0) | ||
b2fun(x) = 0.0 | ||
|
||
νfun(x,u1) = (u1+1.0)*x[1] | ||
|
||
# Construct the discrete model | ||
model = CartesianDiscreteModel(domain=(0.0,1.0,0.0,1.0), partition=(4,4)) | ||
|
||
# Construct the FEspace | ||
order = 1 | ||
diritag = "boundary" | ||
fespace = ConformingFESpace(Float64,model,order,diritag) | ||
|
||
# Define test and trial | ||
V1 = TestFESpace(fespace) | ||
V2 = V1 | ||
V = [V1, V2] | ||
|
||
U1 = TrialFESpace(fespace,u1fun) | ||
U2 = TrialFESpace(fespace,u2fun) | ||
U = [U1, U2] | ||
|
||
# Define integration mesh and quadrature | ||
trian = Triangulation(model) | ||
quad = CellQuadrature(trian,order=2) | ||
|
||
# Define cell field describing the source term | ||
b1field = CellField(trian,b1fun) | ||
b2field = CellField(trian,b2fun) | ||
|
||
# Define a solution dependent material parameter | ||
ν(u1) = CellField(trian,νfun,u1) | ||
|
||
# Define residual and jacobian | ||
a(u,v,du) = inner(∇(v[1]),ν(u[1])*∇(du[1])) + inner(v[1],du[2]) + inner(∇(v[2]),∇(du[2])) | ||
b(v) = inner(v[1],b1field) + inner(v[2],b2field) | ||
|
||
res(u,v) = a(u,v,u) - b(v) | ||
jac(u,v,du) = a(u,v,du) # + inner(∇(v[1]),ν(du[1])*∇(u[1])) | ||
|
||
# Define Assembler | ||
assem = SparseMatrixAssembler(V,U) | ||
|
||
# Define the FEOperator | ||
op = NonLinearFEOperator(res,jac,V,U,assem,trian,quad) | ||
|
||
# Define the FESolver | ||
ls = LUSolver() | ||
tol = 1.e-10 | ||
maxiters = 20 | ||
nls = NewtonRaphsonSolver(ls,tol,maxiters) | ||
solver = NonLinearFESolver(nls) | ||
|
||
# Solve! | ||
uh = solve(solver,op) | ||
|
||
# Define exact solution and error | ||
u1 = CellField(trian,u1fun) | ||
e1 = u1 - uh[1] | ||
|
||
u2 = CellField(trian,u2fun) | ||
e2 = u2 - uh[2] | ||
|
||
# Define norms to measure the error | ||
l2(u) = inner(u,u) | ||
h1(u) = inner(∇(u),∇(u)) + l2(u) | ||
|
||
# Compute errors | ||
e1l2 = sqrt(sum( integrate(l2(e1),trian,quad) )) | ||
e1h1 = sqrt(sum( integrate(h1(e1),trian,quad) )) | ||
|
||
e2l2 = sqrt(sum( integrate(l2(e2),trian,quad) )) | ||
e2h1 = sqrt(sum( integrate(h1(e2),trian,quad) )) | ||
|
||
@test e1l2 < 1.e-8 | ||
@test e1h1 < 1.e-8 | ||
|
||
@test e2l2 < 1.e-8 | ||
@test e2h1 < 1.e-8 | ||
|
||
end |
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