Add equation to problem.
(self, equation, condition="True")
| 63 | return np.result_type(*[eqn['dtype'] for eqn in self.equations]) |
| 64 | |
| 65 | def add_equation(self, equation, condition="True"): |
| 66 | """Add equation to problem.""" |
| 67 | logger.debug(f"Adding equation {len(self.eqs)}") |
| 68 | # Split equation into LHS and RHS expressions |
| 69 | if isinstance(equation, str): |
| 70 | # Parse string-valued equations |
| 71 | namespace = dict(self.namespace) |
| 72 | LHS_str, RHS_str = parsing.split_equation(equation) |
| 73 | LHS = eval(LHS_str, namespace) |
| 74 | RHS = eval(RHS_str, namespace) |
| 75 | else: |
| 76 | # Split operator tuples |
| 77 | LHS, RHS = equation |
| 78 | logger.debug(f" LHS: {LHS}") |
| 79 | logger.debug(f" RHS: {RHS}") |
| 80 | logger.debug(f" condition: {condition}") |
| 81 | # Build basic equation dictionary |
| 82 | # Note: domain determined after NCC reinitialization |
| 83 | expr = LHS - RHS |
| 84 | eqn = {'eqn': expr, |
| 85 | 'LHS': LHS, |
| 86 | 'RHS': RHS, |
| 87 | 'condition': condition, |
| 88 | 'tensorsig': expr.tensorsig, |
| 89 | 'dtype': expr.dtype, |
| 90 | 'valid_modes': expr.valid_modes.copy()} |
| 91 | self._check_equation_conditions(eqn) |
| 92 | self._build_matrix_expressions(eqn) |
| 93 | self.equations.append(eqn) |
| 94 | return eqn |
| 95 | |
| 96 | def build_solver(self, *args, **kw): |
| 97 | """Build corresponding solver class.""" |