From 3934eb8c9dfdacfc94f287d66b5d9a68e9f7458f Mon Sep 17 00:00:00 2001 From: yz Date: Mon, 24 Feb 2025 16:56:02 +0800 Subject: [PATCH] vault backup: 2025-02-24 16:56:01 --- 多体+耦合求解器/数据结构.md | 149 ++++++++++++++++++++++++++++++ 补课/多体动力学/sympy_start.ipynb | 125 +++++++++++++++++++++++++ 补课/多体动力学/sympy_start.py | 21 +++++ 3 files changed, 295 insertions(+) create mode 100644 多体+耦合求解器/数据结构.md create mode 100644 补课/多体动力学/sympy_start.ipynb create mode 100644 补课/多体动力学/sympy_start.py diff --git a/多体+耦合求解器/数据结构.md b/多体+耦合求解器/数据结构.md new file mode 100644 index 0000000..679edf5 --- /dev/null +++ b/多体+耦合求解器/数据结构.md @@ -0,0 +1,149 @@ + +```rust +#![allow(unused)] // 忽略未使用的警告 + + + +use ndarray::*; // 导入 ndarray crate,提供高效的 n 维数组功能 + + + +// 定义结构体: MyStructType1,用于存储不同维度的矩阵 + + + +#[derive(Default)] // 使用 Default trait 自动实现默认构造函数 + +pub struct MyStructType1 { + +    pub matrix1: Array1, // 1D 矩阵,类型为 f64 + +    pub matrix2: Array2, // 2D 矩阵,类型为 f64 + +    pub matrix3: Array3, // 3D 矩阵,类型为 f64 + +} + + + +#[derive(Default)] // 使用 Default trait 自动实现默认构造函数 + +pub struct MyStructType { + +    pub attribute_string: String, // Supplied by Driver: full path and filename for the HydroDyn module + +    pub attribute_bool: bool, // Supplied by Driver: true if using an input file, false if all inputs are being passed in by the caller + +    pub attribute_value: f64, // i32, f32, etc ...// Wave field handling (switch) + +    pub attribute_vec: Vec, // 用于存储一个固定类型元素如String的可变长度集合, 注意1维数组统一用Array1D + +    pub attribute_array1d: Array1, // 1D 矩阵,类型为 f64 + +    pub attribute_array2d: Array2, // 2D 矩阵,类型为 f64 + +    pub attribute_array3d: Array3, // 3D 矩阵,类型为 f64 + +    pub attribute_struct: MyStructType1, // StructType 结构体 + + + +    // default values + +    pub attribute_val_with_default: f64,      // i32, f32, etc ... + +    pub attribute_vec_with_default: Vec, // ??? + +    pub attribute_array_with_default: Array2, // 2D 矩阵,类型为 f64 + + + +    // constant values + +    pub attribute_constant: f64, //  gravity how to define?   Supplied by Driver: Gravitational acceleration (m/s^2) + +} + + + +// 为 MyStructType 提供一个新的构造函数 + +impl MyStructType { + +    // new 方法用于创建一个新的 StructType 实例,默认初始化 + +    pub fn new() -> Self { + +        MyStructType::default()// 调用默认构造函数 + +    } + +} + + + +impl MyStructType { + + + +    pub fn test() -> Self { + +        MyStructType::new() // + +    } + +} + + + +fn main() { + +    // 定义矩阵的维度 + +    let nx = 10_usize; // 矩阵的行数 + +    let ny = 10_usize; // 矩阵的列数 + +    let nz = 10_usize; // 3D 矩阵的深度(层数) + + + +    // 创建一个 MyStructType 实例 + +    let mut my_struct = MyStructType::new(); + + + +    // 初始化 1D 矩阵 matrix1,元素数量为 nx,且所有元素值为 0.0 + +    // my_struct.attribute_array1d = Array1::zeros(nx); // or + +    // define 1D array, and assign values + +    // my_struct.attribute_array1d = array![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]; + +    let array1d = array![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]; + +    my_struct.attribute_array1d = array1d; + + + +    // 初始化 2D 矩阵 matrix2,行数为 nx,列数为 ny,且所有元素值为 0.0 + +    my_struct.attribute_array2d = Array2::zeros((nx, ny)); + + + +    // 初始化 3D 矩阵 matrix3,维度为 (nx, ny, nz),且所有元素值为 0.0 + +    my_struct.attribute_array3d = Array3::zeros((nx, ny, nz)); + +} +``` + + + +```rust +pub inp_bl: Vec,              // 各个叶片的输入数据 +``` +default inp_bl = vec![] \ No newline at end of file diff --git a/补课/多体动力学/sympy_start.ipynb b/补课/多体动力学/sympy_start.ipynb new file mode 100644 index 0000000..d343dbe --- /dev/null +++ b/补课/多体动力学/sympy_start.ipynb @@ -0,0 +1,125 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import sympy as sm\n", + "a, b, th, gama, x, t, y, z = sm.symbols(\"a, b, theta, gamma, x, t, y, z\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(a, b, theta, gamma, x, t, y, z)" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a, b, th, gama, x, t, y, z\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "f" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f = sm.Function('f')\n", + "f" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\sin{\\left(f{\\left(t \\right)} \\right)} - \\frac{\\tan{\\left(\\frac{a}{b} \\right)}}{\\log{\\left(\\gamma \\right)}}$" + ], + "text/plain": [ + "sin(f(t)) - tan(a/b)/log(gamma)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "expr3 = sm.sin(f(t)) - sm.tan(a/b)/sm.log(gama)\n", + "expr3" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{2 a \\left(\\tan^{2}{\\left(\\frac{a}{b} \\right)} + 1\\right) \\tan{\\left(\\frac{a}{b} \\right)}}{b^{3} \\log{\\left(\\gamma \\right)}} + \\frac{\\tan^{2}{\\left(\\frac{a}{b} \\right)} + 1}{b^{2} \\log{\\left(\\gamma \\right)}}$" + ], + "text/plain": [ + "2*a*(tan(a/b)**2 + 1)*tan(a/b)/(b**3*log(gamma)) + (tan(a/b)**2 + 1)/(b**2*log(gamma))" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "part1 = sm.diff(expr3, a)\n", + "part2 = sm.diff(part1, b)\n", + "part2" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "blade", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.16" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/补课/多体动力学/sympy_start.py b/补课/多体动力学/sympy_start.py new file mode 100644 index 0000000..a6ae927 --- /dev/null +++ b/补课/多体动力学/sympy_start.py @@ -0,0 +1,21 @@ +import sympy as sm + + +sm.init_printing() + +a, b, th, gama, x, t, y, z = sm.symbols("a, b, theta, gamma, x, t, y, z") +# # sm.pprint(a, b, th, gama, x, t, y, z) + +f = sm.Function('f') + +# print(sm.latex(f(t))) + +expr3 = sm.sin(f(t)) - sm.tan(a/b)/sm.log(gama) + +sm.pprint(expr3) + +part1 = sm.diff(expr3, a) +part2 = sm.diff(part1, b) + +sm.pprint(part2) +print(sm.latex(part2)) \ No newline at end of file