groundmodels-core

Crates.iogroundmodels-core
lib.rsgroundmodels-core
version0.1.0
created_at2025-07-22 04:43:48.261054+00
updated_at2025-07-22 04:43:48.261054+00
descriptionA library for geotechnical ground modeling and soil parameter analysis
homepage
repositoryhttps://github.com/yourusername/groundmodels
max_upload_size
id1763000
size575,115
Sam Rogers (Samotron)

documentation

README

GroundModels - AGSi Conversion Library

A Rust library for converting AGSi (Applied Ground Science Information) files to soil parameters and ground models.

Overview

This library provides functionality equivalent to the TypeScript addConvertCommand function, allowing you to:

  1. Convert AGSi files to arrays of SoilParams
  2. Convert AGSi files to GroundModel objects
  3. Export results to JSON format

Core Functions

convert_agsi_file

The main conversion function that processes AGSi JSON files:

pub fn convert_agsi_file(
    file_path: &str, 
    convert_type: ConvertType, 
    output_path: Option<&str>
) -> Result<String, Box<dyn std::error::Error>>

SoilParams::from_agsi_data_parameters

Converts AGSi data parameter values to soil parameters:

pub fn from_agsi_data_parameters(data: &[AgsiDataParameterValueElement]) -> Self

GroundModel::from_agsi_file

Creates a ground model from AGSi JSON data:

pub fn from_agsi_file(agsi_json: &serde_json::Value) -> Self

Supported AGSi Parameters

The conversion process maps the following AGSi parameter codes:

AGSi Code ID SoilParams Field Description
UnitWeight unit_weight Unit weight of soil
AngleFriction phi_prime Angle of internal friction
UndrainedShearStrength cu Undrained shear strength (sets behavior to Cohesive)
YoungsModulus youngs_modulus Young's modulus
Cohesion c_prime Effective cohesion
ModulusOfVolumeCompressibility mv Coefficient of volume compressibility
GeologicalStrengthIndex gsi Geological Strength Index
UnconfinedCompressiveStrength ucs UCS (sets behavior to Rock)
HoekBrownParamMi mi Hoek-Brown parameter mi
Disturbance disturbance Disturbance factor

Any unrecognized parameters are stored in the advanced_parameters field.

Usage Examples

Basic Conversion

use groundmodels::{convert_agsi_file, ConvertType};

// Convert to SoilParams array
let result = convert_agsi_file(
    "input.json", 
    ConvertType::SoilParams, 
    Some("output.json")
)?;

// Convert to GroundModel
let result = convert_agsi_file(
    "input.json", 
    ConvertType::GroundModel, 
    None // Print to stdout
)?;

Direct Parameter Conversion

use groundmodels::{SoilParams, AgsiDataParameterValueElement};

let data = vec![
    AgsiDataParameterValueElement {
        code_id: "UnitWeight".to_string(),
        value_numeric: Some(18.0),
    },
    AgsiDataParameterValueElement {
        code_id: "AngleFriction".to_string(),
        value_numeric: Some(30.0),
    },
];

let soil_params = SoilParams::from_agsi_data_parameters(&data);

Soil Behavior Classification

The library automatically determines soil behavior based on parameters:

  • Cohesive: When UndrainedShearStrength is provided with a positive value
  • Rock: When UnconfinedCompressiveStrength is provided
  • Granular: Default behavior

Data Structures

AgsiDataParameterValueElement

pub struct AgsiDataParameterValueElement {
    pub code_id: String,
    pub value_numeric: Option<f64>,
}

ConvertType

pub enum ConvertType {
    SoilParams,
    GroundModel,
}

AdvancedParameter

pub struct AdvancedParameter {
    pub name: String,
    pub value: f64,
}

Error Handling

The conversion functions return Result types for proper error handling:

match convert_agsi_file("input.json", ConvertType::SoilParams, None) {
    Ok(json_output) => println!("Success: {}", json_output),
    Err(e) => eprintln!("Error: {}", e),
}

Input Format

The expected AGSi JSON structure:

{
  "agsiModel": [
    {
      "agsiModelElement": [
        {
          "elementName": "Layer Name",
          "agsiDataParameterValue": [
            {
              "codeID": "UnitWeight",
              "valueNumeric": 18.0
            }
          ]
        }
      ]
    }
  ]
}

Output Format

SoilParams Array

Returns a JSON array of soil parameter objects with all the geotechnical properties.

GroundModel

Returns a JSON object containing:

  • soil_layers: Array of soil layers (empty in basic conversion)
  • soil_params: Array of soil parameters
  • rigid_boundary: Optional rigid boundary depth
  • groundwater: Groundwater level
  • reference: Reference identifier
Commit count: 0

cargo fmt