20 #ifndef __mast_mesh_generation_inplane_2d_h__ 21 #define __mast_mesh_generation_inplane_2d_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> 45 namespace Generation {
55 template <
typename ScalarType>
65 template <
typename ContextType>
66 inline ScalarType
value(ContextType& c)
const {
67 ScalarType v=(fabs(c.qp_location(0)-
_l1*0.5) <= 0.5*
_frac*
_l1)?
_p:0.;
71 template <
typename ContextType,
typename ScalarFieldType>
73 const ScalarFieldType& f)
const {
82 template <
typename ScalarType>
85 template <
typename Context>
90 length = c.input(
"length",
"length of domain along x-axis", 1.0),
91 height = c.input(
"height",
"length of domain along y-axis", 1.0);
93 return length * height;
111 return i + (2*nx+1)*j;
115 Error(
false,
"Invalid element type");
118 return libMesh::invalid_uint;
128 const libMesh::ElemType type) {
130 Assert0(type == libMesh::QUAD4 || type == libMesh::QUAD9,
131 "Method only implemented for Quad4/Quad9");
136 libMesh::BoundaryInfo & boundary_info = mesh.get_boundary_info();
138 mesh.set_mesh_dimension(3);
139 mesh.set_spatial_dimension(3);
140 mesh.reserve_elem(nx*ny);
142 if (type == libMesh::QUAD4)
143 mesh.reserve_nodes( (nx+1)*(ny+1));
144 else if (type == libMesh::QUAD9)
145 mesh.reserve_nodes( (2*nx+1)*(2*ny+1));
152 std::map<uint_t, libMesh::Node*> nodes;
160 case libMesh::QUAD4: {
162 for (
uint_t j=0; j<=ny; j++)
163 for (
uint_t i=0; i<=nx; i++) {
165 mesh.add_point(libMesh::Point(static_cast<real_t>(i)/static_cast<real_t>(nx)*length,
166 static_cast<real_t>(j)/static_cast<real_t>(ny)*height,
176 case libMesh::QUAD9: {
178 for (
uint_t j=0; j<=(2*ny); j++)
179 for (
uint_t i=0; i<=(2*nx); i++) {
181 mesh.add_point(libMesh::Point(static_cast<real_t>(i)/static_cast<real_t>(2*nx)*length,
182 static_cast<real_t>(j)/static_cast<real_t>(2*ny)*height,
193 Assert0(
false,
"ERROR: Unrecognized 2D element type.");
201 case libMesh::QUAD4: {
203 for (
uint_t j=0; j<ny; j++)
204 for (
uint_t i=0; i<nx; i++) {
208 elem->set_id(elem_id++);
211 elem->set_node(0) = nodes[
idx(type,nx,i,j) ];
212 elem->set_node(1) = nodes[
idx(type,nx,i+1,j) ];
213 elem->set_node(2) = nodes[
idx(type,nx,i+1,j+1) ];
214 elem->set_node(3) = nodes[
idx(type,nx,i,j+1) ];
217 boundary_info.add_side(elem, 0, 0);
220 boundary_info.add_side(elem, 2, 2);
223 boundary_info.add_side(elem, 3, 3);
226 boundary_info.add_side(elem, 1, 1);
232 case libMesh::QUAD9: {
234 for (
uint_t j=0; j<(2*ny); j += 2)
235 for (
uint_t i=0; i<(2*nx); i += 2) {
239 elem->set_id(elem_id++);
242 elem->set_node(0) = nodes[
idx(type,nx,i, j) ];
243 elem->set_node(1) = nodes[
idx(type,nx,i+2,j) ];
244 elem->set_node(2) = nodes[
idx(type,nx,i+2,j+2) ];
245 elem->set_node(3) = nodes[
idx(type,nx,i, j+2) ];
246 elem->set_node(4) = nodes[
idx(type,nx,i+1,j) ];
247 elem->set_node(5) = nodes[
idx(type,nx,i+2,j+1) ];
248 elem->set_node(6) = nodes[
idx(type,nx,i+1,j+2) ];
249 elem->set_node(7) = nodes[
idx(type,nx,i, j+1) ];
250 elem->set_node(8) = nodes[
idx(type,nx,i+1,j+1) ];
253 boundary_info.add_side(elem, 0, 0);
256 boundary_info.add_side(elem, 2, 2);
259 boundary_info.add_side(elem, 3, 3);
262 boundary_info.add_side(elem, 1, 1);
268 Assert0(
false,
"ERROR: Unrecognized 2D element type.");
272 boundary_info.sideset_name(0) =
"bottom";
273 boundary_info.sideset_name(1) =
"right";
274 boundary_info.sideset_name(2) =
"top";
275 boundary_info.sideset_name(3) =
"left";
278 boundary_info.nodeset_name(0) =
"bottom";
279 boundary_info.nodeset_name(1) =
"right";
280 boundary_info.nodeset_name(2) =
"top";
281 boundary_info.nodeset_name(3) =
"left";
284 mesh.prepare_for_use ();
288 template <
typename Context>
291 libMesh::UnstructuredMesh& mesh) {
294 length = c.input(
"length",
"length of domain along x-axis", 1.0),
295 height = c.input(
"height",
"length of domain along y-axis", 1.0);
298 nx_divs = c.input(
"nx_divs",
"number of elements along x-axis", 30),
299 ny_divs = c.input(
"ny_divs",
"number of elements along y-axis", 30);
302 t = c.input(
"elem_type",
"type of geometric element in the mesh",
"quad4");
305 e_type = libMesh::Utility::string_to_enum<libMesh::ElemType>(t);
311 if (c.sol_fe_order > 1 && e_type == libMesh::QUAD4)
312 e_type = libMesh::QUAD9;
328 template <
typename Context>
332 c.sys->get_dof_map().add_dirichlet_boundary
333 (libMesh::DirichletBoundary({1, 3}, {0, 1}, libMesh::ZeroFunction<real_t>()));
338 template <
typename ScalarType,
typename InitType>
339 std::unique_ptr<pressure_t<ScalarType>>
343 length = c.input(
"length",
"length of domain along x-axis", 1.0),
344 frac = c.input(
"loadlength_fraction",
"fraction of boundary length on which pressure will act", 0.2),
345 p_val = c.input(
"pressure",
"pressure on side of domain", 2.e6);
348 std::unique_ptr<pressure_t<ScalarType>>
356 template <
typename ScalarType,
typename Context>
365 Assert2(c.rho_fe_family == libMesh::LAGRANGE,
366 c.rho_fe_family, libMesh::LAGRANGE,
367 "Method assumes Lagrange interpolation function for density");
368 Assert2(c.rho_fe_order == libMesh::FIRST,
369 c.rho_fe_order, libMesh::FIRST,
370 "Method assumes Lagrange interpolation function for density");
374 length = c.input(
"length",
"length of domain along x-axis", 1.0),
375 height = c.input(
"height",
"length of domain along y-axis", 1.0),
376 frac = c.input(
"loadlength_fraction",
"fraction of boundary length on which pressure will act", 0.2),
377 filter_radius = c.input(
"filter_radius",
"radius of geometric filter for level set field", 0.07),
378 vf = c.input(
"volume_fraction",
"upper limit for the volume fraction", 0.2);
381 sys_num = c.rho_sys->number(),
382 first_dof = c.rho_sys->get_dof_map().first_dof(c.rho_sys->comm().rank()),
383 end_dof = c.rho_sys->get_dof_map().end_dof(c.rho_sys->comm().rank()),
389 libMesh::MeshBase::const_element_iterator
390 e_it = c.mesh->active_local_elements_begin(),
391 e_end = c.mesh->active_local_elements_end();
393 std::set<const libMesh::Node*> nodes;
395 for ( ; e_it != e_end; e_it++) {
397 const libMesh::Elem* e = *e_it;
399 Assert0(e->type() == libMesh::QUAD4 ||
400 e->type() == libMesh::QUAD9,
401 "Method requires Quad4/Quad9 element");
404 for (
uint_t i=0; i<4; i++) {
406 const libMesh::Node& n = *e->node_ptr(i);
417 dof_id = n.dof_number(sys_num, 0, 0);
423 if (dof_id >= first_dof &&
432 c.rho_sys->solution->close();
441 #endif // __mast_mesh_generation_inplane_2d_h__
void init_analysis_dirichlet_conditions(Context &c)
This constrains the u and v displacements on the left (id: 3) and right (id: 1) boundaries.
std::unique_ptr< pressure_t< ScalarType > > build_pressure_load(InitType &c)
This struct provides the methods to populate the mesh, load, Dirichlet conditions and design variable...
MAST::Base::ParameterData & add_ghosted_topology_parameter(MAST::Optimization::DesignParameter< ScalarType > &p, const uint_t id)
void init_simp_dvs(Context &c, MAST::Optimization::DesignParameterVector< ScalarType > &dvs)
ScalarType derivative(ContextType &c, const ScalarFieldType &f) const
void init_analysis_mesh(Context &c, libMesh::UnstructuredMesh &mesh)
MAST::Base::ParameterData & add_topology_parameter(MAST::Optimization::DesignParameter< ScalarType > &p, const uint_t id)
Pressure(real_t p, real_t l1, real_t frac)
uint_t idx(const libMesh::ElemType type, const uint_t nx, const uint_t i, const uint_t j)
ScalarType value(ContextType &c) const
#define Assert0(cond, msg)
real_t reference_volume(Context &c)
#define Assert2(cond, v1, v2, msg)
void build_mesh(libMesh::UnstructuredMesh &mesh, const uint_t nx, const uint_t ny, const real_t length, const real_t height, const libMesh::ElemType type)
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)