user-defined vector valued function

Asked by Richard Norton

Given a function u (u=Function(V) where V = FunctionSpace(mesh, "CG", 1)) I want to define an operator/function that returns sigma(grad(u)) where sigma_1(a,b) = a and sigma_2(a,b) = 2(b^2-1)b.

I then want to include "sigma" in the following

L = dot(sigma(grad(uold)),grad(v))*dx

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Garth Wells
Solved:
Last query:
Last reply:
Revision history for this message
Garth Wells (garth-wells) said :
#1

Richard Norton wrote:
> New question #102159 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/102159
>
> Given a function u (u=Function(V) where V = FunctionSpace(mesh, "CG",
> 1)) I want to define an operator/function that returns sigma(grad(u))
> where sigma_1(a,b) = a and sigma_2(a,b) = 2(b^2-1)b.
>

I don't follow what you're after. What are (a,b)? What are sigma_1 and
sigma_2? Are they the components of sigma?

Garth

> I then want to include "sigma" in the following
>
> L = dot(sigma(grad(uold)),grad(v))*dx
>
>
>

Revision history for this message
Richard Norton (norton) said :
#2

Sorry... in mathematical terms, sigma is a vector field from R^2 to R^2. It maps (a,b) to (a,2(b^2-1)b) for real numbers a and b. So yes, sigma_1 and sigma_2 are the two components of sigma. I want to define an expression or function (called "sigma") so that the following code makes sense...

# Test and trial functions
v = TestFunction(V)
u = TrialFunction(V)
uold = Function(V)

def sigma(gradu):
    ????

# Variational problem
a = dot(grad(u), grad(v))*dx
L = dot(sigma(grad(uold)),grad(v))*dx

Revision history for this message
Best Garth Wells (garth-wells) said :
#3

On Thu, 2010-02-25 at 11:28 +0000, Richard Norton wrote:
> Question #102159 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/102159
>
> Status: Answered => Open
>
> Richard Norton is still having a problem:
> Sorry... in mathematical terms, sigma is a vector field from R^2 to R^2.
> It maps (a,b) to (a,2(b^2-1)b) for real numbers a and b. So yes,
> sigma_1 and sigma_2 are the two components of sigma. I want to define
> an expression or function (called "sigma") so that the following code
> makes sense...
>

Try this:

  # Test and trial functions
  v = TestFunction(V)
  u = TrialFunction(V)
  uold = Function(V)

  def sigma(u):
      return as_vector( [u.dx(0), 2*(u.dx(1)**2 -1)*u.dx(1)] )

  # Variational problem
  a = dot(grad(u), grad(v))*dx
  L = dot(sigma(uold),grad(v))*dx

Garth

>
>
>
> # Test and trial functions
> v = TestFunction(V)
> u = TrialFunction(V)
> uold = Function(V)
>
> def sigma(gradu):
> ????
>
> # Variational problem
> a = dot(grad(u), grad(v))*dx
> L = dot(sigma(grad(uold)),grad(v))*dx
>

Revision history for this message
Richard Norton (norton) said :
#4

Thanks Garth Wells, that solved my question.