Unverified Commit 17c59a74 authored by Julien Veyssier's avatar Julien Veyssier
Browse files

implement combined irrigation application module, add surface irrigation to communication module


Signed-off-by: default avatarJulien Veyssier <eneiluj@posteo.net>
No related merge requests found
Showing with 191 additions and 0 deletions
+191 -0
...@@ -51,6 +51,7 @@ public class CouplingCommunication extends JAMSComponent { ...@@ -51,6 +51,7 @@ public class CouplingCommunication extends JAMSComponent {
private static Map<String, Double> irrigAspersion; private static Map<String, Double> irrigAspersion;
private static Map<String, Double> irrigDrip; private static Map<String, Double> irrigDrip;
private static Map<String, Double> irrigSurface;
private static CouplingCommunication singleton; private static CouplingCommunication singleton;
private int mi = 0; private int mi = 0;
...@@ -93,6 +94,10 @@ public class CouplingCommunication extends JAMSComponent { ...@@ -93,6 +94,10 @@ public class CouplingCommunication extends JAMSComponent {
return irrigDrip.getOrDefault(key, 0.0); return irrigDrip.getOrDefault(key, 0.0);
} }
public static double getIrrigSurface(String key) {
return irrigSurface.getOrDefault(key, 0.0);
}
public static void setIrrigAspersion(JSONObject values) { public static void setIrrigAspersion(JSONObject values) {
Iterator<String> keys = values.keys(); Iterator<String> keys = values.keys();
String key; String key;
...@@ -116,6 +121,18 @@ public class CouplingCommunication extends JAMSComponent { ...@@ -116,6 +121,18 @@ public class CouplingCommunication extends JAMSComponent {
System.out.println("Coupling module set drip of HRU " + key + " TO " + val); System.out.println("Coupling module set drip of HRU " + key + " TO " + val);
} }
} }
public static void setIrrigSurface(JSONObject values) {
Iterator<String> keys = values.keys();
String key;
Double val;
while (keys.hasNext()) {
key = keys.next();
val = values.getDouble(key);
irrigSurface.put(key, val);
System.out.println("Coupling module set surface of HRU " + key + " TO " + val);
}
}
public void run() { public void run() {
if (comServer.isRunning()) { if (comServer.isRunning()) {
...@@ -336,6 +353,10 @@ public class CouplingCommunication extends JAMSComponent { ...@@ -336,6 +353,10 @@ public class CouplingCommunication extends JAMSComponent {
JSONObject value = (JSONObject)jsonPayload.get("value"); JSONObject value = (JSONObject)jsonPayload.get("value");
setIrrigDrip(value); setIrrigDrip(value);
} }
else if ("surface".equals(key)) {
JSONObject value = (JSONObject)jsonPayload.get("value");
setIrrigSurface(value);
}
} }
sAcceptConnection.release(); sAcceptConnection.release();
} else { } else {
......
/*
* IrrigationApplication.java
* Created on 13.08.2015, 17:42:55
*
* This file is part of JAMS
* Copyright (C) FSU Jena
*
* JAMS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* JAMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JAMS. If not, see <http://www.gnu.org/licenses/>.
*
*/
package irrigation;
import jams.data.*;
import jams.model.*;
import management.CouplingCommunication;
/**
*
* @author Sven Kralisch <sven.kralisch at uni-jena.de>
*/
@JAMSComponentDescription(
title = "IrrigationApplicationExternalCombined",
author = "Julien Veyssier",
description = "Apply irrigation on an HRU based on external model",
date = "2020-02-25",
version = "0.1"
)
@VersionComments(entries = {
@VersionComments.Entry(version = "0.1", comment = "Initial version")
})
public class IrrigationApplicationExternalCombined extends JAMSComponent {
/*
* Component attributes
*/
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READ,
description = "HRUs list"
)
public Attribute.EntityCollection hrus;
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READWRITE,
description = "Water available for irrigation",
unit = "L"
)
public Attribute.Double irrigationWater;
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READWRITE,
description = "Added water for irrigation",
unit = "l"
)
public Attribute.Double irrigationTotal;
// for drip irrigation
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READ,
description = "maximum MPS",
unit = "L"
)
public Attribute.Double maxMPS;
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READWRITE,
description = "state var actual MPS",
unit = "L"
)
public Attribute.Double actMPS;
// for surface irrigation
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READWRITE,
description = "HRU net Rain",
unit = "L"
)
public Attribute.Double netRain;
// for aspersion irrigation
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READWRITE,
description = "HRU precipitation",
unit = "mm"
)
public Attribute.Double precip;
@JAMSVarDescription(
access = JAMSVarDescription.AccessType.READ,
description = "HRU area",
unit = "m²"
)
public Attribute.Double area;
/*
* Component run stages
*/
@Override
public void run() {
// get current HRU ID
if (hrus == null) {
System.out.println("HRUSSSS is null");
return;
}
System.out.println("Irrig demand 1");
Attribute.Entity hru = hrus.getCurrent();
System.out.println("Irrig demand 2");
Double hruId = hru.getDouble("ID");
System.out.println("Irrig demand HRUID " + hruId);
int iHruId = hruId.intValue();
String sHruId = String.valueOf(iHruId);
double aspersionVal = CouplingCommunication.getIrrigAspersion(String.valueOf(sHruId));
double dripVal = CouplingCommunication.getIrrigDrip(String.valueOf(sHruId));
double surfaceVal = CouplingCommunication.getIrrigSurface(String.valueOf(sHruId));
System.out.println("Irrig demand HRUID: " + sHruId
+ " ASPER " + aspersionVal
+ " DRIP " + dripVal
+ " SURFACE " + surfaceVal
);
double irrigationInMM;
double afterDrip = 0.0;
irrigationTotal.setValue(0);
// CODE OF DRIP
if (dripVal != 0.0) {
// actual irrigation is the minimum of available storage capacity and
// availabe irrigation water
double actIrrigation = Math.min(maxMPS.getValue() - actMPS.getValue(), dripVal);
// increase actMPS by the irrigation volume
actMPS.setValue(actMPS.getValue() + actIrrigation);
// decrease irrigationWater by the irrigation volume
afterDrip = dripVal - actIrrigation;
// set irrigationTotal to the irrigation volume
irrigationTotal.setValue(irrigationTotal.getValue() + actIrrigation);
}
// put what's left of drip in surface
surfaceVal += dripVal;
if (surfaceVal > 0.0) {
// CODE OF SURFACE
irrigationInMM = surfaceVal;
netRain.setValue(netRain.getValue() + irrigationInMM);
irrigationTotal.setValue(irrigationTotal.getValue() + surfaceVal);
}
if (aspersionVal > 0.0) {
// CODE OF ASPERSION
irrigationInMM = aspersionVal / area.getValue();
precip.setValue(precip.getValue() + irrigationInMM);
irrigationTotal.setValue(irrigationTotal.getValue() + aspersionVal);
}
}
}
Supports Markdown
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