f4cff065 by Nathan Lighthart

Create spatial only contexts for HRU and Reach

- Rename old hruContexts and reachContexts to hruTemporalContexts and reachTemporalContexts
- Add maps call hruContexts and reachContexts to store spatial only contexts
- Update context initialization for hrus and reaches
1 parent 4639cb99
......@@ -199,7 +199,9 @@ public class AgESModel {
private Context outletContext;
private Context outletAggregateContext;
private Map<Integer, Context> hruContexts;
private Map<Integer, Context> hruTemporalContexts;
private Map<Integer, Context> reachContexts;
private Map<Integer, Context> reachTemporalContexts;
private Map<Integer, HRUProgramSet> hruProgramSets;
private Map<Integer, ReachProgramSet> reachProgramSets;
......@@ -458,21 +460,26 @@ public class AgESModel {
private void initializeHRUContexts() {
hruContexts = new LinkedHashMap<>();
hruTemporalContexts = new LinkedHashMap<>();
for (HRU hru : hrus) {
Context hruContext = createHRUContext(hru);
hruContexts.put(hru.ID, hruContext);
Context hruTemporalContext = new CombinedContext(new MapContext(),
hruContext, temporalContext, agesContext);
hruTemporalContexts.put(hru.ID, hruTemporalContext);
}
// Add routing information to contexts
for (HRU hru : hrus) {
Context hruContext = hruContexts.get(hru.ID);
Context hruContext = hruTemporalContexts.get(hru.ID);
HRURoutingInformation routingInformation = routingTable.getRoutingInformationHRU(hru.ID);
List<RoutingEdge> fromHRUs = routingInformation.getFromHRUs();
RoutingContext[] routingContexts = new RoutingContext[fromHRUs.size()];
int i = 0;
for (RoutingEdge edge : fromHRUs) {
Context fromContext = hruContexts.get(edge.getId());
Context fromContext = hruTemporalContexts.get(edge.getId());
RoutingContext routingContext = new RoutingContext(fromContext, edge.getWeight());
routingContexts[i++] = routingContext;
}
......@@ -482,7 +489,7 @@ public class AgESModel {
}
private Context createHRUContext(HRU hru) {
Context context = new CombinedContext(new MapContext(), temporalContext, agesContext);
Context context = new MapContext();
// Initialize basic hru properties
context.put("hru", hru);
......@@ -501,14 +508,19 @@ public class AgESModel {
private void initializeReachContexts() {
reachContexts = new LinkedHashMap<>();
reachTemporalContexts = new LinkedHashMap<>();
for (StreamReach reach : reaches) {
Context reachContext = createReachContext(reach);
reachContexts.put(reach.ID, reachContext);
Context reachTemporalContext = new CombinedContext(new MapContext(),
reachContext, temporalContext, agesContext);
reachTemporalContexts.put(reach.ID, reachTemporalContext);
}
// Add routing information to contexts
for (StreamReach reach : reaches) {
Context reachContext = reachContexts.get(reach.ID);
Context reachContext = reachTemporalContexts.get(reach.ID);
ReachRoutingInformation routingInformation = routingTable.getRoutingInformationReach(reach.ID);
......@@ -516,7 +528,7 @@ public class AgESModel {
RoutingContext[] hruRoutingContexts = new RoutingContext[fromHRUs.size()];
int i = 0;
for (RoutingEdge edge : fromHRUs) {
Context fromContext = hruContexts.get(edge.getId());
Context fromContext = hruTemporalContexts.get(edge.getId());
RoutingContext routingContext = new RoutingContext(fromContext, edge.getWeight());
hruRoutingContexts[i++] = routingContext;
}
......@@ -526,7 +538,7 @@ public class AgESModel {
RoutingContext[] reachRoutingContexts = new RoutingContext[fromReaches.size()];
i = 0;
for (RoutingEdge edge : fromReaches) {
Context fromContext = reachContexts.get(edge.getId());
Context fromContext = reachTemporalContexts.get(edge.getId());
RoutingContext routingContext = new RoutingContext(fromContext, edge.getWeight());
reachRoutingContexts[i++] = routingContext;
}
......@@ -535,7 +547,7 @@ public class AgESModel {
}
private Context createReachContext(StreamReach reach) {
Context context = new CombinedContext(new MapContext(), temporalContext, agesContext);
Context context = new MapContext();
context.put("reach", reach);
context.put("ID", reach.ID);
......@@ -557,7 +569,7 @@ public class AgESModel {
System.out.print("--> Finding watershed outlet: ");
int outletId = routingTable.getOutletId();
System.out.println(outletId);
outletContext = reachContexts.get(outletId);
outletContext = reachTemporalContexts.get(outletId);
outletAggregateContext = new CombinedContext(new MapContext(), temporalContext, agesContext);
}
......@@ -566,7 +578,7 @@ public class AgESModel {
return;
}
ParameterOverrideReader reader = new ParameterOverrideReader(parameters.hruOverrideFilePath, hruContexts);
ParameterOverrideReader reader = new ParameterOverrideReader(parameters.hruOverrideFilePath, hruTemporalContexts);
reader.read();
}
......@@ -736,7 +748,7 @@ public class AgESModel {
if (parameters.flagRegionalization) {
RegionalizationCacher cacher = new RegionalizationCacher(parameters.dataFileTmin, parameters.dataFileTmax,
parameters.dataFileHum, parameters.dataFilePrecip, parameters.dataFileSol, parameters.dataFileWind);
cacher.cache(hrus, hruContexts, agesContext, temporalContext);
cacher.cache(hrus, hruTemporalContexts, agesContext, temporalContext);
}
System.out.println("--> Preprocessing start ...");
......@@ -750,7 +762,7 @@ public class AgESModel {
}
readerTmean.readData();
hruContexts.values().parallelStream().forEach((hruContext) -> {
hruTemporalContexts.values().parallelStream().forEach((hruContext) -> {
// tmean depends on tmin and tmax if not cached in regionalized file
if (!parameters.flagRegionalization) {
readerTmin.setValue(hruContext);
......@@ -775,7 +787,7 @@ public class AgESModel {
Map<Integer, ContextTask> subSurfaceTask = new HashMap<>();
Map<Integer, Runnable> hruOutputTask = new HashMap<>();
for (HRU hru : hrus) {
Context hruContext = hruContexts.get(hru.ID);
Context hruContext = hruTemporalContexts.get(hru.ID);
HRUProgramSet hruProgramSet = hruProgramSets.get(hru.ID);
surfaceTask.put(hru.ID, new ContextTask(hruContext, (context) -> {
......@@ -800,7 +812,7 @@ public class AgESModel {
Map<Integer, Runnable> reachOutputTask = new HashMap<>();
for (StreamReach reach : reaches) {
Context reachContext = reachContexts.get(reach.ID);
Context reachContext = reachTemporalContexts.get(reach.ID);
ReachProgramSet reachProgramSet = reachProgramSets.get(reach.ID);
reachRoutingTask.put(reach.ID, new ContextTask(reachContext, reachProgramSet.routeProgram));
......@@ -839,7 +851,7 @@ public class AgESModel {
private void emulateHRUPrograms(Program initProgram, Program surfaceProgram, Program subSurfaceProgram) {
HRU firstHRU = hrus.get(0);
Context hruContext = hruContexts.get(firstHRU.ID);
Context hruContext = hruTemporalContexts.get(firstHRU.ID);
Context dummyContext = Contexts.createIdentityContext(hruContext);
initProgram.emulate(dummyContext);
......@@ -883,7 +895,7 @@ public class AgESModel {
private void emulateReachPrograms(Program routeProgram) {
StreamReach firstReach = reaches.get(0);
Context reachContext = reachContexts.get(firstReach.ID);
Context reachContext = reachTemporalContexts.get(firstReach.ID);
Context dummyContext = Contexts.createIdentityContext(reachContext);
routeProgram.emulate(dummyContext);
}
......@@ -891,7 +903,7 @@ public class AgESModel {
private void runInitProgram() {
long now1 = System.currentTimeMillis();
hrus.parallelStream().forEach((hru) -> {
Context hruContext = hruContexts.get(hru.ID);
Context hruContext = hruTemporalContexts.get(hru.ID);
HRUProgramSet hruProgramSet = hruProgramSets.get(hru.ID);
hruProgramSet.initProgram.execute(hruContext);
});
......@@ -1156,7 +1168,7 @@ public class AgESModel {
if (parameters.flagReachRouting) {
tasks.add(() -> {
aggregator_outlet.aggregate(reachContexts.values(), outletContext, outletAggregateContext);
aggregator_outlet.aggregate(reachTemporalContexts.values(), outletContext, outletAggregateContext);
try {
writer_outlet.write(outletAggregateContext);
} catch (IOException ex) {
......@@ -1174,7 +1186,7 @@ public class AgESModel {
private Runnable createCatchmentRunnableHRU(OutputWriter writer, CatchmentAggregator aggregator, Context aggregateContext) {
return () -> {
aggregator.aggregate(hruContexts.values(), aggregateContext);
aggregator.aggregate(hruTemporalContexts.values(), aggregateContext);
try {
writer.write(aggregateContext);
} catch (IOException ex) {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!