usnistgov / fipy

FiPy is a Finite Volume PDE solver written in Python
http://pages.nist.gov/fipy/en/latest
Other
515 stars 149 forks source link

How to set/find the derivative of the solution variable? #1059

Closed CalebDmArcher closed 4 months ago

CalebDmArcher commented 4 months ago

image For the equation above, the initial distribution of the values of the solution variable 𝜙, and the values of the coefficient (1/𝜌) are known.

Is there a way to set a constant flow (or a flow distribution) among the whole object?

For example, if I have the following structure and I want to find the final voltage distribution among the object: image In this image, a constant 25 V is applied on one side of the top layer. There is no voltage flow between the surface of the structure and the ambient (If it is a temperature case, we call it adiabatic. I am not sure about the term for voltage). But since there is no flow on the outer surfaces, in the steady state, the whole structure will be 25 V. (Since the middle layer is an insulator so ideally only the whole top layer gets 25 V if the initial voltage of the whole structure is 0 V.)

So, if we put a constant current on the top layer, we should see a constant voltage drop from the 25 V side to the other side on the top layer. I assume this current can be represented as ∇𝜙, which I think is the voltage flow, or 'flow of the solution variable'.

So one of my questions is if there is a way to set this flow. I found something Internal fixed gradient but I am not sure if it is the correct one. What I hope to achieve more specifically is in 3D case, the flow has directions (x, y, and z) and may be different in both value and directions for different parts of the structure. (Like for the diffusion coefficient, Gamma0, we can use masks to assign different values to it for different parts of the structure).

My second question is whether there is a way to find the derivative of the solution variable after the equation has been solved (in the case above, it would be 𝜕𝜙/𝜕x, 𝜕𝜙/𝜕y, and 𝜕𝜙/𝜕z, and hexahedron mesh is used)?

wd15 commented 4 months ago

Is there a way to set a constant flow (or a flow distribution) among the whole object?

It's the same for any solution variable, general variable or coefficient. Any FaceVariable or CellVariable can be set to any set of given values that are chosen. Generally, this is based on a previous solution variable or on a function of position. If you want to set $\phi = x y$ for example you can use

phi[:] = mesh.x * mesh.y

assuming the CellVariable, $\phi$ is already initialized.

So one of my questions is if there is a way to set this flow. I found something Internal fixed gradient but I am not sure if it is the correct one. What I hope to achieve more specifically is in 3D case, the flow has directions (x, y, and z) and may be different in both value and directions for different parts of the structure. (Like for the diffusion coefficient, Gamma0, we can use masks to assign different values to it for different parts of the structure).

Yes, of course, use an expression involving mesh.x, mesh.y and mesh.z. What exactly is the function that you're using to set the value of $\phi$ or $\nabla \phi$?

My second question is whether there is a way to find the derivative of the solution variable after the equation has been solved (in the case above, it would be 𝜕𝜙/𝜕x, 𝜕𝜙/𝜕y, and 𝜕𝜙/𝜕z, and hexahedron mesh is used)?

That would be phi.grad and then index for individual components. This is independent of the mesh.