420cebd3 by Nathan Lighthart

Expose reach routing program

- Add parameter to read a reach routing program file
- Add reading of external reach routing if necessary
- Add reachrouting.xml to arti_catch that represents default reach routing
- Update programs.xml in arti_catch to contain default implementation of reach routing
1 parent 822d6df0
......@@ -693,16 +693,17 @@ public class AgESModel {
Program subSurfaceProgram = createSubSurfaceProgram();
// read all programs if some programs were not found in specific files
ProgramListLayout allProgramsList = null;
if (parameters.programsFilePath != null) {
if (surfaceProgram == null || subSurfaceProgram == null) {
XMLLayoutReader reader = new XMLLayoutReader(parameters.programsFilePath);
ProgramListLayout pll = (ProgramListLayout) reader.read(XMLLayoutReader.LayoutType.PROGRAM_LIST);
allProgramsList = (ProgramListLayout) reader.read(XMLLayoutReader.LayoutType.PROGRAM_LIST);
if (surfaceProgram == null) {
surfaceProgram = pll.createProgram("surface");
surfaceProgram = allProgramsList.createProgram("surface");
}
if (subSurfaceProgram == null) {
subSurfaceProgram = pll.createProgram("subsurface");
subSurfaceProgram = allProgramsList.createProgram("subsurface");
}
}
}
......@@ -728,6 +729,22 @@ public class AgESModel {
if (parameters.flagReachRouting) {
Program reachRoutingProgram = createReachRoutingProgram();
if (parameters.programsFilePath != null) {
if (reachRoutingProgram == null) {
if (allProgramsList == null) {
XMLLayoutReader reader = new XMLLayoutReader(parameters.programsFilePath);
allProgramsList = (ProgramListLayout) reader.read(XMLLayoutReader.LayoutType.PROGRAM_LIST);
}
reachRoutingProgram = allProgramsList.createProgram("reach-routing");
}
}
if (reachRoutingProgram == null) {
reachRoutingProgram = createDefaultReachRoutingProgram();
}
emulateReachPrograms(reachRoutingProgram);
reachProgramSets = new LinkedHashMap<>();
......@@ -772,14 +789,7 @@ public class AgESModel {
if (parameters.surfaceProgramFilePath == null) {
return null;
}
XMLLayoutReader reader = new XMLLayoutReader(parameters.surfaceProgramFilePath);
ProgramLayout pl;
try {
pl = (ProgramLayout) reader.read(XMLLayoutReader.LayoutType.PROGRAM);
} catch (IOException ex) {
throw new IOException("Failed to read surface program", ex);
}
return pl.createProgram();
return createProgram(parameters.surfaceProgramFilePath);
}
private Program createDefaultSurfaceProgram() {
......@@ -807,14 +817,7 @@ public class AgESModel {
if (parameters.subSurfaceProgramFilePath == null) {
return null;
}
XMLLayoutReader reader = new XMLLayoutReader(parameters.subSurfaceProgramFilePath);
ProgramLayout pl;
try {
pl = (ProgramLayout) reader.read(XMLLayoutReader.LayoutType.PROGRAM);
} catch (IOException ex) {
throw new IOException("Failed to read subsurface program", ex);
}
return pl.createProgram();
return createProgram(parameters.subSurfaceProgramFilePath);
}
private Program createDefaultSubSurfaceProgram() {
......@@ -845,7 +848,14 @@ public class AgESModel {
return new Program(root);
}
private Program createReachRoutingProgram() {
private Program createReachRoutingProgram() throws IOException {
if (parameters.reachRoutingProgramFilePath == null) {
return null;
}
return createProgram(parameters.reachRoutingProgramFilePath);
}
private Program createDefaultReachRoutingProgram() {
AdapterStatement musleHRUReach = new AdapterStatement(new ProcessHRUReachRoutingMusleAdapter());
AdapterStatement musleReachInput = new AdapterStatement(new ProcessReachRoutingInputMusleAdapter());
AdapterStatement musle = new AdapterStatement(new ProcessReachRoutingMusleAdapter());
......@@ -870,6 +880,17 @@ public class AgESModel {
return new Program(root);
}
private Program createProgram(Path programFilePath) throws IOException {
XMLLayoutReader reader = new XMLLayoutReader(programFilePath);
ProgramLayout pl;
try {
pl = (ProgramLayout) reader.read(XMLLayoutReader.LayoutType.PROGRAM);
} catch (IOException ex) {
throw new IOException("Failed to read program from file: " + programFilePath, ex);
}
return pl.createProgram();
}
private void runModel() throws IOException {
LocalDate time = parameters.startTime;
temporalContext.put("time", time);
......
......@@ -88,6 +88,9 @@ public class AgESParameters {
@Description("Sub-Surface program file path")
public final Path subSurfaceProgramFilePath;
@Description("Reach-Routing program file path")
public final Path reachRoutingProgramFilePath;
@Description("All programs file path")
public final Path programsFilePath;
......@@ -700,6 +703,7 @@ public class AgESParameters {
surfaceProgramFilePath = builder.surfaceProgramFilePath;
subSurfaceProgramFilePath = builder.subSurfaceProgramFilePath;
reachRoutingProgramFilePath = builder.reachRoutingProgramFilePath;
programsFilePath = builder.programsFilePath;
hruAdditionalFilePath = builder.hruAdditionalFilePath;
......@@ -931,6 +935,7 @@ public class AgESParameters {
private Path surfaceProgramFilePath;
private Path subSurfaceProgramFilePath;
private Path reachRoutingProgramFilePath;
private Path programsFilePath;
private Path hruAdditionalFilePath;
......@@ -1330,6 +1335,11 @@ public class AgESParameters {
return this;
}
public Builder reachRoutingProgramFilePath(Path reachRoutingProgramFilePath) {
this.reachRoutingProgramFilePath = reachRoutingProgramFilePath;
return this;
}
public Builder programsFilePath(Path programsFilePath) {
this.programsFilePath = programsFilePath;
return this;
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!