If it's down to programming as such, I suggest stackoverflow.com, when it's about specific programming questions.
I'd probably map them out in a a graph and then use positional informaion to map them onto the new graph. Note that using pure trapezoidal information is often not desirable, you'd be downmixing onto all channels. I'd probably use the resulting adjacency matrix to figure out what channels are mixed by which source channels.
If say you're adding a new channel in between an existing channel, you can use its positional information to figure out the fractional downmix of the the two source channels, but this might be not what you get as a result. In the end, it'd be a lot down to checking.
The "easiest" approach would be to simply disregard the additional channels and map eight of the new 13 channels to their closest original counterpart, and leave the five new channels just silent.
Another Idea to consider is something like Dolby Atmos, which uses a large number of speakers but also a variable number of speakers between users. The audio source is provided in terms of "sound objects" and the mixing happens on the user's devices. The exact math to get a decent result is kept somewhat secret, it's not just a simple trapezoidal fractions based on a graph, with the distances of the speakers as their weight to the object location as an additional node. Although there are articles and tests, which suggest it isn't that much more