forked from topopt/TopOpt_in_PETSc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTopOpt.h
111 lines (89 loc) · 2.88 KB
/
TopOpt.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
#ifndef TOPOPT_H
#define TOPOPT_H
#include <petsc.h>
//#include <petsc-private/dmdaimpl.h>
#include <petsc/private/dmdaimpl.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <math.h>
#include <MMA.h>
/*
Authors: Niels Aage, Erik Andreassen, Boyan Lazarov, August 2013
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.
*/
/*
*
* Parameter container for the topology optimization problem
*
* min_x fx
* s.t. gx_j <= 0, j=1..m
* xmin_i <= x_i <= xmax_i, i=1..n
*
* with filtering and a volume constraint
*
*/
class TopOpt {
public:
// Constructor/Destructor
TopOpt();
~TopOpt();
// Method to allocate MMA with/without restarting
PetscErrorCode AllocateMMAwithRestart(PetscInt *itr, MMA **mma);
PetscErrorCode WriteRestartFiles(PetscInt *itr, MMA *mma);
// Physical domain variables
PetscScalar xc[6]; // Domain coordinates
PetscScalar dx,dy,dz; // Element size
PetscInt nxyz[3]; // Number of nodes in each direction
PetscInt nlvls; // Number of multigrid levels
PetscScalar nu; // Poisson's ratio
// Nodal mesh (contains physics)
DM da_nodes;
// element mesh (contains design)
DM da_elem;
// Optimization parameters
PetscInt n; // Total number of design variables
PetscInt nloc ; // Local number of local nodes?
PetscInt m; // Number of constraints
PetscScalar fx; // Objective value
PetscScalar fscale; // Scaling factor for objective
PetscScalar *gx; // Array with constraint values
PetscScalar Xmin; // Min. value of design variables
PetscScalar Xmax; // Max. value of design variables
PetscScalar movlim; // Max. change of design variables
PetscScalar volfrac; // Volume fraction
PetscScalar penal; // Penalization parameter
PetscScalar Emin, Emax; // Modified SIMP, max and min E
PetscScalar rmin; // filter radius
PetscInt maxItr; // Max iterations
PetscInt filter; // Filter type
Vec x; // Design variables
Vec xPhys; // Physical variables (filtered x)
Vec dfdx; // Sensitivities of objective
Vec xmin, xmax; // Vectors with max and min values of x
Vec xold; // x from previous iteration
Vec *dgdx; // Sensitivities of constraints (vector array)
// Restart data for MMA:
PetscBool restart, flip;
std::string restdens_1,restdens_2;
Vec xo1, xo2, U, L;
private:
// Allocate and set default values
PetscErrorCode SetUp();
PetscErrorCode SetUpMESH();
PetscErrorCode SetUpOPT();
// Restart filenames
std::string filename00, filename00Itr, filename01, filename01Itr;
// File existence
inline PetscBool fexists(const std::string& filename) {
std::ifstream ifile(filename.c_str());
if (ifile) {
return PETSC_TRUE;
}
return PETSC_FALSE;
}
};
#endif