-
Notifications
You must be signed in to change notification settings - Fork 23
/
WorkflowAppPBE.cpp
870 lines (680 loc) · 29.1 KB
/
WorkflowAppPBE.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
/* *****************************************************************************
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 "WorkflowAppPBE.h"
#include "MainWindowWorkflowApp.h"
#include "Utils/RelativePathResolver.h"
#include <Stampede3Machine.h>
#include <SC_ToolDialog.h>
#include <SC_RemoteAppTool.h>
#include <RemoteOpenSeesApp.h>
#include <QList>
#include <ShakerMaker.h>
#include <DRM_Model.h>
#include <peerNGA/PEER_NGA_Records.h>
// Qt Widgets
#include <QPushButton>
#include <QScrollArea>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QLabel>
#include <QDebug>
#include <QHBoxLayout>
#include <QProcess>
#include <QCoreApplication>
#include <QDir>
#include <QFile>
#include <RemoteService.h>
#include <Stampede3Machine.h>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QHostInfo>
#include <QSettings>
#include <StandardEarthquakeEDP.h>
#include <QMenu>
#include <QMenuBar>
#include <QAction>
// SimCenter Widgets
#include <Utils/FileOperations.h>
#include <SimCenterComponentSelection.h>
#include <EarthquakeEventSelection.h>
#include <RunLocalWidget.h>
#include <RemoteService.h>
#include <GeneralInformationWidget.h>
#include <SIM_Selection.h>
#include <RandomVariablesContainer.h>
#include <UQ_EngineSelection.h>
#include <FEA_Selection.h>
#include <LocalApplication.h>
#include <RemoteApplication.h>
#include <RemoteJobManager.h>
#include <LossModel/LossModelSelection.h>
#include <PerformanceMethodSelection.h>
#include <RunWidget.h>
#include <InputWidgetBIM.h>
#include <ResultsPelicun.h>
#include <Utils/ProgramOutputDialog.h>
#include <GoogleAnalytics.h>
WorkflowAppPBE *
WorkflowAppPBE::getInstance(RemoteService *theService, QWidget *parent) {
if (theInstance == 0)
theInstance = new WorkflowAppPBE(theService, parent);
return theInstance;
}
WorkflowAppPBE *WorkflowAppPBE::theInstance = 0;
// static pointer for global procedure set in constructor
static WorkflowAppPBE *theApp = nullptr;
// global procedure
int getNumParallelTasks() {
return theApp->getMaxNumParallelTasks();
}
WorkflowAppPBE::WorkflowAppPBE(RemoteService *theService, QWidget *parent)
: WorkflowAppWidget(theService, parent)
{
theApp = this;
ProgramOutputDialog *theDialog=ProgramOutputDialog::getInstance();
theDialog->appendInfoMessage("Initializing application...<br>");
//
// create the various widgets
//
theRVs = RandomVariablesContainer::getInstance();
theGI = GeneralInformationWidget::getInstance();
theSIM_Selection = new SIM_Selection();
theEventSelection = new EarthquakeEventSelection(theRVs, theGI);
theAnalysisSelection = new FEA_Selection();
theUQ_Selection = new UQ_EngineSelection(ForwardOnly);
theDLModelSelection = new LossModelSelection();
thePrfMethodSelection = new PerformanceMethodSelection();
theResults = new ResultsPelicun();
TapisMachine *theMachine = new Stampede3Machine();
localApp = new LocalApplication("sWHALE.py");
remoteApp = new RemoteApplication("sWHALE.py", theService, theMachine);
theJobManager = new RemoteJobManager(theService);
SimCenterWidget *theWidgets[1];
theRunWidget = new RunWidget(localApp, remoteApp, theWidgets, 0);
//
// connect signals and slots
//
connect(localApp,SIGNAL(setupForRun(QString &,QString &)),
this, SLOT(setUpForApplicationRun(QString &,QString &)));
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(localApp,SIGNAL(runComplete()),
this, SLOT(runComplete()));
connect(localApp, SIGNAL(processResults(QString &)),
this, SLOT(processResults(QString &)));
connect(remoteApp,SIGNAL(setupForRun(QString &,QString &)),
this, SLOT(setUpForApplicationRun(QString &,QString &)));
connect(remoteApp,SIGNAL(successfullJobStart()),
this, SLOT(runComplete()));
connect(remoteApp,SIGNAL(successfullJobStart()), theRunWidget, SLOT(hide()));
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(closeDialog()),
this, SLOT(runComplete()));
connect(theJobManager,SIGNAL(processResults(QString &)),
this, SLOT(processResults(QString &)));
connect(theJobManager,SIGNAL(loadFile(QString&)),
this, SLOT(loadFile(QString&)));
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()));
// SY 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, create component selction & add to layout & then add components to cmponentselection
//
QHBoxLayout *horizontalLayout = new QHBoxLayout();
this->setLayout(horizontalLayout);
this->setContentsMargins(0,5,0,5);
horizontalLayout->setContentsMargins(0,0,0,0);
theComponentSelection = new SimCenterComponentSelection();
horizontalLayout->addWidget(theComponentSelection);
theComponentSelection->addComponent(QString("UQ"), theUQ_Selection);
theComponentSelection->addComponent(QString("GI"), theGI);
theComponentSelection->addComponent(QString("SIM"), theSIM_Selection);
theComponentSelection->addComponent(QString("EVT"), theEventSelection);
theComponentSelection->addComponent(QString("FEM"), theAnalysisSelection);
theComponentSelection->addComponent(QString("RV"), theRVs);
theComponentSelection->addComponent(QString("DL"), theDLModelSelection);
theComponentSelection->addComponent(QString("PRF"), thePrfMethodSelection);
theComponentSelection->addComponent(QString("RES"), theResults);
theComponentSelection->displayComponent("DL");
// 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")));
theGI->setDefaultProperties(1,144,360,360,37.426,-122.171);
theGI->setLengthUnit(QString("ft")); // set default length unit to ft
theDialog->appendBlankLine();
theDialog->appendInfoMessage("Welcome to PBE<br>");
// theDialog->hideAfterElapsedTime(1);
// QString test = "inputFileName";
// QString test2 = "/Users/stevan.gavrilovic/Documents/PBE/LocalWorkDir/tmp.SimCenter";
// theResults->processResults(test,test2);
// theResults->processREDiResults(test,test2);
}
WorkflowAppPBE::~WorkflowAppPBE()
{
// hack to get around a sometimes occuring seg fault
// as some classes in destructur remove RV from the RVCOntainer
// which may already have been destructed .. so removing so no destructor calls
//QWidget *newUQ = new QWidget();
//theComponentSelection->swapComponent("RV",newUQ);
}
void
WorkflowAppPBE::setMainWindow(MainWindowWorkflowApp* window) {
this->WorkflowAppWidget::setMainWindow(window);
//
// Add a Tool option to menu bar & add options to it
//
auto menuBar = theMainWindow->menuBar();
QMenu *toolsMenu = new QMenu(tr("&Tools"),menuBar);
SC_ToolDialog *theToolDialog = new SC_ToolDialog(this);
//
// Add Some Tools
//
// peer ground motion selection
PEER_NGA_Records *peerNGA = new PEER_NGA_Records(theGI);
theToolDialog->addTool(peerNGA, "PEER Ground Motion Records");
QAction *showPEER = toolsMenu->addAction("&PEER Ground Motion Records");
connect(showPEER, &QAction::triggered, this,[this, theDialog=theToolDialog, theEmp = peerNGA] {
theDialog->showTool("PEER Ground Motion Records");
});
// shaker maker
ShakerMaker *theShakerMaker = new ShakerMaker();
theToolDialog->addTool(theShakerMaker, "ShakerMaker");
QAction *showShakerMaker = toolsMenu->addAction("&ShakerMaker");
connect(showShakerMaker, &QAction::triggered, this,[this, theDialog=theToolDialog, theEmp = theShakerMaker] {
theDialog->showTool("ShakerMaker");
});
// DRM Model
DRM_Model *theDRM_Model = new DRM_Model();
theToolDialog->addTool(theDRM_Model, "Domain Reduction Method Analysis");
QAction *showDRM_Model = toolsMenu->addAction("&Domain Reduction Method Analysis");
connect(showDRM_Model, &QAction::triggered, this,[this, theDialog=theToolDialog, theEmp = theDRM_Model] {
theDialog->showTool("Domain Reduction Method Analysis");
});
// opensees@designsafe
RemoteOpenSeesApp *theOpenSeesApp = new RemoteOpenSeesApp();
QString testAppName = "simcenter-opensees-frontera";
QString testAppVersion = "1.0.0";
TapisMachine *theMachine = new Stampede3Machine();
SC_RemoteAppTool *theOpenSeesTool = new SC_RemoteAppTool(testAppName,
testAppVersion,
theMachine,
theRemoteService,
theOpenSeesApp,
theToolDialog);
QStringList filesToDownload; filesToDownload << "results.zip";
theOpenSeesTool->setFilesToDownload(filesToDownload, false);
theToolDialog->addTool(theOpenSeesTool, "OpenSees@DesignSafe");
QAction *showOpenSees = toolsMenu->addAction("&OpenSees@DesignSafe");
connect(showOpenSees, &QAction::triggered, this,[this, theDialog=theToolDialog, theEmp = theOpenSeesApp] {
theDialog->showTool("OpenSees@DesignSafe");
});
//
// 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
QString actionText = action->text();
if(actionText.compare("&Examples") == 0)
{
menuAfter = action;
break;
}
else if(actionText.compare("&Help") == 0)
{
menuAfter = action;
break;
}
}
menuBar->insertMenu(menuAfter, toolsMenu);
//menuBar->addMenu(toolsMenu);
}
bool
WorkflowAppPBE::outputToJSON(QJsonObject &jsonObjectTop) {
bool result = true;
//
// get each of the main widgets to output themselves
//
this->outputFilePath = this->getTheMainWindow()->outputFilePath;
qDebug() << "OUTPUT PATH: " << this->outputFilePath;
QJsonObject apps;
QJsonObject jsonObjGenInfo;
result = theGI->outputToJSON(jsonObjGenInfo);
if (result == false)
return result;
jsonObjectTop["GeneralInformation"] = jsonObjGenInfo;
result = theRVs->outputToJSON(jsonObjectTop);
if (result == false)
return result;
// sy - temporary solution..
// built in EDP
QJsonObject appsEDP;
if (theSIM_Selection->getCurrentSIM()=="SurrogateGPBuildingModel") {
appsEDP["Application"] = "SurrogateEDP";
} else {
appsEDP["Application"] = "StandardEarthquakeEDP";
}
QJsonObject dataObj;
appsEDP["ApplicationData"] = dataObj;
apps["EDP"] = appsEDP;
QJsonObject edpData;
jsonObjectTop["EDP"] = edpData;
result = theUQ_Selection->outputAppDataToJSON(apps);
if (result == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - UQ_Selection failed appData";
return result;
}
result = theUQ_Selection->outputToJSON(jsonObjectTop);
if (result == false)
return result;
result = theSIM_Selection->outputAppDataToJSON(apps);
if (result == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - SIM_Selection failed appData";
return result;
}
result = theSIM_Selection->outputToJSON(jsonObjectTop);
if (result == false){
qDebug() << "WorkflowAppPBE::outputToJSON - SIM_Selection";
return result;
}
result = theAnalysisSelection->outputAppDataToJSON(apps);
if (result == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - ANA_Selection failed appData";
return result;
}
result = theAnalysisSelection->outputToJSON(jsonObjectTop);
if (result == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - ANA_Selection failed";
return result;
}
// NOTE: Events treated differently, due to array nature of objects
result = theEventSelection->outputToJSON(jsonObjectTop);
if (result == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - EVENT_Selection failed";
return result;
}
result = theEventSelection->outputAppDataToJSON(apps);
if (result == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - EVENT_Selection failed appData";
return result;
}
result = theRunWidget->outputToJSON(jsonObjectTop);
if (result == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - Run failed";
return result;
}
if (theDLModelSelection->outputToJSON(jsonObjectTop) == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - DL_Selection failed";
return false;
}
if (theDLModelSelection->outputAppDataToJSON(apps) == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - DL_Selection failed appData";
return false;
}
if (thePrfMethodSelection->outputToJSON(jsonObjectTop) == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - PRF_Selection failed";
return false;
}
if (thePrfMethodSelection->outputAppDataToJSON(apps) == false) {
qDebug() << "WorkflowAppPBE::outputToJSON - Prf Method Selection failed appData";
return false;
}
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("AIM.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 true;
}
void
WorkflowAppPBE::processResults(QString &dirPath) {
statusMessage("Backend Done. Processing Results ...");
theResults->processResults(loadedFile, dirPath);
theResults->processREDiResults(loadedFile, dirPath);
theRunWidget->hide();
theComponentSelection->displayComponent("RES");
this->runComplete();
}
void
WorkflowAppPBE::clear(void)
{
theGI->clear();
theSIM_Selection->clear();
}
bool
WorkflowAppPBE::inputFromJSON(QJsonObject &jsonObject)
{
//
// get each of the main widgets to input themselves
//
//qDebug() << "General Info";
if (jsonObject.contains("GeneralInformation")) {
QJsonObject jsonObjGeneralInformation = jsonObject["GeneralInformation"].toObject();
if (theGI->inputFromJSON(jsonObjGeneralInformation) == false) {
this->errorMessage(": ERROR: failed to read GeneralInformation");
}
} else {
this->errorMessage(" ERROR: failed to find GeneralInformation");
return false;
}
//qDebug() << "Applications";
if (jsonObject.contains("Applications")) {
QJsonObject theApplicationObject = jsonObject["Applications"].toObject();
// note: Events is different because the object is an Array
//qDebug() << "Events";
if (theApplicationObject.contains("Events")) {
// QJsonObject theObject = theApplicationObject["Events"].toObject(); it is null object, actually an array
if (theEventSelection->inputAppDataFromJSON(theApplicationObject) == false) {
this->errorMessage(" ERROR: failed to read Event Application");
}
} else {
this->errorMessage(" ERROR: failed to find Event Application");
return false;
}
if (theUQ_Selection->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("PBE: failed to read UQ application");
if (theSIM_Selection->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("PBE: failed to read SIM application");
if (theAnalysisSelection->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("PBE: failed to read FEM application");
if (thePrfMethodSelection->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("PBE: failed to read PRF application");
if (theDLModelSelection->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("PBE: failed to read DL application");
} else
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 (theUQ_Selection->inputFromJSON(jsonObject) == false)
this->errorMessage("PBE: failed to read UQ Method data");
if (theSIM_Selection->inputFromJSON(jsonObject) == false)
this->errorMessage("PBE: failed to read FEM Method data");
if (theAnalysisSelection->inputFromJSON(jsonObject) == false)
this->errorMessage("PBE: failed to read FEM Method data");
if (thePrfMethodSelection->inputFromJSON(jsonObject) == false)
this->errorMessage("PBE: failed to read PRF Method data");
if (theDLModelSelection->inputFromJSON(jsonObject) == false)
this->errorMessage("PBE: failed to read PRF Method data");
/*
if (jsonObject.contains("DL")) {
QJsonObject jsonObjLossModel = jsonObject["DL"].toObject();
if (theDLModelSelection->inputFromJSON(jsonObjLossModel) == false)
this->errorMessage(" ERROR: failed to find Damage and Loss Model");
} else {
this->errorMessage("WARNING: failed to find Damage and Loss Model");
return false;
}
*/
this->runComplete();
return true;
}
void
WorkflowAppPBE::onRunButtonClicked() {
theRunWidget->showLocalApplication();
GoogleAnalytics::ReportLocalRun();
}
void
WorkflowAppPBE::onRemoteRunButtonClicked(){
this->errorMessage("");
bool loggedIn = theRemoteService->isLoggedIn();
if (loggedIn == true) {
theRunWidget->hide();
theRunWidget->showRemoteApplication();
} else {
errorMessage("ERROR - You Need to Login");
}
GoogleAnalytics::ReportDesignSafeRun();
}
void
WorkflowAppPBE::onRemoteGetButtonClicked(){
this->errorMessage("");
bool loggedIn = theRemoteService->isLoggedIn();
if (loggedIn == true) {
theJobManager->hide();
theJobManager->updateJobTable("");
theJobManager->show();
} else {
errorMessage("ERROR - You Need to Login");
}
}
void
WorkflowAppPBE::onExitButtonClicked(){
}
void
WorkflowAppPBE::setUpForApplicationRun(QString &workingDir, QString &subDir) {
errorMessage("");
//
// create temporary directory in working dir
// and copy all files needed to this directory by invoking copyFiles() on app widgets
//
QString tmpDirName = QString("tmp.SimCenter");
qDebug() << "TMP_DIR: " << tmpDirName;
QDir workDir(workingDir);
QString tmpDirectory = workDir.absoluteFilePath(tmpDirName);
QDir destinationDirectory(tmpDirectory);
if(destinationDirectory.exists()) {
if (SCUtils::isSafeToRemoveRecursivily(tmpDirectory))
destinationDirectory.removeRecursively();
else {
QString msg("The Program stopped, it was about to recursivily remove: ");
msg += tmpDirectory;
fatalMessage(msg);
return;
}
}
destinationDirectory.mkpath(tmpDirectory);
QString templateDirectory = destinationDirectory.absoluteFilePath(subDir);
destinationDirectory.mkpath(templateDirectory);
theSIM_Selection->copyFiles(templateDirectory);
theEventSelection->copyFiles(templateDirectory);
theAnalysisSelection->copyFiles(templateDirectory);
theUQ_Selection->copyFiles(templateDirectory);
//
// in new templatedir dir save the UI data into scInput.json file (same result as using saveAs)
// NOTE: we append object workingDir to this which points to template dir
//
QString inputFile = templateDirectory + QDir::separator() + tr("scInput.json");
QFile file(inputFile);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
//errorMessage();
return;
}
//QString outFilePath = tmpDirectory + QDir::separator() + tr("dakota.json");
this->getTheMainWindow()->outputFilePath = inputFile;
QJsonObject json;
if (this->outputToJSON(json) == false) {
this->errorMessage("WorkflowApp - failed in outputToJson");
return;
}
json["runDir"]=tmpDirectory;
json["WorkflowType"]="Building Simulation";
QJsonObject citations;
QString citeFile = templateDirectory + QDir::separator() + tr("please_cite.json");
// QString citeFile = destinationDirectory.filePath("plases_cite.json"); // file getting deleted
this->createCitation(citations, citeFile);
// json.insert("citations",citations);
// if the EDPs are loaded from an external file, then there is no need
// to run the whole simulation
QJsonObject DL_app_data;
DL_app_data = (json["DL"].toObject())["Demands"].toObject();
QString runType;
if (DL_app_data.contains("DemandFilePath")) {
runType = QString("loss_only");
} else {
runType = QString("run");
}
QJsonDocument doc(json);
file.write(doc.toJson());
file.close();
emit setUpForApplicationRunDone(tmpDirectory, inputFile);
}
int
WorkflowAppPBE::loadFile(QString &fileName){
//
// open file
//
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
this->errorMessage(QString("Could Not Open File: ") + fileName);
return -1;
}
//
// place contents of file into json object
//
QString val;
val=file.readAll();
QJsonDocument doc = QJsonDocument::fromJson(val.toUtf8());
QJsonObject jsonObj = doc.object();
// close file
file.close();
// resolve file paths
QFileInfo fileInfo(fileName);
SCUtils::ResolveAbsolutePaths(jsonObj, fileInfo.dir());
//
// clear current and input from new JSON
//
this->clear();
bool result = this->inputFromJSON(jsonObj);
if (result == false)
return -1;
this->runComplete();
loadedFile = fileName;
this->statusMessage("Done Loading File");
return 0;
}
int
WorkflowAppPBE::getMaxNumParallelTasks() {
return theUQ_Selection->getNumParallelTasks();
}
int
WorkflowAppPBE::createCitation(QJsonObject &citation, QString citeFile) {
//
// put PBE citation in
//
QJsonObject citationPBE;
citationPBE.insert("citation",
"Adam Zsarnoczay, Frank McKenna, Michael Gardner, Michael Gardner, Charles Wang, Sang-ri Yi, Aakash Bangalore Satish, Amin Pakzad, & Wael Elhaddad. (2024). NHERI-SimCenter/PBE: Version 4.1.0 (v4.1.0). Zenodo. https://doi.org/10.5281/zenodo.13865401");
citationPBE.insert("description",
"This is the overall tool reference used to indicate the version of the tool.");
QJsonObject citationSimCenterMarker;
citationSimCenterMarker.insert("citation",
"Gregory G. Deierlein, Frank McKenna, Adam Zsarnóczay, Tracy Kijewski-Correa, \
Ahsan Kareem, Wael Elhaddad, Laura Lowes, Matthew J. Schoettler, and Sanjay Govindjee (2020) \
A Cloud-Enabled Application Framework for Simulating Regional-Scale Impacts of Natural \
Hazards on the Built Environment. \
Frontiers in the Built Environment. 6:558706. doi: 10.3389/fbuil.2020.558706");
citationSimCenterMarker.insert("description",
"This marker paper describes the SimCenter application framework, which was designed \
to simulate the impacts of natural hazards on the built environment. It is a \
necessary attribute for publishing work resulting from the use of SimCenter tools, \
software, and datasets.");
QJsonArray citationsArray;
citationsArray.push_back(citationPBE);
citationsArray.push_back(citationSimCenterMarker);
QJsonObject unnecessaryCitationsElement;
unnecessaryCitationsElement.insert("citations", citationsArray);
citation.insert("PBE",unnecessaryCitationsElement);
/*
QString cit("{\"PBE\": { \"citations\": [{\"citation\": \"Adam Zsarnoczay, Frank McKenna, Charles Wang, Stevan Gavrilovic, Michael Gardner, Sang-ri Yi, Aakash Bangalore Satish, & Wael Elhaddad. (2024). NHERI-SimCenter/PBE: Version 3.4.0 (V3.4.0). Zenodo. https://doi.org/10.5281/zenodo.10902085\",\"description\": \"This is the overall tool reference used to indicate the version of the tool.\"},{\"citation\": \"Gregory G. Deierlein, Frank McKenna, Adam Zsarnóczay, Tracy Kijewski-Correa, Ahsan Kareem, Wael Elhaddad, Laura Lowes, Mat J. Schoettler, and Sanjay Govindjee (2020) A Cloud-Enabled Application Framework for Simulating Regional-Scale Impacts of Natural Hazards on the Built Environment. Frontiers in the Built Environment. 6:558706. doi: 10.3389/fbuil.2020.558706\",\"description\": \" This marker paper describes the SimCenter application framework, which was designed to simulate the impacts of natural hazards on the built environment.It is a necessary attribute for publishing work resulting from the use of SimCenter tools, software, and datasets.\"}]}}");
QJsonDocument docC = QJsonDocument::fromJson(cit.toUtf8());
if(!docC.isNull()) {
if(docC.isObject()) {
citation = docC.object();
} else {
qDebug() << "WorkflowdAppEE_UQ citation text is not valid JSON: \n" << cit << endl;
}
}
*/
theSIM_Selection->outputCitation(citation);
theEventSelection->outputCitation(citation);
theAnalysisSelection->outputCitation(citation);
theUQ_Selection->outputCitation(citation);
theDLModelSelection->outputCitation(citation);
thePrfMethodSelection->outputCitation(citation);
//
// write the citation to a file if name of one provided
//
if (!citeFile.isEmpty()) {
QFile file(citeFile);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
errorMessage(QString("writeCitation - could not open file") + citeFile);
progressDialog->hideProgressBar();
return 0;
}
QJsonDocument doc(citation);
file.write(doc.toJson());
file.close();
}
return 0;
}