-
Notifications
You must be signed in to change notification settings - Fork 18
/
LinearElasticity.h
173 lines (138 loc) · 5.99 KB
/
LinearElasticity.h
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
#ifndef __LINEARELASTICITY__
#define __LINEARELASTICITY__
#include <fstream>
#include <iostream>
#include <math.h>
#include <petsc.h>
#include <petsc/private/dmdaimpl.h>
#include "options.h" // # new; framework options
/*
Authors: Niels Aage, Erik Andreassen, Boyan Lazarov, August 2013
Updated: June 2019, Niels Aage
Copyright (C) 2013-2019,
Disclaimer:
The authors reserves all rights but does not guaranty that the code is
free from errors. Furthermore, we shall not be liable in any event
caused by the use of the program.
*/
/*
* Modified by Zhidong Brian Zhang in May 2020, University of Waterloo
*/
class LinearElasticity {
public:
// Constructor
LinearElasticity (DM da_nodes, PetscInt m, PetscInt numDES,
PetscInt numLODFIX, PetscInt numNodeLoadAddingCounts, PetscScalar nu,
PetscScalar E, PetscScalar *loadVector, Vec xPassive0, Vec xPassive1,
Vec xPassive2, Vec xPassive3); // # modified
// Destructor
~LinearElasticity ();
// Compute objective and constraints and sensitivities at once: GOOD FOR
// SELF_ADJOINT PROBLEMS
PetscErrorCode ComputeObjectiveConstraintsSensitivities (PetscScalar *fx,
PetscScalar *gx, Vec dfdx, Vec *dgdx, Vec xPhys, PetscScalar Emin,
PetscScalar Emax, PetscScalar penal, PetscScalar volfrac, Vec xPassive0,
Vec xPassive1, Vec xPassive2, Vec xPassive3); // # modified
// Compute objective and constraints for the optimiation
PetscErrorCode ComputeObjectiveConstraints (PetscScalar *fx,
PetscScalar *gx, Vec xPhys, PetscScalar Emin, PetscScalar Emax,
PetscScalar penal, PetscScalar volfrac, Vec xPassive0,
Vec xPassive1, Vec xPassive2, Vec xPassive3); // # modified
// Compute sensitivities
PetscErrorCode ComputeSensitivities (Vec dfdx, Vec *dgdx, Vec xPhys,
PetscScalar Emin, PetscScalar Emax, PetscScalar penal,
PetscScalar volfrac, Vec xPassive0, Vec xPassive1,
Vec xPassive2, Vec xPassive3); // # modified; needs ....
// Restart writer
PetscErrorCode WriteRestartFiles ();
// Get pointer to the FE solution
Vec GetStateField () {
return (U);
}
// Get pointer to DMDA
DM GetDM () {
return (da_nodal);
}
// Logical mesh
DM da_nodal; // Nodal mesh
// # new; FEA with the TopOpt final results
PetscErrorCode FEAWithTopOptResults (Vec xPhys, Vec xPassive0,
Vec xPassive1, Vec xPassive2, Vec xPassive3, PetscInt loadConditionFEA,
PetscScalar *loadVectorFEAp);
private:
// Logical mesh
PetscInt nn[DIM]; // # modified; Number of nodes in each direction
PetscInt ne[DIM]; // # modified; Number of elements in each direction
PetscScalar xc[2 * DIM]; // # modified; Domain coordinates
// Linear algebra
Mat K; // Global stiffness matrix
Vec U; // # modified; Displacement vector
Vec *RHS; // # modified; Load vector
Vec *N; // # modified; Dirichlet vector (used when imposing BCs)
#if DIM == 2 // # new
static const PetscInt nedof = 8; // Number of elemental dofs
#elif DIM == 3 // # new
static const PetscInt nedof = 24; // Number of elemental dofs
#endif
PetscScalar KE[nedof * nedof]; // # new; Element stiffness matrix
// Solver
KSP ksp; // Pointer to the KSP object i.e. the linear solver+prec
PetscInt nlvls;
PetscScalar nu; // Possions ratio
PetscScalar E; // Young's modulus
// Loading conditions
PetscInt numDES; // # new; number of loading conditions
PetscInt numLODFIX; // # new; number of loading conditions
PetscScalar *loadVector; // # new; load vector
PetscInt numNodeLoadAddingCounts; // # new; number of node adding loads during the system assembly
// Element dimensions
PetscScalar dx, dy, dz; // # new
// Number of constraints
PetscInt m; // # new
// Set up the FE mesh, data structures, and load and boundary conditions
PetscErrorCode SetUpLoadAndBC (DM da_nodes, Vec xPassive0, Vec xPassive1,
Vec xPassive2, Vec xPassive3, PetscInt loadCondition); // # modified
// Solve the FE problem
PetscErrorCode SolveState (Vec xPhys, PetscScalar Emin, PetscScalar Emax,
PetscScalar penal, PetscInt loadCondition); // # modified
// Assemble the stiffness matrix
PetscErrorCode AssembleStiffnessMatrix (Vec xPhys, PetscScalar Emin,
PetscScalar Emax, PetscScalar penal, PetscInt loadCondition); // # modified
// Start the solver
PetscErrorCode SetUpSolver ();
#if DIM == 2 // # new
// Routine that doesn't change the element type upon repeated calls
PetscErrorCode DMDAGetElements_2D (DM dm, PetscInt *nel, PetscInt *nen,
const PetscInt *e[]);
// Methods used to assemble the element stiffness matrix
PetscInt Quad4Isoparametric (PetscScalar *X, PetscScalar *Y, PetscScalar nu,
PetscInt redInt, PetscScalar *ke);
void DifferentiatedShapeFunctions_2D (PetscScalar xi, PetscScalar eta,
PetscScalar *dNdxi, PetscScalar *dNdeta);
PetscScalar Inverse2M (PetscScalar J[][2], PetscScalar invJ[][2]);
#elif DIM == 3
// Routine that doesn't change the element type upon repeated calls
PetscErrorCode DMDAGetElements_3D (DM dm, PetscInt *nel, PetscInt *nen,
const PetscInt *e[]);
// Methods used to assemble the element stiffness matrix
PetscInt Hex8Isoparametric (PetscScalar *X, PetscScalar *Y, PetscScalar *Z,
PetscScalar nu, PetscInt redInt, PetscScalar *ke);
void DifferentiatedShapeFunctions (PetscScalar xi, PetscScalar eta,
PetscScalar zeta, PetscScalar *dNdxi, PetscScalar *dNdeta,
PetscScalar *dNdzeta);
PetscScalar Inverse3M (PetscScalar J[][3], PetscScalar invJ[][3]);
#endif
PetscScalar Dot (PetscScalar *v1, PetscScalar *v2, PetscInt l);
// Restart
PetscBool restart, flip;
std::string filename00, filename01;
// File existence
inline PetscBool fexists (const std::string &filename) {
std::ifstream ifile (filename.c_str ());
if (ifile) {
return PETSC_TRUE;
}
return PETSC_FALSE;
}
};
#endif