WEPPData.java [src/java/d/dataNodes] Revision: default  Date:
/*
 * $Id$
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API, and application suite.
 *
 * 2012-2017, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package d.dataNodes;

import org.json.JSONException;
import org.json.JSONObject;
import soils.Component;
import soils.Horizon;

/**
 *
 * @author Brad
 */
public class WEPPData {
    
    private double conductivity;
    private double interrill;
    private double rill;
    private double shear;
    private double restrict;
    private int restrictType;
    private double aniso;
    private double uksat;

    public double getConductivity() {
        return conductivity;
    }

    public double getInterrill() {
        return interrill;
    }

    public double getRill() {
        return rill;
    }

    public double getShear() {
        return shear;
    }

    public double getRestrict() {
        return restrict;
    }

    public int getRestrictType() {
        return restrictType;
    }

    public double getAniso() {
        return aniso;
    }

    public double getUksat() {
        return uksat;
    }
    
    
    
    public void computeErodibility(Horizon horizon) {

        if ((horizon.sandtotal_r() > 0) && (horizon.claytotal_r() > 0) && (horizon.cec7_r() > 0)) {
            if (horizon.claytotal_r() <= 40) {
                if (horizon.cec7_r() > 1) {
                    conductivity =  -0.265 + 0.0086 * Math.pow(horizon.sandtotal_r(), 1.8) + 11.46 * Math.pow(horizon.cec7_r(), -0.75);
                } else {
                    conductivity = 11.195 + 0.0086 * Math.pow(horizon.sandtotal_r(), 1.8); // from WEPP code, not in documentation
                }
            } else {
                conductivity = 0.0066 * Math.exp(244.0 / horizon.claytotal_r());
            }
        } else {
            conductivity = 0; // let model calc
        }
        if ((horizon.sandtotal_r() > 0) && (horizon.sandvf_r() > 0) && (horizon.om_r() > 0) && (horizon.claytotal_r() > 0)) {
            if (horizon.sandtotal_r() >= 30) {
                if (horizon.sandvf_r() > 40) {
                    horizon.sandvf_r(40);
                }
                if (horizon.om_r() < 0.35) {
                    horizon.om_r(0.35);
                }
                if (horizon.claytotal_r() > 40) {
                    horizon.claytotal_r(40);
                }
                interrill = 2728000 + 192100 * horizon.sandvf_r();
                rill = 0.00197 + 0.00030 * horizon.sandvf_r() + 0.03863 * Math.exp(-1.84 * horizon.om_r());
                shear = 2.67 + 0.065 * horizon.claytotal_r() - 0.058 * horizon.sandvf_r();
            } else {
                if (horizon.claytotal_r() < 10) {
                    horizon.claytotal_r(10);
                }
                interrill = 6054000 - 55130 * horizon.claytotal_r();
                rill = 0.0069 + 0.134 * Math.exp(-0.20 * horizon.claytotal_r());
                shear = 3.5;
            }
        } else {
            interrill = 0;
            rill = 0;
            shear = 0;
        }
    }
    
    public void setBedrockData(Component comp){
        char hzChar;
        
        for(Horizon h : comp.horizons.values()){
            if(h.hzname().length() == 0)
                hzChar = 'N'; // null and not bedrock
            else
                hzChar = h.hzname().charAt(0);
            switch (hzChar) {
            case 'C':
                // weathered, use the info for fractured igneous and metamorphic rock
                if(h.hzname().length() > 1 && h.hzname().charAt(1) == 'r'){
                    restrict = 1;
                    restrictType = 2;
                    aniso = 25.000000;
                    uksat = 3.6;
                }
                break;
            case 'R':
                // solid bedrock, use the info for basalt
                restrict = 1;
                restrictType = 2;
                aniso = 25.000000;
                uksat = 0.0036;
                break;
            default:
                // no bedrock
                restrict = 0;
                restrictType = 0;
                aniso = 0;
                uksat = 0;
                break;
            }
        }
        
    }
}