Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panzer mini em #9666

Merged
merged 8 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ class ResponseEvaluatorFactory_SolutionWriter : public panzer::ResponseEvaluator
void removeField(const std::string & fieldName)
{ removedFields_.push_back(fieldName); }

private:
// should be private but needs a lambda
void computeReferenceCentroid(const std::map<std::string,Teuchos::RCP<const panzer::PureBasis> > & bases,
int baseDimension,
Kokkos::DynRankView<double,PHX::Device> & centroid) const;

private:
//! Delete from the argument all the fields that are in the removedFields array
void deleteRemovedFields(const std::vector<std::string> & removedFields,
std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > & fields) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ computeReferenceCentroid(const std::map<std::string,Teuchos::RCP<const panzer::P
using Teuchos::rcp_dynamic_cast;

centroid = Kokkos::DynRankView<double,PHX::Device>("centroid",1,baseDimension);
auto l_centroid = centroid;

// loop over each possible basis
for(std::map<std::string,RCP<const panzer::PureBasis> >::const_iterator itr=bases.begin();
Expand All @@ -293,14 +294,12 @@ computeReferenceCentroid(const std::map<std::string,Teuchos::RCP<const panzer::P
intrepidBasis->getDofCoords(coords);
TEUCHOS_ASSERT(coords.rank()==2);
TEUCHOS_ASSERT(coords.extent_int(1)==baseDimension);

for(int i=0;i<coords.extent_int(0);i++)
for(int d=0;d<coords.extent_int(1);d++)
centroid(0,d) += coords(i,d);

// take the average
for(int d=0;d<coords.extent_int(1);d++)
centroid(0,d) /= coords.extent(0);

Kokkos::parallel_for(coords.extent_int(0), KOKKOS_LAMBDA (int i) {
for(int d=0;d<coords.extent_int(1);d++)
l_centroid(0,d) += coords(i,d)/coords.extent(0);
});
Kokkos::fence();

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,10 @@ namespace panzer
using std::size_t;

// Get the PHX::Views of the field multipliers.
auto kokkosFieldMults_h = Kokkos::create_mirror_view(kokkosFieldMults_);
for (size_t i(0); i < fieldMults_.size(); ++i)
kokkosFieldMults_(i) = fieldMults_[i].get_static_view();
kokkosFieldMults_h(i) = fieldMults_[i].get_static_view();
Kokkos::deep_copy(kokkosFieldMults_, kokkosFieldMults_h);

// Determine the number of quadrature points and the dimensionality of the
// vector that we're integrating.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,10 @@ namespace panzer
using std::vector;

// Get the PHX::Views of the field multipliers.
auto kokkosFieldMults_h = Kokkos::create_mirror_view(kokkosFieldMults_);
for (size_t i(0); i < fieldMults_.size(); ++i)
kokkosFieldMults_(i) = fieldMults_[i].get_static_view();

kokkosFieldMults_h(i) = fieldMults_[i].get_static_view();
Kokkos::deep_copy(kokkosFieldMults_, kokkosFieldMults_h);
// Determine the index in the Workset bases for our particular basis
// name.
if (not useDescriptors_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,12 @@ evaluateFields(typename TRAITS::EvalData /* workset */)

for(std::size_t fieldIndex = 0; fieldIndex < inFields_.size(); ++fieldIndex) {

const PHX::MDField<const ScalarT>& inField = inFields_[fieldIndex];
const PHX::MDField<ScalarT>& outField = outFields_[fieldIndex];

const auto & inField_v = inFields_[fieldIndex].get_view();
const auto & outField_v = outFields_[fieldIndex].get_view();
auto inField = Kokkos::create_mirror_view(inField_v);
auto outField = Kokkos::create_mirror_view(outField_v);
Kokkos::deep_copy(inField, inField_v);

if(inField.size()>0) {

Expand Down Expand Up @@ -275,7 +279,7 @@ evaluateFields(typename TRAITS::EvalData /* workset */)
}

}

Kokkos::deep_copy(outField_v, outField);
}

//Irina TOFIX
Expand Down
1 change: 1 addition & 0 deletions packages/panzer/mini-em/example/BlockPrec/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Teuchos_StackedTimer.hpp"
#include "Teuchos_ScalarTraits.hpp"

#include "Kokkos_View_Fad.hpp"
#include "KokkosCompat_ClassicNodeAPI_Wrapper.hpp"

#include "Panzer_NodeType.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ template <typename EvalT,typename Traits>
void InversePermeability<EvalT,Traits>::evaluateFields(typename Traits::EvalData workset)
{
using panzer::index_t;

for (index_t cell = 0; cell < workset.num_cells; ++cell) {
for (int point = 0; point < permeability.extent_int(1); ++point) {
// const ScalarT& x = coords(cell,point,0);
// const ScalarT& y = coords(cell,point,1);
// const ScalarT& z = coords(cell,point,2);
permeability(cell,point) = 1.0/mu;
}
}
auto perm = permeability.get_static_view();
auto inv_mu = 1./mu;
Kokkos::parallel_for (workset.num_cells, KOKKOS_LAMBDA (int cell) {
for (int point = 0; point < perm.extent_int(1); ++point) {
// const ScalarT& x = coords(cell,point,0);
// const ScalarT& y = coords(cell,point,1);
// const ScalarT& z = coords(cell,point,2);
perm(cell,point) = inv_mu;
}
});
Kokkos::fence();
}

//**********************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,8 @@ template <typename EvalT,typename Traits>
void Permittivity<EvalT,Traits>::evaluateFields(typename Traits::EvalData workset)
{
using panzer::index_t;
Kokkos::deep_copy(permittivity.get_static_view(), epsilon);

for (index_t cell = 0; cell < workset.num_cells; ++cell) {
for (int point = 0; point < permittivity.extent_int(1); ++point) {
// const ScalarT& x = coords(cell,point,0);
// const ScalarT& y = coords(cell,point,1);
// const ScalarT& z = coords(cell,point,2);
permittivity(cell,point) = epsilon;
}
}
}

//**********************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,30 @@ void RandomForcing<EvalT,Traits>::evaluateFields(typename Traits::EvalData works
using panzer::index_t;

// double time = workset.time;

auto current_h = Kokkos::create_mirror_view(current.get_static_view());

if (ir_dim == 3) {
for (index_t cell = 0; cell < workset.num_cells; ++cell) {
for (int point = 0; point < current.extent_int(1); ++point) {
for (int point = 0; point < current_h.extent_int(1); ++point) {
// const ScalarT& x = coords(cell,point,0);
// const ScalarT& y = coords(cell,point,1);
// const ScalarT& z = coords(cell,point,2);
current(cell,point,0) = rangeMult_ * double(std::rand())/double(RAND_MAX) + rangeShift_;
current(cell,point,1) = rangeMult_ * double(std::rand())/double(RAND_MAX) + rangeShift_;
current(cell,point,2) = rangeMult_ * double(std::rand())/double(RAND_MAX) + rangeShift_;
current_h(cell,point,0) = rangeMult_ * double(std::rand())/double(RAND_MAX) + rangeShift_;
current_h(cell,point,1) = rangeMult_ * double(std::rand())/double(RAND_MAX) + rangeShift_;
current_h(cell,point,2) = rangeMult_ * double(std::rand())/double(RAND_MAX) + rangeShift_;
}
}
} else {
for (index_t cell = 0; cell < workset.num_cells; ++cell) {
for (int point = 0; point < current.extent_int(1); ++point) {
for (int point = 0; point < current_h.extent_int(1); ++point) {
// const ScalarT& x = coords(cell,point,0);
// const ScalarT& y = coords(cell,point,1);
current(cell,point,0) = rangeMult_ * double(std::rand())/double(RAND_MAX) + rangeShift_;
current(cell,point,1) = rangeMult_ * double(std::rand())/double(RAND_MAX) + rangeShift_;
current_h(cell,point,0) = rangeMult_ * double(std::rand())/double(RAND_MAX) + rangeShift_;
current_h(cell,point,1) = rangeMult_ * double(std::rand())/double(RAND_MAX) + rangeShift_;
}
}
}
Kokkos::deep_copy(current.get_static_view(), current_h);
}

//**********************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,40 @@ template <typename EvalT,typename Traits>
void TensorConductivity<EvalT,Traits>::evaluateFields(typename Traits::EvalData workset)
{
using panzer::index_t;

auto conductivity_h = Kokkos::create_mirror_view(conductivity.get_static_view());
if (ir_dim == 3) {
for (index_t cell = 0; cell < workset.num_cells; ++cell) {
for (int point = 0; point < conductivity.extent_int(1); ++point) {
for (int point = 0; point < conductivity_h.extent_int(1); ++point) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am missig somethign, but is there a reason not to run this code on device?

// const ScalarT& x = coords(cell,point,0);
// const ScalarT& y = coords(cell,point,1);
// const ScalarT& z = coords(cell,point,2);
conductivity(cell,point,0,0) = sigma * (1.0 + betax*betax);
conductivity(cell,point,0,1) = sigma * ( betax*betay - betaz);
conductivity(cell,point,0,2) = sigma * ( betax*betaz + betay);
conductivity_h(cell,point,0,0) = sigma * (1.0 + betax*betax);
conductivity_h(cell,point,0,1) = sigma * ( betax*betay - betaz);
conductivity_h(cell,point,0,2) = sigma * ( betax*betaz + betay);

conductivity(cell,point,1,0) = sigma * ( betay*betax + betaz);
conductivity(cell,point,1,1) = sigma * (1.0 + betay*betay);
conductivity(cell,point,1,2) = sigma * ( betay*betaz - betax);
conductivity_h(cell,point,1,0) = sigma * ( betay*betax + betaz);
conductivity_h(cell,point,1,1) = sigma * (1.0 + betay*betay);
conductivity_h(cell,point,1,2) = sigma * ( betay*betaz - betax);

conductivity(cell,point,2,0) = sigma * ( betaz*betax - betay);
conductivity(cell,point,2,1) = sigma * ( betaz*betay + betax);
conductivity(cell,point,2,2) = sigma * (1.0 + betaz*betaz);
conductivity_h(cell,point,2,0) = sigma * ( betaz*betax - betay);
conductivity_h(cell,point,2,1) = sigma * ( betaz*betay + betax);
conductivity_h(cell,point,2,2) = sigma * (1.0 + betaz*betaz);
}
}
} else {
for (index_t cell = 0; cell < workset.num_cells; ++cell) {
for (int point = 0; point < conductivity.extent_int(1); ++point) {
for (int point = 0; point < conductivity_h.extent_int(1); ++point) {
// const ScalarT& x = coords(cell,point,0);
// const ScalarT& y = coords(cell,point,1);
conductivity(cell,point,0,0) = sigma;
conductivity(cell,point,0,1) = 0.;
conductivity_h(cell,point,0,0) = sigma;
conductivity_h(cell,point,0,1) = 0.;

conductivity(cell,point,1,0) = 0.;
conductivity(cell,point,1,1) = sigma;
conductivity_h(cell,point,1,0) = 0.;
conductivity_h(cell,point,1,1) = sigma;
}
}
}
Kokkos::deep_copy(conductivity.get_static_view(), conductivity_h);
}

//**********************************************************************
Expand Down
Loading