On 02/08/2016 06:09 PM, JT Hu wrote:
> Thanks for the suggestion - the code runs now. I basically created
> another function (similar to RHS) that returns different diffusivity
> at different point, created a dynamic function object and passed its
> pointer to create_laplace_matrix function. Is that right? I assumed
> that the same equation pretty much works and that
> create_laplace_matrix will just multiply the diffusivity values to the
> right matrix entries.
Yes, that is the idea. The coefficient you pass in is part of the
integrand when computing the matrix entries.
> I still have some problems and questions:
> 1. Is there a special reason for passing the function by pointer
> instead of reference? The RHS function is usually passed by reference.
> Just for curiosity.
It's because there is no way to default a reference in case you don't
want to pass a coefficient. For pointers, the NULL pointer is always a
viable way to create a default value.
> 2. I got some strange result as attached. The distribution should be
> simple since I have only a constant spherical heater in the center. It
> might still be an issue of the time step I set, but I am not sure if
> there is any other issue.
>
> Any suggestions or comments are highly appreciated!
Yes, this doesn't look right. If you use a coefficient, do you adjust
the time step? Experiment first by choosing a constant coefficient, then
making things gradually more complicated.