On 05/09/17 08:59, Dodwell, Timothy wrote:
Hi Lawrence,
Thanks for you email.
I am setting up a Multilevel Monte Carlos Algorithm for porous flow within a log-normal random permeability field (truncated KL expansion), so
Perm(x,y) = exp(\sum xi_i * phi_i(x,y)), xi ~N(0,1) and phi_i(x,y) some scaled eigenfunction of covariance operator.
I was defining the perm field as piecewise constant function, and trying to assign values at midpoints. But like you said why don’t I just define it as a function (which I probably want to do for each phi_i as used for each random sample!) Yeah, so let's assume you've computed the phis and stored them in a list of Functions, then you could write:
phis = [phi1, phi2, phi3, ...] xis = [xi1, xi2, xi3, ...] expr = exp(sum(xi*phi for xi, phi in zip(xis, phis))) perm = interpolate(expr, FunctionSpace(mesh, "DG", 0)) I think this is what you want. This evaluates expr at the nodes of the target function space and interpolates it there. Naturally this value changes if you change the definition of the nodes (the node for the DG0 space happens to be at the barycentre of the cell, but it need not be). You could also project if you wanted an L2 optimal approximation. Lawrence