Repository navigation
Expand file tree
/
Copy pathFFaFunctionManager.C
More file actions
406 lines (358 loc) · 12.1 KB
/
Copy pathFFaFunctionManager.C
File metadata and controls
406 lines (358 loc) · 12.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
// SPDX-FileCopyrightText: 2023 SAP SE
//
// SPDX-License-Identifier: Apache-2.0
//
// This file is part of FEDEM - https://openfedem.org
////////////////////////////////////////////////////////////////////////////////
/*!
\file FFaFunctionManager.C
\brief Global functions direct evaluation of some explicit function types.
\details Must of the functions herein forward to Fortran subroutines in
explicitFunctions.f90 and waveFunctions.f90 for conducting the evaluation.
*/
#include "FFaFunctionManager.H"
#include "FFaFunctionProperties.H"
#include "FFaLib/FFaAlgebra/FFaVec3.H"
#include "FFaLib/FFaOS/FFaFortran.H"
#include <cstdlib>
#ifdef _NO_FORTRAN
#include <iostream>
#else
//! \cond NO_DOCUMENATION
DOUBLE_FUNCTION (getfunctionvalue,GETFUNCTIONVALUE) (const int& baseID,
const int* intVars,
const double* realVars,
const int& intNR,
const int& realNC,
const double& x,
int& ierr);
DOUBLE_FUNCTION (getfunctionderiv,GETFUNCTIONDERIV) (const int& baseID,
const int* intVars,
const double* realVars,
const int& intNR,
const int& realNC,
const double& x,
int& ierr);
INTEGER_FUNCTION (getfunctiontypeid,GETFUNCTIONTYPEID) (const char* funcName,
const int nChar);
SUBROUTINE(initwavefuncfromfile,INITWAVEFUNCFROMFILE) (const char* fileName,
#ifdef _NCHAR_AFTER_CHARARG
const int nChar,
#endif
const int& nWave,
const int& rSeed,
double* realVars,
int& ierr
#ifndef _NCHAR_AFTER_CHARARG
, const int nChar
#endif
);
SUBROUTINE(initwavefuncspectrum,INITWAVEFUNCSPECTRUM) (const int& iop,
const int& nWave,
const int& nDir,
const int& sprExp,
const int& rSeed,
double* realVars,
int& ierr);
SUBROUTINE(initnonlinwavefunc,INITNONLINWAVEFUNC) (const int& iop,
const double& g,
const double& d,
double* realVars,
int& ierr);
SUBROUTINE(initembeddedwave,INITEMBEDDEDWAVE) (const int& iop,
const int& nWave,
const int& rSeed,
const double& g,
const double& d,
int* intVars,
double* realVars,
int& ierr);
DOUBLE_FUNCTION(waveprofile,WAVEPROFILE) (const int& iop, const int& ldi,
const int& ldr, const int& nWave,
const int& nDir, const int* intVars,
const double* realVars,
const double& g, const double& d,
const double* x, const double& t);
SUBROUTINE(evalwave,EVALWAVE) (const int& iop, const int& ldi,
const int& ldr, const int& nWave,
const int& nDir, const int* intVars,
const double* realVars,
const double& g, const double& d,
const double* x, const double& t,
double& eta, double* v, double* a);
//! \endcond
#endif
//! \sa The fortran routine \ref getfunctionvalue().
double FFaFunctionManager::getValue (int baseID,
const std::vector<int>& intVars,
const std::vector<double>& realVars,
const double x, int& ierr)
{
if (realVars.empty() || intVars.empty())
{
ierr = -3;
return 0.0;
}
double value = 0.0;
ierr = FFaFunctionProperties::getValue(baseID,intVars,realVars,x,value);
if (ierr <= 0) return value;
#ifdef _NO_FORTRAN
std::cerr <<" *** FFaFunctionManager::getValue(dummy) "<< baseID
<<" "<< intVars.size() <<" "<< realVars.size() <<" "<< x
<< std::endl;
ierr = -99;
return 0.0;
#else
return F90_NAME(getfunctionvalue,GETFUNCTIONVALUE) (baseID,
&intVars.front(),
&realVars.front(),
intVars.size(),
realVars.size(),
x, ierr);
#endif
}
//! \sa The fortran routine \ref getfunctionvalue().
double FFaFunctionManager::getValue (int baseID, int fType, int extrap,
const std::vector<double>& realVars,
const double x, int& ierr)
{
if (realVars.empty())
{
ierr = -3;
return 0.0;
}
#ifdef _NO_FORTRAN
std::cerr <<" *** FFaFunctionManager::getValue(dummy) "<< baseID
<<" "<< fType <<" "<< extrap <<" "<< realVars.size() <<" "<< x
<< std::endl;
ierr = -99;
return 0.0;
#else
// Set intVars[2]=2 for sinusoidals, to indicate that the function parameters
// are permuted for wave function evaluation, see FmfSinusoidal::initGetValue
int nComp = fType == 4 ? realVars.size()/3 : (fType == 1 ? 2 : -1);
int intVars[3] = { fType, extrap, nComp };
return F90_NAME(getfunctionvalue,GETFUNCTIONVALUE) (baseID, intVars,
&realVars.front(),
3, realVars.size(),
x, ierr);
#endif
}
//! \sa The fortran routine \ref getfunctionderiv().
double FFaFunctionManager::getDerivative (int baseID, int fType, int extrap,
const std::vector<double>& realVars,
const double x, int& ierr)
{
if (realVars.empty())
{
ierr = -3;
return 0.0;
}
#ifdef _NO_FORTRAN
std::cerr <<" *** FFaFunctionManager::getDerivative(dummy) "<< baseID
<<" "<< fType <<" "<< extrap <<" "<< realVars.size() <<" "<< x
<< std::endl;
ierr = -99;
return 0.0;
#else
// Set intVars[2]=2 for sinusoidals, to indicate that the function parameters
// are permuted for wave function evaluation, see FmfSinusoidal::initGetValue
int nComp = fType == 4 ? realVars.size()/3 : (fType == 1 ? 2 : -1);
int intVars[3] = { fType, extrap, nComp };
return F90_NAME(getfunctionderiv,GETFUNCTIONDERIV) (baseID, intVars,
&realVars.front(),
3, realVars.size(),
x, ierr);
#endif
}
//! \sa The fortran routine \ref getfunctiontypeid().
int FFaFunctionManager::getTypeID (const std::string& functionType)
{
#ifdef _NO_FORTRAN
return FFaFunctionProperties::getTypeID(functionType);
#else
const char* fType = functionType.c_str();
const int nChar = functionType.length();
return F90_NAME(getfunctiontypeid,GETFUNCTIONTYPEID) (fType, nChar);
#endif
}
//! \sa FFaFunctionProperties::getSmartPoints().
int FFaFunctionManager::getSmartPoints (int funcType, int extrap,
const double start, const double stop,
const std::vector<double>& realVars,
std::vector<double>& xvec,
std::vector<double>& yvec)
{
return FFaFunctionProperties::getSmartPoints (funcType, start, stop,
extrap, realVars, xvec, yvec);
}
//! \sa The fortran routine \ref initwavefuncfromfile().
bool FFaFunctionManager::initWaveFunction (const std::string& fileName,
const int nWave, const int rSeed,
std::vector<double>& realVars)
{
if (nWave < 1) return false;
#ifdef _NO_FORTRAN
std::cerr <<" *** FFaFunctionManager::initWaveFunction(dummy) "<< fileName
<<" "<< rSeed <<" "<< realVars.size() << std::endl;
return false;
#else
int ierr = 0;
realVars.resize(3*nWave);
F90_NAME(initwavefuncfromfile,INITWAVEFUNCFROMFILE) (fileName.c_str(),
#ifdef _NCHAR_AFTER_CHARARG
fileName.length(),
#endif
nWave, rSeed,
&realVars.front(), ierr
#ifndef _NCHAR_AFTER_CHARARG
, fileName.length()
#endif
);
return ierr < 0 ? false : true;
#endif
}
//! \sa The fortran routine \ref initwavefuncspectrum().
bool FFaFunctionManager::initWaveFunction (const int iop,
const int nWave, const int nDir,
const int sprExp, const int rSeed,
std::vector<double>& realVars)
{
if (nWave < 1 || nDir < 1 || nDir%2 == 0) return false;
if (nDir > 1 && (sprExp%2 == 1 || sprExp < 2)) return false;
#ifdef _NO_FORTRAN
std::cerr <<" *** FFaFunctionManager::initWaveFunction(dummy) "<< iop
<<" "<< rSeed <<" "<< realVars.size() << std::endl;
return false;
#else
int ierr = 0;
realVars.resize(3*nWave*nDir);
F90_NAME(initwavefuncspectrum,INITWAVEFUNCSPECTRUM) (iop, nWave, nDir,
sprExp, rSeed,
&realVars.front(), ierr);
return ierr < 0 ? false : true;
#endif
}
//! \sa The fortran routine \ref initnonlinwavefunc().
bool FFaFunctionManager::initWaveFunction (const int iop,
const double g, const double d,
std::vector<double>& realVars)
{
if (realVars.empty())
return false;
#ifdef _NO_FORTRAN
std::cerr <<" *** FFaFunctionManager::initWaveFunction(dummy) "<< iop
<<" "<< g <<" "<< d << std::endl;
return false;
#else
int ierr = 0;
F90_NAME(initnonlinwavefunc,INITNONLINWAVEFUNC) (iop, g, d,
&realVars.front(), ierr);
if (ierr < 0) return false;
realVars.resize(ierr);
return true;
#endif
}
//! \sa The fortran routine \ref initembeddedwave().
bool FFaFunctionManager::initWaveFunction (const int iop,
const int nWave, const int rSeed,
const double g, const double d,
std::vector<int>& intVars,
std::vector<double>& realVars)
{
int ierr = intVars[3];
if (ierr < 1) return false;
#ifdef _NO_FORTRAN
std::cerr <<" *** FFaFunctionManager::initWaveFunction(dummy) "<< iop
<<" "<< nWave <<" "<< rSeed <<" "<< g <<" "<< d
<<" "<< realVars.size() << std::endl;
return false;
#else
intVars.resize(4+ierr,0);
realVars.resize(3*nWave+50*ierr);
intVars[4] = realVars.size();
F90_NAME(initembeddedwave,INITEMBEDDEDWAVE) (iop, nWave, rSeed, g, d,
&intVars.front(),
&realVars.front(), ierr);
if (ierr < 0) return false;
realVars.resize(ierr);
return true;
#endif
}
//! \sa The fortran routine \ref waveprofile().
double FFaFunctionManager::getWaveValue (const std::vector<double>& realVars,
const double g, const double d,
const FaVec3& x, const double t,
int iop)
{
std::vector<int> intVars;
if (iop > 100)
{
// Both the function type ID and the user-defined function ID are assumed
// encoded into iop argument. The latter needs to be stored in intVars.
intVars.resize(3,0);
intVars.back() = iop/100;
iop %= 100;
}
return FFaFunctionManager::getWaveValue(intVars,realVars,g,d,x,t,iop);
}
//! \sa The fortran routine \ref waveprofile().
double FFaFunctionManager::getWaveValue (const std::vector<int>& intVars,
const std::vector<double>& realVars,
const double g, const double d,
const FaVec3& x, const double t,
int iop)
{
int ldr = realVars.size();
int nWave = 1, nDir = 1;
if (iop < 2 || iop == 4)
{
// Airy wave theory, with one or many wave components
if (intVars.size() > 3 && intVars[3] > 1)
nDir = intVars[3];
nWave = ldr / (3*nDir);
if (nWave < 1) return 0.0;
ldr = 3;
iop = d > 0.0 ? 1 : 0;
}
#ifdef _NO_FORTRAN
std::cerr <<" ** FFaFunctionManager::getWaveValue(dummy) "<< g <<" "<< d
<<" "<< x <<" "<< t <<" "<< iop << std::endl;
return 0.0;
#else
return F90_NAME(waveprofile,WAVEPROFILE) (iop, intVars.size(), ldr,
nWave, nDir, &intVars.front(),
&realVars.front(),
g, d, x.getPt(), t);
#endif
}
//! \sa The fortran routine \ref evalwave().
double FFaFunctionManager::getWaveValue (const std::vector<int>& intVars,
const std::vector<double>& realVars,
const double g, const double d,
const FaVec3& x, const double t,
FaVec3& v, FaVec3& a, int iop)
{
int ldr = realVars.size();
int nWave = 1, nDir = 1;
if (iop < 2 || iop == 4)
{
// Airy wave theory, with one or many wave components
if (intVars.size() > 3 && intVars[3] > 1)
nDir = intVars[3];
nWave = ldr / (3*nDir);
if (nWave < 1) return 0.0;
ldr = 3;
iop = d > 0.0 ? 1 : 0;
}
double eta = 0.0;
#ifdef _NO_FORTRAN
std::cerr <<" ** FFaFunctionManager::getWaveValue(dummy) "<< g <<" "<< d
<<" "<< x <<" "<< t <<" "<< v <<" "<< a <<" "<< iop << std::endl;
#else
F90_NAME(evalwave,EVALWAVE) (iop, intVars.size(), ldr,
nWave, nDir, &intVars.front(), &realVars.front(),
g, d, x.getPt(), t, eta, v.getPt(), a.getPt());
#endif
return eta;
}