20 #ifndef __mast_mesh_generation_panel_3d_h__ 21 #define __mast_mesh_generation_panel_3d_h__ 30 #include <libmesh/system.h> 31 #include <libmesh/unstructured_mesh.h> 32 #include <libmesh/fe_type.h> 33 #include <libmesh/string_to_enum.h> 34 #include <libmesh/mesh_generation.h> 35 #include <libmesh/elem.h> 36 #include <libmesh/node.h> 37 #include <libmesh/boundary_info.h> 38 #include <libmesh/dirichlet_boundaries.h> 39 #include <libmesh/zero_function.h> 40 #include <libmesh/mesh_refinement.h> 41 #include <libmesh/mesh_modification.h> 46 namespace Generation {
51 template <
typename ScalarType>
61 template <
typename ContextType>
62 inline ScalarType
value(ContextType& c)
const {
63 ScalarType v=(fabs(c.qp_location(0)-
_l1*0.5) <= 0.5*
_frac*
_l1)?
_p:0.;
67 template <
typename ContextType,
typename ScalarFieldType>
69 const ScalarFieldType& f)
const {
78 template <
typename ScalarType>
81 template <
typename Context>
86 length = c.input(
"length",
"length of domain along x-axis", 0.3),
87 height = c.input(
"height",
"length of domain along y-axis", 0.03),
88 width = c.input(
"width",
"length of domain along z-axis", 0.3);
90 return length * height * width;
105 return i + (nx+1)*(j + k*(ny+1));
110 return i + (2*nx+1)*(j + k*(2*ny+1));
114 Error(
false,
"Invalid element type");
117 return libMesh::invalid_uint;
128 const real_t dirichlet_length_fraction,
129 const libMesh::ElemType type) {
131 Assert0(type == libMesh::HEX8 || type == libMesh::HEX27,
132 "Method only implemented for Hex8/Hex27");
137 libMesh::BoundaryInfo & boundary_info = mesh.get_boundary_info();
139 mesh.set_mesh_dimension(3);
140 mesh.set_spatial_dimension(3);
141 mesh.reserve_elem(nx*ny*nz);
143 if (type == libMesh::HEX8)
144 mesh.reserve_nodes( (nx+1)*(ny+1)*(nz+1) );
145 else if (type == libMesh::HEX27)
146 mesh.reserve_nodes( (2*nx+1)*(2*ny+1)*(2*nz+1) );
155 std::map<uint_t, libMesh::Node*> nodes;
163 case libMesh::HEX8: {
165 for (
uint_t k=0; k<=nz; k++)
166 for (
uint_t j=0; j<=ny; j++)
167 for (
uint_t i=0; i<=nx; i++) {
169 mesh.add_point(libMesh::Point(static_cast<real_t>(i)/static_cast<real_t>(nx)*length,
170 static_cast<real_t>(j)/static_cast<real_t>(ny)*height,
171 static_cast<real_t>(k)/static_cast<real_t>(nz)*width),
180 case libMesh::HEX27: {
182 for (
uint_t k=0; k<=(2*nz); k++)
183 for (
uint_t j=0; j<=(2*ny); j++)
184 for (
uint_t i=0; i<=(2*nx); i++) {
186 mesh.add_point(libMesh::Point(static_cast<real_t>(i)/static_cast<real_t>(2*nx)*length,
187 static_cast<real_t>(j)/static_cast<real_t>(2*ny)*height,
188 static_cast<real_t>(k)/static_cast<real_t>(2*nz)*width),
198 Assert0(
false,
"ERROR: Unrecognized 3D element type.");
208 for (
uint_t k=0; k<nz; k++)
209 for (
uint_t j=0; j<ny; j++)
210 for (
uint_t i=0; i<nx; i++) {
214 elem->set_id(elem_id++);
217 elem->set_node(0) = nodes[
idx(type,nx,ny,i,j,k) ];
218 elem->set_node(1) = nodes[
idx(type,nx,ny,i+1,j,k) ];
219 elem->set_node(2) = nodes[
idx(type,nx,ny,i+1,j+1,k) ];
220 elem->set_node(3) = nodes[
idx(type,nx,ny,i,j+1,k) ];
221 elem->set_node(4) = nodes[
idx(type,nx,ny,i,j,k+1) ];
222 elem->set_node(5) = nodes[
idx(type,nx,ny,i+1,j,k+1) ];
223 elem->set_node(6) = nodes[
idx(type,nx,ny,i+1,j+1,k+1)];
224 elem->set_node(7) = nodes[
idx(type,nx,ny,i,j+1,k+1) ];
227 boundary_info.add_side(elem, 0, 0);
230 boundary_info.add_side(elem, 5, 5);
233 boundary_info.add_side(elem, 1, 1);
236 boundary_info.add_side(elem, 3, 3);
239 boundary_info.add_side(elem, 4, 4);
242 boundary_info.add_side(elem, 2, 2);
245 if (k == 0 && j >= (1.-dirichlet_length_fraction)* ny)
246 boundary_info.add_side(elem, 0, 6);
249 if (i == (nx-1) && j >= (1.-dirichlet_length_fraction)* ny)
250 boundary_info.add_side(elem, 2, 7);
253 if (i == 0 && j >= (1.-dirichlet_length_fraction)* ny)
254 boundary_info.add_side(elem, 4, 8);
257 if (k == (nz-1) && j >= (1.-dirichlet_length_fraction)* ny)
258 boundary_info.add_side(elem, 5, 9);
264 case libMesh::HEX27: {
266 for (
uint_t k=0; k<(2*nz); k += 2)
267 for (
uint_t j=0; j<(2*ny); j += 2)
268 for (
uint_t i=0; i<(2*nx); i += 2)
272 elem->set_id(elem_id++);
275 elem->set_node(0) = nodes[
idx(type,nx,ny,i, j, k) ];
276 elem->set_node(1) = nodes[
idx(type,nx,ny,i+2,j, k) ];
277 elem->set_node(2) = nodes[
idx(type,nx,ny,i+2,j+2,k) ];
278 elem->set_node(3) = nodes[
idx(type,nx,ny,i, j+2,k) ];
279 elem->set_node(4) = nodes[
idx(type,nx,ny,i, j, k+2)];
280 elem->set_node(5) = nodes[
idx(type,nx,ny,i+2,j, k+2)];
281 elem->set_node(6) = nodes[
idx(type,nx,ny,i+2,j+2,k+2)];
282 elem->set_node(7) = nodes[
idx(type,nx,ny,i, j+2,k+2)];
283 elem->set_node(8) = nodes[
idx(type,nx,ny,i+1,j, k) ];
284 elem->set_node(9) = nodes[
idx(type,nx,ny,i+2,j+1,k) ];
285 elem->set_node(10) = nodes[
idx(type,nx,ny,i+1,j+2,k) ];
286 elem->set_node(11) = nodes[
idx(type,nx,ny,i, j+1,k) ];
287 elem->set_node(12) = nodes[
idx(type,nx,ny,i, j, k+1)];
288 elem->set_node(13) = nodes[
idx(type,nx,ny,i+2,j, k+1)];
289 elem->set_node(14) = nodes[
idx(type,nx,ny,i+2,j+2,k+1)];
290 elem->set_node(15) = nodes[
idx(type,nx,ny,i, j+2,k+1)];
291 elem->set_node(16) = nodes[
idx(type,nx,ny,i+1,j, k+2)];
292 elem->set_node(17) = nodes[
idx(type,nx,ny,i+2,j+1,k+2)];
293 elem->set_node(18) = nodes[
idx(type,nx,ny,i+1,j+2,k+2)];
294 elem->set_node(19) = nodes[
idx(type,nx,ny,i, j+1,k+2)];
296 elem->set_node(20) = nodes[
idx(type,nx,ny,i+1,j+1,k) ];
297 elem->set_node(21) = nodes[
idx(type,nx,ny,i+1,j, k+1)];
298 elem->set_node(22) = nodes[
idx(type,nx,ny,i+2,j+1,k+1)];
299 elem->set_node(23) = nodes[
idx(type,nx,ny,i+1,j+2,k+1)];
300 elem->set_node(24) = nodes[
idx(type,nx,ny,i, j+1,k+1)];
301 elem->set_node(25) = nodes[
idx(type,nx,ny,i+1,j+1,k+2)];
302 elem->set_node(26) = nodes[
idx(type,nx,ny,i+1,j+1,k+1)];
305 boundary_info.add_side(elem, 0, 0);
308 boundary_info.add_side(elem, 5, 5);
311 boundary_info.add_side(elem, 1, 1);
314 boundary_info.add_side(elem, 3, 3);
317 boundary_info.add_side(elem, 4, 4);
320 boundary_info.add_side(elem, 2, 2);
323 if (k == 0 && j >= (1.-dirichlet_length_fraction)* 2*ny)
324 boundary_info.add_side(elem, 0, 6);
327 if (i == 2*(nx-1) && j >= (1.-dirichlet_length_fraction)* 2*ny)
328 boundary_info.add_side(elem, 2, 7);
331 if (i == 0 && j >= (1.-dirichlet_length_fraction)* 2*ny)
332 boundary_info.add_side(elem, 4, 8);
335 if (k == 2*(nz-1) && j >= (1.-dirichlet_length_fraction)* 2*ny)
336 boundary_info.add_side(elem, 5, 9);
343 Assert0(
false,
"ERROR: Unrecognized 3D element type.");
347 boundary_info.sideset_name(0) =
"back";
348 boundary_info.sideset_name(1) =
"bottom";
349 boundary_info.sideset_name(2) =
"right";
350 boundary_info.sideset_name(3) =
"top";
351 boundary_info.sideset_name(4) =
"left";
352 boundary_info.sideset_name(5) =
"front";
353 boundary_info.sideset_name(6) =
"back_dirichlet";
354 boundary_info.sideset_name(7) =
"right_dirichlet";
355 boundary_info.sideset_name(8) =
"left_dirichlet";
356 boundary_info.sideset_name(9) =
"front_dirichlet";
359 boundary_info.nodeset_name(0) =
"back";
360 boundary_info.nodeset_name(1) =
"bottom";
361 boundary_info.nodeset_name(2) =
"right";
362 boundary_info.nodeset_name(3) =
"top";
363 boundary_info.nodeset_name(4) =
"left";
364 boundary_info.nodeset_name(5) =
"front";
367 mesh.prepare_for_use ();
372 template <
typename Context>
375 libMesh::UnstructuredMesh& mesh) {
378 length = c.input(
"length",
"length of domain along x-axis", 0.3),
379 height = c.input(
"height",
"length of domain along y-axis", 0.03),
380 width = c.input(
"width",
"length of domain along z-axis", 0.3),
381 dirichlet_length_fraction = c.input
382 (
"dirichlet_length_fraction",
383 "length fraction of the truss boundary where dirichlet condition is applied",
387 nx_divs = c.input(
"nx_divs",
"number of elements along x-axis", 100),
388 ny_divs = c.input(
"ny_divs",
"number of elements along y-axis", 10),
389 nz_divs = c.input(
"nz_divs",
"number of elements along z-axis", 100),
390 n_refine= c.input(
"n_uniform_refinement",
"number of times the mesh is uniformly refined", 0);
393 t = c.input(
"elem_type",
"type of geometric element in the mesh",
"hex8");
396 e_type = libMesh::Utility::string_to_enum<libMesh::ElemType>(t);
402 if (c.sol_fe_order > 1 && e_type == libMesh::HEX8)
403 e_type = libMesh::HEX27;
404 else if (c.rho_fe_order > 1 && e_type == libMesh::TET4)
405 e_type = libMesh::TET10;
411 nx_divs, ny_divs, nz_divs,
415 dirichlet_length_fraction,
421 libMesh::MeshRefinement(mesh).uniformly_refine(n_refine);
422 libMesh::MeshTools::Modification::flatten(mesh);
428 template <
typename Context>
432 c.sys->get_dof_map().add_dirichlet_boundary
433 (libMesh::DirichletBoundary({6, 7, 8, 9}, {0, 1, 2}, libMesh::ZeroFunction<real_t>()));
438 template <
typename ScalarType,
typename InitType>
439 std::unique_ptr<pressure_t<ScalarType>>
443 length = c.input(
"length",
"length of domain along x-axis", 0.3),
444 frac = c.input(
"loadlength_fraction",
"fraction of boundary length on which pressure will act", 1.0),
445 p_val = c.input(
"pressure",
"pressure on side of domain", 2.e6);
448 std::unique_ptr<pressure_t<ScalarType>>
456 template <
typename ScalarType,
typename Context>
465 Assert2(c.rho_fe_family == libMesh::LAGRANGE,
466 c.rho_fe_family, libMesh::LAGRANGE,
467 "Method assumes Lagrange interpolation function for density");
468 Assert2(c.rho_fe_order == libMesh::FIRST,
469 c.rho_fe_order, libMesh::FIRST,
470 "Method assumes Lagrange interpolation function for density");
473 vf = c.input(
"volume_fraction",
"upper limit for the volume fraction", 0.2);
476 sys_num = c.rho_sys->number(),
477 first_dof = c.rho_sys->get_dof_map().first_dof(c.rho_sys->comm().rank()),
478 end_dof = c.rho_sys->get_dof_map().end_dof(c.rho_sys->comm().rank()),
484 libMesh::MeshBase::const_element_iterator
485 e_it = c.mesh->active_local_elements_begin(),
486 e_end = c.mesh->active_local_elements_end();
488 std::set<const libMesh::Node*> nodes;
490 for ( ; e_it != e_end; e_it++) {
492 const libMesh::Elem* e = *e_it;
494 Assert0(e->type() == libMesh::HEX8 ||
495 e->type() == libMesh::HEX27,
496 "Method requires Hex8/Hex27 element");
499 for (
uint_t i=0; i<8; i++) {
501 const libMesh::Node& n = *e->node_ptr(i);
512 dof_id = n.dof_number(sys_num, 0, 0);
518 if (dof_id >= first_dof &&
527 c.rho_sys->solution->close();
536 #endif // __mast_mesh_generation_truss_3d_h__
ScalarType value(ContextType &c) const
void init_analysis_dirichlet_conditions(Context &c)
MAST::Base::ParameterData & add_ghosted_topology_parameter(MAST::Optimization::DesignParameter< ScalarType > &p, const uint_t id)
std::unique_ptr< pressure_t< ScalarType > > build_pressure_load(InitType &c)
real_t reference_volume(Context &c)
MAST::Base::ParameterData & add_topology_parameter(MAST::Optimization::DesignParameter< ScalarType > &p, const uint_t id)
void init_analysis_mesh(Context &c, libMesh::UnstructuredMesh &mesh)
uint_t idx(const libMesh::ElemType type, const uint_t nx, const uint_t ny, const uint_t i, const uint_t j, const uint_t k)
void init_simp_dvs(Context &c, MAST::Optimization::DesignParameterVector< ScalarType > &dvs)
#define Assert0(cond, msg)
#define Assert2(cond, v1, v2, msg)
void set_point(real_t x, real_t y=0., real_t z=0.)
void synchronize(const libMesh::DofMap &dof_map)
std::unique_ptr< ValType > build(const libMesh::System &sys)
ScalarType derivative(ContextType &c, const ScalarFieldType &f) const
void build_cube(libMesh::UnstructuredMesh &mesh, const uint_t nx, const uint_t ny, const uint_t nz, const real_t length, const real_t height, const real_t width, const real_t dirichlet_length_fraction, const libMesh::ElemType type)
Pressure(real_t p, real_t l1, real_t frac)