20 #ifndef __mast_mesh_generation_truss_3d_h__ 21 #define __mast_mesh_generation_truss_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.24),
87 height = c.input(
"height",
"length of domain along y-axis", 0.04),
88 width = c.input(
"width",
"length of domain along z-axis", 0.08);
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);
244 if (j == 0 && i <= dirichlet_length_fraction * nx)
245 boundary_info.add_side(elem, 1, 6);
247 if (j == 0 && i >= (1.-dirichlet_length_fraction)* nx)
248 boundary_info.add_side(elem, 1, 7);
250 if (j == 0 && i == 0 && k == 0)
251 boundary_info.add_side(elem, 1, 8);
257 case libMesh::HEX27: {
259 for (
uint_t k=0; k<(2*nz); k += 2)
260 for (
uint_t j=0; j<(2*ny); j += 2)
261 for (
uint_t i=0; i<(2*nx); i += 2)
265 elem->set_id(elem_id++);
268 elem->set_node(0) = nodes[
idx(type,nx,ny,i, j, k) ];
269 elem->set_node(1) = nodes[
idx(type,nx,ny,i+2,j, k) ];
270 elem->set_node(2) = nodes[
idx(type,nx,ny,i+2,j+2,k) ];
271 elem->set_node(3) = nodes[
idx(type,nx,ny,i, j+2,k) ];
272 elem->set_node(4) = nodes[
idx(type,nx,ny,i, j, k+2)];
273 elem->set_node(5) = nodes[
idx(type,nx,ny,i+2,j, k+2)];
274 elem->set_node(6) = nodes[
idx(type,nx,ny,i+2,j+2,k+2)];
275 elem->set_node(7) = nodes[
idx(type,nx,ny,i, j+2,k+2)];
276 elem->set_node(8) = nodes[
idx(type,nx,ny,i+1,j, k) ];
277 elem->set_node(9) = nodes[
idx(type,nx,ny,i+2,j+1,k) ];
278 elem->set_node(10) = nodes[
idx(type,nx,ny,i+1,j+2,k) ];
279 elem->set_node(11) = nodes[
idx(type,nx,ny,i, j+1,k) ];
280 elem->set_node(12) = nodes[
idx(type,nx,ny,i, j, k+1)];
281 elem->set_node(13) = nodes[
idx(type,nx,ny,i+2,j, k+1)];
282 elem->set_node(14) = nodes[
idx(type,nx,ny,i+2,j+2,k+1)];
283 elem->set_node(15) = nodes[
idx(type,nx,ny,i, j+2,k+1)];
284 elem->set_node(16) = nodes[
idx(type,nx,ny,i+1,j, k+2)];
285 elem->set_node(17) = nodes[
idx(type,nx,ny,i+2,j+1,k+2)];
286 elem->set_node(18) = nodes[
idx(type,nx,ny,i+1,j+2,k+2)];
287 elem->set_node(19) = nodes[
idx(type,nx,ny,i, j+1,k+2)];
289 elem->set_node(20) = nodes[
idx(type,nx,ny,i+1,j+1,k) ];
290 elem->set_node(21) = nodes[
idx(type,nx,ny,i+1,j, k+1)];
291 elem->set_node(22) = nodes[
idx(type,nx,ny,i+2,j+1,k+1)];
292 elem->set_node(23) = nodes[
idx(type,nx,ny,i+1,j+2,k+1)];
293 elem->set_node(24) = nodes[
idx(type,nx,ny,i, j+1,k+1)];
294 elem->set_node(25) = nodes[
idx(type,nx,ny,i+1,j+1,k+2)];
295 elem->set_node(26) = nodes[
idx(type,nx,ny,i+1,j+1,k+1)];
298 boundary_info.add_side(elem, 0, 0);
301 boundary_info.add_side(elem, 5, 5);
304 boundary_info.add_side(elem, 1, 1);
307 boundary_info.add_side(elem, 3, 3);
310 boundary_info.add_side(elem, 4, 4);
313 boundary_info.add_side(elem, 2, 2);
315 if (j == 0 && i <= dirichlet_length_fraction * 2*nx)
316 boundary_info.add_side(elem, 1, 6);
318 if (j == 0 && i >= (1.-dirichlet_length_fraction)* 2*nx)
319 boundary_info.add_side(elem, 1, 7);
321 if (j == 0 && i == 0 && k == 0)
322 boundary_info.add_side(elem, 1, 8);
328 Assert0(
false,
"ERROR: Unrecognized 3D element type.");
332 boundary_info.sideset_name(0) =
"back";
333 boundary_info.sideset_name(1) =
"bottom";
334 boundary_info.sideset_name(2) =
"right";
335 boundary_info.sideset_name(3) =
"top";
336 boundary_info.sideset_name(4) =
"left";
337 boundary_info.sideset_name(5) =
"front";
338 boundary_info.sideset_name(6) =
"left_dirichlet";
339 boundary_info.sideset_name(7) =
"right_dirichlet";
342 boundary_info.nodeset_name(0) =
"back";
343 boundary_info.nodeset_name(1) =
"bottom";
344 boundary_info.nodeset_name(2) =
"right";
345 boundary_info.nodeset_name(3) =
"top";
346 boundary_info.nodeset_name(4) =
"left";
347 boundary_info.nodeset_name(5) =
"front";
350 mesh.prepare_for_use ();
355 template <
typename Context>
358 libMesh::UnstructuredMesh& mesh) {
361 length = c.input(
"length",
"length of domain along x-axis", 0.24),
362 height = c.input(
"height",
"length of domain along y-axis", 0.04),
363 width = c.input(
"width",
"length of domain along z-axis", 0.08),
364 dirichlet_length_fraction = c.input
365 (
"dirichlet_length_fraction",
366 "length fraction of the truss boundary where dirichlet condition is applied",
370 nx_divs = c.input(
"nx_divs",
"number of elements along x-axis", 30),
371 ny_divs = c.input(
"ny_divs",
"number of elements along y-axis", 5),
372 nz_divs = c.input(
"nz_divs",
"number of elements along z-axis", 10),
373 n_refine= c.input(
"n_uniform_refinement",
"number of times the mesh is uniformly refined", 0);
376 t = c.input(
"elem_type",
"type of geometric element in the mesh",
"hex8");
379 e_type = libMesh::Utility::string_to_enum<libMesh::ElemType>(t);
385 if (c.sol_fe_order > 1 && e_type == libMesh::HEX8)
386 e_type = libMesh::HEX27;
387 else if (c.sol_fe_order > 1 && e_type == libMesh::TET4)
388 e_type = libMesh::TET10;
394 nx_divs, ny_divs, nz_divs,
398 dirichlet_length_fraction,
404 libMesh::MeshRefinement(mesh).uniformly_refine(n_refine);
405 libMesh::MeshTools::Modification::flatten(mesh);
411 template <
typename Context>
415 c.sys->get_dof_map().add_dirichlet_boundary
416 (libMesh::DirichletBoundary({6, 7}, {0, 1, 2}, libMesh::ZeroFunction<real_t>()));
421 template <
typename ScalarType,
typename InitType>
422 std::unique_ptr<pressure_t<ScalarType>>
426 length = c.input(
"length",
"length of domain along x-axis", 0.24),
427 frac = c.input(
"loadlength_fraction",
"fraction of boundary length on which pressure will act", 0.2),
428 p_val = c.input(
"pressure",
"pressure on side of domain", 2.e4);
431 std::unique_ptr<pressure_t<ScalarType>>
439 template <
typename ScalarType,
typename Context>
448 Assert2(c.rho_fe_family == libMesh::LAGRANGE,
449 c.rho_fe_family, libMesh::LAGRANGE,
450 "Method assumes Lagrange interpolation function for density");
451 Assert2(c.rho_fe_order == libMesh::FIRST,
452 c.rho_fe_order, libMesh::FIRST,
453 "Method assumes Lagrange interpolation function for density");
457 length = c.input(
"length",
"length of domain along x-axis", 0.24),
458 height = c.input(
"height",
"length of domain along y-axis", 0.04),
459 frac = c.input(
"loadlength_fraction",
"fraction of boundary length on which pressure will act", 0.2),
460 filter_radius = c.input(
"filter_radius",
"radius of geometric filter for level set field", 0.008),
461 vf = c.input(
"volume_fraction",
"upper limit for the volume fraction", 0.2);
464 sys_num = c.rho_sys->number(),
465 first_dof = c.rho_sys->get_dof_map().first_dof(c.rho_sys->comm().rank()),
466 end_dof = c.rho_sys->get_dof_map().end_dof(c.rho_sys->comm().rank()),
472 libMesh::MeshBase::const_element_iterator
473 e_it = c.mesh->active_local_elements_begin(),
474 e_end = c.mesh->active_local_elements_end();
476 std::set<const libMesh::Node*> nodes;
478 for ( ; e_it != e_end; e_it++) {
480 const libMesh::Elem* e = *e_it;
482 Assert0(e->type() == libMesh::HEX8 ||
483 e->type() == libMesh::HEX27,
484 "Method requires Hex8/Hex27 element");
487 for (
uint_t i=0; i<8; i++) {
489 const libMesh::Node& n = *e->node_ptr(i);
500 dof_id = n.dof_number(sys_num, 0, 0);
518 if (dof_id >= first_dof &&
528 c.rho_sys->solution->close();
537 #endif // __mast_mesh_generation_truss_3d_h__
Pressure(real_t p, real_t l1, real_t frac)
void init_analysis_mesh(Context &c, libMesh::UnstructuredMesh &mesh)
real_t reference_volume(Context &c)
MAST::Base::ParameterData & add_ghosted_topology_parameter(MAST::Optimization::DesignParameter< ScalarType > &p, const uint_t id)
void init_analysis_dirichlet_conditions(Context &c)
MAST::Base::ParameterData & add_topology_parameter(MAST::Optimization::DesignParameter< ScalarType > &p, const uint_t id)
ScalarType value(ContextType &c) 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)
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)
std::unique_ptr< pressure_t< ScalarType > > build_pressure_load(InitType &c)
void set_point(real_t x, real_t y=0., real_t z=0.)
ScalarType derivative(ContextType &c, const ScalarFieldType &f) const
void synchronize(const libMesh::DofMap &dof_map)
std::unique_ptr< ValType > build(const libMesh::System &sys)