0

I am attempting to solve two coupled 1D advection-dispersion-reaction equations:

∂[CO2]/∂t = -v∂[CO2] + D∂^2[CO2]/dx^2 - k([CO2]air - [CO2]w) - alpha([Ca2+]eq - [Ca2+]), 

and

∂[Ca2+]/∂t = -v∂[Ca2+] + D∂^2[Ca2+]/dx^2 + alpha([Ca2+]eq - [Ca2+]),

where v, k, and alpha are constants.

The equilibrium concentration of Ca2+ ([Ca2+]Eq) depends non-linearly on [CO2]. To incorporate this into my equation I've created a CellVariable CaEq. The equations are then:

CO2Eqn = TransientTerm(var=CO2) == ConvectionTerm(coeff=-v, var=CO2) + \
    DiffusionTerm(coeff=D_L, var=CO2) - \
    k*ConcCO2Air + ImplicitSourceTerm(coeff=k, var=CO2) - \
    alpha*CaEq + \
    ImplicitSourceTerm(coeff=alpha, var=Ca)

CaEqn = TransientTerm(var=Ca) == ConvectionTerm(coeff=-v, var=Ca) +\
    DiffusionTerm(coeff=D_L, var=CO2) + \
    alpha*CaEq - \
    ImplicitSourceTerm(coeff=alpha, var=Ca)

eqn = CO2Eqn & CaEqn

and I am calculating CaEq by:

CaEq.setValue(concCaEqFromPCO2(numerix.array(pConc(CO2)), T_C)).

The function concCaEqFromPCO2 finds [Ca2+]Eq from [CO2] and temperature via root finding.

When I run the solver it errors with: The coefficient must be a vector value. This occurs when v is set to an integer. When I set it to a tuple a different error arises on the line with alpha*CaEq: bad operand for unary -: 'tuple'.

Is there a way to resolve this? Or, more generally, is there a simple way to incorporate a non-linear dependence on one of the variables?

MaxC
  • 43
  • 5

1 Answers1

0

The errors you're reporting don't appear to have anything to do with the non-linear dependence of [Ca2+]Eq.

  1. A ConvectionTerm requires a vector coefficient. Wrapping this as a single element tuple or list is fine.

  2. -(3,) is not valid Python. (-3,) is fine.

There may be more effective ways to incorporate the nonlinearity of CaEq, but I'd need to see more of the usage to know for sure. That's not the cause of the errors you're getting, though.

jeguyer
  • 2,379
  • 1
  • 11
  • 15