0

I need some help with setting boundary conditions for a material simulation, which is thermally degrading. The following aspects are of main concern to me at this stage:

  • Mesh motion or deformation is substituted by some kind of loose level set method. Therefore a cell can "switch" the domain (from solid to gas phase e.g.), since the material is only degrading from the outside to the inside. This is marked by a level variable. Here, I use internal boundary conditions as described here to describe the moving boundary. This is implemented in the example below.

  • I want to set a specified heat flux as boundary condition for the energy equation in form of a temperature equation (see example below). My first attempt would be to use the fixed flux condition described here, but I'm unsure whether this is physically correct. Is it possible to set a specified heat flux boundary also at internal faces, similar to the fixed value/gradient in the link above? How do I describe this in the energy equation? Moreover, there are source terms which do not use existing fipy classes (see example below). Must they be adusted in some way to allow for the internal flux boundary? I was thinking about adding a generic unity coefficient to be set to 0 on the respective faces as shown with the fixed flux boundary in the usage doc.

The minimal working example can be found below. Since it shall only give the frame for my technical questions, it is not physically correct. I'm aware that the units of the energy equation do not match in this example.

from fipy import Grid2D, CellVariable, TransientTerm, DiffusionTerm, Viewer, ImplicitSourceTerm, FaceVariable

# Consider a 2D mesh with initially constant temperature
mesh = Grid2D(nx=50, ny=50)

# Variables are defined below. Main variables are the temperature and the level variable
# Further variables are defined to include a generic term in the equation
temperature = CellVariable(mesh=mesh, name="temperature", value=300.)
pressure = CellVariable(mesh=mesh, name="pressure", value=1.2 * temperature * 330.)
transCoeff = CellVariable(mesh=mesh, name="transient coefficient", value=.01)
diffCoeff = CellVariable(mesh=mesh, name="diffusion coefficient", value=1.)

# Define first mesh row as boundary mask to simulate initial boundary condition
level_variable = CellVariable(mesh=mesh, name="level variable", value=0)
level_variable.setValue(1, where=((mesh.cellCenters[1] > 49) | (mesh.cellCenters[0] < 1)))

# Simple energy equation including a generic convection term and internal boundary terms
largeValue = 1e10
value = 1000.
transCoeff.constrain(0., mesh.exteriorFaces)
diffCoeff.constrain(0., mesh.exteriorFaces)

eqn = (
        TransientTerm(coeff=transCoeff, var=temperature) == DiffusionTerm(coeff=diffCoeff, var=temperature)
        # generic gas convection term
        - (1e2 * pressure.faceGrad).divergence

        # Internal fixed value boundary condition
        # This is to be changed for a "internal fixed flux boundary condition"
        - ImplicitSourceTerm(level_variable * largeValue, var=temperature)
        + level_variable * largeValue * value

        # Fixed Flux boundary condition on exterior faces:
        # + (mesh.facesLeft * exteriorFlux).divergence
)

# Define viewer and run simulation
viewer = Viewer(vars=[temperature, level_variable], cmap="jet")
steps = 200
dt = 1e-2

for i in range(steps):
    # Here, 950K is the criterion for the material to completely decompose
    # After reaching 950K, the level variable is set to 1 and the cell is immediately considered as boundary for 1000 K
    level_variable.setValue(1, where=(temperature >= 950.))
    eqn.solve(var=temperature, dt=dt)
    viewer.plot()

Besides the questions above I would like to understand the physical/mathematical meaning of the internal or fixed flux conditions added within the PDE. Are there any references that can be recommended in this context? I wasn't able to find further infos in the FiPy documentation. Also, general notes on the procedure are very welcome. Physical integrity is as already mentioned not given in the example. Of course, an additional mass conservation (therefore sweeping) and a detailed material model need to be implemented.

Thanks in advance for any help!

Mathematical expression

Consider following PDE. Since the coefficients of the transient terms are outside of the temporal derivative and also CellVariables, the transient term is modelled as follows:

# Transient term:

TransientTerm(var=temperature, coeff=(rho * Cv))
- temperature * (rho * Cv - rho .old * Cv.old)

The mathematical expression herefore is given here. The heat conduction is a straight-forward diffusion term with conductivity as coefficient:

DiffusionTerm(var=temperature, coeff=k)

The last rhs term describes energy change due to some generic phase change. Since there is a temporal change of a CellVariable with is not the var of the equation, I modelled it as follows:

(rho_h * enthalpy_h - rho_h.old * enthalpy_h.old) / dt
ATG12
  • 3
  • 2
  • Please express mathematically what you want to happen – jeguyer Mar 20 '23 at 15:49
  • @jeguyer I've added a section to the question, but the mathematical formulation is part of the problem. I do not really understand the background of the internal boundary formulation, therefore I'm having trouble formulating the "internal heat-flux boundary" mathematically. – ATG12 Mar 22 '23 at 14:03
  • If you do not understand the mathematics you wish to model, then knowing how FiPy represents things will not help you. What equation do you want to solve? With what boundary conditions? – jeguyer Mar 22 '23 at 14:50
  • I'm being a stickler about this because I suspect you have an [XY problem](https://en.wikipedia.org/wiki/XY_problem). If I understand what you're trying to model, what you actually know is some latent heat due to transformation, *not* the flux at a moving internal boundary. If so, then model this latent heat as a `SourceTerm` within the decomposed domain and the fluxes will take care of themselves. – jeguyer Mar 22 '23 at 14:52
  • Thanks for the answer! Indeed the overall model is more extensive, which is why I wanted to reduce the problem to the core question of the internal boundary. The mathematical description of the PDE and boundary is at least for its definition clear, I only struggle with the internal BC formulation within FiPy. For example: a fixed value is substituted by a source term and `mask * largeValue * value`. How does this translates to a fixed value within `mask`? To give a better foundation I added a PDE with a more suiting generic term to the question post and set this equation in FiPy terms. – ATG12 Mar 22 '23 at 16:50
  • The boundary I want to set is indeed a heat flux in the units of W/m2. This heat flux will be calculated in another simulation. The decomposed domain is therefore not longer of interest, only the inner domain which the respective boundary. – ATG12 Mar 22 '23 at 16:52
  • I see. The thing to understand about FiPy is that values and sources happen at cell centers and fluxes happen at the faces between cells. You don't have a fixed value, you have a fixed flux. As such, the discussion about [fixing internal gradients](https://www.ctcms.nist.gov/fipy/documentation/USAGE.html#internal-fixed-gradient) is more appropriate. The discussion on [Robin conditions](https://www.ctcms.nist.gov/fipy/documentation/USAGE.html#applying-robin-boundary-conditions) goes into a lot of detail on how they are discretized and all of that applies to internal boundaries, too. – jeguyer Mar 23 '23 at 17:59
  • A caveat is that your level set presumably does not fall neatly on FiPy faces. @wd15 has more experience with that sort of thing. – jeguyer Mar 23 '23 at 18:00
  • I tried using the internal fixed gradient as boundary, but ran into different errors. First of all, the `mask` varibale should typically be a FaceVariable as mentioned in the Using FiPy docs. This leads to a `TypeError: The coefficient can not be a FaceVariable.` If I change the variable to a CellVariable, another error occurs: `AttributeError: 'ImplicitSourceTerm' object has no attribute 'divergence'`. – ATG12 Apr 04 '23 at 08:39
  • I found the error, the paranthesis were inconsistent which lead to both errors. – ATG12 Apr 05 '23 at 06:17
  • I'm glad you figured it out – jeguyer Apr 05 '23 at 13:30

0 Answers0