Debian Codegraph @

packages/panzer/adapters-stk/test/local_mesh/PanzerSTK_UnitTest_BuildMesh.cpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10
11 #include "PanzerSTK_UnitTest_BuildMesh.hpp"
12
13 #include "Teuchos_ParameterList.hpp"
14 #include "Teuchos_Assert.hpp"
15
16 #include "Panzer_STK_Interface.hpp"
17
18 #include "PanzerSTK_UnitTest_STKInterfaceGenerator.hpp"
19
20 namespace panzer_stk
21 {
22
23 Teuchos::RCP<panzer_stk::STK_Interface>
24 buildMesh(const std::vector<int> & N,
25 const std::vector<int> & B,
26 const std::vector<double> & L)
27 {
28
29 const int num_dims = N.size();
30
31 TEUCHOS_ASSERT(L.size() == static_cast<std::size_t>(num_dims));
32
33 Teuchos::ParameterList mesh_parameters("Mesh");
34
35 mesh_parameters.set<double>("X0",-L[0]/2.);
36 mesh_parameters.set<double>("Xf", L[0]/2.);
37 mesh_parameters.set<int>("X Elements", N[0]);
38 mesh_parameters.set<int>("X Blocks", B[0]);
39 if(num_dims>1){
40 mesh_parameters.set<double>("Y0",-L[1]/2.);
41 mesh_parameters.set<double>("Yf", L[1]/2.);
42 mesh_parameters.set<int>("Y Elements", N[1]);
43 mesh_parameters.set<int>("Y Blocks", B[1]);
44 }
45 if(num_dims>2){
46 mesh_parameters.set<double>("Z0",-L[2]/2.);
47 mesh_parameters.set<double>("Zf", L[2]/2.);
48 mesh_parameters.set<int>("Z Elements", N[2]);
49 mesh_parameters.set<int>("Z Blocks", B[2]);
50 }
51
52 if(num_dims == 1){
53 mesh_parameters.set<std::string>("Mesh Type","Line");
54 } else if(num_dims == 2){
55 mesh_parameters.set<std::string>("Mesh Type","Quad");
56 } else if(num_dims == 3){
57 mesh_parameters.set<std::string>("Mesh Type","Hex");
58 } else {
59 TEUCHOS_ASSERT(false);
60 }
61
62 return generateMesh(mesh_parameters);
63 }
64
65
66 Teuchos::RCP<panzer_stk::STK_Interface>
67 buildParallelMesh(const std::vector<int> & N,
68 const std::vector<int> & B,
69 const std::vector<int> & P,
70 const std::vector<double> & L,
71 const std::vector<int> & periodic_dims)
72 {
73
74 const size_t num_dims = N.size();
75
76 TEUCHOS_ASSERT(L.size() == num_dims);
77 TEUCHOS_ASSERT(P.size() == num_dims);
78
79 Teuchos::ParameterList mesh_parameters("Mesh");
80
81 mesh_parameters.set<double>("X0",-L[0]/2.);
82 mesh_parameters.set<double>("Xf", L[0]/2.);
83 mesh_parameters.set<int>("X Elements", N[0]);
84 mesh_parameters.set<int>("X Blocks", B[0]);
85
86 // The line mesh factory doesn't allow this
87 if(num_dims>1)
88 mesh_parameters.set<int>("X Procs", P[0]);
89
90 if(num_dims>1){
91 mesh_parameters.set<double>("Y0",-L[1]/2.);
92 mesh_parameters.set<double>("Yf", L[1]/2.);
93 mesh_parameters.set<int>("Y Elements", N[1]);
94 mesh_parameters.set<int>("Y Blocks", B[1]);
95 mesh_parameters.set<int>("Y Procs", P[1]);
96 }
97 if(num_dims>2){
98 mesh_parameters.set<double>("Z0",-L[2]/2.);
99 mesh_parameters.set<double>("Zf", L[2]/2.);
100 mesh_parameters.set<int>("Z Elements", N[2]);
101 mesh_parameters.set<int>("Z Blocks", B[2]);
102 mesh_parameters.set<int>("Z Procs", P[2]);
103 }
104
105 if(num_dims == 1){
106 mesh_parameters.set<std::string>("Mesh Type","Line");
107 } else if(num_dims == 2){
108 mesh_parameters.set<std::string>("Mesh Type","Quad");
109 } else if(num_dims == 3){
110 mesh_parameters.set<std::string>("Mesh Type","Hex");
111 } else {
112 TEUCHOS_ASSERT(false);
113 }
114
115 if(periodic_dims.size() > 0){
116 auto & periodic_params = mesh_parameters.sublist("Periodic BCs");
117 int arg=1;
118 for(const auto & periodic_dim : periodic_dims){
119 if(periodic_dim == 0){
120 if(num_dims==1)
121 periodic_params.set("Periodic Condition " +std::to_string(arg++), "y-coord 1.e-8: left;right");
122 else if(num_dims==2){
123 periodic_params.set("Periodic Condition " +std::to_string(arg++), "y-coord 1.e-8: left;right");
124 periodic_params.set("Periodic Condition " +std::to_string(arg++), "y-edge 1.e-8: left;right");
125 } else if(num_dims==3){
126 periodic_params.set("Periodic Condition " +std::to_string(arg++), "yz-coord 1.e-8: left;right");
127 periodic_params.set("Periodic Condition " +std::to_string(arg++), "yz-edge 1.e-8: left;right");
128 periodic_params.set("Periodic Condition " +std::to_string(arg++), "yz-face 1.e-8: left;right");
129 }
130 } else if(periodic_dim == 1){
131 if(num_dims==2){
132 periodic_params.set("Periodic Condition " +std::to_string(arg++), "x-coord 1.e-8: top;bottom");
133 periodic_params.set("Periodic Condition " +std::to_string(arg++), "x-edge 1.e-8: top;bottom");
134 } else if(num_dims==3){
135 periodic_params.set("Periodic Condition " +std::to_string(arg++), "xz-coord 1.e-8: top;bottom");
136 periodic_params.set("Periodic Condition " +std::to_string(arg++), "xz-edge 1.e-8: top;bottom");
137 periodic_params.set("Periodic Condition " +std::to_string(arg++), "xz-face 1.e-8: top;bottom");
138 }
139 } else if(periodic_dim == 2){
140 if(num_dims==3){
141 periodic_params.set("Periodic Condition " +std::to_string(arg++), "xy-coord 1.e-8: front;back");
142 periodic_params.set("Periodic Condition " +std::to_string(arg++), "xy-edge 1.e-8: front;back");
143 periodic_params.set("Periodic Condition " +std::to_string(arg++), "xy-face 1.e-8: front;back");
144 }
145 }
146 }
147 periodic_params.set("Count",arg-1);
148 }
149
150 return generateMesh(mesh_parameters);
151 }
152
153 }