Skip to content

Commit

Permalink
Merge branch 'develop' into add-elmer
Browse files Browse the repository at this point in the history
  • Loading branch information
IshaanDesai authored Oct 23, 2024
2 parents 4733959 + 77f190d commit 62a49ed
Show file tree
Hide file tree
Showing 44 changed files with 368 additions and 172 deletions.
11 changes: 11 additions & 0 deletions channel-transport-reaction/chemical-fenics/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
numpy >1, <2
fenicsprecice~=2.0

# Assuming FEniCS from ppa:fenics-packages/fenics was installed https://fenicsproject.org/download/archive/
# Use --system-site-packages in venv
fenics-dijitso==2019.2.0.dev0
fenics-dolfin==2019.2.0.13.dev0
fenics-ffc==2019.2.0.dev0
fenics-fiat==2019.2.0.dev0
fenics-ufl-legacy==2022.3.0

6 changes: 5 additions & 1 deletion channel-transport-reaction/chemical-fenics/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ set -e -u
. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

python3 -m venv --system-site-package .venv
. .venv/bin/activate
pip install -r requirements.txt

python3 chemical-reaction-advection-diffusion.py

close_log
close_log
10 changes: 10 additions & 0 deletions channel-transport-reaction/fluid-fenics/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
numpy >1, <2
fenicsprecice~=2.0

# Assuming FEniCS from ppa:fenics-packages/fenics was installed https://fenicsproject.org/download/archive/
# Use --system-site-packages in venv
fenics-dijitso==2019.2.0.dev0
fenics-dolfin==2019.2.0.13.dev0
fenics-ffc==2019.2.0.dev0
fenics-fiat==2019.2.0.dev0
fenics-ufl-legacy==2022.3.0
5 changes: 5 additions & 0 deletions channel-transport-reaction/fluid-fenics/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ set -e -u
. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

python3 -m venv --system-site-package .venv
. .venv/bin/activate
pip install -r requirements.txt


python3 fluid.py

close_log
2 changes: 1 addition & 1 deletion elastic-tube-1d/fluid-python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
matplotlib
numpy >1, <2
pyprecice~=3.0
pyprecice~=3.0
10 changes: 10 additions & 0 deletions elastic-tube-3d/solid-fenics/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fenicsprecice~=2.0
numpy >1, <2

# Assuming FEniCS from ppa:fenics-packages/fenics was installed https://fenicsproject.org/download/archive/
# Use --system-site-packages in venv
fenics-dijitso==2019.2.0.dev0
fenics-dolfin==2019.2.0.13.dev0
fenics-ffc==2019.2.0.dev0
fenics-fiat==2019.2.0.dev0
fenics-ufl-legacy==2022.3.0
7 changes: 7 additions & 0 deletions elastic-tube-3d/solid-fenics/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/usr/bin/env bash
set -e -u

. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

python3 -m venv --system-site-package .venv
. .venv/bin/activate
pip install -r requirements.txt

python3 solid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fmiprecice
4 changes: 4 additions & 0 deletions flow-around-controlled-moving-cylinder/controller-fmi/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ if [ ! -f PIDcontroller.fmu ]; then
cd ../../
fi

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

fmiprecice ./fmi-settings.json ./precice-settings.json

close_log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyprecice~=3.0
numpy >1, <2
4 changes: 4 additions & 0 deletions flow-around-controlled-moving-cylinder/solid-python/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ set -e -u
. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

python3 solid.py ../precice-config.xml

close_log
10 changes: 10 additions & 0 deletions flow-over-heated-plate/solid-fenics/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fenicsprecice~=2.0
numpy >1, <2

# Assuming FEniCS from ppa:fenics-packages/fenics was installed https://fenicsproject.org/download/archive/
# Use --system-site-packages in venv
fenics-dijitso==2019.2.0.dev0
fenics-dolfin==2019.2.0.13.dev0
fenics-ffc==2019.2.0.dev0
fenics-fiat==2019.2.0.dev0
fenics-ufl-legacy==2022.3.0
4 changes: 4 additions & 0 deletions flow-over-heated-plate/solid-fenics/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ set -e -u
. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

python3 -m venv --system-site-packages .venv
. .venv/bin/activate
pip install -r requirements.txt

python3 solid.py

close_log
8 changes: 4 additions & 4 deletions oscillator-overlap/mass-left-python/run.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
set -e -u

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

python3 -m venv .venv
. .venv/bin/activate
pip install -r ../solver-python/requirements.txt

python3 ../solver-python/oscillator.py Mass-Left

close_log
8 changes: 4 additions & 4 deletions oscillator-overlap/mass-right-python/run.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
set -e -u

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

python3 -m venv .venv
. .venv/bin/activate
pip install -r ../solver-python/requirements.txt

python3 ../solver-python/oscillator.py Mass-Right

close_log
1 change: 1 addition & 0 deletions oscillator/mass-left-fmi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fmiprecice
4 changes: 4 additions & 0 deletions oscillator/mass-left-fmi/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ if [ ! -f ../solver-fmi/Oscillator.fmu ]; then
cd ../../../mass-left-fmi
fi

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

fmiprecice fmi-settings.json precice-settings.json
python3 ../solver-fmi/calculate-error.py ../mass-left-fmi/fmi-settings.json ../mass-left-fmi/precice-settings.json ../mass-right-fmi/fmi-settings.json ../mass-right-fmi/precice-settings.json Mass-Left

Expand Down
3 changes: 0 additions & 3 deletions oscillator/mass-left-python/requirements.txt

This file was deleted.

8 changes: 4 additions & 4 deletions oscillator/mass-left-python/run.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
set -e -u

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

python3 -m venv .venv
. .venv/bin/activate
pip install -r ../solver-python/requirements.txt

python3 ../solver-python/oscillator.py Mass-Left

close_log
1 change: 1 addition & 0 deletions oscillator/mass-right-fmi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fmiprecice
4 changes: 4 additions & 0 deletions oscillator/mass-right-fmi/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ if [ ! -f ../solver-fmi/Oscillator.fmu ]; then
cd ../../../mass-right-fmi
fi

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

fmiprecice fmi-settings.json precice-settings.json
python3 ../solver-fmi/calculate-error.py ../mass-left-fmi/fmi-settings.json ../mass-left-fmi/precice-settings.json ../mass-right-fmi/fmi-settings.json ../mass-right-fmi/precice-settings.json Mass-Right

Expand Down
3 changes: 0 additions & 3 deletions oscillator/mass-right-python/requirements.txt

This file was deleted.

8 changes: 4 additions & 4 deletions oscillator/mass-right-python/run.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
set -e -u

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

python3 -m venv .venv
. .venv/bin/activate
pip install -r ../solver-python/requirements.txt

python3 ../solver-python/oscillator.py Mass-Right

close_log
1 change: 1 addition & 0 deletions oscillator/solver-fmi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fmiprecice
7 changes: 7 additions & 0 deletions oscillator/solver-python/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[mypy]

[mypy-scipy.*]
ignore_missing_imports = True

[mypy-precice.*]
ignore_missing_imports = True
64 changes: 30 additions & 34 deletions oscillator/solver-python/oscillator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from enum import Enum
import csv
import os
from typing import Type

import problemDefinition
import timeSteppers
from timeSteppers import TimeStepper, TimeSteppingSchemes, GeneralizedAlpha, RungeKutta4, RadauIIA


class Participant(Enum):
Expand All @@ -25,20 +26,24 @@ class Participant(Enum):
help="Time stepping scheme being used.",
type=str,
choices=[
s.value for s in timeSteppers.TimeSteppingSchemes],
default=timeSteppers.TimeSteppingSchemes.NEWMARK_BETA.value)
s.value for s in TimeSteppingSchemes],
default=TimeSteppingSchemes.NEWMARK_BETA.value)
args = parser.parse_args()

participant_name = args.participantName

this_mass: Type[problemDefinition.Mass]
other_mass: Type[problemDefinition.Mass]
this_spring: Type[problemDefinition.Spring]
connecting_spring = problemDefinition.SpringMiddle

if participant_name == Participant.MASS_LEFT.value:
write_data_name = 'Force-Left'
read_data_name = 'Force-Right'
mesh_name = 'Mass-Left-Mesh'

this_mass = problemDefinition.MassLeft
this_spring = problemDefinition.SpringLeft
connecting_spring = problemDefinition.SpringMiddle
other_mass = problemDefinition.MassRight

elif participant_name == Participant.MASS_RIGHT.value:
Expand All @@ -48,7 +53,6 @@ class Participant(Enum):

this_mass = problemDefinition.MassRight
this_spring = problemDefinition.SpringRight
connecting_spring = problemDefinition.SpringMiddle
other_mass = problemDefinition.MassLeft

else:
Expand Down Expand Up @@ -89,25 +93,19 @@ class Participant(Enum):
a = a0
t = 0

if args.time_stepping == timeSteppers.TimeSteppingSchemes.GENERALIZED_ALPHA.value:
time_stepper = timeSteppers.GeneralizedAlpha(stiffness=stiffness, mass=mass, alpha_f=0.4, alpha_m=0.2)
elif args.time_stepping == timeSteppers.TimeSteppingSchemes.NEWMARK_BETA.value:
time_stepper = timeSteppers.GeneralizedAlpha(stiffness=stiffness, mass=mass, alpha_f=0.0, alpha_m=0.0)
elif args.time_stepping == timeSteppers.TimeSteppingSchemes.RUNGE_KUTTA_4.value:
ode_system = np.array([
[0, 1], # du
[-stiffness / mass, 0], # dv
])
time_stepper = timeSteppers.RungeKutta4(ode_system=ode_system)
elif args.time_stepping == timeSteppers.TimeSteppingSchemes.Radau_IIA.value:
ode_system = np.array([
[0, 1], # du
[-stiffness / mass, 0], # dv
])
time_stepper = timeSteppers.RadauIIA(ode_system=ode_system)
time_stepper: TimeStepper

if args.time_stepping == TimeSteppingSchemes.GENERALIZED_ALPHA.value:
time_stepper = GeneralizedAlpha(stiffness=stiffness, mass=mass, alpha_f=0.4, alpha_m=0.2)
elif args.time_stepping == TimeSteppingSchemes.NEWMARK_BETA.value:
time_stepper = GeneralizedAlpha(stiffness=stiffness, mass=mass, alpha_f=0.0, alpha_m=0.0)
elif args.time_stepping == TimeSteppingSchemes.RUNGE_KUTTA_4.value:
time_stepper = RungeKutta4(stiffness=stiffness, mass=mass)
elif args.time_stepping == TimeSteppingSchemes.Radau_IIA.value:
time_stepper = RadauIIA(stiffness=stiffness, mass=mass)
else:
raise Exception(
f"Invalid time stepping scheme {args.time_stepping}. Please use one of {[ts.value for ts in timeSteppers.TimeSteppingSchemes]}")
f"Invalid time stepping scheme {args.time_stepping}. Please use one of {[ts.value for ts in TimeSteppingSchemes]}")


positions = []
Expand All @@ -133,34 +131,32 @@ class Participant(Enum):
precice_dt = participant.get_max_time_step_size()
dt = np.min([precice_dt, my_dt])

def f(t): return participant.read_data(mesh_name, read_data_name, vertex_ids, t)[0]
def f(t: float) -> float: return participant.read_data(mesh_name, read_data_name, vertex_ids, t)[0]

# do time step, write data, and advance
# performs adaptive time stepping with dense output; multiple write calls per time step
if args.time_stepping == timeSteppers.TimeSteppingSchemes.Radau_IIA.value:
u_new, v_new, a_new, sol = time_stepper.do_step(u, v, a, f, dt)
t_new = t + dt
u_new, v_new, a_new = time_stepper.do_step(u, v, a, f, dt)

t_new = t + dt

# RadauIIA time stepper provides dense output. Do multiple write calls per time step.
if isinstance(time_stepper, RadauIIA):
# create n samples_per_step of time stepping scheme. Degree of dense
# interpolating function is usually larger 1 and, therefore, we need
# multiple samples per step.
samples_per_step = 5
n_time_steps = len(sol.ts) # number of time steps performed by adaptive time stepper
n_time_steps = len(time_stepper.dense_output.ts) # number of time steps performed by adaptive time stepper
n_pseudo = samples_per_step * n_time_steps # samples_per_step times no. time steps per window.

t_pseudo = 0
for i in range(n_pseudo):
# perform n_pseudo pseudosteps
dt_pseudo = dt / n_pseudo
t_pseudo += dt_pseudo
write_data = [connecting_spring.k * sol(t_pseudo)[0]]
write_data = np.array([connecting_spring.k * time_stepper.dense_output(t_pseudo)[0]])
participant.write_data(mesh_name, write_data_name, vertex_ids, write_data)
participant.advance(dt_pseudo)

else: # simple time stepping without dense output; only a single write call per time step
u_new, v_new, a_new = time_stepper.do_step(u, v, a, f, dt)
t_new = t + dt

write_data = [connecting_spring.k * u_new]
write_data = np.array([connecting_spring.k * u_new])
participant.write_data(mesh_name, write_data_name, vertex_ids, write_data)
participant.advance(dt)

Expand Down
Loading

0 comments on commit 62a49ed

Please sign in to comment.