diff --git a/src/app/page.tsx b/src/app/page.tsx index d902116..ac39a43 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -17,6 +17,7 @@ import Box from "@mui/material/Box"; import type React from "react"; import type { ChangeEvent } from "react"; import { useEffect, useState } from "react"; +import type { Result } from "seismic-response"; const VisuallyHiddenInput = styled("input")({ clip: "rect(0 0 0 0)", @@ -41,7 +42,7 @@ const defaultStates = { initV: 0, initA: 0, initXg: 0, - resAccIndex: 0, + resultIndex: 0, csvColIndex: 0, }; @@ -67,11 +68,24 @@ export default function Home() { const [initXg, setInitXg] = useState(defaultStates.initXg); const [time, setTime] = useState([1]); - const [resAcc, setResAcc] = useState([[1]]); - const [resAccIndex, setResAccIndex] = useState(0); + const [result, setResult] = useState([ + { + x: Float64Array.from([1]), + v: Float64Array.from([1]), + a: Float64Array.from([1]), + abs_acc: Float64Array.from([1]), + free() {}, + }, + ]); + const [resultIndex, setResultIndex] = useState(0); const [naturalPeriodsSec, setNaturalPeriodsSec] = useState([1]); - const [spectrum, setSpectrum] = useState([1]); + const [spectrum, setSpectrum] = useState>({ + x: Float64Array.from([1]), + v: Float64Array.from([1]), + a: Float64Array.from([1]), + abs_acc: Float64Array.from([1]), + }); const [csvColIndex, setCsvColIndex] = useState( defaultStates.csvColIndex, @@ -88,7 +102,7 @@ export default function Home() { setInitV(defaultStates.initV); setInitA(defaultStates.initA); setInitXg(defaultStates.initXg); - setResAccIndex(defaultStates.resAccIndex); + setResultIndex(defaultStates.resultIndex); setCsvColIndex(defaultStates.csvColIndex); } @@ -102,7 +116,7 @@ export default function Home() { { length: numOfNaturalPeriods }, (_, i) => naturalPeriodStart + i * naturalPeriodOffset, ); - const resAccList = naturalPeriods.map((naturalPeriod) => { + const results = naturalPeriods.map((naturalPeriod) => { const params = { natural_period_ms: naturalPeriod, dt_ms: dt, @@ -115,25 +129,41 @@ export default function Home() { }; const analyzer = ResponseAccAnalyzer.from_params(params); - return Array.from(analyzer.analyze(data[csvColIndex])); + return analyzer.analyze(data[csvColIndex]); }); setTime( Array.from( - { length: resAccList[0].length }, + { length: results[0].x.length }, (_, i) => i * (dt / 1000), ), ); - setResAcc(resAccList); + setResult(results); setNaturalPeriodsSec( naturalPeriods.map((naturalPeriod) => naturalPeriod / 1000), ); - const spectrum = resAccList.map((resAcc) => { - return resAcc.reduce((acc, cur) => Math.max(acc, Math.abs(cur)), 0); - }); + const spectrum = (() => { + const max = results.map(({ x, v, a, abs_acc }) => ({ + x: x.reduce((acc, cur) => Math.max(acc, cur), 0), + v: v.reduce((acc, cur) => Math.max(acc, cur), 0), + a: a.reduce((acc, cur) => Math.max(acc, cur), 0), + abs_acc: abs_acc.reduce( + (acc, cur) => Math.max(acc, Math.abs(cur)), + 0, + ), + })); + + return { + x: Float64Array.from(max.map((v) => v.x)), + v: Float64Array.from(max.map((v) => v.v)), + a: Float64Array.from(max.map((v) => v.a)), + abs_acc: Float64Array.from(max.map((v) => v.abs_acc)), + }; + })(); + setSpectrum(spectrum); })(), 100, @@ -187,7 +217,7 @@ export default function Home() { return (
- + 1質点系 地震応答解析ツール{" "} @@ -312,37 +342,88 @@ export default function Home() { }> - 応答解析結果 - + 応答解析結果 + サンプル setResAccIndex(v as number)} + valueLabelDisplay="off" + value={resultIndex} + onChange={(_, v) => setResultIndex(v as number)} /> - + 固有周期:{" "} - {naturalPeriodStart + naturalPeriodOffset * resAccIndex} [ms] + {naturalPeriodStart + naturalPeriodOffset * resultIndex} [ms] - + + + + + + + + 応答スペクトル + + + + + + diff --git a/src/components/MyLineChart.tsx b/src/components/MyLineChart.tsx index 6777069..d8c6c88 100644 --- a/src/components/MyLineChart.tsx +++ b/src/components/MyLineChart.tsx @@ -2,11 +2,10 @@ import { Download } from "@mui/icons-material"; import { Button, FormControlLabel, - IconButton, Slider, Stack, Switch, - Tooltip, + Typography, } from "@mui/material"; import { ChartsClipPath, @@ -24,11 +23,13 @@ export function MyLineChart({ y, xLabel, yLabel, + title, }: { x: number[]; - y: number[]; + y: Float64Array; xLabel: string; yLabel: string; + title: string; }) { const id = useId(); const clipPathId = `${id}-clip-path`; @@ -70,7 +71,7 @@ export function MyLineChart({ @@ -138,6 +139,15 @@ export function MyLineChart({ 表示範囲のCSVをダウンロード + + + {title} + ); }