00001
00002
00003
00004
00005
00006
00007 #include "Teuchos_TestForException.hpp"
00008
00009
00010 template<typename EvalT, typename Traits>
00011 QCAD::MeshRegion<EvalT, Traits>::
00012 MeshRegion(std::string coordVecName, std::string weightsName,
00013 Teuchos::ParameterList& p,
00014 const Teuchos::RCP<QCAD::MaterialDatabase> matDB,
00015 const Teuchos::RCP<Albany::Layouts>& dl_ )
00016 {
00017 materialDB = matDB;
00018 coordVecFieldname = coordVecName;
00019 weightsFieldname = weightsName;
00020
00021
00022 std::vector<PHX::DataLayout::size_type> dims;
00023 dl = dl_;
00024 dl->qp_vector->dimensions(dims);
00025 numQPs = dims[1];
00026 numDims = dims[2];
00027
00028
00029 std::string ebNameStr = p.get<std::string>("Element Block Name","");
00030 if(ebNameStr.length() == 0) ebNameStr = p.get<std::string>("Element Block Names","");
00031 if(ebNameStr.length() > 0) Albany::splitStringOnDelim(ebNameStr,',',ebNames);
00032 bQuantumEBsOnly = p.get<bool>("Quantum Element Blocks Only",false);
00033
00034
00035 limitX = limitY = limitZ = false;
00036 if( p.isParameter("x min") && p.isParameter("x max") ) {
00037 limitX = true; TEUCHOS_TEST_FOR_EXCEPT(numDims <= 0);
00038 xmin = p.get<double>("x min");
00039 xmax = p.get<double>("x max");
00040 }
00041 if( p.isParameter("y min") && p.isParameter("y max") ) {
00042 limitY = true; TEUCHOS_TEST_FOR_EXCEPT(numDims <= 1);
00043 ymin = p.get<double>("y min");
00044 ymax = p.get<double>("y max");
00045 }
00046 if( p.isParameter("z min") && p.isParameter("z max") ) {
00047 limitZ = true; TEUCHOS_TEST_FOR_EXCEPT(numDims <= 2);
00048 zmin = p.get<double>("z min");
00049 zmax = p.get<double>("z max");
00050 }
00051
00052
00053 levelSetFieldname = p.get<std::string>("Level Set Field Name","");
00054 levelSetFieldMin = p.get<double>("Level Set Field Minimum", -1e100);
00055 levelSetFieldMax = p.get<double>("Level Set Field Maximum", +1e100);
00056 bRestrictToLevelSet = (levelSetFieldname.length() > 0);
00057
00058 }
00059
00060
00061
00062
00063 template<typename EvalT, typename Traits>
00064 void QCAD::MeshRegion<EvalT, Traits>::
00065 addDependentFields(PHX::EvaluatorWithBaseImpl<Traits>* evaluator)
00066 {
00067 PHX::MDField<MeshScalarT,Cell,QuadPoint,Dim> f(coordVecFieldname, dl->qp_vector);
00068 coordVec = f;
00069 evaluator->addDependentField(coordVec);
00070
00071 if(bRestrictToLevelSet) {
00072 PHX::MDField<MeshScalarT,Cell,QuadPoint> g(weightsFieldname, dl->qp_scalar);
00073 weights = g;
00074 evaluator->addDependentField(weights);
00075
00076 PHX::MDField<ScalarT> h(levelSetFieldname, dl->qp_scalar);
00077 levelSetField = h;
00078 evaluator->addDependentField(levelSetField);
00079 }
00080 }
00081
00082
00083
00084 template<typename EvalT, typename Traits>
00085 void QCAD::MeshRegion<EvalT, Traits>::
00086 postRegistrationSetup(PHX::FieldManager<Traits>& fm)
00087 {
00088 utils.setFieldData(coordVec,fm);
00089 if(bRestrictToLevelSet) {
00090 utils.setFieldData(weights,fm);
00091 utils.setFieldData(levelSetField,fm);
00092 }
00093 }
00094
00095
00096
00097
00098 template<typename EvalT, typename Traits>
00099 bool QCAD::MeshRegion<EvalT, Traits>::
00100 elementBlockIsInRegion(std::string ebName) const
00101 {
00102 bool bQuantumEB = false;
00103
00104 if(materialDB != Teuchos::null)
00105 bQuantumEB = materialDB->getElementBlockParam<bool>(ebName,"quantum",false);
00106
00107 if(bQuantumEBsOnly == true && bQuantumEB == false)
00108 return false;
00109
00110 if(ebNames.size() > 0 && std::find(ebNames.begin(), ebNames.end(), ebName) == ebNames.end())
00111 return false;
00112
00113 return true;
00114 }
00115
00116 template<typename EvalT, typename Traits>
00117 bool QCAD::MeshRegion<EvalT, Traits>::
00118 cellIsInRegion(std::size_t cell)
00119 {
00120
00121 for (std::size_t qp=0; qp < numQPs; ++qp) {
00122 if( (limitX && (coordVec(cell,qp,0) < xmin || coordVec(cell,qp,0) > xmax)) ||
00123 (limitY && (coordVec(cell,qp,1) < ymin || coordVec(cell,qp,1) > ymax)) ||
00124 (limitZ && (coordVec(cell,qp,2) < zmin || coordVec(cell,qp,2) > zmax)) )
00125 return false;
00126 }
00127
00128 if(bRestrictToLevelSet) {
00129 for (std::size_t qp=0; qp < numQPs; ++qp) {
00130
00131
00132 ScalarT cellVol = 0.0, avgCellVal = 0.0;;
00133 for (std::size_t qp=0; qp < numQPs; ++qp) {
00134 avgCellVal += levelSetField(cell,qp) * weights(cell,qp);
00135 cellVol += weights(cell,qp);
00136 }
00137 avgCellVal /= cellVol;
00138
00139 if( avgCellVal > levelSetFieldMax || avgCellVal < levelSetFieldMin)
00140 return false;
00141 }
00142 }
00143
00144 return true;
00145 }
00146
00147
00148