This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Source term from a dataset

0 votes

Hello,

this question is still related to my first case I'm trying to solve with DOLFIN (and FEniCS), i.e. a 2D advection-diffusion-reaction problem for temperature with exotic source terms.

In particular I have a source term that is spatially "spotted", like a grid of localized heat sinks, imagine it to be the sum of several gaussian distributions that are localized in several $x_i$ locations:

$$ q(x, T) = f(x)g(T) $$

where $T$ is the temperature. The spatial function is:

$$ f(\mathbf{x}) = \sum_i\left[ \frac{1}{\sqrt{2\pi\sigma^2}}\exp \left( - \frac{(x-x_i)^2 + (y-y_i)^2}{2\sigma^2} \right)\right]$$

I implemented this with Python, subclassing Expression, but it is hyperslow. So I thought to save the distribution of $f(\mathbf{x})$ in a file and then interpolate it from the file and use it in the source expression.

q = InterpolateFromFile('spatial_source.pvd')
def source(u):
    return q*g(u)

I imagine there should be something integrated in dolfin to do this low-level. Am I right?

asked May 11, 2017 by RdB FEniCS Novice (220 points)
edited May 11, 2017 by RdB

1 Answer

0 votes
 
Best answer

I'm trying to do this as well, what you can do is use a c++ class in the python code like shown here:
https://fenicsproject.org/olddocs/dolfin/1.6.0/python/programmers-reference/functions/expression/Expression.html

answered May 12, 2017 by alexmm FEniCS User (4,240 points)
edited May 13, 2017 by alexmm
...