|
62 | 62 | The Python library, called `romtools`, contains abstract interfaces and functions required for, e.g.,
|
63 | 63 |
|
64 | 64 | - Constructing parameter spaces
|
65 |
| -- Constructing a snapshot data class |
66 | 65 | - Constructing trial spaces
|
67 | 66 | - Constructing and exploiting ROMs via outer loop workflows
|
68 | 67 |
|
|
81 | 80 |
|
82 | 81 | ## Representative abstract base classes
|
83 | 82 |
|
84 |
| -- `AbstractSnapshotData` |
85 |
| - - This class defines the minimum API requirements for a "snapshot_data" class that will be used in the construction |
86 |
| - of a trial space. |
87 |
| -
|
88 | 83 | - `AbstractTrialSpace`
|
89 | 84 | - This class defines the minimum API requirements for a trial space
|
90 | 85 |
|
|
107 | 102 |
|
108 | 103 | In this section, we present some demos/examples showing how to use `romtools` in practice.
|
109 | 104 |
|
110 |
| -## 1. Snapshot data |
111 |
| -
|
112 |
| -The first demo is a simple example of how you could use collect snapshot data for a basic problem.\ |
113 |
| -For the sake of exposition, suppose that we are solving the [1D heat equation](https://aquaulb.github.io/book_solving_pde_mooc/solving_pde_mooc/notebooks/04_PartialDifferentialEquations/04_03_Diffusion_Explicit.html) |
114 |
| -
|
115 |
| -$$\\partial_t T(x,t) = \\alpha \\frac{d^2 T} {dx^2}(x,t) + \\sigma (x,t)$$ |
116 |
| -
|
117 |
| -where $x$ is space, $t$ is time, $T$ is the temperature, $\\alpha$ is the diffusivity, |
118 |
| -and $\\sigma$ is the source term. |
119 |
| -Instead of the numerical solution, for now let's work with the analytical solution: |
120 |
| -
|
121 |
| -$$T(x,t)=e^{-4\\pi^2\\alpha t}\\sin(2\\pi x) + \\frac{2}{\\pi^2\\alpha}(1-e^{-\\pi^2\\alpha t})\\sin(\\pi x)$$ |
122 |
| -
|
123 |
| -
|
124 |
| -```python |
125 |
| -import numpy as np |
126 |
| -
|
127 |
| -def exact_solution(x,t, alpha): |
128 |
| - """ |
129 |
| - Returns the exact solution of the 1D heat equation with |
130 |
| - heat source term sin(np.pi*x) and initial condition sin(2*np.pi*x) |
| 105 | +TBD |
131 | 106 |
|
132 |
| - Parameters |
133 |
| - ---------- |
134 |
| - x : array of floats, grid points coordinates |
135 |
| - t : float, time |
136 |
| -
|
137 |
| - Returns |
138 |
| - ------- |
139 |
| - f : array of floats, exact solution |
140 |
| - """ |
141 |
| - f = (np.exp(-4*np.pi**2*alpha*t) * np.sin(2*np.pi*x) |
142 |
| - + 2.0*(1-np.exp(-np.pi**2*alpha*t)) * np.sin(np.pi*x) |
143 |
| - / (np.pi**2*alpha)) |
144 |
| -
|
145 |
| - return f |
146 |
| -
|
147 |
| -import romtools as rt |
148 |
| -class HeatSnapshots(rt.AbstractSnapshotData): |
149 |
| - def __init__(self, snapshots: list): |
150 |
| - rt.AbstractSnapshotData.__init__(self, var_names=['T']) |
151 |
| - self.snapshots = snapshots |
152 |
| -
|
153 |
| - def getMeshGids(self): |
154 |
| - # this method is a noop for now but needs to be defined |
155 |
| - # since it is an abstract method in the base class |
156 |
| - pass |
157 |
| -
|
158 |
| - def getSnapshotsAsListOfArrays(self): |
159 |
| - return self.snapshots |
160 |
| -
|
161 |
| -if __name__=="__main__": |
162 |
| - numPoints, numTimes = 21, 11 |
163 |
| - x = np.linspace(0., 1., numPoints) |
164 |
| - times = np.linspace(0., 5., numTimes) |
165 |
| -
|
166 |
| - alpha = 0.1 |
167 |
| - data = [exact_solution(x, t, alpha) for t in times] |
168 |
| - snapshots = HeatSnapshots(data) |
169 |
| -``` |
170 | 107 | # License
|
171 | 108 | ```plaintext
|
172 | 109 | .. include:: ../LICENSE
|
|
0 commit comments