FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
FEBio/FEBioOpt/FEDataSource.cpp at develop · febiosoftware/FEBio · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
febiosoftware
/
FEBio
Public
Notifications
You must be signed in to change notification settings
Fork
89
Star
279
Code
Issues
32
Pull requests
1
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
FEBio
/
FEBioOpt
/
FEDataSource.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
547 lines (440 loc) · 13.4 KB
Breadcrumbs
FEBio
/
FEBioOpt
/
FEDataSource.cpp
Copy path
File metadata and controls
547 lines (440 loc) · 13.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
This file is part of the FEBio source code and is licensed under the MIT license
listed below.
See Copyright-FEBio.txt for details.
Copyright (c) 2021 University of Utah, The Trustees of Columbia University in
the City of New York, and others.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#
include
"
stdafx.h
"
#
include
<
cwctype
>
#
include
"
FEDataSource.h
"
#
include
<
FECore/FEModel.h
>
#
include
<
FECore/log.h
>
#
include
<
FECore/NodeDataRecord.h
>
#
include
<
FECore/ElementDataRecord.h
>
#
include
<
FECore/SurfaceDataRecord.h
>
#
include
<
FECore/DomainDataRecord.h
>
//
=================================================================================================
FEDataSource::FEDataSource
(FEModel* fem) : m_fem(*fem)
{
}
FEDataSource::~FEDataSource
()
{
}
bool
FEDataSource::Init
()
{
return
true
;
}
void
FEDataSource::Reset
()
{
}
//
=================================================================================================
bool
FEDataParameter::update
(FEModel* pmdl,
unsigned
int
nwhen,
void
* pd)
{
//
get the optimizaton data
FEDataParameter& src = *((FEDataParameter*)pd);
src.
update
();
return
true
;
}
void
FEDataParameter::update
()
{
//
get the current time value
double
time = m_fem.
GetTime
().
currentTime
;
//
evaluate the current reaction force value
double
x =
m_fx
();
double
y =
m_fy
();
//
add the data pair to the loadcurve
m_rf.
Add
(x, y);
}
FEDataParameter::FEDataParameter
(FEModel* fem) : FEDataSource(fem)
{
m_ord =
"
fem.time
"
;
}
void
FEDataParameter::SetParameterName
(
const
std::string& name)
{
m_param = name;
}
//
set the ordinate name
void
FEDataParameter::SetOrdinateName
(
const
std::string& name)
{
m_ord = name;
}
bool
FEDataParameter::Init
()
{
FEModel* fem = &m_fem;
//
find all the parameters
FEParamValue val = m_fem.
GetParameterValue
(
ParamString
(m_param.
c_str
()));
if
(val.
isValid
() ==
false
) {
//
see if it's a data parameter
if
(
strstr
(m_param.
c_str
(),
"
fem.node_data
"
))
{
char
buf[
256
] = {
0
};
strcpy
(buf, m_param.
c_str
());
char
* sz = buf +
14
;
char
* c1 =
strchr
(sz,
'
,
'
);
*c1++ =
0
;
int
nid =
atoi
(c1);
c1 =
strrchr
(sz,
'
\'
'
);
if
(sz[
0
] ==
'
\'
'
) sz++;
*c1 =
0
;
FELogNodeData* pd = fecore_new<FELogNodeData>(sz, fem);
if
(pd ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid parameter name %s
"
, m_param.
c_str
());
return
false
; }
FEMesh& mesh = fem->
GetMesh
();
FENode* pn = mesh.
FindNodeFromID
(nid);
if
(pn ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid node id
"
);
return
false
; }
m_fy = [=]() {
return
pd->
value
(*pn); };
}
else
if
(
strstr
(m_param.
c_str
(),
"
fem.element_data
"
))
{
char
buf[
256
] = {
0
};
strcpy
(buf, m_param.
c_str
());
char
* sz = buf +
17
;
char
* c1 =
strchr
(sz,
'
,
'
);
*c1++ =
0
;
int
eid =
atoi
(c1);
c1 =
strrchr
(sz,
'
\'
'
);
if
(sz[
0
] ==
'
\'
'
) sz++;
*c1 =
0
;
FELogElemData* pd = fecore_new<FELogElemData>(sz, fem);
if
(pd ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid parameter name %s
"
, m_param.
c_str
());
return
false
; }
FEMesh& mesh = fem->
GetMesh
();
FEElement* pe = mesh.
FindElementFromID
(eid);
if
(pe ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid element id
"
);
return
false
; }
m_fy = [=]() {
return
pd->
value
(*pe); };
}
else
if
(
strstr
(m_param.
c_str
(),
"
fem.surface_data
"
))
{
char
buf[
256
] = {
0
};
strcpy
(buf, m_param.
c_str
());
char
* sz = buf +
17
;
char
* c1 =
strchr
(sz,
'
,
'
);
*c1++ =
0
;
char
* szsurf =
strchr
(c1,
'
\'
'
);
if
(szsurf ==
0
) {
feLogErrorEx
(fem,
"
Syntax error in parameter name %s
"
, m_param.
c_str
());
return
false
; }
szsurf++;
c1 =
strrchr
(sz,
'
\'
'
);
if
(sz[
0
] ==
'
\'
'
) sz++;
*c1 =
0
;
c1 =
strrchr
(szsurf,
'
\'
'
);
if
(c1) *c1 =
0
;
FELogSurfaceData* pd = fecore_new<FELogSurfaceData>(sz, fem);
if
(pd ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid parameter name %s
"
, m_param.
c_str
());
return
false
; }
FEMesh& mesh = fem->
GetMesh
();
FESurface* surf = mesh.
FindSurface
(szsurf);
if
(surf ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid surface name %s
"
, szsurf);
return
false
; }
m_fy = [=]() {
return
pd->
value
(*surf); };
}
else
if
(
strstr
(m_param.
c_str
(),
"
fem.domain_data
"
))
{
const
char
* c = m_param.
c_str
() +
15
;
char
buf[
256
] = {
0
};
int
n =
0
;
bool
skipws =
true
;
while
(c && *c)
{
if
(*c ==
'
\'
'
)
{
if
(skipws) skipws =
false
;
else
skipws =
true
;
}
if
((skipws ==
false
) || (
iswspace
(*c) ==
0
)) buf[n++] = *c;
c++;
}
buf[n] =
0
;
char
* sz = buf;
int
l =
strlen
(sz);
if
(sz[
0
] !=
'
(
'
) {
feLogErrorEx
(fem,
"
Syntax error in parameter name %s
"
, m_param.
c_str
());
return
false
; }
if
(sz[l-
1
] !=
'
)
'
) {
feLogErrorEx
(fem,
"
Syntax error in parameter name %s
"
, m_param.
c_str
());
return
false
; }
sz[l -
1
] =
0
;
*sz++ =
0
;
//
separate string in data variable and domain name
char
* c1 =
strrchr
(sz,
'
,
'
);
*c1++ =
0
;
//
process part name
char
* szdom =
strchr
(c1,
'
\'
'
);
if
(szdom ==
0
) {
feLogErrorEx
(fem,
"
Syntax error in parameter name %s
"
, m_param.
c_str
());
return
false
; }
szdom++;
c1 =
strrchr
(szdom,
'
\'
'
);
if
(c1) *c1 =
0
;
else
{
feLogErrorEx
(fem,
"
Syntax error in parameter name %s
"
, m_param.
c_str
());
return
false
; }
FEMesh& mesh = fem->
GetMesh
();
FEDomain* dom = mesh.
FindDomain
(szdom);
if
(dom ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid domain name %s
"
, szdom);
return
false
; }
//
process data name
FELogDomainData* pd =
nullptr
;
if
(sz[
0
] ==
'
\'
'
)
{
sz++;
c1 =
strrchr
(sz,
'
\'
'
);
if
(c1 ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid domain name %s
"
, szdom);
return
false
; }
*c1 =
0
;
pd = fecore_new<FELogDomainData>(sz, fem);
}
else
{
c1 =
strchr
(sz,
'
(
'
);
if
(c1 ==
nullptr
) {
feLogErrorEx
(fem,
"
Syntax error
"
);
return
false
; }
char
* cvar = c1 +
1
;
*c1 =
0
;
if
((c1 =
strrchr
(cvar,
'
)
'
)) ==
nullptr
) {
feLogErrorEx
(fem,
"
Syntax error
"
);
return
false
; }
*c1 =
0
;
std::vector<std::string> varList;
do
{
if
(cvar[
0
] ==
'
\'
'
)
{
*cvar++ =
0
;
if
((c1 =
strchr
(cvar,
'
\'
'
)) ==
nullptr
) {
feLogErrorEx
(fem,
"
Syntax error
"
);
return
false
; }
*c1 =
0
;
varList.
push_back
(cvar);
cvar = c1 +
1
;
}
else
varList.
push_back
(cvar);
cvar =
strchr
(cvar,
'
,
'
);
if
(cvar) cvar++;
}
while
(cvar && *cvar);
pd = fecore_new<FELogDomainData>(sz, fem);
if
(pd ==
nullptr
) {
feLogErrorEx
(fem,
"
Syntax error
"
);
return
false
; }
if
(pd->
SetParameters
(varList) ==
false
) {
feLogErrorEx
(fem,
"
Syntax error
"
);
return
false
; }
}
if
(pd ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid parameter name %s
"
, m_param.
c_str
());
return
false
; }
m_fy = [=]() {
return
pd->
value
(*dom); };
}
else
{
feLogErrorEx
(fem,
"
Invalid parameter name %s
"
, m_param.
c_str
());
return
false
;
}
}
else
{
if
(val.
type
() !=
FE_PARAM_DOUBLE
) {
feLogErrorEx
(fem,
"
Invalid type for parameter %s
"
, m_param.
c_str
());
return
false
;
}
m_fy = [=]() {
return
val.
value
<
double
>(); };
}
//
find the ordinate
val = m_fem.
GetParameterValue
(
ParamString
(m_ord.
c_str
()));
if
(val.
isValid
() ==
false
) {
//
see if it's a data parameter
if
(
strstr
(m_ord.
c_str
(),
"
fem.node_data
"
))
{
char
buf[
256
] = {
0
};
strcpy
(buf, m_ord.
c_str
());
char
* sz = buf +
14
;
char
* c1 =
strchr
(sz,
'
,
'
);
*c1++ =
0
;
int
nid =
atoi
(c1);
c1 =
strrchr
(sz,
'
\'
'
);
if
(sz[
0
] ==
'
\'
'
) sz++;
*c1 =
0
;
FELogNodeData* pd = fecore_new<FELogNodeData>(sz, fem);
if
(pd ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid ordinate name %s
"
, m_ord.
c_str
());
return
false
; }
FEMesh& mesh = fem->
GetMesh
();
FENode* pn = mesh.
FindNodeFromID
(nid);
if
(pn ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid node id
"
);
return
false
; }
m_fx = [=]() {
return
pd->
value
(*pn); };
}
else
if
(
strstr
(m_ord.
c_str
(),
"
fem.element_data
"
))
{
char
buf[
256
] = {
0
};
strcpy
(buf, m_ord.
c_str
());
char
* sz = buf +
17
;
char
* c1 =
strchr
(sz,
'
,
'
);
*c1++ =
0
;
int
eid =
atoi
(c1);
c1 =
strrchr
(sz,
'
\'
'
);
if
(sz[
0
] ==
'
\'
'
) sz++;
*c1 =
0
;
FELogElemData* pd = fecore_new<FELogElemData>(sz, fem);
if
(pd ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid ordinate name %s
"
, m_ord.
c_str
());
return
false
; }
FEMesh& mesh = fem->
GetMesh
();
FEElement* pe = mesh.
FindElementFromID
(eid);
if
(pe ==
nullptr
) {
feLogErrorEx
(fem,
"
Invalid element id
"
);
return
false
; }
m_fx = [=]() {
return
pd->
value
(*pe); };
}
else
{
feLogErrorEx
(fem,
"
Invalid ordinate name %s
"
, m_ord.
c_str
());
return
false
;
}
}
else
{
if
(val.
type
() !=
FE_PARAM_DOUBLE
) {
feLogErrorEx
(fem,
"
Invalid type for ordinate %s
"
, m_ord.
c_str
());
return
false
;
}
m_fx = [=]() {
return
val.
value
<
double
>(); };
}
//
register callback
m_fem.
AddCallback
(update,
CB_INIT
|
CB_MAJOR_ITERS
, (
void
*)
this
);
return
FEDataSource::Init
();
}
void
FEDataParameter::Reset
()
{
//
reset the reaction force load curve
m_rf.
Clear
();
FEDataSource::Reset
();
}
double
FEDataParameter::Evaluate
(
double
x)
{
return
m_rf.
value
(x);
}
//
=================================================================================================
FEDataFilterPositive::FEDataFilterPositive
(FEModel* fem) : FEDataSource(fem)
{
m_src =
0
;
}
FEDataFilterPositive::~FEDataFilterPositive
()
{
}
void
FEDataFilterPositive::SetDataSource
(FEDataSource* src)
{
m_src = src;
}
bool
FEDataFilterPositive::Init
()
{
if
(m_src ==
0
)
return
false
;
return
m_src->
Init
();
}
void
FEDataFilterPositive::Reset
()
{
if
(m_src) m_src->
Reset
();
}
double
FEDataFilterPositive::Evaluate
(
double
t)
{
double
v = m_src->
Evaluate
(t);
return
(v >=
0.0
? v : -v);
}
//
=================================================================================================
FENodeDataFilterSum::FENodeDataFilterSum
(FEModel* fem) : FEDataSource(fem)
{
m_data =
nullptr
;
m_nodeSet =
nullptr
;
}
FENodeDataFilterSum::~FENodeDataFilterSum
()
{
}
void
FENodeDataFilterSum::SetData
(FELogNodeData* data, FENodeSet* nodeSet)
{
m_data = data;
m_nodeSet = nodeSet;
}
//
Initialize data
bool
FENodeDataFilterSum::Init
()
{
if
(m_data ==
nullptr
)
return
false
;
if
(m_nodeSet ==
nullptr
)
return
false
;
if
(m_data->
Init
() ==
false
)
return
false
;
//
register callback
m_fem.
AddCallback
(update,
CB_MAJOR_ITERS
, (
void
*)
this
);
return
FEDataSource::Init
();
}
//
reset data
void
FENodeDataFilterSum::Reset
()
{
m_rf.
Clear
();
m_rf.
Add
(
0
,
0
);
}
//
evaluate data source at x
double
FENodeDataFilterSum::Evaluate
(
double
x)
{
return
m_rf.
value
(x);
}
bool
FENodeDataFilterSum::update
(FEModel* pmdl,
unsigned
int
nwhen,
void
* pd)
{
//
get the optimizaton data
FENodeDataFilterSum& src = *((FENodeDataFilterSum*)pd);
src.
update
();
return
true
;
}
void
FENodeDataFilterSum::update
()
{
//
get the current time value
double
time = m_fem.
GetTime
().
currentTime
;
FEMesh* mesh = m_nodeSet->
GetMesh
();
FENodeSet& ns = *m_nodeSet;
double
sum =
0.0
;
for
(
int
i =
0
; i < m_nodeSet->
Size
(); ++i)
{
double
vi = m_data->
value
(*ns.
Node
(i));
sum += vi;
}
//
evaluate the current reaction force value
double
x = time;
double
y = sum;
//
add the data pair to the loadcurve
m_rf.
Add
(x, y);
}
FEElemDataFilterSum::FEElemDataFilterSum
(FEModel* fem) : FEDataSource(fem)
{
m_data =
nullptr
;
m_elemSet =
nullptr
;
}
FEElemDataFilterSum::~FEElemDataFilterSum
()
{
}
void
FEElemDataFilterSum::SetData
(FELogElemSource* data, FEElementSet* elemSet)
{
m_data = data;
m_elemSet = elemSet;
}
//
Initialize data
bool
FEElemDataFilterSum::Init
()
{
if
(m_data ==
nullptr
)
return
false
;
if
(m_elemSet ==
nullptr
)
return
false
;
if
(m_data->
Init
() ==
false
)
return
false
;
//
register callback
m_fem.
AddCallback
(update,
CB_MAJOR_ITERS
, (
void
*)
this
);
return
FEDataSource::Init
();
}
//
reset data
void
FEElemDataFilterSum::Reset
()
{
m_rf.
Clear
();
m_rf.
Add
(
0
,
0
);
}
//
evaluate data source at x
double
FEElemDataFilterSum::Evaluate
(
double
x)
{
return
m_rf.
value
(x);
}
bool
FEElemDataFilterSum::update
(FEModel* pmdl,
unsigned
int
nwhen,
void
* pd)
{
//
get the optimizaton data
FEElemDataFilterSum& src = *((FEElemDataFilterSum*)pd);
src.
update
();
return
true
;
}
void
FEElemDataFilterSum::update
()
{
//
get the current time value
double
time = m_fem.
GetTime
().
currentTime
;
FEMesh* mesh = m_elemSet->
GetMesh
();
FEElementSet& eset = *m_elemSet;
double
sum =
0.0
;
for
(
int
i =
0
; i < eset.
Elements
(); ++i)
{
double
vi = m_data->
value
(eset.
Element
(i));
sum += vi;
}
//
evaluate the current reaction force value
double
x = time;
double
y = sum;
//
add the data pair to the loadcurve
m_rf.
Add
(x, y);
}
Back
|
FazBrowse Home
|
New Git URL