-
Notifications
You must be signed in to change notification settings - Fork 977
Expand file tree
/
Copy pathoption_structure.inl
More file actions
2018 lines (1757 loc) · 62.1 KB
/
option_structure.inl
File metadata and controls
2018 lines (1757 loc) · 62.1 KB
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
/*!
* \file option_structure.inl
* \brief Template derived classes from COption, defined here as we
* only include them where needed to reduce compilation time.
* \author J. Hicken, B. Tracey
* \version 8.1.0 "Harrier"
*
* SU2 Project Website: https://su2code.github.io
*
* The SU2 Project is maintained by the SU2 Foundation
* (http://su2foundation.org)
*
* Copyright 2012-2024, SU2 Contributors (cf. AUTHORS.md)
*
* SU2 is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* SU2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with SU2. If not, see <http://www.gnu.org/licenses/>.
*/
#include "parallelization/mpi_structure.hpp"
using namespace std;
template <class Tenum, class TField>
class COptionEnum final : public COptionBase {
const map<string, Tenum>& m;
TField& field; // Reference to the fieldname
const Tenum def; // Default value
const string name; // identifier for the option
public:
COptionEnum() = delete;
COptionEnum(string option_field_name, const map<string, Tenum>& m_, TField& option_field, Tenum default_value)
: m(m_), field(option_field), def(default_value), name(std::move(option_field_name)) {}
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
// Check if there is more than one string
string out = optionCheckMultipleValues(option_value, "enum", name);
if (out.compare("") != 0) {
return out;
}
// Check to see if the enum value is in the map
auto it = m.find(option_value[0]);
if (it == m.cend()) {
stringstream ss;
ss << name << ": invalid option value " << option_value[0] << ".\nDid you mean";
for (auto& item : m) ss << ", " << item.first;
ss << "?";
return ss.str();
}
// If it is there, set the option value
field = it->second;
return "";
}
void SetDefault() override { field = def; }
};
template <typename Scalar>
class COptionScalar : public COptionBase {
protected:
Scalar& field; // Reference to the fieldname
const Scalar def; // Default value
const string name; // identifier for the option
const string typeName; // name for the scalar type
public:
COptionScalar() = delete;
COptionScalar(const string& type_name, const string& option_field_name, Scalar& option_field, Scalar default_value)
: field(option_field), def(default_value), name(option_field_name), typeName(type_name) {}
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
string out = optionCheckMultipleValues(option_value, typeName, name);
if (!out.empty()) return out;
istringstream is(option_value.front());
if (is >> field) return "";
return badValue(typeName, name);
}
void SetDefault() final { field = def; }
};
class COptionDouble final : public COptionScalar<su2double> {
public:
template <class... Ts>
COptionDouble(Ts&&... args) : COptionScalar<su2double>("su2double", args...) {}
};
class COptionInt final : public COptionScalar<int> {
public:
template <class... Ts>
COptionInt(Ts&&... args) : COptionScalar<int>("int", args...) {}
};
class COptionULong final : public COptionScalar<unsigned long> {
public:
template <class... Ts>
COptionULong(Ts&&... args) : COptionScalar<unsigned long>("unsigned long", args...) {}
};
class COptionUShort final : public COptionScalar<unsigned short> {
public:
template <class... Ts>
COptionUShort(Ts&&... args) : COptionScalar<unsigned short>("unsigned short", args...) {}
};
class COptionLong final : public COptionScalar<long> {
public:
template <class... Ts>
COptionLong(Ts&&... args) : COptionScalar<long>("long", args...) {}
};
class COptionBool final : public COptionScalar<bool> {
public:
template <class... Ts>
COptionBool(Ts&&... args) : COptionScalar<bool>("bool", args...) {}
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
string result;
auto msg = COptionScalar<string>("bool", name, result, "").SetValue(option_value);
if (!msg.empty()) return msg;
if (result.compare("YES") == 0) {
field = true;
return "";
}
if (result.compare("NO") == 0) {
field = false;
return "";
}
return badValue("bool", name);
}
};
class COptionString final : public COptionBase {
protected:
string& field; // Reference to the fieldname
const string def; // Default value
const string name; // identifier for the option
public:
COptionString() = delete;
COptionString(const string& option_field_name, string& option_field, string default_value)
: field(option_field), def(default_value), name(option_field_name) {}
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
string out = optionCheckMultipleValues(option_value, "string", name);
if (!out.empty()) return out;
field = option_value.front();
return "";
}
void SetDefault() override { field = def; }
};
template <class Tenum, class TField>
class COptionEnumList final : public COptionBase {
const map<string, Tenum>& m;
TField*& field;
unsigned short& mySize;
const string name;
public:
COptionEnumList() = delete;
COptionEnumList(string option_field_name, const map<string, Tenum>& m_, TField*& option_field,
unsigned short& list_size)
: m(m_), field(option_field), mySize(list_size), name(option_field_name) {
field = nullptr;
}
~COptionEnumList() {
delete[] field;
field = nullptr;
}
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
if (option_value.size() == 1 && option_value[0].compare("NONE") == 0) {
mySize = 0;
return "";
}
// size is the length of the option list
mySize = option_value.size();
field = new TField[mySize];
for (unsigned short i = 0; i < mySize; i++) {
// Check to see if the enum value is in the map
auto it = m.find(option_value[i]);
if (it == m.cend()) {
stringstream ss;
ss << name << ": invalid option value " << option_value[i] << ".\nDid you mean";
for (auto& item : m) ss << ", " << item.first;
ss << "?";
return ss.str();
}
// If it is there, set the option value
field[i] = it->second;
}
return "";
}
void SetDefault() override { mySize = 0; }
};
template <class Type>
class COptionArray final : public COptionBase {
string name; // Identifier for the option
const int size; // Number of elements
Type* field; // Reference to the field
public:
COptionArray(string option_field_name, const int list_size, Type* option_field)
: name(option_field_name), size(list_size), field(option_field) {}
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
// Check that the size is correct
if (option_value.size() != (unsigned long)this->size) {
string newstring;
newstring.append(this->name);
newstring.append(": wrong number of arguments: ");
stringstream ss;
ss << this->size;
newstring.append(ss.str());
newstring.append(" expected, ");
stringstream ss2;
ss2 << option_value.size();
newstring.append(ss2.str());
newstring.append(" found");
return newstring;
}
for (int i = 0; i < this->size; i++) {
istringstream is(option_value[i]);
if (!(is >> field[i])) {
return badValue(" array", this->name);
}
}
return "";
}
void SetDefault() override {}
};
template <typename Scalar>
class COptionScalarList : public COptionBase {
Scalar*& field; // reference to the field
const string name; // identifier for the option
unsigned short& mySize; // size of the list
const string typeName; // name of the scalar type
public:
COptionScalarList() = delete;
COptionScalarList(const string& type_name, const string& option_field_name, unsigned short& list_size,
Scalar*& option_field)
: field(option_field), name(option_field_name), mySize(list_size), typeName(type_name) {
field = nullptr;
}
~COptionScalarList() {
delete[] field;
// prevent double free
field = nullptr;
}
string SetValue(const vector<string>& option_value) final {
COptionBase::SetValue(option_value);
// The size is the length of option_value
mySize = option_value.size();
if (mySize == 1 && option_value[0].compare("NONE") == 0) {
// No options
mySize = 0;
return "";
}
// Parse all of the options
field = new Scalar[mySize];
for (unsigned short i = 0; i < mySize; i++) {
istringstream is(option_value[i]);
Scalar val;
if (!(is >> val)) {
return badValue(typeName + " list", name);
}
field[i] = std::move(val);
}
return "";
}
void SetDefault() final {
mySize = 0; // There is no default value for list
}
};
class COptionDoubleList final : public COptionScalarList<su2double> {
public:
template <class... Ts>
COptionDoubleList(Ts&&... args) : COptionScalarList<su2double>("su2double", args...) {}
};
class COptionShortList final : public COptionScalarList<short> {
public:
template <class... Ts>
COptionShortList(Ts&&... args) : COptionScalarList<short>("short", args...) {}
};
class COptionUShortList final : public COptionScalarList<unsigned short> {
public:
template <class... Ts>
COptionUShortList(Ts&&... args) : COptionScalarList<unsigned short>("unsigned short", args...) {}
};
class COptionULongList final : public COptionScalarList<unsigned long> {
public:
template <class... Ts>
COptionULongList(Ts&&... args) : COptionScalarList<unsigned long>("unsigned long", args...) {}
};
class COptionStringList final : public COptionScalarList<string> {
public:
template <class... Ts>
COptionStringList(Ts&&... args) : COptionScalarList<string>("string", args...) {}
};
class COptionConvect : public COptionBase {
string name; // identifier for the option
unsigned short& space;
CENTERED& centered;
UPWIND& upwind;
public:
COptionConvect(string option_field_name, unsigned short& space_field, CENTERED& centered_field, UPWIND& upwind_field)
: name(option_field_name), space(space_field), centered(centered_field), upwind(upwind_field) {}
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
string out = optionCheckMultipleValues(option_value, "unsigned short", this->name);
if (out.compare("") != 0) {
return out;
}
if (Centered_Map.count(option_value[0])) {
this->space = SPACE_CENTERED;
this->centered = Centered_Map.find(option_value[0])->second;
this->upwind = UPWIND::NONE;
return "";
}
if (Upwind_Map.count(option_value[0])) {
this->space = SPACE_UPWIND;
this->upwind = Upwind_Map.find(option_value[0])->second;
this->centered = CENTERED::NONE;
return "";
}
// Make them defined in case something weird happens
SetDefault();
return badValue("convect", this->name);
}
void SetDefault() override {
this->centered = CENTERED::NONE;
this->upwind = UPWIND::NONE;
this->space = NO_CONVECTIVE;
}
};
class COptionFEMConvect : public COptionBase {
string name; // identifier for the option
unsigned short& space;
unsigned short& fem;
public:
COptionFEMConvect(string option_field_name, unsigned short& space_field, unsigned short& fem_field)
: space(space_field), fem(fem_field) {
this->name = option_field_name;
}
~COptionFEMConvect() override{};
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
string out = optionCheckMultipleValues(option_value, "unsigned short", this->name);
if (out.compare("") != 0) {
return out;
}
if (FEM_Map.count(option_value[0])) {
this->space = FINITE_ELEMENT;
this->fem = FEM_Map.find(option_value[0])->second;
return "";
}
// Make them defined in case something weird happens
this->fem = NO_FEM;
return badValue("convect", this->name);
}
void SetDefault() override { this->fem = NO_FEM; }
};
class COptionMathProblem : public COptionBase {
string name; // identifier for the option
bool& cont_adjoint;
bool cont_adjoint_def;
bool& disc_adjoint;
bool disc_adjoint_def;
bool& restart;
bool restart_def;
public:
COptionMathProblem(string option_field_name, bool& cont_adjoint_field, bool cont_adjoint_default,
bool& disc_adjoint_field, bool disc_adjoint_default, bool& restart_field, bool restart_default)
: cont_adjoint(cont_adjoint_field), disc_adjoint(disc_adjoint_field), restart(restart_field) {
name = option_field_name;
cont_adjoint_def = cont_adjoint_default;
disc_adjoint_def = disc_adjoint_default;
restart_def = restart_default;
}
~COptionMathProblem() override{};
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
string out = optionCheckMultipleValues(option_value, "unsigned short", name);
if (out.compare("") != 0) {
return out;
} else if (option_value[0] == "ADJOINT") {
return badValue("math problem (try CONTINUOUS_ADJOINT)", name);
} else if (option_value[0] == "DIRECT") {
cont_adjoint = false;
disc_adjoint = false;
restart = false;
return "";
} else if (option_value[0] == "CONTINUOUS_ADJOINT") {
cont_adjoint = true;
disc_adjoint = false;
restart = true;
return "";
} else if (option_value[0] == "DISCRETE_ADJOINT") {
disc_adjoint = true;
cont_adjoint = false;
restart = true;
return "";
}
return badValue("math problem", name);
}
void SetDefault() override {
cont_adjoint = cont_adjoint_def;
disc_adjoint = disc_adjoint_def;
restart = restart_def;
}
};
class COptionDVParam : public COptionBase {
string name; // identifier for the option
unsigned short& nDV;
su2double**& paramDV;
string*& FFDTag;
unsigned short*& design_variable;
public:
COptionDVParam(string option_field_name, unsigned short& nDV_field, su2double**& paramDV_field, string*& FFDTag_field,
unsigned short*& design_variable_field)
: nDV(nDV_field), paramDV(paramDV_field), FFDTag(FFDTag_field), design_variable(design_variable_field) {
this->name = option_field_name;
}
~COptionDVParam() override{};
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
if ((option_value.size() == 1) && (option_value[0].compare("NONE") == 0)) {
this->nDV = 0;
return "";
}
// Cannot have ; at the beginning or the end
if (option_value[0].compare(";") == 0) {
string newstring;
newstring.append(this->name);
newstring.append(": may not have beginning semicolon");
return newstring;
}
if (option_value[option_value.size() - 1].compare(";") == 0) {
string newstring;
newstring.append(this->name);
newstring.append(": may not have ending semicolon");
return newstring;
}
// use the ";" token to determine the number of design variables
// This works because semicolon is not one of the delimiters in tokenize string
this->nDV = 0;
// unsigned int num_semi = 0;
for (unsigned int i = 0; i < static_cast<unsigned int>(option_value.size()); i++) {
if (option_value[i].compare(";") == 0) {
this->nDV++;
// num_semi++;
}
}
// One more design variable than semicolon
this->nDV++;
if ((this->nDV > 0) && (this->design_variable == nullptr)) {
string newstring;
newstring.append(this->name);
newstring.append(
": Design_Variable array has not been allocated. Check that DV_KIND appears before DV_PARAM in configuration "
"file.");
return newstring;
}
this->paramDV = new su2double*[this->nDV];
for (unsigned short iDV = 0; iDV < this->nDV; iDV++) {
this->paramDV[iDV] = new su2double[MAX_PARAMETERS];
}
this->FFDTag = new string[this->nDV];
vector<unsigned short> nParamDV(nDV, 0);
unsigned short totalnParamDV = 0;
stringstream ss;
unsigned int i = 0;
for (unsigned short iDV = 0; iDV < this->nDV; iDV++) {
switch (this->design_variable[iDV]) {
case NO_DEFORMATION:
nParamDV[iDV] = 0;
break;
case FFD_SETTING:
nParamDV[iDV] = 0;
break;
case FFD_CONTROL_POINT_2D:
nParamDV[iDV] = 5;
break;
case FFD_CAMBER_2D:
nParamDV[iDV] = 2;
break;
case FFD_THICKNESS_2D:
nParamDV[iDV] = 2;
break;
case HICKS_HENNE:
nParamDV[iDV] = 2;
break;
case SURFACE_BUMP:
nParamDV[iDV] = 3;
break;
case CST:
nParamDV[iDV] = 3;
break;
case ANGLE_OF_ATTACK:
nParamDV[iDV] = 1;
break;
case SCALE:
nParamDV[iDV] = 0;
break;
case TRANSLATION:
nParamDV[iDV] = 3;
break;
case ROTATION:
nParamDV[iDV] = 6;
break;
case NACA_4DIGITS:
nParamDV[iDV] = 3;
break;
case PARABOLIC:
nParamDV[iDV] = 2;
break;
case AIRFOIL:
nParamDV[iDV] = 2;
break;
case FFD_CONTROL_POINT:
nParamDV[iDV] = 7;
break;
case FFD_NACELLE:
nParamDV[iDV] = 6;
break;
case FFD_GULL:
nParamDV[iDV] = 2;
break;
case FFD_TWIST:
nParamDV[iDV] = 8;
break;
case FFD_ROTATION:
nParamDV[iDV] = 7;
break;
case FFD_CONTROL_SURFACE:
nParamDV[iDV] = 7;
break;
case FFD_CAMBER:
nParamDV[iDV] = 3;
break;
case FFD_THICKNESS:
nParamDV[iDV] = 3;
break;
case FFD_ANGLE_OF_ATTACK:
nParamDV[iDV] = 2;
break;
case SURFACE_FILE:
nParamDV[iDV] = 0;
break;
case DV_EFIELD:
nParamDV[iDV] = 2;
break;
case DV_YOUNG:
nParamDV[iDV] = 0;
break;
case DV_POISSON:
nParamDV[iDV] = 0;
break;
case DV_RHO:
nParamDV[iDV] = 0;
break;
case DV_RHO_DL:
nParamDV[iDV] = 0;
break;
case SCALE_GRID:
nParamDV[iDV] = 0;
break;
case TRANSLATE_GRID:
nParamDV[iDV] = 3;
break;
case ROTATE_GRID:
nParamDV[iDV] = 6;
break;
default: {
string newstring;
newstring.append(this->name);
newstring.append(": undefined design variable type found in configuration file. ");
return newstring;
}
}
totalnParamDV += nParamDV[iDV];
}
if (totalnParamDV > option_value.size()) {
SU2_MPI::Error("Wrong number of arguments for DV_PARAM!", CURRENT_FUNCTION);
}
for (unsigned short iDV = 0; iDV < this->nDV; iDV++) {
for (unsigned short iParamDV = 0; iParamDV < nParamDV[iDV]; iParamDV++) {
ss << option_value[i] << " ";
if ((iParamDV == 0) &&
((this->design_variable[iDV] == NO_DEFORMATION) || (this->design_variable[iDV] == FFD_SETTING) ||
(this->design_variable[iDV] == FFD_ANGLE_OF_ATTACK) ||
(this->design_variable[iDV] == FFD_CONTROL_POINT_2D) || (this->design_variable[iDV] == FFD_CAMBER_2D) ||
(this->design_variable[iDV] == FFD_THICKNESS_2D) || (this->design_variable[iDV] == FFD_CONTROL_POINT) ||
(this->design_variable[iDV] == FFD_NACELLE) || (this->design_variable[iDV] == FFD_GULL) ||
(this->design_variable[iDV] == FFD_TWIST) || (this->design_variable[iDV] == FFD_ROTATION) ||
(this->design_variable[iDV] == FFD_CONTROL_SURFACE) || (this->design_variable[iDV] == FFD_CAMBER) ||
(this->design_variable[iDV] == FFD_THICKNESS))) {
ss >> this->FFDTag[iDV];
this->paramDV[iDV][iParamDV] = 0;
} else
ss >> this->paramDV[iDV][iParamDV];
i++;
}
if (iDV < (this->nDV - 1)) {
if (option_value[i].compare(";") != 0) {
string newstring;
newstring.append(this->name);
newstring.append(": a design variable in the configuration file has the wrong number of parameters");
return newstring;
}
i++;
}
}
// Need to return something...
return "";
}
void SetDefault() override {
this->nDV = 0;
this->paramDV = nullptr;
this->FFDTag = nullptr;
// Don't mess with the Design_Variable because it's an input, not modified
}
};
class COptionDVValue : public COptionBase {
string name; // identifier for the option
unsigned short*& nDV_Value;
su2double**& valueDV;
unsigned short& nDV;
su2double**& paramDV;
unsigned short*& design_variable;
public:
COptionDVValue(string option_field_name, unsigned short*& nDVValue_field, su2double**& valueDV_field,
unsigned short& nDV_field, su2double**& paramDV_field, unsigned short*& design_variable_field)
: nDV_Value(nDVValue_field),
valueDV(valueDV_field),
nDV(nDV_field),
paramDV(paramDV_field),
design_variable(design_variable_field) {
this->name = option_field_name;
}
~COptionDVValue() override{};
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
if ((option_value.size() == 1) && (option_value[0].compare("NONE") == 0)) {
this->nDV_Value = nullptr;
return "";
}
if ((this->nDV > 0) && (this->design_variable == nullptr)) {
string newstring;
newstring.append(this->name);
newstring.append(
": Design_Variable array has not been allocated. Check that DV_KIND appears before DV_VALUE in configuration "
"file.");
return newstring;
}
if ((this->nDV > 0) && (this->paramDV == nullptr)) {
string newstring;
newstring.append(this->name);
newstring.append(
": Design_Parameter array has not been allocated. Check that DV_PARAM appears before DV_VALUE in "
"configuration file.");
return newstring;
}
this->valueDV = new su2double*[this->nDV];
this->nDV_Value = new unsigned short[this->nDV];
for (unsigned short iDV = 0; iDV < this->nDV; iDV++) {
this->valueDV[iDV] = new su2double[3];
}
unsigned short nValueDV = 0;
unsigned short totalnValueDV = 0;
stringstream ss;
unsigned int i = 0;
for (unsigned short iDV = 0; iDV < this->nDV; iDV++) {
switch (this->design_variable[iDV]) {
case FFD_CONTROL_POINT:
if ((this->paramDV[iDV][4] == 0) && (this->paramDV[iDV][5] == 0) && (this->paramDV[iDV][6] == 0)) {
nValueDV = 3;
} else {
nValueDV = 1;
}
break;
case FFD_CONTROL_POINT_2D:
if ((this->paramDV[iDV][3] == 0) && (this->paramDV[iDV][4] == 0)) {
nValueDV = 2;
} else {
nValueDV = 1;
}
break;
default:
nValueDV = 1;
}
this->nDV_Value[iDV] = nValueDV;
totalnValueDV += nValueDV;
for (unsigned short iValueDV = 0; iValueDV < nValueDV; iValueDV++) {
if (i >= option_value.size()) {
string newstring;
newstring.append(this->name);
newstring.append(": DV_VALUE does not contain enough entries to match DV_KIND or DV_PARAM.");
return newstring;
}
ss << option_value[i] << " ";
ss >> this->valueDV[iDV][iValueDV];
i++;
}
}
if (i != totalnValueDV) {
string newstring;
newstring.append(this->name);
newstring.append(": a design variable in the configuration file has the wrong number of values");
return newstring;
}
// Need to return something...
return "";
}
void SetDefault() override {
this->nDV_Value = nullptr;
this->valueDV = nullptr;
// Don't mess with the Design_Variable because it's an input, not modified
}
};
class COptionFFDDef : public COptionBase {
string name;
unsigned short& nFFD;
su2double**& CoordFFD;
string*& FFDTag;
public:
COptionFFDDef(string option_field_name, unsigned short& nFFD_field, su2double**& coordFFD_field,
string*& FFDTag_field)
: name(option_field_name), nFFD(nFFD_field), CoordFFD(coordFFD_field), FFDTag(FFDTag_field) {
nFFD = 0;
CoordFFD = nullptr;
FFDTag = nullptr;
}
~COptionFFDDef() {
for (unsigned short i = 0; i < nFFD; ++i) {
delete[] CoordFFD[i];
}
delete[] CoordFFD;
CoordFFD = nullptr;
delete[] FFDTag;
FFDTag = nullptr;
};
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
if ((option_value.size() == 1) && (option_value[0].compare("NONE") == 0)) {
return "";
}
// Cannot have ; at the beginning or the end
if (option_value[0].compare(";") == 0) {
return name + ": may not have beginning semicolon";
}
if (option_value[option_value.size() - 1].compare(";") == 0) {
return name + ": may not have ending semicolon";
}
// use the ";" token to determine the number of design variables
// This works because semicolon is not one of the delimiters in tokenize string
this->nFFD = 0;
for (unsigned int i = 0; i < static_cast<unsigned int>(option_value.size()); i++) {
if (option_value[i].compare(";") == 0) {
this->nFFD++;
}
}
// One more design variable than semicolon
this->nFFD++;
this->CoordFFD = new su2double*[this->nFFD];
for (unsigned short iFFD = 0; iFFD < this->nFFD; iFFD++) {
this->CoordFFD[iFFD] = new su2double[25];
}
this->FFDTag = new string[this->nFFD];
unsigned short nCoordFFD = 0;
stringstream ss;
unsigned int i = 0;
for (unsigned short iFFD = 0; iFFD < this->nFFD; iFFD++) {
nCoordFFD = 25;
for (unsigned short iCoordFFD = 0; iCoordFFD < nCoordFFD; iCoordFFD++) {
ss << option_value[i] << " ";
if (iCoordFFD == 0)
ss >> this->FFDTag[iFFD];
else
ss >> this->CoordFFD[iFFD][iCoordFFD - 1];
i++;
}
if (iFFD < (this->nFFD - 1)) {
if (option_value[i].compare(";") != 0) {
string newstring;
newstring.append(this->name);
newstring.append(": a FFD box in the configuration file has the wrong number of parameters");
return newstring;
}
i++;
}
}
// Need to return something...
return "";
}
void SetDefault() override {}
};
class COptionFFDDegree : public COptionBase {
string name;
unsigned short& nFFD;
unsigned short**& DegreeFFD;
public:
COptionFFDDegree(string option_field_name, unsigned short& nFFD_field, unsigned short**& degreeFFD_field)
: name(option_field_name), nFFD(nFFD_field), DegreeFFD(degreeFFD_field) {
nFFD = 0;
DegreeFFD = nullptr;
}
~COptionFFDDegree() {
for (unsigned short i = 0; i < nFFD; ++i) {
delete[] DegreeFFD[i];
}
delete[] DegreeFFD;
DegreeFFD = nullptr;
};
string SetValue(const vector<string>& option_value) override {
COptionBase::SetValue(option_value);
if ((option_value.size() == 1) && (option_value[0].compare("NONE") == 0)) {
return "";
}
// Cannot have ; at the beginning or the end
if (option_value[0].compare(";") == 0) {
return name + ": may not have beginning semicolon";
}
if (option_value[option_value.size() - 1].compare(";") == 0) {
return name + ": may not have ending semicolon";
}
// use the ";" token to determine the number of design variables
// This works because semicolon is not one of the delimiters in tokenize string
this->nFFD = 0;
for (unsigned int i = 0; i < static_cast<unsigned int>(option_value.size()); i++) {
if (option_value[i].compare(";") == 0) {
this->nFFD++;
}
}
// One more design variable than semicolon
this->nFFD++;
this->DegreeFFD = new unsigned short*[this->nFFD];
for (unsigned short iFFD = 0; iFFD < this->nFFD; iFFD++) {
this->DegreeFFD[iFFD] = new unsigned short[3];
}
unsigned short nDegreeFFD = 0;
stringstream ss;
unsigned int i = 0;
for (unsigned short iFFD = 0; iFFD < this->nFFD; iFFD++) {
nDegreeFFD = 3;
for (unsigned short iDegreeFFD = 0; iDegreeFFD < nDegreeFFD; iDegreeFFD++) {
ss << option_value[i] << " ";
ss >> this->DegreeFFD[iFFD][iDegreeFFD];
i++;
}
if (iFFD < (this->nFFD - 1)) {
if (option_value[i].compare(";") != 0) {
string newstring;
newstring.append(this->name);
newstring.append(": a FFD degree in the configuration file has the wrong number of parameters");
return newstring;
}
i++;
}
}
// Need to return something...
return "";
}
void SetDefault() override {}
};
class COptionInlet : public COptionBase {
string name; // identifier for the option