vault backup: 2025-02-24 16:56:01

This commit is contained in:
yz 2025-02-24 16:56:02 +08:00
parent dd8a98764e
commit 3934eb8c9d
3 changed files with 295 additions and 0 deletions

View File

@ -0,0 +1,149 @@
```rust
#![allow(unused)] // 忽略未使用的警告
use ndarray::*; // 导入 ndarray crate提供高效的 n 维数组功能
// 定义结构体: MyStructType1用于存储不同维度的矩阵
#[derive(Default)] // 使用 Default trait 自动实现默认构造函数
pub struct MyStructType1 {
    pub matrix1: Array1<f64>, // 1D 矩阵,类型为 f64
    pub matrix2: Array2<f64>, // 2D 矩阵,类型为 f64
    pub matrix3: Array3<f64>, // 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<f64>, // 用于存储一个固定类型元素如String的可变长度集合, 注意1维数组统一用Array1D
    pub attribute_array1d: Array1<f64>, // 1D 矩阵,类型为 f64
    pub attribute_array2d: Array2<f64>, // 2D 矩阵,类型为 f64
    pub attribute_array3d: Array3<f64>, // 3D 矩阵,类型为 f64
    pub attribute_struct: MyStructType1, // StructType 结构体
    // default values
    pub attribute_val_with_default: f64,      // i32, f32, etc ...
    pub attribute_vec_with_default: Vec<f64>, // ???
    pub attribute_array_with_default: Array2<f64>, // 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<BladeInputData>,              // 各个叶片的输入数据
```
default inp_bl = vec![]

View File

@ -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
}

View File

@ -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))