-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblems.py
More file actions
69 lines (56 loc) · 2.14 KB
/
Copy pathproblems.py
File metadata and controls
69 lines (56 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Public problem-builder compatibility functions."""
from __future__ import annotations
from collections.abc import Mapping
import torch
from experiments.problem_builders import (
build_damped_oscillator,
build_harmonic_oscillator,
build_heat_problem,
)
def _oscillator_params(param: Mapping[str, float]) -> dict[str, float]:
dt = float(param["dt"])
steps = int(param["steps"])
return {
"T": steps * dt,
"dt": dt,
"k": float(param["k"]),
"m": float(param["m"]),
"nu": float(param["nu"]),
"C": float(param["C"]),
"x0": float(param["x0"]),
"xT": float(param["xq"]),
}
def problem_OAF(
param: Mapping[str, float], scaling: bool = True
) -> tuple[torch.Tensor, torch.Tensor]:
"""Create the corrected forced harmonic oscillator interior system.
``steps`` retains its historical meaning of time intervals. Thus
``steps=100`` gives 101 nodes, two prescribed endpoints, and 99 unknowns.
"""
problem = build_harmonic_oscillator(_oscillator_params(param), scale=scaling)
return (
problem["rhs"].to(dtype=torch.complex128),
problem["matrix"].to(dtype=torch.complex128),
)
def problem_OAA(
param: Mapping[str, float], scaling: bool = True
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
"""Create the corrected damped system and its Hermitian embedding."""
parameters = _oscillator_params(param)
parameters["gamma"] = float(param["gamma"])
problem = build_damped_oscillator(parameters, scale=scaling)
return (
problem["embedded_rhs"].to(dtype=torch.complex128),
problem["embedding"].to(dtype=torch.complex128),
problem["rhs"].to(dtype=torch.complex128),
problem["matrix"].to(dtype=torch.complex128),
)
def problem_C2D(
param: Mapping[str, float], scaling: bool = True
) -> tuple[torch.Tensor, torch.Tensor]:
"""Create the existing two-dimensional static heat-equation system."""
problem = build_heat_problem(param, scale=scaling)
return (
problem["rhs"].to(dtype=torch.complex128),
problem["matrix"].to(dtype=torch.complex128),
)