44{
46
47 if (argc != 6)
48 {
49 fprintf(
50 stderr,
51 "Usage: AddModeTo2DFld scal1 scal2 2Dfieldfile1 fieldfile2 "
52 "outfield\n"
53 "\t produces scal1*2Dfieldfiel1 + scal2*fieldfile2 in outfield\n");
54 exit(1);
55 }
56
57 scal1 = boost::lexical_cast<double>(argv[argc - 5]);
58 scal2 = boost::lexical_cast<double>(argv[argc - 4]);
59
60
61
62 string fieldfile1(argv[argc - 3]);
63 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef1;
64 vector<vector<NekDouble>> fielddata1;
66
67
68
69
70 string fieldfile2(argv[argc - 2]);
71 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef2;
72 vector<vector<NekDouble>> fielddata2;
74
75
76 vector<vector<NekDouble>> combineddata;
77
78 ASSERTL0(fielddata1.size() == fielddata2.size(),
79 "Inner has different size");
80
81
82
83 int i = 0;
84 int j = 0;
85 int k = 0;
86 int n = 0;
87
88 for (i = 0; i < fielddata2.size(); ++i)
89 {
90 ASSERTL0(fielddef2[i]->m_numHomogeneousDir == 1,
91 "Expected second fld to have one homogeneous direction");
92 ASSERTL0(fielddef2[i]->m_numModes[2] == 2,
93 "Expected Fourier field to have 2 modes");
94
95 int datalen1 = fielddata1[i].size() / fielddef1[i]->m_fields.size();
96 int datalen2 = fielddata2[i].size() / fielddef2[i]->m_fields.size();
97
99 "Data per fields is note compatible");
100
101
102 int ncoeffs = 0;
103 switch (fielddef2[i]->m_shapeType)
104 {
107 fielddef2[i]->m_numModes[0], fielddef2[i]->m_numModes[1]);
108 break;
110 ncoeffs =
111 fielddef2[i]->m_numModes[0] * fielddef2[i]->m_numModes[1];
112 break;
113 default:
114 ASSERTL0(
false,
"Shape not recognised");
115 break;
116 }
117
118
120
121
122 Vmath::Smul(fielddata1[i].size(), scal1, &fielddata1[i][0], 1,
123 &fielddata1[i][0], 1);
124 Vmath::Smul(fielddata2[i].size(), scal2, &fielddata2[i][0], 1,
125 &fielddata2[i][0], 1);
126
127 vector<NekDouble> newdata;
128 auto vec_iter = fielddata2[i].begin();
129
130 for (k = 0; k < fielddef2[i]->m_fields.size(); ++k)
131 {
132
133 int offset = 0;
134 for (j = 0; j < fielddef1[i]->m_fields.size(); ++j)
135 {
136 if (fielddef1[i]->m_fields[j] == fielddef2[i]->m_fields[k])
137 {
138 break;
139 }
140 offset += datalen1;
141 }
142
143 if (j != fielddef1[i]->m_fields.size())
144 {
145 for (n = 0; n < fielddef2[i]->m_elementIDs.size(); ++n)
146 {
147
148 newdata.insert(
149 newdata.end(), &(fielddata1[i][offset + n * ncoeffs]),
150 &(fielddata1[i][offset + n * ncoeffs]) + ncoeffs);
151
152
153 newdata.insert(newdata.end(), &
Zero[0], &
Zero[0] + ncoeffs);
154
155
156 newdata.insert(newdata.end(), vec_iter,
157 vec_iter + 2 * ncoeffs);
158 vec_iter += 2 * ncoeffs;
159 }
160 }
161 else
162 {
163
164 for (n = 0; n < fielddef2[i]->m_elementIDs.size(); ++n)
165 {
166
167 newdata.insert(newdata.end(), &
Zero[0], &
Zero[0] + ncoeffs);
168 newdata.insert(newdata.end(), &
Zero[0], &
Zero[0] + ncoeffs);
169
170
171 newdata.insert(newdata.end(), vec_iter,
172 vec_iter + 2 * ncoeffs);
173 vec_iter += 2 * ncoeffs;
174 }
175 }
176 }
177 combineddata.push_back(newdata);
178 fielddef2[i]->m_numModes[2] += 2;
179 fielddef2[i]->m_homogeneousZIDs.push_back(2);
180 fielddef2[i]->m_homogeneousZIDs.push_back(3);
181
182
183
184 for (k = 0; k < fielddef1[i]->m_fields.size(); ++k)
185 {
186 for (j = 0; j < fielddef2[i]->m_fields.size(); ++j)
187 {
188 if (fielddef1[i]->m_fields[k] == fielddef2[i]->m_fields[j])
189 {
190 break;
191 }
192 }
193
194 if (j == fielddef2[i]->m_fields.size())
195 {
196 cout << "Warning: Field \'" << fielddef1[i]->m_fields[k]
197 << "\' was not included in output " << endl;
198 }
199 }
200 }
201
202
203
204
206
207
208 return 0;
209}
#define ASSERTL0(condition, msg)
int getNumberOfCoefficients(int Na)
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > &ElementIDs)
This function allows for data to be imported from an FLD file when a session and/or communicator is n...
void Write(const std::string &outFile, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, const FieldMetaDataMap &fieldinfomap, const bool backup)
This function allows for data to be written to an FLD file when a session and/or communicator is not ...
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
void Zero(int n, T *x, const int incx)
Zero vector.