-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAdditionalOutput.cs
122 lines (111 loc) · 4.66 KB
/
AdditionalOutput.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHI.Mike1D.ADDataAccess;
using DHI.Mike1D.Generic;
using DHI.Mike1D.Mike1DDataAccess;
using DHI.Mike1D.Plugins;
using DHI.Mike1D.ResultDataAccess;
namespace DHI.Mike1D.Examples.Scripts
{
/// <summary>
/// Script for adding additional outputs.
/// <para>
/// If you want to disable one or more of the script methods in the class,
/// you can delete that method, or you can just comment out the [Script] attribute line.
/// </para>
/// </summary>
public class AdditionalOutput
{
/// <summary>
/// Add water depth output to default HD result file
/// <para>
/// Method called when Mike1DData object has been loaded.
/// </para>
/// </summary>
[Script]
public void AddToOutput(Mike1DData mike1DData)
{
// Add Water Depth to default HD result output
ResultSpecification hdResSpec = mike1DData.ResultSpecifications.Find(rs => rs.ID == "DefaultHDResults");
if (hdResSpec != null)
{
hdResSpec.What.Add(Quantity.Create(PredefinedQuantity.WaterDepth));
}
}
/// <summary>
/// Set flag such that results are written at exact time matching output interval specification.
/// When output time does not match engine time, interpolation in time is applied.
/// <para>
/// This is relevant when running with adaptive or tabulated time stepping.
/// </para>
/// </summary>
[Script]
public void SetInterpolationFlag(Mike1DData mike1DData)
{
foreach (ResultSpecification resSpec in mike1DData.ResultSpecifications)
{
resSpec.Interpolate = true;
}
}
/// <summary>
/// Disable various outputs, based on their output id.
/// </summary>
[Script]
public void DisableOutput(Mike1DData mike1DData)
{
// Remove default RR results
mike1DData.ResultSpecifications.RemoveAll(item => item.ID == "DefaultRRResults");
// Remove additional NAM RR results
mike1DData.ResultSpecifications.RemoveAll(item => item.ID == "AdditionalNAMRRResults");
// Remove Catchment Discharge results
mike1DData.ResultSpecifications.RemoveAll(item => item.ID == "CatchmentDischargeRRResults");
}
/// <summary>
/// Make a user defined output file that outputs mass transport in a specified set of links and weirs
/// <para>
/// Method called when Mike1DData object has been loaded.
/// </para>
/// </summary>
[Script]
public void AddADUserOutput(Mike1DData mike1DData, IDiagnostics diagnostics)
{
ResultSpecification adUserResSpec = mike1DData.GetDefaultResultSpecification(ResultSpecificationTypes.AD);
adUserResSpec.ID = "ADUserOutput";
// How often to store
adUserResSpec.StoringFrequencyType = StoringFrequencyUnitTypes.Minutes;
adUserResSpec.StoringFrequency = 15;
// Where to store the file
adUserResSpec.Connection.FilePath = new FilePath(mike1DData.Id + mike1DData.ScenarioId + "UserAD.res1d");
// What to store
ADComponent adComp = mike1DData.ADComponentData.Components.Find(comp => comp.Id == "Spill");
if (adComp == null)
{
diagnostics.Error(new DiagnosticItem("Could not find AD component with Id: Spill"));
return;
}
// Mass transport of "Spill" AD component
// IQuantity massTransport = ADComponentQuantities.FaceTransport(adComp.Quantity); // For Release 2019 (17.0), this works
IQuantity massTransport = ADComponentQuantities.Create(adComp, PredefinedQuantityAD.Transport); // For later releases (>17.0), this is recommended
adUserResSpec.What.Add(massTransport);
// Which data in the network to store
var spatialFilter = new Res1DNetworkFilter();
// Links, output at all grid points
spatialFilter.AddGlobalReachValue("Link_1", true);
spatialFilter.AddGlobalReachValue("Link_2", true);
// Links, output at inflow to link only
spatialFilter.AddGlobalReachValue("Link_3", Res1DSpatialFilterTypeEnum.First);
spatialFilter.AddGlobalReachValue("Link_4", Res1DSpatialFilterTypeEnum.First);
// Weirs
spatialFilter.AddGlobalReachValue("Weir:Weir_1", true);
spatialFilter.AddGlobalReachValue("Weir:Weir_2", true);
// Set filter for specific quantity or for all quantities
//adUserResSpec.SetFilter(massTransport, spatialFilter);
adUserResSpec.DefaultFilter = spatialFilter;
// Add to list of result files
mike1DData.ResultSpecifications.Add(adUserResSpec);
}
}
}