-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathWorkflowAppEE_UQ.cpp
802 lines (635 loc) · 25.6 KB
/
WorkflowAppEE_UQ.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
/* *****************************************************************************
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 "WorkflowAppEE_UQ.h"
#include <MainWindowWorkflowApp.h>
#include <QPushButton>
#include <QScrollArea>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QLabel>
#include <QDebug>
#include <QHBoxLayout>
#include <QStackedWidget>
#include <EarthquakeEventSelection.h>
#include <EDP_EarthquakeSelection.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 <QUuid>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QHostInfo>
#include <QMenuBar>
#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 <Stampede3Machine.h>
#include <RemoteApplication.h>
#include <RemoteJobManager.h>
#include <RunWidget.h>
#include <InputWidgetBIM.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>
#include "CustomizedItemModel.h"
#include <Utils/ProgramOutputDialog.h>
#include <Utils/RelativePathResolver.h>
#include <GoogleAnalytics.h>
#include <Utils/FileOperations.h>
// static pointer for global procedure set in constructor
static WorkflowAppEE_UQ *theApp = 0;
// global procedure
int getNumParallelTasks() {
return theApp->getMaxNumParallelTasks();
}
WorkflowAppEE_UQ::WorkflowAppEE_UQ(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(false, true);
theEventSelection = new EarthquakeEventSelection(theRVs, theGI);
theAnalysisSelection = new FEA_Selection(true);
theUQ_Selection = new UQ_EngineSelection(ForwardReliabilitySensitivitySurrogate);
theEDP_Selection = new EDP_EarthquakeSelection(theRVs);
theResults = theUQ_Selection->getResults();
TapisMachine *theMachine = new Stampede3Machine();
localApp = new LocalApplication("sWHALE.py");
remoteApp = new RemoteApplication("sWHALE.py", theService, theMachine);
theJobManager = new RemoteJobManager(theService);
SimCenterWidget *theWidgets[1];// =0;
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(processResults(QString&)),
this, SLOT(processResults(QString&)));
connect(localApp,SIGNAL(runComplete()),
this, SLOT(runComplete()));
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,SIGNAL(setupForRun(QString &,QString &)),
this, SLOT(setUpForApplicationRun(QString &,QString &)));
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 selectio
//
QHBoxLayout *horizontalLayout = new QHBoxLayout();
this->setLayout(horizontalLayout);
this->setContentsMargins(0,5,0,5);
horizontalLayout->setMargin(0);
//
// create the component selection & add the components to it
//
theComponentSelection = new SimCenterComponentSelection();
horizontalLayout->addWidget(theComponentSelection);
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);
theComponentSelection->addComponent(QString("RV"), theRVs);
theComponentSelection->addComponent(QString("RES"), theResults);
theComponentSelection->displayComponent("UQ");
//
// set the defults in the General Info
//
theGI->setDefaultProperties(1,144,360,360,37.8715,-122.2730);
ProgramOutputDialog *theDialog=ProgramOutputDialog::getInstance();
theDialog->appendInfoMessage("Welcome to EE-UQ");
}
void
WorkflowAppEE_UQ::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);
theOpenSeesTool->setAppNameReport(QString("OpenSeesAtDesignSafe"));
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);
}
WorkflowAppEE_UQ::~WorkflowAppEE_UQ()
{
// 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 called
// QWidget *newUQ = new QWidget();
// theComponentSelection->swapComponent("RV",newUQ);
}
void WorkflowAppEE_UQ::replyFinished(QNetworkReply *pReply)
{
return;
}
bool
WorkflowAppEE_UQ::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 outut appData to apps
//
// theGI
QJsonObject jsonObjGenInfo;
result = theGI->outputToJSON(jsonObjGenInfo);
if (result == false)
return result;
jsonObjectTop["GeneralInformation"] = jsonObjGenInfo;
// theRVs
result = theRVs->outputToJSON(jsonObjectTop);
if (result == false)
return result;
// theEDP
QJsonObject jsonObjectEDP;
result = theEDP_Selection->outputToJSON(jsonObjectEDP);
if (result == false)
return result;
jsonObjectTop["EDP"] = jsonObjectEDP;
QJsonObject appsEDP;
result = theEDP_Selection->outputAppDataToJSON(appsEDP);
if (result == false)
return result;
apps["EDP"]=appsEDP;
// theUQ
result = theUQ_Selection->outputAppDataToJSON(apps);
if (result == false)
return result;
result = theUQ_Selection->outputToJSON(jsonObjectTop);
if (result == false)
return result;
// theSIM
result = theSIM->outputAppDataToJSON(apps);
if (result == false)
return result;
result = theSIM->outputToJSON(jsonObjectTop);
if (result == false)
return result;
// theAnalysis
result = theAnalysisSelection->outputAppDataToJSON(apps);
if (result == false)
return result;
result = theAnalysisSelection->outputToJSON(jsonObjectTop);
if (result == false)
return result;
// NOTE: Events treated differently, due to array nature of objects
result = theEventSelection->outputToJSON(jsonObjectTop);
if (result == false)
return result;
result = theEventSelection->outputAppDataToJSON(apps);
if (result == false)
return result;
result = theRunWidget->outputToJSON(jsonObjectTop);
if (result == false)
return result;
// sy - to save results
result = theResults->outputToJSON(jsonObjectTop);
if (result == 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
WorkflowAppEE_UQ::processResults(QString &dirName){
//
// get results widget fr currently selected UQ option
//
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);
if (oldResults != NULL) {
delete oldResults;
}
//
// process results
//
theResults->processResults(dirName);
// theRunWidget->hide();
theComponentSelection->displayComponent("RES");
}
void
WorkflowAppEE_UQ::clear(void)
{
theGI->clear();
theSIM->clear();
}
bool
WorkflowAppEE_UQ::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("EE_UQ: failed to read GeneralInformation");
}
} else {
this->errorMessage("EE_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("EE_UQ: failed to read Event Application");
}
} else {
this->errorMessage("EE_UQ: failed to find Event Application");
return false;
}
if (theUQ_Selection->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("EE_UQ: failed to read UQ application");
if (theSIM->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("EE_UQ: failed to read SIM application");
if (theAnalysisSelection->inputAppDataFromJSON(theApplicationObject) == false)
this->errorMessage("EE_UQ: failed to read FEM application");
if (theApplicationObject.contains("EDP")) {
QJsonObject theObject = theApplicationObject["EDP"].toObject();
if (theEDP_Selection->inputAppDataFromJSON(theObject) == false) {
this->errorMessage("EE_UQ: failed to read EDP application");
}
} else {
this->errorMessage("EE_UQ: failed to find EDP application");
return false;
}
} 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 (jsonObject.contains("EDP")) {
QJsonObject edpObj = jsonObject["EDP"].toObject();
if (theEDP_Selection->inputFromJSON(edpObj) == false)
this->errorMessage("EE_UQ: failed to read EDP data");
} else {
this->errorMessage("EE_UQ: failed to find EDP data");
return false;
}
if (theUQ_Selection->inputFromJSON(jsonObject) == false)
this->errorMessage("EE_UQ: failed to read UQ Method data");
if (theAnalysisSelection->inputFromJSON(jsonObject) == false)
this->errorMessage("EE_UQ: failed to read FEM Method data");
if (theSIM->inputFromJSON(jsonObject) == false)
this->errorMessage("EE_UQ: failed to read SIM Method data");
// sy - to display results
auto* theNewResults = theUQ_Selection->getResults();
if (theNewResults->inputFromJSON(jsonObject) == false)
this->errorMessage("EE_UQ: failed to read RES Method data");
theResults->setResultWidget(theNewResults);
this->statusMessage("Done Loading File");
return true;
}
void
WorkflowAppEE_UQ::onRunButtonClicked() {
theRunWidget->hide();
theRunWidget->setMinimumWidth(this->width()*0.5);
theRunWidget->showLocalApplication();
GoogleAnalytics::ReportLocalRun();
}
void
WorkflowAppEE_UQ::onRemoteRunButtonClicked(){
this->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");
}
GoogleAnalytics::ReportDesignSafeRun();
}
void
WorkflowAppEE_UQ::onRemoteGetButtonClicked(){
this->errorMessage("");
bool loggedIn = theRemoteService->isLoggedIn();
if (loggedIn == true) {
theJobManager->hide();
theJobManager->updateJobTable("");
theJobManager->show();
} else {
errorMessage("ERROR - You Need to Login");
}
}
void
WorkflowAppEE_UQ::onExitButtonClicked(){
}
void
WorkflowAppEE_UQ::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");
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.append(tmpDirectory);
fatalMessage(msg);
return;
}
}
destinationDirectory.mkpath(tmpDirectory);
QString templateDirectory = destinationDirectory.absoluteFilePath(subDir);
destinationDirectory.mkpath(templateDirectory);
// copyPath(path, tmpDirectory, false);
//theSIM->copyFiles(templateDirectory);
if (theSIM->copyFiles(templateDirectory) == false) {
errorMessage("Workflow Failed to start as SIM failed in copyFiles");
return;
}
if (theEventSelection->copyFiles(templateDirectory) == false) {
errorMessage("Workflow Failed to start as EVENT failed in copyFiles");
return;
}
theAnalysisSelection->copyFiles(templateDirectory);
theUQ_Selection->copyFiles(templateDirectory);
theEDP_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;
}
QJsonObject json;
if (this->outputToJSON(json) == false) {
this->errorMessage("WorkflowApp - failed in outputToJson");
return;
}
json["runDir"]=tmpDirectory;
json["WorkflowType"]="Building Simulation";
QJsonDocument doc(json);
file.write(doc.toJson());
file.close();
//
// ouput citation
//
QJsonObject citations;
QString citeFile = templateDirectory + QDir::separator() + tr("please_cite.json");
// QString citeFile = destinationDirectory.filePath("please_cite.json"); // file getting deleted
this->createCitation(citations, citeFile);
statusMessage("SetUp Done .. Now starting application");
emit setUpForApplicationRunDone(tmpDirectory, inputFile);
}
int
WorkflowAppEE_UQ::loadFile(QString &fileName){
errorMessage("");
//
// 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();
//Resolve absolute paths from relative ones
QFileInfo fileInfo(fileName);
SCUtils::ResolveAbsolutePaths(jsonObj, fileInfo.dir());
// close file
file.close();
//
// clear current and input from new JSON
//
this->clear();
bool result = this->inputFromJSON(jsonObj);
if (result == true)
return 0;
else
return -1;
}
int
WorkflowAppEE_UQ::getMaxNumParallelTasks() {
return theUQ_Selection->getNumParallelTasks();
}
int
WorkflowAppEE_UQ::createCitation(QJsonObject &citation, QString citeFile) {
QString cit("{\"EE-UQ\": { \"citations\": [{\"citation\": \"Frank McKenna, Kuanshi Zhong, Michael Gardner, Adam Zsarnoczay, Sang-ri Yi, Aakash Bangalore Satish, Charles Wang, Amin Pakzad, Pedro Arduino, & Wael Elhaddad. (2024). NHERI-SimCenter/EE-UQ: Version 4.1.0 (v4.1.0).\",\"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, 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\",\"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() << "WorkflowAppEE_UQ citation text is not valid JSON: \n" << cit << endl;
}
}
theSIM->outputCitation(citation);
theEventSelection->outputCitation(citation);
theAnalysisSelection->outputCitation(citation);
theUQ_Selection->outputCitation(citation);
theEDP_Selection->outputCitation(citation);
// write the citation to a citeFile if 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;
}