SundanceExtrusionMeshTransformation.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 
00043 #include "SundanceExtrusionMeshTransformation.hpp"
00044 #include "PlayaExceptions.hpp"
00045 #include "SundanceOut.hpp"
00046 
00047 using namespace Sundance;
00048 using namespace Sundance;
00049 
00050 using namespace Teuchos;
00051 using namespace Sundance;
00052 
00053 
00054 
00055 Mesh ExtrusionMeshTransformation::apply(const Mesh& inputMesh) const
00056 {
00057   TEUCHOS_TEST_FOR_EXCEPTION(inputMesh.spatialDim() != 2, std::runtime_error,
00058                      "ExtrusionMeshTransformation::applyLocal() given mesh with "
00059                      "dimension " << inputMesh.spatialDim() << ". The "
00060                      "extrusion filter expects a 2D mesh as input");
00061 
00062   /* create the output 3D mesh, using the communicator from the input mesh */
00063   Mesh outputMesh = createMesh(3, inputMesh.comm());
00064 
00065   //  BasicSimplicialMesh* outputMeshP 
00066   //    = dynamic_cast<BasicSimplicialMesh*>(outputMesh.ptr().get());
00067 
00068   int nPts = inputMesh.numCells(0);
00069   
00070   /* create points in output mesh */
00071   int pointCount = 0;
00072   outputMesh.estimateNumVertices(nzLevels_ * nPts);
00073 
00074   for (int i=0; i<nPts; i++)
00075     {
00076       const Point& p = inputMesh.nodePosition(i);
00077       for (int j=0; j<=nzLevels_; j++, pointCount++)
00078         {
00079           double z = z0_ + (z1_-z0_)*j/((double) nzLevels_);
00080           outputMesh.addVertex(pointCount, Point(p[0], p[1], z), 0, 0);
00081         }
00082     }
00083 
00084 
00085   /* now do the elements */
00086   int nTri = inputMesh.numCells(2);
00087 
00088   /* each triangle in the input mesh will give rise to 
00089    * three tets per extrusion level in the output mesh */
00090 
00091   outputMesh.estimateNumElements(3*nTri*nzLevels_);
00092 
00093   Array<int> facetNodes(3);
00094   Array<int> facetOrientations(3);
00095 
00096   int tetCount = 0;
00097 
00098   TEUCHOS_TEST_FOR_EXCEPTION(inputMesh.cellType(2) != TriangleCell,
00099                      std::runtime_error,
00100                      "ExtrusionMeshTransformation::applyLocal() detected a "
00101                      "non-triangular mesh");
00102   for (int i=0; i<nTri; i++)
00103     {
00104       inputMesh.getFacetArray(2, i, 0, facetNodes, facetOrientations);
00105 
00106       SUNDANCE_OUT(this->verb()==3,
00107                    "triangle=" << i << " facet nodes are " << facetNodes);
00108 
00109       /* We sort the facets in order to get a consistent direction
00110        * for the edges at the different z-planes.  */
00111       std::sort(facetNodes.begin(), facetNodes.end());
00112 
00113       SUNDANCE_OUT(this->verb()==3,
00114                    "triangle=" << i << " sorted facet nodes are " 
00115                    << facetNodes);
00116 
00117       int a0 = facetNodes[0]*(nzLevels_+1);
00118       int b0 = facetNodes[1]*(nzLevels_+1);
00119       int c0 = facetNodes[2]*(nzLevels_+1);
00120 
00121       for (int j=0; j<nzLevels_; j++, tetCount+=3)
00122         {
00123           int a = a0 + j;
00124           int b = b0 + j;
00125           int c = c0 + j;
00126           int a1 = a+1;
00127           int b1 = b+1;
00128           int c1 = c+1;
00129           outputMesh.addElement(tetCount, tuple(a, a1, b1, c1), 0, 0);
00130           outputMesh.addElement(tetCount+1, tuple(a, b, b1, c1), 0, 0);
00131           outputMesh.addElement(tetCount+2, tuple(a, b, c, c1), 0, 0);
00132         }
00133     }
00134 
00135   return outputMesh;
00136 
00137 }     
00138 

Site Contact