-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelastic_wave_equation_abc_linear.py
49 lines (36 loc) · 1.85 KB
/
elastic_wave_equation_abc_linear.py
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
"""This file contains a model setup which only assembles the Jacobian once.
The default behavior when running porepy models is that the Jacobian is assembled at
every time step. This is not necessary for linear problems, where the Jacobian doesn't
change between time steps. Hence, this is a model class setup for the purpose of running
linear models:
The model inherits from the dynamic momentum balance with ABC2. A "custom" solution
strategy mixin is defined. This solution strategy mixin checks the time step to see if
only the residual, or both the residual and Jacobian should be assembled. In the case of
time_index > 1, the residual is constructed and the Jacobian is kept the same.
Note that the Jacobian must be constant throughout the simulation (linear problem) for
this simplification to be done.
"""
from __future__ import annotations
import logging
import time
from . import DynamicMomentumBalanceABC2
logger = logging.getLogger(__name__)
class SolutionStrategyAssembleLinearSystemOnce:
def assemble_linear_system(self) -> None:
"""Assemble the linearized system and store it in :attr:`linear_system`.
The linear system is defined by the current state of the model.
"""
t_0 = time.time()
if self.time_manager.time_index <= 1:
self.linear_system = self.equation_system.assemble()
self.linear_system_jacobian = self.linear_system[0]
self.linear_system_residual = self.linear_system[1]
else:
self.linear_system_residual = self.equation_system.assemble(
evaluate_jacobian=False
)
logger.debug(f"\nAssembled linear system in {time.time() - t_0:.2e} seconds.")
class DynamicMomentumBalanceABC2Linear(
SolutionStrategyAssembleLinearSystemOnce,
DynamicMomentumBalanceABC2,
): ...