simulkade / FVTool

Finite volume toolbox for Matlab/Octave
http://fvt.simulkade.com
BSD 2-Clause "Simplified" License
97 stars 56 forks source link

Diffusion equation #11

Closed ainafp closed 5 years ago

ainafp commented 7 years ago

Hello,

First of all, thank you for this tool! It is being very helpful.

I wanted to ask if there is any way I can input a tensor in D in the diffusion term, and if so how to do it.

Thanks!

simulkade commented 7 years ago

Hi @ainafp

Thank you for your nice words. Right now, you can only have the main diagonal of a tensor in the diffusion coefficient. For instance, for a 2D diffusion problem you can write:

L = 50;  % domain length
Nx = 20; % number of cells
m = createMesh2D(Nx,Nx, L,L);
D_x = 1;
D_y = 20;
D = createFaceVariable(m, [D_x, D_y]);
Mdiff = diffusionTerm(D);

or alternatively

L = 50;  % domain length
Nx = 20; % number of cells
m = createMesh2D(Nx,Nx, L,L);
D_x = 1;
D_y = 20;
D = createFaceVariable(m, 0.0);
D.xvalue(:) = D_x;
D.yvalue(:) = D_y;
Mdiff = diffusionTerm(D);
simulkade commented 7 years ago

@ainafp Apparently, it is possible to diagonalize the diffusion tensor by finding the right coordinate.

ainafp commented 7 years ago

ok thanks! I'll try to do it diagonalizing and otherwise I will extend it to use a matrix. Thank you for being so responsive! I saw you added the example to the toolbox too.

simulkade commented 7 years ago

Please feel free to submit a PR if you manage to extend the code. I forgot to link the example. It's good that you saw it yourself!

ainafp commented 7 years ago

Hello! I am trying to input the tensor finally, entering vectors instead of scalars in xvalue, yvalue and zvalue. Can I do it as FaceVariable? Or should I do some kind of mean like harmonicMean? I am not sure I understand the difference between face and center of the cells. Thank you in advance!

simulkade commented 7 years ago

Hi @ainafp The fluxes are calculated on the interfaces between finite volume cells. Usually, the value of, e.g., concentration on the interface (or what I call a face variable) is calculated by linearly interpolating between the values of concentration in the neighboring cells. Also, the transport coefficients need to be calculated on the cell interfaces, that is done by using one of the averaging methods.
To answer your question about using a FaceVariable or averaging an scalar to get the FaceVariable, it depends on your specific problem. My guess is, you need to define the FaceVariable and assign the values of your diagonal tensors [ax, ay, az] to the FaceVariable, i.e.,

F = createFaceVariable(m, [ax, ay, az]);

which automatically assigns ax, ay, and az, to xvalue, yvalue, and zvalue of a FaceVariable, respectively.

P.S. I have written a post about the transport coefficients here