11 #ifndef PANZER_RESPONSE_SCATTER_EVALUATOR_EXTREMEVALUE_IMPL_HPP
12 #define PANZER_RESPONSE_SCATTER_EVALUATOR_EXTREMEVALUE_IMPL_HPP
17 #include "PanzerDiscFE_config.hpp"
19 #include "Phalanx_Evaluator_Macros.hpp"
20 #include "Phalanx_MDField.hpp"
21 #include "Phalanx_DataLayout_MDALayout.hpp"
30 #include "Intrepid2_FunctionSpaceTools.hpp"
32 #include "Thyra_SpmdVectorBase.hpp"
33 #include "Teuchos_ArrayRCP.hpp"
35 #include "Kokkos_ViewFactory.hpp"
39 template<
typename EvalT,
typename Traits,
typename LO,
typename GO>
42 const std::string & responseName,
43 const std::string & fieldName,
44 const int fieldComponent,
50 : responseName_(responseName)
51 , fieldName_(fieldName)
52 , fieldComponent_(fieldComponent)
55 , topology_(ir.topology)
56 , globalIndexer_(indexer)
57 , scatterObj_(probeScatter)
67 this->addDependentField(
field_);
77 std::string dummyName =
83 std::string n =
"Probe Response Scatter: " + responseName;
87 template<
typename EvalT,
typename Traits,
typename LO,
typename GO>
92 for (
const auto& workset : *sd.
worksets_) {
93 this->findCellAndComputeBasisValues(workset);
99 template<
typename EvalT,
typename Traits,
typename LO,
typename GO>
110 template<
typename EvalT,
typename Traits,
typename LO,
typename GO>
116 using HostSpace = Kokkos::DefaultHostExecutionSpace;
117 using CTD = Intrepid2::CellTools<HostSpace>;
118 using FST = Intrepid2::FunctionSpaceTools<HostSpace>;
121 const int num_points = 1;
122 Kokkos::DynRankView<int,HostSpace> inCell(
"inCell", this->wda(d).cell_node_coordinates.extent_int(0), num_points);
123 Kokkos::DynRankView<double,HostSpace> physical_points_cell(
"physical_points_cell", this->wda(d).cell_node_coordinates.extent_int(0), num_points, num_dim);
124 auto tmp_point = point_;
126 Kokkos::MDRangePolicy<HostSpace,Kokkos::Rank<2>> policy({0,0},{d.
num_cells,
static_cast<decltype(d.num_cells)
>(num_dim)});
127 Kokkos::parallel_for(
"copy node coords",policy,[&](
const int cell,
const int dim){
128 physical_points_cell(cell,0,dim) = tmp_point[dim];
132 auto cell_coords = this->wda(d).cell_node_coordinates.get_view();
133 auto cell_coords_host = Kokkos::create_mirror_view(cell_coords);
134 Kokkos::deep_copy(cell_coords_host, cell_coords);
136 const double tol = 1.0e-12;
137 CTD::checkPointwiseInclusion(inCell,
138 physical_points_cell,
144 for (index_t cell=0; cell<static_cast<int>(d.
num_cells); ++cell) {
145 if (inCell(cell,0) == 1) {
159 const size_t num_nodes = this->wda(d).cell_node_coordinates.extent(1);
160 Kokkos::DynRankView<double,HostSpace> cell_coords(
"cell_coords", 1,
int(num_nodes),
int(num_dim));
161 auto cnc_host = Kokkos::create_mirror_view(this->wda(d).cell_node_coordinates.get_view());
162 Kokkos::deep_copy(cnc_host,this->wda(d).cell_node_coordinates.get_view());
163 for (
size_t i=0; i<num_nodes; ++i) {
164 for (
size_t j=0; j<num_dim; ++j) {
165 cell_coords(0,i,j) = cnc_host(cellIndex_,i,j);
168 Kokkos::DynRankView<double,HostSpace> physical_points(
"physical_points", 1, 1, num_dim);
169 for (
size_t i=0; i<num_dim; ++i)
170 physical_points(0,0,i) = physical_points_cell(0,0,i);
172 Kokkos::DynRankView<double,HostSpace> reference_points(
"reference_points", 1, 1, num_dim);
173 CTD::mapToReferenceFrame(reference_points, physical_points, cell_coords, *topology_);
175 Kokkos::DynRankView<double,HostSpace> reference_points_cell(
"reference_points_cell", 1, num_dim);
176 for (
size_t i=0; i<num_dim; ++i)
177 reference_points_cell(0,i) = reference_points(0,0,i);
184 Kokkos::DynRankView<double,HostSpace> ref_basis_values(
"ref_basis_values", num_basis, 1);
185 basis_->getIntrepid2Basis<HostSpace,double,
double>()->getValues(ref_basis_values,
186 reference_points_cell,
187 Intrepid2::OPERATOR_VALUE);
190 auto basis_values_host = Kokkos::create_mirror_view(basis_values_);
191 FST::HGRADtransformVALUE<double>(basis_values_host, ref_basis_values);
192 Kokkos::deep_copy(basis_values_,basis_values_host);
198 Kokkos::DynRankView<double,HostSpace> ref_basis_values(
"ref_basis_values", num_basis, 1, num_dim);
199 basis_->getIntrepid2Basis<HostSpace,double,
double>()->getValues(ref_basis_values,
200 reference_points_cell,
201 Intrepid2::OPERATOR_VALUE);
204 Kokkos::DynRankView<double,HostSpace>
jac(
"jac", 1, 1, num_dim, num_dim);
205 CTD::setJacobian(jac, reference_points, cell_coords, *topology_);
206 Kokkos::DynRankView<double,HostSpace> basis_values_vec(
"basis_values_vec", 1, num_basis, 1, num_dim);
208 Kokkos::DynRankView<double,HostSpace> jac_inv(
"jac_inv", 1, 1, num_dim, num_dim);
209 CTD::setJacobianInv(jac_inv, jac);
210 FST::HCURLtransformVALUE<double>(basis_values_vec, jac_inv,
214 Kokkos::DynRankView<double,HostSpace> jac_det(
"jac_det", 1, 1);
215 CTD::setJacobianDet(jac_det, jac);
216 FST::HDIVtransformVALUE<double>(basis_values_vec,
jac, jac_det,
221 std::vector<double> orientation;
222 globalIndexer_->getElementOrientation(cellIndex_, orientation);
223 std::string blockId = this->wda(d).block_id;
224 int fieldNum = globalIndexer_->getFieldNum(fieldName_);
225 const std::vector<int> & elmtOffset = globalIndexer_->getGIDFieldOffsets(blockId,fieldNum);
228 for (
size_t i=0; i<num_basis; ++i) {
229 int offset = elmtOffset[i];
230 basis_values_(0,i,0) = orientation[offset] * basis_values_vec(0,i,0,fieldComponent_);
238 template<
typename EvalT,
typename Traits,
typename LO,
typename GO>
242 using HostSpace = Kokkos::DefaultHostExecutionSpace;
248 auto field_coeffs_host = Kokkos::create_mirror_view(field_.get_view());
249 Kokkos::deep_copy(field_coeffs_host,field_.get_view());
251 auto field_coeffs_host_subview = Kokkos::subview(field_coeffs_host,std::pair<int,int>(cellIndex_,cellIndex_+1),Kokkos::ALL);
253 auto field_val = Kokkos::createDynRankViewWithType<Kokkos::DynRankView<ScalarT,HostSpace>>(field_coeffs_host,
"field_val_at_point", 1, 1);
255 auto basis_values_host = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(),basis_values_);
257 Intrepid2::FunctionSpaceTools<HostSpace>::evaluate(field_val, field_coeffs_host_subview, basis_values_host);
258 responseObj_->value = field_val(0,0);
259 responseObj_->have_probe =
true;
262 template <
typename LO,
typename GO>
267 using Teuchos::rcp_dynamic_cast;
268 using Thyra::SpmdVectorBase;
277 rcp_dynamic_cast<SpmdVectorBase<double> >(this->
responseObj_->getGhostedVector());
278 dgdx->getNonconstLocalData(ptrFromRef(local_dgdx));
283 this->responseObj_->have_probe,
Teuchos::RCP< const panzer::PureBasis > basis_
Teuchos::RCP< GlobalEvaluationDataContainer > gedc
PHX::MDField< const ScalarT, Cell, BASIS > field_
int num_cells
DEPRECATED - use: numCells()
std::size_t getIdentifier() const
Get the unique identifier for this workset, this is not an index!
Teuchos::Array< double > point_
Teuchos::RCP< PHX::FieldTag > scatterHolder_
void preEvaluate(typename Traits::PreEvalData d)
static std::string buildLookupName(const std::string &responseName)
void postRegistrationSetup(typename Traits::SetupData, PHX::FieldManager< Traits > &)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void evaluateFields(typename Traits::EvalData d)
bool findCellAndComputeBasisValues(typename Traits::EvalData d)
Kokkos::DynRankView< double, PHX::Device > basis_values_
ResponseScatterEvaluator_ProbeBase(const std::string &responseName, const std::string &fieldName, const int fieldComponent, const Teuchos::Array< double > &point, const IntegrationRule &ir, const Teuchos::RCP< const PureBasis > &basis, const Teuchos::RCP< const panzer::GlobalIndexer > &indexer, const Teuchos::RCP< ProbeScatterBase > &probeScatter)
A constructor with concrete arguments instead of a parameter list.
Teuchos::RCP< Response_Probe< EvalT > > responseObj_
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< PHX::DataLayout > functional
<Cell,Basis> or <Cell,Basis>
Teuchos::RCP< ProbeScatterBase > scatterObj_
Teuchos::RCP< const std::vector< panzer::Workset > > worksets_