berechnung

$(document).ready(function () {

  // Assign data-value to Material options if missing
  const $newSelect = $('select[name="Material"]');
  if ($newSelect.length === 0) return;

  const dataMap = {
    "Grobkies": "20",
    "Mittelkies": "6.3",
    "Feinkies": "2",
    "Grobsand": "0.63",
    "Mittelsand": "0.2",
    "Feinsand": "0.063",
    "Grobschluff": "0.02",
    "Mittelschluff": "0.0063",
    "Feinschluff": "0.002",
    "Grobton": "0.00063",
    "Mittelton": "0.0002",
    "Feinton": "0.0001"
  };

  $newSelect.find("option").each(function () {
    const key = $(this).val().trim();
    if (dataMap[key]) {
      $(this).attr("data-value", dataMap[key]);
    }
  });


  // Temperature → Dynamic viscosity mapping
  const viscosityMap = {
    "0": 0.001792,
    "10": 0.001307,
    "20": 0.001002,
    "30": 0.000797,
    "40": 0.000653
  };

  function calculate() {
    const g = 9.81;
    const rho_p = 2650;
    const rho_f = 1000;

    // Get material grain size (mm)
    const material = parseFloat($('.material option:selected').data('value')) || 0;

    // Get flow input
    const Q = parseFloat($('.durchfluss').val()) || 0;

    // Temperature → viscosity
    const temp = $('.temperatur').val();
    const eta = viscosityMap[temp] || null;

    // Update grain size display
    $('#ct_korngr').text(material || "XX");
    $('#ct_h_korngr').val(material || "");

    // Update viscosity display
    if (eta) {
      $('#ct_dynamische').text(eta);
      $('#ct_h_dynamische').val(eta);
    } else {
      $('#ct_dynamische').text("XX");
      $('#ct_h_dynamische').val("");
    }

    // Stop calculation if missing values
    if (!material || !eta || Q <= 0) {
      $('#ct_sinkges').text("XX");
      $('#ct_h_sinkges').val("");

      $('#ct_ober').text("XX");
      $('#ct_h_ober').val("");

      return;
    }

    // mm → m
    const d = material / 1000;

    // Settling velocity
    const vs = (d*d * g * (rho_p - rho_f)) / (18 * eta); // m/s
    const vs_mm = vs * 1000; // mm/s

    // Required surface area
    const A = (Q / 1000) / vs; // l/s → m³/s

    // Output results
    $('#ct_sinkges').text(vs_mm.toFixed(2));
    $('#ct_h_sinkges').val(vs_mm.toFixed(2));

    $('#ct_ober').text(A.toFixed(2));
    $('#ct_h_ober').val(A.toFixed(2));
  }

  // Listen for changes
  $('.material, .durchfluss, .temperatur').on('change input', calculate);

  // Initial calculation
  calculate();

});

Leave a Reply

Your email address will not be published. Required fields are marked *