Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_Workset_Utilities.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 
43 #ifndef PANZER_WORKSET_UTILITIES_HPP
44 #define PANZER_WORKSET_UTILITIES_HPP
45 
46 #include "Panzer_Traits.hpp"
47 #include "Panzer_Workset.hpp"
48 #include "Teuchos_Assert.hpp"
49 #include <vector>
50 #include <string>
51 #include <algorithm>
52 #include <iterator>
53 
54 namespace panzer {
55 
56  std::vector<std::string>::size_type
57  getPureBasisIndex(std::string basis_name, const panzer::Workset& workset, WorksetDetailsAccessor& wda)
58  {
59  std::vector<std::string>::iterator basis = wda(workset).basis_names->begin();
60  std::vector<std::string>::const_iterator last = wda(workset).basis_names->end();
61 
62  while (basis != last) {
63 
64  std::vector<std::string>::size_type index = std::distance(wda(workset).basis_names->begin(), basis);
65  if (wda(workset).bases[index]->basis_layout->getBasis()->name() == basis_name)
66  break;
67 
68  ++basis;
69  }
70 
71  TEUCHOS_TEST_FOR_EXCEPTION(basis == wda(workset).basis_names->end(),
72  std::logic_error,
73  "Could not find the basis named \""
74  << basis_name << "\" in the workset!");
75 
76  return std::distance(wda(workset).basis_names->begin(), basis);
77  }
78 
79  std::vector<std::string>::size_type
80  getBasisIndex(std::string basis_name, const panzer::Workset& workset, WorksetDetailsAccessor& wda)
81  {
82  std::vector<std::string>::iterator basis;
83 
84  basis = std::find(wda(workset).basis_names->begin(),
85  wda(workset).basis_names->end(),
86  basis_name);
87 
88  TEUCHOS_TEST_FOR_EXCEPTION(basis == wda(workset).basis_names->end(),
89  std::logic_error,
90  "Could not find the basis named \""
91  << basis_name << "\" in the workset!");
92 
93  return std::distance(wda(workset).basis_names->begin(), basis);
94  }
95 
96  std::vector<std::string>::size_type
97  getIntegrationRuleIndex(int ir_degree, const panzer::Workset& workset, WorksetDetailsAccessor& wda)
98  {
99  std::vector<int>::iterator ir;
100 
101  ir = std::find(wda(workset).ir_degrees->begin(),
102  wda(workset).ir_degrees->end(),
103  ir_degree);
104 
105  TEUCHOS_TEST_FOR_EXCEPTION(ir == wda(workset).ir_degrees->end(),
106  std::logic_error,
107  "Could not find the integration rule degree \""
108  << ir_degree << "\" in the workset!");
109 
110  return std::distance(wda(workset).ir_degrees->begin(), ir);
111  }
112 
113  void printWorkset(std::ostream& os, const panzer::Workset & workset, WorksetDetailsAccessor& wda)
114  {
115  os << "WORKSET"
116  << " block_id = \"" << wda(workset).block_id << "\""
117  << " num_cells = \"" << workset.num_cells << "\"\n";
118  os << " cell_local_ids = [ ";
119  for(index_t i=0;i<workset.num_cells;i++)
120  os << wda(workset).cell_local_ids[i] << " ";
121  os << "]\n";
122  os << " ir_degrees = [ ";
123  for(std::size_t i=0;i<wda(workset).ir_degrees->size();i++)
124  os << (*wda(workset).ir_degrees)[i] << " ";
125  os << "]\n";
126  os << " basis_names = [ ";
127  for(std::size_t i=0;i<wda(workset).basis_names->size();i++)
128  os << (*wda(workset).basis_names)[i] << " ";
129  os << "]\n";
130  /*
131  os << " int rule = "; wda(workset).int_rules[0]->int_rule->print(os); os << "\n";
132  os << " basis = "; wda(workset).bases[0]->panzer_basis->print(os); os << "\n";
133 
134  for(index_t i=0;i<workset.num_cells;i++) {
135  os << " cell " << i << " vertices =\n";
136  for(int j=0;j<wda(workset).cell_vertex_coordinates.extent(1);j++) {
137  os << " ";
138  for(int k=0;k<wda(workset).cell_vertex_coordinates.extent(2);k++)
139  os << wda(workset).cell_vertex_coordinates(i,j,k) << " ";
140  os << "\n";
141  }
142  }
143 
144  os << " integration rule points =\n";
145  for(int j=0;j<wda(workset).int_rules[0]->cub_points.extent(0);j++) {
146  os << " ";
147  for(int k=0;k<wda(workset).int_rules[0]->cub_points.extent(1);k++)
148  os << wda(workset).int_rules[0]->cub_points(j,k) << " ";
149  os << "\n";
150  }
151  os << " integration weights = [ ";
152  for(int j=0;j<wda(workset).int_rules[0]->cub_weights.extent(0);j++) {
153  os << wda(workset).int_rules[0]->cub_weights(j) << " ";
154  }
155  os << "]\n";
156 
157  os << " jac = [ ";
158  for(int i=0;i<wda(workset).int_rules[0]->jac.size();i++) {
159  os << wda(workset).int_rules[0]->jac[i] << " ";
160  }
161  os << "]\n";
162 
163  os << " jac_inv = [ ";
164  for(int i=0;i<wda(workset).int_rules[0]->jac_inv.size();i++) {
165  os << wda(workset).int_rules[0]->jac_inv[i] << " ";
166  }
167  os << "]\n";
168 
169  os << " jac_det = [ ";
170  for(int i=0;i<wda(workset).int_rules[0]->jac_det.size();i++) {
171  os << wda(workset).int_rules[0]->jac_det[i] << " ";
172  }
173  os << "]\n";
174 
175  os << " node_coordinates = [ ";
176  for(int i=0;i<wda(workset).int_rules[0]->node_coordinates.size();i++) {
177  os << wda(workset).int_rules[0]->node_coordinates[i] << " ";
178  }
179  os << "]\n";
180 
181  os << " weighted_basis = [ ";
182  for(int i=0;i<wda(workset).bases[0]->weighted_basis.size();i++)
183  os << wda(workset).bases[0]->weighted_basis[i] << " ";
184  os << "]\n";
185 
186  os << " weighted_grad_basis = [ ";
187  for(int i=0;i<wda(workset).bases[0]->weighted_grad_basis.size();i++)
188  os << wda(workset).bases[0]->weighted_grad_basis[i] << " ";
189  os << "]\n";
190 
191  os << " basis = [ ";
192  for(int i=0;i<wda(workset).bases[0]->basis.size();i++)
193  os << wda(workset).bases[0]->basis[i] << " ";
194  os << "]\n";
195 
196  os << " grad_basis = [ ";
197  for(int i=0;i<wda(workset).bases[0]->grad_basis.size();i++)
198  os << wda(workset).bases[0]->grad_basis[i] << " ";
199  os << "]\n";
200  */
201  }
202 
203  std::vector<std::string>::size_type
204  getPureBasisIndex(std::string basis_name, const panzer::Workset& workset) {
206  return getPureBasisIndex(basis_name, workset, wda);
207  }
208  std::vector<std::string>::size_type
209  getBasisIndex(std::string basis_name, const panzer::Workset& workset) {
211  return getBasisIndex(basis_name, workset, wda);
212  }
213  std::vector<int>::size_type
214  getIntegrationRuleIndex(int ir_degree, const panzer::Workset& workset) {
216  return getIntegrationRuleIndex(ir_degree, workset, wda);
217  }
218  void printWorkset(std::ostream& os, const panzer::Workset & workset) {
220  printWorkset(os, workset, wda);
221  }
222 }
223 
224 #endif
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::vector< std::string >::size_type getIntegrationRuleIndex(int ir_degree, const panzer::Workset &workset, WorksetDetailsAccessor &wda)
void printWorkset(std::ostream &os, const panzer::Workset &workset, WorksetDetailsAccessor &wda)
std::vector< std::string >::size_type getBasisIndex(std::string basis_name, const panzer::Workset &workset, WorksetDetailsAccessor &wda)
Returns the index in the workset bases for a particular BasisIRLayout name.
std::vector< std::string >::size_type getPureBasisIndex(std::string basis_name, const panzer::Workset &workset, WorksetDetailsAccessor &wda)
Returns the index in the workset bases for a particular PureBasis name.