Skip to content
Permalink
Browse files

Merge pull request #12991 from dschwen/spheresurface_8414

Sphere surface mesh generator
  • Loading branch information...
permcody committed Mar 7, 2019
2 parents a0a6ea0 + 7c6df5c commit b6b10896bbc462355488c1ef5343f4f957960abd
Submodule large_media updated from c946e6 to 523f2e
@@ -0,0 +1,22 @@
# SphereSurfaceMeshGenerator

!syntax description /MeshGenerators/SphereSurfaceMeshGenerator

This object generates a 2D mesh approximating the surface of a sphere in 3D space
using TRI3 triangle elements. Both center and radius of the sphere may be specified.

!media phase_field/sphere.gif style=width:30%;margin-left:20px;float:right;
caption=Targeted mesh refinement prior to nucleus insertion.

The mesh is constructed by iterative refinement of an initial icosahedron (depth 0)
for a number of steps specified using the `depth` parameter. After each refinement step
all nodes are snapped to the sphere surface defined by `radius` and `center`.
Each refinement step multiplies the number of mesh elements by a factor of four.

!syntax parameters /MeshGenerators/SphereSurfaceMeshGenerator

!syntax inputs /MeshGenerators/SphereSurfaceMeshGenerator

!syntax children /MeshGenerators/SphereSurfaceMeshGenerator

!bibtex bibliography
@@ -0,0 +1,43 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#ifndef SPHERESURFACEMESHGENERATOR_H
#define SPHERESURFACEMESHGENERATOR_H

#include "MeshGenerator.h"
#include "libmesh/point.h"

class SphereSurfaceMeshGenerator;

template <>
InputParameters validParams<SphereSurfaceMeshGenerator>();

/**
* Create a sphere surface mesh based on the recursive subdivision of the faces
* of a regular icosahedron.
*/
class SphereSurfaceMeshGenerator : public MeshGenerator
{
public:
SphereSurfaceMeshGenerator(const InputParameters & parameters);

std::unique_ptr<MeshBase> generate() override;

protected:
/// sphere radius
const Real _radius;

//// Sphere center
const Point _center;

/// recursion levels for triangle subdivision
const unsigned int _depth;
};

#endif // SPHERESURFACEMESHGENERATOR_H
@@ -0,0 +1,115 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "SphereSurfaceMeshGenerator.h"
#include "CastUniquePointer.h"

// libMesh includes
#include "libmesh/face_tri3.h"
#include "libmesh/mesh_modification.h"
#include "libmesh/mesh_refinement.h"
#include "libmesh/sphere.h"
#include "libmesh/unstructured_mesh.h"
#include "libmesh/replicated_mesh.h"

registerMooseObject("PhaseFieldApp", SphereSurfaceMeshGenerator);

template <>
InputParameters
validParams<SphereSurfaceMeshGenerator>()
{
InputParameters params = validParams<MeshGenerator>();
params.addClassDescription(
"Generated sphere mesh - a two dimensional manifold embedded in three dimensional space");
params.addParam<Real>("radius", 1.0, "Sphere radius");
params.addParam<Point>("center", Point(0, 0, 0), "Center of the sphere");
params.addParam<unsigned int>(
"depth", 3, "Iteration steps in the triangle bisection construction");
return params;
}

SphereSurfaceMeshGenerator::SphereSurfaceMeshGenerator(const InputParameters & parameters)
: MeshGenerator(parameters),
_radius(getParam<Real>("radius")),
_center(getParam<Point>("center")),
_depth(getParam<unsigned int>("depth"))
{
}

std::unique_ptr<MeshBase>
SphereSurfaceMeshGenerator::generate()
{
// Have MOOSE construct the correct libMesh::Mesh object using Mesh block and CLI parameters.
auto mesh = _mesh->buildMeshBaseObject();
mesh->set_mesh_dimension(2);
mesh->set_spatial_dimension(3);

const Sphere sphere(_center, _radius);

// icosahedron points (using golden ratio rectangle construction)
const Real phi = (1.0 + std::sqrt(5.0)) / 2.0;
const Real X = std::sqrt(1.0 / (phi * phi + 1.0));
const Real Z = X * phi;
const Point vdata[12] = {{-X, 0.0, Z},
{X, 0.0, Z},
{-X, 0.0, -Z},
{X, 0.0, -Z},
{0.0, Z, X},
{0.0, Z, -X},
{0.0, -Z, X},
{0.0, -Z, -X},
{Z, X, 0.0},
{-Z, X, 0.0},
{Z, -X, 0.0},
{-Z, -X, 0.0}};
for (unsigned int i = 0; i < 12; ++i)
mesh->add_point(vdata[i] * _radius + _center, i);

// icosahedron faces
const unsigned int tindices[20][3] = {{0, 4, 1}, {0, 9, 4}, {9, 5, 4}, {4, 5, 8}, {4, 8, 1},
{8, 10, 1}, {8, 3, 10}, {5, 3, 8}, {5, 2, 3}, {2, 7, 3},
{7, 10, 3}, {7, 6, 10}, {7, 11, 6}, {11, 0, 6}, {0, 1, 6},
{6, 1, 10}, {9, 0, 11}, {9, 11, 2}, {9, 2, 5}, {7, 2, 11}};
for (unsigned int i = 0; i < 20; ++i)
{
Elem * elem = mesh->add_elem(new Tri3);
elem->set_node(0) = mesh->node_ptr(tindices[i][0]);
elem->set_node(1) = mesh->node_ptr(tindices[i][1]);
elem->set_node(2) = mesh->node_ptr(tindices[i][2]);
}

// we need to prepare distributed meshes before using refinement
if (!mesh->is_replicated())
mesh->prepare_for_use(/*skip_renumber =*/false);

// Now we have the beginnings of a sphere.
// Add some more elements by doing uniform refinements and
// popping nodes to the boundary.
MeshRefinement mesh_refinement(*mesh);

// Loop over the elements, refine, pop nodes to boundary.
for (unsigned int r = 0; r < _depth; ++r)
{
mesh_refinement.uniformly_refine(1);

auto it = mesh->active_nodes_begin();
const auto end = mesh->active_nodes_end();

for (; it != end; ++it)
{
Node & node = **it;
node = sphere.closest_point(node);
}
}

// Flatten the AMR mesh to get rid of inactive elements
MeshTools::Modification::flatten(*mesh);

return dynamic_pointer_cast<MeshBase>(mesh);
}
Binary file not shown.
@@ -0,0 +1,16 @@
[MeshGenerators]
[./sphere]
type = SphereSurfaceMeshGenerator
center = '1 2 3'
radius = 4
depth = 2
[]
[]

[Mesh]
type = MeshGeneratorMesh
[]

[Outputs]
exodus = true
[]
@@ -4,12 +4,29 @@
input = 'mortarperiodic.i'
cli_args = 'Mesh/elem_type=HEX8 Outputs/file_base=mortarperiodic_hex8'
exodiff = 'mortarperiodic_hex8.e'
requirement = "The mesh object for mortar based periodic BCs shall work with first order elements"
design = 'MortarPeriodicity/index.md'
issues = '#7045'
[../]

[./mortarperiodic_hex27]
type = 'Exodiff'
input = 'mortarperiodic.i'
cli_args = 'Mesh/elem_type=HEX27 Outputs/file_base=mortarperiodic_hex27'
exodiff = 'mortarperiodic_hex27.e'
requirement = "The mesh object for mortar based periodic BCs shall work with second order elements"
design = 'MortarPeriodicity/index.md'
issues = '#7045'
[../]

[./sphere]
type = 'Exodiff'
input = 'sphere.i'
cli_args = '--mesh-only'
exodiff = 'sphere_in.e'
requirement = "The mesh generator for 2d sphere surfaces in 3d space shall produce a correct mesh"
design = 'mesh/SphereSurfaceMesh.md'
issues = '#8414'
recover = false
[../]
[]

0 comments on commit b6b1089

Please sign in to comment.
You can’t perform that action at this time.