Unit Weight of Soil Calculation

Unit Weight of Soil Calculation – Free Online Tool :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –card-bg: #fff; –shadow: 0 2px 5px rgba(0,0,0,0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 20px; display: flex; flex-direction: column; align-items: center; } .container { max-width: 960px; width: 100%; background-color: var(–card-bg); padding: 30px; border-radius: 8px; box-shadow: var(–shadow); margin-bottom: 30px; } h1, h2, h3 { color: var(–primary-color); text-align: center; margin-bottom: 20px; } h1 { font-size: 2.2em; } h2 { font-size: 1.8em; } h3 { font-size: 1.4em; } .input-group { margin-bottom: 20px; padding: 15px; border: 1px solid var(–border-color); border-radius: 5px; background-color: var(–card-bg); } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group select { width: calc(100% – 24px); /* Account for padding */ padding: 12px; border: 1px solid var(–border-color); border-radius: 4px; box-sizing: border-box; font-size: 1em; } .input-group input[type="number"]:focus, .input-group select:focus { outline: none; border-color: var(–primary-color); box-shadow: 0 0 0 2px rgba(0, 74, 153, 0.2); } .input-group small { display: block; margin-top: 8px; font-size: 0.85em; color: #666; } .error-message { color: #dc3545; font-size: 0.8em; margin-top: 5px; display: none; /* Hidden by default */ } .button-group { display: flex; justify-content: center; gap: 15px; margin-top: 25px; flex-wrap: wrap; } button { padding: 12px 25px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; font-weight: bold; transition: background-color 0.3s ease, transform 0.2s ease; color: white; } button.primary { background-color: var(–primary-color); } button.primary:hover { background-color: #003366; transform: translateY(-1px); } button.success { background-color: var(–success-color); } button.success:hover { background-color: #218838; transform: translateY(-1px); } button.secondary { background-color: #6c757d; } button.secondary:hover { background-color: #5a6268; transform: translateY(-1px); } #results { margin-top: 30px; padding: 25px; border: 1px solid var(–border-color); border-radius: 5px; background-color: var(–card-bg); text-align: center; } #results h3 { margin-top: 0; color: var(–primary-color); } .result-item { margin-bottom: 15px; font-size: 1.1em; } .result-item strong { color: var(–primary-color); display: block; margin-bottom: 5px; } .main-result { font-size: 1.8em; font-weight: bold; color: var(–success-color); background-color: #e6f7e6; padding: 15px; border-radius: 5px; margin-bottom: 20px; border: 1px solid var(–success-color); } .formula-explanation { font-size: 0.95em; color: #555; margin-top: 15px; padding-top: 15px; border-top: 1px dashed var(–border-color); } table { width: 100%; border-collapse: collapse; margin-top: 20px; box-shadow: var(–shadow); } th, td { padding: 12px 15px; text-align: left; border: 1px solid var(–border-color); } thead th { background-color: var(–primary-color); color: white; font-weight: bold; } tbody tr:nth-child(even) { background-color: #f2f2f2; } caption { font-size: 1.1em; font-weight: bold; color: var(–primary-color); margin-bottom: 10px; text-align: left; } canvas { margin-top: 20px; display: block; width: 100%; max-width: 600px; margin-left: auto; margin-right: auto; border: 1px solid var(–border-color); background-color: var(–card-bg); } .chart-caption { font-size: 0.9em; color: #666; text-align: center; margin-top: 5px; } #article-section { margin-top: 40px; background-color: var(–card-bg); padding: 30px; border-radius: 8px; box-shadow: var(–shadow); } #article-section h2, #article-section h3 { text-align: left; } #article-section p, #article-section ul, #article-section ol { margin-bottom: 15px; } #article-section ul, #article-section ol { padding-left: 30px; } #article-section li { margin-bottom: 10px; } .faq-question { font-weight: bold; color: var(–primary-color); margin-top: 15px; margin-bottom: 5px; } .internal-links { margin-top: 30px; padding: 20px; border: 1px dashed var(–primary-color); border-radius: 5px; background-color: #e6f2fa; } .internal-links h4 { margin-top: 0; color: var(–primary-color); text-align: left; } .internal-links ul { list-style: none; padding: 0; } .internal-links li { margin-bottom: 10px; } .internal-links a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .internal-links a:hover { text-decoration: underline; } .internal-links p { font-size: 0.9em; color: #555; margin-top: 5px; } .credit { text-align: center; margin-top: 30px; font-size: 0.8em; color: #888; } .credit a { color: #888; text-decoration: underline; } @media (max-width: 600px) { body { padding: 10px; } .container, #results, #article-section { padding: 20px; } h1 { font-size: 1.8em; } h2 { font-size: 1.5em; } button { width: 100%; margin-bottom: 10px; } .button-group { flex-direction: column; align-items: center; } .main-result { font-size: 1.5em; } table, th, td { font-size: 0.9em; } caption { font-size: 1em; } }

Unit Weight of Soil Calculation

Determine the unit weight of soil with this easy-to-use calculator.

Enter the weight of the soil sample (in grams).
Direct Volume Measurement Water Displacement Method Select how the volume of the soil sample was determined.
Enter the measured volume of the soil sample (in liters).
Enter the initial volume of water in the container (in ml).
Enter the final volume of water after immersing the soil sample (in ml).
Use if accounting for specific soil properties or density variations (e.g., 1.0 for no correction). Default is 1.0.

Calculation Results

Total Soil Volume:
Bulk Unit Weight:
Dry Unit Weight:
Water Content Used:
Formula Used:
Unit Weight = (Weight of Soil Sample / Volume of Soil Sample) * Correction Factor

Dry Unit Weight = Bulk Unit Weight / (1 + (Moisture Content / 100))

Unit Weight vs. Moisture Content (for Fixed Volume)

Chart showing how bulk unit weight changes with moisture content for a fixed soil volume and weight.
Soil Properties Summary
Property Value Unit
Soil Sample Weightgrams
Calculated Soil Volumeliters
Bulk Unit Weightg/L
Dry Unit Weightg/L
Moisture Content%
Correction Factor

Understanding the Unit Weight of Soil

What is Unit Weight of Soil?

The unit weight of soil, also commonly referred to as soil density or specific weight, is a fundamental physical property that describes how much a given volume of soil weighs. It's a crucial parameter in various fields, particularly in geotechnical engineering, civil engineering, and construction, because it directly influences the load-bearing capacity, settlement characteristics, and overall stability of soil structures. Essentially, it tells us how 'heavy' a cubic meter (or cubic foot, or liter) of soil is under its natural, in-situ conditions or after compaction.

Who should use it: Geotechnical engineers, civil engineers, surveyors, construction managers, environmental scientists, and students studying soil mechanics will find this calculation essential. Anyone involved in designing foundations, roads, retaining walls, or earthworks needs to understand the unit weight of the soil they are working with.

Common misconceptions:

  • Unit weight is constant: Soil unit weight is not fixed. It varies significantly based on soil type (sand, clay, gravel), moisture content, compaction level, and the presence of organic matter or voids.
  • Higher density is always better: While denser soils are often stronger, excessive compaction can sometimes lead to undesirable outcomes. The 'optimal' density depends on the specific application.
  • Unit weight is the same as specific gravity: Specific gravity relates the density of soil solids to the density of water, whereas unit weight refers to the weight per unit volume of the bulk soil, including air voids and water.

Unit Weight of Soil Calculation Formula and Mathematical Explanation

The calculation of the unit weight of soil involves straightforward principles of density. The most common measure is the bulk unit weight, which considers the total weight of the soil (solids, water, and air) per unit volume.

Calculating Bulk Unit Weight:

The primary formula is:

γb = (Ws / Vs) * C

Where:

  • γb is the Bulk Unit Weight of the soil.
  • Ws is the total weight of the soil sample.
  • Vs is the total volume occupied by the soil sample (including solids, water, and air voids).
  • C is a Correction Factor, often used to adjust for specific conditions or measurement variations. It is typically 1.0 if no specific correction is needed.

Calculating Dry Unit Weight:

If the moisture content is known, the dry unit weight (the weight of soil solids only per unit volume) can be calculated from the bulk unit weight:

γd = γb / (1 + (w / 100))

Where:

  • γd is the Dry Unit Weight of the soil.
  • γb is the Bulk Unit Weight.
  • w is the Moisture Content of the soil, expressed as a percentage.

Variable Explanations and Units:

Soil Calculation Variables
Variable Meaning Unit Typical Range
Ws (Soil Sample Weight) The total mass of the soil sample collected for testing. grams (g) 100g – 5000g (depending on test scale)
Vs (Soil Sample Volume) The total volume occupied by the soil sample. Determined either directly or via water displacement. liters (L) or cubic centimeters (cm3) 0.1 L – 5 L (common lab scale)
C (Correction Factor) A multiplier to adjust the calculated unit weight for specific conditions or measurement precision. Unitless Typically 0.9 – 1.1 (1.0 is common)
w (Moisture Content) The ratio of the mass of water to the mass of solids in the soil, expressed as a percentage. % 0% – 50%+ (highly variable)
γb (Bulk Unit Weight) The weight of the soil sample per unit of its total volume. g/L or kN/m3 1000 g/L – 2000 g/L (typical range for many soils)
γd (Dry Unit Weight) The weight of the soil solids per unit of the soil's total volume. g/L or kN/m3 800 g/L – 1800 g/L (typical range)

Note: 1 liter = 1000 cm3. If using cm3 for volume, the unit weight will be in g/cm3. Often, geotechnical engineers use kN/m3, requiring conversion factors (1 g/cm3 ≈ 9.81 kN/m3). Our calculator uses g/L for simplicity.

Practical Examples (Real-World Use Cases) of Unit Weight of Soil Calculation

Understanding the unit weight of soil is vital for numerous practical applications in civil and environmental engineering.

Example 1: Foundation Design for a Small Building

A civil engineer is designing the foundation for a small commercial building. They need to estimate the soil's load-bearing capacity. Soil borings reveal a sandy loam. A collected sample weighing 2500 grams is tested in the lab. Using the water displacement method, the initial water volume was 1000 ml, and the final volume with the soil submerged was 2250 ml. The average moisture content is determined to be 12%. A standard correction factor of 1.0 is applied.

  • Inputs: Soil Sample Weight = 2500 g, Initial Water Volume = 1000 ml, Final Water Volume = 2250 ml, Moisture Content = 12%, Correction Factor = 1.0
  • Calculated Soil Volume: Vs = 2250 ml – 1000 ml = 1250 ml = 1.25 L
  • Calculated Bulk Unit Weight: γb = (2500 g / 1.25 L) * 1.0 = 2000 g/L
  • Calculated Dry Unit Weight: γd = 2000 g/L / (1 + (12 / 100)) = 2000 g/L / 1.12 ≈ 1785.7 g/L

Interpretation: The sandy loam has a bulk unit weight of 2000 g/L and a dry unit weight of approximately 1785.7 g/L. This data will be used alongside other soil properties (like shear strength) to determine the allowable bearing pressure for the foundation design, ensuring the structure remains stable and does not settle excessively.

Example 2: Embankment Construction and Compaction

For a road construction project, engineers need to fill an embankment using locally sourced fill material. They are aiming for a specific level of compaction to ensure stability and minimize future settlement. A sample of the fill material, weighing 1500 grams, is placed in a container with a known volume of 1.0 liter (1000 cm³). Laboratory testing reveals a moisture content of 18%. A correction factor of 1.05 is applied due to particle shape considerations.

  • Inputs: Soil Sample Weight = 1500 g, Soil Volume = 1.0 L, Moisture Content = 18%, Correction Factor = 1.05
  • Calculated Soil Volume: Vs = 1.0 L
  • Calculated Bulk Unit Weight: γb = (1500 g / 1.0 L) * 1.05 = 1575 g/L
  • Calculated Dry Unit Weight: γd = 1575 g/L / (1 + (18 / 100)) = 1575 g/L / 1.18 ≈ 1334.7 g/L

Interpretation: The fill material has a bulk unit weight of 1575 g/L and a dry unit weight of about 1334.7 g/L at 18% moisture. This information helps construction crews calibrate their compaction equipment. They might perform field density tests to compare against these lab results and ensure the achieved field unit weight meets the project specifications, typically targeting a high percentage of the maximum dry unit weight determined through a Standard or Modified Proctor test (a related soil mechanics procedure).

How to Use This Unit Weight of Soil Calculator

Our online calculator simplifies the process of determining the unit weight of soil. Follow these steps for accurate results:

  1. Determine Soil Sample Weight: Accurately weigh your collected soil sample using a calibrated scale. Enter this value in grams (g) into the "Soil Sample Weight" field.
  2. Select Volume Method: Choose how you determined the volume of your soil sample:
    • Direct Volume Measurement: If you measured the volume directly (e.g., using a calibrated container or ruler for irregular shapes), select "Direct Volume Measurement".
    • Water Displacement Method: If you used the water displacement technique (measuring the volume of water displaced by the soil), select "Water Displacement Method".
  3. Enter Volume Data:
    • If Direct Volume: Enter the measured volume in liters (L) into the "Soil Sample Volume" field.
    • If Water Displacement: Enter the initial volume of water (in ml) into "Initial Water Volume" and the final volume (water + soil, in ml) into "Final Water Volume (with Soil)". The calculator will compute the soil volume (1 L = 1000 ml).
  4. Input Moisture Content (Optional): If you know the moisture content of the soil sample, enter it as a percentage (e.g., '15' for 15%) in the "Moisture Content" field. Leave blank if not determined.
  5. Apply Correction Factor (Optional): If a specific correction factor is recommended or required for your analysis, enter it in the "Correction Factor" field. The default is 1.0, meaning no correction.
  6. Calculate: Click the "Calculate Unit Weight" button.

Reading the Results:

  • Main Result (Bulk Unit Weight): This is the primary output, shown prominently, indicating the weight per unit volume of the soil as it is (including air and water).
  • Total Soil Volume: Displays the calculated volume of the soil sample used in the calculation.
  • Bulk Unit Weight: Reiterates the main result.
  • Dry Unit Weight: Shown if moisture content was provided. This represents the weight of the solid particles per unit volume.
  • Water Content Used: Shows the moisture content value that was used in the calculation (or indicates if none was provided).

Decision-Making Guidance: Compare the calculated unit weight against typical values for similar soil types or project specifications. A significantly lower unit weight might indicate loose soil or high void content, potentially requiring compaction. A higher unit weight generally suggests denser, more stable soil. Consult geotechnical reports for project-specific requirements.

Key Factors That Affect Unit Weight of Soil Results

Several factors influence the unit weight of soil, making it a variable and context-dependent property. Understanding these elements is crucial for accurate interpretation:

  1. Soil Type (Particle Size Distribution): Different soil types have inherent density differences. Coarse-grained soils like gravel and sand tend to have higher unit weights when compacted compared to fine-grained soils like silts and clays, due to their particle shapes and packing arrangements.
  2. Moisture Content: Water content significantly affects bulk unit weight. As water is added to dry soil, it fills pore spaces, increasing the weight and thus the bulk unit weight, up to a certain point (the optimum moisture content for compaction). Beyond this point, excess water can actually decrease the dry unit weight by pushing solids apart.
  3. Compaction Effort: The degree to which soil is compacted – how densely the particles are packed together – is a major determinant of unit weight. Higher compaction energy generally leads to a denser soil with a higher unit weight and improved strength and reduced permeability. Construction sites often specify a target compaction level (e.g., 95% of Standard Proctor Maximum Dry Density).
  4. Void Ratio and Porosity: The amount of empty space (voids) between soil particles directly impacts unit weight. Soils with a high void ratio (many large pores) will have a lower unit weight compared to soils with a low void ratio (tightly packed particles). This is influenced by particle shape, size, and how the soil was deposited.
  5. Particle Shape and Gradation: Angular particles tend to interlock better than rounded particles, potentially leading to higher unit weights under compaction. Well-graded soils (a wide range of particle sizes) can pack more densely than poorly graded soils (mostly one size), resulting in higher unit weights.
  6. Organic Content: Soils with a high percentage of organic matter (like peat) are generally much lighter (lower unit weight) than mineral soils due to the low density of organic compounds. This can be a critical consideration in land development.
  7. Presence of Gases: While less common in typical field calculations, dissolved or trapped gases within the soil pores can slightly reduce the effective unit weight.

Frequently Asked Questions (FAQ) about Unit Weight of Soil

Q1: What is the typical unit weight of soil?

A1: The unit weight of soil varies greatly. For common soils like sands and clays, the bulk unit weight typically ranges from 1500 g/L to 2000 g/L (or 15 to 20 kN/m³). Dry unit weights are usually lower, ranging from 1000 g/L to 1800 g/L. Specific values depend heavily on the factors mentioned previously.

Q2: How does moisture content affect unit weight?

A2: Initially, adding water to dry soil increases the bulk unit weight as water fills the voids. However, beyond the optimal moisture content for compaction, excessive water can lubricate particles, allowing for looser packing, and the increase in water weight may not compensate for the loss in density, potentially reducing the dry unit weight if the soil solids are pushed apart.

Q3: Is bulk unit weight or dry unit weight more important?

A3: Both are important, but for different purposes. Bulk unit weight represents the actual weight per volume in the ground and is used for calculating earth pressures and foundation loads. Dry unit weight is critical for assessing soil strength and compaction quality, as it isolates the effect of soil solids and is less influenced by fluctuating water content.

Q4: What is the difference between unit weight and density?

A4: In practical terms, especially in soil mechanics, the terms "unit weight" and "density" are often used interchangeably. Technically, density is mass per unit volume (e.g., g/cm³ or kg/m³), while unit weight is weight per unit volume (e.g., N/m³ or lb/ft³). Since weight = mass × acceleration due to gravity (g), unit weight is simply density × g. Our calculator uses mass (grams) for simplicity, resulting in units like g/L, which function similarly to density in this context.

Q5: Can I use this calculator for any type of soil?

A5: Yes, this calculator applies to most common soil types (sands, silts, clays, gravels). However, the accuracy of the results relies on the accuracy of your input measurements (weight and volume). For highly organic soils or special materials, specific standards might apply.

Q6: What does a 'Correction Factor' mean?

A6: The correction factor allows for adjustments based on specific testing conditions, equipment calibration, or known properties of the soil that might influence the direct measurement. For most standard tests, a factor of 1.0 is used unless otherwise specified by testing protocols or project requirements.

Q7: How is the volume of soil measured accurately?

A7: Volume can be measured directly using calibrated containers or geometric calculations for samples with regular shapes. The water displacement method is common for irregular samples: measure a known volume of water, submerge the soil sample, and measure the new volume. The difference is the soil's volume. Ensure the soil sample is fully submerged and doesn't absorb excessive water during the test for accuracy.

Q8: Where can I find typical unit weight values for my project?

A8: Geotechnical reports for the specific site are the best source. You can also find typical ranges in soil mechanics textbooks, engineering handbooks (like the Civil Engineering Reference Manual), and government agency design manuals (e.g., AASHTO for transportation projects).

Related Tools and Internal Resources

var soilWeightInput = document.getElementById('soilWeight'); var soilVolumeInput = document.getElementById('soilVolume'); var waterVolumeInitialInput = document.getElementById('waterVolumeInitial'); var waterVolumeFinalInput = document.getElementById('waterVolumeFinal'); var moistureContentInput = document.getElementById('moistureContent'); var correctionFactorInput = document.getElementById('correctionFactor'); var volumeMethodSelect = document.getElementById('volumeMethod'); var directVolumeGroup = document.getElementById('directVolumeGroup'); var displacementVolumeGroup = document.getElementById('displacementVolumeGroup'); var soilWeightError = document.getElementById('soilWeightError'); var soilVolumeError = document.getElementById('soilVolumeError'); var waterVolumeInitialError = document.getElementById('waterVolumeInitialError'); var waterVolumeFinalError = document.getElementById('waterVolumeFinalError'); var moistureContentError = document.getElementById('moistureContentError'); var correctionFactorError = document.getElementById('correctionFactorError'); var mainResultDisplay = document.getElementById('mainResult'); var displaySoilVolume = document.getElementById('displaySoilVolume'); var displayBulkUnitWeight = document.getElementById('displayBulkUnitWeight'); var displayDryUnitWeight = document.getElementById('displayDryUnitWeight'); var displayWaterContentUsed = document.getElementById('displayWaterContentUsed'); var tableSoilWeight = document.getElementById('tableSoilWeight'); var tableSoilVolume = document.getElementById('tableSoilVolume'); var tableBulkUnitWeight = document.getElementById('tableBulkUnitWeight'); var tableDryUnitWeight = document.getElementById('tableDryUnitWeight'); var tableMoistureContent = document.getElementById('tableMoistureContent'); var tableCorrectionFactor = document.getElementById('tableCorrectionFactor'); var soilWeight = 0; var soilVolumeL = 0; var bulkUnitWeight = 0; var dryUnitWeight = 0; var moistureContent = 0; var correctionFactor = 1.0; var chart = null; var ctx = null; function formatNumber(num, precision = 2) { if (isNaN(num) || !isFinite(num)) { return '–'; } return num.toFixed(precision); } function validateInput(inputElement, errorElement, minValue = null, maxValue = null) { var value = parseFloat(inputElement.value); var isValid = true; errorElement.style.display = 'none'; inputElement.style.borderColor = '#ccc'; if (isNaN(value) || inputElement.value.trim() === "") { errorElement.textContent = "Please enter a valid number."; errorElement.style.display = 'block'; inputElement.style.borderColor = '#dc3545'; isValid = false; } else if (minValue !== null && value maxValue) { errorElement.textContent = "Value cannot be greater than " + maxValue + "."; errorElement.style.display = 'block'; inputElement.style.borderColor = '#dc3545'; isValid = false; } return isValid; } function updateVolumeInputsVisibility() { if (volumeMethodSelect.value === 'volume') { directVolumeGroup.style.display = 'block'; displacementVolumeGroup.style.display = 'none'; soilVolumeInput.value = "; // Clear if switching waterVolumeInitialInput.value = "; waterVolumeFinalInput.value = "; } else { // displacement directVolumeGroup.style.display = 'none'; displacementVolumeGroup.style.display = 'block'; soilVolumeInput.value = "; waterVolumeInitialInput.value = "; // Clear if switching waterVolumeFinalInput.value = "; } } function calculateVolume() { soilVolumeL = 0; // Reset if (volumeMethodSelect.value === 'volume') { if (validateInput(soilVolumeInput, soilVolumeError, 0.0001)) { soilVolumeL = parseFloat(soilVolumeInput.value); } else { return false; // Indicate volume calculation failed } } else { // displacement var validInitial = validateInput(waterVolumeInitialInput, waterVolumeInitialError, 0); var validFinal = validateInput(waterVolumeFinalInput, waterVolumeFinalError, 0); if (validInitial && validFinal) { var initialVol = parseFloat(waterVolumeInitialInput.value); var finalVol = parseFloat(waterVolumeFinalInput.value); if (finalVol <= initialVol) { waterVolumeFinalError.textContent = "Final volume must be greater than initial."; waterVolumeFinalError.style.display = 'block'; waterVolumeFinalInput.style.borderColor = '#dc3545'; return false; } soilVolumeL = (finalVol – initialVol) / 1000.0; // Convert ml to L } else { return false; // Indicate volume calculation failed } } return true; // Volume calculated successfully } function calculateUnitWeight() { var isSoilWeightValid = validateInput(soilWeightInput, soilWeightError, 0.0001); var isCorrectionFactorValid = validateInput(correctionFactorInput, correctionFactorError, 0.1, 5.0); // Reasonable range for correction var isMoistureValid = true; if (moistureContentInput.value.trim() !== "") { isMoistureValid = validateInput(moistureContentInput, moistureContentError, 0, 1000); // Allow high moisture for extreme cases } else { moistureContentInput.style.borderColor = '#ccc'; moistureContentError.style.display = 'none'; } if (!isSoilWeightValid || !isCorrectionFactorValid || !isMoistureValid) { return; // Stop if primary inputs are invalid } soilWeight = parseFloat(soilWeightInput.value); correctionFactor = parseFloat(correctionFactorInput.value); moistureContent = (moistureContentInput.value.trim() === "") ? 0 : parseFloat(moistureContentInput.value); if (!calculateVolume()) { return; // Stop if volume calculation failed } if (soilVolumeL 0) { dryUnitWeight = bulkUnitWeight / (1 + (moistureContent / 100)); } updateResultsDisplay(); updateTableDisplay(); updateChart(); } function updateResultsDisplay() { displaySoilVolume.textContent = formatNumber(soilVolumeL, 3) + ' L'; displayBulkUnitWeight.textContent = formatNumber(bulkUnitWeight, 2) + ' g/L'; mainResultDisplay.textContent = formatNumber(bulkUnitWeight, 2) + ' g/L'; // Main result is Bulk Unit Weight if (moistureContent > 0) { displayDryUnitWeight.textContent = formatNumber(dryUnitWeight, 2) + ' g/L'; displayWaterContentUsed.textContent = formatNumber(moistureContent, 1) + '%'; } else { displayDryUnitWeight.textContent = '–'; displayWaterContentUsed.textContent = 'N/A'; } } function updateTableDisplay() { tableSoilWeight.textContent = formatNumber(soilWeight, 1); tableSoilVolume.textContent = formatNumber(soilVolumeL, 3); tableBulkUnitWeight.textContent = formatNumber(bulkUnitWeight, 2); tableDryUnitWeight.textContent = (moistureContent > 0) ? formatNumber(dryUnitWeight, 2) : '–'; tableMoistureContent.textContent = (moistureContent > 0) ? formatNumber(moistureContent, 1) + '%' : 'N/A'; tableCorrectionFactor.textContent = formatNumber(correctionFactor, 2); } function resetCalculator() { soilWeightInput.value = '2000'; volumeMethodSelect.value = 'volume'; updateVolumeInputsVisibility(); soilVolumeInput.value = '1.2'; waterVolumeInitialInput.value = "; waterVolumeFinalInput.value = "; moistureContentInput.value = '15'; correctionFactorInput.value = '1.0'; // Clear errors soilWeightError.style.display = 'none'; soilWeightInput.style.borderColor = '#ccc'; soilVolumeError.style.display = 'none'; soilVolumeInput.style.borderColor = '#ccc'; waterVolumeInitialError.style.display = 'none'; waterVolumeInitialInput.style.borderColor = '#ccc'; waterVolumeFinalError.style.display = 'none'; waterVolumeFinalInput.style.borderColor = '#ccc'; moistureContentError.style.display = 'none'; moistureContentInput.style.borderColor = '#ccc'; correctionFactorError.style.display = 'none'; correctionFactorInput.style.borderColor = '#ccc'; calculateUnitWeight(); // Recalculate with defaults } function copyResults() { var resultsText = "Unit Weight of Soil Calculation Results:\n\n"; resultsText += "Main Result (Bulk Unit Weight): " + mainResultDisplay.textContent + "\n"; resultsText += "Total Soil Volume: " + displaySoilVolume.textContent + "\n"; resultsText += "Bulk Unit Weight: " + displayBulkUnitWeight.textContent + "\n"; resultsText += "Dry Unit Weight: " + displayDryUnitWeight.textContent + "\n"; resultsText += "Water Content Used: " + displayWaterContentUsed.textContent + "\n\n"; resultsText += "Key Assumptions:\n"; resultsText += "- Soil Sample Weight: " + tableSoilWeight.textContent + " g\n"; resultsText += "- Soil Volume: " + tableSoilVolume.textContent + "\n"; resultsText += "- Correction Factor: " + tableCorrectionFactor.textContent + "\n"; resultsText += "- Moisture Content: " + tableMoistureContent.textContent + "\n"; try { var textArea = document.createElement("textarea"); textArea.value = resultsText; textArea.style.position = "fixed"; textArea.style.left = "-9999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); document.execCommand('copy'); document.body.removeChild(textArea); alert("Results copied to clipboard!"); } catch (err) { alert("Failed to copy results. Please copy manually."); } } function initializeChart() { ctx = document.getElementById('unitWeightChart').getContext('2d'); chart = new Chart(ctx, { type: 'line', data: { labels: [], // Will be populated by updateChart datasets: [{ label: 'Bulk Unit Weight (g/L)', data: [], // Will be populated by updateChart borderColor: 'var(–primary-color)', backgroundColor: 'rgba(0, 74, 153, 0.1)', fill: true, tension: 0.1 }, { label: 'Dry Unit Weight (g/L)', data: [], // Will be populated by updateChart borderColor: 'var(–success-color)', backgroundColor: 'rgba(40, 167, 69, 0.1)', fill: true, tension: 0.1 }] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, title: { display: true, text: 'Unit Weight (g/L)' } }, x: { title: { display: true, text: 'Moisture Content (%)' } } }, plugins: { tooltip: { callbacks: { label: function(context) { var label = context.dataset.label || "; if (label) { label += ': '; } if (context.parsed.y !== null) { label += context.parsed.y.toFixed(2); } return label; } } } } } }); } function updateChart() { if (!chart) { initializeChart(); } var currentSoilWeight = parseFloat(soilWeightInput.value) || 2000; // Use default if input is empty var currentCorrectionFactor = parseFloat(correctionFactorInput.value) || 1.0; // Use default if input is empty // Get the volume determined by the calculator logic var calculatedVolumeL = soilVolumeL > 0 ? soilVolumeL : 1.2; // Default to 1.2L if not calculated yet var moistureLevels = []; var bulkWeights = []; var dryWeights = []; // Generate data points for moisture content from 0% to 50% for (var mc = 0; mc <= 50; mc += 2) { moistureLevels.push(mc); var currentBulk = (currentSoilWeight / calculatedVolumeL) * currentCorrectionFactor; var currentDry = currentBulk / (1 + (mc / 100)); bulkWeights.push(currentBulk); dryWeights.push(currentDry); } chart.data.labels = moistureLevels; chart.data.datasets[0].data = bulkWeights; chart.data.datasets[1].data = dryWeights; chart.update(); } // Initial setup document.addEventListener('DOMContentLoaded', function() { updateVolumeInputsVisibility(); // Set initial values and trigger calculation on load resetCalculator(); // Ensure chart is initialized and updated initializeChart(); updateChart(); // Add event listeners for real-time updates soilWeightInput.addEventListener('input', calculateUnitWeight); soilVolumeInput.addEventListener('input', calculateUnitWeight); waterVolumeInitialInput.addEventListener('input', calculateUnitWeight); waterVolumeFinalInput.addEventListener('input', calculateUnitWeight); moistureContentInput.addEventListener('input', calculateUnitWeight); correctionFactorInput.addEventListener('input', calculateUnitWeight); volumeMethodSelect.addEventListener('change', function() { updateVolumeInputsVisibility(); calculateUnitWeight(); // Recalculate when method changes }); });

Leave a Comment