Skip to content

Commit

Permalink
[py] Import OpenGeoSys module properly.
Browse files Browse the repository at this point in the history
Needs to be imported with:

try:
    import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
    import OpenGeoSys

`ogs.callbacks` is needed when imported via pip installed package.
`import OpenGeoSys` else.
  • Loading branch information
bilke committed Dec 19, 2023
1 parent 1a15894 commit b35c143
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from math import cos, cosh, pi, sin, sinh

import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys

a = 2.0 * pi / 3.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from math import pi, sin

import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys

a = 2.0 * pi
b = 2.0 * pi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys

p_flux_in = 1e-2
p_0 = 1e5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys

dirichlet_displacement_top = -0.05
dirichlet_displacement_0 = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys

dirichlet_displacement_0 = 0
neumann_displacement_overburden = -2.125e6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys

dirichlet_displacement_0 = 0
neumann_displacement_overburden = -2.125e6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys

SPHERE_RADIUS = 1.0
START_TIME = 0.0
Expand Down
5 changes: 4 additions & 1 deletion Tests/Data/Mechanics/Linear/PythonPiston/piston_bc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys
from chamber import *


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys


class BCPressure(OpenGeoSys.BoundaryCondition):
Expand Down
6 changes: 5 additions & 1 deletion Tests/Data/Parabolic/T/3D_3BHEs_array/bcs_tespy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import os

import numpy as np
import OpenGeoSys

try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys
from pandas import read_csv
from tespy.networks import load_network

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import os

import numpy as np
import OpenGeoSys

try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys
from pandas import read_csv
from tespy.networks import load_network

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import os

import numpy as np
import OpenGeoSys

try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys
from pandas import read_csv
from tespy.networks import load_network

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import sys

print(sys.version)
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys
from pandas import read_csv

df_server = read_csv(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ Python object `sinx_sinx_source_term` that is created in the last line of the
Python script:

```python
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys

from math import pi, sin

a = 2.0*pi
Expand Down
10 changes: 8 additions & 2 deletions web/content/docs/userguide/features/python_bc.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ The path to the file can be defined in relative or absolute terms. For example:
First, the OpenGeoSys module has to be imported:

```python
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys
```

This module doesn't need to be installed, if OpenGeoSys is compiled with Python support, then it is part of the Python
Expand Down Expand Up @@ -127,7 +130,10 @@ Examples of the application of Python boundary conditions can be found in [this
## Full example of a Python boundary condition

```python
import OpenGeoSys
try:
import ogs.callbacks as OpenGeoSys
except ModuleNotFoundError:
import OpenGeoSys

class BoundaryCondition(OpenGeoSys):

Expand Down

0 comments on commit b35c143

Please sign in to comment.