# Best way to solve system of ODEs with different types in DifferentialEquations.jl

**URL:** <https://discourse.julialang.org/t/best-way-to-solve-system-of-odes-with-different-types-in-differentialequations-jl/43533>\
**Category:** Numerics\
**Tags:** diffeq\
**Created:** [July 23, 2020, 2:22am UTC](https://discourse.julialang.org/t/best-way-to-solve-system-of-odes-with-different-types-in-differentialequations-jl/43533 "2020-07-23T02:22:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpolakovic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tpolakovic/32/8612_2.png) [@tpolakovic](https://discourse.julialang.org/u/tpolakovic)\
**Post date:** [July 23, 2020, 2:22am UTC](https://discourse.julialang.org/t/best-way-to-solve-system-of-odes-with-different-types-in-differentialequations-jl/43533/1 "2020-07-23T02:22:08Z")

</div>

I have two fields, `A` (complex scalar field) and `B` (real vector field), which are sampled on staggered grids. This means that (in, say, three dimensions) `A` is an complex array with N^3 elements, while `B` is a real array with 3\*(N-1)^3 elements. I also have corresponding equations of motion with `dA = fA(A,B)` and `dB = fB(A,B)`. I’m rolling my own integrator, but I would prefer to switch to DifferentialEquations.jl.

I can see a trivial, even if inconvenient, solution to the difference of array shapes by flattening and stacking both into a vector and then `view`-ing `reshape`-ing them into correct form inside the problem definition.

My bigger concern is the complex/real split between the arrays. This type difference has physical relevance and is enforced through the code base, so I would prefer to not cast the real field into a complex-valued field just for sake of this numerical step. There is also space, where in practical situations, N will be large (easily N=10^4, could increase magnitude or two) and I’m not too keen on almost doubling the memory footprint just to store billions of zeros.

What is the most graceful way of solving a system of equations like this?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 23, 2020, 11:20am UTC](https://discourse.julialang.org/t/best-way-to-solve-system-of-odes-with-different-types-in-differentialequations-jl/43533/2 "2020-07-23T11:20:05Z")

</div>

An ArrayPartition should be a good data structure for this.

[https://github.com/SciML/RecursiveArrayTools.jl#arraypartition](https://github.com/SciML/RecursiveArrayTools.jl#arraypartition)
