Commit 10525849 authored by patrick.lambert's avatar patrick.lambert
Browse files

code cleaning

parent bcc08e41
package species; package species;
import org.openide.util.lookup.ServiceProvider;
import java.util.List;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver; import com.thoughtworks.xstream.io.xml.DomDriver;
import environment.Basin; import environment.Basin;
import environment.Time;
import fr.cemagref.simaqualife.kernel.AquaNismsGroup;
import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess; import fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess;
import fr.cemagref.simaqualife.kernel.util.TransientParameters.InitTransientParameters; import fr.cemagref.simaqualife.kernel.util.TransientParameters.InitTransientParameters;
import fr.cemagref.simaqualife.pilot.Pilot; import fr.cemagref.simaqualife.pilot.Pilot;
import miscellaneous.Miscellaneous; import miscellaneous.Miscellaneous;
import org.openide.util.lookup.ServiceProvider;
import species.DiadromousFish.Gender; import species.DiadromousFish.Gender;
import species.DiadromousFish.Stage; import species.DiadromousFish.Stage;
import umontreal.iro.lecuyer.probdist.NormalDist; import umontreal.iro.lecuyer.probdist.NormalDist;
...@@ -27,30 +21,32 @@ public class Grow extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGr ...@@ -27,30 +21,32 @@ public class Grow extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGr
/** /**
* temperature minimum for growth * temperature minimum for growth
*
* @unit °C * @unit °C
*/ */
private double tempMinGrow = 3.; private double tempMinGrow = 3.;
/** /**
* temperature maximum for growth * temperature maximum for growth
*
* @unit °C * @unit °C
*/ */
private double tempMaxGrow = 26.; private double tempMaxGrow = 26.;
/** /**
* temperature optimal for growth * temperature optimal for growth
*
* @unit °C * @unit °C
*/ */
private double tempOptGrow = 17.; private double tempOptGrow = 17.;
/** /**
* K, Brody growth rate at optimal temperature * K, Brody growth rate at optimal temperature L = Linf *(1-exp(-K*(t-t0))
* L = Linf *(1-exp(-K*(t-t0)) *
* @unit year -1 * @unit year -1
*/ */
private double kOptForFemale= 0.3; private double kOptForFemale = 0.3;
/** /**
* @return the kOptForFemale * @return the kOptForFemale
*/ */
...@@ -58,13 +54,16 @@ public class Grow extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGr ...@@ -58,13 +54,16 @@ public class Grow extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGr
return kOptForFemale; return kOptForFemale;
} }
/** /**
* @param kOptForFemale the kOptForFemale to set * @param kOptForFemale
* the kOptForFemale to set
*/ */
public void setkOptForFemale(double kOptForFemale) { public void setkOptForFemale(double kOptForFemale) {
this.kOptForFemale = kOptForFemale; this.kOptForFemale = kOptForFemale;
} }
/** /**
* @return the kOptForMale * @return the kOptForMale
*/ */
...@@ -72,95 +71,110 @@ public class Grow extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGr ...@@ -72,95 +71,110 @@ public class Grow extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGr
return kOptForMale; return kOptForMale;
} }
/** /**
* @param kOptForMale the kOptForMale to set * @param kOptForMale
* the kOptForMale to set
*/ */
public void setkOptForMale(double kOptForMale) { public void setkOptForMale(double kOptForMale) {
this.kOptForMale = kOptForMale; this.kOptForMale = kOptForMale;
} }
/** /**
* K, Brody growth rate at optimal temperature * K, Brody growth rate at optimal temperature L = Linf *(1-exp(-K*(t-t0))
* L = Linf *(1-exp(-K*(t-t0)) *
* @unit year -1 * @unit year -1
*/ */
private double kOptForMale= 0.3; private double kOptForMale = 0.3;
/** /**
* standart deviation for the lognormal random draw of growth increment * standart deviation for the lognormal random draw of growth increment
*
* @unit cm * @unit cm
*/ */
private double sigmaDeltaLVonBert = 0.2; private double sigmaDeltaLVonBert = 0.2;
private transient NormalGen genNormal; private transient NormalGen genNormal;
public static void main(String[] args) { System.out.println((new public static void main(String[] args) {
XStream(new DomDriver())) .toXML(new Grow())); } System.out.println((new XStream(new DomDriver())).toXML(new Grow()));
}
@Override @Override
@InitTransientParameters @InitTransientParameters
public void initTransientParameters(Pilot pilot) { public void initTransientParameters(Pilot pilot) {
super.initTransientParameters(pilot); super.initTransientParameters(pilot);
genNormal = new NormalACRGen( pilot.getRandomStream(), genNormal = new NormalACRGen(pilot.getRandomStream(), new NormalDist(0., 1.));
new NormalDist(0., 1.));
} }
@Override @Override
public void doProcess(DiadromousFishGroup group) { public void doProcess(DiadromousFishGroup group) {
for(Basin basin : group.getEnvironment().getBasins()){ for (Basin basin : group.getEnvironment().getBasins()) {
if (basin.getFishs(group)!=null) double currentTemperature = basin.getCurrentTemperature(group.getPilot());
for(DiadromousFish fish : basin.getFishs(group)){ if (basin.getFishs(group) != null)
for (DiadromousFish fish : basin.getFishs(group)) {
double muDeltaLVonBert = 0.; double muDeltaLVonBert = 0.;
double kVonBert = 0.; double kVonBert = 0.;
double growthIncrement = 0.; double growthIncrement = 0.;
// 1) calculate the kVonBert
//System.out.println(this.getKOpt(fish, group) );
kVonBert = this.getKOpt(fish, group) *
Miscellaneous.temperatureEffect(fish.getPosition().getCurrentTemperature(group.getPilot()), tempMinGrow, tempOptGrow, tempMaxGrow);
// 2) Update the fish length with a lognormal normal draw of increment // 1) calculate the kVonBert
// System.out.println(this.getKOpt(fish, group) );
kVonBert = this.getKOpt(fish, group)
* Miscellaneous.temperatureEffect(currentTemperature, tempMinGrow, tempOptGrow, tempMaxGrow);
// 2) Update the fish length with a lognormal normal draw of increment
// limit the fish length to Linf // limit the fish length to Linf
if (fish.getLength() < group.getLinfVonBert(fish)){ double lengthBefore = fish.getLength();
muDeltaLVonBert = Math.log((group.getLinfVonBert(fish) - fish.getLength()) * (1 - Math.exp(-kVonBert * group.getEnvironment().getTime().getSeasonDuration()))) - (sigmaDeltaLVonBert*sigmaDeltaLVonBert)/2; double alea = Double.NaN;
growthIncrement = Math.exp(genNormal.nextDouble()*sigmaDeltaLVonBert + muDeltaLVonBert); if (fish.getLength() < group.getLinfVonBert(fish)) {
muDeltaLVonBert = Math
fish.setLength(Math.min(group.getLinfVonBert(fish), fish.getLength() + growthIncrement)); .log((group.getLinfVonBert(fish) - fish.getLength())
} * (1 - Math.exp(-kVonBert * group.getEnvironment().getTime().getSeasonDuration())))
else { - (sigmaDeltaLVonBert * sigmaDeltaLVonBert) / 2;
alea = genNormal.nextDouble();
growthIncrement = Math.exp(alea * sigmaDeltaLVonBert + muDeltaLVonBert);
fish.setLength(Math.min(group.getLinfVonBert(fish), fish.getLength() + growthIncrement));
} else {
fish.setLength(group.getLinfVonBert(fish)); fish.setLength(group.getLinfVonBert(fish));
} }
//System.out.println(fish.getAge() + " -> "+ fish.getLength() + " ("+fish.getStage()+"): "+ growthIncrement);
System.out.println(basin.getName() + " :" + fish.getAge() + " " + fish.getGender() + " : " + lengthBefore
+ " -> " + fish.getLength() + " (" + fish.getStage() + "): " + growthIncrement + " with kVonBert = "
+ kVonBert + " (" + currentTemperature + " / " + alea + ")");
// test if fish become mature // test if fish become mature
if (fish.getStage() == Stage.IMMATURE && fish.getLength() > group.getlFirstMaturity(fish)){ if (fish.getStage() == Stage.IMMATURE && fish.getLength() > group.getlFirstMaturity(fish)) {
fish.setStage(Stage.MATURE); fish.setStage(Stage.MATURE);
} }
//System.out.println("la temp�rature du lieu de vie du poisson est :" + fish.getPosition().getCurrentTemperature() + ", la saison est :" + Time.getSeason() + " et sa nouvelle taille est :" + fish.getLength()); // System.out.println("la temp�rature du lieu de vie du poisson est :" +
// fish.getPosition().getCurrentTemperature() + ", la saison est :" + Time.getSeason() + " et sa
// nouvelle taille est :" + fish.getLength());
} }
} }
} }
/** /**
* @param fish * @param fish
* @param group * @param group
* @return the Brody coeff from Diadromousgroup if exists or from this grow process * @return the Brody coeff from Diadromousgroup if exists or from this grow process depends of the fish gender .In
* depends of the fish gender .In case of undifferentiaced fish, the mean for male and female is considered * case of undifferentiaced fish, the mean for male and female is considered
*/ */
public double getKOpt(DiadromousFish fish, DiadromousFishGroup group) { public double getKOpt(DiadromousFish fish, DiadromousFishGroup group) {
double kOpt = group.getKOpt(fish); double kOpt = group.getKOpt(fish);
if (Double.isNaN(kOpt)){ // no definition for the group if (Double.isNaN(kOpt)) { // no definition for the group
if (fish.getGender() == Gender.FEMALE) if (fish.getGender() == Gender.FEMALE)
kOpt = kOptForFemale; kOpt = kOptForFemale;
else if (fish.getGender() == Gender.MALE) else if (fish.getGender() == Gender.MALE)
kOpt = kOptForMale; kOpt = kOptForMale;
else else
kOpt= (kOptForFemale + kOptForMale) / 2.; kOpt = (kOptForFemale + kOptForMale) / 2.;
} }
return kOpt; return kOpt;
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment