-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathWorkflowAppHydroUQ.cpp
1427 lines (1171 loc) · 60.5 KB
/
WorkflowAppHydroUQ.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* *****************************************************************************
Copyright (c) 2016-2017, The Regents of the University of California (Regents).
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS
PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*************************************************************************** */
// Written: fmckenna
#include "WorkflowAppHydroUQ.h"
#include <MainWindowWorkflowApp.h>
#include <Utils/FileOperations.h>
#include <QPushButton>
#include <QScrollArea>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QLabel>
#include <QDebug>
#include <QMessageBox>
#include <QFrame>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QStackedWidget>
#include <HydroEventSelection.h>
#include <RunLocalWidget.h>
#include <QProcess>
#include <QCoreApplication>
#include <RemoteService.h>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QHostInfo>
#include <QUuid>
#include <QDir>
#include <QFile>
#include <QSettings>
#include <SimCenterComponentSelection.h>
#include "GeneralInformationWidget.h"
#include <SIM_Selection.h>
#include <RandomVariablesContainer.h>
#include <FEA_Selection.h>
#include <UQ_EngineSelection.h>
#include <UQ_Results.h>
#include <LocalApplication.h>
#include <RemoteApplication.h>
#include <RemoteJobManager.h>
#include <RunWidget.h>
#include <InputWidgetBIM.h>
#include <HydroEDP_Selection.h>
// #include <EDP_Selection.h>
#include "CustomizedItemModel.h"
#include <Utils/ProgramOutputDialog.h>
#include <Utils/RelativePathResolver.h>
#include <GoogleAnalytics.h>
#include <QList>
#include <QMenuBar>
#include <Stampede3Machine.h>
#include <FronteraMachine.h>
#include <SC_ToolDialog.h>
#include <SC_RemoteAppTool.h>
#include <SC_LocalAppTool.h>
#include <SimCenterPreferences.h>
#include <RemoteAppTest.h>
// #include <DakotaResultsSampling.h>
#include <QtGlobal>
// #include <QSvgWidget>
// EVT classes for standalone tool runs
// HydroUQ original EVT classes from Ajay. Used OpenFOAM with GeoCLAW. TODO: Update OpenFOAM / GeoClaw version and build for TapisV3
#if defined(HYDROUQ_GEOCLAW)
#endif
#include <GeoClawOpenFOAM/GeoClawOpenFOAM.h>
#include <WaveDigitalFlume/WaveDigitalFlume.h>
#include <coupledDigitalTwin/CoupledDigitalTwin.h>
#include <MPM/MPM.h>
#include <MPM/SPH.h>
#include <StochasticWaveModel/include/StochasticWaveInput.h>
#include <TaichiEvent/TaichiEvent.h>
#include <Celeris/Celeris.h>
// #include <Celeris/WebGPU.h>
#include <NOAA/DigitalCoast.h>
#include <Utils/FileOperations.h>
// static pointer for global procedure set in constructor
static WorkflowAppHydroUQ *theApp = 0;
// global procedure
int getNumParallelTasks() {
return theApp->getMaxNumParallelTasks();
}
WorkflowAppHydroUQ::WorkflowAppHydroUQ(RemoteService *theService, QWidget *parent)
: WorkflowAppWidget(theService, parent)
{
// set static pointer for global procedure
theApp = this;
//
// create the various widgets
//
theRVs = RandomVariablesContainer::getInstance();
theGI = GeneralInformationWidget::getInstance();
theSIM = new SIM_Selection(true, true);
theEventSelection = new HydroEventSelection(theRVs, theService);
// theEventSelection = new HydroEventSelection(theRVs, theGI);
theAnalysisSelection = new FEA_Selection(true);
theUQ_Selection = new UQ_EngineSelection(ForwardReliabilitySensitivitySurrogate); // ForwardReliabilitySensitivitySurrogate
theEDP_Selection = new HydroEDP_Selection(theRVs);
theResults = theUQ_Selection->getResults();
//
// Set workflow scripts
//
TapisMachine *theMachine = new FronteraMachine();
localApp = new LocalApplication("sWHALE.py");
remoteApp = new RemoteApplication("sWHALE.py", theService, theMachine, nullptr);
//QStringList filesToDownload; filesToDownload << "inputRWHALE.json" << "input_data.zip" << "Results.zip";
theJobManager = new RemoteJobManager(theService);
SimCenterWidget *theWidgets[1];// =0;
theRunWidget = new RunWidget(localApp, remoteApp, theWidgets, 0);
//
// connect signals and slots for (1) local and (2) remote application runs.
//
connect(localApp, &Application::setupForRun, this, [this](QString &workingDir, QString &subDir)
{
currentApp = localApp;
setUpForApplicationRun(workingDir, subDir);
});
connect(localApp, SIGNAL(processResults(QString&)), this, SLOT(processResults(QString&)));
connect(localApp, SIGNAL(runComplete()), this, SLOT(runComplete())); // swao with next?
connect(localApp,SIGNAL(sendErrorMessage(QString)),
this,SLOT(errorMessage(QString)));
connect(localApp,SIGNAL(sendStatusMessage(QString)),
this,SLOT(statusMessage(QString)));
connect(localApp,SIGNAL(sendFatalMessage(QString)),
this,SLOT(fatalMessage(QString)));
connect(remoteApp, &Application::setupForRun, this, [this](QString &workingDir, QString &subDir)
{
currentApp = remoteApp;
setUpForApplicationRun(workingDir, subDir);
});
connect(remoteApp, SIGNAL(successfullJobStart()), theRunWidget, SLOT(hide()));;
connect(remoteApp, SIGNAL(successfullJobStart()), this, SLOT(runComplete()));
connect(remoteApp,SIGNAL(sendErrorMessage(QString)),
this,SLOT(errorMessage(QString)));
connect(remoteApp,SIGNAL(sendStatusMessage(QString)),
this,SLOT(statusMessage(QString)));
connect(remoteApp,SIGNAL(sendFatalMessage(QString)),
this,SLOT(fatalMessage(QString)));
connect(theJobManager, SIGNAL(processResults(QString&)), this, SLOT(processResults(QString&)));
connect(theJobManager, SIGNAL(loadFile(QString&)), this, SLOT(loadFile(QString&)));
connect(theJobManager, SIGNAL(closeDialog()), this, SLOT(runComplete()));
connect(theJobManager,SIGNAL(sendErrorMessage(QString)),
this,SLOT(errorMessage(QString)));
connect(theJobManager,SIGNAL(sendStatusMessage(QString)),
this,SLOT(statusMessage(QString)));
connect(theJobManager,SIGNAL(sendFatalMessage(QString)),
this,SLOT(fatalMessage(QString)));
connect(this, SIGNAL(setUpForApplicationRunDone(QString&, QString &)), theRunWidget, SLOT(setupForRunApplicationDone(QString&, QString &)));
connect(theService, SIGNAL(closeDialog()), this, SLOT(runComplete()));
// KZ connect queryEVT and the reply
connect(theUQ_Selection, SIGNAL(queryEVT()), theEventSelection, SLOT(replyEventType()));
connect(theEventSelection, SIGNAL(typeEVT(QString)), theUQ_Selection, SLOT(setEventType(QString)));
//
// create layout to hold component selection
//
QHBoxLayout *horizontalLayout = new QHBoxLayout();
horizontalLayout->setMargin(0);
this->setLayout(horizontalLayout);
//
// create the component selection & add the components to it
//
theComponentSelection = new SimCenterComponentSelection();
horizontalLayout->addWidget(theComponentSelection);
horizontalLayout->setAlignment(Qt::AlignLeft);
theComponentSelection->addComponent(QString("UQ"), theUQ_Selection);
theComponentSelection->addComponent(QString("GI"), theGI);
theComponentSelection->addComponent(QString("SIM"), theSIM);
theComponentSelection->addComponent(QString("EVT"), theEventSelection);
theComponentSelection->addComponent(QString("FEM"), theAnalysisSelection);
theComponentSelection->addComponent(QString("EDP"), theEDP_Selection); // Using EDP_HydroSelection
theComponentSelection->addComponent(QString("RV"), theRVs);
theComponentSelection->addComponent(QString("RES"), theResults);
theComponentSelection->displayComponent("UQ"); // Initial page on startup
//
// set the defults in the General Info
//
theGI->setDefaultProperties(1,144,360,360,37.8715,-122.2730); // Berkeley, kips and inches
// access a web page which will increment the usage count for this tool
// manager = new QNetworkAccessManager(this);
// connect(manager, SIGNAL(finished(QNetworkReply*)),
// this, SLOT(replyFinished(QNetworkReply*)));
// manager->get(QNetworkRequest(QUrl("http://opensees.berkeley.edu/OpenSees/developer/eeuq/use.php"))); // EE-UQ?
ProgramOutputDialog *theDialog=ProgramOutputDialog::getInstance();
theDialog->appendInfoMessage("Welcome to HydroUQ");
}
// Development mode for tools
constexpr bool DEV_MODE = false; // Set to true for development mode, false for production mode
// Quickly enable/disable tools here for compile-time
constexpr bool USE_CLAYMORE_TOOL = true;
constexpr bool USE_MPM_EVENT_TOOL = true;
constexpr bool USE_TAICHI_TOOL = false;
constexpr bool USE_NOAA_TOOL = true;
constexpr bool USE_CELERIS_TOOL = false;
constexpr bool USE_WEBGPU_TOOL = false;
void
WorkflowAppHydroUQ::setMainWindow(MainWindowWorkflowApp* window) {
this->WorkflowAppWidget::setMainWindow(window); // Call the parent class's function, which sets the main window
auto menuBar = theMainWindow->menuBar();
//
// Add a Tool option to menu bar & add options to it
//
QMenu *toolsMenu = new QMenu(tr("&Tools"), menuBar);
SC_ToolDialog *theToolDialog = new SC_ToolDialog(this);
//
// Add standalone events to tools menu
//
QString appName;
QList<QString> queues;
if constexpr (USE_CLAYMORE_TOOL) {
MPM *miniMPM = new MPM(theRVs);
if (!miniMPM->isInitialize()) {
miniMPM->initialize();
}
if constexpr (DEV_MODE) {
appName = "simcenter-claymore-ls6"; // Lonestar6 dev app for ClaymoreUW MPM, Justin Bonus (bonusj)
queues << "gpu-a100-dev"; // These are later changed to "normal" and "fast" in the tool based on number of cores/processors? Should fix this
} else {
appName = "simcenter-claymore-ls6"; // Lonestar6 public app for ClaymoreUW MPM
queues << "gpu-a100"; // These are later changed to "normal" and "fast" in the tool based on number of cores/processors? Should fix this
}
// QString appVersion = "1.0.0";
// QString machine = "lonestar6"; // "ls6";
QString appVersion = "1.0.1";
QString machine = "ls6"; // "ls6";
SC_RemoteAppTool *miniMPMTool = new SC_RemoteAppTool(appName, appVersion, machine, queues, theRemoteService, miniMPM, theToolDialog); // lonestar6
// delete miniMPM; // Clean up the MPM object after creating the tool?
theToolDialog->addTool(miniMPMTool, "Digital Twin (MPM)");
QAction *showMPM = toolsMenu->addAction("Digital Twin (&MPM)");
connect(showMPM, &QAction::triggered, this,[this, theDialog=theToolDialog, miniM = miniMPMTool] {
theDialog->showTool("Digital Twin (MPM)");
});
// currentTool = miniMPMTool; // TODO: Make this more dynamics / use a better interface
}
if constexpr (USE_TAICHI_TOOL) {
queues.clear(); queues << "rtx" << "rtx-dev"; // These are later changed to "normal" and "fast" in the tool based on number of cores/processors? Should fix this
TaichiEvent *miniTaichi = new TaichiEvent();
appName = "simcenter-taichi-frontera"; // Frontera
QString appVersion = "1.0.0";
QString machine = "frontera";
SC_RemoteAppTool *miniTaichiTool = new SC_RemoteAppTool(appName, appVersion, machine, queues, theRemoteService, miniTaichi, theToolDialog);
theToolDialog->addTool(miniTaichiTool, "General Event (Taichi)");
QAction *showTaichi = toolsMenu->addAction("General Event (&Taichi)");
connect(showTaichi, &QAction::triggered, this,[this, theDialog=theToolDialog, miniT = miniTaichiTool] {
theDialog->showTool("General Event (Taichi)");
});
}
if constexpr (USE_NOAA_TOOL) {
DigitalCoast *miniDC = new DigitalCoast();
QString appNameDC = "noaa-digital-coast-localhost"; // Frontera
QString appVersion = "1.0.0";
QString machine = "localhost";
queues.clear(); queues << "chromium"; // These are later changed to "normal" and "fast" in the tool based on number of cores/processors? Should fix this
SC_RemoteAppTool *miniDCTool = new SC_RemoteAppTool(appNameDC, appVersion, machine, queues, theRemoteService, miniDC, theToolDialog);
theToolDialog->addTool(miniDCTool, "Sea-Level Rise (NOAA Digital Coast)");
QAction *showDC = toolsMenu->addAction("Sea-Level Rise (&NOAA Digital Coast)");
connect(showDC, &QAction::triggered, this,[this, theDialog=theToolDialog, miniD = miniDCTool] {
theDialog->showTool("Sea-Level Rise (NOAA Digital Coast)");
});
}
// if constexpr (USE_CELERIS_TOOL) {
// Celeris *miniCeleris = new Celeris();
// QString appNameCeleris = "simcenter-celeris-frontera"; // Frontera
// QString systemNameCeleris = "frontera";
// QString appVersion = "1.0.0";
// QString machine = "frontera";
// QList<QString> queuesCeleris; queuesCeleris << "rtx" << "rtx-dev"; // These are later changed to "normal" and "fast" in the tool based on number of cores/processors? Should fix this
// SC_RemoteAppTool *miniCelerisTool = new SC_RemoteAppTool(appNameCeleris, appVersion, machine, queuesCeleris, theRemoteService, miniCeleris, theToolDialog);
// theToolDialog->addTool(miniCelerisTool, "Boussinesq Waves (Celeris)");
// QAction *showCeleris = toolsMenu->addAction("Boussinesq Waves (&Celeris)");
// connect(showCeleris, &QAction::triggered, this,[this, theDialog=theToolDialog, miniC = miniCelerisTool] {
// theDialog->showTool("Boussinesq Waves (Celeris)");
// });
// }
// if constexpr (USE_WEBGPU_TOOL) {
// WebGPU *miniWebGPU = new WebGPU();
// QString appNameWebGPU = "WebGPU-1.0.0"; // Frontera
// QString systemNameWebGPU = "frontera";
// QList<QString> queuesWebGPU; queuesWebGPU << "rtx" << "rtx-dev"; // These are later changed to "normal" and "fast" in the tool based on number of cores/processors? Should fix this
// SC_RemoteAppTool *miniWebGPUTool = new SC_RemoteAppTool(appNameWebGPU, queuesWebGPU, theRemoteService, miniWebGPU, theToolDialog);
// theToolDialog->addTool(miniWebGPUTool, "Trouble-Shoot WebGPU (Hardware Acceleration)");
// QAction *showWebGPU = toolsMenu->addAction("Trouble-Shoot &WebGPU (Hardware Acceleration)");
// connect(showWebGPU, &QAction::triggered, this,[this, theDialog=theToolDialog, miniW = miniWebGPUTool] {
// theDialog->showTool("Trouble-Shoot WebGPU (Hardware Acceleration)");
// });
// }
/*
RemoteAppTest *theTest = new RemoteAppTest();
QString appNameTest = "remoteAppTest-1.0.0";
QList<QString> queuesTest; queuesTest << "normal" << "fast";
SC_RemoteAppTool *theTestTool = new SC_RemoteAppTool(appNameTest, queuesTest, theRemoteService, theTest, theToolDialog);
theToolDialog->addTool(theTestTool, "Build and Run MPI Program");
QAction *showTest = toolsMenu->addAction("&Build and Run MPI Program");
connect(showTest, &QAction::triggered, this,[this, theDialog=theToolDialog, theEmp = theTestTool] {
theDialog->showTool("Build and Run MPI Program");
});
*/
//
// Add Tools to menu bar
//
QAction* menuAfter = nullptr;
foreach (QAction *action, menuBar->actions()) {
// First check for an examples menu and if that does not exist put it before the help menu
auto actionText = action->text();
if(actionText.compare("&Examples") == 0)
{
menuAfter = action;
break;
}
else if(actionText.compare("&Help") == 0)
{
menuAfter = action;
break;
}
}
menuBar->insertMenu(menuAfter, toolsMenu);
// TODO - Make this a bit more dynamic, use bibtex, and consider swapping tools in and out automaticlly
// This outputs citations, makes it easy for people to add their own
// to tools and have them grouped for output with the rest
auto prefs = SimCenterPreferences::getInstance();
// defaultWorkDir = QDir(stringLocalWorkDir);
QString localWorkDirString = prefs->getLocalWorkDir();
QDir localWorkDir(localWorkDirString);
if (!localWorkDir.exists()) {
localWorkDir.mkpath(localWorkDirString);
}
QString tmpDirName = QString("tmp.SimCenter");
QString tmpDirectoryString = localWorkDir.absoluteFilePath(tmpDirName);
QDir tmpDirectory(tmpDirectoryString);
if (tmpDirectory.exists()) {
if (SCUtils::isSafeToRemoveRecursivily(tmpDirectoryString))
tmpDirectory.removeRecursively();
else {
QString msg("The Program stopped, it was about to recursivily remove: ");
msg += tmpDirName;
fatalMessage(msg);
return;
}
}
tmpDirectory.mkpath(tmpDirectoryString);
tmpDirectory.mkdir(defaultSubDir);
defaultWorkDir = QDir(tmpDirectoryString);
QString templateDirectoryString = tmpDirectory.absoluteFilePath(defaultSubDir); // "templatedir" by default
QDir templateDirectory(templateDirectoryString);
if (templateDirectory.exists()) {
templateDirectory.removeRecursively();
} else {
templateDirectory.mkpath(templateDirectoryString);
}
// connect(theToolDialog, SIGNAL(toolSelected(QString)), this, SLOT(toolSelected(QString)));
QJsonObject citations;
QString localCiteFile = templateDirectoryString + QDir::separator() + tr("tool_cite.json");
// QString citeFile = destinationDirectory.filePath("please_cite.json"); // file getting deleted
currentTool = nullptr;
this->createToolCitation(citations, localCiteFile);
// }
/**
QString remoteWorkDirString = prefs->getRemoteWorkDir();
QDir remoteWorkDir(remoteWorkDirString);
if (!remoteWorkDir.exists()) {
remoteWorkDir.mkpath(remoteWorkDirString);
}
QString tmpDirName = QString("tmp.SimCenter");
remoteWorkDir.mkdir(tmpDirName); // defaultWorkDirString should start as "tmp.SimCenter"
{
QString tmpDirectoryString = remoteWorkDir.absoluteFilePath(tmpDirName);
QDir tmpDirectory(tmpDirectoryString);
if (tmpDirectory.exists()) {
tmpDirectory.removeRecursively();
} else {
tmpDirectory.mkpath(tmpDirectoryString);
}
tmpDirectory.mkdir(defaultSubDir);
defaultWorkDir = QDir(tmpDirectoryString);
QString templateDirectoryString = tmpDirectory.absoluteFilePath(defaultSubDir); // "templatedir" by default
QDir templateDirectory(templateDirectoryString);
if (templateDirectory.exists()) {
templateDirectory.removeRecursively();
} else {
templateDirectory.mkpath(templateDirectoryString);
}
QJsonObject citations;
QString remoteCiteFile = templateDirectoryString + QDir::separator() + tr("tool_cite.json");
this->createToolCitation(citations, remoteCiteFile);
}
**/
// json.insert("citations",citations);
}
// WorkflowAppHydroUQ::toolSelected(QString toolName) {
// if (currentTool != nullptr) {
// currentTool->hide();
// }
// currentTool = theToolDialog->getTool(toolName);
// currentTool->show();
// }
WorkflowAppHydroUQ::~WorkflowAppHydroUQ()
{
// hack to get around a sometimes occuring seg fault
// as some classes in destructor remove RV from the RVContainer
// which may already have been destructed .. so removing so no destructor called
// QWidget *newUQ = new QWidget();
// theComponentSelection->swapComponent("RV",newUQ);
}
void WorkflowAppHydroUQ::replyFinished(QNetworkReply *pReply)
{
Q_UNUSED(pReply);
return;
}
bool WorkflowAppHydroUQ::canRunLocally()
{
// From old HydroUQ, assumes no local run and only checks event app
// TODO: Look into local run
// QMessageBox msgBox;
// msgBox.setText("The current workflow cannot run locally, please run at DesignSafe instead.");
// msgBox.exec();
// return false;
QList<SimCenterAppWidget*> apps({theEventSelection, theEDP_Selection, theSIM});
foreach(SimCenterAppWidget* app, apps)
{
if(!app->supportsLocalRun())
{
theRunWidget->close();
QMessageBox msgBox;
msgBox.setText("The current workflow cannot run locally, please run at DesignSafe instead.");
msgBox.exec();
return false;
}
}
return true;
}
bool
WorkflowAppHydroUQ::outputToJSON(QJsonObject &jsonObjectTop) {
//
// get each of the main widgets to output themselves
//
bool result = true;
QJsonObject apps;
//
// get each of the main widgets to output themselves to top
// and workflow widgets to output appData to apps
//
// theGI
QJsonObject jsonObjGenInfo;
result = theGI->outputToJSON(jsonObjGenInfo);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theGI->outputToJSON() returned false!"); return result; }
jsonObjectTop["GeneralInformation"] = jsonObjGenInfo;
// theRVs
result = theRVs->outputToJSON(jsonObjectTop);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theRVs->outputToJSON() returned false!"); return result; }
// theEDP
QJsonObject jsonObjectEDP;
result = theEDP_Selection->outputToJSON(jsonObjectEDP);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theEDP_Selection->outputToJSON() returned false!"); return result; }
jsonObjectTop["EDP"] = jsonObjectEDP;
QJsonObject appsEDP;
result = theEDP_Selection->outputAppDataToJSON(appsEDP);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theEDP_Selection->outputAppDataToJSON() returned false!"); return result; }
apps["EDP"]=appsEDP;
// theUQ
result = theUQ_Selection->outputAppDataToJSON(apps);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theUQ_Selection->outputAppDataToJSON() returned false!"); return result; }
result = theUQ_Selection->outputToJSON(jsonObjectTop);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theUQ_Selection->outputToJSON() returned false!"); return result; }
// theSIM
result = theSIM->outputAppDataToJSON(apps);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theSIM->outputAppDataToJSON() returned false!"); return result; }
result = theSIM->outputToJSON(jsonObjectTop);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theSIM->outputToJSON() returned false!"); return result; }
// theAnalysis
result = theAnalysisSelection->outputAppDataToJSON(apps);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theAnalysisSelection->outputAppDataToJSON() returned false!"); return result; }
result = theAnalysisSelection->outputToJSON(jsonObjectTop);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theAnalysisSelection->outputToJSON() returned false!"); return result; }
// theEventSelection
// NOTE: Events treated differently, due to array nature of objects
result = theEventSelection->outputToJSON(jsonObjectTop);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theEventSelection->outputToJSON() returned false!"); return result; }
result = theEventSelection->outputAppDataToJSON(apps);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theEventSelection->outputAppDataToJSON() returned false!"); return result; }
// theRunWidget
result = theRunWidget->outputToJSON(jsonObjectTop);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theRunWidget->outputToJSON() returned false!"); return result; }
// theResults
// sy - to save results
result = theResults->outputToJSON(jsonObjectTop);
if (result == false)
{ this->errorMessage("ERROR: WorkflowAppHydroUQ::outputToJSON() theResults->outputToJSON() returned false!"); return result; }
jsonObjectTop["Applications"]=apps;
QJsonObject defaultValues;
defaultValues["workflowInput"]=QString("scInput.json");
defaultValues["filenameAIM"]=QString("AIM.json");
defaultValues["filenameEVENT"] = QString("EVENT.json");
defaultValues["filenameSAM"]= QString("SAM.json");
defaultValues["filenameEDP"]= QString("EDP.json");
defaultValues["filenameSIM"]= QString("SIM.json");
defaultValues["driverFile"]= QString("driver");
defaultValues["filenameDL"]= QString("BIM.json");
defaultValues["workflowOutput"]= QString("EDP.json");
QJsonArray rvFiles, edpFiles;
rvFiles.append(QString("AIM.json"));
rvFiles.append(QString("SAM.json"));
rvFiles.append(QString("EVENT.json"));
rvFiles.append(QString("SIM.json"));
edpFiles.append(QString("EDP.json"));
defaultValues["rvFiles"]= rvFiles;
defaultValues["edpFiles"]=edpFiles;
jsonObjectTop["DefaultValues"]=defaultValues;
return result;
}
void
WorkflowAppHydroUQ::processResults(QString &dirName)
{
//
// get results widget for currently selected UQ option
//
theResults = theUQ_Selection->getResults();
if (theResults == NULL) {
this->errorMessage("FATAL - UQ option selected not returning results widget");
return;
}
//
// connect signals for results widget
//
// connect(theResults,SIGNAL(sendStatusMessage(QString)), this,SLOT(statusMessage(QString)));
// connect(theResults,SIGNAL(sendErrorMessage(QString)), this,SLOT(errorMessage(QString)));
//
// swap current results with existing one in selection & disconnect signals
//
QWidget *oldResults = theComponentSelection->swapComponent(QString("RES"), theResults);
if (oldResults != NULL) {
this->statusMessage("WorkflowAppHydroUQ::processResults() - Deleting oldResults");
delete oldResults;
}
// if (oldResults != NULL && oldResults != theResults) {;
// this->errorMessage("WorkflowAppHydroUQ::processResults() - Deleting oldResults");
// // disconnect(oldResults,SIGNAL(sendErrorMessage(QString)), this,SLOT(errorMessage(QString)));
// // disconnect(oldResults,SIGNAL(sendFatalMessage(QString)), this,SLOT(fatalMessage(QString)));
// delete oldResults;
// }
//
// process results
//
theResults->processResults(dirName);
// theRunWidget->hide(); // Hide the run widget after the results are processed, as the results are now displayed
theComponentSelection->displayComponent("RES");
}
void
WorkflowAppHydroUQ::clear(void)
{
// EE-UQ
theGI->clear();
theSIM->clear();
// /*******************************************
// Needed?
theRVs->clear();
theUQ_Selection->clear();
theEventSelection->clear();
theAnalysisSelection->clear();
// Function theUQ_Selection->getResults returns UQ simulation results to the theResults from a "Workflow" perspective. I.e., it will host the results after retrieving the data from a completed workflow simulation on a remote HPC system (or local if that is implemented). It won't contain the results from an "individual" app/tool perspective, i.e. if just EVT is ran to perform a normal CFD simulation, the results will be in the EVT app in its own results widget. Depending on the EVT implementation, this widget can be theResults if it is "passed" to it. (JB)
theResults=theUQ_Selection->getResults();
if (theResults == NULL) {
this->errorMessage("FATAL - UQ option selected not returning results widget");
return;
}
//
// swap current results with existing one in selection & disconnect signals
//
QWidget *oldResults = theComponentSelection->swapComponent(QString("RES"), theResults); // The "swap" takes care of deleting the oldResults widget that was swapped out from theComponentSelection. theResults is the new widget that was swapped in and is now owned by theComponentSelection. oldResults is the old widget that was swapped out and is now owned by this function so it needs to be deleted, though smart pointers could take care of this if we refactor the code to use them.
if (oldResults != NULL && oldResults != theResults) {
this->statusMessage("WorkflowAppHydroUQ::clear() - Deleting oldResults");
delete oldResults;
}
//
// ready to process results
//
// *******************************************/
}
bool
WorkflowAppHydroUQ::inputFromJSON(QJsonObject &jsonObject)
{
//
// get each of the main widgets to input themselves
//
if (jsonObject.contains("GeneralInformation")) {
QJsonObject jsonObjGeneralInformation = jsonObject["GeneralInformation"].toObject();
if (theGI->inputFromJSON(jsonObjGeneralInformation) == false) {
this->errorMessage("Hydro_UQ: failed to read GeneralInformation");
}
} else {
this->errorMessage("Hydro_UQ: failed to find GeneralInformation");
return false;
}
if (jsonObject.contains("Applications")) {
QJsonObject theApplicationObject = jsonObject["Applications"].toObject();
// note: Events is different because the object is an Array
if (theApplicationObject.contains("Events")) {
// QJsonObject theObject = theApplicationObject["Events"].toObject(); it is null object, actually an array
if (theEventSelection->inputAppDataFromJSON(theApplicationObject) == false) {
this->errorMessage("Hydro_UQ: found Events in Applications but failed to read");
}
} else {
this->errorMessage("Hydro_UQ: failed to find Events in Applications");
return false;
}
if (theUQ_Selection->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("Hydro_UQ: failed to read UQ application");
if (theSIM->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("Hydro_UQ: failed to read SIM application");
if (theAnalysisSelection->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("Hydro_UQ: failed to read FEM application");
if (theApplicationObject.contains("EDP")) {
QJsonObject theObject = theApplicationObject["EDP"].toObject();
if (theEDP_Selection->inputAppDataFromJSON(theObject) == false) {
this->errorMessage("Hydro_UQ: failed to read EDP application");
}
} else {
this->errorMessage("Hydro_UQ: failed to find EDP application");
return false;
}
} else {
this->errorMessage("WorkflowAppHydroUQ::inputFromJSON failed to find Applications in JSON");
return false;
}
/*
** Note to me - RVs and Events treated differently as both use arrays .. rethink API!
*/
theEventSelection->inputFromJSON(jsonObject);
theRVs->inputFromJSON(jsonObject);
theRunWidget->inputFromJSON(jsonObject);
if (jsonObject.contains("EDP")) {
QJsonObject edpObj = jsonObject["EDP"].toObject();
if (theEDP_Selection->inputFromJSON(edpObj) == false)
this->errorMessage("Hydro_UQ: failed to read EDP data");
} else {
this->errorMessage("Hydro_UQ: failed to find EDP data");
return false;
}
if (theUQ_Selection->inputFromJSON(jsonObject) == false) {
this->errorMessage("Hydro_UQ: failed to read UQ Method data");
}
if (theSIM->inputFromJSON(jsonObject) == false) {
this->errorMessage("Hydro_UQ: failed to read SIM Modeling Method data");
}
if (theAnalysisSelection->inputFromJSON(jsonObject) == false) {
this->errorMessage("Hydro_UQ: failed to read FEM Analysis Method data");
}
// Below allows users to load in existing results from a previous run / example. Appear in RES tab.
// sy - to display results
auto *theNewResults = theUQ_Selection->getResults();
if (theNewResults->inputFromJSON(jsonObject) == false) {
this->errorMessage("Hydro_UQ: failed to read RES Method data");
}
theResults->setResultWidget(theNewResults);
this->statusMessage("WorkflowAppHydroUQ::inputFromJSON - Done Loading File");
return true;
// I guess below is incorrect? Above was from WE-UQ's refactor Sep 14 and May 2, 2022
// ---
// if (theUQ_Selection->inputFromJSON(jsonObject) == false)
// this->errorMessage("Hydro_UQ: failed to read UQ Method data");
// if (theAnalysisSelection->inputFromJSON(jsonObject) == false)
// this->errorMessage("Hydro_UQ: failed to read FEM Method data");
// if (theSIM->inputFromJSON(jsonObject) == false)
// this->errorMessage("Hydro_UQ: failed to read SIM Method data");
// this->statusMessage("WorkflowAppHydroUQ::inputFromJSON - Done Loading File");
// return true;
// ---
}
void
WorkflowAppHydroUQ::onRunButtonClicked() {
emit errorMessage("");
if (!canRunLocally())
emit errorMessage("HydroUQ cannot be run locally yet. Please run remotely on DesignSafe.");
else
{
theRunWidget->hide();
theRunWidget->setMinimumWidth(this->width()*0.5);
theRunWidget->showLocalApplication();
GoogleAnalytics::ReportLocalRun();
}
}
void
WorkflowAppHydroUQ::onRemoteRunButtonClicked(){
emit errorMessage("");
bool loggedIn = theRemoteService->isLoggedIn();
if (loggedIn == true) {
theRunWidget->hide();
theRunWidget->setMinimumWidth(this->width()*0.5);
theRunWidget->showRemoteApplication();
} else {
errorMessage("ERROR - You Need to Login to DesignSafe to Run HydroUQ Remotely.");
}
GoogleAnalytics::ReportDesignSafeRun();
}
void
WorkflowAppHydroUQ::onRemoteGetButtonClicked(){
emit errorMessage("");
bool loggedIn = theRemoteService->isLoggedIn();
if (loggedIn == true) {
theJobManager->hide();
theJobManager->updateJobTable("");
theJobManager->show();
} else {
errorMessage("ERROR - You Need to Login to DesignSafe to Get HydroUQ Results From Remote Storage.");
}
}
void
WorkflowAppHydroUQ::onExitButtonClicked(){
}
void
WorkflowAppHydroUQ::setUpForApplicationRun(QString &workingDir, QString &subDir) {
// errorMessage(""); // I dont think we need this? Will clutter up any error counting tool. - JB
//
// create temporary directory in working dir
// and copy all files needed to this directory by invoking copyFiles() on app widgets
//
// designsafe will need a unique name
/* *********************************************
will let ParallelApplication rename dir
QUuid uniqueName = QUuid::createUuid();
QString strUnique = uniqueName.toString();
strUnique = strUnique.mid(1,36);
QString tmpDirName = QString("tmp.SimCenter") + strUnique;
*********************************************** */
QString tmpDirName = QString("tmp.SimCenter");
qDebug() << "TMP_DIR: " << tmpDirName;
QDir workDir(workingDir);
QString tmpDirectory = workDir.absoluteFilePath(tmpDirName);
qDebug() << "tmpDirectory: " << tmpDirectory;
QDir destinationDirectory(tmpDirectory);
if (destinationDirectory.exists()) {
qDebug() << "Destination Directory Exists, trying to remove it";
if (SCUtils::isSafeToRemoveRecursivily(tmpDirectory)) {
qDebug() << "Removing Destination Directory Recursivily";
destinationDirectory.removeRecursively();
}
else {
QString msg("The Program stopped, it was about to recursivily remove: ");
msg.append(tmpDirectory);
fatalMessage(msg);
}
}
// Used in other places temporarily,
// e.g. citation output for Tools to avoid passing parameters
defaultWorkDir = destinationDirectory;
defaultSubDir = subDir;
qDebug() << "defaultWorkDir: " << defaultWorkDir;
qDebug() << "defaultSubDir: " << defaultSubDir;
destinationDirectory.mkpath(tmpDirectory);
QString templateDirectory = destinationDirectory.absoluteFilePath(subDir);
qDebug() << "templateDirectory: " << templateDirectory;
destinationDirectory.mkpath(templateDirectory);
// copyPath(path, tmpDirectory, false);
if (theSIM->copyFiles(templateDirectory) == false) {
errorMessage("Workflow Failed to start as SIM failed in copyFiles");
return;
} else {
qDebug() << "SIM copyFiles() successful";
}
if (theEventSelection->copyFiles(templateDirectory) == false) {
errorMessage("Workflow Failed to start as EVENT failed in copyFiles");
return;
} else {
qDebug() << "EVENT copyFiles() successful";
}
if (theAnalysisSelection->copyFiles(templateDirectory) == false) {
errorMessage("Workflow Failed to start as FEM failed in copyFiles");
return;
} else {