comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java @ 6970:7be97faf5848

flys/issue1235: Same kicks against a few inconsistencies and bugs in the calculation of sediment loads. I believe it _do_not_ delivers the right results.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 05 Sep 2013 17:15:04 +0200
parents 733c35239fe7
children 2b022ca95b3b
comparison
equal deleted inserted replaced
6969:c137f5028591 6970:7be97faf5848
336 } 336 }
337 return partialTotal(load); 337 return partialTotal(load);
338 } 338 }
339 339
340 340
341 /** Returns true if all fraction values except SuspSediment are unset. */
342 private boolean hasOnlySuspValues(SedimentLoadFraction fraction) {
343 return (fraction.getSuspSediment() != 0d &&
344 fraction.getCoarse() == 0d &&
345 fraction.getFineMiddle() == 0d &&
346 fraction.getSand() == 0d &&
347 fraction.getSuspSand() == 0d);
348 }
349
350
351 /** Returns true if all fraction values except SuspSediment are set. */
352 private boolean hasButSuspValues(SedimentLoadFraction fraction) {
353 return (fraction.getSuspSediment() == 0d &&
354 fraction.getCoarse() != 0d &&
355 fraction.getFineMiddle() != 0d &&
356 fraction.getSand() != 0d &&
357 fraction.getSuspSand() != 0d);
358 }
359
360
361 /** Returns true if all fraction needed for total calculation are set. */
362 private boolean complete(SedimentLoadFraction fraction) {
363 return (fraction.getCoarse() != 0d &&
364 fraction.getFineMiddle() != 0d &&
365 fraction.getSand() != 0d &&
366 fraction.getSuspSand() != 0d &&
367 fraction.getSuspSediment() != 0d);
368 }
369
370 341
371 /** 342 /**
372 * Set total values in load. 343 * Set total values in load.
373 * 344 *
374 * Therefore, run over the sorted kms and find ranges where either all 345 * Therefore, run over the sorted kms and find ranges where either all
387 double lastOtherValue = 0d; 358 double lastOtherValue = 0d;
388 359
389 Range lastSuspRange = null; 360 Range lastSuspRange = null;
390 double lastSuspValue = 0d; 361 double lastSuspValue = 0d;
391 362
392 TreeSet<Double> kms = new TreeSet<Double>(load.getKms()); 363 for (double km: load.getKms()) { // kms are already sorted!
393
394 for (double km: kms) {
395 logger.debug ("Trying to add at km " + km); 364 logger.debug ("Trying to add at km " + km);
396 SedimentLoadFraction fraction = load.getFraction(km); 365 SedimentLoadFraction fraction = load.getFraction(km);
397 if (complete(fraction)) { 366 if (fraction.isComplete()) {
398 double total = fraction.getCoarse() + 367 double total = fraction.getCoarse() +
399 fraction.getFineMiddle() + 368 fraction.getFineMiddle() +
400 fraction.getSand() + 369 fraction.getSand() +
401 fraction.getSuspSand() + 370 fraction.getSuspSand() +
402 fraction.getSuspSediment(); 371 fraction.getSuspSediment();
428 lastSuspRange = null; 397 lastSuspRange = null;
429 fairLoad.setTotal(km, total, fraction.getSuspSedimentRange()); 398 fairLoad.setTotal(km, total, fraction.getSuspSedimentRange());
430 } 399 }
431 } 400 }
432 } 401 }
433 else if (hasOnlySuspValues(fraction) && lastOtherRange != null) { 402 else if (fraction.hasOnlySuspValues() && lastOtherRange != null) {
434 // Split stuff. 403 // Split stuff.
435 Range suspSedimentRange = fraction.getSuspSedimentRange(); 404 Range suspSedimentRange = fraction.getSuspSedimentRange();
436 // if intersects with last other range, cool! merge and add! 405 // if intersects with last other range, cool! merge and add!
437 if (lastOtherRange.contains(km)) { 406 if (lastOtherRange.contains(km)) {
438 double maxStart = 0d; 407 double maxStart = 0d;
453 else { 422 else {
454 // Other is "longer". 423 // Other is "longer".
455 lastOtherRange.setStart(suspSedimentRange.getEnd()); 424 lastOtherRange.setStart(suspSedimentRange.getEnd());
456 lastSuspRange = null; 425 lastSuspRange = null;
457 } 426 }
458 if (Math.abs(suspSedimentRange.getEnd() - lastOtherRange.getEnd()) < 0.1d) { 427 if (lastOtherRange != null
428 && Math.abs(suspSedimentRange.getEnd() - lastOtherRange.getEnd()) < 0.1d) {
459 lastOtherRange = null; 429 lastOtherRange = null;
460 lastSuspRange = null; 430 lastSuspRange = null;
461 } 431 }
462 fairLoad.setTotal(km, total + fraction.getSuspSediment(), totalRange); 432 fairLoad.setTotal(km, total + fraction.getSuspSediment(), totalRange);
463 } 433 }
465 lastSuspRange = suspSedimentRange; 435 lastSuspRange = suspSedimentRange;
466 lastSuspValue = fraction.getSuspSediment(); 436 lastSuspValue = fraction.getSuspSediment();
467 lastOtherRange = null; 437 lastOtherRange = null;
468 } 438 }
469 } 439 }
470 else if (hasButSuspValues(fraction) && lastSuspRange != null) { 440 else if (fraction.hasButSuspValues() && lastSuspRange != null) {
471 // If intersects with last suspsed range, merge and add 441 // If intersects with last suspsed range, merge and add
472 double total = fraction.getCoarse() + 442 double total = fraction.getCoarse() +
473 fraction.getFineMiddle() + 443 fraction.getFineMiddle() +
474 fraction.getSand() + 444 fraction.getSand() +
475 fraction.getSuspSand() + 445 fraction.getSuspSand() +
490 lastOtherRange = (Range) fraction.getCoarseRange().clone(); 460 lastOtherRange = (Range) fraction.getCoarseRange().clone();
491 lastOtherRange.setStart(lastSuspRange.getEnd()); 461 lastOtherRange.setStart(lastSuspRange.getEnd());
492 lastSuspRange = null; 462 lastSuspRange = null;
493 lastOtherValue = total - lastSuspValue; 463 lastOtherValue = total - lastSuspValue;
494 } 464 }
495 if (lastSuspRange != null && Math.abs(lastSuspRange.getEnd() - lastOtherRange.getEnd()) < 0.1d) { 465 if (lastSuspRange != null
466 && lastOtherRange != null
467 && Math.abs(lastSuspRange.getEnd() - lastOtherRange.getEnd()) < 0.1d) {
496 lastOtherRange = null; 468 lastOtherRange = null;
497 lastSuspRange = null; 469 lastSuspRange = null;
498 } 470 }
499 fairLoad.setTotal(km, total, totalRange); 471 fairLoad.setTotal(km, total, totalRange);
500 } 472 }
506 } 478 }
507 } 479 }
508 else { 480 else {
509 // Some values are missing or no intersection with former values. 481 // Some values are missing or no intersection with former values.
510 // Stay as we are. 482 // Stay as we are.
511 if (hasButSuspValues(fraction)) { 483 if (fraction.hasButSuspValues()) {
512 double total = fraction.getCoarse() + 484 double total = fraction.getCoarse() +
513 fraction.getFineMiddle() + 485 fraction.getFineMiddle() +
514 fraction.getSand() + 486 fraction.getSand() +
515 fraction.getSuspSand(); 487 fraction.getSuspSand();
516 lastOtherRange = fraction.getCoarseRange(); 488 lastOtherRange = fraction.getCoarseRange();
517 lastOtherValue = total; 489 lastOtherValue = total;
518 lastSuspRange = null; 490 lastSuspRange = null;
519 } 491 }
520 else if (hasOnlySuspValues(fraction)) { 492 else if (fraction.hasOnlySuspValues()) {
521 lastSuspRange = fraction.getSuspSedimentRange(); 493 lastSuspRange = fraction.getSuspSedimentRange();
522 lastSuspValue = fraction.getSuspSediment(); 494 lastSuspValue = fraction.getSuspSediment();
523 lastOtherRange = null; 495 lastOtherRange = null;
524 } 496 }
525 } 497 }

http://dive4elements.wald.intevation.org