forked from febiosoftware/FEBio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FEDomain.cpp
198 lines (175 loc) · 5.61 KB
/
FEDomain.cpp
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
/*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 "FEDomain.h"
#include "FEMaterial.h"
#include "DumpStream.h"
#include "FEMesh.h"
#include "FEGlobalMatrix.h"
//-----------------------------------------------------------------------------
FEDomain::FEDomain(int nclass, FEModel* fem) : FEMeshPartition(nclass, fem)
{
}
//-----------------------------------------------------------------------------
void FEDomain::SetMaterial(FEMaterial* pm)
{
assert(pm);
if (pm) pm->AddDomain(this);
}
//-----------------------------------------------------------------------------
void FEDomain::SetMatID(int mid)
{
ForEachElement([=](FEElement& el) { el.SetMatID(mid); });
}
//-----------------------------------------------------------------------------
// This routine allocates the material point data for the element's integration points.
// Currently, this has to be called after the elements have been assigned a type (since this
// determines how many integration points an element gets).
void FEDomain::CreateMaterialPointData()
{
FEMaterial* pmat = GetMaterial();
FEMesh* mesh = GetMesh();
if (pmat) ForEachElement([=](FEElement& el) {
vec3d r[FEElement::MAX_NODES];
int ne = el.Nodes();
for (int i = 0; i < ne; ++i) r[i] = mesh->Node(el.m_node[i]).m_r0;
for (int k = 0; k < el.GaussPoints(); ++k)
{
FEMaterialPoint* mp = pmat->CreateMaterialPointData();
mp->m_r0 = el.Evaluate(r, k);
mp->m_index = k;
el.SetMaterialPointData(mp, k);
}
});
}
//-----------------------------------------------------------------------------
// serialization
void FEDomain::Serialize(DumpStream& ar)
{
FEMeshPartition::Serialize(ar);
if (ar.IsShallow())
{
int NEL = Elements();
for (int i = 0; i < NEL; ++i)
{
FEElement& el = ElementRef(i);
el.Serialize(ar);
int nint = el.GaussPoints();
for (int j = 0; j < nint; ++j) el.GetMaterialPoint(j)->Serialize(ar);
}
}
else
{
if (ar.IsSaving())
{
FEMaterial* mat = GetMaterial();
ar << mat;
int NEL = Elements();
ar << NEL;
for (int i = 0; i < NEL; ++i)
{
FEElement& el = ElementRef(i);
el.Serialize(ar);
int nint = el.GaussPoints();
for (int j = 0; j < nint; ++j) el.GetMaterialPoint(j)->Serialize(ar);
}
}
else
{
FEMaterial* pmat = 0;
ar >> pmat;
SetMaterial(pmat);
FE_Element_Spec espec; // invalid element spec!
int NEL = 0;
ar >> NEL;
Create(NEL, espec);
for (int i = 0; i < NEL; ++i)
{
FEElement& el = ElementRef(i);
el.Serialize(ar);
int nint = el.GaussPoints();
for (int j = 0; j < nint; ++j)
{
el.SetMaterialPointData(pmat->CreateMaterialPointData(), j);
el.GetMaterialPoint(j)->Serialize(ar);
}
}
}
}
}
//-----------------------------------------------------------------------------
//! Unpack the LM data for an element of this domain
void FEDomain::UnpackLM(FEElement& el, vector<int>& lm)
{
UnpackLM(el, GetDOFList(), lm);
}
//-----------------------------------------------------------------------------
//! Activate the domain
void FEDomain::Activate()
{
Activate(GetDOFList());
}
//-----------------------------------------------------------------------------
// This is the default packing method.
// It stores all the degrees of freedom for the first node in the order defined
// by the DOF array, then for the second node, and so on.
void FEDomain::UnpackLM(FEElement& el, const FEDofList& dof, vector<int>& lm)
{
FEMesh* mesh = GetMesh();
int N = el.Nodes();
int ndofs = dof.Size();
lm.resize(N*ndofs);
for (int i = 0; i<N; ++i)
{
int n = el.m_node[i];
FENode& node = mesh->Node(n);
vector<int>& id = node.m_ID;
for (int j = 0; j<ndofs; ++j) lm[i*ndofs + j] = id[dof[j]];
}
}
//-----------------------------------------------------------------------------
void FEDomain::BuildMatrixProfile(FEGlobalMatrix& M)
{
vector<int> elm;
const int NE = Elements();
for (int j = 0; j<NE; ++j)
{
FEElement& el = ElementRef(j);
UnpackLM(el, elm);
M.build_add(elm);
}
}
//-----------------------------------------------------------------------------
void FEDomain::Activate(const FEDofList& dof)
{
// get the number of degrees of freedom for this domain.
const int ndofs = dof.Size();
// activate all the degrees of freedom of this domain
for (int i = 0; i<Nodes(); ++i)
{
FENode& node = Node(i);
if (node.HasFlags(FENode::EXCLUDE) == false)
{
for (int j = 0; j<ndofs; ++j)
if (dof[j] >= 0) node.set_active(dof[j]);
}
}
}