00001
00002
00003
00004
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
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
00031 if(paramsFromProblem != Teuchos::null)
00032 materialDB = paramsFromProblem->get< Teuchos::RCP<QCAD::MaterialDatabase> >("MaterialDB");
00033 else materialDB = Teuchos::null;
00034
00035
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
00055 outputFilename = plist->get<std::string>("Output Filename");
00056
00057
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
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
00105
00106
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
00115
00116
00117
00118
00119
00120 for(std::size_t i=0; i<numDims; i++) {
00121
00122
00123
00124
00125
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
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 }
00153
00154
00155
00156
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