Refactoring of risklib needed to solve the problem of the block size dependence

See https://bugs.launchpad.net/oq-engine/+bug/1242372 and https://bugs.launchpad.net/oq-engine/+bug/1309373. The tests pass: https://ci.openquake.org/job/zdevel_oq-risklib/22/