Panzer  Version of the Day
Panzer_GeometricAggFieldPattern.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
44 
45 using Teuchos::RCP;
46 
47 namespace panzer {
48 
50  : patternBuilt_(false), dimension_(0)
51 {}
52 
53 GeometricAggFieldPattern::GeometricAggFieldPattern(std::vector<Teuchos::RCP<const FieldPattern> > & patterns)
54  : patternBuilt_(false), dimension_(0)
55 {
56  buildPattern(patterns);
57 }
58 
59 GeometricAggFieldPattern::GeometricAggFieldPattern(const Teuchos::RCP<const FieldPattern> & pattern)
60  : patternBuilt_(false), dimension_(0)
61 {
62  buildPattern(pattern);
63 }
64 
65 void GeometricAggFieldPattern::buildPattern(const std::vector<Teuchos::RCP<const FieldPattern> > & patterns)
66 {
67  std::size_t numPat = patterns.size();
68 
69  // must be at least one field to do something
70  if(numPat<1) {
71  bool no_patterns_to_construct = true;
72  TEUCHOS_TEST_FOR_EXCEPTION(no_patterns_to_construct,std::logic_error,
73  "GeometricAggFieldPattern::buildPattern requires at least one field pattern");
74  return;
75  }
76 
77  bool sameGeometry=true;
78  for(std::size_t i=1;i<patterns.size();i++)
79  sameGeometry &= patterns[0]->sameGeometry(*patterns[i]);
80  TEUCHOS_TEST_FOR_EXCEPTION(not sameGeometry,std::logic_error,
81  "GeometricAggFieldPattern::buildPattern(): Patterns must "
82  "have the same geometry!");
83 
84  // copy cell topology
85  cellTopo_ = patterns[0]->getCellTopology();
86 
87  // grab the dimension
88  dimension_ = patterns[0]->getDimension();
89  patternData_.resize(dimension_+1);
90 
91  // build space for subcells
92  std::vector<int> subcellCount(dimension_+1);
93  for(std::size_t d=0;d<dimension_+1;d++) {
94  subcellCount[d] = patterns[0]->getSubcellCount(d);
95  patternData_[d].resize(subcellCount[d]);
96  }
97 
98  // build geometric pattern: increment it logically
99  // over all the subcells.
100  int counter = 0;
101  for(std::size_t d=0;d<dimension_+1;d++) {
102  for(int s=0;s<subcellCount[d];s++) {
103  std::vector<int> & current = patternData_[d][s];
104  for(std::size_t p=0;p<patterns.size();p++) {
105  RCP<const FieldPattern> field = patterns[p];
106 
107  // if dofs exist, we have a geometric entity
108  const std::size_t num = ( (field->getSubcellIndices(d,s).size() > 0) ? 1 : 0 );
109 
110  if(current.size()<num) {
111  for(int i=num-current.size();i>0;i--,counter++)
112  current.push_back(counter);
113  }
114  }
115  }
116  }
117 
118  // record that the pattern has been built
119  patternBuilt_ = true;
120 }
121 
122 void GeometricAggFieldPattern::buildPattern(const Teuchos::RCP<const FieldPattern> & pattern)
123 {
124  std::vector<Teuchos::RCP<const FieldPattern> > patterns;
125  patterns.push_back(pattern);
126  buildPattern(patterns);
127 }
128 
130 {
131  if(patternBuilt_) return patternData_[dim].size();
132 
133  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
134  "GeometricAggFieldPattern::getSubcellCount() cannot be called before "
135  "GeometricAggFieldPattern::buildPattern()");
136 }
137 
138 const std::vector<int> & GeometricAggFieldPattern::getSubcellIndices(int dim,int cellIndex) const
139 {
140  if(patternBuilt_) return patternData_[dim][cellIndex];
141 
142  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
143  "GeometricAggFieldPattern::getSubcellIndices() cannot be called before "
144  "GeometricAggFieldPattern::buildPattern()");
145 }
146 
148 {
149  if(patternBuilt_) return dimension_;
150 
151  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
152  "GeometricAggFieldPattern::getDimension() cannot be called before "
153  "GeometricAggFieldPattern::buildPattern()");
154 }
155 
156 shards::CellTopology GeometricAggFieldPattern::getCellTopology() const
157 {
158  if(patternBuilt_) return cellTopo_;
159 
160  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
161  "GeometricAggFieldPattern::getCellTopology() cannot be called before "
162  "GeometricAggFieldPattern::buildPattern()");
163 }
164 
165 }
std::vector< std::vector< std::vector< int > > > patternData_
virtual shards::CellTopology getCellTopology() const
PHX::MDField< ScalarT > vector
virtual const std::vector< int > & getSubcellIndices(int dim, int cellIndex) const
PHX::MDField< const ScalarT, Cell, IP > field
virtual void buildPattern(const std::vector< Teuchos::RCP< const FieldPattern > > &patterns)
virtual bool sameGeometry(const FieldPattern &fp) const