Skip to content

Commit

Permalink
HexMesh: Add ability to specify mesh spacings
Browse files Browse the repository at this point in the history
  • Loading branch information
sayerhs committed Oct 2, 2017
1 parent 81bb366 commit c835595
Show file tree
Hide file tree
Showing 11 changed files with 512 additions and 26 deletions.
12 changes: 12 additions & 0 deletions doc/manual/source/dev/api/mesh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ HexBlockMesh

.. doxygenclass:: sierra::nalu::HexBlockMesh
:members:

Mesh Spacing Options
~~~~~~~~~~~~~~~~~~~~

.. doxygenclass:: sierra::nalu::MeshSpacing
:members:

.. doxygenclass:: sierra::nalu::ConstantSpacing
:members:

.. doxygenclass:: sierra::nalu::GeometricStretching
:members:
34 changes: 31 additions & 3 deletions doc/manual/source/user/abl_mesh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ parameters.A sample input file is shown below
``fluid_part``.

Boundary names
~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~

The user has the option to provide custom boundary names through the input file.
Use the boundary name input parameters to change the default parameters. If
Expand All @@ -120,11 +120,39 @@ Boundary Default sideset name
``zmax_boundary_name`` ``top``
====================== =====================

Mesh spacing
~~~~~~~~~~~~

Users can specify the mesh spacing to be applied in each direction by adding
additional sections (``x_spacing``, ``y_spacing``, and ``z_spacing``
respectively) to the input file. If no option is specified then a constant mesh
spacing is used in that direction.

========================== ===============================================
Available options Implementation
========================== ===============================================
``constant_spacing`` :class:`~sierra::nalu::ConstantSpacing`
``geometric_stretching`` :class:`~sierra::nalu::GeometricStretching`
========================== ===============================================

**Example input file**

.. code-block:: yaml
# Specifiy constant spacing in x direction (this is the default)
x_spacing:
spacing_type: constant_spacing
# No spacing type specified for y, taken to be constant_spacing
# z direction has a mesh stretching factor
z_spacing:
spacing_type: geometric_stretching
stretching_factor: 1.1
Limitations
-----------

#. Currently the code is setup to only generate constant size grids in each direction.

#. Does not support the ability to generate multiple blocks

#. Must be run on a single processor, running with multiple MPI ranks is currently
Expand Down
40 changes: 26 additions & 14 deletions src/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@

add_library(nalumeshutils
HexBlockMesh.cpp
)
target_link_libraries(nalumeshutils utilscore
${Trilinos_TPL_LIBRARIES}
${Trilinos_LIBRARIES}
${YAML_LIBRARIES}
${MPI_LIBRARIES})
# add_library(nalumeshutils
# # Mesh spacing functions
# spacing/MeshSpacing.cpp
# spacing/ConstantSpacing.cpp
# spacing/GeometricStretching.cpp
#
# HexBlockMesh.cpp
# )
# target_link_libraries(nalumeshutils utilscore
# ${Trilinos_TPL_LIBRARIES}
# ${Trilinos_LIBRARIES}
# ${YAML_LIBRARIES}
# ${MPI_LIBRARIES})

add_executable(abl_mesh
# Mesh spacing functions
spacing/MeshSpacing.cpp
spacing/ConstantSpacing.cpp
spacing/GeometricStretching.cpp

HexBlockMesh.cpp
abl_mesh.cpp)

target_link_libraries(abl_mesh
nalumeshutils utilscore
utilscore
${Trilinos_TPL_LIBRARIES}
${Trilinos_LIBRARIES}
${YAML_LIBRARIES}
Expand All @@ -27,11 +39,11 @@ if(MPI_LINK_FLAGS)
LINK_FLAGS "${MPI_LINK_FLAGS}")
endif(MPI_LINK_FLAGS)

install(TARGETS nalumeshutils
EXPORT "${CMAKE_PROJECT_NAME}Libraries"
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
#install(TARGETS nalumeshutils
# EXPORT "${CMAKE_PROJECT_NAME}Libraries"
# RUNTIME DESTINATION bin
# LIBRARY DESTINATION lib
# ARCHIVE DESTINATION lib)

install(TARGETS abl_mesh
RUNTIME DESTINATION bin
Expand Down
50 changes: 43 additions & 7 deletions src/mesh/HexBlockMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,35 @@ void HexBlockMesh::load(const YAML::Node& node)
get_optional(node, "ymax_boundary_name", ss_ymax_name_);
get_optional(node, "zmin_boundary_name", ss_zmin_name_);
get_optional(node, "zmax_boundary_name", ss_zmax_name_);

// Process mesh spacing inputs

if (node["x_spacing"]) {
auto& xsnode = node["x_spacing"];
get_optional(xsnode, "spacing_type", xspacing_type_);

xSpacing_.reset(MeshSpacing::create(meshDims_[0]+1, xsnode, xspacing_type_));
} else {
xSpacing_.reset(MeshSpacing::create(meshDims_[0]+1, node, xspacing_type_));
}

if (node["y_spacing"]) {
auto& ysnode = node["y_spacing"];
get_optional(ysnode, "spacing_type", yspacing_type_);

ySpacing_.reset(MeshSpacing::create(meshDims_[1]+1, ysnode, yspacing_type_));
} else {
ySpacing_.reset(MeshSpacing::create(meshDims_[1]+1, node, yspacing_type_));
}

if (node["z_spacing"]) {
auto& zsnode = node["z_spacing"];
get_optional(zsnode, "spacing_type", zspacing_type_);

zSpacing_.reset(MeshSpacing::create(meshDims_[2]+1, zsnode, zspacing_type_));
} else {
zSpacing_.reset(MeshSpacing::create(meshDims_[2]+1, node, zspacing_type_));
}
}

void HexBlockMesh::initialize()
Expand Down Expand Up @@ -335,17 +364,24 @@ void HexBlockMesh::generate_coordinates(const std::vector<stk::mesh::EntityId>&
VectorFieldType* coords = meta_.get_field<VectorFieldType>(
stk::topology::NODE_RANK, "coordinates");

// TODO: implement stretching factors
double dx = 1.0 / static_cast<double>(meshDims_[0]);
double dy = 1.0 / static_cast<double>(meshDims_[1]);
double dz = 1.0 / static_cast<double>(meshDims_[2]);
// // TODO: implement stretching factors
// double dx = 1.0 / static_cast<double>(meshDims_[0]);
// double dy = 1.0 / static_cast<double>(meshDims_[1]);
// double dz = 1.0 / static_cast<double>(meshDims_[2]);
xSpacing_->init_spacings();
ySpacing_->init_spacings();
zSpacing_->init_spacings();

auto& rxvec = xSpacing_->ratios();
auto& ryvec = ySpacing_->ratios();
auto& rzvec = zSpacing_->ratios();

for (int k=0; k < nz; k++) {
double rz = k * dz;
double rz = rzvec[k];
for (int j=0; j < ny; j++) {
double ry = j * dy;
double ry = ryvec[j];
for (int i=0; i < nx; i++) {
double rx = i * dx;
double rx = rxvec[i];
int idx = k * (nx * ny) + j * nx + i;
auto node = bulk_.get_entity(stk::topology::NODE_RANK, nodeVec[idx]);
double* pt = stk::mesh::field_data(*coords, node);
Expand Down
15 changes: 13 additions & 2 deletions src/mesh/HexBlockMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define HEXBLOCKMESH_H

#include "core/CFDMesh.h"
#include "spacing/MeshSpacing.h"

#include "yaml-cpp/yaml.h"

Expand Down Expand Up @@ -90,8 +91,9 @@ class HexBlockMesh
//! Mesh dimensions in each direction
std::vector<int> meshDims_;

//! Stretch factor
std::array<double, 3> stretchFactor{{1.0, 1.0, 1.0}};
std::unique_ptr<MeshSpacing> xSpacing_;
std::unique_ptr<MeshSpacing> ySpacing_;
std::unique_ptr<MeshSpacing> zSpacing_;

//! Name of the fluid domain block
std::string blockName_{"fluid_part"};
Expand All @@ -116,6 +118,15 @@ class HexBlockMesh
//! Name of the ZMAX sideset
std::string ss_zmax_name_{"top"};

//! Spacing type in x-direction
std::string xspacing_type_{"constant_spacing"};

//! Spacing type in y-direction
std::string yspacing_type_{"constant_spacing"};

//! Spacing type in z-direction
std::string zspacing_type_{"constant_spacing"};

//! Flag indicating user selection of domain extents
DomainExtentsType vertexDef_{BOUND_BOX};
};
Expand Down
40 changes: 40 additions & 0 deletions src/mesh/spacing/ConstantSpacing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2016 National Renewable Energy Laboratory
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "ConstantSpacing.h"

namespace sierra {
namespace nalu {

REGISTER_DERIVED_CLASS(MeshSpacing, ConstantSpacing, "constant_spacing");

ConstantSpacing::ConstantSpacing(
int npts,
const YAML::Node&
) : MeshSpacing(npts)
{
// Ignore yaml node... no additional inputs
}

void ConstantSpacing::init_spacings()
{
double dx = 1.0 / static_cast<double>(numPts_-1);

for (int i=0; i<numPts_; i++)
ratios_[i] = i * dx;
}

} // nalu
} // sierra
50 changes: 50 additions & 0 deletions src/mesh/spacing/ConstantSpacing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2016 National Renewable Energy Laboratory
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef CONSTANTSPACING_H
#define CONSTANTSPACING_H

#include "MeshSpacing.h"

namespace sierra {
namespace nalu {

/** Constant mesh spacing distribution
*
* Specialization of MeshSpacing to allow for constant mesh spacing which is
* the default implementation if no user option is specified in the input file.
* This class requires no additional input arguments in the YAML file.
*/
class ConstantSpacing : public MeshSpacing
{
public:
ConstantSpacing(
int,
const YAML::Node&);

//! Initialize a constant spacing 1-D mesh
virtual void init_spacings();

private:
ConstantSpacing() = delete;
ConstantSpacing(const ConstantSpacing&) = delete;
};

} // nalu
} // sierra



#endif /* CONSTANTSPACING_H */

0 comments on commit c835595

Please sign in to comment.