• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

QCAD_ResponseRegionBoundary_Def.hpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 
00007 #include <fstream>
00008 #include "Teuchos_TestForException.hpp"
00009 #include "Teuchos_CommHelpers.hpp"
00010 #include "Albany_Utils.hpp"
00011 
00012 template<typename EvalT, typename Traits>
00013 QCAD::ResponseRegionBoundary<EvalT, Traits>::
00014 ResponseRegionBoundary(Teuchos::ParameterList& p,
00015        const Teuchos::RCP<Albany::Layouts>& dl) :
00016   coordVec("Coord Vec", dl->qp_vector),
00017   weights("Weights", dl->qp_scalar)
00018 {
00019   // get and validate Response parameter list
00020   Teuchos::ParameterList* plist = 
00021     p.get<Teuchos::ParameterList*>("Parameter List");
00022   Teuchos::RCP<const Teuchos::ParameterList> reflist = 
00023     this->getValidResponseParameters();
00024   plist->validateParameters(*reflist,0);
00025 
00027   Teuchos::RCP<Teuchos::ParameterList> paramsFromProblem = 
00028     p.get< Teuchos::RCP<Teuchos::ParameterList> >("Parameters From Problem");
00029 
00030     // Material database (if given)
00031   if(paramsFromProblem != Teuchos::null)
00032     materialDB = paramsFromProblem->get< Teuchos::RCP<QCAD::MaterialDatabase> >("MaterialDB");
00033   else materialDB = Teuchos::null;
00034 
00035   // number of quad points per cell and dimension of space
00036   Teuchos::RCP<PHX::DataLayout> scalar_dl = dl->qp_scalar;
00037   Teuchos::RCP<PHX::DataLayout> vector_dl = dl->qp_vector;
00038   
00039   std::vector<PHX::DataLayout::size_type> dims;
00040   vector_dl->dimensions(dims);
00041   numQPs  = dims[1];
00042   numDims = dims[2];
00043 
00044   minVals.resize(numDims);
00045   maxVals.resize(numDims);
00046   for(std::size_t i=0; i<numDims; i++) {
00047     minVals[i] =  1e100;
00048     maxVals[i] = -1e100;
00049   }
00050 
00052   opRegion  = Teuchos::rcp( new QCAD::MeshRegion<EvalT, Traits>("Coord Vec","Weights",*plist,materialDB,dl) );
00053 
00054   // User-specified parameters
00055   outputFilename = plist->get<std::string>("Output Filename");
00056 
00057   // add dependent fields
00058   this->addDependentField(coordVec);
00059   this->addDependentField(weights);
00060   opRegion->addDependentFields(this);
00061 
00062   response_field_tag = Teuchos::rcp(new PHX::Tag<ScalarT>("Get Region Boundary Response -> " + outputFilename,
00063                 dl->dummy));
00064   this->addEvaluatedField(*response_field_tag);
00065 }
00066 
00067 // **********************************************************************
00068 template<typename EvalT, typename Traits>
00069 void QCAD::ResponseRegionBoundary<EvalT, Traits>::
00070 postRegistrationSetup(typename Traits::SetupData d,
00071                       PHX::FieldManager<Traits>& fm)
00072 {
00073   this->utils.setFieldData(coordVec,fm);
00074   this->utils.setFieldData(weights,fm);
00075   opRegion->postRegistrationSetup(fm);
00076 }
00077 
00078 // **********************************************************************
00079 template<typename EvalT, typename Traits>
00080 void QCAD::ResponseRegionBoundary<EvalT, Traits>::
00081 evaluateFields(typename Traits::EvalData workset)
00082 {
00083   if(!opRegion->elementBlockIsInRegion(workset.EBName))
00084     return;
00085 
00086   for (std::size_t cell=0; cell < workset.numCells; ++cell) {
00087     if(!opRegion->cellIsInRegion(cell)) continue;
00088     
00089     //Update min/max values using coordinates of quad points in this cell - better way using nodes?
00090     for (std::size_t qp=0; qp < numQPs; ++qp)  {
00091       for(std::size_t i=0; i<numDims; i++) {
00092   if(minVals[i] > coordVec(cell,qp,i)) minVals[i] = coordVec(cell,qp,i);
00093   if(maxVals[i] < coordVec(cell,qp,i)) maxVals[i] = coordVec(cell,qp,i);
00094       }
00095     }
00096   }
00097 }
00098 
00099 // **********************************************************************
00100 template<typename EvalT, typename Traits>
00101 void QCAD::ResponseRegionBoundary<EvalT, Traits>::
00102 postEvaluate(typename Traits::PostEvalData workset)
00103 {
00104   //Only perform this post-evaluation for the residual case or jacobian cases, 
00105   // since we just write coordinate values to an output file.  In particular, Tangent doesn't
00106   // work with EvalUatorTools correctly yet, so we want to skip it for now.
00107   if(QCAD::EvaluatorTools<EvalT,Traits>::getEvalType() != "Residual" && 
00108      QCAD::EvaluatorTools<EvalT,Traits>::getEvalType() != "Jacobian") {
00109     return;
00110   }
00111 
00112   std::vector<double> global_minVals(numDims), global_maxVals(numDims);
00113 
00114   // EGN: Removed (commented out) serializer since this gives templating compile errors
00115   //   for MeshScalarT.
00116  
00117   //Teuchos::RCP< Teuchos::ValueTypeSerializer<int,MeshScalarT> > serializer =
00118   //  workset.serializerManager.template getValue<EvalT>();
00119 
00120   for(std::size_t i=0; i<numDims; i++) {
00121     // Compute contributions across processors
00122     //Teuchos::reduceAll(*workset.comm, *serializer, Teuchos::REDUCE_MIN, 1, 
00123     //                    &global_minVals[i], &minVals[i]);
00124     //Teuchos::reduceAll(*workset.comm, *serializer, Teuchos::REDUCE_MAX, 1,
00125     //                    &global_maxVals[i], &maxVals[i]);
00126     double minVal = QCAD::EvaluatorTools<EvalT,Traits>::getMeshDoubleValue(minVals[i]);
00127     double maxVal = QCAD::EvaluatorTools<EvalT,Traits>::getMeshDoubleValue(maxVals[i]);
00128     Teuchos::reduceAll(*workset.comm, Teuchos::REDUCE_MIN, 1, &minVal, &(global_minVals[i]));
00129     Teuchos::reduceAll(*workset.comm, Teuchos::REDUCE_MAX, 1, &maxVal, &(global_maxVals[i]));
00130 
00131     //DEBUG (assumes 2D case)
00132     //std::cout << "DEBUG: min/max vals["<<i<<"] (global) = " << global_minVals[i] << "," << global_maxVals[i] << std::endl;
00133 
00134     //Note: we really don't need any of this fancy MPI to broadcast the global min/max to each processor
00135     //  since only rank 0 writes the output file, but keep here for reference.
00136     /*int procToBcast_max = -1, procToBcast_min = -1;
00137     if( global_minVals[i] == minVal ) 
00138       procToBcast_min = workset.comm->getRank();
00139     if( global_maxVals[i] == maxVal ) 
00140       procToBcast_max = workset.comm->getRank();
00141 
00142     int winner_max, winner_min;
00143     Teuchos::reduceAll(*workset.comm, Teuchos::REDUCE_MAX, 1, &procToBcast_min, &winner_min);
00144     Teuchos::reduceAll(*workset.comm, Teuchos::REDUCE_MAX, 1, &procToBcast_max, &winner_max);
00145 
00146     std::cout << "DEBUG: min/max winners = " << winner_min << ", " << winner_max << std::endl;
00147     //Teuchos::broadcast(*workset.comm, *serializer, winner_min, 1, &global_minVals[i]);
00148     //Teuchos::broadcast(*workset.comm, *serializer, winner_max, 1, &global_maxVals[i]);
00149     Teuchos::broadcast(*workset.comm, winner_min, 1, &global_minVals[i]);
00150     Teuchos::broadcast(*workset.comm, winner_max, 1, &global_maxVals[i]);
00151     */
00152   }
00153 
00154   //Now global_minVals and global_maxVals have global min/max coordinate values on each proc
00155   
00156   // Rank 0 proc outputs to file
00157   if(workset.comm->getRank() == 0) {
00158     if( outputFilename.length() > 0) {
00159       std::fstream out;
00160       out.open(outputFilename.c_str(), std::fstream::out);
00161       out << "# i-th line below gives <min> <max> values for i-th dimension" << std::endl;
00162       
00163       for(std::size_t i=0; i<numDims; i++)
00164   out << global_minVals[i] << " " << global_maxVals[i] << std::endl;
00165 
00166       out.close();
00167     }
00168   }
00169 }
00170 
00171 // **********************************************************************
00172 template<typename EvalT,typename Traits>
00173 Teuchos::RCP<const Teuchos::ParameterList>
00174 QCAD::ResponseRegionBoundary<EvalT,Traits>::getValidResponseParameters() const
00175 {
00176   Teuchos::RCP<Teuchos::ParameterList> validPL =
00177       rcp(new Teuchos::ParameterList("Valid ResponseRegionBoundary Params"));
00178 
00179   Teuchos::RCP<const Teuchos::ParameterList> regionValidPL =
00180     QCAD::MeshRegion<EvalT,Traits>::getValidParameters();
00181   validPL->setParameters(*regionValidPL);
00182 
00183   validPL->set<std::string>("Name", "", "Name of response function");
00184   validPL->set<int>("Phalanx Graph Visualization Detail", 0, "Make dot file to visualize phalanx graph");
00185   validPL->set<std::string>("Output Filename", "<filename>", "The file to write region boundary (min/max values) to");
00186   validPL->set<std::string>("Description", "", "Description of this response used by post processors");
00187 
00188   return validPL;
00189 }
00190 
00191 // **********************************************************************
00192 

Generated on Wed Mar 26 2014 18:36:44 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1