Skip to content

Commit

Permalink
Renaming of classes + files (and some function) in DAE project (#463)
Browse files Browse the repository at this point in the history
* Rename ProblemDAE.py -> problemDAE.py with renaming of class ptype_dae -> ProblemDAE

* Renaming of the rest..

* Renaming of rest rest - Having consistency feels more comfortable now.
  • Loading branch information
lisawim authored Jul 27, 2024
1 parent 6b323dd commit 97e238e
Show file tree
Hide file tree
Showing 33 changed files with 210 additions and 212 deletions.
4 changes: 2 additions & 2 deletions pySDC/playgrounds/DAE/DiscontinuousTestDAE.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import matplotlib.pyplot as plt

from pySDC.helpers.stats_helper import get_sorted
from pySDC.projects.DAE.sweepers.SemiImplicitDAE import SemiImplicitDAE
from pySDC.projects.DAE.problems.DiscontinuousTestDAE import DiscontinuousTestDAE
from pySDC.projects.DAE.sweepers.semiImplicitDAE import SemiImplicitDAE
from pySDC.projects.DAE.problems.discontinuousTestDAE import DiscontinuousTestDAE
from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI

from pySDC.implementations.hooks.log_solution import LogSolution
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import numpy as np

from pySDC.core.problem import WorkCounter
from pySDC.projects.DAE.misc.ProblemDAE import ptype_dae
from pySDC.projects.DAE.misc.problemDAE import ProblemDAE
from pySDC.core.errors import ProblemError


class LinearTestDAEMinion(ptype_dae):
class LinearTestDAEMinion(ProblemDAE):
r"""
This class implements a linear stiff DAE problem from [1]_ that is given by
Expand Down
10 changes: 5 additions & 5 deletions pySDC/playgrounds/DAE/log_residual_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ class LogResidualComponentsPostIter(Hooks):
Parameters
----------
Hooks : _type_
_description_
Hooks : pySDC.core.hooks.Hooks
Hook base class.
"""

def post_iteration(self, step, level_number):
r"""
Default routine called after each step.
Default routine called after each iteration.
Parameters
----------
step : pySDC.core.Step
step : pySDC.core.step.Step
Current step.
level_number : pySDC.core.level
level_number : pySDC.core.level.Level
Current level number.
"""

Expand Down
4 changes: 2 additions & 2 deletions pySDC/playgrounds/DAE/playground_MPI.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from mpi4py import MPI
from pathlib import Path

from pySDC.projects.DAE.sweepers.SemiImplicitDAEMPI import SemiImplicitDAEMPI
from pySDC.projects.DAE.problems.DiscontinuousTestDAE import DiscontinuousTestDAE
from pySDC.projects.DAE.sweepers.semiImplicitDAEMPI import SemiImplicitDAEMPI
from pySDC.projects.DAE.problems.discontinuousTestDAE import DiscontinuousTestDAE
from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI

from pySDC.playgrounds.DAE.DiscontinuousTestDAE import plotSolution
Expand Down
40 changes: 20 additions & 20 deletions pySDC/projects/DAE/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ To run the scripts contained in this project a standard installation of pySDC sh
Project overview
----------------
- misc
- | ``DAEMesh.py``
- | ``meshDAE.py``
| Datatype for semi-explicit DAE problem classes differential and algebraic parts to have a clean treatment.
- | ``HookClass_DAE.py``
- | ``hooksDAE.py``
| Simple hook classes to read out the approximate solution and error after each time step.
- | ``ProblemDAE.py``
- | ``problemDAE.py``
| Parent class for DAE problems containing the method to solve the (non)-linear system at each node/stage.
- plotting
Expand All @@ -24,19 +24,19 @@ Project overview
| Reads a previously generated data file in `.npy` format and generates a plot on logarithmic y-axis and linear x-axis.
- problems
- | ``DiscontinousTestDAE``
- | ``discontinousTestDAE.py``
| Simple nonlinear semi-explicit index-1 DAE with discrete state event whose event time is known.
- | ``pendulum2D.py``
| Example of the pendulum described by a semi-implicit DAE of index 3.
- | ``problematicF.py``
| Fully-implicit DAE of index 2 which is not solvable for numerically solvable for certain choices of parameter :math:`\eta`.
- | ``simple_DAE.py``
- | ``simpleDAE.py``
| Linear semi-explicit index-2 system of Hessenberg form with known analytical solution.
- | ``synchronous_machine.py``
- | ``synchronousMachine.py``
| Synchronous machine model attached to an infinite bus undergoing torque disturbance test. Results in an index-1 system.
- | ``transistor_amplifier.py``
- | ``transistorAmplifier.py``
| A two transistor amplifier model that results in an index-1 differential algebraic system. A nice example of a system resulting from a common real world situation.
- | ``WSCC9BusSystem.py``
- | ``wscc9BusSystem.py``
| Large power system test case with three reduced model synchronous machines and nine buses. It is also part of the `PinTSimE project <https://github.com/Parallel-in-Time/pySDC/tree/master/pySDC/projects/PinTSimE>`_.
- run
Expand All @@ -52,15 +52,15 @@ Project overview
| Script checking the order of accuracy of MPI sweepers for DAEs of different indices.
- sweepers
- | ``fully_implicit_DAE.py``
- | ``fullyImplicitDAE.py``
| Sweeper that accepts a fully implicit formulation of a system of differential equations and applies to it a modified version of spectral deferred correction
- | ``SemiImplicitDAE.py``
- | ``semiImplicitDAE.py``
| SDC sweeper especially for semi-explicit DAEs. This sweeper is based on ideas mentioned in `Huang et al. (2007) <https://www.sciencedirect.com/science/article/abs/pii/S0021999106003147>`_.
- | ``fully_implicit_DAE_MPI.py``
- | ``fullyImplicitDAEMPI.py``
| MPI version of fully-implicit SDC-DAE sweeper.
- | ``SemiImplicitDAEMPI.py``
- | ``semiImplicitDAEMPI.py``
| MPI version of semi-implicit SDC-DAE sweeper.
- | ``RungeKuttaDAE.py``
- | ``rungeKuttaDAE.py``
| Runge-Kutta methods that can be used to solve DAEs in pySDC in a fully-implicit description.
- tests
Expand Down Expand Up @@ -173,9 +173,9 @@ which is of the general form
.. literalinclude:: ../../../pySDC/projects/DAE/problems/problematicF.py

The imports for the classes ``ptype_dae`` and ``mesh`` are necessary for implementing this problem.
The imports for the classes ``ProblemDAE`` and ``mesh`` are necessary for implementing this problem.

The problem class inherits from the parent ``ptype_dae`` that
The problem class inherits from the parent ``ProblemDAE`` that
has the ``solve_system`` method solving the (non)-linear system to find the root, i.e., updating the values of the unknown derivative. All DAE problem classes should therefore inherit from this class.
For this general type of DAEs the datatype ``mesh`` is used here for both, ``u`` and ``f``.
Further, the constructor requires at least the parameter ``newton_tol``, the tolerance passed to the root solver. It is possible to set a default value (which is set to ``1e-8`` in the example above).
Expand Down Expand Up @@ -208,16 +208,16 @@ We want to implement such an equation and consider the example
0 &= (t + 2) u_1 (t) + (t^2 - 4) u_2 (t) - (t^2 + t - 2) e^t.
This example has two differential variables :math:`u_1`, :math:`u_2` (two differential equations) and one algebraic variable :math:`z` (thus one algebraic equation).
In ``pySDC`` defining a problem class for semi-explicit DAEs is slightly different to those of fully-implicit form. Additionally to ``numpy`` for the example the imports for the classes ``ptype_dae`` and ``DAEMesh`` are needed.
In ``pySDC`` defining a problem class for semi-explicit DAEs is slightly different to those of fully-implicit form. Additionally to ``numpy`` for the example the imports for the classes ``ProblemDAE`` and ``MeshDAE`` are needed.

.. literalinclude:: ../../../pySDC/projects/DAE/problems/simple_DAE.py
.. literalinclude:: ../../../pySDC/projects/DAE/problems/simpleDAE.py

This problem class inherits again from ``ptype_dae``. In contrast, for the solution ``u`` and the right-hand side of the ``f``
a different datatype ``DAEMesh`` is used that allows to separate between the differential variables and the algebraic variables as well
This problem class inherits again from ``ProblemDAE``. In contrast, for the solution ``u`` and the right-hand side of the ``f``
a different datatype ``MeshDAE`` is used that allows to separate between the differential variables and the algebraic variables as well
as for the equations. The tolerance for the root solver is passed with a default value of ``1e-10`` and the number of unknowns is :math:`3`, i.e., ``nvars=3``.
The problem-specific parameter ``a`` has a default value of ``10.0``.

In the ``eval_f`` method the equations and the variables are now separated using the components of the ``DAEMesh``. Recall that ``eval_f`` returns the right-hand side function so that we have a root problem. However, for this semi-explicit DAE this is not the case, but we can change that by rewriting the system to
In the ``eval_f`` method the equations and the variables are now separated using the components of the ``MeshDAE``. Recall that ``eval_f`` returns the right-hand side function so that we have a root problem. However, for this semi-explicit DAE this is not the case, but we can change that by rewriting the system to

.. math::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def post_step(self, step, level_number):
Parameters
----------
step : pySDC.core.Step
step : pySDC.core.step.Step
Current step.
level_number : pySDC.core.level
level_number : pySDC.core.level.Level
Current level number.
"""

Expand Down Expand Up @@ -46,7 +46,7 @@ def post_step(self, step, level_number):

class LogGlobalErrorPostStepAlgebraicVariable(Hooks):
"""
Logs the global error in the algebraic variable
Logs the global error in the algebraic variable after each step.
"""

def post_step(self, step, level_number):
Expand All @@ -55,9 +55,9 @@ def post_step(self, step, level_number):
Parameters
----------
step : pySDC.core.Step
step : pySDC.core.step.Step
Current step.
level_number : pySDC.core.level
level_number : pySDC.core.level.Level
Current level number.
"""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pySDC.implementations.datatype_classes.mesh import MultiComponentMesh


class DAEMesh(MultiComponentMesh):
class MeshDAE(MultiComponentMesh):
r"""
Datatype for DAE problems. The solution of the problem can be splitted in the differential part
and in an algebraic part.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from scipy.optimize import root

from pySDC.core.problem import Problem, WorkCounter
from pySDC.projects.DAE.misc.DAEMesh import DAEMesh
from pySDC.projects.DAE.misc.meshDAE import MeshDAE


class ptype_dae(Problem):
class ProblemDAE(Problem):
r"""
This class implements a generic DAE class and illustrates the interface class for DAE problems.
It ensures that all parameters are passed that are needed by DAE sweepers.
Expand All @@ -25,8 +25,8 @@ class ptype_dae(Problem):
in work_counters['rhs']
"""

dtype_u = DAEMesh
dtype_f = DAEMesh
dtype_u = MeshDAE
dtype_f = MeshDAE

def __init__(self, nvars, newton_tol):
"""Initialization routine"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np

from pySDC.core.problem import WorkCounter
from pySDC.projects.DAE.misc.ProblemDAE import ptype_dae
from pySDC.projects.DAE.misc.problemDAE import ProblemDAE


class DiscontinuousTestDAE(ptype_dae):
class DiscontinuousTestDAE(ProblemDAE):
r"""
This class implements a scalar test discontinuous differential-algebraic equation (DAE) similar to [1]_. The event function
is defined as :math:`h(y):= 2y - 100`. Then, the discontinuous DAE model reads:
Expand Down
4 changes: 2 additions & 2 deletions pySDC/projects/DAE/problems/pendulum2D.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pySDC.projects.DAE.misc.ProblemDAE import ptype_dae
from pySDC.projects.DAE.misc.problemDAE import ProblemDAE


class pendulum_2d(ptype_dae):
class Pendulum2D(ProblemDAE):
r"""
Example implementing the well known 2D pendulum as a first order differential-algebraic equation (DAE) of index 3.
The DAE system is given by the equations
Expand Down
4 changes: 2 additions & 2 deletions pySDC/projects/DAE/problems/problematicF.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np

from pySDC.projects.DAE.misc.ProblemDAE import ptype_dae
from pySDC.projects.DAE.misc.problemDAE import ProblemDAE
from pySDC.implementations.datatype_classes.mesh import mesh


class problematic_f(ptype_dae):
class ProblematicF(ProblemDAE):
r"""
Standard example of a very simple fully implicit index-2 differential algebraic equation (DAE) that is not
numerically solvable for certain choices of the parameter :math:`\eta`. The DAE system is given by
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import numpy as np

from pySDC.projects.DAE.misc.ProblemDAE import ptype_dae
from pySDC.projects.DAE.misc.problemDAE import ProblemDAE


class simple_dae_1(ptype_dae):
class SimpleDAE(ProblemDAE):
r"""
Example implementing a smooth linear index-2 differential-algebraic equation (DAE) with known analytical solution.
The DAE system is given by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import warnings
from scipy.interpolate import interp1d

from pySDC.projects.DAE.misc.ProblemDAE import ptype_dae
from pySDC.implementations.datatype_classes.mesh import mesh
from pySDC.projects.DAE.misc.problemDAE import ProblemDAE


class synchronous_machine_infinite_bus(ptype_dae):
class SynchronousMachineInfiniteBus(ProblemDAE):
r"""
Synchronous machine model from Kundur (equiv. circuits fig. 3.18 in [1]_) attached to infinite bus. The machine can be
represented as two different circuits at the direct-axis and the quadrature-axis. Detailed information can be found in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
from scipy.interpolate import interp1d

from pySDC.projects.DAE.misc.ProblemDAE import ptype_dae
from pySDC.projects.DAE.misc.problemDAE import ProblemDAE
from pySDC.implementations.datatype_classes.mesh import mesh


Expand All @@ -11,7 +11,7 @@ def _transistor(u_in):
return 1e-6 * (np.exp(u_in / 0.026) - 1)


class one_transistor_amplifier(ptype_dae):
class OneTransistorAmplifier(ProblemDAE):
r"""
The one transistor amplifier example from pg. 377 in [1]_. The problem is an index-1 differential-algebraic equation
(DAE) having the equations
Expand Down Expand Up @@ -138,7 +138,7 @@ def u_exact(self, t):
return me


class two_transistor_amplifier(ptype_dae):
class TwoTransistorAmplifier(ProblemDAE):
r"""
The two transistor amplifier example from page 108 in [1]_. The problem is an index-1 differential-algebraic equation
(DAE) having the equations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from pySDC.projects.DAE.misc.ProblemDAE import ptype_dae
from pySDC.projects.DAE.misc.problemDAE import ProblemDAE
from pySDC.core.errors import ParameterError


Expand Down Expand Up @@ -573,7 +573,7 @@ def get_event_Ybus():
# return ppc['Ybus']()


class WSCC9BusSystem(ptype_dae):
class WSCC9BusSystem(ProblemDAE):
r"""
Example implementing the WSCC 9 Bus system [1]_. For this complex model, the equations can be found in [2]_, and
sub-transient and turbine parameters are taken from [3]_. The network data of the system are taken from MATPOWER [4]_.
Expand Down
14 changes: 7 additions & 7 deletions pySDC/projects/DAE/run/accuracy_check_MPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from mpi4py import MPI

from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI
from pySDC.projects.DAE.misc.HookClass_DAE import (
from pySDC.projects.DAE.misc.hooksDAE import (
LogGlobalErrorPostStepDifferentialVariable,
LogGlobalErrorPostStepAlgebraicVariable,
)
Expand Down Expand Up @@ -36,26 +36,26 @@ def run(dt, num_nodes, use_MPI, semi_implicit, residual_type, index_case, initia

if not semi_implicit:
if use_MPI:
from pySDC.projects.DAE.sweepers.fully_implicit_DAE_MPI import fully_implicit_DAE_MPI as sweeper
from pySDC.projects.DAE.sweepers.fullyImplicitDAEMPI import FullyImplicitDAEMPI as sweeper

else:
from pySDC.projects.DAE.sweepers.fully_implicit_DAE import fully_implicit_DAE as sweeper
from pySDC.projects.DAE.sweepers.fullyImplicitDAE import FullyImplicitDAE as sweeper

else:
if use_MPI:
from pySDC.projects.DAE.sweepers.SemiImplicitDAEMPI import SemiImplicitDAEMPI as sweeper
from pySDC.projects.DAE.sweepers.semiImplicitDAEMPI import SemiImplicitDAEMPI as sweeper

else:
from pySDC.projects.DAE.sweepers.SemiImplicitDAE import SemiImplicitDAE as sweeper
from pySDC.projects.DAE.sweepers.semiImplicitDAE import SemiImplicitDAE as sweeper

if index_case == 1:
from pySDC.projects.DAE.problems.DiscontinuousTestDAE import DiscontinuousTestDAE as problem
from pySDC.projects.DAE.problems.discontinuousTestDAE import DiscontinuousTestDAE as problem

t0 = 1.0
Tend = 1.5

elif index_case == 2:
from pySDC.projects.DAE.problems.simple_DAE import simple_dae_1 as problem
from pySDC.projects.DAE.problems.simpleDAE import SimpleDAE as problem

t0 = 0.0
Tend = 0.4
Expand Down
8 changes: 4 additions & 4 deletions pySDC/projects/DAE/run/fully_implicit_dae_playground.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pickle

from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI
from pySDC.projects.DAE.problems.problematicF import problematic_f
from pySDC.projects.DAE.sweepers.fully_implicit_DAE import fully_implicit_DAE
from pySDC.projects.DAE.problems.problematicF import ProblematicF
from pySDC.projects.DAE.sweepers.fullyImplicitDAE import FullyImplicitDAE
from pySDC.implementations.hooks.log_errors import LogGlobalErrorPostStep
from pySDC.helpers.stats_helper import get_sorted
from pySDC.implementations.hooks.log_solution import LogSolution
Expand Down Expand Up @@ -39,9 +39,9 @@ def main():

# Fill description dictionary for easy hierarchy creation
description = dict()
description['problem_class'] = problematic_f
description['problem_class'] = ProblematicF
description['problem_params'] = problem_params
description['sweeper_class'] = fully_implicit_DAE
description['sweeper_class'] = FullyImplicitDAE
description['sweeper_params'] = sweeper_params
description['level_params'] = level_params
description['step_params'] = step_params
Expand Down
Loading

0 comments on commit 97e238e

Please sign in to comment.