Example #1
0
    // Construct Shared Array For Serveral Entities
    protected override void OnUpdate()
    {
        // 读取数据并存储在 BlobAsset 中
        gmBlobRefs = new List <BlobAssetReference <GroundMotionBlobAsset> >();
        // 获得所有可选 GroundMotion 的名字
        var gms = GmDataReader.GroundMotionFolders(groundMotionPath);

        foreach (var item in gms)
        {
            //FIXME: Debug 运行了两次,表示读取了两次数据? 可能有问题代码
            //Debug.Log(item);
            if (!GetData(item))
            {
                break;
            }

            // 创建 BlobBuilder,赋值 gmArray 和 gmName
            BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp);

            // Blob 声明资产类型
            ref GroundMotionBlobAsset       groundMotionBlobAsset = ref blobBuilder.ConstructRoot <GroundMotionBlobAsset>();
            BlobBuilderArray <GroundMotion> gmArray = blobBuilder.Allocate(ref groundMotionBlobAsset.gmArray, acc.Count);

            // 存储加速度数据为 BlobArray
            // TODO: 也许有新的数据转换方式从 List<Vector3> 到 BlobBuilderArray<GroundMotion>
            for (int i = 0; i < acc.Count; ++i)
            {
                gmArray[i] = new GroundMotion {
                    acceleration = new float3(acc[i])
                };
            }

            // 存储相应地震名字为 BlobString
            blobBuilder.AllocateString(ref groundMotionBlobAsset.gmName, item);

            // 声明 Blob 资产引用
            BlobAssetReference <GroundMotionBlobAsset> groundMotionBlobAssetReference =
                blobBuilder.CreateBlobAssetReference <GroundMotionBlobAsset>(Allocator.Persistent);

            gmBlobRefs.Add(groundMotionBlobAssetReference);
            // 释放 BlobBuilder
            blobBuilder.Dispose();
        }
Example #2
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag != "Player")
        {
            return;
        }

        GameObject.Destroy(gameObject);

        GroundMotion gm       = GetComponent <GroundMotion>();
        Renderer     renderer = GetComponent <Renderer>();
        float        offsetx  = renderer.bounds.min.x;
        float        offsety  = renderer.bounds.min.y;

        while (offsetx < renderer.bounds.max.x)
        {
            while (offsety < renderer.bounds.max.y)
            {
                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cube.transform.position   = new Vector3(offsetx, offsety, transform.position.z);
                cube.transform.localScale = Vector3.one * CubeSize;
                cube.GetComponent <Renderer>().materials = renderer.materials;

                GroundMotion gmcube = cube.AddComponent(typeof(GroundMotion)) as GroundMotion;
                gmcube.Position  = gm.Position;
                gmcube.GameSpeed = gm.GameSpeed;

                Rigidbody rb         = cube.AddComponent(typeof(Rigidbody)) as Rigidbody;
                Vector3   explodepos = new Vector3(transform.position.x, offsety, transform.position.z);
                rb.mass     = CubeSize;
                rb.velocity = new Vector3(0, 0, gm.GameSpeed.RuntimeValue);
                rb.AddExplosionForce(ExplosionForce * gm.GameSpeed.RuntimeValue, explodepos, 0.25f, UpForce, ForceMode.Impulse);

                GameObject.Destroy(cube, 1f);

                offsety += CubeSize;
            }
            offsetx += CubeSize;
            offsety  = renderer.bounds.min.y;
        }
    }
Example #3
0
        static void Main(string[] args)
        {
            //  HazardCalculation.ThisScenario.saPeriodParam=1;  !!!! See below
            HazardCalculation.ThisScenario.Magnitude           = 6.3;
            HazardCalculation.ThisScenario.RuptureDistance     = 25.6;
            HazardCalculation.ThisScenario.JoynerBooreDistance = 25.1;
            HazardCalculation.ThisScenario.RxDistance          = 25.2;
            HazardCalculation.ThisScenario.VsThirty            = 640.0;
            HazardCalculation.ThisScenario.IsInferred          = false;
            HazardCalculation.ThisScenario.SiteType            = SiteType.FIRM_ROCK;
            HazardCalculation.ThisScenario.MagnitudeType       = MagnitudeType.MOMENT;
            HazardCalculation.ThisScenario.FaultStyle          = FaultStyle.STRIKE_SLIP;
            HazardCalculation.ThisScenario.Dip       = 90;
            HazardCalculation.ThisScenario.Width     = 20;
            HazardCalculation.ThisScenario.Ztor      = 1.0;
            HazardCalculation.ThisScenario.Z1p0      = 1.5;
            HazardCalculation.ThisScenario.Z2p5      = 3.0;
            HazardCalculation.ThisScenario.HypoDepth = 8.0;

            string GMPEName = "ASK2014_AttenRel"; // "CY2014_AttenRel"; // "I2014_AttenRel"; // "CB2014_AttenRel"; // "BSSA2014_AttenRel"; // "ASK2014_AttenRel"; // "Campbell_2003_AttenRel";  GMPEName="ToroEtAl_1997_AttenRel"; //GMPEName = "AB2006_140_AttenRel";

            double[] periods = { 0.01, 0.02, 0.03, 0.05, 0.075, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 7.5, 10.0 };

            // alternative set of periods that require interpolation
            // double[] periods = { 0.015, 0.025, 0.04, 0.0625, 0.0875, 0.125, 0.175, 0.225, 0.275, 0.35, 0.45, 0.625, 0.875, 1.25, 1.75, 2.5, 3.5, 4.5, 5.5, 6.75, 8.75 };

            double[] MedianResults = new double[periods.Length];
            double[] SigmaResults  = new double[periods.Length];

            Type    elementType = Type.GetType("GMPEs." + GMPEName);
            dynamic GMPE        = Activator.CreateInstance(elementType); // method to instantiate a class by it's name

            try
            {
                for (int i = 0; i < periods.Length; i++)
                {
                    HazardCalculation.ThisScenario.saPeriodParam = periods[i];

                    GroundMotion gm = new GroundMotion();
                    gm = GMPE.GetGroundMotion(gm);

                    double Median = Math.Exp(gm.GetLogMean());
                    double Sigma  = gm.GetLogStd();

                    MedianResults[i] = Median;
                    SigmaResults[i]  = Sigma;
                }


                using (StreamWriter writer = new StreamWriter("lnY.txt"))
                {
                    string line = "Period" + " " + (string)GMPE.SHORT_NAME;

                    writer.WriteLine(line);

                    for (int i = 0; i < periods.Length; i++)
                    {
                        line = Convert.ToString(periods[i]);

                        line = line + " " + Convert.ToString(MedianResults[i]);
                        writer.WriteLine(line);
                    }
                }



                using (StreamWriter writer = new StreamWriter("Sigma.txt"))
                {
                    string line = "Period" + " " + GMPE.SHORT_NAME;

                    writer.WriteLine(line);

                    for (int i = 0; i < periods.Length; i++)
                    {
                        line = Convert.ToString(periods[i]);

                        line = line + " " + Convert.ToString(SigmaResults[i]);
                        writer.WriteLine(line);
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("The program will now terminate.\n");
                Console.WriteLine("Press any key to quit.");
                Console.ReadKey();
                Environment.Exit(0);
            }
        }
 // Start is called before the first frame update
 void Start()
 {
     ground = gameObject.GetComponent <GroundMotion>();
 }