Commit 8ea0c2c6 authored by Robert Maynard's avatar Robert Maynard

Merge branch 'smtk_mesh' into smtk_mesh_with_moab

parents b2242062 70b9cb11
# - Try to find MOAB headers and libraries
#
# Usage of this module as follows:
#
# find_package(MOAB)
#
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# MOAB_ROOT_DIR Set this variable to the root installation of
# MOAB if the module has problems finding
# the proper installation path.
#
# Variables defined by this module:
#
# MOAB_FOUND System has MOAB libs/headers
# MOAB_INCLUDE_DIRS The location of MOAB headers
#
# Targets defined by this module:
# MOAB
#
find_path(MOAB_ROOT_DIR
NAMES include/MOAB/version.h
)
find_path(MOAB_INCLUDE_DIR
NAMES moab/Core.hpp
HINTS ${MOAB_ROOT_DIR}/include/
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MOAB DEFAULT_MSG
MOAB_INCLUDE_DIR)
if(MOAB_FOUND)
if(EXISTS ${MOAB_ROOT_DIR}/lib/MOABConfig.cmake)
include(${MOAB_ROOT_DIR}/lib/MOABConfig.cmake)
else()
#now we create fake targets to be used
include(${MOAB_ROOT_DIR}/lib/MOABTargets.cmake)
endif()
endif()
set(MOAB_INCLUDE_DIRS ${MOAB_INCLUDE_DIR})
mark_as_advanced(
MOAB_ROOT_DIR
MOAB_INCLUDE_DIR
)
......@@ -32,16 +32,19 @@ function(smtk_add_header_test name dir_prefix)
set(cxxfiles ${cxxfiles} ${src})
endforeach (header)
# message(STATUS "sysTools_BINARY_DIR='${sysTools_BINARY_DIR}'")
# include_directories(${sysTools_BINARY_DIR})
#include the build directory for the export header
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_library(TestBuild_${name} ${cxxfiles} ${hfiles})
# target_link_libraries(TestBuild_${name} sysTools)
set_source_files_properties(${hfiles}
PROPERTIES HEADER_FILE_ONLY TRUE
)
#include the build directory for the export header
target_include_directories(TestBuild_${name}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
${MOAB_INCLUDE_DIRS}
)
endfunction(smtk_add_header_test)
# Declare a list of header files. Will make sure the header files get
......
# Declare unit tests Usage:
#
# smtk_unit_tests(
# LABEL <prefix for all unit tests>
# SOURCES <test_source_list>
# SOURCES_REQUIRE_DATA <test_sources_that_require_SMTK_DATA_DIR>
# EXTRA_SOURCES <helper_source_files>
# LIBRARIES <dependent_library_list>
# )
function(smtk_unit_tests)
set(options)
set(oneValueArgs)
set(multiValueArgs LABEL SOURCES SOURCES_REQUIRE_DATA EXTRA_SOURCES LIBRARIES)
cmake_parse_arguments(SMTK_ut
"${options}" "${oneValueArgs}" "${multiValueArgs}"
${ARGN}
)
set(have_testing_data OFF)
if (SMTK_DATA_DIR
AND EXISTS ${SMTK_DATA_DIR}/ReadMe.mkd
AND MOAB_USE_HDF)
#we check moab for hdf support since that is the file format
#for all our test data
set(have_testing_data ON)
list(APPEND SMTK_ut_SOURCES ${SMTK_ut_SOURCES_REQUIRE_DATA})
endif()
list(LENGTH SMTK_ut_SOURCES num_sources)
if(NOT ${num_sources})
#no sources don't make a target
return()
endif()
if (SMTK_ENABLE_TESTING)
smtk_get_kit_name(kit)
#we use UnitTests_ so that it is an unique key to exclude from coverage
set(test_prog UnitTests_${kit})
create_test_sourcelist(TestSources ${test_prog}.cxx ${SMTK_ut_SOURCES})
add_executable(${test_prog} ${TestSources} ${SMTK_ut_EXTRA_SOURCES})
target_link_libraries(${test_prog} LINK_PRIVATE ${SMTK_ut_LIBRARIES})
target_include_directories(${test_prog}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${MOAB_INCLUDE_DIRS}
)
if(have_testing_data)
target_compile_definitions(${test_prog} PRIVATE "SMTK_DATA_DIR=\"${SMTK_DATA_DIR}\"")
endif()
foreach (test ${SMTK_ut_SOURCES})
get_filename_component(tname ${test} NAME_WE)
add_test(NAME ${tname}
COMMAND ${test_prog} ${tname}
)
set_tests_properties(${tname} PROPERTIES TIMEOUT 120)
if(SMTK_ut_LABEL)
set_tests_properties(${tname} PROPERTIES LABELS ${SMTK_ut_LABEL})
endif()
endforeach(test)
endif (SMTK_ENABLE_TESTING)
if (SMTK_DATA_DIR AND EXISTS ${SMTK_DATA_DIR}/ReadMe.mkd)
list(APPEND unit_tests
)
endif()
endfunction(smtk_unit_tests)
......@@ -44,6 +44,10 @@ include(GenerateExportHeader)
# export install targets
include(SMTKMacros)
# include cmake code that allows for easier testing of SMTK classes
# and also provides helpers around create_test_sourcelist
include(CMake/SMTKTestingMacros.cmake)
# Include mechanism for determining shared and weak pointer support
include(SharedPtr)
......@@ -179,6 +183,13 @@ if(WIN32 AND MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()
################################################################################
# Moab Related Settings
################################################################################
# Moab is required for building smtk::mesh, as it is the default storage
# format for meshes.
find_package(MOAB REQUIRED)
################################################################################
# Qt Related Settings
################################################################################
......
......@@ -24,6 +24,7 @@ In order to build SMTK you must have
+ [CMake](http://cmake.org) 2.8.11 or newer (3.2 is advised), and
+ [Boost](http://boost.org) 1.50.0 or newer.
We recommend using [Ninja](http://martine.github.io/ninja/) for fast builds.
You may optionally provide
......@@ -44,6 +45,10 @@ You may optionally provide
+ [ParaView](http://paraview.org) version 4.3 or newer,
or [VTK](http://VTK.org) version 6.2 or newer,
for graphical presentation and selection of geometric models.
+ [MOAB](https://bitbucket.org/fathomteam/moab),
built with
[Netcdf](http://www.unidata.ucar.edu/software/netcdf/),
for importing and exporting mesh files.
If you want to build the documentation you will need
......
......@@ -48,6 +48,7 @@ and installed SMTK according to these instructions.
attribute/index.rst
model/index.rst
mesh/index.rst
administration.rst
contributing.rst
......
Key Concepts
============
Like the model system, the mesh system is composed of C++ classes,
also accessible in Python, and based on concepts from MOAB_
which it uses internally.
The class instances perform the following functions:
:smtk:`Handle <smtk::mesh::Handle>`
instances refer to a single mesh entity, which may be an primitive
mesh element (a :smtk:`Cell <smtk::mesh::Cell>`, e.g., a triangle
or quadrilateral) or a set of mesh elements (a :smtk:`MeshSet`)
grouped together for some purpose.
:smtk:`HandleRange <smtk::mesh::HandleRange>`
instances refer to a range of mesh entities.
A range is a run-length encoded list of mesh handles (which are opaque
but internally represented by integers).
By making HandleRanges a primitive type,
meshes with implicit connectivity can be compactly represented.
:smtk:`MeshSet <smtk::mesh::MeshSet>`
instances group :smtk:`HandleRange` instances together so that they
can be marked with properties such as a common association with a model entity,
material, boundary condition, or initial condition.
Each MeshSet instance holds a reference to a parent collection (described below)
and provides methods for setting attributes, computing subsets, and accessing
primitive cells.
In general, a MeshSet will not contain elements that overlap spatially.
Instead, a meshset usually has a boundary that conforms to neighboring
meshsets (or to empty space).
Often, an SMTK modeling entity (corresponding to a
:smtk:`CellEntity <smtk::model::CellEntity>`) will be associated
with a meshset that approximates its point locus;
however, not all MeshSets have an associated model entity.
:smtk:`Collection <smtk::mesh::Collection>`
instances hold related MeshSets together.
Problem domains are often the union of several MeshSets in a Collection.
Often, the problem domain may be decomposed in several ways, so that
all of the MeshSets in a collection may cover the problem domain several
times over.
For example, a Collection may have one MeshSet for each geometric model
cell as well as a MeshSet for each material.
Either of these alone would cover the entire problem domain;
together, they cover it twice.
All of the Cells in all of the MeshSets of a Collection have their
connectivity defined by indices into the same set of points.
Each Collection has a parent mesh Manager.
:smtk:`Manager <smtk::mesh::Manager>`
instances contain mesh collections and provide an interface to an
underlying mesh package, such as MOAB_ that implements methods to
access the mesh.
.. _MOAB: https://bitbucket.org/fathomteam/moab
.. _smtk-mesh-sys:
******************
SMTK's Mesh System
******************
SMTK's third major component is its meshing system,
which allows you to interact with multiple mesh generators
and associate one or more meshes with each geometric model
entity.
.. toctree::
:maxdepth: 3
concepts.rst
......@@ -5,7 +5,7 @@ Like the attribute system, the model system is composed of C++ classes,
also accessible in Python, whose instances perform the following functions:
:smtk:`Manager <smtk::model::Manager>`
instances that contain model topology and geometry.
instances contain model topology and geometry.
All of the model entities such as faces, edges, and vertices are
assigned a UUID by SMTK.
You can think of the manager as a key-value store from UUID values to
......
......@@ -5,7 +5,7 @@ SMTK's Geometric Model System
*****************************
SMTK's second major component is its geometric modeling system,
which allows you to interact with multiple modelsing sessions
which allows you to interact with multiple modeling sessions
that may each interact with different solid modeling kernels.
.. toctree::
......
......@@ -9,6 +9,9 @@ smtk_source_group(common)
add_subdirectory(attribute)
smtk_source_group(attribute)
add_subdirectory(mesh)
smtk_source_group(mesh)
add_subdirectory(model)
smtk_source_group(model)
......@@ -24,6 +27,7 @@ smtk_source_group(io)
set(smtk_headers
${commonHeaders}
${attributeHeaders}
${meshHeaders}
${modelHeaders}
${simulationHeaders}
${ioHeaders}
......@@ -31,6 +35,7 @@ set(smtk_headers
set(smtk_srcs
${commonSrcs}
${attributeSrcs}
${meshSrcs}
${modelSrcs}
${simulationSrcs}
${ioSrcs}
......@@ -42,9 +47,12 @@ target_include_directories(smtkCore
$<INSTALL_INTERFACE:include/smtk/${SMTK_VERSION}>
)
target_link_libraries(smtkCore
LINK_PUBLIC cJSON
LINK_PUBLIC cJSON MOAB
LINK_PRIVATE ${Boost_LIBRARIES})
target_include_directories(smtkCore
PRIVATE ${MOAB_INCLUDE_DIRS})
smtk_export_header(smtkCore CoreExports.h)
if (NOT BUILD_SHARED_LIBS AND SMTK_ENABLE_PYTHON_WRAPPING)
# Set position-independent flag when other project libs are shared.
......
......@@ -64,6 +64,21 @@ namespace smtk
class VoidItemDefinition;
}
namespace mesh
{
class Manager;
class Collection;
class Interface;
class Allocator;
class ConnectivityStorage;
namespace moab
{
class Interface;
}
}
namespace model
{
class Arrangement;
......@@ -164,6 +179,21 @@ namespace smtk
typedef smtk::shared_ptr< smtk::common::View > ViewPtr;
}
namespace mesh
{
typedef smtk::shared_ptr< smtk::mesh::Manager > ManagerPtr;
typedef smtk::shared_ptr< smtk::mesh::Collection > CollectionPtr;
typedef smtk::shared_ptr< smtk::mesh::Interface > InterfacePtr;
typedef smtk::shared_ptr< smtk::mesh::Allocator > AllocatorPtr;
typedef smtk::shared_ptr< smtk::mesh::ConnectivityStorage >
ConnectivityStoragePtr;
namespace moab
{
typedef smtk::shared_ptr< smtk::mesh::moab::Interface > InterfacePtr;
}
}
//Shiboken requires that we use fully qualified namespaces for all
//types that these shared_ptr and weak_ptr are holding
namespace model
......
......@@ -417,7 +417,7 @@ bool Session::addTessellation(
} // namespace smtk
// ++ 1 ++
#include "Session_json.h"
#include "smtk/bridge/exodus/Session_json.h"
smtkImplementsModelingKernel(
SMTKEXODUSSESSION_EXPORT,
......
......@@ -66,7 +66,10 @@ public:
static UUID random();
static UUID null();
static size_type size() { return 16; }
enum {
SIZE = 16
};
static size_type size() { return SIZE; }
bool isNull() const;
iterator begin();
......
......@@ -60,4 +60,11 @@ if(SMTK_ENABLE_VTK_SUPPORT)
vtk_smtk_setup_module_environment("VTKSMTK")
vtk_smtk_process_modules()
endif()
# These are converters to allow importing of vtk data into smtk mesh system.
# We keep this out of the common vtk model for 2 primary reasons.
# The primary being is that this library is focused on bringing data into
# smtk, not rendering, and secondly we don't want to require vtk rendering
#to be linked for IO routines.
add_subdirectory(vtkToMesh)
endif()
set(vtkToMeshSources
VTKDataConverter.cxx
)
set(vtkToMeshHeaders
VTKDataConverter.h
)
add_library(vtkToSMTKMesh ${vtkToMeshSources})
target_link_libraries(vtkToSMTKMesh
LINK_PUBLIC smtkCore vtkCommonDataModel )
smtk_export_header(vtkToSMTKMesh vtkToSMTKMeshExports.h)
target_include_directories(vtkToSMTKMesh
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(vtkToSMTKMesh
PRIVATE ${MOAB_INCLUDE_DIRS})
# On Mac OS X, set the directory included as part of the installed library's path:
if (BUILD_SHARED_LIBS)
set_target_properties(vtkToSMTKMesh PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
endif()
#install the headers
smtk_public_headers(${vtkToMeshHeaders})
# ... and make header compilation tests link properly:
smtk_install_library(vtkToSMTKMesh)
if (SMTK_ENABLE_TESTING)
add_subdirectory(testing)
endif()
This diff is collapsed.
//=============================================================================
//
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
//=============================================================================
#ifndef __smtk_extension_vtkToMesh_VTKDataConverter_h
#define __smtk_extension_vtkToMesh_VTKDataConverter_h
#include "smtk/extension/vtkToMesh/vtkToSMTKMeshExports.h"
//forward declarers for Manager and Collection
#include "smtk/PublicPointerDefs.h"
//forward declare vtk classes
class vtkPolyData;
class vtkUnstructuredGrid;
#include <string>
namespace smtk {
namespace extension {
namespace vtkToMesh {
//Convert a VTK data set to a smtk::mesh::collection.
//Currently we only support creating a new database from a vtk data set.
//
//TODO: Allow insertion of a vtk dataset into an existing collection
class VTKTOSMTKMESH_EXPORT VTKDataConverter
{
public:
//Construct a VTKDataConverter and tie it to a manager. This means
//that all conversion will be added as new collections to this manager
explicit VTKDataConverter(const smtk::mesh::ManagerPtr& manager);
//convert a polydata to a collection.
//Optionally specify the cell property name to be used to split
//the mesh into muliple domain.
smtk::mesh::CollectionPtr operator()(vtkPolyData* polydata,
std::string domainPropertyName = std::string()) const;
//convert an unstructured grid to a collection.
//Optionally specify the cell property name to be used to split
//the mesh into muliple domain.
smtk::mesh::CollectionPtr operator()(vtkUnstructuredGrid* ugrid,
std::string domainPropertyName = std::string()) const;
private:
//both are blank since we currently don't want to support copy by value
VTKDataConverter( const VTKDataConverter& other );
VTKDataConverter& operator=( const VTKDataConverter& other );
//holds a weak reference to the manager
smtk::weak_ptr<smtk::mesh::Manager> m_manager;
};
}
}
}
#endif //__smtk_extension_vtkToMesh_VTKDataConverter_h
#=============================================================================
#
# Copyright (c) Kitware, Inc.
# All rights reserved.
# See LICENSE.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the above copyright notice for more information.
#
#=============================================================================
set(unit_tests_which_require_data
UnitTestVTKDataConverter.cxx
)
smtk_unit_tests(LABEL "Mesh"
SOURCES_REQUIRE_DATA ${unit_tests_which_require_data}
LIBRARIES vtkToSMTKMesh vtkFiltersSources)
add_executable(MultiScaleConverter MultiScaleConverter.cxx)
target_link_libraries(MultiScaleConverter
LINK_PUBLIC vtkToSMTKMesh
vtkIOExodus vtkIOXML vtksys)
target_include_directories(MultiScaleConverter PRIVATE ${MOAB_INCLUDE_DIRS})
add_executable(SurfacePerMaterialExtraction SurfacePerMaterialExtraction.cxx)
target_link_libraries(SurfacePerMaterialExtraction
LINK_PUBLIC vtkToSMTKMesh
vtkIOExodus vtkIOXML vtksys)
target_include_directories(SurfacePerMaterialExtraction PRIVATE ${MOAB_INCLUDE_DIRS})
//=========================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//=========================================================================
#include "smtk/extension/vtkToMesh/VTKDataConverter.h"
#include "smtk/mesh/Collection.h"
#include "smtk/mesh/Manager.h"
#include "smtk/io/ImportMesh.h"
#include "smtk/io/WriteMesh.h"
#include "vtkNew.h"
#include "vtkParametricBoy.h"
#include "vtkParametricFunctionSource.h"
#include "vtkPoints.h"
#include "vtkSmartPointer.h"
#include "vtkTetra.h"
#include "vtkUnstructuredGrid.h"
#include "vtkWedge.h"
#include "vtksys/SystemTools.hxx"
#include "vtkXMLUnstructuredGridReader.h"
#include "vtkXMLPolyDataReader.h"
namespace
{
//----------------------------------------------------------------------------
template<typename TReader>
vtkDataSet* readXMLFile(const std::string& fileName)
{
vtkSmartPointer<TReader> reader = vtkSmartPointer<TReader>::New();
reader->SetFileName(fileName.c_str());
reader->Update();
reader->GetOutput()->Register(reader);
return vtkDataSet::SafeDownCast(reader->GetOutput());
}
//----------------------------------------------------------------------------
class YFilter : public smtk::mesh::CellForEach
{
double yvalue;
public:
smtk::mesh::HandleRange validPoints;
YFilter( double value ) :
smtk::mesh::CellForEach(),
yvalue( value )
{
}
//--------------------------------------------------------------------------
void operator()(smtk::mesh::CellType& cellType,
int numPts,
const smtk::mesh::Handle* const pointIds,
const double* const coords)
{
(void) cellType;
for( int i=0; i < numPts; ++i)
{
const double currValue = coords[(i*3)+1];
//add in a small tolerance
if(currValue >= (yvalue-0.002) &&
currValue <= (yvalue+0.002))
{
validPoints.insert(pointIds[i]);
}
}
}
};
//----------------------------------------------------------------------------
void labelShellWithMaterial(const smtk::mesh::CollectionPtr& c,
const smtk::mesh::MeshSet& shell)
{
//for each material we iterate the meshsets
typedef std::vector< smtk::mesh::Domain > DomainVecType;
typedef DomainVecType::const_iterator dom_cit;
DomainVecType domains = c->domains();
for(dom_cit dom = domains.begin(); dom != domains.end(); ++dom)
{
smtk::mesh::MeshSet domainMeshes = c->meshes(*dom);
//find all cells in the shell that share a point in common
//with domain volume
smtk::mesh::CellSet contactCells = smtk::mesh::point_intersect(domainMeshes.cells(),
shell.cells(),
smtk::mesh::FullyContained);
if(!contactCells.is_empty())
{
//create a new meshset that represents the section of exterior shell
//that has this domain
smtk::mesh::MeshSet contactD = c->createMesh( contactCells );
c->setDomainOnMeshes( contactD, *dom );
}
}
}
//----------------------------------------------------------------------------
bool labelIntersection(const smtk::mesh::CollectionPtr& c,
const smtk::mesh::MeshSet& shell,
double value)
{
static int nextDirId = 0;
//need to removing the verts cells from the query for now
//todo: filter needs to support vert cells
smtk::mesh::CellSet shellCells = shell.cells( );
YFilter filter(value);
//extract the top cells
smtk::mesh::for_each(shellCells ,filter);
smtk::mesh::CellSet filteredCells = smtk::mesh::CellSet(c, filter.validPoints);
//for each material we iterate the meshsets
typedef std::vector< smtk::mesh::Domain > DomainVecType;
typedef DomainVecType::const_iterator dom_cit;
DomainVecType domains = c->domains();
//intersect the material and verts to find the verts of a given
//material that passed the filter.
//This verts than become a dirichlet set
for(dom_cit dom = domains.begin(); dom != domains.end(); ++dom)
{