Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_ClosureModel_Factory_Composite_impl.hpp
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_CLOSURE_MODEL_FACTORY_COMPOSITE_IMPL_HPP
44 #define PANZER_CLOSURE_MODEL_FACTORY_COMPOSITE_IMPL_HPP
45 
46 #include <iostream>
47 #include <sstream>
48 #include <string>
49 #include <vector>
50 #include <list>
51 #include "Panzer_GlobalData.hpp"
54 #include "Teuchos_StandardParameterEntryValidators.hpp"
57 
58 // ********************************************************************
59 template<typename EvalT>
62  m_factories(factories)
63 { }
64 
65 // ********************************************************************
66 template<typename EvalT>
69 buildClosureModels(const std::string& model_id,
70  const Teuchos::ParameterList& models,
73  const Teuchos::ParameterList& default_params,
74  const Teuchos::ParameterList& user_data,
75  const Teuchos::RCP<panzer::GlobalData>& global_data,
77 {
78 
79  using std::string;
80  using std::vector;
81  using Teuchos::RCP;
82  using Teuchos::rcp;
84  using PHX::Evaluator;
85 
87  rcp(new vector< RCP<Evaluator<panzer::Traits> > > );
88 
89  if (!models.isSublist(model_id)) {
90  std::stringstream msg;
91  msg << "Falied to find requested model, \"" << model_id
92  << "\" for equation set:\n" << std::endl;
93  TEUCHOS_TEST_FOR_EXCEPTION(!models.isSublist(model_id), std::logic_error, msg.str());
94  }
95 
96  const ParameterList& my_model = models.sublist(model_id);
97 
98  // pull out the nonlist (not associated with any model) parameters
99  // this will be used by each stored closure model
100  Teuchos::ParameterList nonlist_params(models.name()); // make sure it maintains the models name
101  for (ParameterList::ConstIterator model_it = models.begin();
102  model_it != models.end(); ++model_it) {
103 
104  std::string key = model_it->first;
105  if(!model_it->second.isList())
106  nonlist_params.setEntry(key,model_it->second);
107  }
108 
109  // build a copy of parameter list containing only the closure model of current relevance
110  // with any supplemental non-list information contained in the parameter list
111  ParameterList copy_of_my_model = nonlist_params;
112  copy_of_my_model.sublist(model_id) = my_model; // copy my_model into copy of models
113 
114  // Loop over factories
115  for (std::vector<Teuchos::RCP<panzer::ClosureModelFactory_TemplateManager<panzer::Traits> > >::const_iterator factory = m_factories.begin(); factory != m_factories.end(); ++factory) {
116 
117  (*factory)->getAsObject<EvalT>()->setThrowOnModelNotFound(false);
118  RCP< vector< RCP<Evaluator<panzer::Traits> > > > tmp_evaluators =
119  (*factory)->getAsObject<EvalT>()->buildClosureModels(model_id,copy_of_my_model,fl,ir,default_params,user_data,global_data,fm);
120 
121  if (tmp_evaluators->size() > 0) {
122  for (vector< RCP<Evaluator<panzer::Traits> > >::const_iterator eval = tmp_evaluators->begin(); eval != tmp_evaluators->end(); ++eval)
123  evaluators->push_back(*eval);
124  }
125 
126  }
127 
128 /*
129  // for each model, try each factory until you get a nonnull
130  // return, meaning you have built the evaluators for that model
131  for (ParameterList::ConstIterator model_it = my_model.begin();
132  model_it != my_model.end(); ++model_it) {
133 
134  std::string model_key = model_it->first;
135 
136  // Duplicate models sublist with just the particular model you
137  // want to build
138  ParameterList copy_of_models = nonlist_params;
139  // Teuchos::ParameterList* tmp;
140  // copy_of_models.sublist(model_id).sublist(model_key) = model_it->second.getValue(tmp);
141  copy_of_models.sublist(model_id).setEntry(model_key,model_it->second);
142 
143  std::cout << "COPY OF MODELS = " << model_id << std::endl;
144  copy_of_models.print(std::cout);
145 
146  // Loop over factories
147  for (std::vector<Teuchos::RCP<panzer::ClosureModelFactory_TemplateManager<panzer::Traits> > >::const_iterator factory = m_factories.begin(); factory != m_factories.end(); ++factory) {
148 
149  RCP< vector< RCP<Evaluator<panzer::Traits> > > > tmp_evaluators =
150  (*factory)->getAsObject<EvalT>()->buildClosureModels(model_id,set,copy_of_models,default_params,user_data,global_data,fm);
151 
152  if (tmp_evaluators->size() > 0) {
153 
154  for (vector< RCP<Evaluator<panzer::Traits> > >::const_iterator eval = tmp_evaluators->begin(); eval != tmp_evaluators->end(); ++eval)
155  evaluators->push_back(*eval);
156 
157  }
158 
159  }
160 
161  }
162  */
163 
164  return evaluators;
165 }
166 
167 #endif
const std::string & name() const
ConstIterator end() const
Teuchos::RCP< std::vector< Teuchos::RCP< PHX::Evaluator< panzer::Traits > > > > buildClosureModels(const std::string &model_id, const Teuchos::ParameterList &models, const panzer::FieldLayoutLibrary &fl, const Teuchos::RCP< panzer::IntegrationRule > &ir, const Teuchos::ParameterList &default_params, const Teuchos::ParameterList &user_data, const Teuchos::RCP< panzer::GlobalData > &global_data, PHX::FieldManager< panzer::Traits > &fm) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ParameterList & setEntry(const std::string &name, const ParameterEntry &entry)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool isSublist(const std::string &name) const
ConstIterator begin() const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ClosureModelFactoryComposite(const std::vector< Teuchos::RCP< panzer::ClosureModelFactory_TemplateManager< panzer::Traits > > > &factories)