Skip to content

Commit 30e5405

Browse files
committed
Introduced FELogElemSource class that is now base class of FElogElemData and a new FELogElemDefinition class that allows users to create custom element log data variables. Currently supported are FELogElemAlias, FElogElemFunction, and FELogElemMath.
1 parent 47d6534 commit 30e5405

21 files changed

Lines changed: 277 additions & 52 deletions

FEBioOpt/FEDataSource.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,10 @@ FEDataFilterPositive::FEDataFilterPositive(FEModel* fem) : FEDataSource(fem)
370370

371371
FEDataFilterPositive::~FEDataFilterPositive()
372372
{
373-
if (m_src) delete m_src;
374373
}
375374

376375
void FEDataFilterPositive::SetDataSource(FEDataSource* src)
377376
{
378-
if (m_src) delete m_src;
379377
m_src = src;
380378
}
381379

@@ -407,7 +405,6 @@ FENodeDataFilterSum::FENodeDataFilterSum(FEModel* fem) : FEDataSource(fem)
407405

408406
FENodeDataFilterSum::~FENodeDataFilterSum()
409407
{
410-
delete m_data;
411408
}
412409

413410
void FENodeDataFilterSum::SetData(FELogNodeData* data, FENodeSet* nodeSet)
@@ -482,10 +479,10 @@ FEElemDataFilterSum::FEElemDataFilterSum(FEModel* fem) : FEDataSource(fem)
482479

483480
FEElemDataFilterSum::~FEElemDataFilterSum()
484481
{
485-
delete m_data;
482+
486483
}
487484

488-
void FEElemDataFilterSum::SetData(FELogElemData* data, FEElementSet* elemSet)
485+
void FEElemDataFilterSum::SetData(FELogElemSource* data, FEElementSet* elemSet)
489486
{
490487
m_data = data;
491488
m_elemSet = elemSet;

FEBioOpt/FEDataSource.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class FEElemDataFilterSum : public FEDataSource
158158
FEElemDataFilterSum(FEModel* fem);
159159
~FEElemDataFilterSum();
160160

161-
void SetData(FELogElemData* data, FEElementSet* elemSet);
161+
void SetData(FELogElemSource* data, FEElementSet* elemSet);
162162

163163
// Initialize data
164164
bool Init() override;
@@ -174,7 +174,7 @@ class FEElemDataFilterSum : public FEDataSource
174174
void update();
175175

176176
private:
177-
FELogElemData* m_data;
177+
FELogElemSource* m_data;
178178
FEElementSet* m_elemSet;
179179
PointCurve m_rf;
180180
};

FEBioOpt/FEObjectiveFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool FEMinimizeObjective::ParamFunction::Init()
222222
return true;
223223
}
224224

225-
FEMinimizeObjective::FilterAvgFunction::FilterAvgFunction(FEModel* fem, FELogElemData* pd, FEElementSet* elemSet, double trg) : Function(fem)
225+
FEMinimizeObjective::FilterAvgFunction::FilterAvgFunction(FEModel* fem, FELogElemSource* pd, FEElementSet* elemSet, double trg) : Function(fem)
226226
{
227227
m_pd = pd;
228228
m_elemSet = elemSet;
@@ -323,7 +323,7 @@ void FEElementDataTable::AddValue(int elemID, double v)
323323
m_Data.push_back(d);
324324
}
325325

326-
void FEElementDataTable::SetVariable(FELogElemData* var)
326+
void FEElementDataTable::SetVariable(FELogElemSource* var)
327327
{
328328
m_var = var;
329329
}

FEBioOpt/FEObjectiveFunction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ class FEMinimizeObjective : public FEObjectiveFunction
183183
class FilterAvgFunction : public Function
184184
{
185185
public:
186-
FELogElemData* m_pd = nullptr;
186+
FELogElemSource* m_pd = nullptr;
187187
FEElementSet* m_elemSet = nullptr;
188188
double m_y0 = 0;
189189

190-
FilterAvgFunction(FEModel* fem, FELogElemData* pd, FEElementSet* elemSet, double trg);
190+
FilterAvgFunction(FEModel* fem, FELogElemSource* pd, FEElementSet* elemSet, double trg);
191191

192192
public:
193193
bool Init() override;
@@ -236,7 +236,7 @@ class FEElementDataTable : public FEObjectiveFunction
236236

237237
void AddValue(int elemID, double v);
238238

239-
void SetVariable(FELogElemData* var);
239+
void SetVariable(FELogElemSource* var);
240240

241241
public:
242242
// return number of measurements (i.e. nr of terms in objective function)
@@ -250,7 +250,7 @@ class FEElementDataTable : public FEObjectiveFunction
250250

251251
private:
252252
std::vector<Entry> m_Data;
253-
FELogElemData* m_var;
253+
FELogElemSource* m_var;
254254
};
255255

256256
//=============================================================================

FEBioOpt/FEOptimizeInput.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void FEOptimizeInput::ParseObjectiveTarget(XMLTag& tag)
275275
if (strcmp(sztype, "filter_avg") == 0)
276276
{
277277
FEElementSet* elset = nullptr;
278-
FELogElemData* pdata = nullptr;
278+
FELogElemSource* pdata = nullptr;
279279
double target = 0;
280280
++tag;
281281
do
@@ -334,7 +334,7 @@ void FEOptimizeInput::ParseObjectiveElementData(XMLTag& tag)
334334
const char* sztype = tag.AttributeValue("type");
335335

336336
// try to allocate the element data record
337-
FELogElemData* var = nullptr;
337+
FELogElemSource* var = nullptr;
338338
if (sztype && (sztype[0]=='='))
339339
{
340340
FELogElemMath* logMath = fecore_alloc(FELogElemMath, &fem);
@@ -521,7 +521,7 @@ FEDataSource* FEOptimizeInput::ParseDataSource(XMLTag& tag)
521521
FEElementSet* elemSet = mesh.FindElementSet(szset);
522522
if (elemSet == nullptr) throw XMLReader::InvalidAttributeValue(tag, "elem_set", szset);
523523

524-
FELogElemData* elemData = nullptr;
524+
FELogElemSource* elemData = nullptr;
525525
if (szdata && (szdata[0] == '='))
526526
{
527527
FELogElemMath* logMath = fecore_alloc(FELogElemMath, &fem);

FEBioXML/FEBioOutputSection.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void FEBioOutputSection::ParseLogfile(XMLTag &tag)
145145
}
146146

147147
// get the data attribute
148-
const char* szdata = tag.AttributeValue("data");
148+
const char* szdata = tag.AttributeValue("data", true);
149149

150150
// get the name attribute
151151
const char* szname = tag.AttributeValue("name", true);
@@ -269,7 +269,22 @@ void FEBioOutputSection::ParseLogfile(XMLTag &tag)
269269
{
270270
pdr = new FEModelDataRecord(&fem);
271271
}
272-
else throw XMLReader::InvalidTag(tag);
272+
else if (tag == "define_element_data")
273+
{
274+
if (szname == nullptr) throw XMLReader::MissingAttribute(tag, "name");
275+
const char* sztype = tag.AttributeValue("type");
276+
277+
FELogElemDefinition* pdef = fecore_new<FELogElemDefinition>(sztype, &fem);
278+
if (pdef == nullptr) throw XMLReader::InvalidAttributeValue(tag, "type", sztype);
279+
pdef->SetName(szname);
280+
281+
DataStore& DS = GetFEModel()->GetDataStore();
282+
DS.AddElementDataDefinition(pdef);
283+
284+
ReadParameterList(tag, pdef);
285+
}
286+
else
287+
throw XMLReader::InvalidTag(tag);
273288

274289
if (pdr)
275290
{

FECore/DataStore.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ SOFTWARE.*/
3131
#include "log.h"
3232
#include "FEModel.h"
3333
#include "FEAnalysis.h"
34+
#include "FELogElemMath.h"
35+
#include "FECoreKernel.h"
3436

3537
//-----------------------------------------------------------------------------
36-
DataStore::DataStore()
38+
DataStore::DataStore(FEModel* fem) : m_fem(fem)
3739
{
3840
}
3941

@@ -49,6 +51,16 @@ void DataStore::Clear()
4951
m_data.clear();
5052
}
5153

54+
bool DataStore::Init()
55+
{
56+
for (size_t i = 0; i < m_elemDefs.size(); ++i)
57+
{
58+
auto& def = *m_elemDefs[i];
59+
if (def.Init() == false) return false;
60+
}
61+
return true;
62+
}
63+
5264
//-----------------------------------------------------------------------------
5365

5466
void DataStore::Write()
@@ -67,3 +79,48 @@ void DataStore::AddRecord(DataRecord* prec)
6779
prec->m_nid = (int) m_data.size() + 1;
6880
m_data.push_back(prec);
6981
}
82+
83+
void DataStore::AddElementDataDefinition(FELogElemDefinition* def)
84+
{
85+
m_elemDefs.push_back(def);
86+
}
87+
88+
FELogElemDefinition* DataStore::FindElementDataDefinition(const std::string& name)
89+
{
90+
for (size_t i = 0; i < m_elemDefs.size(); ++i)
91+
{
92+
if (m_elemDefs[i]->GetName() == name) return m_elemDefs[i];
93+
}
94+
return nullptr;
95+
}
96+
97+
FELogElemSource* DataStore::GetElementDataSource(const std::string& name)
98+
{
99+
if (name.empty()) return nullptr;
100+
101+
FELogElemSource* pdata = nullptr;
102+
if (name[0] == '=')
103+
{
104+
FELogElemMath* logMath = fecore_alloc(FELogElemMath, m_fem);
105+
if (logMath)
106+
{
107+
string smath(name.c_str() + 1);
108+
if (logMath->SetExpression(smath))
109+
{
110+
pdata = logMath;
111+
}
112+
}
113+
}
114+
else
115+
{
116+
// try to allocate a built-in element data source
117+
pdata = fecore_new<FELogElemData>(name.c_str(), m_fem);
118+
if (pdata == nullptr)
119+
{
120+
// see if it's a user-defined element data source
121+
pdata = FindElementDataDefinition(name);
122+
}
123+
}
124+
125+
return pdata;
126+
}

FECore/DataStore.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,37 @@ SOFTWARE.*/
2828

2929
#pragma once
3030
#include "DataRecord.h"
31+
#include "FELogElemData.h"
3132
#include "fecore_api.h"
3233

3334
//-----------------------------------------------------------------------------
3435
class FECORE_API DataStore
3536
{
3637
public:
37-
DataStore();
38+
DataStore(FEModel* fem);
3839
virtual ~DataStore();
3940

41+
bool Init();
42+
4043
void Clear();
4144

4245
void Write();
4346

47+
public:
4448
void AddRecord(DataRecord* prec);
4549

4650
int Size() { return (int) m_data.size(); }
4751

4852
DataRecord* GetDataRecord(int i) { return m_data[i]; }
4953

54+
FELogElemSource* GetElementDataSource(const std::string& name);
55+
56+
public:
57+
void AddElementDataDefinition(FELogElemDefinition* def);
58+
FELogElemDefinition* FindElementDataDefinition(const std::string& name);
59+
5060
protected:
61+
FEModel* m_fem = nullptr;
5162
std::vector<DataRecord*> m_data; //!< the data records
63+
std::vector<FELogElemDefinition*> m_elemDefs;
5264
};

FECore/ElementDataRecord.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ ElementDataRecord::ElementDataRecord(FEModel* pfem) : DataRecord(pfem, FE_DATA_E
4242
//-----------------------------------------------------------------------------
4343
void ElementDataRecord::SetData(const char *szexpr)
4444
{
45+
DataStore& DS = GetFEModel()->GetDataStore();
46+
4547
char szcopy[MAX_STRING] = {0};
4648
strcpy(szcopy, szexpr);
4749
char* sz = szcopy, *ch;
@@ -51,21 +53,7 @@ void ElementDataRecord::SetData(const char *szexpr)
5153
{
5254
ch = strchr(sz, ';');
5355
if (ch) *ch++ = 0;
54-
FELogElemData* pdata = nullptr;
55-
if (sz && sz[0] == '=')
56-
{
57-
FELogElemMath* logMath = fecore_alloc(FELogElemMath, GetFEModel());
58-
if (logMath)
59-
{
60-
string smath(sz + 1);
61-
if (logMath->SetExpression(smath))
62-
{
63-
pdata = logMath;
64-
}
65-
}
66-
}
67-
else
68-
pdata = fecore_new<FELogElemData>(sz, GetFEModel());
56+
FELogElemSource* pdata = DS.GetElementDataSource(sz);
6957
if (pdata) m_Data.push_back(pdata);
7058
else throw UnknownDataField(sz);
7159
sz = ch;

FECore/ElementDataRecord.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ class FECORE_API ElementDataRecord : public DataRecord
5757
protected:
5858
vector<ELEMREF> m_ELT;
5959
int m_offset;
60-
vector<FELogElemData*> m_Data;
60+
vector<FELogElemSource*> m_Data;
6161
};

0 commit comments

Comments
 (0)