Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discuss nonlinear problems and nonuniform data in the paper #430

Closed
kinnala opened this issue Jul 15, 2020 · 4 comments
Closed

Discuss nonlinear problems and nonuniform data in the paper #430

kinnala opened this issue Jul 15, 2020 · 4 comments

Comments

@kinnala
Copy link
Owner

kinnala commented Jul 15, 2020

From #426

The authors shall describe how the library could be used in non linear cases. In particular, the contact problem given in the first example is indeed non linear.

Can non uniform coefficients be handled ? To make my question clearer, would I be able to treat:
a linear elastic problem with a non uniform Young Modulus.
a heat transfer equation with a non uniform heat source Those non uniform coefficients are dealt with in UFL using the notion of functions spaces. Is there anything equivalent in scikit-fem ?

Should we discuss these in the paper?

@gdmcbain
Copy link
Contributor

Let's see. These are all handled easily by scikit-fem as it stands, I believe. I think the techniques are covered in the suite of examples. Going back to #24 (2018-08-07), quite new to scikit-fem, I wrote:

It wasn't immediately clear to me how to write forms with variable coefficients so I wrote an example, solving the Legendre equation.

That became ex16 ‘spatially varying coefficient’. It's a diffusion operator, but the same technique would apply to uneven Lamé coefficients in linear elasticity, nonuniform source terms.

That's for a coefficient that varies with position; for coefficients varying by subdomain, there's ex17, fufilling #89 ‘piecewise-definition of coefficients on subdomains’ (2018-11).

Then there are coefficients that are functions of finite element functions, like the Young–Laplace equation ex10, the Bratu–Gelfand equation ex23, and the Navier–Stokes equation ex27. I think that covers the kind of nonlinear cases asked about.

The Bratu–Gelfand equation is handled a bit differently; I'm not sure why. I guess it's simpler so can be, but I think it could be handled in the same way as the others if that was of interest, to have only one way of doing things.

Apart from the Bratu–Gelfand example, the fundamental notion is Basis.interpolate. The coefficient is defined as a finite element function with degrees of freedom in some Basis and then it's interpolated onto the quadrature points associated with that basis. These quadrature points have to be the same as those used by the trial and test bases in the bilinear form (or just the test basis in the linear form), and for the bilinear form itself, but the three bases don't have to be the same. Does that cover it?

@kinnala
Copy link
Owner Author

kinnala commented Jul 16, 2020

From #426

UFL offers functional spaces at quadrature points. This functional spaces are relevant when dealing with non linear constitutive equations in solid mechanics. Is there anything similar in scikit-fem ?

I've been reading an example from Chapter 26 of https://launchpadlibrarian.net/83776282/fenics-book-2011-10-27-final.pdf

from dolfin import *

# Sub domain for Dirichlet boundary condition
class DirichletBoundary(SubDomain):
    def inside(self, x, on_boundary):
        return abs(x[0] - 0.0) < DOLFIN_EPS and on_boundary

# Class for interfacing with the Newton solver
class NonlinearModelProblem(NonlinearProblem):
    def __init__(self, a, L, u, C, S, Q, bc):
        NonlinearProblem.__init__(self)
        self.a, self.L = a, L
        self.u, self.C, self.S, self.Q, self.bc = u, C, S, Q, bc
    def F(self, b, x):
        assemble(self.L, tensor=b)
        self.bc.apply(b, x)
    def J(self, A, x):
        assemble(self.a, tensor=A)
        self.bc.apply(A)
    def form(self, A, b, x):
        C = project((1.0 + self.u**2), self.Q)
        self.C.vector()[:] = C.vector()
        S = project(Dx(self.u, 0), self.Q)
        self.S.vector()[:] = S.vector()
        self.S.vector()[:] = self.S.vector()*self.C.vector()

# Create mesh and define function spaces
mesh = UnitInterval(8)
V = FunctionSpace(mesh, "Lagrange", 2)
Q = FunctionSpace(mesh, "Q", 2)

# Define boundary condition
bc = DirichletBC(V, Constant(1.0), DirichletBoundary())

# Define source and functions
f = Expression("x[0]*x[0] - 4")
u, C, S = Function(V), Function(Q), Function(Q)

# Define variational problems
w = TestFunction(V)
du = TrialFunction(V)
L = S*Dx(w, 0)*dx - f*w*dx
a = C*Dx(du, 0)*Dx(w, 0)*dx + 2*u*Dx(u, 0)*du*Dx(w, 0)*dx

# Create nonlinear problem, solver and solve
problem = NonlinearModelProblem(a, L, u, C, S, Q, bc)
solver = NewtonSolver()
solver.solve(problem, u.vector())

@kinnala
Copy link
Owner Author

kinnala commented Jul 16, 2020

It seems to me that u is defined in FunctionSpace(mesh, "Lagrange", 2) and "projected" to Q:

C = project((1.0 + self.u**2), self.Q)

Does it mean that 1 + u ** 2 is interpolated at the quadrature points and that FunctionSpace(mesh, "Q", 2) simply presents functions evaluated at quadrature points, e.g., similar to a DiscreteField? Or is it something else?

https://github.com/kinnala/scikit-fem/blob/master/skfem/element/discrete_field.py

@gdmcbain
Copy link
Contributor

Yes, that's it, nothing new.

@kinnala kinnala closed this as completed Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants