← Back to team overview

fenics team mailing list archive

Re: initial function

 

My program is implemented in C++, so I'm looking for the equivalent C++ code of your Python code. When I look at dolfin-0.8.1/dolfin/function/ProjectL2.cpp, I found it's not implemented yet:

//-----------------------------------------------------------------------------
void dolfin::projectL2(Mesh& meshB, Function& fA, Function& fB, FiniteElement& element)
{
  error("dolfin::projectL2 is disabled. Will be fixed when new Function is in place.");
  /*
  Form* a = ProjectionLibrary::create_projection_a(element.signature());
  Form* L = ProjectionLibrary::create_projection_L(element.signature(), fA);

  // Compute projection
  // FIXME: LinearPDE should not own memory from fB, allocate on heap for now
  LinearPDE* pde = new LinearPDE(*a, *L, meshB);
  pde->solve(fB);
  */
}


Could you point me a way to do the projection or interpolation in C++?

Thank you.

Best,
Chong Luo


________________________________
From: Anders Logg <logg@xxxxxxxxx>
To: fenics-dev@xxxxxxxxxx
Sent: Friday, November 7, 2008 12:52:16 PM
Subject: Re: [FEniCS-dev] initial function

On Fri, Nov 07, 2008 at 10:04:05AM -0800, Chong Luo wrote:
> I'm trying to use Newton's method to solve an elasticity problem (using FEniCS,
> of course). I want to set the initial displacement u to be a given function
> (for example, u0(x,y) = (x, -0.5*y)). How I can initialise the degrees of
> freedom vector x of the displacement u, so that it takes the values of the
> given initial function u0(x,y)? If there is no direct way to do that, maybe my
> question can be reduced to: given a component of the degrees of freedom vector
> x of some discrete function u, how to get the corresponding coordinates in the
> mesh?
> 
> Thank you!
> 
> Best,
> Chong Luo

With the current (stable) version of FEniCS, I'd recommend projecting
or interpolating whatever function you have into the finite element
space. In Python, this can be done simply by

  f = InitialValue(...)
  u0 = project(f, element)
  u0 = interpolate(f, element)

With the current development version, you should be able to just
define u0 as the initial value, and then in subsequent iterations
(when you solve for the degrees of freedom), u0 will automatically
change behavior from being defined by an expression to being defined
by its degrees of freedom.

-- 
Anders



      

Follow ups

References