Hi Dean,

I've taken your script and edited it so that it works. It's attached.
Below is a diff with some explanation.

*** trynonl.py  2008-03-19 10:16:26.000000000 -0400
--- trynonl_new.py      2008-03-19 10:36:57.000000000 -0400
***************
*** 1,14 ****
! from fipy.meshes.grid1D import Grid1D
! from fipy.variables.cellVariable import CellVariable
! from fipy.terms.transientTerm import TransientTerm
! from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
! from fipy.boundaryConditions.fixedValue import FixedValue
! from fipy.solvers.linearLUSolver import LinearLUSolver

  m = Grid1D(nx=10,dx=0.1)
! x = m.getCellCenters()[...,0]
! u = CellVariable(name="u", mesh=m, value=0, hasOld=1)
! u.setValue(1.-x)

  mu = 0.25
  speed = 1.0
--- 1,10 ----
! from fipy import *

  m = Grid1D(nx=10,dx=0.1)
! x = m.getCellCenters()[0]
! u = CellVariable(name="u", mesh=m, value=0, hasOld=1, rank=1)
! ux = CellVariable(name="ux", mesh=m, value=0, hasOld=1, rank=0)
! ux.setValue(1 - x)

  mu = 0.25
  speed = 1.0
***************


- Most common import statements are now not required if you have "from
fipy import *".
- We have changed the ordering of variables and mesh arrays so that the
first index represents dimension. This made much more sense in many ways.
- Unfortunately, you will require two velocity variables for this example. ux is
a rank 0 cell variable and is the variable to be solved. u is a 1D
vector (rank 1) variable and is required for the ConvectionTerm
coefficient. Both of these vectors are required as there is no way to
solve vector equations yet.

***************
*** 19,32 ****
      coeff = (speed,)
      print '...this will run thru the sweeps'
  else:
!     coeff = (u,)
      print '...this will fail, expect: "array dimensions are not
compatible for copy"'

  diffusion = ImplicitDiffusionTerm(coeff=mu)
  #from fipy.terms.vanLeerConvectionTerm import VanLeerConvectionTerm
  #convection = VanLeerConvectionTerm(coeff=coeff,diffusionTerm=diffusion)
! from fipy.terms.powerLawConvectionTerm import PowerLawConvectionTerm
! convection = PowerLawConvectionTerm(coeff=coeff,diffusionTerm=diffusion)

  eqn = TransientTerm() + convection - diffusion
  uleft = 1.
--- 15,27 ----
      coeff = (speed,)
      print '...this will run thru the sweeps'
  else:
!     coeff = u
      print '...this will fail, expect: "array dimensions are not
compatible for copy"'

  diffusion = ImplicitDiffusionTerm(coeff=mu)
  #from fipy.terms.vanLeerConvectionTerm import VanLeerConvectionTerm
  #convection = VanLeerConvectionTerm(coeff=coeff,diffusionTerm=diffusion)
! convection = PowerLawConvectionTerm(coeff=coeff)

  eqn = TransientTerm() + convection - diffusion
  uleft = 1.
***************

- u is a vector. It does not need to be made into a tuple.
- The ConvectionTerm does not need to know about the diffusion term anymore,
This has been automated.

*** 39,45 ****
  sweeps = 4
  u.updateOld()
  for sweep in range(sweeps):
!    resid = eqn.sweep(var = u, dt = dt,
             boundaryConditions=BC,
             solver = LinearLUSolver())
  #exception (see below) occurs in previous line
--- 34,41 ----
  sweeps = 4
  u.updateOld()
  for sweep in range(sweeps):
!     u[0] = ux
!     resid = eqn.sweep(var = ux, dt = dt,
                        boundaryConditions=BC,
                        solver = LinearLUSolver())
  #exception (see below) occurs in previous line
************

- The velocity vector needs to know the velocity.


On Wed, Mar 19, 2008 at 12:08 AM, fred2 <[EMAIL PROTECTED]> wrote:
>
>
>
>
> hello fipy experts,
>
> i'm trying to deal with a nonlinear 1d convection term, but assume i am
> doing something wrong in term description & eqn setup (rather than in
> particulars of <>ConvectionTerm, etc.,?). here, physicalField.py raises a
> ValueError exception at the start of the sweep call.
>
> from the example cases, however, i'm not sure whether this type of term is
> possible in fipy. (thanks in advance Daniel, but i must not be grasping some
> feature of your example compared to this case - i think it is exactly this
> case?!).
>
> (note: i am using a recent svn version, not the official release).
>
> the attached file has the full fipy script (and traceback msg) for a toy
> problem(!), here is the gist:
>
> u = CellVariable(name="u", mesh=m, value=0, hasOld=1)
>
> speed = 1.0
>
> linear = False
>
> if linear:
>
> coeff = (speed,)
>
> print '...this will run thru the sweeps'
>
> else:
>
> coeff = (u,)
>
> print '...this will fail, expect: "array dimensions are not compatible for
> copy"'
>
> ...
>
> convection = PowerLawConvectionTerm(coeff=coeff,diffusionTerm=diffusion)
>
> eqn = transient + convection - diffusion
>
> ...
>
> resid = eqn.sweep(var = u, dt = dt,
>
> boundaryConditions=BC,
>
> solver = LinearLUSolver())
>
> #traceback starts from sweep call.
>
> can anyone point out the error(s) in my ways?
>
> thanks much in advance,
>
>
>
> dean



-- 
Daniel Wheeler
from fipy import *

m = Grid1D(nx=10,dx=0.1)
x = m.getCellCenters()[0]
u = CellVariable(name="u", mesh=m, value=0, hasOld=1, rank=1)
ux = CellVariable(name="ux", mesh=m, value=0, hasOld=1, rank=0)
ux.setValue(1 - x)

mu = 0.25
speed = 1.0
linear = False
#linear = True
print 'linear is ', linear
if linear:
    coeff = (speed,)
    print '...this will run thru the sweeps' 
else:
    coeff = u
    print '...this will fail, expect: "array dimensions are not compatible for copy"'

diffusion = ImplicitDiffusionTerm(coeff=mu)
#from fipy.terms.vanLeerConvectionTerm import VanLeerConvectionTerm
#convection = VanLeerConvectionTerm(coeff=coeff,diffusionTerm=diffusion)
convection = PowerLawConvectionTerm(coeff=coeff)

eqn = TransientTerm() + convection - diffusion
uleft = 1.
uright = 0.
BC = (FixedValue(faces=m.getFacesLeft(), value=uleft),
               FixedValue(faces=m.getFacesRight(), value=uright))

dt = 0.01
time = 0.
sweeps = 4
u.updateOld()
for sweep in range(sweeps):
    u[0] = ux
    resid = eqn.sweep(var = ux, dt = dt,
                      boundaryConditions=BC,
                      solver = LinearLUSolver())
#exception (see below) occurs in previous line
#
   print ' sweep, resid ', sweep, resid


#######abbrev. traceback from ipython:
#---------------------------------------------------------------------------
#<type 'exceptions.ValueError'>            Traceback (most recent call last)
#
#./trynonl.py in <module>()
#     41    resid = eqn.sweep(var = u, dt = dt,
#     42            boundaryConditions=BC,
#---> 43            solver = LinearLUSolver())
#     44    print ' sweep, resid ', sweep, resid
#     45 
#
#
#...
#
#/fipy/CURRENT/fipy/tools/dimensions/physicalField.py in __init__(self, value, unit, array)
#    207         self.unit = unit
#    208         if array is not None:
#--> 209             array[:] = self.value
#    210             self.value = array
#    211 
#
#<type 'exceptions.ValueError'>: array dimensions are not compatible for copy
#WARNING: Failure executing file: <trynonl.py>
#

Reply via email to