Skip to content

Commit

Permalink
Merge pull request #118 from JustinBonus/master
Browse files Browse the repository at this point in the history
Stochastic Wave Model EVT
  • Loading branch information
fmckenna committed May 16, 2024
2 parents 6c45418 + 6b7a418 commit 0620630
Show file tree
Hide file tree
Showing 26 changed files with 2,254 additions and 232 deletions.
2 changes: 1 addition & 1 deletion EDP/HydroEDP_Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ HydroEDP_Selection::HydroEDP_Selection(QWidget *parent)
theStackedWidget->addWidget(theStandardStormSurgeEDPs);
theStackedWidget->addWidget(theUserDefinedEDPs);
theStackedWidget->addWidget(theStandardEDPs);
theStackedWidget->setCurrentIndex(4);
theStackedWidget->setCurrentIndex(0);
layout->addWidget(theStackedWidget);
this->setLayout(layout);

Expand Down
112 changes: 69 additions & 43 deletions EVENTS/HydroEventSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#include <WaveDigitalFlume/WaveDigitalFlume.h>
#include <coupledDigitalTwin/CoupledDigitalTwin.h>
#include <MPM/MPM.h>
#include <MPM/SPH.h>
// #include <MPM/SPH.h>
#include <StochasticWaveModel/include/StochasticWaveInput.h>
//*********************************************************************************
// Main Hydro event
//*********************************************************************************
Expand Down Expand Up @@ -94,16 +95,19 @@ HydroEventSelection::HydroEventSelection(RandomVariablesContainer *theRandomVari
eventSelection->addItem(tr("General Event (GeoClaw and OpenFOAM)"));
eventSelection->addItem(tr("Digital Twin (GeoClaw and OpenFOAM)"));
eventSelection->addItem(tr("Digital Twin (OpenFOAM and OpenSees)"));
// eventSelection->addItem(tr("Digital Twin (MPM)"));
eventSelection->addItem(tr("Digital Twin (MPM)"));
// eventSelection->addItem(tr("Digital Twin (SPH)"));
eventSelection->addItem(tr("Stochastic Wave Loading"));


// Datatips for the different event types
eventSelection->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
eventSelection->setItemData(0, "Shallow-Water-Equations -> Finite-Volume-Method (GeoClaw -> OpenFOAM) [Multi-CPU]", Qt::ToolTipRole);
eventSelection->setItemData(1, "Shallow-Water-Equations -> Finite-Volume-Method -> Finite-Element-Analysis (GeoClaw -> OpenFOAM -> OpenSees) [Multi-CPU]", Qt::ToolTipRole);
eventSelection->setItemData(2, "Finite-Volume-Method <-> Finite-Element-Analysis (OpenFOAM <-> OpenSees) [Multi-CPU]", Qt::ToolTipRole);
// eventSelection->setItemData(3, "Material-Point-Method (ClaymoreUW) [Multi-GPU]", Qt::ToolTipRole);
eventSelection->setItemData(3, "Material-Point-Method (ClaymoreUW) [Multi-GPU]", Qt::ToolTipRole);
// eventSelection->setItemData(4, "Smoothed-Particle-Hydrodynamics (DualSPHysics) [CPU-GPU]", Qt::ToolTipRole);
eventSelection->setItemData(4, "Stochastic Wave Loading [CPU]", Qt::ToolTipRole);

theSelectionLayout->addWidget(label);
QSpacerItem *spacer = new QSpacerItem(50,10);
Expand All @@ -121,14 +125,16 @@ HydroEventSelection::HydroEventSelection(RandomVariablesContainer *theRandomVari
theGeoClawOpenFOAM = new GeoClawOpenFOAM(theRandomVariablesContainer);
theWaveDigitalFlume = new WaveDigitalFlume(theRandomVariablesContainer);
theCoupledDigitalTwin = new CoupledDigitalTwin(theRandomVariablesContainer);
// theMPM = new MPM(theRandomVariablesContainer);
theMPM = new MPM(theRandomVariablesContainer);
// theSPH = new SPH(theRandomVariablesContainer);
theSimpleWaves = new StochasticWaveInput(theRandomVariablesContainer);

theStackedWidget->addWidget(theGeoClawOpenFOAM);
theStackedWidget->addWidget(theWaveDigitalFlume);
theStackedWidget->addWidget(theCoupledDigitalTwin);
// theStackedWidget->addWidget(theMPM);
theStackedWidget->addWidget(theMPM);
// theStackedWidget->addWidget(theSPH);
theStackedWidget->addWidget(theSimpleWaves);

// ---

Expand All @@ -140,16 +146,20 @@ HydroEventSelection::HydroEventSelection(RandomVariablesContainer *theRandomVari
// Set the default event to select at boot-up. For now, it is MPM
theStackedWidget->setCurrentIndex(3);
theCurrentEvent = theMPM;

// theStackedWidget->setCurrentIndex(0);
// theCurrentEvent = theGeoClawOpenFOAM;
// theCurrentEvent = theSimpleWaves;

connect(eventSelection, SIGNAL(currentIndexChanged(int)), this, SLOT(eventSelectionChanged(int)));
connect(eventSelection,SIGNAL(currentTextChanged(QString)),this,SLOT(eventSelectionChanged(QString))); // WE-UQ

// QString stringForMPM = "Digital Twin (MPM)";
// int indexForMPM = 3;
// eventSelection->setCurrentIndex(indexForMPM);
// eventSelection->setCurrentIndex(indexForMPM);
// theStackedWidget->setCurrentIndex(indexForMPM);
// theStackedWidget->setCurrentIndex(indexForMPM);
QString stringForMPM = "Digital Twin (MPM)";
int indexForMPM = 3;
eventSelection->setCurrentIndex(indexForMPM);
eventSelection->setCurrentIndex(indexForMPM);
theStackedWidget->setCurrentIndex(indexForMPM);
theStackedWidget->setCurrentIndex(indexForMPM);

// // QString stringForMPM = "Digital Twin (OpenFOAM and OpenSees)";
// // int indexForFOAMySees = 2;
Expand Down Expand Up @@ -200,18 +210,18 @@ void HydroEventSelection::eventSelectionChanged(int arg1)
theCurrentEvent = theCoupledDigitalTwin;
theStackedWidget->setCurrentIndex(2);
}
// else if (arg1 == 3) {
// MPM* theM = dynamic_cast<MPM*>(theMPM);
else if (arg1 == 3) {
MPM* theM = dynamic_cast<MPM*>(theMPM);

// theCurrentEvent = theM->isInitialize() ? theMPM
// : (theM->initialize() ? theMPM : nullptr);
// if (theCurrentEvent == nullptr)
// {
// qDebug() << "ERROR: Hydro-EventSelection failed while attempting to initialize the MPM Event, index: " << arg1;
// return;
// }
// theStackedWidget->setCurrentIndex(3);
// }
theCurrentEvent = theM->isInitialize() ? theMPM
: (theM->initialize() ? theMPM : nullptr);
if (theCurrentEvent == nullptr)
{
qDebug() << "ERROR: Hydro-EventSelection failed while attempting to initialize the MPM Event, index: " << arg1;
return;
}
theStackedWidget->setCurrentIndex(3);
}
// else if (arg1 == 4) {
// SPH* theM = dynamic_cast<SPH*>(theSPH);

Expand All @@ -224,6 +234,10 @@ void HydroEventSelection::eventSelectionChanged(int arg1)
// }
// theStackedWidget->setCurrentIndex(4);
// }
else if (arg1 == 4) {
theCurrentEvent = theSimpleWaves;
theStackedWidget->setCurrentIndex(4);
}
else {
qDebug() << "ERROR: Hydro-EventSelection selection-type unknown: " << arg1;
return;
Expand Down Expand Up @@ -252,16 +266,16 @@ void HydroEventSelection::eventSelectionChanged(const QString &arg1)
theCurrentEvent = theCoupledDigitalTwin;
theStackedWidget->setCurrentIndex(2);
}
// else if(arg1 == "Digital Twin (MPM)" || arg1 == "MPM" || arg1 == "theMPM" || arg1 == "MPMDigitalTwin" || arg1 == "theMPMDigitalTwin" || arg1 == "MPM Digital Twin") {
// MPM* theM = dynamic_cast<MPM*>(theMPM);
// theCurrentEvent = theM->isInitialize() ? theMPM
// : ( theM->initialize() ? theMPM : nullptr );
// if (!theCurrentEvent) {
// qDebug() << "ERROR: Hydro-EventSelection failed while attempting to initialize the MPM Event, label: " << arg1;
// return;
// }
// theStackedWidget->setCurrentIndex(3);
// }
else if(arg1 == "Digital Twin (MPM)" || arg1 == "MPM" || arg1 == "theMPM" || arg1 == "MPMDigitalTwin" || arg1 == "theMPMDigitalTwin" || arg1 == "MPM Digital Twin") {
MPM* theM = dynamic_cast<MPM*>(theMPM);
theCurrentEvent = theM->isInitialize() ? theMPM
: ( theM->initialize() ? theMPM : nullptr );
if (!theCurrentEvent) {
qDebug() << "ERROR: Hydro-EventSelection failed while attempting to initialize the MPM Event, label: " << arg1;
return;
}
theStackedWidget->setCurrentIndex(3);
}
// else if(arg1 == "Digital Twin (SPH)" || arg1 == "SPH" || arg1 == "theSPH" || arg1 == "SPHDigitalTwin" || arg1 == "theSPHDigitalTwin" || arg1 == "SPH Digital Twin") {
// SPH* theM = dynamic_cast<SPH*>(theSPH);
// theCurrentEvent = theM->isInitialize() ? theSPH
Expand All @@ -272,6 +286,10 @@ void HydroEventSelection::eventSelectionChanged(const QString &arg1)
// }
// theStackedWidget->setCurrentIndex(4);
// }
else if(arg1 == "Stochastic Wave Loading" || arg1 == "SimpleWaves") {
theCurrentEvent = theSimpleWaves;
theStackedWidget->setCurrentIndex(4);
}
else {
qDebug() << "ERROR .. HydroEventSelection selection .. type unknown: " << arg1;
}
Expand Down Expand Up @@ -341,12 +359,15 @@ bool HydroEventSelection::inputFromJSON(QJsonObject &jsonObject) {
} else if ((type == QString("CoupledDigitalTwin")) || (type == QString("Digital Twin (OpenFOAM and OpenSees)")) || (type == QString("Digital Twin")) || (type == QString("CoupledDigitalTwin")) || (type == QString("theCoupledDigitalTwin"))){
index = 2;
}
// else if ((type == QString("MPM")) || (type == QString("Material Point Method")) || (type == QString("Digital Twin (MPM)")) || (type == QString("MPMDigitalTwin")) || (type == QString("theMPM")) || (type == QString("MPM Digital Twin")) || (type == QString("MPMDigitalTwin")) || (type == QString("theMPMDigitalTwin"))){
// index = 3;
// }
else if ((type == QString("MPM")) || (type == QString("Material Point Method")) || (type == QString("Digital Twin (MPM)")) || (type == QString("MPMDigitalTwin")) || (type == QString("theMPM")) || (type == QString("MPM Digital Twin")) || (type == QString("MPMDigitalTwin")) || (type == QString("theMPMDigitalTwin"))){
index = 3;
}
// // else if ((type == QString("SPH")) || (type == QString("Smoothed Particled Hydrodynamics")) || (type == QString("Digital Twin (SPH)")) || (type == QString("SPHDigitalTwin")) || (type == QString("theSPH")) || (type == QString("SPH Digital Twin")) || (type == QString("SPHDigitalTwin")) || (type == QString("theSPHDigitalTwin"))){
// index = 4;
// }
else if ((type == QString("SimpleWaves")) || (type == QString("Stochastic Wave Loading"))) {
index = 4;
}
else
{
qDebug() << "HydroEventSelection::inputFromJSON type unknown: " << type;
Expand Down Expand Up @@ -446,18 +467,24 @@ bool HydroEventSelection::inputAppDataFromJSON(QJsonObject &jsonObject)
theCurrentEvent = theCoupledDigitalTwin;
index = 2;
}
// else if (((type == "MPM")
// || (type == "Material Point Method")) || ((type == "General Event (MPM)") || (type == "Digital Twin (MPM)")) || (type == "MPMDigitalTwin") || (type == "theMPM")) {
else if (((type == "MPM")
|| (type == "Material Point Method")) || ((type == "General Event (MPM)") || (type == "Digital Twin (MPM)")) || (type == "MPMDigitalTwin") || (type == "theMPM")) {

// theCurrentEvent = theMPM;
// index = 3;
// }
theCurrentEvent = theMPM;
index = 3;
}
// else if (((type == "SPH")
// || (type == "Smoothed Particle Hydrodynamics")) || ((type == "General Event (SPH)") || (type == "Digital Twin (SPH)")) || (type == "SPHDigitalTwin") || (type == "theSPH")) {

// theCurrentEvent = theSPH;
// index = 4;
// }
else if ((type == "SimpleWaves")
|| (type == "Stochastic Wave Loading")) {

theCurrentEvent = theSimpleWaves;
index = 4;
}
else {
qDebug() << "HydroEventSelection::inputAppDataFromJSON type unknown: " << type;
theCurrentEvent = theMPM;
Expand Down Expand Up @@ -507,9 +534,8 @@ bool HydroEventSelection::copyFiles(QString &destDir) {

bool HydroEventSelection::supportsLocalRun()
{
// return theCurrentEvent->supportsLocalRun();
// if theCurrentEvent
return false;
if (theCurrentEvent != 0)
return theCurrentEvent->supportsLocalRun();
}

bool
Expand Down
1 change: 1 addition & 0 deletions EVENTS/HydroEventSelection.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public slots:
SimCenterAppWidget *theCoupledDigitalTwin;
SimCenterAppWidget *theMPM;
SimCenterAppWidget *theSPH;
SimCenterAppWidget *theSimpleWaves;
SimCenterAppWidget *theExistingEvents;

RandomVariablesContainer *theRandomVariablesContainer;
Expand Down
Empty file removed EVENTS/SimpleWaves/SimpleWaves.cpp
Empty file.
Empty file removed EVENTS/SimpleWaves/SimpleWaves.h
Empty file.
121 changes: 121 additions & 0 deletions EVENTS/StochasticWaveModel/Ex1_WaveKinematics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"""
Plot the wave kinematics (elevation, velocity, acceleration) for linear waves
Different locations, times and superposition of frequencies can be used.
"""
import numpy as np
import matplotlib.pyplot as plt
from welib.tools.figure import defaultRC; defaultRC();
from welib.tools.colors import python_colors
from welib.hydro.wavekin import elevation2d, wavenumber, kinematics2d


fig,axes = plt.subplots(2, 2, sharey=False, figsize=(6.4,4.8)) # (6.4,4.8)
fig.subplots_adjust(left=0.10, right=0.95, top=0.91, bottom=0.09, hspace=0.29, wspace=0.46)
plt.suptitle('Hydro - Wave kinematics')


g = 9.81 # gravity [m/s^2]
h = 30. # water depth [m]

# --- (Top Left) Example for one frequency, one point, multiple times
a = 3 # wave peak amplitude [m]
x, z = 0, 0 # position where kinematics are evaluated [m]
T = 12. # period [s]
eps = 0 # phase shift [rad]
f = 1./T
k = wavenumber(f, h, g)
time = np.arange(0,2*T,T/101)
# Wave kinematics
vel,acc = kinematics2d(a, f, k, eps, h, time, z, x)
eta = elevation2d(a, f, k, eps, time, x)

# Plot
ax=axes[0,0]
ax.plot(time, eta , label=r'Elevation [m]')
ax.plot(time, vel , label=r'Velocity [m/s]')
ax.plot(time, acc , label=r'Acceleration [m$^2$/s]')
ax.set_xlabel('Time [s]')
ax.set_ylabel('Kinematics')
ax.legend(fontsize=8, loc='lower center')
ax.set_title('One frequency')


# --- (Bottom Left) Example for one frequencies, multiple points(1d array), multiple times
a = np.array([3, ]) # wave peak amplitude [m]
T = np.array([12.]) # period [s]
eps = np.array([0 ]) # phase shift [rad]
z = np.linspace(-h, 0, 10) # position where kinematics are evaluated
x = z*0
f = 1./T
k = wavenumber(f, h, g)
time = np.linspace(0,2*T[0]/2,5)
vel,acc = kinematics2d(a, f, k, eps, h, time, z, x)
#eta = elevation2d(a, f, k, eps, time, x)
ax=axes[1,0]
sT = ['0','T/4','T/2','3T/4']
for it,t in enumerate(time[:-1]):
ax.plot(vel[:,it], z, ['-','-','-','--'][it], c=python_colors(it), label='vel, t={:}'.format(sT[it]))
for it,t in enumerate(time[:-1]):
ax.plot(acc[:,it], z, ['o','.','.','.'][it], c=python_colors(it), label='acc, t={:}'.format(sT[it]))
ax.set_ylabel('Water depth [m]')
ax.set_xlabel('Velocity and acceleration')
ax.legend(fontsize=8, ncol=2, loc='lower center')


# --- (Top Right) Example for multiple frequencies, one point, multiple times
a = np.array([1., 3., 5., 0.5]) # wave peak amplitude [m]
T = np.array([20., 12.,9., 3.]) # period [s]
eps = np.array([np.pi/4, 0, np.pi/2, 0]) # phase shift [rad]
x, z = 0, 0 # position where kinematics are evaluated
f = 1./T
k = wavenumber(f, h, g)
time = np.arange(0,2*T[0],T[0]/101)
vel,acc = kinematics2d(a, f, k, eps, h, time, z, x)
eta = elevation2d(a, f, k, eps, time, x)

# Plot
ax=axes[0,1]
ax.plot(time, eta , label=r'Elevation [m]')
ax.plot(time, vel , label=r'Velocity [m/s]')
ax.plot(time, acc , label=r'Acceleration [m$^2$/s]')
ax.set_xlabel('Time [s]')
ax.set_ylabel('Kinematics')
ax.legend(fontsize=8, loc='lower center')
ax.tick_params(direction='in')
ax.set_ylim([-8,8])
ax.set_title('Multiple frequencies')


# --- (Bottom Left) multiple frequencies, multiple points (2d array), multiple times
a = np.array([1., 3., 5., 0.5]) # wave peak amplitude [m]
T = np.array([20., 12.,9., 3.]) # period [s]
eps = np.array([np.pi/4, 0, np.pi/2, 0]) # phase shift [rad]
vz = np.linspace(-h, 0, 2) # position where kinematics are evaluated
vx = np.linspace(-10,10,3)
X,Z = np.meshgrid(vx,vz)
f = 1./T
k = wavenumber(f, h, g)
time = np.arange(0,2*T[0],T[0]/101)
vel,acc = kinematics2d(a, f, k, eps, h, time, Z, X)
#eta = elevation2d(a, f, k, eps, time, x)

# --- Plot
ax=axes[1,1]
for i,z in enumerate(vz):
for j,x in enumerate(vx):
ax.plot(time, vel[i,j,:], ['--','-',':'][j], c=python_colors(i), label='z={:.0f} x={:.0f}'.format(z,x))
ax.set_ylabel('Velocity [m/s]')
ax.set_xlabel('Time [s]')
ax.legend(fontsize=8, loc='lower center', ncol=2)
ax.set_ylim([-8,8])
ax.tick_params(direction='in')



if __name__=="__main__":
plt.show()
if __name__=="__test__":
pass
if __name__=="__export__":
from welib.tools.repo import export_figs_callback
export_figs_callback(__file__)
Loading

0 comments on commit 0620630

Please sign in to comment.