Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java @ 6404:e6ceab9e3091
prep issue1235: Rename functions and variable to indicate use of other susp values.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 24 Jun 2013 10:15:34 +0200 |
parents | df1a3826c691 |
children | 74b8362f6a4c |
comparison
equal
deleted
inserted
replaced
6403:2d538e01da7c | 6404:e6ceab9e3091 |
---|---|
296 return partialTotal(load); | 296 return partialTotal(load); |
297 } | 297 } |
298 | 298 |
299 | 299 |
300 /** Returns true if all fraction values except SuspSediment are unset. */ | 300 /** Returns true if all fraction values except SuspSediment are unset. */ |
301 private boolean hasOnlySuspSediment(SedimentLoadFraction fraction) { | 301 private boolean hasOnlySuspValues(SedimentLoadFraction fraction) { |
302 return (fraction.getSuspSediment() != 0d && | 302 return (fraction.getSuspSediment() != 0d && |
303 fraction.getCoarse() == 0d && | 303 fraction.getCoarse() == 0d && |
304 fraction.getFineMiddle() == 0d && | 304 fraction.getFineMiddle() == 0d && |
305 fraction.getSand() == 0d && | 305 fraction.getSand() == 0d && |
306 fraction.getSuspSand() == 0d); | 306 fraction.getSuspSand() == 0d); |
307 } | 307 } |
308 | 308 |
309 | 309 |
310 /** Returns true if all fraction values except SuspSediment are set. */ | 310 /** Returns true if all fraction values except SuspSediment are set. */ |
311 private boolean hasButSuspSediment(SedimentLoadFraction fraction) { | 311 private boolean hasButSuspValues(SedimentLoadFraction fraction) { |
312 return (fraction.getSuspSediment() == 0d && | 312 return (fraction.getSuspSediment() == 0d && |
313 fraction.getCoarse() != 0d && | 313 fraction.getCoarse() != 0d && |
314 fraction.getFineMiddle() != 0d && | 314 fraction.getFineMiddle() != 0d && |
315 fraction.getSand() != 0d && | 315 fraction.getSand() != 0d && |
316 fraction.getSuspSand() != 0d); | 316 fraction.getSuspSand() != 0d); |
340 SedimentLoad fairLoad = load; | 340 SedimentLoad fairLoad = load; |
341 | 341 |
342 Range lastOtherRange = null; | 342 Range lastOtherRange = null; |
343 double lastOtherValue = 0d; | 343 double lastOtherValue = 0d; |
344 | 344 |
345 Range lastSuspSedimentRange = null; | 345 Range lastSuspRange = null; |
346 double lastSuspSedimentValue = 0d; | 346 double lastSuspValue = 0d; |
347 | 347 |
348 for (double km: load.getKms()) { | 348 for (double km: load.getKms()) { |
349 logger.debug ("Trying to add at km " + km); | 349 logger.debug ("Trying to add at km " + km); |
350 SedimentLoadFraction fraction = load.getFraction(km); | 350 SedimentLoadFraction fraction = load.getFraction(km); |
351 if (complete(fraction)) { | 351 if (complete(fraction)) { |
356 fraction.getSuspSediment(); | 356 fraction.getSuspSediment(); |
357 // Easiest case. Add values up and set'em. | 357 // Easiest case. Add values up and set'em. |
358 if (fraction.getCoarseRange().equals( | 358 if (fraction.getCoarseRange().equals( |
359 fraction.getSuspSedimentRange())) { | 359 fraction.getSuspSedimentRange())) { |
360 lastOtherRange = null; | 360 lastOtherRange = null; |
361 lastSuspSedimentRange = null; | 361 lastSuspRange = null; |
362 fairLoad.setTotal(km, total, fraction.getCoarseRange()); | 362 fairLoad.setTotal(km, total, fraction.getCoarseRange()); |
363 } | 363 } |
364 else { | 364 else { |
365 // Need to split a range. | 365 // Need to split a range. |
366 if (fraction.getCoarseRange().getEnd() | 366 if (fraction.getCoarseRange().getEnd() |
367 < fraction.getSuspSedimentRange().getEnd()) { | 367 < fraction.getSuspSedimentRange().getEnd()) { |
368 // Schwebstoff is longer. | 368 // Schwebstoff is longer. |
369 // Adjust and remember schwebstoffs range and value. | 369 // Adjust and remember schwebstoffs range and value. |
370 lastSuspSedimentRange = (Range) fraction.getSuspSedimentRange().clone(); | 370 lastSuspRange = (Range) fraction.getSuspSedimentRange().clone(); |
371 lastSuspSedimentRange.setStart(fraction.getCoarseRange().getEnd()); | 371 lastSuspRange.setStart(fraction.getCoarseRange().getEnd()); |
372 lastSuspSedimentValue = fraction.getSuspSediment(); | 372 lastSuspValue = fraction.getSuspSediment(); |
373 lastOtherRange = null; | 373 lastOtherRange = null; |
374 fairLoad.setTotal(km, total, fraction.getCoarseRange()); | 374 fairLoad.setTotal(km, total, fraction.getCoarseRange()); |
375 } | 375 } |
376 else { | 376 else { |
377 // Geschiebe is longer. | 377 // Geschiebe is longer. |
378 // Adjust and remember other values. | 378 // Adjust and remember other values. |
379 lastOtherRange = (Range) fraction.getSuspSedimentRange().clone(); | 379 lastOtherRange = (Range) fraction.getSuspSedimentRange().clone(); |
380 lastOtherRange.setStart(fraction.getSuspSedimentRange().getEnd()); | 380 lastOtherRange.setStart(fraction.getSuspSedimentRange().getEnd()); |
381 lastOtherValue = (total - fraction.getSuspSediment()); | 381 lastOtherValue = (total - fraction.getSuspSediment()); |
382 lastSuspSedimentRange = null; | 382 lastSuspRange = null; |
383 fairLoad.setTotal(km, total, fraction.getSuspSedimentRange()); | 383 fairLoad.setTotal(km, total, fraction.getSuspSedimentRange()); |
384 } | 384 } |
385 } | 385 } |
386 } | 386 } |
387 else if (hasOnlySuspSediment(fraction) && lastOtherRange != null) { | 387 else if (hasOnlySuspValues(fraction) && lastOtherRange != null) { |
388 // Split stuff. | 388 // Split stuff. |
389 Range suspSedimentRange = fraction.getSuspSedimentRange(); | 389 Range suspSedimentRange = fraction.getSuspSedimentRange(); |
390 // if intersects with last other range, cool! merge and add! | 390 // if intersects with last other range, cool! merge and add! |
391 if (lastOtherRange.contains(km)) { | 391 if (lastOtherRange.contains(km)) { |
392 double maxStart = 0d; | 392 double maxStart = 0d; |
397 minEnd = Math.min(suspSedimentRange.getEnd(), | 397 minEnd = Math.min(suspSedimentRange.getEnd(), |
398 lastOtherRange.getEnd()); | 398 lastOtherRange.getEnd()); |
399 double total = lastOtherValue + fraction.getSuspSediment(); | 399 double total = lastOtherValue + fraction.getSuspSediment(); |
400 Range totalRange = new Range(maxStart, minEnd); | 400 Range totalRange = new Range(maxStart, minEnd); |
401 if (suspSedimentRange.getEnd() > lastOtherRange.getEnd()) { | 401 if (suspSedimentRange.getEnd() > lastOtherRange.getEnd()) { |
402 lastSuspSedimentRange = (Range) suspSedimentRange.clone(); | 402 lastSuspRange = (Range) suspSedimentRange.clone(); |
403 lastSuspSedimentRange.setStart(lastOtherRange.getEnd()); | 403 lastSuspRange.setStart(lastOtherRange.getEnd()); |
404 lastSuspSedimentValue = fraction.getSuspSediment(); | 404 lastSuspValue = fraction.getSuspSediment(); |
405 lastOtherRange = null; | 405 lastOtherRange = null; |
406 } | 406 } |
407 else { | 407 else { |
408 // Other is "longer". | 408 // Other is "longer". |
409 lastOtherRange.setStart(suspSedimentRange.getEnd()); | 409 lastOtherRange.setStart(suspSedimentRange.getEnd()); |
410 lastSuspSedimentRange = null; | 410 lastSuspRange = null; |
411 } | 411 } |
412 if (Math.abs(suspSedimentRange.getEnd() - lastOtherRange.getEnd()) < 0.1d) { | 412 if (Math.abs(suspSedimentRange.getEnd() - lastOtherRange.getEnd()) < 0.1d) { |
413 lastOtherRange = null; | 413 lastOtherRange = null; |
414 lastSuspSedimentRange = null; | 414 lastSuspRange = null; |
415 } | 415 } |
416 fairLoad.setTotal(km, total + fraction.getSuspSediment(), totalRange); | 416 fairLoad.setTotal(km, total + fraction.getSuspSediment(), totalRange); |
417 } | 417 } |
418 else { | 418 else { |
419 lastSuspSedimentRange = suspSedimentRange; | 419 lastSuspRange = suspSedimentRange; |
420 lastSuspSedimentValue = fraction.getSuspSediment(); | 420 lastSuspValue = fraction.getSuspSediment(); |
421 lastOtherRange = null; | 421 lastOtherRange = null; |
422 } | 422 } |
423 } | 423 } |
424 else if (hasButSuspSediment(fraction) && lastSuspSedimentRange != null) { | 424 else if (hasButSuspValues(fraction) && lastSuspRange != null) { |
425 // If intersects with last suspsed range, merge and add | 425 // If intersects with last suspsed range, merge and add |
426 double total = fraction.getCoarse() + | 426 double total = fraction.getCoarse() + |
427 fraction.getFineMiddle() + | 427 fraction.getFineMiddle() + |
428 fraction.getSand() + | 428 fraction.getSand() + |
429 fraction.getSuspSand() + | 429 fraction.getSuspSand() + |
430 lastSuspSedimentValue; | 430 lastSuspValue; |
431 double maxStart = Math.max(fraction.getCoarseRange().getStart(), | 431 double maxStart = Math.max(fraction.getCoarseRange().getStart(), |
432 lastSuspSedimentRange.getStart()); | 432 lastSuspRange.getStart()); |
433 if (lastSuspSedimentRange.contains(km)) { | 433 if (lastSuspRange.contains(km)) { |
434 double minEnd = Math.min(fraction.getCoarseRange().getEnd(), | 434 double minEnd = Math.min(fraction.getCoarseRange().getEnd(), |
435 lastSuspSedimentRange.getEnd()); | 435 lastSuspRange.getEnd()); |
436 Range totalRange = new Range(maxStart, minEnd); | 436 Range totalRange = new Range(maxStart, minEnd); |
437 if (lastSuspSedimentRange.getEnd() > fraction.getCoarseRange().getEnd()) { | 437 if (lastSuspRange.getEnd() > fraction.getCoarseRange().getEnd()) { |
438 // SuspSed longer. | 438 // SuspSed longer. |
439 lastSuspSedimentRange.setStart(fraction.getCoarseRange().getEnd()); | 439 lastSuspRange.setStart(fraction.getCoarseRange().getEnd()); |
440 lastOtherRange = null; | 440 lastOtherRange = null; |
441 } | 441 } |
442 else { | 442 else { |
443 // Other longer | 443 // Other longer |
444 lastOtherRange = (Range) fraction.getCoarseRange().clone(); | 444 lastOtherRange = (Range) fraction.getCoarseRange().clone(); |
445 lastOtherRange.setStart(lastSuspSedimentRange.getEnd()); | 445 lastOtherRange.setStart(lastSuspRange.getEnd()); |
446 lastSuspSedimentRange = null; | 446 lastSuspRange = null; |
447 lastOtherValue = total - lastSuspSedimentValue; | 447 lastOtherValue = total - lastSuspValue; |
448 } | 448 } |
449 if (Math.abs(lastSuspSedimentRange.getEnd() - lastOtherRange.getEnd()) < 0.1d) { | 449 if (Math.abs(lastSuspRange.getEnd() - lastOtherRange.getEnd()) < 0.1d) { |
450 lastOtherRange = null; | 450 lastOtherRange = null; |
451 lastSuspSedimentRange = null; | 451 lastSuspRange = null; |
452 } | 452 } |
453 fairLoad.setTotal(km, total, totalRange); | 453 fairLoad.setTotal(km, total, totalRange); |
454 } | 454 } |
455 else { | 455 else { |
456 // Ranges are disjoint. | 456 // Ranges are disjoint. |
457 lastOtherRange = fraction.getCoarseRange(); | 457 lastOtherRange = fraction.getCoarseRange(); |
458 lastOtherValue = total - fraction.getSuspSediment(); | 458 lastOtherValue = total - fraction.getSuspSediment(); |
459 lastSuspSedimentRange = null; | 459 lastSuspRange = null; |
460 } | 460 } |
461 } | 461 } |
462 else { | 462 else { |
463 // Some values are missing or no intersection with former values. | 463 // Some values are missing or no intersection with former values. |
464 // Stay as we are. | 464 // Stay as we are. |