Sorry for the slow reply. Expressions like [(1.0/density),] and [(temperature / density**2),] unfortunately don't work reliably in FiPy. They might work, but I wouldn't count on it.
The issue is that FiPy sees a Python list that holds the instantaneous value of a rank-0 CelVariable, rather than seeing a rank-1 CellVariable that can change. This is down to Python syntax that FiPy doesn't get a chance reinterpret. I believe you'll have better luck with numerix.dot((1.0/density) * [[1.]], temperature.grad) and numerix.dot((temperature / density**2) * [[1]], density.grad). You could as readily write (1.0/density) * temperature.grad[0] and (temperature / density**2) * density.grad[0]. It depends on what you really mean, which usually is clearer in higher dimensions. > On Dec 14, 2017, at 12:26 PM, Kevin Blondino <[email protected]> wrote: > > Hi, > > I've adjusted the system a little bit, and I wanted some verification and > more criticism. > > I took your suggestions about (Z.grad)**2 and changed it to > numerix.dot(Z.grad, Z.grad) to give me a scalar. > > In addition, the terms that could not be easily written as convection terms: > \begin{align} > \frac{1}{n} \frac{\partial T}{\partial x} + \frac{T}{n^2} > \frac{\partial n}{\partial x} > \end{align} > > I wrote them by making the coefficients a vector and then dotting with the > gradient: > numerix.dot([(1.0/density),], temperature.grad) + > numerix.dot([(temperature / density**2), ], density.grad) > > Are these things a fair / reasonable thing to do? I have looked over my > system in the most original form and it seems there is no way to show them in > a ConvectionTerm or ImplicitSourceTerm. > > I apologize if the code is a little difficult to read. > > Thanks, > Kevin > > On 12 December 2017 at 16:37, Guyer, Jonathan E. Dr. (Fed) > <[email protected]> wrote: > Kevin - > > - Should I model the last term in the temperature (T) equations as a > convection term or explicit source term? > > The best coupling would be obtained by treating this term as a convection > term on n with a velocity proportional to \partial T/\partial x. > Unfortunately, (D/n) sits outside the derivatives and so FiPy has no implicit > way to represent it. I think you're stuck with the source. > > - What about the "S_Z" term in the Z equation? > > Again, as written, these are just sources. > > - Is it required that I declare diffusivity (D) as a cell variable, as it is > now? > > In order to write an equation to solve for D, it must be a CellVariable, > however, there's no advantage in adding this as a solution equation. I would > just define D as a function of Z. As such, it's better to define it as a > FaceVariable for use in the DiffusionTerms. > > Note: > > The expressions Z*(Z.grad) and (Z.grad)**2 amount to multiplying a scalar by > a vector and a vector by a vector, but D needs to be scalar. I recommend > working out what your equations would be using either divergence and gradient > operators or Einstein notation, as premature introduction of d/dx in 1D > equations leads to equations that are difficult to debug and render properly. > > You may find that when you go back to the source equations in general > vectorial form that the sources in the T and Z equations are amenable to > being written as convection terms or implicit sources, which would be good. > > - Jon > > > > On Dec 11, 2017, at 2:42 PM, Kevin Blondino <[email protected]> wrote: > > > > Hello, > > > > I have a somewhat complicated system of highly nonlinear, 1D PDE's which I > > am having trouble modeling. The issue is that I am not sure how to > > represent certain terms. > > > > Here is a the following LaTeX code for the system, as to make sure there is > > no ambiguity: > > \begin{align} > > \frac{\partial n}{\partial t} \,&=\, \frac{\partial}{\partial > > x}\left(D \frac{\partial n}{\partial x}\right) \\ > > \frac{\partial T}{\partial t} \,&=\, \frac{\partial}{\partial > > x}\left(D \frac{\partial T}{\partial x}\right) + > > \frac{D}{n}\,\frac{\partial n}{\partial x}\,\frac{\partial T}{\partial x} \\ > > \frac{\partial Z}{\partial t} \,&=\, \frac{\partial}{\partial > > x}\left(D \frac{\partial Z}{\partial x}\right) + > > \frac{T}{n^2}\frac{\partial n}{\partial x} + \frac{1}{n}\frac{\partial > > T}{\partial x} + G(Z) \\ > > G(Z) \,&=\, a + b(Z - Z_S) + c(Z - Z_S)^3 \\ > > D \,&=\, 1 + \frac{1}{1 + Z^2 + Z\cdot\frac{\partial Z}{\partial x} + > > \left(\frac{\partial Z}{\partial x}\right)^2} > > \end{align} > > > > I have purposefully squelched many coefficients as possible to make simple. > > > > The main code I have been using to model them is as follows: > > > > # ----------------- Variable Declarations ----------------- > > density = CellVariable(name=r"$n$", mesh=mesh, hasOld=True) > > > > temperature = CellVariable(name=r"$T$", mesh=mesh, hasOld=True) > > > > Z = CellVariable(name=r"$Z$", mesh=mesh, hasOld=True) > > > > ## Diffusivity > > D = CellVariable(name=r"$D$", mesh=mesh, hasOld=True) > > > > ... (initial and boundary conditions are here) ... > > > > # ----------------- PDE Declarations ---------------------- > > # Diffusivity Equation (D) > > diffusivity_equation = ImplicitSourceTerm(coeff=1.0, var=D) == 1.0 + > > 1.0 / (1 + Z**2 + Z*(Z.grad) + (Z.grad)**2) > > > > > > # Density Equation (n) > > density_equation = TransientTerm(var=density) == > > DiffusionTerm(coeff=D, var=density) > > > > > > # Temperature Equation (T) > > S_T = (D/density) * numerix.dot(density.grad,temperature.grad) # ??? > > S_T_conv = ConvectionTerm(coeff=(D/density)*density.grad, > > var=temperature) # ?? > > > > temp_equation = TransientTerm(var=temperature) == > > DiffusionTerm(coeff=D, var=temperature) + S_T > > > > > > # Z Equation > > G = a + b*(Z - Z_S) + c*(Z - Z_S)**3 > > S_Z = G + (1 / density)*temperature.grad.mag + (temperature / > > density**2)*density.grad.mag # ??? > > Z_equation = TransientTerm(coeff=1.0, var=Z) == > > DiffusionTerm(coeff=D, var=Z) + S_Z > > > > # Fully-Coupled Equation > > full_equation = density_equation & temp_equation & Z_equation & > > diffusivity_equation > > > > Should I model the last term in the temperature (T) equations as a > > convection term or explicit source term? > > What about the "S_Z" term in the Z equation? > > Is it required that I declare diffusivity (D) as a cell variable, as it is > > now? > > > > I appreciate any help that can be given. > > > > Thank you, > > Kevin > > _______________________________________________ > > fipy mailing list > > [email protected] > > http://www.ctcms.nist.gov/fipy > > [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ] > > > _______________________________________________ > fipy mailing list > [email protected] > http://www.ctcms.nist.gov/fipy > [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ] > > _______________________________________________ > fipy mailing list > [email protected] > http://www.ctcms.nist.gov/fipy > [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ] _______________________________________________ fipy mailing list [email protected] http://www.ctcms.nist.gov/fipy [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
