Add recirculation pump node with input handling and flow management

This commit is contained in:
2025-06-16 16:53:07 +02:00
parent d0f8ada144
commit 5281696a21
6 changed files with 105 additions and 7 deletions

View File

@@ -0,0 +1,57 @@
<script type="text/javascript">
RED.nodes.registerType("recirculation-pump", {
category: "WWTP",
color: "#e4a363",
defaults: {
name: { value: "" },
F2: { value: 0, required: true },
inlet: { value: 1, required: true }
},
inputs: 1,
outputs: 2,
outputLabels: ["Main effluent", "Recirculation effluent"],
icon: "font-awesome/fa-random",
label: function() {
return this.name || "Recirculation pump";
},
oneditprepare: function() {
$("#node-input-F2").typedInput({
type:"num",
types:["num"]
});
$("#node-input-inlet").typedInput({
type:"num",
types:["num"]
});
},
oneditsave: function() {
let debit = parseFloat($("#node-input-F2").typedInput("value"));
if (isNaN(volume) || debit < 0) {
RED.notify("Debit is not set correctly", {type: "error"});
}
let inlet = parseInt($("#node-input-n_inlets").typedInput("value"));
if (isNaN(inlet) || inlet < 1) {
RED.notify("Number of inlets not set correctly", {type: "error"});
}
}
});
</script>
<script type="text/html" data-template-name="recirculation-pump">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-F2"><i class="fa fa-tag"></i> Recirculation debit [m3 s-1]</label>
<input type="text" id="node-input-F2" placeholder="m3 s-1">
</div>
<div class="form-row">
<label for="node-input-inlet"><i class="fa fa-tag"></i> Assigned inlet recirculation</label>
<input type="text" id="node-input-inlet" placeholder="#">
</div>
</script>
<script type="text/html" data-help-name="recirculation-pump">
<p>Recirculation-pump for splitting streams</p>
</script>

View File

@@ -0,0 +1,38 @@
module.exports = function(RED) {
function recirculation(config) {
RED.nodes.createNode(this, config);
var node = this;
let name = config.name;
let F2 = parseFloat(config.F2);
let inlet = parseInt(config.inlet);
node.on('input', function(msg, send, done) {
switch (msg.topic) {
case "Fluent":
// conserve volume flow debit
let F1 = msg.payload.F;
let F_diff = Math.max(F1 - F2, 0);
let F2_corr = F1 < F2 ? F1 : F2;
let msg_F1 = structuredClone(msg);
msg_F1.payload.F = F_diff;
let msg_F2 = structuredClone(msg);
msg_F2.payload.F = F2_corr;
msg_F2.payload.inlet = inlet;
send([msg_F1, msg_F2]);
break;
default:
console.log("Unknown topic: " + msg.topic);
}
if (done) {
done();
}
});
}
RED.nodes.registerType("recirculation-pump", recirculation);
};