diff --git a/src/main/java/species/MigrateToSea.java b/src/main/java/species/MigrateToSea.java index 95fbddeaec73451a1213cafe3d859af86596d9a5..cdbc3bcca715332fea076d6fb8e16df803d42399 100644 --- a/src/main/java/species/MigrateToSea.java +++ b/src/main/java/species/MigrateToSea.java @@ -9,8 +9,13 @@ import environment.Time; import environment.Time.Season; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import java.util.ArrayList; +import java.util.Hashtable; import java.util.List; +import java.util.Map; + import miscellaneous.Duo; +import species.DiadromousFish.Stage; + import org.openide.util.lookup.ServiceProvider; @ServiceProvider(service = AquaNismsGroupProcess.class) @@ -28,19 +33,48 @@ public class MigrateToSea extends AquaNismsGroupProcess<DiadromousFish, Diadromo if (Time.getSeason(group.getPilot()) == seaMigrationSeason ){ Basin destination; - List<Duo<DiadromousFish,Basin>> fishesToMove = new ArrayList<Duo<DiadromousFish,Basin>>(); - for (int i = 0; i < group.getEnvironment().getRiverBasins().length; i++) { - RiverBasin basin = group.getEnvironment().getRiverBasins()[i]; - - List<DiadromousFish> fishes = basin.getFishs(group); - if (fishes!=null) for (DiadromousFish fish : fishes) { - destination = group.getEnvironment().getAssociatedSeaBasin(fish.getPosition()); - fishesToMove.add(new Duo<DiadromousFish, Basin>(fish, destination)); - } - } - for (Duo<DiadromousFish,Basin> duo : fishesToMove) { - duo.getFirst().moveTo(group.getPilot(), duo.getSecond(), group); - } - } + + //On créer la Map pour stocker les flux d'export + Map<String, Double> totalOutputFluxes = new Hashtable<String, Double>(); + + List<Duo<DiadromousFish,Basin>> fishesToMove = new ArrayList<Duo<DiadromousFish,Basin>>(); + for (int i = 0; i < group.getEnvironment().getRiverBasins().length; i++) { + RiverBasin basin = group.getEnvironment().getRiverBasins()[i]; + //Fish move to sea and compute the related export of nutrients + List<DiadromousFish> fishes = basin.getFishs(group); + + // ON ré-initialise notre map pour chauqe bassin + for (String nutrient : group.getFishNutrient().getNutrientsOfInterest()) { + totalOutputFluxes.put(nutrient, 0.); + } + totalOutputFluxes.put("biomass", 0.); //création de la biomasse + + if (fishes!=null) { + for (DiadromousFish fish : fishes) { + destination = group.getEnvironment().getAssociatedSeaBasin(fish.getPosition()); + fishesToMove.add(new Duo<DiadromousFish, Basin>(fish, destination)); //Mentionne la sortie d'un poisson de la boucle + + double biomass = group.getFishNutrient().getWeight(fish) * fish.getAmount(); + + if (fish.getStage()==Stage.IMMATURE) { + Map <String, Double> aFluxExportedByJuveniles= group.getFishNutrient().computeNutrientsExportForJuveniles(fish); + for (String nutrient: aFluxExportedByJuveniles.keySet()) { + totalOutputFluxes.put(nutrient,totalOutputFluxes.get(nutrient) + aFluxExportedByJuveniles.get(nutrient) * fish.getAmount()); + } + + totalOutputFluxes.put("biomass", totalOutputFluxes.get("biomass") + biomass); + } + } + } + + for (Duo<DiadromousFish,Basin> duo : fishesToMove) { + duo.getFirst().moveTo(group.getPilot(), duo.getSecond(), group); //on déplace les poissons dans le fichier MoveTo et on dénote la destination du poisson. + } + System.out.println(group.getPilot().getCurrentTime() + "; " + Time.getYear(group.getPilot()) + ";" + Time.getSeason(group.getPilot()) + ";EXPORT;" + + basin.getName() + "; " + totalOutputFluxes); + } + } + + } -} +} \ No newline at end of file diff --git a/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java b/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java index 67113f6caf1763a15923a4eb7f1cc4e2aeb9caef..5f543a60d3d8845acf94fcfd62ef407b9e370cdf 100644 --- a/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java +++ b/src/main/java/species/ReproduceAndSurviveAfterReproductionWithDiagnose.java @@ -110,11 +110,12 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG if (fishInBasin != null){ //Initiate the total fluxes for this basin - Map<String, Double> totalFluxes = new Hashtable<String, Double>(); //On créer la Map pour stocker les flux + Map<String, Double> totalInputFluxes = new Hashtable<String, Double>(); //On créer la Map pour stocker les flux for (String nutrient : group.getFishNutrient().getNutrientsOfInterest()) { - totalFluxes.put(nutrient, 0.); // ON MET A JOUR NOTRE map + totalInputFluxes.put(nutrient, 0.); // ON MET A JOUR NOTRE map } + totalInputFluxes.put("biomass",0.); // -------------------------------------------------------------------------------------------------- // definition of the stock recruiment relationship // -------------------------------------------------------------------------------------------------- @@ -188,30 +189,44 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG // survival after reproduction (semelparity or iteroparity) of SI (change the amount of the SI) survivalAmount = Miscellaneous.binomialForSuperIndividual(group.getPilot(), fish.getAmount(), survivalRateAfterReproduction); - if (survivalAmount > 0) { + double biomass = 0.; + if (survivalAmount > 0) {// SUperindividu est encore vivant mais il perd des effectifs //Export for fishes survived after spawning (survivalAmount) : excretion + gametes Map <String, Double> aFluxAfterSurvival = group.getFishNutrient().computeNutrientsInputForSurvivalAfterSpawning(fish); + + //Export for fishes that dies after spawning (fish.getAmount - survivalAmount): excretion + gametes + carcasse + Map<String, Double> aFluxForDeadFish = group.getFishNutrient().computeNutrientsInputForDeathAfterSpawning(fish); + for (String nutrient: aFluxAfterSurvival.keySet()) { - totalFluxes.put(nutrient,totalFluxes.get(nutrient) + aFluxAfterSurvival.get(nutrient) * survivalAmount); + //For survival fish + totalInputFluxes.put(nutrient,totalInputFluxes.get(nutrient) + aFluxAfterSurvival.get(nutrient) * survivalAmount); + + //For dead fish + totalInputFluxes.put(nutrient,totalInputFluxes.get(nutrient) + aFluxForDeadFish.get(nutrient) * (fish.getAmount() - survivalAmount)); } - fish.setAmount(survivalAmount); } + + //compute biomass for dead fish + biomass = group.getFishNutrient().getWeight(fish) * (fish.getAmount() - survivalAmount); + totalInputFluxes.put("biomass", totalInputFluxes.get("biomass") + biomass); + + //update the amount of individual in the super-individual + fish.setAmount(survivalAmount); + } else { - + //Le superinvidu est mort !!! deadFish.add(fish); //Export for fished died before spawning (fish.getAmount): carcasses + excretion + gametes Map<String, Double> aFlux = group.getFishNutrient().computeNutrientsInputForDeathAfterSpawning(fish); // + for (String nutrient: aFlux.keySet()) { - totalFluxes.put(nutrient,totalFluxes.get(nutrient) + aFlux.get(nutrient) * (fish.getAmount()) - survivalAmount); //Fish.getAmount - survivalAmount = total fishes died. - + totalInputFluxes.put(nutrient,totalInputFluxes.get(nutrient) + aFlux.get(nutrient) * fish.getAmount()); //Fish.getAmount - survivalAmount = total fishes died. } - - + biomass = group.getFishNutrient().getWeight(fish) * (fish.getAmount()); + totalInputFluxes.put("biomass", totalInputFluxes.get("biomass") + biomass); } - } - } // keep the spawner number @@ -366,15 +381,12 @@ public class ReproduceAndSurviveAfterReproductionWithDiagnose extends AquaNismsG // Remove deadfish and compute the related nutrient fluxes // -------------------------------------------------------------------------------------------------- for (DiadromousFish fish : deadFish){ - - - group.removeAquaNism(fish); } deadFish.clear(); - System.out.println(group.getPilot().getCurrentTime() + "; " + Time.getYear(group.getPilot()) + ";" + Time.getSeason(group.getPilot()) + ";" - + riverBasin.getName() + "; " + totalFluxes); + System.out.println(group.getPilot().getCurrentTime() + "; " + Time.getYear(group.getPilot()) + ";" + Time.getSeason(group.getPilot()) + ";IMPORT;" + + riverBasin.getName() + "; " + totalInputFluxes); } else {