Numerical methods somewhere between lumped constant and FEM

I have a problem to solve repeatedly, which can be stated as solving Poisson’s equation along a single dimension and time, with a Neumann condition at both boundaries. That is, this is a 1d diffusion problem in time with fluxes at both ends.

Using a single lumped constant network is pretty far incorrect. I have to rescale the multiplier on the boundary condition by a factor of several dozen to create a new solution that is first-order correct.

I use dedicated FEM PDE solvers all the time, and that’s fine for solving this problem in a user-intensive way, in fact it’s my gold standard for checking other approaches. But I want to write a very simple C# program for doing this, and that’s why I was hoping to use the single lumped constant approach. I don’t want to add licensing for a store-bought numerical library and am leafing through several scientific computing textbooks.

That said, I’m considering trying lumping the constants into 3 or 10 or so places, or reproducing a finite difference approach I once wrote with interacting arrays (but in C# rather than the technical computing environment I used before) but I can see it’s going to be a fair amount of work and/or may still have a fair amount of error. Maybe this semibrutish force is a dumb approach. I wish I knew more before starting down that path.

So, what are some other strategies for solving problems like this? Are there analytic approaches? Any special tricks? Or do people create FEM and FDM and similar tools because there ain’t no easy way out?

Thanks!

I wish I could help you out (I do numerical simulations and models for a living), but I’m unfamiliar with this type of problem/method. Is there a link (maybe Wiki) describing your general problem and/or method for solving it?

For simple problems, brute force is often the best solution, in terms of minimizing man-hours (at the cost of increased cpu-hours).

So you’re trying to solve, for the region 0<x<L and 0<t<T, an equation like
d/dx(D dy/dx) = dy/dt ,
with Neumann boundary conditions at x=0 and x=L, and y(x,t=0) given; and you want to solve this repeatedly, for different boundary conditions. Is that right?

How much discretization is needed? How quickly do the fluxes change with time, how variable is the diffusion parameter D (or is it constant), and how precisely do you want to know y(x,t)? How much CPU time do you have to solve one of these equations? What answers are you trying to get out at the end?

I don’t understand what you mean about FEM being “user-intensive.” Do you just mean that there are several artificial parameters (space and time discretizations, etc.) to be specified, or is some other user input required?

I also don’t know what sort of numerical library you think you need. The matrix algebra for the diffusion equation is pretty trivial, especially in one dimension.

FEM can be processor-intensive, but this is only a 1+1-dimensional problem. Even using 10 or 100 space-grid elements and a similar number of timesteps should not be a problem on a modern PC, unless you have very little CPU time available. The matrix equations for finding delta-y are sparse, so you don’t even need a full matrix multiplication; figure fewer than 10 additions and multiplications per spacetime grid element.

There are also analytic approaches; the Green’s function for the case of constant D is easy to write down, for example. Without knowing more specifics about what you’re trying to do I can’t say whether an analytic approach is feasible.

I’m trying to find f(x,t) based on k1d2(f)/dx^2 + k2df/dt = 0, and on boundary conditions at x_min and x_max. The boundary conditions jump independently several times between different fixed values.

>I don’t understand what you mean about FEM being “user-intensive.”
Small wonder. What I said is pretty far from what I meant. Sorry! I am trying to provide a little calculator for people to solve a fairly specific problem that still has a half dozen settings as inputs. What I was trying to express was that for a person to solve problems like this, if they are using FEM software, the requirements are that they decide they are serious enough about doing this to purchase software and learn how to use it, and then go through whatever steps the software’s user interface requires (even if they are running a program/script/recipe that I give them). And this is much more intense than I think my typical user would tolerate. I need this to be about as easy as, for instance, configuring a car on some website and getting as a numerical result an indication of how badly the dealer wants to ream them. I don’t even want to trouble them to know there’s a FEM approach involved.

Processor time isn’t an issue. Any numerical methods I know including FEM would be instant for the most complicated versions, in the eyes of the user. The only time I’m trying to reduce is my time to work it out.

>The matrix algebra for the diffusion equation is pretty trivial, especially in one dimension.
It may be trivial, but I personally am even mor trivial. My math skills are pretty weak and I don’t even use matrix math directly, because of ignorance. I did take a course in linear algebra around the time of the US helecopter lifting off the roof of the embassy in Saigon, but both memories have grown pretty vague about the particulars. I have done a solution to problems like this by creating an array and then letting the cells interact with each other in some number of time steps, and I started working this particular problem out this way also (since my posting). I know I can work this algorithm out successfully, but what’s new for me is doing it in C# (which I’m learning through this and other useful exercises). At the moment, this looks like the best choice. I really ought to relearn enough matrix math to try its usefulness in my work, and if you say it’s very easy to do so I might try to do that now, but I also don’t mind just learning the programming skills today.

Thanks for some careful and well thought out information!

Feel free to post if you have further questions. I can’t help with the specifics of C#, but I can probably help with the matrices and the diffusion equation implementation.