├── .gitignore
├── LICENSE
├── MAgNET.jpg
├── README.md
└── src
├── data
└── README.md
├── femscripts
├── datagen_2dhole.nb
├── datagen_2dlshape.nb
├── datagen_3dbeam.nb
├── datagen_3dbreast.nb
└── preprocess.py
├── main
├── __init__.py
├── connectivity
│ ├── connect_2dhole.csv
│ ├── connect_2dlshape.csv
│ ├── connect_3dbeam.csv
│ ├── connect_3dbreast.csv
│ └── unpad_map_2dlshape.npy
├── global_vars.py
├── layers
│ ├── __init__.py
│ ├── g_pool.py
│ ├── g_unpool.py
│ ├── mag.py
│ └── pool_utils.py
├── main.py
├── models.py
└── utils.py
└── postprocess
├── __init__.py
├── post.py
└── visualisation
├── 2dhole.nb
├── 2dlshape.nb
├── 3dbeam.nb
├── 3dbreast.nb
├── breast.msh
└── examples
├── 2dholemagnet.csv
├── 2dlshapecnn.csv
├── 2dlshapemagnet.csv
├── 3dbeamcnn.csv
├── 3dbeammagnet.csv
└── 3dbreastmagnet.csv
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Saurabh Deshpande
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/MAgNET.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saurabhdeshpande93/MAgNET/b301c1d75a198e083014511f208fa018226ed86b/MAgNET.jpg
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## MAgNET: A Graph U-Net Architecture for Mesh-Based Simulations
2 |
3 | MAgNET is a graph U-Net architecture composed of two novel deep learning layers. The first layer is the Multichannel Aggregation (MAg) layer, which expands upon the idea of multichannel localized operations in convolutional neural networks to accommodate arbitrary graph-structured inputs. And second type of layers are pooling/unpooling layers, designed to facilitate efficient learning on high-dimensional inputs by utilizing reduced representations of arbitrary graph-structured inputs.
4 |
5 |
6 |
7 | 
8 |
9 |
10 |
11 | Sources for MAg and GPool/GUnpool are located in [layers](src/main/layers).
12 |
13 |
14 |
15 | ## Implementation to non-linear Finite Element dataset
16 |
17 | We demonstrate the predictive capabilities of MAgNET in surrogate modeling for non-linear finite element simulations in the mechanics of solids. The supplementary finite element simulation data utilised in the paper is available on [](https://doi.org/10.5281/zenodo.7784804).
18 |
19 | While the scripts to generate non-linear FEM datasets are available in the [femscripts](src/femscripts) directory.
20 |
21 |
22 |
23 |
24 | ## Dependencies
25 |
26 | Scripts have been tested running under Python 3.9.5, with the following packages installed (along with their dependencies). In addition, CUDA 10.1 and cuDNN 7 have been used.
27 |
28 |
29 | - `tensorflow-gpu==2.4.1`
30 | - `keras==2.4.3`
31 | - `numpy==1.19.5`
32 | - `pandas==1.3.4`
33 | - `scikit-learn==1.0.1`
34 |
35 | All the finite element simulations are performed using the [AceFEM](http://symech.fgg.uni-lj.si/Download.htm) library.
36 |
37 |
38 |
39 | ## Instructions
40 |
41 | 1. Download the supplementary data from zenodo and keep it in the src directory.
42 |
43 | 2. MAgNET architectures can be used for inference using the pre-trained weights or can be trained from scratch by running `main.py` script in the [main](src/main) directory.
44 |
45 | 3. Use `post.py` to save the example of interest to further visualise it in Acegen using Mathematica notebooks present in the [visualisation](src/postprocess/visualisation) directory.
46 |
47 |
48 |
49 | ## Cite
50 |
51 | Cite our paper if you use this code in your own work:
52 |
53 | ```
54 | @article{DESHPANDE2024108055,
55 | title = {MAgNET: A graph U-Net architecture for mesh-based simulations},
56 | journal = {Engineering Applications of Artificial Intelligence},
57 | volume = {133},
58 | pages = {108055},
59 | year = {2024},
60 | issn = {0952-1976},
61 | doi = {https://doi.org/10.1016/j.engappai.2024.108055},
62 | url = {https://www.sciencedirect.com/science/article/pii/S0952197624002136},
63 | author = {Saurabh Deshpande and Stéphane P.A. Bordas and Jakub Lengiewicz},
64 | keywords = {Geometric deep learning, Mesh based simulations, Finite element method, Graph U-Net, Surrogate modeling}
65 | }
66 | ```
67 |
68 |
69 |
--------------------------------------------------------------------------------
/src/data/README.md:
--------------------------------------------------------------------------------
1 |
2 | ## Supplementary data
3 |
4 | Replace this directory with [](https://doi.org/10.5281/zenodo.7784804).
5 |
6 | 'data' directory is structured as:
7 |
8 | data
9 | |
10 | |--- FEMData (Training and test data)
11 | |--- predictions (Predictions for entire test sets)
12 | |--- saved_models (Optimised weights for all models)
13 |
--------------------------------------------------------------------------------
/src/femscripts/datagen_2dhole.nb:
--------------------------------------------------------------------------------
1 | (* Content-type: application/vnd.wolfram.mathematica *)
2 |
3 | (*** Wolfram Notebook File ***)
4 | (* http://www.wolfram.com/nb *)
5 |
6 | (* CreatedBy='Mathematica 12.1' *)
7 |
8 | (*CacheID: 234*)
9 | (* Internal cache information:
10 | NotebookFileLineBreakTest
11 | NotebookFileLineBreakTest
12 | NotebookDataPosition[ 158, 7]
13 | NotebookDataLength[ 19786, 436]
14 | NotebookOptionsPosition[ 18712, 413]
15 | NotebookOutlinePosition[ 19181, 431]
16 | CellTagsIndexPosition[ 19138, 428]
17 | WindowFrame->Normal*)
18 |
19 | (* Beginning of Notebook Content *)
20 | Notebook[{
21 | Cell["Start AceFEM ", "Text",
22 | CellChangeTimes->{{3.8867500540624657`*^9, 3.886750061805605*^9}},
23 | Background->RGBColor[
24 | 0.94, 0.91, 0.88],ExpressionUUID->"cb95aaab-038b-47c9-b8b4-38863e44f724"],
25 |
26 | Cell[BoxData[
27 | RowBox[{
28 | RowBox[{"<<", "AceFEM`"}], ";"}]], "Input",
29 | CellChangeTimes->{3.8867500431614237`*^9},
30 | Background->RGBColor[0.87, 0.94, 1],
31 | CellLabel->"In[14]:=",ExpressionUUID->"a2665a78-1d14-446b-a248-3bcc2dc6ea45"],
32 |
33 | Cell["Initialise variables ", "Text",
34 | CellChangeTimes->{{3.886749330021789*^9, 3.8867493413088427`*^9}},
35 | Background->RGBColor[
36 | 0.94, 0.91, 0.88],ExpressionUUID->"a8a679c9-9a51-4438-a19d-50108aa2bb7f"],
37 |
38 | Cell[BoxData[{
39 | RowBox[{
40 | RowBox[{"str", "=",
41 | RowBox[{"OpenWrite", "[", "\"\<2dhole.csv\>\"", "]"}]}], ";"}], "\n",
42 | RowBox[{
43 | RowBox[{"count", " ", "=", " ", "0"}], ";"}], "\[IndentingNewLine]",
44 | RowBox[{
45 | RowBox[{
46 | RowBox[{"noTrainings", "=", "400"}], ";"}], " ",
47 | RowBox[{"(*", " ",
48 | RowBox[{"Number", " ", "of", " ", "examples", " ", "per", " ", "node"}],
49 | " ", "*)"}]}], "\n",
50 | RowBox[{
51 | RowBox[{
52 | RowBox[{"L", "=", "4"}], ";",
53 | RowBox[{"H", "=", "1"}], ";"}], " ",
54 | RowBox[{"(*", " ",
55 | RowBox[{
56 | "Dimensions", " ", "of", " ", "the", " ", "2", "d", " ", "domain"}], " ",
57 | "*)"}]}], "\[IndentingNewLine]",
58 | RowBox[{
59 | RowBox[{"points", "=",
60 | RowBox[{"{",
61 | RowBox[{
62 | RowBox[{"{",
63 | RowBox[{"0", ",", "0"}], "}"}], ",",
64 | RowBox[{"{",
65 | RowBox[{"L", ",", "0"}], "}"}], ",",
66 | RowBox[{"{",
67 | RowBox[{"L", ",", "H"}], "}"}], ",",
68 | RowBox[{"{",
69 | RowBox[{"0", ",", "H"}], "}"}]}], "}"}]}], ";"}], "\n",
70 | RowBox[{
71 | RowBox[{"fMinMax", "=",
72 | RowBox[{"{",
73 | RowBox[{
74 | RowBox[{"-", "5"}], ",", "5"}], "}"}]}], ";", " ",
75 | RowBox[{"(*", " ",
76 | RowBox[{
77 | RowBox[{
78 | "Range", " ", "for", " ", "the", " ", "mangnitude", " ", "of", " ",
79 | "force", " ", "in", " ", "x"}], ",", " ",
80 | RowBox[{"y", " ", "direction"}]}], " ", "*)"}], "\[IndentingNewLine]",
81 | RowBox[{"fnodes", " ", "=", " ",
82 | RowBox[{"{",
83 | RowBox[{
84 | "30", ",", "34", ",", "35", ",", "36", ",", "40", ",", "44", ",", "45",
85 | ",", "56", ",", "63", ",", "76", ",", "88", ",", "98"}], "}"}]}], ";",
86 | RowBox[{"(*", " ",
87 | RowBox[{
88 | "nodes", " ", "on", " ", "which", " ", "point", " ", "loads", " ", "are",
89 | " ",
90 | RowBox[{"applied", ".", " ", "Obtained"}], " ", "using", " ",
91 | RowBox[{"SMTFindNodes", "[",
92 | RowBox[{
93 | RowBox[{"\"\\"", "\[Equal]", "1"}], " ", "&"}], "]"}]}], "*)"}],
94 | "\[IndentingNewLine]",
95 | RowBox[{"ntotal", " ", "=", " ",
96 | RowBox[{"Length", "[", "fnodes", "]"}]}], ";"}]}], "Input",
97 | CellChangeTimes->{
98 | 3.8867494318607407`*^9, {3.886749843542871*^9, 3.886749870734338*^9},
99 | 3.886750083237599*^9, {3.886750135970409*^9, 3.8867502090392303`*^9}, {
100 | 3.886750307029993*^9, 3.886750362568502*^9}, {3.886750471091795*^9,
101 | 3.886750501506271*^9}, {3.886750535488695*^9, 3.886750548961138*^9}, {
102 | 3.886750877770767*^9, 3.886750879401791*^9}, {3.88675824681761*^9,
103 | 3.886758247157035*^9}, 3.8867615229521217`*^9},
104 | Background->RGBColor[
105 | 0.87, 0.94, 1],ExpressionUUID->"55c3bd80-f9cc-44fe-8eab-75745b955f07"],
106 |
107 | Cell["\<\
108 | Start the data generation loop by applying random forces on nodes provided in \
109 | the \[OpenCurlyQuote]fnodes\[CloseCurlyQuote] list.
110 | Nonlinear FEM equations are solved in incremental load steps to avoid the \
111 | divergence. \
112 | \>", "Text",
113 | CellChangeTimes->{
114 | 3.886749449307493*^9, {3.886749597841816*^9, 3.886749598185546*^9}, {
115 | 3.886750088020535*^9, 3.886750129010129*^9}},
116 | Background->RGBColor[
117 | 0.94, 0.91, 0.88],ExpressionUUID->"322d8935-2593-4a70-afde-a65b16d54fad"],
118 |
119 | Cell[BoxData[{
120 | RowBox[{
121 | RowBox[{"Do", "[",
122 | RowBox[{
123 | RowBox[{"Do", "[", "\[IndentingNewLine]",
124 | RowBox[{
125 | RowBox[{
126 | RowBox[{"count", " ", "=", " ",
127 | RowBox[{"count", " ", "+", " ", "1"}]}], ";", "\[IndentingNewLine]",
128 | RowBox[{"If", "[",
129 | RowBox[{
130 | RowBox[{
131 | RowBox[{
132 | RowBox[{"QuotientRemainder", "[",
133 | RowBox[{"count", ",", "200"}], "]"}], "[",
134 | RowBox[{"[", "2", "]"}], "]"}], "\[Equal]", "0"}], ",",
135 | RowBox[{"Print", "[",
136 | RowBox[{"\"\\"", ",", " ", "count"}],
137 | "]"}]}], " ", "]"}], ";", "\[IndentingNewLine]",
138 | RowBox[{"force", "=",
139 | RowBox[{"RandomReal", "[",
140 | RowBox[{"fMinMax", ",",
141 | RowBox[{"{", "2", "}"}]}], "]"}]}], ";", "\[IndentingNewLine]",
142 | "\[IndentingNewLine]",
143 | RowBox[{"SMTInputData", "[", "]"}], ";", "\[IndentingNewLine]",
144 | RowBox[{"SMTAddDomain", "[",
145 | RowBox[{"{",
146 | RowBox[{"\"\<\[CapitalOmega]\>\"", ",",
147 | RowBox[{"{",
148 | RowBox[{
149 | "\"\\"", ",", "\"\\"", ",", "\"\\"", ",",
150 | "\"\\"", ",", "\"\\"", ",", "\"\\"", ",",
151 | "\"\\"", ",", "\"\\"", ",",
152 | RowBox[{"{",
153 | RowBox[{"{",
154 | RowBox[{"\"\\"", ",", "\"\\""}], "}"}], "}"}]}],
155 | "}"}], ",",
156 | RowBox[{"{",
157 | RowBox[{
158 | RowBox[{"\"\\"", "\[Rule]", "500"}], ",",
159 | RowBox[{"\"\<\[Nu] *\>\"", "\[Rule]", "0.3"}]}], "}"}]}], "}"}],
160 | "]"}], ";", "\[IndentingNewLine]",
161 | RowBox[{"SMTAddEssentialBoundary", "[",
162 | RowBox[{
163 | RowBox[{
164 | RowBox[{"\"\\"", "\[Equal]", "0"}], "&"}], ",",
165 | RowBox[{"1", "\[Rule]", "0"}], ",",
166 | RowBox[{"2", "\[Rule]", "0"}]}], "]"}], ";", "\[IndentingNewLine]",
167 | RowBox[{"mesh", "=",
168 | RowBox[{"ToElementMesh", "[",
169 | RowBox[{
170 | RowBox[{"ImplicitRegion", "[",
171 | RowBox[{
172 | RowBox[{
173 | RowBox[{
174 | RowBox[{
175 | RowBox[{"(",
176 | RowBox[{"x", "-", "3"}], ")"}], "^", "2"}], "+",
177 | RowBox[{
178 | RowBox[{"(",
179 | RowBox[{"y", "-", "0.5"}], ")"}], "^", "2"}]}], ">", "0.1"}],
180 | ",",
181 | RowBox[{"{",
182 | RowBox[{"x", ",", "y"}], "}"}]}], "]"}], ",",
183 | RowBox[{"{",
184 | RowBox[{
185 | RowBox[{"{",
186 | RowBox[{"0", ",", "L"}], "}"}], ",",
187 | RowBox[{"{",
188 | RowBox[{"0", ",", "H"}], "}"}]}], "}"}], ",",
189 | RowBox[{"\"\\"", "\[Rule]", "1"}], ",",
190 | RowBox[{"MaxCellMeasure", "\[Rule]", "1"}]}], "]"}]}], ";",
191 | RowBox[{"SMTAddMesh", "[",
192 | RowBox[{"mesh", ",", "\"\<\[CapitalOmega]\>\""}], "]"}], ";",
193 | "\[IndentingNewLine]",
194 | RowBox[{"SMTAnalysis", "[", "]"}], ";", "\[IndentingNewLine]",
195 | "\[IndentingNewLine]",
196 | RowBox[{"SMTAddNaturalBoundary", "[",
197 | RowBox[{
198 | RowBox[{"Point", "[",
199 | RowBox[{"SMTNodeData", "[",
200 | RowBox[{
201 | RowBox[{"fnodes", "[",
202 | RowBox[{"[", "ix", "]"}], "]"}], ",", "\"\\""}], "]"}],
203 | "]"}], ",",
204 | RowBox[{"1", "\[Rule]",
205 | RowBox[{"force", "[",
206 | RowBox[{"[", "1", "]"}], "]"}]}], ",",
207 | RowBox[{"2", "\[Rule]",
208 | RowBox[{"force", "[",
209 | RowBox[{"[", "2", "]"}], "]"}]}]}], "]"}], ";",
210 | "\[IndentingNewLine]", "\[IndentingNewLine]",
211 | RowBox[{"\[Lambda]Max", "=", "1"}], ";",
212 | RowBox[{"\[Lambda]0", "=", "\[Lambda]Max"}], ";",
213 | RowBox[{"\[CapitalDelta]\[Lambda]Min", "=",
214 | RowBox[{"\[Lambda]Max", "/", "1000"}]}], ";",
215 | RowBox[{"\[CapitalDelta]\[Lambda]Max", "=", "\[Lambda]Max"}], ";",
216 | "\[IndentingNewLine]",
217 | RowBox[{"tolNR", "=",
218 | RowBox[{"10", "^",
219 | RowBox[{"-", "8"}]}]}], ";",
220 | RowBox[{"maxNR", "=", "15"}], ";",
221 | RowBox[{"targetNR", "=", "8"}], ";", "\[IndentingNewLine]",
222 | RowBox[{"SMTNextStep", "[",
223 | RowBox[{"\"\<\[Lambda]\>\"", "\[Rule]", "\[Lambda]0"}], "]"}], ";",
224 | "\[IndentingNewLine]",
225 | RowBox[{"While", "[", "\[IndentingNewLine]",
226 | RowBox[{
227 | RowBox[{
228 | RowBox[{"While", "[", "\[IndentingNewLine]",
229 | RowBox[{
230 | RowBox[{"step", "=",
231 | RowBox[{"SMTConvergence", "[",
232 | RowBox[{"tolNR", ",", "maxNR", ",",
233 | RowBox[{"{",
234 | RowBox[{
235 | "\"\\"", ",", "targetNR", ",",
236 | "\[CapitalDelta]\[Lambda]Min", ",",
237 | "\[CapitalDelta]\[Lambda]Max", ",", "\[Lambda]Max"}],
238 | "}"}]}], "]"}]}], "\[IndentingNewLine]", ",", " ",
239 | RowBox[{
240 | RowBox[{"SMTNewtonIteration", "[", "]"}], ";"}]}],
241 | "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]",
242 | RowBox[{"If", "[",
243 | RowBox[{
244 | RowBox[{
245 | RowBox[{
246 | "step", "\[LeftDoubleBracket]", "4", "\[RightDoubleBracket]"}],
247 | "===", "\"\\""}], ",",
248 | RowBox[{
249 | RowBox[{"SMTStatusReport", "[", "\"\\"", "]"}], ";",
250 | RowBox[{"SMTStepBack", "[", "]"}], ";"}]}], "]"}], ";",
251 | "\[IndentingNewLine]",
252 | RowBox[{
253 | "step", "\[LeftDoubleBracket]", "3", "\[RightDoubleBracket]"}]}],
254 | " ", "\[IndentingNewLine]", ",",
255 | RowBox[{
256 | RowBox[{"If", "[",
257 | RowBox[{
258 | RowBox[{
259 | "step", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}],
260 | ",",
261 | RowBox[{
262 | RowBox[{"SMTStepBack", "[", "]"}], ";"}]}], "]"}], ";",
263 | "\[IndentingNewLine]",
264 | RowBox[{"SMTNextStep", "[",
265 | RowBox[{"\"\<\[CapitalDelta]\[Lambda]\>\"", "\[Rule]",
266 | RowBox[{
267 | "step", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}],
268 | "]"}]}]}], "\[IndentingNewLine]", "]"}], ";",
269 | "\[IndentingNewLine]", "\n", " ",
270 | RowBox[{"dispData", "=",
271 | RowBox[{"SMTNodeData", "[", "\"\\"", "]"}]}], ";", "\n",
272 | " ",
273 | RowBox[{"forceData", "=",
274 | RowBox[{"ConstantArray", "[",
275 | RowBox[{
276 | RowBox[{"{",
277 | RowBox[{"0", ",", "0"}], "}"}], ",", "SMTNoNodes"}], "]"}]}], ";",
278 | "\n", " ",
279 | RowBox[{
280 | RowBox[{"forceData", "[",
281 | RowBox[{"[",
282 | RowBox[{
283 | RowBox[{"SMTFindNodes", "[",
284 | RowBox[{"Point", "[",
285 | RowBox[{"SMTNodeData", "[",
286 | RowBox[{
287 | RowBox[{"fnodes", "[",
288 | RowBox[{"[", "ix", "]"}], "]"}], ",", "\"\\""}], "]"}],
289 | "]"}], "]"}], "[",
290 | RowBox[{"[", "1", "]"}], "]"}], "]"}], "]"}], "=", "force"}], ";",
291 | "\n", " ",
292 | RowBox[{"data", "=",
293 | RowBox[{"Transpose", "[",
294 | RowBox[{"{",
295 | RowBox[{
296 | RowBox[{"Flatten", "[", "forceData", "]"}], ",",
297 | RowBox[{"Flatten", "[", "dispData", "]"}]}], "}"}], "]"}]}], ";",
298 | "\[IndentingNewLine]",
299 | RowBox[{"Write", "[",
300 | RowBox[{"str", ",",
301 | RowBox[{"OutputForm", "[",
302 | RowBox[{"StringTrim", "[",
303 | RowBox[{"ExportString", "[",
304 | RowBox[{"data", ",", "\"\\""}], "]"}], "]"}], "]"}]}],
305 | "]"}], ";"}], "\[IndentingNewLine]", ",", "noTrainings"}], "]"}], ",",
306 | RowBox[{"{",
307 | RowBox[{"ix", ",", "ntotal", ",", "1", ",",
308 | RowBox[{"-", "1"}]}], "}"}]}], "]"}], ";"}], "\[IndentingNewLine]",
309 | RowBox[{
310 | RowBox[{"Close", "[", "str", "]"}], ";"}]}], "Input",
311 | CellChangeTimes->{
312 | 3.821965192044854*^9, {3.8219653154195557`*^9, 3.8219653189953995`*^9}, {
313 | 3.8219655397845397`*^9, 3.8219655864450216`*^9}, {3.821965710134426*^9,
314 | 3.8219657350041943`*^9}, {3.8219657828942485`*^9,
315 | 3.8219658015948415`*^9}, {3.8219665355432262`*^9,
316 | 3.8219665401324463`*^9}, {3.821966847511552*^9, 3.821966849751898*^9}, {
317 | 3.821966920841444*^9, 3.8219669233415604`*^9}, {3.8219669893214054`*^9,
318 | 3.8219670791012683`*^9}, {3.821967122331189*^9, 3.82196716523065*^9}, {
319 | 3.8219671973207536`*^9, 3.821967260351164*^9}, {3.821967304220663*^9,
320 | 3.8219673107368546`*^9}, {3.8221241416830587`*^9, 3.822124194147181*^9}, {
321 | 3.8221242404481792`*^9, 3.822124240592225*^9}, {3.8221242875783453`*^9,
322 | 3.822124295123638*^9}, 3.822139543350972*^9, {3.822140457772345*^9,
323 | 3.8221405235475187`*^9}, {3.822140730834997*^9, 3.822140740285911*^9}, {
324 | 3.822141117046734*^9, 3.822141202399768*^9}, {3.822141267221489*^9,
325 | 3.8221412673962717`*^9}, 3.822141307037161*^9, {3.822141575035481*^9,
326 | 3.822141639669756*^9}, 3.822141745231423*^9, {3.8221417823205833`*^9,
327 | 3.8221417874791803`*^9}, {3.82214197021202*^9, 3.822141976099279*^9}, {
328 | 3.822142092470138*^9, 3.82214211111882*^9}, {3.822142202971827*^9,
329 | 3.8221422250581408`*^9}, {3.8221422725938377`*^9, 3.822142272991407*^9}, {
330 | 3.822654426378932*^9, 3.822654426427167*^9}, {3.822654495241746*^9,
331 | 3.822654540582633*^9}, {3.822654634648336*^9, 3.822654662506812*^9}, {
332 | 3.822656254413233*^9, 3.822656260256075*^9}, {3.822656300284781*^9,
333 | 3.8226563226642427`*^9}, {3.822656395224551*^9, 3.822656436494863*^9}, {
334 | 3.822656490617902*^9, 3.82265649065287*^9}, {3.8226565491337137`*^9,
335 | 3.8226565839259357`*^9}, {3.8226567343788157`*^9, 3.822656735810171*^9}, {
336 | 3.8226570493699923`*^9, 3.82265705141556*^9}, {3.8254931332368402`*^9,
337 | 3.825493175060429*^9}, {3.825493217203763*^9, 3.8254932913902817`*^9},
338 | 3.825493339104052*^9, {3.825493376179337*^9, 3.8254934141082973`*^9}, {
339 | 3.8254934737606087`*^9, 3.8254934918675117`*^9}, 3.825493528673787*^9, {
340 | 3.8254949924881496`*^9, 3.825495048202458*^9}, {3.8254959303138723`*^9,
341 | 3.82549596490524*^9}, {3.825496048578911*^9, 3.82549605848689*^9}, {
342 | 3.825496112071883*^9, 3.825496125661634*^9}, {3.8254962903332243`*^9,
343 | 3.825496320339239*^9}, {3.825511417642839*^9, 3.825511438725836*^9}, {
344 | 3.8255115575559483`*^9, 3.8255115593973303`*^9}, {3.825595141773703*^9,
345 | 3.825595156620282*^9}, {3.831539428321787*^9, 3.831539494016539*^9}, {
346 | 3.831540579752222*^9, 3.8315406027651377`*^9}, {3.8315406401619577`*^9,
347 | 3.831540640749992*^9}, {3.831541112543934*^9, 3.831541112599615*^9}, {
348 | 3.8316660956288433`*^9, 3.831666123397357*^9}, {3.8317461728889313`*^9,
349 | 3.8317461834348183`*^9}, {3.831746248089954*^9, 3.831746312358238*^9}, {
350 | 3.83174639690373*^9, 3.831746435813846*^9}, {3.8317469078192863`*^9,
351 | 3.831746917020805*^9}, {3.8321352349888773`*^9, 3.8321352591492434`*^9}, {
352 | 3.832135649251347*^9, 3.83213566851049*^9}, {3.8321364244071407`*^9,
353 | 3.832136441504654*^9}, {3.832136945519353*^9, 3.832136966094544*^9}, {
354 | 3.832476609788207*^9, 3.8324766598797483`*^9}, {3.832557337455909*^9,
355 | 3.8325573497598667`*^9}, {3.833287537522161*^9, 3.833287550068927*^9},
356 | 3.833287800057768*^9, {3.833300947324387*^9, 3.833300953212232*^9}, {
357 | 3.8335153331722383`*^9, 3.833515342613603*^9}, {3.834311121768818*^9,
358 | 3.834311138032061*^9}, {3.834311215480112*^9, 3.8343112423876143`*^9}, {
359 | 3.835082065958465*^9, 3.835082087205077*^9}, 3.835162922526888*^9, {
360 | 3.835241490916497*^9, 3.835241503109651*^9}, {3.854609943583509*^9,
361 | 3.854609945685597*^9}, {3.854610051177617*^9, 3.8546100907415752`*^9}, {
362 | 3.854610122886209*^9, 3.8546101229099197`*^9}, {3.854610160849771*^9,
363 | 3.854610228904871*^9}, {3.8546102979948463`*^9, 3.8546103094851418`*^9},
364 | 3.859511947908472*^9, {3.859511995185315*^9, 3.859512008994154*^9}, {
365 | 3.860053330513054*^9, 3.860053363820912*^9}, {3.860053577721846*^9,
366 | 3.860053584810158*^9}, 3.860053617561412*^9, 3.86005365038883*^9, {
367 | 3.8600536977401047`*^9, 3.8600537189096193`*^9}, 3.860053768378895*^9, {
368 | 3.860053803232006*^9, 3.86005381318511*^9}, 3.860053848457139*^9, {
369 | 3.86005390971282*^9, 3.860053922543666*^9}, {3.8600607377452517`*^9,
370 | 3.860060769406006*^9}, {3.860060917336913*^9, 3.860060953271481*^9}, {
371 | 3.86006108375139*^9, 3.860061085426832*^9}, {3.860061144345109*^9,
372 | 3.86006116552497*^9}, 3.8600624862659397`*^9, {3.860078670781857*^9,
373 | 3.860078671004154*^9}, {3.860078809064108*^9, 3.860078810098551*^9}, {
374 | 3.869924399129694*^9, 3.869924401996571*^9}, 3.869924601088356*^9, {
375 | 3.869924689569829*^9, 3.869924694786701*^9}, {3.886749370961598*^9,
376 | 3.886749411260113*^9}, {3.886749471760263*^9, 3.8867495104239264`*^9},
377 | 3.886749847392501*^9, {3.886750514587121*^9, 3.886750586848199*^9}, {
378 | 3.886751194973837*^9, 3.886751213767396*^9}, {3.8867514392671013`*^9,
379 | 3.886751440124166*^9}, {3.886751476498486*^9, 3.886751479281823*^9}, {
380 | 3.886754169242684*^9, 3.886754223486622*^9}, {3.8867542553059607`*^9,
381 | 3.886754262190567*^9}, 3.8867545303646803`*^9, 3.886754587421139*^9, {
382 | 3.88675467397999*^9, 3.886754719357572*^9}, {3.8867547755598097`*^9,
383 | 3.886754780645525*^9}, {3.886754853390584*^9, 3.8867548545203943`*^9},
384 | 3.886754890334724*^9, {3.886754929921597*^9, 3.886754939365498*^9}, {
385 | 3.886761616326561*^9, 3.886761631628985*^9}},
386 | Background->RGBColor[
387 | 0.87, 0.94, 1],ExpressionUUID->"4798baed-be29-492f-8f8b-bd6d61f81a6e"],
388 |
389 | Cell["Save the element connectivity matrix (topology of the mesh)", "Text",
390 | CellChangeTimes->{{3.886749537693083*^9, 3.88674955495541*^9}},
391 | Background->RGBColor[
392 | 0.94, 0.91, 0.88],ExpressionUUID->"b0026e1c-df6a-42a7-b2a1-0593e9862506"],
393 |
394 | Cell[BoxData[{
395 | RowBox[{
396 | RowBox[{"elements", "=", " ", "SMTElements"}], ";"}], "\[IndentingNewLine]",
397 | RowBox[{
398 | RowBox[{"connectivity", " ", "=", " ",
399 | RowBox[{"elements", "[",
400 | RowBox[{"[",
401 | RowBox[{"All", ",", "3"}], "]"}], "]"}]}], ";"}], "\[IndentingNewLine]",
402 | RowBox[{
403 | RowBox[{"Export", "[",
404 | RowBox[{
405 | "\"\<../main/connectivity/connect_2dhole.csv\>\"", ",", "connectivity"}],
406 | "]"}], ";"}]}], "Input",
407 | CellChangeTimes->{{3.8595121753657207`*^9, 3.859512190909903*^9}, {
408 | 3.8600537955197372`*^9, 3.860053797026778*^9}, {3.886749618627297*^9,
409 | 3.886749638034384*^9}, 3.886749714282317*^9, 3.886753043093046*^9,
410 | 3.888580445585188*^9},
411 | Background->RGBColor[
412 | 0.87, 0.94, 1],ExpressionUUID->"d366eead-7ab1-4f47-bf10-26902e84fecc"]
413 | },
414 | WindowSize->{1481, 806},
415 | WindowMargins->{{3682, Automatic}, {-77, Automatic}},
416 | TaggingRules->{"TryRealOnly" -> False},
417 | Magnification:>1.25 Inherited,
418 | FrontEndVersion->"12.1 for Mac OS X x86 (64-bit) (March 13, 2020)",
419 | StyleDefinitions->"Default.nb",
420 | ExpressionUUID->"afd3d2f2-b59f-49d9-b374-9cc1921237d0"
421 | ]
422 | (* End of Notebook Content *)
423 |
424 | (* Internal cache information *)
425 | (*CellTagsOutline
426 | CellTagsIndex->{}
427 | *)
428 | (*CellTagsIndex
429 | CellTagsIndex->{}
430 | *)
431 | (*NotebookFileOutline
432 | Notebook[{
433 | Cell[558, 20, 196, 3, 64, "Text",ExpressionUUID->"cb95aaab-038b-47c9-b8b4-38863e44f724"],
434 | Cell[757, 25, 230, 5, 57, "Input",ExpressionUUID->"a2665a78-1d14-446b-a248-3bcc2dc6ea45"],
435 | Cell[990, 32, 204, 3, 64, "Text",ExpressionUUID->"a8a679c9-9a51-4438-a19d-50108aa2bb7f"],
436 | Cell[1197, 37, 2542, 67, 266, "Input",ExpressionUUID->"55c3bd80-f9cc-44fe-8eab-75745b955f07"],
437 | Cell[3742, 106, 486, 10, 93, "Text",ExpressionUUID->"322d8935-2593-4a70-afde-a65b16d54fad"],
438 | Cell[4231, 118, 13460, 268, 942, "Input",ExpressionUUID->"4798baed-be29-492f-8f8b-bd6d61f81a6e"],
439 | Cell[17694, 388, 239, 3, 64, "Text",ExpressionUUID->"b0026e1c-df6a-42a7-b2a1-0593e9862506"],
440 | Cell[17936, 393, 772, 18, 110, "Input",ExpressionUUID->"d366eead-7ab1-4f47-bf10-26902e84fecc"]
441 | }
442 | ]
443 | *)
444 |
445 |
--------------------------------------------------------------------------------
/src/femscripts/datagen_2dlshape.nb:
--------------------------------------------------------------------------------
1 | (* Content-type: application/vnd.wolfram.mathematica *)
2 |
3 | (*** Wolfram Notebook File ***)
4 | (* http://www.wolfram.com/nb *)
5 |
6 | (* CreatedBy='Mathematica 12.1' *)
7 |
8 | (*CacheID: 234*)
9 | (* Internal cache information:
10 | NotebookFileLineBreakTest
11 | NotebookFileLineBreakTest
12 | NotebookDataPosition[ 158, 7]
13 | NotebookDataLength[ 20355, 463]
14 | NotebookOptionsPosition[ 19320, 441]
15 | NotebookOutlinePosition[ 19750, 458]
16 | CellTagsIndexPosition[ 19707, 455]
17 | WindowFrame->Normal*)
18 |
19 | (* Beginning of Notebook Content *)
20 | Notebook[{
21 | Cell["Start AceFEM ", "Text",
22 | CellChangeTimes->{{3.8867500540624657`*^9, 3.886750061805605*^9}},
23 | Background->RGBColor[
24 | 0.94, 0.91, 0.88],ExpressionUUID->"45a63fd7-ebf9-4afe-bec5-86facf53f4db"],
25 |
26 | Cell[BoxData[
27 | RowBox[{
28 | RowBox[{"<<", "AceFEM`"}], ";"}]], "Input",
29 | CellChangeTimes->{3.8867500431614237`*^9},
30 | Background->RGBColor[0.87, 0.94, 1],
31 | CellLabel->"In[14]:=",ExpressionUUID->"5650789f-7306-4a16-a082-93e09349bc87"],
32 |
33 | Cell["Initialise variables ", "Text",
34 | CellChangeTimes->{{3.886749330021789*^9, 3.8867493413088427`*^9}},
35 | Background->RGBColor[
36 | 0.94, 0.91, 0.88],ExpressionUUID->"f4d2a67c-ce4e-4826-b735-b72c300b868e"],
37 |
38 | Cell[BoxData[{
39 | RowBox[{
40 | RowBox[{"str", "=",
41 | RowBox[{"OpenWrite", "[", "\"\<2dlshape.csv\>\"", "]"}]}], ";"}], "\n",
42 | RowBox[{
43 | RowBox[{"count", " ", "=", "0"}], ";"}], "\[IndentingNewLine]",
44 | RowBox[{
45 | RowBox[{"noTrainings", "=", "1000"}], ";"}], "\n",
46 | RowBox[{
47 | RowBox[{"L", "=", "6"}], ";",
48 | RowBox[{"H", "=", "2"}], ";",
49 | RowBox[{"H2", "=",
50 | RowBox[{"6", "/", "7"}]}], ";",
51 | RowBox[{"nx", "=", "12"}], ";",
52 | RowBox[{"ny", "=", "3"}], ";", " ",
53 | RowBox[{"nx2", "=", "3"}], ";", " ",
54 | RowBox[{"ny2", "=", "7"}], ";"}], "\[IndentingNewLine]",
55 | RowBox[{
56 | RowBox[{"ntx", " ", "=", " ",
57 | RowBox[{"nx", "+", "nx2"}]}], ";", " ",
58 | RowBox[{"nty", " ", "=", " ", "ny2"}], ";"}], "\[IndentingNewLine]",
59 | RowBox[{
60 | RowBox[{"points", "=",
61 | RowBox[{"{",
62 | RowBox[{
63 | RowBox[{"{",
64 | RowBox[{"0", ",", "0"}], "}"}], ",",
65 | RowBox[{"{",
66 | RowBox[{
67 | RowBox[{"4", "*",
68 | RowBox[{"L", "/", "5"}]}], ",", "0"}], "}"}], ",",
69 | RowBox[{"{",
70 | RowBox[{
71 | RowBox[{"4", "*",
72 | RowBox[{"L", "/", "5"}]}], ",", "H2"}], "}"}], ",",
73 | RowBox[{"{",
74 | RowBox[{"0", ",", "H2"}], "}"}]}], "}"}]}],
75 | ";"}], "\[IndentingNewLine]",
76 | RowBox[{
77 | RowBox[{"points2", "=",
78 | RowBox[{"{",
79 | RowBox[{
80 | RowBox[{"{",
81 | RowBox[{
82 | RowBox[{"4", "*",
83 | RowBox[{"L", "/", "5"}]}], ",", "0"}], "}"}], ",",
84 | RowBox[{"{",
85 | RowBox[{"L", ",", "0"}], "}"}], ",",
86 | RowBox[{"{",
87 | RowBox[{"L", ",", "H"}], "}"}], ",",
88 | RowBox[{"{",
89 | RowBox[{
90 | RowBox[{"4", "*",
91 | RowBox[{"L", "/", "5"}]}], ",", "H"}], "}"}]}], "}"}]}],
92 | ";"}], "\[IndentingNewLine]",
93 | RowBox[{
94 | RowBox[{"hx", "=",
95 | RowBox[{"L", "/", "ntx"}]}], ";",
96 | RowBox[{"hy", "=",
97 | RowBox[{"H", "/", "nty"}]}], ";"}], "\[IndentingNewLine]",
98 | RowBox[{
99 | RowBox[{"fMinMax", "=",
100 | RowBox[{"{",
101 | RowBox[{
102 | RowBox[{"-", "1.0"}], ",", "1.0"}], "}"}]}], ";"}]}], "Input",
103 | CellChangeTimes->{
104 | 3.886763094503565*^9, {3.886763133275679*^9, 3.8867631335472383`*^9}},
105 | Background->RGBColor[
106 | 0.87, 0.94, 1],ExpressionUUID->"83507a54-0b8f-48d1-a140-51e074d40df5"],
107 |
108 | Cell["Start the data-generation loop ", "Text",
109 | CellChangeTimes->{{3.886763112628151*^9, 3.886763121196658*^9}},
110 | Background->RGBColor[
111 | 0.94, 0.91, 0.88],ExpressionUUID->"73342590-697b-4df0-a7d6-8d46f83e44bf"],
112 |
113 | Cell[BoxData[{
114 | RowBox[{
115 | RowBox[{"Do", "[",
116 | RowBox[{
117 | RowBox[{"Do", "[", "\[IndentingNewLine]",
118 | RowBox[{
119 | RowBox[{
120 | RowBox[{"count", " ", "=", " ",
121 | RowBox[{"count", " ", "+", " ", "1"}]}], ";", "\[IndentingNewLine]",
122 | RowBox[{"If", "[",
123 | RowBox[{
124 | RowBox[{
125 | RowBox[{
126 | RowBox[{"QuotientRemainder", "[",
127 | RowBox[{"count", ",", "100"}], "]"}], "[",
128 | RowBox[{"[", "2", "]"}], "]"}], "\[Equal]", "0"}], ",",
129 | RowBox[{"Print", "[",
130 | RowBox[{"\"\\"", ",", " ", "count"}],
131 | "]"}]}], " ", "]"}], ";", "\[IndentingNewLine]",
132 | "\[IndentingNewLine]",
133 | RowBox[{"force", "=",
134 | RowBox[{"RandomReal", "[",
135 | RowBox[{"fMinMax", ",",
136 | RowBox[{"{", "2", "}"}]}], "]"}]}], ";", "\[IndentingNewLine]",
137 | "\[IndentingNewLine]",
138 | RowBox[{"SMTInputData", "[", "]"}], ";", "\[IndentingNewLine]",
139 | RowBox[{"SMTAddDomain", "[",
140 | RowBox[{
141 | "\"\<\[CapitalOmega]\>\"", ",", "\"\\"",
142 | ",",
143 | RowBox[{"{",
144 | RowBox[{
145 | RowBox[{"\"\\"", "\[Rule]", "500"}], ",",
146 | RowBox[{"\"\<\[Nu] *\>\"", "->", "0.4"}]}], "}"}]}], "]"}], ";",
147 | "\n", " ",
148 | RowBox[{"SMTAddEssentialBoundary", "[",
149 | RowBox[{
150 | RowBox[{
151 | RowBox[{"\"\\"", "==", "0"}], "&"}], ",",
152 | RowBox[{"1", "\[Rule]", "0"}], ",",
153 | RowBox[{"2", "\[Rule]", "0"}]}], "]"}], ";", "\n", " ",
154 | RowBox[{"SMTAddNaturalBoundary", "[",
155 | RowBox[{
156 | RowBox[{"Point", "[",
157 | RowBox[{
158 | RowBox[{"{",
159 | RowBox[{"ix", ",", "nty"}], "}"}],
160 | RowBox[{"{",
161 | RowBox[{
162 | RowBox[{"L", "/", "ntx"}], ",",
163 | RowBox[{"H", "/", "nty"}]}], "}"}]}], "]"}], ",",
164 | RowBox[{"1", "\[Rule]",
165 | RowBox[{"force", "[",
166 | RowBox[{"[", "1", "]"}], "]"}]}], ",",
167 | RowBox[{"2", "\[Rule]",
168 | RowBox[{"force", "[",
169 | RowBox[{"[", "2", "]"}], "]"}]}]}], "]"}], ";", "\n", " ",
170 | RowBox[{"SMTAddMesh", "[",
171 | RowBox[{
172 | RowBox[{"Polygon", "[", "points", "]"}], ",",
173 | "\"\<\[CapitalOmega]\>\"", ",", "\"\\"", ",",
174 | RowBox[{"{",
175 | RowBox[{"nx", ",", "ny"}], "}"}]}], "]"}], ";", "\n", " ",
176 | RowBox[{"SMTAddMesh", "[",
177 | RowBox[{
178 | RowBox[{"Polygon", "[", "points2", "]"}], ",",
179 | "\"\<\[CapitalOmega]\>\"", ",", "\"\\"", ",",
180 | RowBox[{"{",
181 | RowBox[{"nx2", ",", "ny2"}], "}"}]}], "]"}], ";",
182 | "\[IndentingNewLine]", "\[IndentingNewLine]",
183 | RowBox[{"SMTAnalysis", "[", "]"}], ";", "\[IndentingNewLine]",
184 | RowBox[{"\[Lambda]Max", "=", "1"}], ";",
185 | RowBox[{"\[Lambda]0", "=", "\[Lambda]Max"}], ";",
186 | RowBox[{"\[CapitalDelta]\[Lambda]Min", "=",
187 | RowBox[{"\[Lambda]Max", "/", "1000"}]}], ";",
188 | RowBox[{"\[CapitalDelta]\[Lambda]Max", "=", "\[Lambda]Max"}], ";",
189 | "\[IndentingNewLine]",
190 | RowBox[{"tolNR", "=",
191 | RowBox[{"10", "^",
192 | RowBox[{"-", "8"}]}]}], ";",
193 | RowBox[{"maxNR", "=", "15"}], ";",
194 | RowBox[{"targetNR", "=", "8"}], ";", "\[IndentingNewLine]",
195 | RowBox[{"SMTNextStep", "[",
196 | RowBox[{"\"\<\[Lambda]\>\"", "\[Rule]", "\[Lambda]0"}], "]"}], ";",
197 | "\[IndentingNewLine]",
198 | RowBox[{"While", "[", "\[IndentingNewLine]",
199 | RowBox[{
200 | RowBox[{
201 | RowBox[{"While", "[", "\[IndentingNewLine]",
202 | RowBox[{
203 | RowBox[{"step", "=",
204 | RowBox[{"SMTConvergence", "[",
205 | RowBox[{"tolNR", ",", "maxNR", ",",
206 | RowBox[{"{",
207 | RowBox[{
208 | "\"\\"", ",", "targetNR", ",",
209 | "\[CapitalDelta]\[Lambda]Min", ",",
210 | "\[CapitalDelta]\[Lambda]Max", ",", "\[Lambda]Max"}],
211 | "}"}]}], "]"}]}], "\[IndentingNewLine]", ",", " ",
212 | RowBox[{
213 | RowBox[{"SMTNewtonIteration", "[", "]"}], ";"}]}],
214 | "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]",
215 | RowBox[{"If", "[",
216 | RowBox[{
217 | RowBox[{
218 | RowBox[{
219 | "step", "\[LeftDoubleBracket]", "4", "\[RightDoubleBracket]"}],
220 | "===", "\"\\""}], ",",
221 | RowBox[{
222 | RowBox[{"SMTStatusReport", "[", "\"\\"", "]"}], ";",
223 | RowBox[{"SMTStepBack", "[", "]"}], ";"}]}], "]"}], ";",
224 | "\[IndentingNewLine]",
225 | RowBox[{
226 | "step", "\[LeftDoubleBracket]", "3", "\[RightDoubleBracket]"}]}],
227 | " ", "\[IndentingNewLine]", ",",
228 | RowBox[{
229 | RowBox[{"If", "[",
230 | RowBox[{
231 | RowBox[{
232 | "step", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}],
233 | ",",
234 | RowBox[{
235 | RowBox[{"SMTStepBack", "[", "]"}], ";"}]}], "]"}], ";",
236 | "\[IndentingNewLine]",
237 | RowBox[{"SMTNextStep", "[",
238 | RowBox[{"\"\<\[CapitalDelta]\[Lambda]\>\"", "\[Rule]",
239 | RowBox[{
240 | "step", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}],
241 | "]"}]}]}], "\[IndentingNewLine]", "]"}], ";",
242 | "\[IndentingNewLine]", "\[IndentingNewLine]",
243 | RowBox[{"(*", " ",
244 | RowBox[{
245 | "Zero", " ", "padding", " ", "step", " ", "to", " ", "make", " ",
246 | "input", " ", "compatible", " ", "to", " ", "be", " ", "used", " ",
247 | "for", " ", "CNNs"}], " ", "*)"}], "\n", " ",
248 | RowBox[{"a", " ", "=", " ",
249 | RowBox[{"Map", "[",
250 | RowBox[{
251 | RowBox[{
252 | RowBox[{"(",
253 | RowBox[{
254 | RowBox[{
255 | RowBox[{"{",
256 | RowBox[{"x", ",", "y"}], "}"}], "=", "#"}], ";",
257 | RowBox[{"Round", "[",
258 | RowBox[{
259 | RowBox[{
260 | RowBox[{"(",
261 | RowBox[{"x", "/", "hx"}], ")"}],
262 | RowBox[{"(",
263 | RowBox[{
264 | RowBox[{"H", "/", "hy"}], "+", "1"}], ")"}]}], "+",
265 | RowBox[{"y", "/", "hy"}], "+", "1"}], "]"}]}], ")"}], "&"}],
266 | ",",
267 | RowBox[{"SMTNodeData", "[", "\"\\"", "]"}]}], "]"}]}], ";",
268 | "\[IndentingNewLine]",
269 | RowBox[{"dispData", "=", " ",
270 | RowBox[{"ConstantArray", "[",
271 | RowBox[{
272 | RowBox[{"{",
273 | RowBox[{"0", ",", "0"}], "}"}], ",",
274 | RowBox[{
275 | RowBox[{"(",
276 | RowBox[{"ntx", "+", "1"}], ")"}], "*",
277 | RowBox[{"(",
278 | RowBox[{"nty", "+", "1"}], ")"}]}]}], "]"}]}], ";",
279 | "\[IndentingNewLine]",
280 | RowBox[{
281 | RowBox[{"dispData", "[",
282 | RowBox[{"[", "a", "]"}], "]"}], "=",
283 | RowBox[{"SMTNodeData", "[", "\"\\"", "]"}]}], ";",
284 | "\[IndentingNewLine]", "\[IndentingNewLine]",
285 | RowBox[{"forceDatapad", " ", "=", " ",
286 | RowBox[{"ConstantArray", "[",
287 | RowBox[{
288 | RowBox[{"{",
289 | RowBox[{"0", ",", "0"}], "}"}], ",",
290 | RowBox[{
291 | RowBox[{"(",
292 | RowBox[{"ntx", "+", "1"}], ")"}], "*",
293 | RowBox[{"(",
294 | RowBox[{"nty", "+", "1"}], ")"}]}]}], "]"}]}], ";", " ",
295 | "\[IndentingNewLine]",
296 | RowBox[{"forceData", "=",
297 | RowBox[{"ConstantArray", "[",
298 | RowBox[{
299 | RowBox[{"{",
300 | RowBox[{"0", ",", "0"}], "}"}], ",", "SMTNoNodes"}], "]"}]}], ";",
301 | "\n", " ",
302 | RowBox[{
303 | RowBox[{"forceData", "[",
304 | RowBox[{"[",
305 | RowBox[{
306 | RowBox[{"SMTFindNodes", "[",
307 | RowBox[{"Point", "[",
308 | RowBox[{
309 | RowBox[{"{",
310 | RowBox[{"ix", ",", "nty"}], "}"}],
311 | RowBox[{"{",
312 | RowBox[{
313 | RowBox[{"L", "/", "ntx"}], ",",
314 | RowBox[{"H", "/", "nty"}]}], "}"}]}], "]"}], "]"}], "[",
315 | RowBox[{"[", "1", "]"}], "]"}], "]"}], "]"}], "=", "force"}], ";",
316 | "\[IndentingNewLine]",
317 | RowBox[{
318 | RowBox[{"forceDatapad", "[",
319 | RowBox[{"[", "a", "]"}], "]"}], " ", "=", " ", "forceData"}], ";",
320 | "\n", "\[IndentingNewLine]",
321 | RowBox[{"data", "=",
322 | RowBox[{"Transpose", "[",
323 | RowBox[{"{",
324 | RowBox[{
325 | RowBox[{"Flatten", "[", "forceDatapad", "]"}], ",",
326 | RowBox[{"Flatten", "[", "dispData", "]"}]}], "}"}], "]"}]}], ";",
327 | "\n", " ",
328 | RowBox[{"Write", "[",
329 | RowBox[{"str", ",",
330 | RowBox[{"OutputForm", "[",
331 | RowBox[{"StringTrim", "[",
332 | RowBox[{"ExportString", "[",
333 | RowBox[{"data", ",", "\"\\""}], "]"}], "]"}], "]"}]}],
334 | "]"}], ";"}], "\[IndentingNewLine]", ",", "noTrainings"}], "]"}], ",",
335 | RowBox[{"{",
336 | RowBox[{"ix", ",", "nx", ",", "ntx"}], "}"}]}], "]"}],
337 | ";"}], "\[IndentingNewLine]",
338 | RowBox[{
339 | RowBox[{"Close", "[", "str", "]"}], ";"}]}], "Input",
340 | CellChangeTimes->{
341 | 3.821965192044854*^9, {3.8219653154195557`*^9, 3.8219653189953995`*^9}, {
342 | 3.8219655397845397`*^9, 3.8219655864450216`*^9}, {3.821965710134426*^9,
343 | 3.8219657350041943`*^9}, {3.8219657828942485`*^9,
344 | 3.8219658015948415`*^9}, {3.8219665355432262`*^9,
345 | 3.8219665401324463`*^9}, {3.821966847511552*^9, 3.821966849751898*^9}, {
346 | 3.821966920841444*^9, 3.8219669233415604`*^9}, {3.8219669893214054`*^9,
347 | 3.8219670791012683`*^9}, {3.821967122331189*^9, 3.82196716523065*^9}, {
348 | 3.8219671973207536`*^9, 3.821967260351164*^9}, {3.821967304220663*^9,
349 | 3.8219673107368546`*^9}, {3.8221241416830587`*^9, 3.822124194147181*^9}, {
350 | 3.8221242404481792`*^9, 3.822124240592225*^9}, {3.8221242875783453`*^9,
351 | 3.822124295123638*^9}, 3.822139543350972*^9, {3.822140457772345*^9,
352 | 3.8221405235475187`*^9}, {3.822140730834997*^9, 3.822140740285911*^9}, {
353 | 3.822141117046734*^9, 3.822141202399768*^9}, {3.822141267221489*^9,
354 | 3.8221412673962717`*^9}, 3.822141307037161*^9, {3.822141575035481*^9,
355 | 3.822141639669756*^9}, 3.822141745231423*^9, {3.8221417823205833`*^9,
356 | 3.8221417874791803`*^9}, {3.82214197021202*^9, 3.822141976099279*^9}, {
357 | 3.822142092470138*^9, 3.82214211111882*^9}, {3.822142202971827*^9,
358 | 3.8221422250581408`*^9}, {3.8221422725938377`*^9, 3.822142272991407*^9}, {
359 | 3.822654426378932*^9, 3.822654426427167*^9}, {3.822654495241746*^9,
360 | 3.822654540582633*^9}, {3.822654634648336*^9, 3.822654662506812*^9}, {
361 | 3.822656254413233*^9, 3.822656260256075*^9}, {3.822656300284781*^9,
362 | 3.8226563226642427`*^9}, {3.822656395224551*^9, 3.822656436494863*^9}, {
363 | 3.822656490617902*^9, 3.82265649065287*^9}, {3.8226565491337137`*^9,
364 | 3.8226565839259357`*^9}, {3.8226567343788157`*^9, 3.822656735810171*^9}, {
365 | 3.8226570493699923`*^9, 3.82265705141556*^9}, {3.8254931332368402`*^9,
366 | 3.825493175060429*^9}, {3.825493217203763*^9, 3.8254932913902817`*^9},
367 | 3.825493339104052*^9, {3.825493376179337*^9, 3.8254934141082973`*^9}, {
368 | 3.8254934737606087`*^9, 3.8254934918675117`*^9}, 3.825493528673787*^9, {
369 | 3.8254949924881496`*^9, 3.825495048202458*^9}, {3.8254959303138723`*^9,
370 | 3.82549596490524*^9}, {3.825496048578911*^9, 3.82549605848689*^9}, {
371 | 3.825496112071883*^9, 3.825496125661634*^9}, {3.8254962903332243`*^9,
372 | 3.825496320339239*^9}, {3.825511417642839*^9, 3.825511438725836*^9}, {
373 | 3.8255115575559483`*^9, 3.8255115593973303`*^9}, {3.825595141773703*^9,
374 | 3.825595156620282*^9}, {3.827987689632758*^9, 3.8279876980057163`*^9}, {
375 | 3.82798817806607*^9, 3.827988257987124*^9}, {3.827988456768091*^9,
376 | 3.827988537872569*^9}, {3.827988601657734*^9, 3.827988675388229*^9}, {
377 | 3.82798873052322*^9, 3.827988766652604*^9}, {3.8279888327271643`*^9,
378 | 3.827988833270499*^9}, {3.827988942132016*^9, 3.827988942835457*^9}, {
379 | 3.827989116109681*^9, 3.8279891161956453`*^9}, {3.8279892642942333`*^9,
380 | 3.827989295648918*^9}, {3.8279894352706947`*^9, 3.827989463906386*^9}, {
381 | 3.827993642165086*^9, 3.827993666946126*^9}, {3.827993703849545*^9,
382 | 3.82799370582521*^9}, {3.8279939648293467`*^9, 3.827994029494875*^9}, {
383 | 3.827994089690242*^9, 3.8279940901927967`*^9}, {3.827994238046195*^9,
384 | 3.827994292925908*^9}, {3.8279943397343807`*^9, 3.827994339989107*^9}, {
385 | 3.828080159863842*^9, 3.828080162375189*^9}, 3.8280823159310637`*^9, {
386 | 3.82808235441116*^9, 3.828082359298596*^9}, {3.828082446550805*^9,
387 | 3.8280824722222233`*^9}, {3.8280830062784758`*^9,
388 | 3.8280830104407673`*^9}, {3.828083085254216*^9, 3.828083092633354*^9}, {
389 | 3.8280831228220043`*^9, 3.828083132220759*^9}, {3.828083175411886*^9,
390 | 3.828083208628812*^9}, {3.828520976194586*^9, 3.828520976650131*^9}, {
391 | 3.82852823900845*^9, 3.828528239419785*^9}, {3.830317109261979*^9,
392 | 3.830317117133668*^9}, {3.830317147395599*^9, 3.830317171132547*^9}, {
393 | 3.830317225050706*^9, 3.8303172413302937`*^9}, {3.830317428167159*^9,
394 | 3.830317440427329*^9}, {3.830317482084693*^9, 3.8303175107787027`*^9}, {
395 | 3.8303176826181583`*^9, 3.830317758522751*^9}, {3.83031788033541*^9,
396 | 3.8303179438754396`*^9}, {3.830318225653551*^9, 3.830318232873714*^9}, {
397 | 3.8303235686504908`*^9, 3.8303236038164577`*^9}, {3.830328061750646*^9,
398 | 3.830328075463883*^9}, {3.8305068409971333`*^9, 3.8305068649506807`*^9}, {
399 | 3.830508057958014*^9, 3.830508076949965*^9}, 3.830508314449415*^9,
400 | 3.830508353075094*^9, {3.83050848715408*^9, 3.830508509675399*^9}, {
401 | 3.8305086407319117`*^9, 3.830508641741984*^9}, {3.830527526422708*^9,
402 | 3.8305275600424643`*^9}, {3.831729751335424*^9, 3.8317298417606*^9}, {
403 | 3.83172987323573*^9, 3.8317298813181868`*^9}, {3.831729934920775*^9,
404 | 3.831730003904006*^9}, 3.831730064923625*^9, {3.83173016876715*^9,
405 | 3.83173016884741*^9}, {3.8317304243299513`*^9, 3.831730441332569*^9}, {
406 | 3.831730711692953*^9, 3.831730714188188*^9}, 3.831730803503851*^9, {
407 | 3.831731076867614*^9, 3.831731077191291*^9}, {3.833089278273612*^9,
408 | 3.8330892835124893`*^9}, {3.8330893169251547`*^9, 3.833089318473606*^9}, {
409 | 3.834028037237917*^9, 3.834028047022088*^9}, 3.8340283733207817`*^9, {
410 | 3.834037284751246*^9, 3.834037284989908*^9}, {3.834299854525585*^9,
411 | 3.8342998873703623`*^9}, {3.886763058441082*^9, 3.886763091282894*^9}, {
412 | 3.8867631370137997`*^9, 3.886763144211894*^9}, {3.886763184917571*^9,
413 | 3.886763337517836*^9}, {3.886763386022367*^9, 3.8867635254924173`*^9}},
414 | Background->RGBColor[
415 | 0.87, 0.94, 1],ExpressionUUID->"4798baed-be29-492f-8f8b-bd6d61f81a6e"],
416 |
417 | Cell["Save the element connectivity matrix (topology of the mesh)", "Text",
418 | CellChangeTimes->{{3.886749537693083*^9, 3.88674955495541*^9}},
419 | Background->RGBColor[
420 | 0.94, 0.91, 0.88],ExpressionUUID->"5641b47e-ddb5-4afa-9982-e812bed0bbe5"],
421 |
422 | Cell[BoxData[{
423 | RowBox[{
424 | RowBox[{"elements", "=", " ", "SMTElements"}], ";"}], "\[IndentingNewLine]",
425 | RowBox[{
426 | RowBox[{"connectivity", " ", "=", " ",
427 | RowBox[{"elements", "[",
428 | RowBox[{"[",
429 | RowBox[{"All", ",", "3"}], "]"}], "]"}]}], ";"}], "\[IndentingNewLine]",
430 | RowBox[{
431 | RowBox[{"Export", "[",
432 | RowBox[{
433 | "\"\<../main/connectivity/connect_2dlshape.csv\>\"", ",", "connectivity"}],
434 | "]"}], ";"}]}], "Input",
435 | CellChangeTimes->{{3.8595121753657207`*^9, 3.859512190909903*^9}, {
436 | 3.8600537955197372`*^9, 3.860053797026778*^9}, {3.886749618627297*^9,
437 | 3.886749638034384*^9}, 3.886749714282317*^9, 3.886753043093046*^9, {
438 | 3.886763168852957*^9, 3.886763169562682*^9}, 3.888580463947233*^9},
439 | Background->RGBColor[
440 | 0.87, 0.94, 1],ExpressionUUID->"e9324ed3-e64a-4bda-80ae-5b3785b25237"]
441 | },
442 | WindowSize->{1404, 769},
443 | WindowMargins->{{Automatic, -1765}, {-90, Automatic}},
444 | Magnification:>1.25 Inherited,
445 | FrontEndVersion->"12.1 for Mac OS X x86 (64-bit) (March 13, 2020)",
446 | StyleDefinitions->"Default.nb",
447 | ExpressionUUID->"c130e6f3-7300-4c6a-98e1-f37ac45195d5"
448 | ]
449 | (* End of Notebook Content *)
450 |
451 | (* Internal cache information *)
452 | (*CellTagsOutline
453 | CellTagsIndex->{}
454 | *)
455 | (*CellTagsIndex
456 | CellTagsIndex->{}
457 | *)
458 | (*NotebookFileOutline
459 | Notebook[{
460 | Cell[558, 20, 196, 3, 64, "Text",ExpressionUUID->"45a63fd7-ebf9-4afe-bec5-86facf53f4db"],
461 | Cell[757, 25, 230, 5, 57, "Input",ExpressionUUID->"5650789f-7306-4a16-a082-93e09349bc87"],
462 | Cell[990, 32, 204, 3, 64, "Text",ExpressionUUID->"f4d2a67c-ce4e-4826-b735-b72c300b868e"],
463 | Cell[1197, 37, 2155, 68, 266, "Input",ExpressionUUID->"83507a54-0b8f-48d1-a140-51e074d40df5"],
464 | Cell[3355, 107, 212, 3, 64, "Text",ExpressionUUID->"73342590-697b-4df0-a7d6-8d46f83e44bf"],
465 | Cell[3570, 112, 14681, 302, 1124, "Input",ExpressionUUID->"4798baed-be29-492f-8f8b-bd6d61f81a6e"],
466 | Cell[18254, 416, 239, 3, 64, "Text",ExpressionUUID->"5641b47e-ddb5-4afa-9982-e812bed0bbe5"],
467 | Cell[18496, 421, 820, 18, 110, "Input",ExpressionUUID->"e9324ed3-e64a-4bda-80ae-5b3785b25237"]
468 | }
469 | ]
470 | *)
471 |
472 |
--------------------------------------------------------------------------------
/src/femscripts/datagen_3dbeam.nb:
--------------------------------------------------------------------------------
1 | (* Content-type: application/vnd.wolfram.mathematica *)
2 |
3 | (*** Wolfram Notebook File ***)
4 | (* http://www.wolfram.com/nb *)
5 |
6 | (* CreatedBy='Mathematica 12.1' *)
7 |
8 | (*CacheID: 234*)
9 | (* Internal cache information:
10 | NotebookFileLineBreakTest
11 | NotebookFileLineBreakTest
12 | NotebookDataPosition[ 158, 7]
13 | NotebookDataLength[ 14507, 347]
14 | NotebookOptionsPosition[ 13565, 326]
15 | NotebookOutlinePosition[ 13994, 343]
16 | CellTagsIndexPosition[ 13951, 340]
17 | WindowFrame->Normal*)
18 |
19 | (* Beginning of Notebook Content *)
20 | Notebook[{
21 | Cell[BoxData[
22 | RowBox[{
23 | RowBox[{"<<", "AceFEM`"}], ";"}]], "Input",
24 | CellChangeTimes->{{3.821960854645931*^9, 3.8219608753257465`*^9}},
25 | Background->RGBColor[0.87, 0.94, 1],
26 | CellLabel->"In[1]:=",ExpressionUUID->"bfdda654-c2f4-45f7-90d9-e46c25286ea2"],
27 |
28 | Cell["Initialise the variables ", "Text",
29 | CellChangeTimes->{{3.886759041586936*^9, 3.886759047498005*^9}},
30 | Background->RGBColor[
31 | 0.94, 0.91, 0.88],ExpressionUUID->"9cf7c054-3bdb-4c14-9445-4d8d051ecb32"],
32 |
33 | Cell[BoxData[{
34 | RowBox[{
35 | RowBox[{
36 | RowBox[{"str", "=",
37 | RowBox[{"OpenWrite", "[", "\"\<3dbeam.csv\>\"", "]"}]}], ";"}],
38 | " "}], "\n",
39 | RowBox[{
40 | RowBox[{"noTrainings", "=", "110"}], ";", " ",
41 | RowBox[{"(*", " ",
42 | RowBox[{"Number", " ", "of", " ", "examples", " ", "per", " ", "node"}],
43 | " ", "*)"}], "\n",
44 | RowBox[{"L", "=", "4"}], ";",
45 | RowBox[{"H", "=", "1"}], ";",
46 | RowBox[{"V", "=", "1"}], ";",
47 | RowBox[{"nx", "=", "27"}], " ", ";",
48 | RowBox[{"ny", "=", "11"}], " ", ";",
49 | RowBox[{"nz", "=", "11"}], " ", ";", " ",
50 | RowBox[{"(*", " ",
51 | RowBox[{
52 | "Dimensions", " ", "of", " ", "the", " ", "2", "d", " ", "domain"}], " ",
53 | "*)"}], "\[IndentingNewLine]",
54 | RowBox[{"points", "=",
55 | RowBox[{"{",
56 | RowBox[{
57 | RowBox[{"{",
58 | RowBox[{"0", ",", "0", ",", "0"}], "}"}], ",",
59 | RowBox[{"{",
60 | RowBox[{"L", ",", "0", ",", "0"}], "}"}], ",",
61 | RowBox[{"{",
62 | RowBox[{"L", ",", "H", ",", "0"}], "}"}], ",",
63 | RowBox[{"{",
64 | RowBox[{"0", ",", "H", ",", "0"}], "}"}], ",",
65 | RowBox[{"{",
66 | RowBox[{"0", ",", "0", ",", "V"}], "}"}], ",",
67 | RowBox[{"{",
68 | RowBox[{"L", ",", "0", ",", "V"}], "}"}], ",",
69 | RowBox[{"{",
70 | RowBox[{"L", ",", "H", ",", " ", "V"}], "}"}], ",",
71 | RowBox[{"{",
72 | RowBox[{"0", ",", "H", ",", " ", "V"}], "}"}]}], "}"}]}], ";"}], "\n",
73 | RowBox[{
74 | RowBox[{"fMinMax", "=",
75 | RowBox[{"{",
76 | RowBox[{
77 | RowBox[{"-", "2"}], ",", "2"}], "}"}]}], ";", " ",
78 | RowBox[{"(*", " ",
79 | RowBox[{
80 | "Range", " ", "for", " ", "the", " ", "mangnitude", " ", "of", " ",
81 | "force", " ", "in", " ", "each", " ", "direction"}], " ",
82 | "*)"}]}]}], "Input",
83 | CellChangeTimes->{
84 | 3.8867590647478333`*^9, {3.886759173220069*^9, 3.8867591738512707`*^9}, {
85 | 3.8867592545968323`*^9, 3.886759262812035*^9}, {3.8867595026012907`*^9,
86 | 3.8867595032785883`*^9}, {3.886759686605502*^9, 3.886759696088447*^9}, {
87 | 3.886759948039256*^9, 3.886759948145823*^9}, {3.886761494920457*^9,
88 | 3.8867615745181627`*^9}},
89 | Background->RGBColor[
90 | 0.87, 0.94, 1],ExpressionUUID->"b7bdd5ab-e26d-442b-8ddc-b7fcbbebf384"],
91 |
92 | Cell["\<\
93 | Start the data generation loop of applying random point loads on the top \
94 | surface of the 3D beam. Again, point loads are applied in incremental steps \
95 | to avoid divergence of the solver. \
96 | \>", "Text",
97 | CellChangeTimes->{{3.886759184908367*^9, 3.8867592217236233`*^9}, {
98 | 3.8867613398548603`*^9, 3.886761371645998*^9}},
99 | Background->RGBColor[
100 | 0.94, 0.91, 0.88],ExpressionUUID->"2636dfaf-4b1c-4152-ad52-9773214b36b5"],
101 |
102 | Cell[BoxData[{
103 | RowBox[{
104 | RowBox[{"Do", "[",
105 | RowBox[{
106 | RowBox[{"Do", "[", "\[IndentingNewLine]",
107 | RowBox[{
108 | RowBox[{
109 | RowBox[{"force", "=",
110 | RowBox[{"RandomReal", "[",
111 | RowBox[{"fMinMax", ",",
112 | RowBox[{"{", "3", "}"}]}], "]"}]}], ";", "\[IndentingNewLine]",
113 | RowBox[{"SMTInputData", "[", "]"}], ";", "\[IndentingNewLine]",
114 | RowBox[{"SMTAddDomain", "[",
115 | RowBox[{
116 | "\"\<\[CapitalOmega]\>\"", ",", "\"\\"",
117 | ",",
118 | RowBox[{"{",
119 | RowBox[{
120 | RowBox[{"\"\\"", "\[Rule]", "500"}], ",",
121 | RowBox[{"\"\<\[Nu] *\>\"", "->", "0.4"}]}], "}"}]}], "]"}], ";",
122 | "\n", " ",
123 | RowBox[{"SMTAddEssentialBoundary", "[",
124 | RowBox[{
125 | RowBox[{"Polygon", "[",
126 | RowBox[{"{",
127 | RowBox[{
128 | RowBox[{"{",
129 | RowBox[{"0", ",", "0", ",", "0"}], "}"}], ",",
130 | RowBox[{"{",
131 | RowBox[{"0", ",", "H", ",", "0"}], "}"}], ",",
132 | RowBox[{"{",
133 | RowBox[{"0", ",", "H", ",", "V"}], "}"}], ",",
134 | RowBox[{"{",
135 | RowBox[{"0", ",", "0", ",", "V"}], "}"}]}], "}"}], "]"}], ",",
136 | RowBox[{"1", "\[Rule]", "0"}], ",",
137 | RowBox[{"2", "->", "0"}], ",",
138 | RowBox[{"3", "->", "0"}]}], "]"}], ";", "\n", " ",
139 | RowBox[{"SMTAddNaturalBoundary", "[",
140 | RowBox[{
141 | RowBox[{"Point", "[",
142 | RowBox[{
143 | RowBox[{"{",
144 | RowBox[{"ix", ",", "iy", ",", "nz"}], "}"}],
145 | RowBox[{"{",
146 | RowBox[{
147 | RowBox[{"L", "/", "nx"}], ",",
148 | RowBox[{"H", "/", "ny"}], ",",
149 | RowBox[{"V", "/", "nz"}]}], "}"}]}], "]"}], ",",
150 | RowBox[{"1", "\[Rule]",
151 | RowBox[{"force", "[",
152 | RowBox[{"[", "1", "]"}], "]"}]}], ",",
153 | RowBox[{"2", "\[Rule]",
154 | RowBox[{"force", "[",
155 | RowBox[{"[", "2", "]"}], "]"}]}], ",",
156 | RowBox[{"3", "\[Rule]",
157 | RowBox[{"force", "[",
158 | RowBox[{"[", "3", "]"}], "]"}]}]}], "]"}], ";", "\n", " ",
159 | RowBox[{"SMTAddMesh", "[",
160 | RowBox[{
161 | RowBox[{"Hexahedron", "[", "points", "]"}], ",",
162 | "\"\<\[CapitalOmega]\>\"", ",", "\"\\"", ",",
163 | RowBox[{"{",
164 | RowBox[{"nx", ",", "ny", ",", "nz"}], "}"}]}], "]"}], ";", "\n",
165 | " ", "\[IndentingNewLine]",
166 | RowBox[{"SMTAnalysis", "[", "]"}], ";", "\n", "\[IndentingNewLine]",
167 | RowBox[{"\[Lambda]Max", "=", "1"}], ";",
168 | RowBox[{"\[Lambda]0", "=", "\[Lambda]Max"}], ";",
169 | RowBox[{"\[CapitalDelta]\[Lambda]Min", "=",
170 | RowBox[{"\[Lambda]Max", "/", "1000"}]}], ";",
171 | RowBox[{"\[CapitalDelta]\[Lambda]Max", "=", "\[Lambda]Max"}], ";",
172 | "\[IndentingNewLine]",
173 | RowBox[{"tolNR", "=",
174 | RowBox[{"10", "^",
175 | RowBox[{"-", "8"}]}]}], ";",
176 | RowBox[{"maxNR", "=", "15"}], ";",
177 | RowBox[{"targetNR", "=", "8"}], ";", "\[IndentingNewLine]",
178 | RowBox[{"SMTNextStep", "[",
179 | RowBox[{"\"\<\[Lambda]\>\"", "\[Rule]", "\[Lambda]0"}], "]"}], ";",
180 | "\[IndentingNewLine]",
181 | RowBox[{"While", "[", "\[IndentingNewLine]",
182 | RowBox[{
183 | RowBox[{
184 | RowBox[{"While", "[", "\[IndentingNewLine]",
185 | RowBox[{
186 | RowBox[{"step", "=",
187 | RowBox[{"SMTConvergence", "[",
188 | RowBox[{"tolNR", ",", "maxNR", ",",
189 | RowBox[{"{",
190 | RowBox[{
191 | "\"\\"", ",", "targetNR", ",",
192 | "\[CapitalDelta]\[Lambda]Min", ",",
193 | "\[CapitalDelta]\[Lambda]Max", ",", "\[Lambda]Max"}],
194 | "}"}]}], "]"}]}], "\[IndentingNewLine]", ",", " ",
195 | RowBox[{
196 | RowBox[{"SMTNewtonIteration", "[", "]"}], ";"}]}],
197 | "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]",
198 | "\[IndentingNewLine]",
199 | RowBox[{"If", "[",
200 | RowBox[{
201 | RowBox[{
202 | RowBox[{
203 | "step", "\[LeftDoubleBracket]", "4", "\[RightDoubleBracket]"}],
204 | "===", "\"\\""}], ",",
205 | RowBox[{
206 | RowBox[{"SMTStatusReport", "[", "\"\\"", "]"}], ";",
207 | RowBox[{"SMTStepBack", "[", "]"}], ";"}]}], "]"}], ";",
208 | "\[IndentingNewLine]",
209 | RowBox[{
210 | "step", "\[LeftDoubleBracket]", "3", "\[RightDoubleBracket]"}]}],
211 | " ", "\[IndentingNewLine]", ",",
212 | RowBox[{
213 | RowBox[{"If", "[",
214 | RowBox[{
215 | RowBox[{
216 | "step", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}],
217 | ",",
218 | RowBox[{
219 | RowBox[{"SMTStepBack", "[", "]"}], ";"}]}], "]"}], ";",
220 | "\[IndentingNewLine]",
221 | RowBox[{"SMTNextStep", "[",
222 | RowBox[{"\"\<\[CapitalDelta]\[Lambda]\>\"", "\[Rule]",
223 | RowBox[{
224 | "step", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}],
225 | "]"}]}]}], "\[IndentingNewLine]", "]"}], ";",
226 | "\[IndentingNewLine]", "\n", " ",
227 | RowBox[{"dispData", "=",
228 | RowBox[{"SMTNodeData", "[", "\"\\"", "]"}]}], ";", "\n",
229 | " ",
230 | RowBox[{"forceData", "=",
231 | RowBox[{"ConstantArray", "[",
232 | RowBox[{
233 | RowBox[{"{",
234 | RowBox[{"0", ",", "0", ",", "0"}], "}"}], ",", "SMTNoNodes"}],
235 | "]"}]}], ";", "\n", " ",
236 | RowBox[{
237 | RowBox[{"forceData", "[",
238 | RowBox[{"[",
239 | RowBox[{
240 | RowBox[{"SMTFindNodes", "[",
241 | RowBox[{"Point", "[",
242 | RowBox[{
243 | RowBox[{"{",
244 | RowBox[{"ix", ",", "iy", ",", "nz"}], "}"}],
245 | RowBox[{"{",
246 | RowBox[{
247 | RowBox[{"L", "/", "nx"}], ",",
248 | RowBox[{"H", "/", "ny"}], ",",
249 | RowBox[{"V", "/", "nz"}]}], "}"}]}], "]"}], "]"}], "[",
250 | RowBox[{"[", "1", "]"}], "]"}], "]"}], "]"}], "=", "force"}], ";",
251 | "\n", " ",
252 | RowBox[{"data", "=",
253 | RowBox[{"Transpose", "[",
254 | RowBox[{"{",
255 | RowBox[{
256 | RowBox[{"Flatten", "[", "forceData", "]"}], ",",
257 | RowBox[{"Flatten", "[", "dispData", "]"}]}], "}"}], "]"}]}], ";",
258 | "\[IndentingNewLine]",
259 | RowBox[{"Write", "[",
260 | RowBox[{"str", ",",
261 | RowBox[{"OutputForm", "[",
262 | RowBox[{"StringTrim", "[",
263 | RowBox[{"ExportString", "[",
264 | RowBox[{"data", ",", "\"\\""}], "]"}], "]"}], "]"}]}],
265 | "]"}], ";"}], "\[IndentingNewLine]", ",", "noTrainings"}], "]"}], ",",
266 | RowBox[{"{",
267 | RowBox[{"ix", ",", "nx", ",", "1", ",",
268 | RowBox[{"-", "1"}]}], "}"}], ",",
269 | RowBox[{"{",
270 | RowBox[{"iy", ",", "0", ",", "ny"}], "}"}]}], "]"}],
271 | ";"}], "\[IndentingNewLine]",
272 | RowBox[{
273 | RowBox[{"Close", "[", "str", "]"}], ";"}]}], "Input",
274 | CellChangeTimes->{
275 | 3.821965192044854*^9, {3.8219653154195557`*^9, 3.8219653189953995`*^9}, {
276 | 3.8219655397845397`*^9, 3.8219655864450216`*^9}, {3.821965710134426*^9,
277 | 3.8219657350041943`*^9}, {3.8219657828942485`*^9,
278 | 3.8219658015948415`*^9}, {3.8219665355432262`*^9,
279 | 3.8219665401324463`*^9}, {3.821966847511552*^9, 3.821966849751898*^9}, {
280 | 3.821966920841444*^9, 3.8219669233415604`*^9}, {3.8219669893214054`*^9,
281 | 3.8219670791012683`*^9}, {3.821967122331189*^9, 3.82196716523065*^9}, {
282 | 3.8219671973207536`*^9, 3.821967260351164*^9}, {3.821967304220663*^9,
283 | 3.8219673107368546`*^9}, {3.822038817529505*^9, 3.822038868914257*^9}, {
284 | 3.822038935830645*^9, 3.8220389463931007`*^9}, {3.822039063613682*^9,
285 | 3.822039132577607*^9}, {3.822039489037347*^9, 3.822039516032612*^9},
286 | 3.82203973080825*^9, 3.822039781005536*^9, {3.8220399744515133`*^9,
287 | 3.822040046081605*^9}, {3.8220400908420773`*^9, 3.822040101170217*^9}, {
288 | 3.822040215810095*^9, 3.822040231929935*^9}, {3.822040381015777*^9,
289 | 3.822040390033843*^9}, {3.822040837040793*^9, 3.822040873113199*^9}, {
290 | 3.822041203627969*^9, 3.822041228411079*^9}, {3.886758903234687*^9,
291 | 3.886758923618925*^9}, 3.8867590607187157`*^9, 3.886759230574546*^9, {
292 | 3.88675933505646*^9, 3.886759342094679*^9}, {3.886759726470257*^9,
293 | 3.8867597331474047`*^9}, {3.886759765753681*^9, 3.8867598142192*^9}, {
294 | 3.886759930389045*^9, 3.886759942011567*^9}, {3.886760066454688*^9,
295 | 3.886760066964253*^9}, {3.886761232702545*^9, 3.886761244510921*^9}},
296 | Background->RGBColor[
297 | 0.87, 0.94, 1],ExpressionUUID->"4798baed-be29-492f-8f8b-bd6d61f81a6e"],
298 |
299 | Cell["Save the element connectivity matrix (topology of the mesh)", "Text",
300 | CellChangeTimes->{{3.886757904786881*^9, 3.886757923853223*^9}},
301 | Background->RGBColor[
302 | 0.94, 0.91, 0.88],ExpressionUUID->"d28ea502-d990-413d-bab4-1dbafebe1f75"],
303 |
304 | Cell[BoxData[{
305 | RowBox[{
306 | RowBox[{"elements", "=", " ", "SMTElements"}], ";"}], "\[IndentingNewLine]",
307 | RowBox[{
308 | RowBox[{"connectivity", " ", "=", " ",
309 | RowBox[{"elements", "[",
310 | RowBox[{"[",
311 | RowBox[{"All", ",", "3"}], "]"}], "]"}]}], ";"}], "\[IndentingNewLine]",
312 | RowBox[{
313 | RowBox[{"Export", "[",
314 | RowBox[{
315 | "\"\<../main/connectivity/connect_3dbeam.csv\>\"", ",", "connectivity"}],
316 | "]"}], ";"}]}], "Input",
317 | CellChangeTimes->{{3.859968339154389*^9, 3.859968359518798*^9}, {
318 | 3.859968411067058*^9, 3.8599684111736526`*^9}, 3.8599684733704777`*^9, {
319 | 3.8599688095070047`*^9, 3.859968840208817*^9}, {3.859968899285262*^9,
320 | 3.859968910465919*^9}, {3.859968963050453*^9, 3.859968977807967*^9}, {
321 | 3.8623109978725767`*^9, 3.862311017606647*^9}, {3.862415035214591*^9,
322 | 3.8624150396134768`*^9}, {3.886758150200418*^9, 3.886758190134881*^9}, {
323 | 3.886761399207737*^9, 3.886761399997923*^9}, 3.888580471822447*^9},
324 | Background->RGBColor[
325 | 0.87, 0.94, 1],ExpressionUUID->"6b506043-4217-4b77-8dfb-66c0995b0c3a"]
326 | },
327 | WindowSize->{1078, 747},
328 | WindowMargins->{{Automatic, -1552}, {44, Automatic}},
329 | Magnification:>1.25 Inherited,
330 | FrontEndVersion->"12.1 for Mac OS X x86 (64-bit) (March 13, 2020)",
331 | StyleDefinitions->"Default.nb",
332 | ExpressionUUID->"83d01d62-8103-439c-9d5b-fd03edec3169"
333 | ]
334 | (* End of Notebook Content *)
335 |
336 | (* Internal cache information *)
337 | (*CellTagsOutline
338 | CellTagsIndex->{}
339 | *)
340 | (*CellTagsIndex
341 | CellTagsIndex->{}
342 | *)
343 | (*NotebookFileOutline
344 | Notebook[{
345 | Cell[558, 20, 253, 5, 57, "Input",ExpressionUUID->"bfdda654-c2f4-45f7-90d9-e46c25286ea2"],
346 | Cell[814, 27, 206, 3, 64, "Text",ExpressionUUID->"9cf7c054-3bdb-4c14-9445-4d8d051ecb32"],
347 | Cell[1023, 32, 2128, 57, 162, "Input",ExpressionUUID->"b7bdd5ab-e26d-442b-8ddc-b7fcbbebf384"],
348 | Cell[3154, 91, 431, 8, 93, "Text",ExpressionUUID->"2636dfaf-4b1c-4152-ad52-9773214b36b5"],
349 | Cell[3588, 101, 8683, 195, 916, "Input",ExpressionUUID->"4798baed-be29-492f-8f8b-bd6d61f81a6e"],
350 | Cell[12274, 298, 240, 3, 64, "Text",ExpressionUUID->"d28ea502-d990-413d-bab4-1dbafebe1f75"],
351 | Cell[12517, 303, 1044, 21, 110, "Input",ExpressionUUID->"6b506043-4217-4b77-8dfb-66c0995b0c3a"]
352 | }
353 | ]
354 | *)
355 |
356 |
--------------------------------------------------------------------------------
/src/femscripts/datagen_3dbreast.nb:
--------------------------------------------------------------------------------
1 | (* Content-type: application/vnd.wolfram.mathematica *)
2 |
3 | (*** Wolfram Notebook File ***)
4 | (* http://www.wolfram.com/nb *)
5 |
6 | (* CreatedBy='Mathematica 12.1' *)
7 |
8 | (*CacheID: 234*)
9 | (* Internal cache information:
10 | NotebookFileLineBreakTest
11 | NotebookFileLineBreakTest
12 | NotebookDataPosition[ 158, 7]
13 | NotebookDataLength[ 18603, 403]
14 | NotebookOptionsPosition[ 17473, 380]
15 | NotebookOutlinePosition[ 17901, 397]
16 | CellTagsIndexPosition[ 17858, 394]
17 | WindowFrame->Normal*)
18 |
19 | (* Beginning of Notebook Content *)
20 | Notebook[{
21 | Cell[BoxData[
22 | RowBox[{
23 | RowBox[{"<<", "AceFEM`"}], ";"}]], "Input",
24 | CellChangeTimes->{{3.821960854645931*^9, 3.8219608753257465`*^9}},
25 | Background->RGBColor[0.87, 0.94, 1],
26 | CellLabel->"In[1]:=",ExpressionUUID->"ab517154-a866-458d-a571-dcb556e42771"],
27 |
28 | Cell["\<\
29 | For the first run, you need to install the additional libraries using the \
30 | following command, comment it once done. (*ResourceFunction[\
31 | \[OpenCurlyDoubleQuote]FEMAddOnsInstall\[CloseCurlyDoubleQuote]][];*).
32 | This allows us to import external meshes to AceFEM as follows: \
33 | \>", "Text",
34 | CellChangeTimes->{{3.88371640053328*^9, 3.883716435141411*^9}, {
35 | 3.883716465186616*^9, 3.883716514202464*^9}, {3.8837167872860327`*^9,
36 | 3.8837167986265697`*^9}},
37 | Background->RGBColor[
38 | 0.94, 0.91, 0.88],ExpressionUUID->"d652565c-173c-433b-81d7-7c5ecec68214"],
39 |
40 | Cell[BoxData[
41 | RowBox[{
42 | RowBox[{"(*",
43 | RowBox[{
44 | RowBox[{
45 | RowBox[{"ResourceFunction", "[", "\"\\"", "]"}], "[",
46 | "]"}], ";"}], "*)"}], "\[IndentingNewLine]",
47 | RowBox[{
48 | RowBox[{
49 | RowBox[{"PacletFind", "[", "\"\\"", "]"}], ";"}],
50 | "\[IndentingNewLine]",
51 | RowBox[{
52 | RowBox[{"Needs", "[", "\"\\"", "]"}], ";"}],
53 | "\[IndentingNewLine]",
54 | RowBox[{
55 | RowBox[{"Get", "[", "\"\\"", "]"}], ";"}],
56 | "\[IndentingNewLine]",
57 | RowBox[{
58 | RowBox[{"mesh", " ", "=", " ",
59 | RowBox[{"Import", "[",
60 | RowBox[{
61 | "\"\<../postprocess/visualisation/breast.msh\>\"", ",",
62 | "\"\\""}], "]"}]}], ";"}]}]}]], "Input",
63 | CellChangeTimes->{{3.859013397394458*^9, 3.859013488348074*^9}, {
64 | 3.859013519433028*^9, 3.859013527756604*^9}, {3.859013685819697*^9,
65 | 3.859013711433762*^9}, {3.859013818546336*^9, 3.859013823392849*^9}, {
66 | 3.859014539107383*^9, 3.8590145522685204`*^9}, {3.859014591028316*^9,
67 | 3.8590146201825933`*^9}, {3.859014665524804*^9, 3.859014687942999*^9}, {
68 | 3.8590147846355743`*^9, 3.859014789316461*^9}, {3.859019942725045*^9,
69 | 3.859019977781187*^9}, {3.859020147411499*^9, 3.859020147699615*^9},
70 | 3.859020266047024*^9, {3.859020385203589*^9, 3.8590204350277863`*^9}, {
71 | 3.859020468075383*^9, 3.859020474313511*^9}, {3.859020527469241*^9,
72 | 3.8590206837482777`*^9}, {3.8590207236284018`*^9,
73 | 3.8590207314001217`*^9}, {3.886755196527871*^9, 3.886755221650185*^9}, {
74 | 3.88675810507235*^9, 3.886758129932716*^9}, {3.88857980954002*^9,
75 | 3.888579840102166*^9}, {3.888579916850635*^9, 3.888579920085721*^9}, {
76 | 3.888579992874055*^9, 3.888579994535515*^9}, {3.888580488388467*^9,
77 | 3.88858051099046*^9}, {3.8889296396492558`*^9, 3.8889296804733477`*^9}},
78 | Background->RGBColor[
79 | 0.87, 0.94, 1],ExpressionUUID->"56793914-8666-4255-a7f2-7f964a73826e"],
80 |
81 | Cell["Initialise variables ", "Text",
82 | CellChangeTimes->{{3.8837167822014303`*^9, 3.8837168049261913`*^9}},
83 | Background->RGBColor[
84 | 0.94, 0.91, 0.88],ExpressionUUID->"a61efbf9-a4e8-43c5-8ba0-0a7b2d25f415"],
85 |
86 | Cell[BoxData[{
87 | RowBox[{
88 | RowBox[{"str", "=",
89 | RowBox[{"OpenWrite", "[", "\"\<3dbreast.csv\>\"", "]"}]}], ";"}], "\n",
90 | RowBox[{
91 | RowBox[{"noTrainings", "=", "2"}], ";"}], "\n",
92 | RowBox[{
93 | RowBox[{"count", "=", "0"}], ";"}], "\[IndentingNewLine]",
94 | RowBox[{
95 | RowBox[{"fminmax", "=", " ",
96 | RowBox[{"{",
97 | RowBox[{
98 | RowBox[{"-", "6"}], ",", "6"}], "}"}]}], ";"}]}], "Input",
99 | CellChangeTimes->{{3.859020686950986*^9, 3.859020686959427*^9}, {
100 | 3.859020788073502*^9, 3.859020812492607*^9}, {3.85978131924419*^9,
101 | 3.8597813209110603`*^9}, {3.8597824698243513`*^9, 3.859782470473053*^9}, {
102 | 3.859882396701106*^9, 3.859882408477496*^9}, {3.859882861931478*^9,
103 | 3.85988287526542*^9}, {3.859882921114256*^9, 3.859882939423882*^9}, {
104 | 3.859951029714862*^9, 3.859951053816742*^9}, {3.859951134835566*^9,
105 | 3.859951139160821*^9}, {3.859952041912109*^9, 3.859952045023036*^9}, {
106 | 3.859952268707067*^9, 3.859952276922269*^9}, {3.859953659797695*^9,
107 | 3.859953663611594*^9}, {3.859953725360023*^9, 3.8599537648418293`*^9}, {
108 | 3.8599550139478893`*^9, 3.859955014262189*^9}, 3.85995506917555*^9, {
109 | 3.8599652809580517`*^9, 3.859965281696746*^9}, {3.8599657823556023`*^9,
110 | 3.859965833696148*^9}, {3.859965879544107*^9, 3.859965879721301*^9},
111 | 3.8599659968915787`*^9, 3.859966058487116*^9, {3.85996614747619*^9,
112 | 3.859966149078264*^9}, {3.859966192487275*^9, 3.85996619639861*^9}, {
113 | 3.859966305167514*^9, 3.859966306333911*^9}, 3.859966359402602*^9, {
114 | 3.859966479812763*^9, 3.859966484433013*^9}, {3.85996721387549*^9,
115 | 3.859967229772037*^9}, {3.859967268758428*^9, 3.859967281301333*^9}, {
116 | 3.859967342746002*^9, 3.859967345128914*^9}, 3.859967417668832*^9, {
117 | 3.859967454876822*^9, 3.859967455130949*^9}, {3.8599675069380913`*^9,
118 | 3.859967515725424*^9}, {3.8599679965473623`*^9, 3.859968029833666*^9}, {
119 | 3.8599681118158712`*^9, 3.859968120080944*^9}, {3.859968232456477*^9,
120 | 3.859968241864027*^9}, {3.8599682770176907`*^9, 3.8599683250602283`*^9}, {
121 | 3.8599683955253153`*^9, 3.859968439776473*^9}, {3.8599685029865932`*^9,
122 | 3.859968508219933*^9}, {3.8599685606836643`*^9, 3.859968578703205*^9},
123 | 3.8599688012869263`*^9, {3.8599689881400013`*^9, 3.859968988282508*^9}, {
124 | 3.8599741765752583`*^9, 3.8599742331913652`*^9}, {3.859974369499166*^9,
125 | 3.859974410450532*^9}, {3.859974443906658*^9, 3.85997446497147*^9},
126 | 3.859974540300239*^9, 3.862298677166275*^9, {3.862298799083108*^9,
127 | 3.862298806017108*^9}, {3.8622989478618*^9, 3.862298962115309*^9},
128 | 3.86229917479396*^9, {3.862299289862282*^9, 3.862299297117051*^9}, {
129 | 3.8623003337507877`*^9, 3.862300337784739*^9}, {3.86230054923493*^9,
130 | 3.862300617094779*^9}, {3.862300655430986*^9, 3.86230072315626*^9}, {
131 | 3.8623007585603313`*^9, 3.862300775189312*^9}, {3.862300843352334*^9,
132 | 3.862300936754583*^9}, {3.862301004847273*^9, 3.8623010057014*^9}, {
133 | 3.862301128370328*^9, 3.862301168925465*^9}, {3.862301216032814*^9,
134 | 3.862301216708705*^9}, {3.862301316677376*^9, 3.862301316819145*^9},
135 | 3.862301453998254*^9, {3.8623017899089613`*^9, 3.8623017901003113`*^9}, {
136 | 3.86230194600327*^9, 3.862301962887405*^9}, {3.8623020138022213`*^9,
137 | 3.8623020145349627`*^9}, {3.862302184401589*^9, 3.8623021884371967`*^9}, {
138 | 3.86230349896236*^9, 3.862303528007195*^9}, {3.862303629546468*^9,
139 | 3.8623036308407307`*^9}, {3.8623036836254*^9, 3.862303684313759*^9}, {
140 | 3.8623042459338207`*^9, 3.862304246611891*^9}, {3.862371343314794*^9,
141 | 3.862371343695931*^9}, {3.8623713964542837`*^9, 3.862371413687477*^9}, {
142 | 3.8623716994467907`*^9, 3.86237170902693*^9}, {3.8623721251340923`*^9,
143 | 3.862372192068438*^9}, {3.8623755409961*^9, 3.8623755524259*^9},
144 | 3.862380115663755*^9, {3.8624033909889917`*^9, 3.862403391038753*^9},
145 | 3.886755220121471*^9, {3.8867552655052977`*^9, 3.886755284645912*^9}, {
146 | 3.886757667585061*^9, 3.886757702743734*^9}, 3.88675776762584*^9, {
147 | 3.886758134364547*^9, 3.886758136012732*^9}, {3.886758239257011*^9,
148 | 3.886758240102099*^9}, {3.888579958046648*^9, 3.88857996121703*^9}},
149 | Background->RGBColor[0.87, 0.94, 1],
150 | CellLabel->"In[10]:=",ExpressionUUID->"b512ef81-0c0e-4257-8a20-3265cc238cb8"],
151 |
152 | Cell["\<\
153 | Start the data generation loop. Again, body force is applied in incremental \
154 | steps to avoid divergence of the solver. \
155 | \>", "Text",
156 | CellChangeTimes->{{3.886757710896799*^9, 3.88675771229537*^9}, {
157 | 3.886757845932824*^9, 3.886757847140698*^9}, {3.886759214676836*^9,
158 | 3.88675921774767*^9}},
159 | Background->RGBColor[
160 | 0.94, 0.91, 0.88],ExpressionUUID->"72b0a4d1-ef08-4fbc-811d-85010d0c1067"],
161 |
162 | Cell[BoxData[{
163 | RowBox[{
164 | RowBox[{"Do", "[", "\[IndentingNewLine]",
165 | RowBox[{
166 | RowBox[{
167 | RowBox[{"count", " ", "=", " ",
168 | RowBox[{"count", " ", "+", " ", "1"}]}], ";", "\[IndentingNewLine]",
169 | RowBox[{"If", "[",
170 | RowBox[{
171 | RowBox[{
172 | RowBox[{
173 | RowBox[{"QuotientRemainder", "[",
174 | RowBox[{"count", ",", "200"}], "]"}], "[",
175 | RowBox[{"[", "2", "]"}], "]"}], "\[Equal]", "0"}], ",",
176 | RowBox[{"Print", "[",
177 | RowBox[{"\"\\"", ",", " ", "count"}],
178 | "]"}]}], " ", "]"}], ";", "\[IndentingNewLine]",
179 | RowBox[{"force", "=",
180 | RowBox[{"RandomReal", "[",
181 | RowBox[{"fminmax", ",",
182 | RowBox[{"{", "3", "}"}]}], "]"}]}], ";", "\[IndentingNewLine]",
183 | RowBox[{"SMTInputData", "[", "]"}], ";", "\[IndentingNewLine]",
184 | RowBox[{"(*",
185 | RowBox[{
186 | RowBox[{"SMTAddDomain", "[",
187 | RowBox[{
188 | "\"\<\[CapitalOmega]\>\"", ",", "\"\\"",
189 | ",",
190 | RowBox[{"{",
191 | RowBox[{
192 | RowBox[{"\"\\"", "\[Rule]", "500"}], ",",
193 | RowBox[{"\"\<\[Nu] *\>\"", "->", "0.4"}]}], "}"}]}], "]"}], ";"}],
194 | "*)"}], "\[IndentingNewLine]",
195 | RowBox[{"SMTAddDomain", "[",
196 | RowBox[{"{",
197 | RowBox[{"\"\<\[CapitalOmega]\>\"", ",",
198 | RowBox[{"{",
199 | RowBox[{
200 | "\"\\"", ",", "\"\\"", ",", "\"\\"", ",",
201 | "\"\\"", ",", "\"\\"", ",", "\"\\"", ",",
202 | "\"\\"", ",", "\"\\"", ",", "\"\\""}], "}"}],
203 | ",",
204 | RowBox[{"{",
205 | RowBox[{
206 | RowBox[{"\"\\"", "\[Rule]", "800"}], ",",
207 | RowBox[{"\"\<\[Nu] *\>\"", "\[Rule]", "0.4"}], ",",
208 | RowBox[{"\"\<\[Rho] *\>\"", "\[Rule]", "1000"}], ",",
209 | RowBox[{"\"\\"", "\[Rule]",
210 | RowBox[{"force", "[",
211 | RowBox[{"[", "1", "]"}], "]"}]}], ",",
212 | RowBox[{"\"\\"", "\[Rule]",
213 | RowBox[{"force", "[",
214 | RowBox[{"[", "2", "]"}], "]"}]}], ",",
215 | RowBox[{"\"\\"", "\[Rule]",
216 | RowBox[{
217 | RowBox[{"force", "[",
218 | RowBox[{"[", "3", "]"}], "]"}], "/", "2"}]}]}], "}"}]}], "}"}],
219 | "]"}], ";", "\[IndentingNewLine]",
220 | RowBox[{"SMTAddEssentialBoundary", "[",
221 | RowBox[{
222 | RowBox[{
223 | RowBox[{"\"\\"", "==", "0"}], "&"}], ",",
224 | RowBox[{"1", "\[Rule]", "0"}], ",",
225 | RowBox[{"2", "\[Rule]", "0"}], ",",
226 | RowBox[{"3", "\[Rule]", "0"}]}], "]"}], ";", "\[IndentingNewLine]",
227 | RowBox[{"SMTAddMesh", "[",
228 | RowBox[{"mesh", ",", "\"\<\[CapitalOmega]\>\""}], "]"}], ";",
229 | "\[IndentingNewLine]",
230 | RowBox[{"SMTAnalysis", "[", "]"}], ";", "\[IndentingNewLine]",
231 | RowBox[{"bodyforce", " ", "=", " ",
232 | RowBox[{
233 | RowBox[{"-", "1"}], "*",
234 | RowBox[{"SMTResidual", "[",
235 | RowBox[{"SMTNodes", "[",
236 | RowBox[{"[",
237 | RowBox[{"All", ",", "1"}], "]"}], "]"}], "]"}]}]}], ";",
238 | "\[IndentingNewLine]",
239 | RowBox[{"bodyforce", " ", "=", " ",
240 | RowBox[{"Drop", "[",
241 | RowBox[{"bodyforce", ",",
242 | RowBox[{"-", "1"}]}], "]"}]}], ";", " ",
243 | RowBox[{"(*",
244 | RowBox[{"Remove", " ", "the", " ", "unnecessary", " ", "entry"}],
245 | "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]",
246 | RowBox[{"\[Lambda]Max", "=", "1"}], ";",
247 | RowBox[{"\[Lambda]0", "=", "\[Lambda]Max"}], ";",
248 | RowBox[{"\[CapitalDelta]\[Lambda]Min", "=",
249 | RowBox[{"\[Lambda]Max", "/", "1000"}]}], ";",
250 | RowBox[{"\[CapitalDelta]\[Lambda]Max", "=", "\[Lambda]Max"}], ";", " ",
251 | RowBox[{"(*", " ",
252 | RowBox[{"Iterative", " ", "solver"}], "*)"}], "\[IndentingNewLine]",
253 | RowBox[{"tolNR", "=",
254 | RowBox[{"10", "^",
255 | RowBox[{"-", "8"}]}]}], ";",
256 | RowBox[{"maxNR", "=", "15"}], ";",
257 | RowBox[{"targetNR", "=", "8"}], ";", "\[IndentingNewLine]",
258 | RowBox[{"ddata", "=",
259 | RowBox[{
260 | RowBox[{"SMTDomainData", "[", "\"\\"", "]"}], "[",
261 | RowBox[{"[", "1", "]"}], "]"}]}], ";", "\[IndentingNewLine]",
262 | RowBox[{"SMTNextStep", "[",
263 | RowBox[{"\"\<\[Lambda]\>\"", "\[Rule]", "\[Lambda]0"}], "]"}], ";",
264 | "\[IndentingNewLine]",
265 | RowBox[{"SMTDomainData", "[",
266 | RowBox[{"\"\\"", ",",
267 | RowBox[{"{",
268 | RowBox[{"ddata",
269 | RowBox[{"{",
270 | RowBox[{"1", ",", "1", ",",
271 | RowBox[{"SMTData", "[", "\"\\"", "]"}], ",",
272 | RowBox[{"SMTData", "[", "\"\\"", "]"}], ",",
273 | RowBox[{"SMTData", "[", "\"\\"", "]"}], ",", "1"}],
274 | "}"}]}], "}"}]}], "]"}], ";", "\[IndentingNewLine]",
275 | RowBox[{"While", "[", "\[IndentingNewLine]",
276 | RowBox[{
277 | RowBox[{
278 | RowBox[{"While", "[", "\[IndentingNewLine]",
279 | RowBox[{
280 | RowBox[{"step", "=",
281 | RowBox[{"SMTConvergence", "[",
282 | RowBox[{"tolNR", ",", "maxNR", ",",
283 | RowBox[{"{",
284 | RowBox[{
285 | "\"\\"", ",", "targetNR", ",",
286 | "\[CapitalDelta]\[Lambda]Min", ",",
287 | "\[CapitalDelta]\[Lambda]Max", ",", "\[Lambda]Max"}], "}"}]}],
288 | "]"}]}], "\[IndentingNewLine]", ",", " ",
289 | RowBox[{
290 | RowBox[{"SMTNewtonIteration", "[", "]"}], ";"}]}],
291 | "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]",
292 | RowBox[{"If", "[",
293 | RowBox[{
294 | RowBox[{
295 | RowBox[{
296 | "step", "\[LeftDoubleBracket]", "4", "\[RightDoubleBracket]"}],
297 | "===", "\"\\""}], ",",
298 | RowBox[{
299 | RowBox[{"SMTStatusReport", "[", "\"\\"", "]"}], ";",
300 | RowBox[{"SMTStepBack", "[", "]"}], ";"}]}], "]"}], ";",
301 | "\[IndentingNewLine]",
302 | RowBox[{
303 | "step", "\[LeftDoubleBracket]", "3", "\[RightDoubleBracket]"}]}], " ",
304 | "\[IndentingNewLine]", ",",
305 | RowBox[{
306 | RowBox[{"If", "[",
307 | RowBox[{
308 | RowBox[{
309 | "step", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",",
310 | RowBox[{
311 | RowBox[{"SMTStepBack", "[", "]"}], ";"}]}], "]"}], ";",
312 | "\[IndentingNewLine]",
313 | RowBox[{"SMTNextStep", "[",
314 | RowBox[{"\"\<\[CapitalDelta]\[Lambda]\>\"", "\[Rule]",
315 | RowBox[{
316 | "step", "\[LeftDoubleBracket]", "2", "\[RightDoubleBracket]"}]}],
317 | "]"}], ";", "\[IndentingNewLine]",
318 | RowBox[{"SMTDomainData", "[",
319 | RowBox[{"\"\\"", ",",
320 | RowBox[{"{",
321 | RowBox[{"ddata",
322 | RowBox[{"{",
323 | RowBox[{"1", ",", "1", ",",
324 | RowBox[{"SMTData", "[", "\"\\"", "]"}], ",",
325 | RowBox[{"SMTData", "[", "\"\\"", "]"}], ",",
326 | RowBox[{"SMTData", "[", "\"\\"", "]"}], ",", "1"}],
327 | "}"}]}], "}"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";",
328 | "\[IndentingNewLine]", "\[IndentingNewLine]",
329 | RowBox[{"dispData", "=",
330 | RowBox[{"SMTNodeData", "[", "\"\\"", "]"}]}], ";",
331 | "\[IndentingNewLine]",
332 | RowBox[{"data", "=",
333 | RowBox[{"Transpose", "[",
334 | RowBox[{"{",
335 | RowBox[{
336 | RowBox[{"Flatten", "[", "bodyforce", "]"}], ",",
337 | RowBox[{"Flatten", "[", "dispData", "]"}]}], "}"}], "]"}]}], ";",
338 | "\[IndentingNewLine]",
339 | RowBox[{"Write", "[",
340 | RowBox[{"str", ",",
341 | RowBox[{"OutputForm", "[",
342 | RowBox[{"StringTrim", "[",
343 | RowBox[{"ExportString", "[",
344 | RowBox[{"data", ",", "\"\\""}], "]"}], "]"}], "]"}]}], "]"}],
345 | ";"}], "\[IndentingNewLine]", ",", "noTrainings"}], "]"}],
346 | ";"}], "\[IndentingNewLine]",
347 | RowBox[{
348 | RowBox[{"Close", "[", "str", "]"}], ";"}]}], "Input",
349 | CellChangeTimes->{3.886757715629888*^9, 3.886757891001164*^9},
350 | Background->RGBColor[0.87, 0.94, 1],
351 | CellLabel->"In[14]:=",ExpressionUUID->"b1bd3bc6-60f7-45dd-81bf-94f9e4612a41"],
352 |
353 | Cell["Save the element connectivity matrix (topology of the mesh)", "Text",
354 | CellChangeTimes->{{3.886757904786881*^9, 3.886757923853223*^9}},
355 | Background->RGBColor[
356 | 0.94, 0.91, 0.88],ExpressionUUID->"93ca9fde-6e8e-4520-8bc5-32a7903dc136"],
357 |
358 | Cell[BoxData[{
359 | RowBox[{
360 | RowBox[{"elements", "=", " ", "SMTElements"}], ";"}], "\[IndentingNewLine]",
361 | RowBox[{
362 | RowBox[{"connectivity", " ", "=", " ",
363 | RowBox[{"elements", "[",
364 | RowBox[{"[",
365 | RowBox[{"All", ",", "3"}], "]"}], "]"}]}], ";"}], "\[IndentingNewLine]",
366 | RowBox[{
367 | RowBox[{"Export", "[",
368 | RowBox[{
369 | "\"\<../main/connectivity/connect_3dbreast.csv\>\"", ",", "connectivity"}],
370 | "]"}], ";"}]}], "Input",
371 | CellChangeTimes->{{3.859968339154389*^9, 3.859968359518798*^9}, {
372 | 3.859968411067058*^9, 3.8599684111736526`*^9}, 3.8599684733704777`*^9, {
373 | 3.8599688095070047`*^9, 3.859968840208817*^9}, {3.859968899285262*^9,
374 | 3.859968910465919*^9}, {3.859968963050453*^9, 3.859968977807967*^9}, {
375 | 3.8623109978725767`*^9, 3.862311017606647*^9}, {3.862415035214591*^9,
376 | 3.8624150396134768`*^9}, {3.886758150200418*^9, 3.886758190134881*^9}, {
377 | 3.888580034019451*^9, 3.888580062393281*^9}, 3.8885801199266768`*^9},
378 | Background->RGBColor[
379 | 0.87, 0.94, 1],ExpressionUUID->"c5dd71de-3482-45d0-8188-f36c9390e89a"]
380 | },
381 | WindowSize->{1334, 747},
382 | WindowMargins->{{Automatic, -3569}, {2, Automatic}},
383 | Magnification:>1.25 Inherited,
384 | FrontEndVersion->"12.1 for Mac OS X x86 (64-bit) (March 13, 2020)",
385 | StyleDefinitions->"Default.nb",
386 | ExpressionUUID->"bb6ada76-345f-48e9-83a6-98713b207dd2"
387 | ]
388 | (* End of Notebook Content *)
389 |
390 | (* Internal cache information *)
391 | (*CellTagsOutline
392 | CellTagsIndex->{}
393 | *)
394 | (*CellTagsIndex
395 | CellTagsIndex->{}
396 | *)
397 | (*NotebookFileOutline
398 | Notebook[{
399 | Cell[558, 20, 253, 5, 57, "Input",ExpressionUUID->"ab517154-a866-458d-a571-dcb556e42771"],
400 | Cell[814, 27, 563, 10, 122, "Text",ExpressionUUID->"d652565c-173c-433b-81d7-7c5ecec68214"],
401 | Cell[1380, 39, 1907, 39, 162, "Input",ExpressionUUID->"56793914-8666-4255-a7f2-7f964a73826e"],
402 | Cell[3290, 80, 206, 3, 64, "Text",ExpressionUUID->"a61efbf9-a4e8-43c5-8ba0-0a7b2d25f415"],
403 | Cell[3499, 85, 4180, 64, 136, "Input",ExpressionUUID->"b512ef81-0c0e-4257-8a20-3265cc238cb8"],
404 | Cell[7682, 151, 405, 8, 64, "Text",ExpressionUUID->"72b0a4d1-ef08-4fbc-811d-85010d0c1067"],
405 | Cell[8090, 161, 8087, 189, 968, "Input",ExpressionUUID->"b1bd3bc6-60f7-45dd-81bf-94f9e4612a41"],
406 | Cell[16180, 352, 240, 3, 64, "Text",ExpressionUUID->"93ca9fde-6e8e-4520-8bc5-32a7903dc136"],
407 | Cell[16423, 357, 1046, 21, 110, "Input",ExpressionUUID->"c5dd71de-3482-45d0-8188-f36c9390e89a"]
408 | }
409 | ]
410 | *)
411 |
--------------------------------------------------------------------------------
/src/femscripts/preprocess.py:
--------------------------------------------------------------------------------
1 | import pandas as pd
2 | import numpy as np
3 | from sklearn.model_selection import train_test_split
4 |
5 | class Preprocess():
6 |
7 | def __init__(self,df,dim,dof,**kwargs):
8 | self.df = df #dataframe
9 | self.dim = dim #Dimensionality of the problem 2D or 3D
10 | self.dof = dof #Degree of freedom of the problem
11 | self.tot_n = int(len(self.df)/self.dof) #Total examples in the data
12 | self.n_nodes = int(self.dof/self.dim) #Total number of nodes
13 |
14 |
15 | def get_data_UNET(self,split,mesh_dim):
16 |
17 | '''
18 | Create train test dataset for training CNNs from FEM dataset csv file
19 |
20 | Inputs
21 |
22 | - split: ratio for test set
23 | - mesh_dim: list containing number of FEM nodes in x,y (,z) directions [n_x, n_y] (,n_z])
24 |
25 | Outputs
26 |
27 | - X_train, X_test, Y_train, Y_test with shape as
28 | (n_train/n_test, n_ch, dim_x, dim_y) or (n_train/n_test, n_ch, dim_x, dim_y, dim_z)
29 | depending on 2D or 3D problem
30 |
31 | '''
32 |
33 | X_org = np.zeros((self.tot_n, self.dof))
34 | Y_org = np.zeros((self.tot_n, self.dof))
35 |
36 | for i in range(self.tot_n):
37 | X_org[i, :] = self.df['f'].values[i * self.dof:(i + 1) * self.dof]
38 | Y_org[i, :] = self.df['u'].values[i * self.dof:(i + 1) * self.dof]
39 |
40 | X_org[i, :] = Preprocess.reorder(X_org[i, :],self.dof,self.dim)
41 | Y_org[i, :] = Preprocess.reorder(Y_org[i, :],self.dof,self.dim)
42 |
43 |
44 | X_train, X_test, Y_train, Y_test = train_test_split(X_org, Y_org, test_size=split,random_state=42)
45 |
46 | n_train = len(X_train)
47 | n_test = len(X_test)
48 |
49 | if self.dim==2:
50 | n_x, n_y = mesh_dim
51 |
52 | X_train = X_train.reshape(n_train,n_ch, dim_x, dim_y)
53 | Y_train = Y_train.reshape(n_train,n_ch, dim_x, dim_y)
54 |
55 | X_test = X_test.reshape(n_test, n_ch, dim_x, dim_y)
56 | Y_test = Y_test.reshape(n_test, n_ch, dim_x, dim_y)
57 |
58 | elif self.dim==3:
59 | n_x, n_y, n_z = mesh_dim
60 | n_ch, dim_x, dim_y, dim_z = self.dim, n_x, n_y, n_z
61 |
62 | X_train = X_train.reshape(n_train, n_ch, dim_x, dim_y, dim_z)
63 | Y_train = Y_train.reshape(n_train, n_ch, dim_x, dim_y, dim_z)
64 |
65 | X_test = X_test.reshape(n_test, n_ch, dim_x, dim_y, dim_z)
66 | Y_test = Y_test.reshape(n_test, n_ch, dim_x, dim_y, dim_z)
67 |
68 |
69 | return X_train, X_test, Y_train, Y_test
70 |
71 |
72 | def get_data_MAgNET(self,split):
73 |
74 | '''
75 | To generate data for MAgNET/Perceiver IO
76 |
77 | Returns:
78 |
79 | Training and test sets with shape as (n_train(& n_test),dof) with reordered dofs
80 |
81 | '''
82 |
83 | X_org = np.zeros((self.tot_n, self.dof)) # Features
84 | Y_org = np.zeros((self.tot_n, self.dof))
85 |
86 | for i in range(self.tot_n):
87 | X_org[i, :] = self.df['f'].values[i * self.dof:(i + 1) * self.dof]
88 | Y_org[i, :] = self.df['u'].values[i * self.dof:(i + 1) * self.dof]
89 |
90 | X_org[i,:] = Preprocess.reorder(X_org[i,:],self.dof,self.dim)
91 | Y_org[i,:] = Preprocess.reorder(Y_org[i,:],self.dof,self.dim)
92 |
93 | X_train, X_test, Y_train, Y_test = train_test_split(X_org, Y_org, test_size=split,random_state=42)
94 |
95 |
96 | return X_train, X_test, Y_train, Y_test
97 |
98 |
99 |
100 | @staticmethod
101 | def reorder(X,dof,dim):
102 |
103 | '''
104 | Original FEM data is stored as (1x, 1y, 2x, 2y ...,nx,ny)
105 | But for efficient use of MAgNET/CNNs, we need to re-arrange all x, y dofs in
106 | separate channels.
107 |
108 | inputs:
109 |
110 | - Array of features and lables in the form (1x, 1y, 1z, 2x, 2y, 2z ...,nx,ny,nz)
111 |
112 | outputs:
113 |
114 | - Reordered array in the form (1x, 2x, ... , nx, 1y, 2y ...ny ,1z, ....,nz)
115 |
116 | '''
117 |
118 | if dim == 2:
119 | dof_x = X[0:dof-1:dim]
120 | dof_y = X[1:dof:dim]
121 |
122 | reordered_dof = np.hstack((dof_x,dof_y))
123 |
124 | elif dim == 3:
125 | dof_x = X[0:dof-1:dim]
126 | dof_y = X[1:dof-1:dim]
127 | dof_z = X[2:dof:dim]
128 |
129 | reordered_dof = np.hstack((dof_x,dof_y,dof_z))
130 |
131 | return reordered_dof
132 |
133 |
134 | @staticmethod
135 | def org_order(reordered_dof,dof,dim):
136 |
137 | '''
138 | Get back the original dof arrangement
139 |
140 | Inputs:
141 |
142 | - Reordered array in the form (1x, 2x, ... , nx, 1y, 2y ...ny ,1z, ....,nz)
143 |
144 | Outputs:
145 |
146 | - Returns original ordering in the form (1x, 1y, 1z, 2x, 2y, 2z ...,nx,ny,nz)
147 |
148 | '''
149 |
150 | original_dof = np.zeros((dof,))
151 |
152 | if dim==2:
153 |
154 | reordered_dof_x = reordered_dof[0:int(dof/dim)]
155 | reordered_dof_y = reordered_dof[int(dof/dim):dof]
156 |
157 | for i in range(int(dof/dim)):
158 | original_dof[2*i] = reordered_dof_x[i]
159 | original_dof[2*i+1] = reordered_dof_y[i]
160 |
161 |
162 | elif dim==3:
163 |
164 | reordered_dof_x = reordered_dof[0:int(dof/dim)]
165 | reordered_dof_y = reordered_dof[int(dof/dim):int(2*dof/dim)]
166 | reordered_dof_z = reordered_dof[int(2*dof/dim):dof]
167 |
168 | for i in range(int(dof/dim)):
169 | original_dof[3*i] = reordered_dof_x[i]
170 | original_dof[3*i+1] = reordered_dof_y[i]
171 | original_dof[3*i+2] = reordered_dof_z[i]
172 |
173 | return original_dof
174 |
--------------------------------------------------------------------------------
/src/main/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saurabhdeshpande93/MAgNET/b301c1d75a198e083014511f208fa018226ed86b/src/main/__init__.py
--------------------------------------------------------------------------------
/src/main/connectivity/connect_2dhole.csv:
--------------------------------------------------------------------------------
1 | 31,99,97
2 | 51,55,52
3 | 85,96,32
4 | 98,26,99
5 | 69,37,46
6 | 49,92,70
7 | 49,90,92
8 | 19,47,62
9 | 43,24,23
10 | 59,14,13
11 | 14,59,71
12 | 53,5,4
13 | 47,52,55
14 | 52,18,17
15 | 47,33,62
16 | 37,59,13
17 | 26,98,27
18 | 13,12,37
19 | 51,65,77
20 | 96,34,99
21 | 41,12,11
22 | 65,16,15
23 | 57,10,67
24 | 50,56,36
25 | 11,10,57
26 | 67,63,79
27 | 89,46,79
28 | 67,10,9
29 | 51,17,16
30 | 37,12,41
31 | 53,4,66
32 | 7,64,8
33 | 37,41,46
34 | 50,54,56
35 | 52,47,18
36 | 18,47,19
37 | 51,16,65
38 | 62,20,19
39 | 80,90,49
40 | 81,83,93
41 | 24,43,39
42 | 68,22,21
43 | 57,46,41
44 | 58,22,68
45 | 88,44,94
46 | 68,61,80
47 | 49,39,43
48 | 23,58,43
49 | 5,53,54
50 | 1,24,39
51 | 50,64,7
52 | 37,69,59
53 | 6,50,7
54 | 54,50,6
55 | 54,6,5
56 | 47,55,33
57 | 70,60,39
58 | 1,39,60
59 | 2,60,72
60 | 77,65,81
61 | 1,60,2
62 | 36,64,50
63 | 66,4,3
64 | 57,41,11
65 | 23,22,58
66 | 55,51,38
67 | 53,66,78
68 | 58,49,43
69 | 56,53,40
70 | 17,51,52
71 | 53,56,54
72 | 57,67,79
73 | 58,68,80
74 | 15,71,65
75 | 39,49,70
76 | 3,72,66
77 | 61,74,75
78 | 20,62,74
79 | 74,68,21
80 | 63,73,76
81 | 8,64,73
82 | 73,67,9
83 | 15,14,71
84 | 51,77,38
85 | 3,2,72
86 | 53,78,40
87 | 73,9,8
88 | 79,63,45
89 | 74,21,20
90 | 80,61,48
91 | 69,46,91
92 | 42,93,86
93 | 70,87,84
94 | 66,82,78
95 | 69,83,59
96 | 77,81,42
97 | 70,84,60
98 | 78,82,44
99 | 76,73,64
100 | 63,67,73
101 | 75,74,62
102 | 61,68,74
103 | 81,65,71
104 | 62,33,75
105 | 64,36,76
106 | 42,38,77
107 | 82,66,72
108 | 44,40,78
109 | 89,79,45
110 | 46,57,79
111 | 90,80,48
112 | 49,58,80
113 | 83,71,59
114 | 81,71,83
115 | 84,72,60
116 | 82,72,84
117 | 85,83,69
118 | 85,32,86
119 | 70,92,87
120 | 87,30,88
121 | 91,46,89
122 | 85,91,96
123 | 83,85,93
124 | 93,42,81
125 | 29,30,87
126 | 84,94,82
127 | 84,87,94
128 | 94,44,82
129 | 45,35,89
130 | 69,91,85
131 | 48,28,90
132 | 92,95,29
133 | 89,35,91
134 | 96,91,35
135 | 95,90,28
136 | 87,92,29
137 | 85,86,93
138 | 87,88,94
139 | 34,96,35
140 | 90,95,92
141 | 31,32,96
142 | 26,25,97
143 | 99,26,97
144 | 34,98,99
145 | 96,99,31
146 |
--------------------------------------------------------------------------------
/src/main/connectivity/connect_2dlshape.csv:
--------------------------------------------------------------------------------
1 | 1,5,6,2
2 | 2,6,7,3
3 | 3,7,8,4
4 | 5,9,10,6
5 | 6,10,11,7
6 | 7,11,12,8
7 | 9,13,14,10
8 | 10,14,15,11
9 | 11,15,16,12
10 | 13,17,18,14
11 | 14,18,19,15
12 | 15,19,20,16
13 | 17,21,22,18
14 | 18,22,23,19
15 | 19,23,24,20
16 | 21,25,26,22
17 | 22,26,27,23
18 | 23,27,28,24
19 | 25,29,30,26
20 | 26,30,31,27
21 | 27,31,32,28
22 | 29,33,34,30
23 | 30,34,35,31
24 | 31,35,36,32
25 | 33,37,38,34
26 | 34,38,39,35
27 | 35,39,40,36
28 | 37,41,42,38
29 | 38,42,43,39
30 | 39,43,44,40
31 | 41,45,46,42
32 | 42,46,47,43
33 | 43,47,48,44
34 | 45,49,50,46
35 | 46,50,51,47
36 | 47,51,52,48
37 | 49,57,58,50
38 | 50,58,59,51
39 | 51,59,60,52
40 | 52,60,61,53
41 | 53,61,62,54
42 | 54,62,63,55
43 | 55,63,64,56
44 | 57,65,66,58
45 | 58,66,67,59
46 | 59,67,68,60
47 | 60,68,69,61
48 | 61,69,70,62
49 | 62,70,71,63
50 | 63,71,72,64
51 | 65,73,74,66
52 | 66,74,75,67
53 | 67,75,76,68
54 | 68,76,77,69
55 | 69,77,78,70
56 | 70,78,79,71
57 | 71,79,80,72
58 |
--------------------------------------------------------------------------------
/src/main/connectivity/unpad_map_2dlshape.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saurabhdeshpande93/MAgNET/b301c1d75a198e083014511f208fa018226ed86b/src/main/connectivity/unpad_map_2dlshape.npy
--------------------------------------------------------------------------------
/src/main/global_vars.py:
--------------------------------------------------------------------------------
1 |
2 | '''
3 |
4 | All global variables are defined in this file.
5 |
6 | '''
7 |
8 | ## All paths
9 | import os
10 |
11 | srcpath = os.path.dirname(os.getcwd())
12 | datapath = srcpath + "/data/FEMData/"
13 | weights_path = srcpath + "/data/saved_models/"
14 | prediction_path = srcpath + "/data/predictions/"
15 | visualisation_path = srcpath + "/postprocess/visualisation/"
16 |
17 |
18 | ## [Degrees of freedom(dof) and dimensionality(dim) of the problem].
19 | dofdim = { 'magnet': {'2dlshape': [160, 2],
20 | "2dhole" : [198, 2],
21 | "3dbeam" : [12096, 3],
22 | "3dbreast": [3105, 3]},
23 | 'cnn': {'2dlshape': [256, 2], #CNN 2d L-shape has padded dofs
24 | "3dbeam" : [12096, 3]}
25 | }
26 |
27 | ## No. of channels at respective graph U-NET level of MAgNET
28 | magnet_channels = {
29 | "2dlshape": [16, 32, 64, 128],
30 | "2dhole" : [8, 16, 32, 64],
31 | "3dbeam" : [6, 6, 12, 24, 48, 96],
32 | "3dbreast": [6, 12, 12, 24, 48]
33 | }
34 |
35 | ## [Number of poolings, random seed for the first pooling layer]
36 | magnet_pool_details = {
37 | "2dlshape": [3, 44],
38 | "2dhole" : [3, 632],
39 | "3dbeam" : [5, 827],
40 | "3dbreast": [4, 96]
41 | }
42 |
43 | ## Grid mesh dimensions
44 | cnn_input_shapes = {
45 | "2dlshape": [2, 16, 8],
46 | "3dbeam" : [3, 28, 12, 12],
47 | }
48 |
49 | ## No. of channels at respective CNN U-NET level
50 | cnn_channels = {
51 | "2dlshape": [64, 128, 512],
52 | "3dbeam" : [256, 256, 256, 512, 512],
53 | }
54 |
55 | ## Number of training epochs
56 | epochs = { 'magnet': {'2dlshape': 12000,
57 | "2dhole" : 6000,
58 | "3dbeam" : 600,
59 | "3dbreast": 2000},
60 | 'cnn' : {"2dlshape": 12000,
61 | "3dbeam" : 150}}
62 |
--------------------------------------------------------------------------------
/src/main/layers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saurabhdeshpande93/MAgNET/b301c1d75a198e083014511f208fa018226ed86b/src/main/layers/__init__.py
--------------------------------------------------------------------------------
/src/main/layers/g_pool.py:
--------------------------------------------------------------------------------
1 | import tensorflow as tf
2 | from tensorflow import keras
3 |
4 |
5 | class G_Pool(keras.layers.Layer):
6 |
7 | """
8 |
9 | Pooling layer
10 |
11 | Input : Tensorflow layer with shape (None, units) ; units = n_channels*nodes
12 | Output : Tensorflow layer with shape (None, pool_units) ; unpool_units = n_channels*pool_nodes
13 |
14 | :argument
15 |
16 | subgraph = This is a list of tensors(tf.int32) containing the subgraphs over which pooling has to be performed
17 | nodes = number of nodes for the unpooled graph (for the originally pooled graph)
18 |
19 | """
20 |
21 | def __init__(self,subgraph, nodes = None):
22 | super(G_Pool, self).__init__()
23 | self.subgraph = subgraph
24 | self.nodes = nodes
25 |
26 | def call(self, inputs):
27 |
28 | batch_dim = tf.shape(inputs)[0]
29 | units = inputs.shape[-1]
30 |
31 | n_channels = int(units/self.nodes)
32 | n_cliques = len(self.subgraph)
33 |
34 | batch_layer = tf.reshape(inputs, [batch_dim, n_channels, self.nodes])
35 |
36 | out = tf.range(n_cliques, dtype=tf.float32)
37 | out = tf.reshape(out, [1, n_cliques])
38 | out = tf.tile(out, tf.constant([n_channels, 1], tf.int32))
39 | out = tf.tile(tf.expand_dims(out, 0), [batch_dim, 1, 1])
40 | pooled_out = out
41 |
42 | for i in range(n_cliques):
43 | sliced_tensor = tf.gather(batch_layer, self.subgraph[i], axis=2)
44 | indices = tf.where(tf.equal(out, tf.constant(i, dtype=tf.float32)))
45 | indices = tf.reshape(indices, [batch_dim, n_channels, 3])
46 | pooled_out = tf.tensor_scatter_nd_update(pooled_out, indices, tf.reduce_max(sliced_tensor, axis=2))
47 |
48 | pooled_out = tf.reshape(pooled_out,[batch_dim,n_cliques*n_channels])
49 |
50 | return pooled_out
51 |
52 |
53 | def get_config(self):
54 |
55 | config = super().get_config().copy()
56 | config.update({
57 | 'subgraph': self.subgraph,
58 | 'nodes': self.nodes,
59 | })
60 | return config
61 |
--------------------------------------------------------------------------------
/src/main/layers/g_unpool.py:
--------------------------------------------------------------------------------
1 | import tensorflow as tf
2 | from tensorflow import keras
3 |
4 |
5 | class G_Unpool(keras.layers.Layer):
6 |
7 | """
8 |
9 | Un-pooling layer
10 |
11 | Input : Tensorflow layer with shape (None, units) ; units = n_channels*nodes
12 | Output : Tensorflow layer with shape (None, unpool_units) ; unpool_units = n_channels*unpool_nodes
13 |
14 | :arguments
15 |
16 | subgraph = This is a list of tensors(tf.int32) containing the subgraph over which pooling has to be performed
17 | nodes = number of nodes in the input graph
18 |
19 | """
20 |
21 | def __init__(self, subgraph, nodes = None):
22 | super(G_Unpool, self).__init__()
23 | self.subgraph = subgraph
24 | self.nodes = nodes
25 |
26 | def call(self, inputs):
27 |
28 | batch_dim = tf.shape(inputs)[0]
29 | units = inputs.shape[-1]
30 |
31 | n_cliques = len(self.subgraph)
32 | n_channels = int(units/n_cliques)
33 |
34 | pooled_out = tf.reshape(inputs, [batch_dim, n_channels, n_cliques])
35 |
36 | unpool_out = tf.zeros([batch_dim, n_channels, self.nodes])
37 |
38 | # i-th coloumn of pooled out should replicate to columns corresponding to nodes of that element in the unpooled out
39 | for i in range(n_cliques):
40 | node_list = self.subgraph[i]
41 | pool_length = tf.shape(node_list)[0]
42 | indices = tf.stack([tf.tile(tf.repeat(tf.range(batch_dim), pool_length), [n_channels]),
43 | tf.repeat(tf.range(n_channels), batch_dim * pool_length)], axis=1)
44 | indices = tf.concat([indices,tf.expand_dims(tf.tile(node_list, [batch_dim*n_channels]),axis=-1)], axis=1)
45 |
46 | indices = tf.reshape(indices, [batch_dim, n_channels, pool_length, 3])
47 |
48 | updates = tf.gather(pooled_out, [i], axis=2)
49 | updates = tf.repeat(updates, pool_length, axis=2)
50 |
51 | unpool_out = tf.tensor_scatter_nd_add(unpool_out, indices, updates)
52 |
53 |
54 | unpool_out = tf.reshape(unpool_out,[batch_dim,self.nodes*n_channels])
55 |
56 | return unpool_out
57 |
58 |
59 | def get_config(self):
60 |
61 | config = super().get_config().copy()
62 | config.update({
63 | 'subgraph': self.subgraph,
64 | 'nodes': self.nodes,
65 | })
66 | return config
67 |
--------------------------------------------------------------------------------
/src/main/layers/mag.py:
--------------------------------------------------------------------------------
1 | import tensorflow as tf
2 | from tensorflow import keras
3 | from keras import activations
4 | import numpy as np
5 |
6 | class MAg(keras.layers.Layer):
7 |
8 | """
9 |
10 | Multichannel Aggregation Layer
11 |
12 | - Input : Tensorflow layer of shape (None, n*channels[i-1])
13 | - Output : Tensorflow layer of shape (None, n*channels)
14 |
15 | where,
16 | 'channels[i-1]' : number of channels in the input layer
17 | 'None' : stands for the batch size.
18 | 'n' : number of nodes in the graph
19 |
20 | :arguments
21 |
22 | channels = number of channels in the input layer
23 | adjacency = adjacency matrix for the input graph
24 |
25 | """
26 |
27 | def __init__(self, channels, adjacency, kernel_initializer="glorot_uniform",
28 | bias_initializer="glorot_uniform",
29 | activation=None, use_bias=True):
30 | super(MAg, self).__init__()
31 | self.channels = channels
32 | self.activation = activations.get(activation)
33 | self.use_bias = use_bias
34 | self.kernel_initializer = kernel_initializer
35 | self.bias_initializer = bias_initializer
36 | self.adjacency = adjacency
37 | self.nonzero = np.count_nonzero(adjacency)
38 | self.n_nodes = adjacency.shape[-1]
39 |
40 |
41 | def build(self, input_shape):
42 |
43 | in_dim = input_shape[-1]
44 | in_chan = int(in_dim/self.n_nodes)
45 |
46 | out_dim = self.channels*self.n_nodes
47 | ker_dim = self.channels*self.nonzero*in_chan
48 |
49 |
50 | self.kernel = self.add_weight(
51 | shape=(ker_dim,),
52 | initializer=self.kernel_initializer,
53 | name='kernel',
54 | trainable=True)
55 |
56 | if self.use_bias:
57 | self.bias = self.add_weight(
58 | shape=(out_dim,), initializer=self.bias_initializer,name='bias', trainable=True)
59 |
60 |
61 | def call(self, inputs):
62 |
63 | in_dim = inputs.shape[-1]
64 | out_dim = self.channels*self.n_nodes
65 | in_chan = int(in_dim/self.n_nodes)
66 |
67 | mul = tf.constant([in_chan,self.channels],tf.int32)
68 | ker_wt = tf.tile(self.adjacency, mul)
69 |
70 | where = tf.not_equal(ker_wt, tf.constant(0, dtype=tf.float32))
71 | indices = tf.where(where)
72 |
73 | ker_wt = tf.tensor_scatter_nd_update(ker_wt, indices, self.kernel)
74 |
75 |
76 | out = tf.matmul(inputs, ker_wt)
77 |
78 | if self.use_bias:
79 | out = tf.nn.bias_add(out, self.bias)
80 |
81 | if self.activation is not None:
82 | out = self.activation(out)
83 |
84 | return out
85 |
86 |
87 | def get_config(self):
88 |
89 | config = super().get_config().copy()
90 | config.update({
91 | 'channels': self.channels,
92 | 'activation': self.activation,
93 | 'use_bias': self.use_bias,
94 | 'kernel_initializer': self.kernel_initializer,
95 | 'bias_initializer': self.bias_initializer,
96 | 'adjacency': self.adjacency,
97 | 'nonzero': self.nonzero,
98 | 'n_nodes': self.n_nodes,
99 | })
100 | return config
101 |
--------------------------------------------------------------------------------
/src/main/layers/pool_utils.py:
--------------------------------------------------------------------------------
1 | import tensorflow as tf
2 | import numpy as np
3 |
4 |
5 | def adjacency_pool(adjacency, pool_type: str, seed=10):
6 |
7 | """
8 |
9 | Function for creating pooled adjacency matrix along with list of subgraphs over which pooling is to be performed.
10 |
11 | :argument adjacency: A numpy array of adjacency matrix
12 | :argument pool_type: String defining type of pooling
13 | 'clique' - Pooling over non-overlapping cliques of a graph
14 | 'element' - Pooling over elements of a FEM mesh
15 | :argument seed : Integer for numpy random seed.
16 |
17 | :return: A_pool : Pooled adjacency matrix
18 | :return: subgraphs: List of tensors representing nodes over which pooling is to be performed
19 |
20 | """
21 |
22 | if pool_type == 'clique':
23 |
24 | A_reduced = np.copy(adjacency)
25 | subgraphs = []
26 | node_list = np.arange(len(A_reduced))
27 | np.random.seed(seed)
28 |
29 | while ~(node_list == 0.0).all():
30 |
31 | rand_node = np.random.choice(node_list)
32 |
33 | graph = np.array([rand_node])
34 |
35 | connected_nodes = np.squeeze(np.array(np.nonzero(A_reduced[rand_node])))
36 | connected_nodes = np.delete(connected_nodes, np.where(connected_nodes == rand_node))
37 |
38 | # connections = [p for p in itertools.combinations(connected_nodes, 2)]
39 |
40 | for node in connected_nodes:
41 | if (adjacency[graph, node] == 1.0).all():
42 | graph = np.append(graph, node)
43 |
44 | A_reduced[:, graph] = 0.
45 | A_reduced[graph, :] = 0.
46 |
47 | subgraphs.append(graph)
48 |
49 | node_list = np.asarray([i for i in node_list if i not in graph])
50 |
51 | #Corss check if you have a overlapping node in the subgraph
52 | for i in range(len(subgraphs)):
53 | for j in range(i, len(subgraphs)):
54 | if i != j and np.in1d(subgraphs[i], subgraphs[j]).any():
55 | raise ValueError('Common node found')
56 |
57 | A_pool = new_adjacency(subgraphs,adjacency)
58 |
59 | subgraphs = [tf.convert_to_tensor(graph, dtype=tf.int32) if graph.ndim != 0 else tf.expand_dims(
60 | tf.convert_to_tensor(graph, dtype=tf.int32), axis=0) for graph in subgraphs]
61 |
62 | # We pool over each element of the finite element mesh, not implemented in the paper
63 | elif pool_type == 'element':
64 |
65 | no_ele = len(e_connect)
66 |
67 | A_pool = np.zeros((no_ele, no_ele))
68 |
69 | for i in range(no_ele):
70 | for j in range(no_ele):
71 | if bool(set(e_connect[i]) & set(e_connect[j])):
72 | A_pool[i, j] = 1
73 |
74 | subgraphs = tf.convert_to_tensor(e_connect, dtype=tf.int32)
75 |
76 |
77 | else:
78 | raise ValueError('This type of pooling is not implemented')
79 |
80 |
81 | return A_pool, subgraphs
82 |
83 |
84 |
85 | def new_adjacency(subgraphs, adjacency):
86 |
87 | '''
88 |
89 | Creates a pooled adjacency using subghrap connections and parent adjacency matrix
90 |
91 | '''
92 |
93 | new_size = len(subgraphs)
94 | A_pool = np.zeros((new_size, new_size))
95 |
96 | for i in range(new_size):
97 | for j in range(new_size):
98 | slice1 = adjacency[subgraphs[i], :]
99 |
100 | if slice1.ndim == 1:
101 | slice1 = np.expand_dims(slice1, axis=0)
102 |
103 | slice2 = slice1[:, subgraphs[j]]
104 |
105 | if ~(slice2 == 0.0).all():
106 | A_pool[i, j] = 1
107 |
108 | return A_pool
109 |
110 |
111 |
112 |
113 | def pooled_adjacencies(adjacency, no_poolings, poolseed):
114 |
115 | '''
116 | Generates multiple pooled adjacencies
117 |
118 | :argument adjacency : Adjacency matrix of the input graph (adjacency of first graph U-Net level)
119 | :argument no_poolings : Number of times pooling to be performed (number of pooling operations in graph U-Net)
120 | :argument poolseed : Random seed for the first pooling operation
121 |
122 | :return: pooled_adjs : Adjacencies of pooled graphs
123 | :return: subgraphs : Subgraphs (List of nodes over which pooling performed) for all pooled adjacencies
124 |
125 | '''
126 |
127 | pooled_adjs = [adjacency]
128 | subgraphs = []
129 |
130 | for i in range(no_poolings):
131 | if i==0:
132 | A_pooled, subgraph = adjacency_pool(pooled_adjs[-1],pool_type='clique', seed=poolseed)
133 | pooled_adjs.append(A_pooled)
134 | subgraphs.append(subgraph)
135 | else:
136 | A_pooled, subgraph = adjacency_pool(pooled_adjs[-1],pool_type='clique')
137 | pooled_adjs.append(A_pooled)
138 | subgraphs.append(subgraph)
139 |
140 | pooled_adjs = [tf.convert_to_tensor(adj,dtype=tf.float32) for adj in pooled_adjs]
141 |
142 | return pooled_adjs, subgraphs
143 |
--------------------------------------------------------------------------------
/src/main/main.py:
--------------------------------------------------------------------------------
1 | import os
2 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
3 | import numpy as np
4 | import matplotlib.pyplot as plt
5 | import tensorflow as tf
6 | from layers.pool_utils import pooled_adjacencies
7 | from models import Models
8 | from utils import *
9 | from global_vars import *
10 |
11 | ## case = '2dlshape', '2dhole', '3dbeam', '3dbreast'
12 | case = '2dhole'
13 |
14 | ## network type = 'magnet', 'cnn'
15 | type = 'magnet'
16 |
17 | ## load train/test datasets
18 | data = get_data(case, type)
19 |
20 | dof, dim = dofdim[type][case]
21 |
22 | if type == 'magnet':
23 | A = get_adjacency(case)
24 | no_poolings, poolseed = magnet_pool_details[case]
25 | pooled_adjs, subgraphs = pooled_adjacencies(A, no_poolings=no_poolings, poolseed=poolseed)
26 |
27 | channels = magnet_channels[case]
28 | input_shape = (dof,)
29 |
30 | network = Models(input_shape, channels)
31 |
32 | if case == '2dhole' or case == '2dlshape':
33 | model = network.magnet_2d(pooled_adjs, subgraphs)
34 | elif case == '3dbeam':
35 | model = network.magnet_3dbeam(pooled_adjs, subgraphs)
36 | else:
37 | model = network.magnet_3dbreast(pooled_adjs, subgraphs)
38 |
39 |
40 | else:
41 | input_shape = cnn_input_shapes[case]
42 | channels = cnn_channels[case]
43 | network = Models(input_shape, channels)
44 |
45 | model = network.cnn_2d() if case == '2dlshape' else network.cnn_3d()
46 |
47 |
48 | training = False
49 |
50 | ## load the pretrained weights
51 | if training == False:
52 | model.load_weights(weights_path+case+'_'+type+'.h5')
53 | print("=== Pretrained weights are assigned to the model ===")
54 |
55 | ## for training = True
56 | else:
57 | no_epochs = epochs[type][case]
58 | new_weights_path = weights_path+case+'_'+type+'new.h5'
59 | lr_scheduler = lrate_scheduler(case,type)
60 | network.train(model, data, new_weights_path, lr_scheduler, no_epochs)
61 | model.load_weights(new_weights_path)
62 |
63 | ## Compute predictions
64 | test_features = data[-2]
65 | n_test = len(test_features)
66 | predictions = model.predict(test_features, batch_size=4)
67 | if type == 'cnn': predictions = predictions.reshape((n_test,dof))
68 |
69 | ## Convert degrees of freedom ordering to Acegen format
70 | predictions = reorder_dof(predictions,dof,dim)
71 |
72 | ## Remove zero paded region for the 2D L-shape CNN case
73 | if case == '2dlshape' and type == 'cnn':
74 | predictions = remove_pad(predictions)
75 |
76 |
77 | np.save(prediction_path+case+'_'+type+'_predicts.npy', predictions)
78 |
79 | print("=== Predictions are saved in : {}".format(prediction_path))
80 |
81 | ## Set to True to print the model
82 | network.print_summary(model, print=False)
83 |
--------------------------------------------------------------------------------
/src/main/models.py:
--------------------------------------------------------------------------------
1 |
2 | import os
3 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
4 | from layers.mag import MAg
5 | from layers.g_pool import G_Pool
6 | from layers.g_unpool import G_Unpool
7 | from utils import nth_adjacency
8 | from keras.models import Model
9 | from tensorflow.keras.optimizers import Adam
10 | from keras.callbacks import ModelCheckpoint, LearningRateScheduler
11 | from keras.layers import Input, ReLU, LeakyReLU, BatchNormalization, concatenate, Lambda
12 | from keras.layers import MaxPooling2D, MaxPooling3D, Conv2D, Conv3D, ZeroPadding2D, ZeroPadding3D, UpSampling2D, UpSampling3D
13 | import tensorflow as tf
14 |
15 | tf.random.set_seed(50)
16 |
17 |
18 | class Models():
19 |
20 | def __init__(self, input_shape, channels):
21 | self.input_shape = input_shape
22 | self.channels = channels
23 |
24 |
25 | def mag(self, channels, adjacency, hop, **kwargs):
26 | activation = LeakyReLU(alpha=0.01) if 'activation' not in kwargs else kwargs.get('activation')
27 | return MAg(channels=channels, activation=activation, adjacency= nth_adjacency(adjacency,hop))
28 |
29 |
30 | def conv2d(self, channels, input, **kwargs):
31 | activation = ReLU() if 'activation' not in kwargs else kwargs.get('activation')
32 | kernel = (3,3) if 'kernel' not in kwargs else kwargs.get('kernel')
33 |
34 | conv = Conv2D(channels, kernel, padding='same', data_format='channels_first')(input)
35 | if activation is not None:
36 | conv = BatchNormalization()(conv)
37 | conv = activation(conv)
38 |
39 | return conv
40 |
41 |
42 | def conv3d(self, channels,input, **kwargs):
43 | activation = ReLU() if 'activation' not in kwargs else kwargs.get('activation')
44 | kernel = (3,3,3) if 'kernel' not in kwargs else kwargs.get('kernel')
45 |
46 | conv = Conv3D(channels, kernel, padding='same', data_format='channels_first')(input)
47 | if activation is not None:
48 | conv = BatchNormalization()(conv)
49 | conv = activation(conv)
50 |
51 | return conv
52 |
53 |
54 | def magnet_2d(self, pooled_adjacencies, subgraphs):
55 |
56 | c0, c1, c2, c3 = self.channels
57 | A, Ap1, Ap2, Ap3 = pooled_adjacencies
58 | subgraph1, subgraph2, subgraph3 = subgraphs
59 |
60 | inputs = Input(shape=self.input_shape)
61 |
62 | mag1 = self.mag(c0, A, 2)(inputs)
63 | mag1 = self.mag(c0, A, 2)(mag1)
64 | pool1 = G_Pool(subgraph1, nodes=len(A))(mag1)
65 |
66 | mag2 = self.mag(c1, Ap1, 2)(pool1)
67 | mag2 = self.mag(c1, Ap1, 2)(mag2)
68 | pool2 = G_Pool(subgraph2, nodes=len(Ap1))(mag2)
69 |
70 | mag3 = self.mag(c2, Ap2, 2)(pool2)
71 | mag3 = self.mag(c2, Ap2, 2)(mag3)
72 | pool3 = G_Pool(subgraph3, nodes=len(Ap2))(mag3)
73 |
74 | mag4 = self.mag(c3, Ap3, 2)(pool3)
75 | mag4 = self.mag(c3, Ap3, 2)(mag4)
76 |
77 | up1 = G_Unpool(subgraph3, nodes=len(Ap2))(mag4)
78 | up1 = tf.concat((mag3,up1),axis=1)
79 | mag5 = self.mag(c2, Ap2, 2)(up1)
80 | mag5 = self.mag(c2, Ap2, 2)(mag5)
81 |
82 | up2 = G_Unpool(subgraph2, nodes=len(Ap1))(mag5)
83 | up2 = tf.concat((mag2,up2),axis=1)
84 | mag6 = self.mag(c1, Ap1, 2)(up2)
85 | mag6 = self.mag(c1, Ap1, 2)(mag6)
86 |
87 | up3 = G_Unpool(subgraph1, nodes=len(A))(mag6)
88 | up3 = tf.concat((mag1,up3),axis=1)
89 | mag7 = self.mag(c0, A, 2)(up3)
90 | mag7 = self.mag(c0, A, 2)(mag7)
91 |
92 | out = self.mag(2, A, 2, activation=None)(mag7)
93 |
94 | model = Model(inputs=inputs, outputs=out)
95 |
96 | return model
97 |
98 |
99 | def magnet_3dbeam(self, pooled_adjacencies, subgraphs):
100 |
101 | c0, c1, c2, c3, c4, c5 = self.channels
102 | A, Ap1, Ap2, Ap3, Ap4, Ap5 = pooled_adjacencies
103 | subgraph1, subgraph2, subgraph3, subgraph4, subgraph5 = subgraphs
104 |
105 | inputs = Input(shape=self.input_shape)
106 |
107 | mag1 = self.mag(c0, A, 2)(inputs)
108 | pool1 = G_Pool(subgraph1, nodes=len(A))(mag1)
109 |
110 | mag2 = self.mag(c1, Ap1, 2)(pool1)
111 | pool2 = G_Pool(subgraph2, nodes=len(Ap1))(mag2)
112 |
113 | mag3 = self.mag(c2, Ap2, 2)(pool2)
114 | pool3 = G_Pool(subgraph3, nodes=len(Ap2))(mag3)
115 |
116 | mag4 = self.mag(c3, Ap3, 2)(pool3)
117 | pool4 = G_Pool(subgraph4, nodes=len(Ap3))(mag4)
118 |
119 | mag5 = self.mag(c4, Ap4, 2)(pool4)
120 | pool5 = G_Pool(subgraph5, nodes=len(Ap4))(mag5)
121 |
122 | mag6 = self.mag(c5, Ap5, 3)(pool5)
123 |
124 | up1 = G_Unpool(subgraph5, nodes=len(Ap4))(mag6)
125 | up1 = tf.concat((mag5,up1),axis=1)
126 | mag7 = self.mag(c4, Ap4, 2)(up1)
127 |
128 | up2 = G_Unpool(subgraph4, nodes=len(Ap3))(mag7)
129 | up2 = tf.concat((mag4,up2),axis=1)
130 | mag8 = self.mag(c3, Ap3, 2)(up2)
131 |
132 | up3 = G_Unpool(subgraph3, nodes=len(Ap2))(mag8)
133 | up3 = tf.concat((mag3,up3),axis=1)
134 | mag9 = self.mag(c2, Ap2, 2)(up3)
135 |
136 | up4 = G_Unpool(subgraph2, nodes=len(Ap1))(mag9)
137 | up4 = tf.concat((mag2,up4),axis=1)
138 | mag10 = self.mag(c1, Ap1, 2)(up4)
139 |
140 | up5 = G_Unpool(subgraph1, nodes=len(A))(mag10)
141 | up5 = tf.concat((mag1,up5),axis=1)
142 | mag11 = self.mag(c0, A, 2)(up5)
143 |
144 | out = self.mag(3, A, 3, activation=None)(mag11)
145 |
146 | model = Model(inputs=inputs,outputs=out)
147 |
148 | return model
149 |
150 |
151 | def magnet_3dbreast(self, pooled_adjacencies, subgraphs):
152 |
153 | c0, c1, c2, c3, c4 = self.channels
154 | A, Ap1, Ap2, Ap3, Ap4 = pooled_adjacencies
155 | subgraph1, subgraph2, subgraph3, subgraph4 = subgraphs
156 |
157 | inputs = Input(shape=self.input_shape)
158 |
159 | mag1 = self.mag(c0, A, 2)(inputs)
160 | pool1 = G_Pool(subgraph1, nodes=len(A))(mag1)
161 |
162 | mag2 = self.mag(c1, Ap1, 2)(pool1)
163 | pool2 = G_Pool(subgraph2, nodes=len(Ap1))(mag2)
164 |
165 | mag3 = self.mag(c2, Ap2, 2)(pool2)
166 | pool3 = G_Pool(subgraph3, nodes=len(Ap2))(mag3)
167 |
168 | mag4 = self.mag(c3, Ap3, 2)(pool3)
169 | pool4 = G_Pool(subgraph4, nodes=len(Ap3))(mag4)
170 |
171 | mag5 = self.mag(c4, Ap4, 3)(pool4)
172 |
173 | up1 = G_Unpool(subgraph4, nodes=len(Ap3))(mag5)
174 | up1 = tf.concat((mag4,up1),axis=1)
175 | mag6 = self.mag(c3, Ap3, 2)(up1)
176 |
177 | up2 = G_Unpool(subgraph3, nodes=len(Ap2))(mag6)
178 | up2 = tf.concat((mag3,up2),axis=1)
179 | mag7 = self.mag(c2, Ap2, 2)(up2)
180 |
181 | up3 = G_Unpool(subgraph2, nodes=len(Ap1))(mag7)
182 | up3 = tf.concat((mag2,up3),axis=1)
183 | mag8 = self.mag(c1, Ap1, 2)(up3)
184 |
185 | up4 = G_Unpool(subgraph1, nodes=len(A))(mag8)
186 | up4 = tf.concat((mag1,up4),axis=1)
187 | mag9 = self.mag(c0, A, 2)(up4)
188 |
189 | out = self.mag(3, A, 3, activation=None)(mag9)
190 |
191 | model = Model(inputs=inputs,outputs=out)
192 |
193 | return model
194 |
195 |
196 | def cnn_2d(self):
197 |
198 | dim, n_x, n_y = self.input_shape
199 | c0, c1, c2 = self.channels
200 |
201 | inputs = Input(shape=(dim, n_x, n_y))
202 |
203 | conv1 = ZeroPadding2D(padding=2, data_format='channels_first')(inputs)
204 | conv1 = self.conv2d(c0,conv1)
205 | conv1 = self.conv2d(c0,conv1)
206 | pool1 = MaxPooling2D((2,2),data_format='channels_first')(conv1)
207 |
208 | conv2 = self.conv2d(c1, pool1)
209 | conv2 = self.conv2d(c1, conv2)
210 | pool2 = MaxPooling2D((2,2),data_format='channels_first')(conv2)
211 |
212 | conv3 = self.conv2d(c2, pool2)
213 | conv3 = self.conv2d(c2, conv3)
214 |
215 | up1 = UpSampling2D(size=(2,2),data_format='channels_first')(conv3)
216 | up1 = concatenate([conv2,up1],axis=1)
217 | conv4 = self.conv2d(c1, up1)
218 | conv4 = self.conv2d(c1, conv4)
219 |
220 | up2 = UpSampling2D(size=(2,2),data_format='channels_first')(conv4)
221 | up2 = concatenate([conv1,up2],axis=1)
222 | conv5 = self.conv2d(c0, up2)
223 | conv5 = self.conv2d(c0, conv5)
224 |
225 | conv6 = self.conv2d(dim, conv5, activation=None, kernel=(1,1))
226 | conv6 = Lambda(lambda x: x[:, :, 2:(n_x+2), 2:(n_y+2)])(conv6)
227 |
228 | model = Model(inputs=inputs, outputs=conv6)
229 |
230 | return model
231 |
232 |
233 | def cnn_3d(self):
234 |
235 | dim, n_x, n_y , n_z = self.input_shape
236 | c0, c1, c2, c3, c4 = self.channels
237 |
238 | inputs = Input(shape=(dim, n_x, n_y , n_z))
239 | ##
240 | conv1 = ZeroPadding3D(padding=2, data_format='channels_first')(inputs)
241 | conv1 = self.conv3d(c0, conv1)
242 | conv1 = self.conv3d(c0, conv1)
243 | pool1 = MaxPooling3D((2,2,2), data_format='channels_first')(conv1)
244 | ##
245 | conv2 = self.conv3d(c1, pool1)
246 | conv2 = self.conv3d(c1, conv2)
247 | pool2 = MaxPooling3D((2,2,2), data_format='channels_first')(conv2)
248 | ##
249 | conv3 = self.conv3d(c2, pool2)
250 | conv3 = self.conv3d(c2, conv3)
251 | pool3 = MaxPooling3D((2,2,2), data_format='channels_first')(conv3)
252 | ##
253 | conv4 = self.conv3d(c3,pool3)
254 | conv4 = self.conv3d(c3,conv4)
255 | pool4 = MaxPooling3D((2,2,2),data_format='channels_first')(conv4)
256 | ##
257 | conv5 = self.conv3d(c4,pool4)
258 | conv5 = self.conv3d(c4,conv5)
259 | ##
260 | up1 = UpSampling3D(size=(2,2,2),data_format='channels_first')(conv5)
261 | up1 = concatenate([conv4,up1],axis=1)
262 | conv6 = self.conv3d(c3,up1)
263 | conv6 = self.conv3d(c3,conv6)
264 | ##
265 | up2 = UpSampling3D(size=(2,2,2),data_format='channels_first')(conv6)
266 | up2 = concatenate([conv3,up2],axis=1)
267 | conv7 = self.conv3d(c2, up2)
268 | conv7 = self.conv3d(c2, conv7)
269 | #
270 | up3 = UpSampling3D(size=(2,2,2),data_format='channels_first')(conv7)
271 | up3 = concatenate([conv2,up3],axis=1)
272 | conv8 = self.conv3d(c1, up3)
273 | conv8 = self.conv3d(c1, conv8)
274 | #
275 | up4 = UpSampling3D(size=(2,2,2),data_format='channels_first')(conv8)
276 | up4 = concatenate([conv1,up4],axis=1)
277 | conv9 = self.conv3d(c0, up4)
278 | conv9 = self.conv3d(c0, conv9)
279 |
280 | conv10 = self.conv3d(dim, conv9, activation=None, kernel=(1,1,1))
281 | conv10 = Lambda(lambda x: x[:,:,2:(n_x+2), 2:(n_y+2),2:(n_z+2)])(conv10)
282 |
283 | model = Model(inputs=inputs, outputs=conv10)
284 |
285 | return model
286 |
287 | def train(self, model, data, path, lr_scheduler, epochs):
288 |
289 | X_train, Y_train, X_test, Y_test = data
290 |
291 | opt = Adam(lr = 0.0001)
292 | model.compile(optimizer=opt, loss='mean_squared_error')
293 |
294 | checkpoint = [LearningRateScheduler(lr_scheduler, verbose=1), ModelCheckpoint(path, monitor='val_loss', verbose=1,
295 | save_best_only=True,save_weights_only=True, mode='min', period=1)]
296 |
297 | print("\n \n === Training from scratch === \n \n ")
298 |
299 | hist = model.fit(X_train, Y_train,
300 | epochs= epochs,
301 | batch_size = 4,
302 | shuffle=False, validation_data=(X_test , Y_test),
303 | callbacks=checkpoint)
304 |
305 | return print(" \n \n === Training procedure completed === \n \n")
306 |
307 | @staticmethod
308 | def print_summary(model, print=False):
309 | if print == True:
310 | return model.summary()
311 |
--------------------------------------------------------------------------------
/src/main/utils.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import pandas as pd
3 | import itertools
4 | from global_vars import *
5 |
6 |
7 | def get_data(case, type):
8 |
9 | '''
10 | Import the datasets (numpy arrays) used in the paper
11 |
12 | Shape of X_train/Y_train = [n_train, dof]
13 | Shape of X_test/Y_test = [n_test, dof]
14 |
15 | dofs are ordered as : [1x, 2x, ... , nx, 1y, 2y, ... , ny, 1z, 2z, ... , nz]
16 |
17 | '''
18 |
19 | print_magnet()
20 |
21 | if type == 'cnn' and case=='2dhole' or type == 'cnn' and case =='3dbreast':
22 | raise ValueError('This case is not implemented')
23 |
24 |
25 | print("=== Loading dataset for the "+ type.upper() +" network and "+ case + " case === ")
26 |
27 | if case == '2dlshape' and type == 'cnn': case += '_padded'
28 |
29 | X_train = np.load(datapath+'features_train_'+str(case)+'.npy')
30 | Y_train = np.load(datapath+'labels_train_'+str(case)+'.npy')
31 |
32 | X_test = np.load(datapath+'features_test_'+str(case)+'.npy')
33 | Y_test = np.load(datapath+'labels_test_'+str(case)+'.npy')
34 |
35 | if type == 'cnn':
36 | # Need to reshape data to make it compatible with convolution layers
37 | n_train = len(X_train)
38 | n_test = len(X_test)
39 |
40 | if case == '3dbeam':
41 | dim, n_x, n_y, n_z = cnn_input_shapes[case]
42 |
43 | X_train = X_train.reshape(n_train, dim, n_x, n_y, n_z)
44 | Y_train = Y_train.reshape(n_train, dim, n_x, n_y, n_z)
45 |
46 | X_test = X_test.reshape(n_test, dim, n_x, n_y, n_z)
47 | Y_test = Y_test.reshape(n_test, dim, n_x, n_y, n_z)
48 |
49 | else:
50 | case = case.replace('_padded','')
51 |
52 | dim, n_x, n_y = cnn_input_shapes[case]
53 |
54 | X_train = X_train.reshape(n_train, dim, n_x, n_y)
55 | Y_train = Y_train.reshape(n_train, dim, n_x, n_y)
56 |
57 | X_test = X_test.reshape(n_test, dim, n_x, n_y)
58 | Y_test = Y_test.reshape(n_test, dim, n_x, n_y)
59 |
60 | return [X_train, Y_train, X_test, Y_test]
61 |
62 |
63 |
64 | def get_adjacency(case: str):
65 |
66 | '''
67 | Generates adjacancy matrix (inclues cross edges in elements) using the connectivity matrix.
68 |
69 | '''
70 |
71 | # dataframe for elemenet connectivity file
72 | df_adj = pd.read_csv('connectivity/connect_'+str(case)+'.csv', header=None)
73 |
74 | element_connectivity = df_adj.to_numpy() - 1 #Acegen numbering starts from 1
75 | n_elements = element_connectivity.shape[0]
76 | n_nodes = np.max(element_connectivity) + 1
77 |
78 | A = np.zeros((n_nodes,n_nodes))
79 |
80 | for i in range(n_elements):
81 |
82 | element = element_connectivity[i]
83 |
84 | t = [p for p in itertools.product(element, repeat=2)]
85 |
86 | for j in range(len(t)):
87 | A[t[j]] = 1
88 |
89 | return A
90 |
91 |
92 | def nth_adjacency(A, n):
93 |
94 | '''
95 | Gives n-th hop for the given adjacency matrix
96 |
97 | '''
98 |
99 | A_n = A
100 |
101 | if n == 1:
102 | A_n = A
103 |
104 | else:
105 |
106 | for i in range(n - 1):
107 | A_n = np.dot(A_n, A)
108 |
109 | non_zero = np.count_nonzero(A_n)
110 |
111 | rows, cols = np.nonzero(A_n)
112 | A_n[rows, cols] = np.ones(non_zero)
113 |
114 | return A_n
115 |
116 |
117 | def lrate_scheduler(case,type):
118 |
119 | '''
120 | Learning rate schedulers used in the paper. 2D and 3D cases use different schedulers
121 |
122 | '''
123 | if case == '2dlshape' or case =='2dhole':
124 | def scheduler(epoch, lr):
125 |
126 | if epoch < 10:
127 | lr = lr
128 | elif 10 < epoch < 200:
129 | lr = lr - (0.0001 - 0.00001)/(190)
130 | elif 200 < epoch < 900:
131 | lr = lr- (0.00001 - 0.000001)/(700)
132 | else:
133 | lr = lr
134 | return lr
135 |
136 | elif case =='3dbeam' and type =='cnn':
137 | def scheduler(epoch, lr):
138 |
139 | if epoch < 85:
140 | k = 0.001
141 | lr = lr * np.exp(-k * (epoch))
142 | else:
143 | lr = lr
144 | return lr
145 |
146 | else:
147 | def scheduler(epoch, lr):
148 |
149 | if epoch < 10:
150 | lr = lr
151 | elif 10 <= epoch < 100:
152 | lr = lr - (0.0001 - 0.000001)/(90)
153 | else:
154 | lr = lr
155 | return lr
156 |
157 | return scheduler
158 |
159 |
160 | def reorder_dof(predictions, dof, dim):
161 |
162 | '''
163 | Changes dof oredering to the Acegen format for entire predictions.
164 | Refer to original_order function below.
165 |
166 | Can be efficiently done as:
167 | predictions.reshape(len(predictions), dim, int(dof/dim)).transpose(0,2,1).reshape(len(predictions),dof)
168 |
169 | '''
170 |
171 | reorder_predictions = np.copy(predictions)
172 |
173 | for i in range(len(predictions)):
174 | reorder_predictions[i] = orginal_order(predictions[i],dof,dim)
175 |
176 | return reorder_predictions
177 |
178 |
179 | def orginal_order(array, dof, dim):
180 |
181 | '''
182 | Inputs:
183 |
184 | - Dof array in the form (1x, 2x, ... , nx, 1y, 2y ..., ny, 1z, ... ,nz)
185 |
186 | Outputs:
187 |
188 | - Array with original Acegen ordering (1x, 1y, 1z, 2x, 2y, 2z ...,nx,ny,nz)
189 |
190 | Can be efficiently done as: array.reshape(dim,int(dof/dim)).transpose().flatten()
191 |
192 | '''
193 |
194 | original_dof = np.zeros((dof,))
195 |
196 | if dim==2:
197 |
198 | dof_x = array[0:int(dof/dim)]
199 | dof_y = array[int(dof/dim):dof]
200 |
201 | for i in range(int(dof/dim)):
202 | original_dof[2*i] = dof_x[i]
203 | original_dof[2*i+1] = dof_y[i]
204 |
205 |
206 | elif dim==3:
207 |
208 | dof_x = array[0:int(dof/dim)]
209 | dof_y = array[int(dof/dim):int(2*dof/dim)]
210 | dof_z = array[int(2*dof/dim):dof]
211 |
212 | for i in range(int(dof/dim)):
213 | original_dof[3*i] = dof_x[i]
214 | original_dof[3*i+1] = dof_y[i]
215 | original_dof[3*i+2] = dof_z[i]
216 |
217 | return original_dof
218 |
219 | def remove_pad(predictions):
220 |
221 | '''
222 | To remove dofs in the 0 paded region for the L-shape cnn case.
223 |
224 | unpad_map_2dlshape.npy is the arrays for indices of non-zero padded region of the padded
225 | 2D L-shape domain.
226 |
227 | '''
228 |
229 | unpad_indices = np.load(srcpath+'/main/connectivity/unpad_map_2dlshape.npy')
230 |
231 | return predictions[:,unpad_indices]
232 |
233 |
234 | def max_disp_index(predictions, dof, dim):
235 |
236 | '''
237 | Gives array of maximum nodal displacements of all test examples.
238 | '''
239 |
240 | n_test = len(predictions)
241 | max_disps = np.zeros(n_test)
242 |
243 | for i in range(n_test):
244 | pred = predictions[i]
245 | pred = pred.reshape(int(dof/dim),dim)
246 | pred_norm = np.linalg.norm(pred,axis=1)
247 | max_disps[i] = np.max(abs(pred_norm))
248 |
249 | return np.argmax(max_disps)
250 |
251 |
252 | def print_magnet():
253 | print("\n")
254 | print(" ___ ___ ___ _ _ _____ _____ ")
255 | print(" | \/ | / _ \ | \ | || ___|_ _| ")
256 | print(" | . . |/ /_\ \ __ _| \| || |__ | | ")
257 | print(" | |\/| || _ |/ _` | . ` || __| | | ")
258 | print(" | | | || | | | (_| | |\ || |___ | | ")
259 | print(" \_| |_/\_| |_/\__, \_| \_/\____/ \_/ ")
260 | print(" __/ | ")
261 | print(" |___/ ")
262 | print("\n")
263 |
--------------------------------------------------------------------------------
/src/postprocess/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saurabhdeshpande93/MAgNET/b301c1d75a198e083014511f208fa018226ed86b/src/postprocess/__init__.py
--------------------------------------------------------------------------------
/src/postprocess/post.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import sys
3 | sys.path.append('../main/')
4 | from utils import get_data, reorder_dof, remove_pad, max_disp_index
5 | from global_vars import *
6 |
7 | ## case = '2dlshape', '2dhole', '3dbeam', '3dbreast'
8 | case = '2dhole'
9 | ## network type = 'magnet', 'cnn'
10 | type = 'magnet'
11 |
12 | ## Import predictions
13 | predictions = np.load(prediction_path+case+'_'+type+'_predicts.npy')
14 |
15 | ## Import deatures/labels and reorder dofs as per the Acegen compatible format
16 | dof, dim = dofdim[type][case]
17 |
18 | data = get_data(case, type)
19 | test_features, test_labels = data[-2], data[-1]
20 |
21 | test_labels = reorder_dof(test_labels.reshape((len(test_labels), dof)), dof, dim)
22 | test_features = reorder_dof(test_features.reshape((len(test_features), dof)), dof, dim)
23 |
24 | ## Remove zero padded region for L-shape CNN case
25 | if case == '2dlshape' and type == 'cnn':
26 | test_labels = remove_pad(test_labels)
27 | test_features = remove_pad(test_features)
28 | dof = 160 #unpaded dofs
29 |
30 | ## Absolute error of prediction
31 | error = np.abs(predictions - test_labels)
32 |
33 | print("=== Mean error of the test set is ", np.mean(error))
34 | print("=== Max error of the test set is ", np.max(error))
35 |
36 | ## Find out the example with maximum nodal displacement
37 | index = max_disp_index(predictions, dof, dim)
38 |
39 | ## Save prediction of single example to visualise it in Acegen
40 | test_viz = np.vstack((test_features[index],predictions[index],test_labels[index],error[index])).transpose()
41 | np.savetxt('visualisation/examples/'+str(case)+str(type)+'.csv', test_viz, delimiter=",")
42 |
43 | print("=== Example to be visualised is saved in : {}".format(visualisation_path))
44 |
--------------------------------------------------------------------------------
/src/postprocess/visualisation/2dlshape.nb:
--------------------------------------------------------------------------------
1 | (* Content-type: application/vnd.wolfram.mathematica *)
2 |
3 | (*** Wolfram Notebook File ***)
4 | (* http://www.wolfram.com/nb *)
5 |
6 | (* CreatedBy='Mathematica 12.1' *)
7 |
8 | (*CacheID: 234*)
9 | (* Internal cache information:
10 | NotebookFileLineBreakTest
11 | NotebookFileLineBreakTest
12 | NotebookDataPosition[ 158, 7]
13 | NotebookDataLength[ 33932, 687]
14 | NotebookOptionsPosition[ 32861, 663]
15 | NotebookOutlinePosition[ 33287, 680]
16 | CellTagsIndexPosition[ 33244, 677]
17 | WindowFrame->Normal*)
18 |
19 | (* Beginning of Notebook Content *)
20 | Notebook[{
21 | Cell[BoxData[
22 | RowBox[{
23 | RowBox[{"<<", "AceFEM`"}], ";"}]], "Input",
24 | CellChangeTimes->{{3.821960854645931*^9, 3.8219608753257465`*^9}, {
25 | 3.825409669055526*^9, 3.8254096828998632`*^9}, {3.8254106876336*^9,
26 | 3.8254106975507097`*^9}, {3.825420926827032*^9, 3.8254209279350243`*^9}},
27 | Background->RGBColor[0.87, 0.94, 1],
28 | CellLabel->
29 | "In[176]:=",ExpressionUUID->"0a911bc4-b23d-4c2b-8c9d-050cfe157332"],
30 |
31 | Cell["Import the prediction to be visualised.", "Text",
32 | CellChangeTimes->{{3.883825633093244*^9, 3.883825649572625*^9}, {
33 | 3.88856277931837*^9, 3.888562798499352*^9}},
34 | Background->RGBColor[
35 | 0.94, 0.91, 0.88],ExpressionUUID->"a6c61410-0551-49f2-a3ad-bbd4013c6827"],
36 |
37 | Cell[BoxData[{
38 | RowBox[{
39 | RowBox[{"input", " ", "=", " ",
40 | RowBox[{"Import", "[", "\"\\"", "]"}]}],
41 | ";"}], "\[IndentingNewLine]",
42 | RowBox[{
43 | RowBox[{"nn", "=",
44 | RowBox[{"input", "[",
45 | RowBox[{"[",
46 | RowBox[{"All", ",", "2"}], "]"}], "]"}]}], " ",
47 | ";"}], "\[IndentingNewLine]",
48 | RowBox[{
49 | RowBox[{"fem", " ", "=", " ",
50 | RowBox[{"input", "[",
51 | RowBox[{"[",
52 | RowBox[{"All", ",", "3"}], "]"}], "]"}]}], " ",
53 | ";"}], "\[IndentingNewLine]",
54 | RowBox[{
55 | RowBox[{"error", " ", "=", " ",
56 | RowBox[{"input", "[",
57 | RowBox[{"[",
58 | RowBox[{"All", ",", "4"}], "]"}], "]"}]}], ";"}], "\[IndentingNewLine]",
59 | RowBox[{
60 | RowBox[{"list", " ", "=", " ",
61 | RowBox[{"Partition", "[",
62 | RowBox[{"error", ",", " ", "2"}], "]"}]}], ";"}], "\[IndentingNewLine]",
63 | RowBox[{
64 | RowBox[{"nodeerror", " ", "=", " ",
65 | RowBox[{"(",
66 | RowBox[{"Norm", "/@", "list"}], ")"}]}], " ", ";"}]}], "Input",
67 | CellChangeTimes->{{3.8885627233856993`*^9, 3.8885627611731987`*^9}, {
68 | 3.888585527995905*^9, 3.8885855375060472`*^9}, {3.888585598067934*^9,
69 | 3.8885855985894613`*^9}, {3.889000549228243*^9, 3.8890005508592997`*^9}},
70 | Background->RGBColor[0.87, 0.94, 1],
71 | CellLabel->
72 | "In[177]:=",ExpressionUUID->"2bfc7563-8bdd-4eb1-a901-7d0d986a9ca5"],
73 |
74 | Cell["Setup the domain as used while generating the dataset. ", "Text",
75 | CellChangeTimes->{{3.883825633093244*^9, 3.883825649572625*^9}},
76 | Background->RGBColor[
77 | 0.94, 0.91, 0.88],ExpressionUUID->"80a249a0-be02-45bd-81cd-a64684a7ef1a"],
78 |
79 | Cell[BoxData[{
80 | RowBox[{
81 | RowBox[{"SMTInputData", "[", "]"}], ";"}], "\[IndentingNewLine]",
82 | RowBox[{
83 | RowBox[{"L", "=", "6"}], ";",
84 | RowBox[{"H", "=", "2"}], ";",
85 | RowBox[{"H2", "=",
86 | RowBox[{"6", "/", "7"}]}], ";",
87 | RowBox[{"nx", "=", "12"}], ";",
88 | RowBox[{"ny", "=", "3"}], ";", " ",
89 | RowBox[{"nx2", "=", "3"}], ";", " ",
90 | RowBox[{"ny2", "=", "7"}], ";"}], "\[IndentingNewLine]",
91 | RowBox[{
92 | RowBox[{"ntx", " ", "=", " ",
93 | RowBox[{"nx", "+", "nx2"}]}], ";", " ",
94 | RowBox[{"nty", " ", "=", " ", "ny2"}], ";"}], "\[IndentingNewLine]",
95 | RowBox[{
96 | RowBox[{"points", "=",
97 | RowBox[{"{",
98 | RowBox[{
99 | RowBox[{"{",
100 | RowBox[{"0", ",", "0"}], "}"}], ",",
101 | RowBox[{"{",
102 | RowBox[{
103 | RowBox[{"4", "*",
104 | RowBox[{"L", "/", "5"}]}], ",", "0"}], "}"}], ",",
105 | RowBox[{"{",
106 | RowBox[{
107 | RowBox[{"4", "*",
108 | RowBox[{"L", "/", "5"}]}], ",", "H2"}], "}"}], ",",
109 | RowBox[{"{",
110 | RowBox[{"0", ",", "H2"}], "}"}]}], "}"}]}],
111 | ";"}], "\[IndentingNewLine]",
112 | RowBox[{
113 | RowBox[{"points2", "=",
114 | RowBox[{"{",
115 | RowBox[{
116 | RowBox[{"{",
117 | RowBox[{
118 | RowBox[{"4", "*",
119 | RowBox[{"L", "/", "5"}]}], ",", "0"}], "}"}], ",",
120 | RowBox[{"{",
121 | RowBox[{"L", ",", "0"}], "}"}], ",",
122 | RowBox[{"{",
123 | RowBox[{"L", ",", "H"}], "}"}], ",",
124 | RowBox[{"{",
125 | RowBox[{
126 | RowBox[{"4", "*",
127 | RowBox[{"L", "/", "5"}]}], ",", "H"}], "}"}]}], "}"}]}],
128 | ";"}], "\[IndentingNewLine]",
129 | RowBox[{
130 | RowBox[{"SMTAddDomain", "[",
131 | RowBox[{
132 | "\"\<\[CapitalOmega]\>\"", ",", "\"\\"", ",",
133 | RowBox[{"{",
134 | RowBox[{
135 | RowBox[{"\"\\"", "\[Rule]", "500"}], ",",
136 | RowBox[{"\"\<\[Nu] *\>\"", "->", "0.4"}]}], "}"}]}], "]"}],
137 | ";"}], "\[IndentingNewLine]",
138 | RowBox[{
139 | RowBox[{"SMTAddEssentialBoundary", "[",
140 | RowBox[{
141 | RowBox[{
142 | RowBox[{"\"\\"", "==", "0"}], "&"}], ",",
143 | RowBox[{"1", "\[Rule]", "0"}], ",",
144 | RowBox[{"2", "\[Rule]", "0"}]}], "]"}], ";"}], "\[IndentingNewLine]",
145 | RowBox[{
146 | RowBox[{"SMTAddMesh", "[",
147 | RowBox[{
148 | RowBox[{"Polygon", "[", "points", "]"}], ",", "\"\<\[CapitalOmega]\>\"",
149 | ",", "\"\\"", ",",
150 | RowBox[{"{",
151 | RowBox[{"nx", ",", "ny"}], "}"}]}], "]"}], ";"}], "\n",
152 | RowBox[{
153 | RowBox[{"SMTAddMesh", "[",
154 | RowBox[{
155 | RowBox[{"Polygon", "[", "points2", "]"}], ",", "\"\<\[CapitalOmega]\>\"",
156 | ",", "\"\\"", ",",
157 | RowBox[{"{",
158 | RowBox[{"nx2", ",", "ny2"}], "}"}]}], "]"}],
159 | ";"}], "\[IndentingNewLine]",
160 | RowBox[{
161 | RowBox[{
162 | RowBox[{"SMTAnalysis", "[", "]"}], ";"}], " "}], "\n",
163 | RowBox[{
164 | RowBox[{"mrest", " ", "=", " ",
165 | RowBox[{"SMTShowMesh", "[",
166 | RowBox[{
167 | RowBox[{"\"\\"", "\[Rule]", "False"}], ",",
168 | RowBox[{"\"\\"", "\[Rule]", "False"}], ",",
169 | RowBox[{"\"\\"", "\[Rule]", "Gray"}], ",",
170 | RowBox[{"\"\\"", "\[Rule]", "False"}], ",",
171 | RowBox[{"\"\\"", "\[Rule]", "300"}]}], "]"}]}],
172 | ";"}]}], "Input",
173 | CellChangeTimes->{
174 | 3.821965192044854*^9, {3.8219653154195557`*^9, 3.8219653189953995`*^9}, {
175 | 3.8219655397845397`*^9, 3.8219655864450216`*^9}, {3.821965710134426*^9,
176 | 3.8219657350041943`*^9}, {3.8219657828942485`*^9,
177 | 3.8219658015948415`*^9}, {3.8219665355432262`*^9,
178 | 3.8219665401324463`*^9}, {3.821966847511552*^9, 3.821966849751898*^9}, {
179 | 3.821966920841444*^9, 3.8219669233415604`*^9}, {3.8219669893214054`*^9,
180 | 3.8219670791012683`*^9}, {3.821967122331189*^9, 3.82196716523065*^9}, {
181 | 3.8219671973207536`*^9, 3.821967260351164*^9}, {3.821967304220663*^9,
182 | 3.8219673107368546`*^9}, {3.8221241416830587`*^9, 3.822124194147181*^9}, {
183 | 3.8221242404481792`*^9, 3.822124240592225*^9}, {3.8221242875783453`*^9,
184 | 3.822124295123638*^9}, 3.822139543350972*^9, {3.822139693442659*^9,
185 | 3.8221397922157383`*^9}, {3.822139842571007*^9, 3.822139868395749*^9}, {
186 | 3.822139936535603*^9, 3.822139943526333*^9}, {3.825409219485692*^9,
187 | 3.8254092874766293`*^9}, {3.825409352771736*^9, 3.8254093572002697`*^9}, {
188 | 3.825409483191493*^9, 3.825409537143609*^9}, {3.8254095952580423`*^9,
189 | 3.825409596553171*^9}, {3.825409650603897*^9, 3.825409658073277*^9}, {
190 | 3.8254098275676727`*^9, 3.825409834138969*^9}, {3.825410068515636*^9,
191 | 3.825410071176087*^9}, {3.8254105764576607`*^9, 3.825410591281969*^9}, {
192 | 3.825410684488536*^9, 3.825410684847625*^9}, {3.825410740593747*^9,
193 | 3.825410754479602*^9}, {3.825411081885809*^9, 3.825411174851499*^9},
194 | 3.825411231291931*^9, {3.8254115365942497`*^9, 3.825411548914361*^9}, {
195 | 3.8254115796332912`*^9, 3.825411593331539*^9}, {3.825411638183797*^9,
196 | 3.825411670212558*^9}, {3.825420916649703*^9, 3.825420962170663*^9},
197 | 3.825421028873686*^9, {3.825421071803864*^9, 3.825421076471592*^9}, {
198 | 3.825421121274477*^9, 3.825421141689094*^9}, 3.8254211761053743`*^9, {
199 | 3.8254212074667*^9, 3.825421257520597*^9}, {3.8254214070556507`*^9,
200 | 3.825421408093533*^9}, {3.830243222372376*^9, 3.830243228161334*^9}, {
201 | 3.8302433053283777`*^9, 3.830243377861684*^9}, {3.8302434862830687`*^9,
202 | 3.830243487236199*^9}, {3.8302436052356033`*^9, 3.830243615460943*^9}, {
203 | 3.830243789050218*^9, 3.830243789508829*^9}, 3.830243821596486*^9,
204 | 3.830245710432716*^9, {3.830245976581883*^9, 3.830246012938117*^9},
205 | 3.830246064578821*^9, {3.830248618436378*^9, 3.830248635363606*^9}, {
206 | 3.8302487359850473`*^9, 3.830248742398052*^9}, {3.830327746795968*^9,
207 | 3.83032775312929*^9}, {3.834135116793043*^9, 3.834135138963889*^9}, {
208 | 3.834399110371314*^9, 3.8343992361563883`*^9}, 3.834399445990974*^9, {
209 | 3.83440077200359*^9, 3.8344007921644897`*^9}, {3.834401863168833*^9,
210 | 3.8344018745148077`*^9}, {3.834402058347307*^9, 3.834402094425786*^9}, {
211 | 3.8344022741504297`*^9, 3.8344022744412823`*^9}, {3.834476095685998*^9,
212 | 3.8344761159055634`*^9}, {3.834476173418168*^9, 3.834476178896414*^9}, {
213 | 3.834564426605702*^9, 3.8345644303244753`*^9}, 3.834564692683526*^9, {
214 | 3.836467924576872*^9, 3.836467927981073*^9}, {3.836467988658051*^9,
215 | 3.8364680037475986`*^9}, {3.836547222203988*^9, 3.8365472346180553`*^9}, {
216 | 3.836547288867098*^9, 3.836547311993544*^9}, 3.837152535457017*^9, {
217 | 3.837152686873437*^9, 3.837152713937914*^9}, {3.8371529631860933`*^9,
218 | 3.837152976875746*^9}, {3.837153398062256*^9, 3.837153398308392*^9}, {
219 | 3.858262398601037*^9, 3.8582624105102463`*^9}, {3.858262619319726*^9,
220 | 3.858262620153852*^9}, 3.871534067005701*^9, {3.8715477850482807`*^9,
221 | 3.8715477855722218`*^9}, {3.871547851466426*^9, 3.871547851738098*^9}, {
222 | 3.871548076085926*^9, 3.871548112693244*^9}, {3.871550853924492*^9,
223 | 3.871550865386997*^9}, {3.871721642267828*^9, 3.87172164954128*^9}, {
224 | 3.888553462714451*^9, 3.888553474177103*^9}, {3.888553523091007*^9,
225 | 3.888553542841443*^9}, {3.888562668422887*^9, 3.888562668971291*^9},
226 | 3.888562708392735*^9, {3.8885627657636423`*^9, 3.888562771756201*^9}, {
227 | 3.888562818327858*^9, 3.888562837694729*^9}, {3.88856301736588*^9,
228 | 3.888563017576948*^9}, {3.8885631027410603`*^9, 3.888563106541029*^9}},
229 | Background->RGBColor[0.87, 0.94, 1],
230 | CellLabel->
231 | "In[183]:=",ExpressionUUID->"4798baed-be29-492f-8f8b-bd6d61f81a6e"],
232 |
233 | Cell["Visualise FEM and NN Predictions ", "Text",
234 | CellChangeTimes->{{3.883825633093244*^9, 3.883825649572625*^9}, {
235 | 3.886921976843274*^9, 3.8869219865627317`*^9}},
236 | Background->RGBColor[
237 | 0.94, 0.91, 0.88],ExpressionUUID->"9aac0009-712e-4e4f-b0ba-874038fb84c9"],
238 |
239 | Cell[CellGroupData[{
240 |
241 | Cell[BoxData[
242 | RowBox[{
243 | RowBox[{"(*",
244 | RowBox[{"Assign", " ", "true", " ", "FEM", " ",
245 | RowBox[{"solutions", ".", " ", "Red"}], " ", "mesh"}], "*)"}],
246 | "\[IndentingNewLine]",
247 | RowBox[{
248 | RowBox[{
249 | RowBox[{"SMTNodeData", "[",
250 | RowBox[{"\"\\"", ",",
251 | RowBox[{"Partition", "[",
252 | RowBox[{"fem", " ", ",", "2"}], "]"}]}], "]"}], ";"}],
253 | "\[IndentingNewLine]",
254 | RowBox[{
255 | RowBox[{"mfem", "=",
256 | RowBox[{"SMTShowMesh", "[",
257 | RowBox[{
258 | RowBox[{"\"\\"", "\[Rule]", "False"}], ",",
259 | RowBox[{"\"\\"", "\[Rule]", "True"}], ",",
260 | RowBox[{"\"\\"", "\[Rule]", "Red"}], ",",
261 | RowBox[{"\"\\"", "\[Rule]", "False"}], ",",
262 | RowBox[{"\"\\"", "\[Rule]", "300"}]}], "]"}]}], ";"}],
263 | "\[IndentingNewLine]", "\[IndentingNewLine]",
264 | RowBox[{"(*",
265 | RowBox[{"Assign", " ", "neural", " ", "network", " ",
266 | RowBox[{"predictions", ".", " ", "Blue"}], " ", "mesh"}], "*)"}],
267 | "\[IndentingNewLine]",
268 | RowBox[{
269 | RowBox[{"SMTNodeData", "[",
270 | RowBox[{"\"\\"", ",",
271 | RowBox[{"Partition", "[",
272 | RowBox[{"nn", ",", "2"}], "]"}]}], "]"}], ";"}], "\[IndentingNewLine]",
273 | RowBox[{
274 | RowBox[{"mnn", "=",
275 | RowBox[{"SMTShowMesh", "[",
276 | RowBox[{
277 | RowBox[{"\"\\"", "\[Rule]", "False"}], ",",
278 | RowBox[{"\"\\"", "\[Rule]", "True"}], ",",
279 | RowBox[{"\"\\"", "\[Rule]", "Blue"}], ",",
280 | RowBox[{"\"\\"", "\[Rule]", "False"}], ",",
281 | RowBox[{"\"\\"", "\[Rule]", "300"}]}], "]"}]}], " ", ";"}],
282 | "\[IndentingNewLine]", "\[IndentingNewLine]",
283 | RowBox[{"(*",
284 | RowBox[{"Plot", " ", "prediction", " ", "error"}], "*)"}],
285 | "\[IndentingNewLine]",
286 | RowBox[{
287 | RowBox[{"errorplt", "=",
288 | RowBox[{"SMTShowMesh", "[",
289 | RowBox[{
290 | RowBox[{"\"\\"", "\[Rule]", "False"}], ",",
291 | RowBox[{"\"\\"", "\[Rule]", "True"}], ",",
292 | RowBox[{"\"\\"", "\[Rule]", "False"}], ",",
293 | RowBox[{"\"\\"", "\[Rule]", " ", "nodeerror"}], ",",
294 | RowBox[{"\"\\"", "\[Rule]", " ", "Black"}], ",",
295 | RowBox[{"\"\\"", "\[Rule]",
296 | RowBox[{"{",
297 | RowBox[{"0.00147", ",", "0.0143", ",", "5"}], "}"}]}], ",",
298 | RowBox[{"\"\\"", "\[Rule]", "350"}], ",",
299 | RowBox[{
300 | "\"\