Skip to content

Commit

Permalink
got through issue #34 in responses
Browse files Browse the repository at this point in the history
thanks to @rppawlo for resolving
trilinos/Trilinos#1063 which made
this progress possible.
  • Loading branch information
ibaned committed Feb 15, 2017
1 parent 2eac39d commit c2bcef9
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager<Traits>& f
template<typename EvalT, typename Traits>
void FELIX::ResponseBoundarySquaredL2Norm<EvalT, Traits>::preEvaluate(typename Traits::PreEvalData workset)
{
PHAL::set(this->global_response, 0.0);
PHAL::set(this->global_response_eval, 0.0);

p_reg = 0;

Expand All @@ -98,7 +98,7 @@ void FELIX::ResponseBoundarySquaredL2Norm<EvalT, Traits>::evaluateFields(typenam
"Side sets defined in input file but not properly specified on the mesh" << std::endl);

// Zero out local response
PHAL::set(this->local_response, 0.0);
PHAL::set(this->local_response_eval, 0.0);

// ----------------- Surface side ---------------- //

Expand Down
2 changes: 1 addition & 1 deletion src/FELIX/evaluators/FELIX_ResponseSMBMismatch_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void FELIX::ResponseSMBMismatch<EvalT, Traits>::postRegistrationSetup(typename T
// **********************************************************************
template<typename EvalT, typename Traits>
void FELIX::ResponseSMBMismatch<EvalT, Traits>::preEvaluate(typename Traits::PreEvalData workset) {
PHAL::set(this->global_response, 0.0);
PHAL::set(this->global_response_eval, 0.0);

p_resp = p_reg = p_misH =0;

Expand Down
6 changes: 3 additions & 3 deletions src/evaluators/PHAL_ResponseFieldIntegralT_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ template<typename EvalT, typename Traits>
void PHAL::ResponseFieldIntegralT<EvalT, Traits>::
preEvaluate(typename Traits::PreEvalData workset)
{
PHAL::set(this->global_response, 0.0);
PHAL::set(this->global_response_eval, 0.0);
// Do global initialization
PHAL::SeparableScatterScalarResponseT<EvalT,Traits>::preEvaluate(workset);
}
Expand All @@ -179,7 +179,7 @@ void PHAL::ResponseFieldIntegralT<EvalT, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
// Zero out local response
PHAL::set(this->local_response, 0.0);
PHAL::set(this->local_response_eval, 0.0);

if( ebNames.size() == 0 ||
std::find(ebNames.begin(), ebNames.end(), workset.EBName) != ebNames.end() ) {
Expand Down Expand Up @@ -232,7 +232,7 @@ void PHAL::ResponseFieldIntegralT<EvalT, Traits>::
postEvaluate(typename Traits::PostEvalData workset)
{
PHAL::reduceAll<ScalarT>(*workset.comm, Teuchos::REDUCE_SUM,
this->global_response);
this->global_response_eval);
PHAL::SeparableScatterScalarResponseT<EvalT,Traits>::postEvaluate(workset);
}

Expand Down
6 changes: 3 additions & 3 deletions src/evaluators/PHAL_ResponseFieldIntegral_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ template<typename EvalT, typename Traits>
void PHAL::ResponseFieldIntegral<EvalT, Traits>::
preEvaluate(typename Traits::PreEvalData workset)
{
PHAL::set(this->global_response, 0.0);
PHAL::set(this->global_response_eval, 0.0);
// Do global initialization
PHAL::SeparableScatterScalarResponse<EvalT,Traits>::preEvaluate(workset);
}
Expand All @@ -178,7 +178,7 @@ void PHAL::ResponseFieldIntegral<EvalT, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
// Zero out local response
PHAL::set(this->local_response, 0.0);
PHAL::set(this->local_response_eval, 0.0);

if( ebNames.size() == 0 ||
std::find(ebNames.begin(), ebNames.end(), workset.EBName) != ebNames.end() ) {
Expand Down Expand Up @@ -231,7 +231,7 @@ void PHAL::ResponseFieldIntegral<EvalT, Traits>::
postEvaluate(typename Traits::PostEvalData workset)
{
PHAL::reduceAll<ScalarT>(*workset.comm, Teuchos::REDUCE_SUM,
this->global_response);
this->global_response_eval);
// Do global scattering
PHAL::SeparableScatterScalarResponse<EvalT,Traits>::postEvaluate(workset);
}
Expand Down
10 changes: 5 additions & 5 deletions src/evaluators/PHAL_ResponseSquaredL2ErrorSide_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager<Traits>& f
template<typename EvalT, typename Traits, typename TargetScalarT>
void PHAL::ResponseSquaredL2ErrorSideBase<EvalT, Traits, TargetScalarT>::preEvaluate(typename Traits::PreEvalData workset)
{
PHAL::set(this->global_response, 0.0);
PHAL::set(this->global_response_eval, 0.0);

// Do global initialization
PHAL::SeparableScatterScalarResponse<EvalT, Traits>::preEvaluate(workset);
Expand All @@ -104,7 +104,7 @@ void PHAL::ResponseSquaredL2ErrorSideBase<EvalT, Traits, TargetScalarT>::evaluat
"Side sets defined in input file but not properly specified on the mesh" << std::endl);

// Zero out local response
PHAL::set(this->local_response, 0.0);
PHAL::set(this->local_response_eval, 0.0);

if (workset.sideSets->find(sideSetName) != workset.sideSets->end())
{
Expand Down Expand Up @@ -133,8 +133,8 @@ void PHAL::ResponseSquaredL2ErrorSideBase<EvalT, Traits, TargetScalarT>::evaluat
sum += sq * w_measure(cell,side,qp);
}

this->local_response(cell, 0) += sum*scaling;
this->global_response(0) += sum*scaling;
this->local_response_eval(cell, 0) += sum*scaling;
this->global_response_eval(0) += sum*scaling;
}
}

Expand All @@ -146,7 +146,7 @@ void PHAL::ResponseSquaredL2ErrorSideBase<EvalT, Traits, TargetScalarT>::evaluat
template<typename EvalT, typename Traits, typename TargetScalarT>
void PHAL::ResponseSquaredL2ErrorSideBase<EvalT, Traits, TargetScalarT>::postEvaluate(typename Traits::PostEvalData workset)
{
PHAL::reduceAll<ScalarT>(*workset.comm, Teuchos::REDUCE_SUM, this->global_response);
PHAL::reduceAll<ScalarT>(*workset.comm, Teuchos::REDUCE_SUM, this->global_response_eval);

if(workset.comm->getRank()==0)
std::cout << "resp: " << Sacado::ScalarValue<ScalarT>::eval(this->global_response(0)) << "\n" << std::flush;
Expand Down
10 changes: 5 additions & 5 deletions src/evaluators/PHAL_ResponseSquaredL2Error_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager<Traits>& f
template<typename EvalT, typename Traits, typename TargetScalarT>
void PHAL::ResponseSquaredL2ErrorBase<EvalT, Traits, TargetScalarT>::preEvaluate(typename Traits::PreEvalData workset)
{
PHAL::set(this->global_response, 0.0);
PHAL::set(this->global_response_eval, 0.0);

// Do global initialization
PHAL::SeparableScatterScalarResponse<EvalT, Traits>::preEvaluate(workset);
Expand All @@ -96,7 +96,7 @@ template<typename EvalT, typename Traits, typename TargetScalarT>
void PHAL::ResponseSquaredL2ErrorBase<EvalT, Traits, TargetScalarT>::evaluateFields(typename Traits::EvalData workset)
{
// Zero out local response
PHAL::set(this->local_response, 0.0);
PHAL::set(this->local_response_eval, 0.0);

for (int cell=0; cell<workset.numCells; ++cell)
{
Expand All @@ -118,8 +118,8 @@ void PHAL::ResponseSquaredL2ErrorBase<EvalT, Traits, TargetScalarT>::evaluateFie
sum += sq * w_measure(cell,qp);
}

this->local_response(cell, 0) += sum*scaling;
this->global_response(0) += sum*scaling;
this->local_response_eval(cell, 0) += sum*scaling;
this->global_response_eval(0) += sum*scaling;
}

// Do any local-scattering necessary
Expand All @@ -130,7 +130,7 @@ void PHAL::ResponseSquaredL2ErrorBase<EvalT, Traits, TargetScalarT>::evaluateFie
template<typename EvalT, typename Traits, typename TargetScalarT>
void PHAL::ResponseSquaredL2ErrorBase<EvalT, Traits, TargetScalarT>::postEvaluate(typename Traits::PostEvalData workset)
{
PHAL::reduceAll<ScalarT>(*workset.comm, Teuchos::REDUCE_SUM, this->global_response);
PHAL::reduceAll<ScalarT>(*workset.comm, Teuchos::REDUCE_SUM, this->global_response_eval);

if(workset.comm->getRank()==0)
std::cout << "resp: " << Sacado::ScalarValue<ScalarT>::eval(this->global_response(0)) << "\n" << std::flush;
Expand Down
10 changes: 5 additions & 5 deletions src/evaluators/PHAL_ResponseThermalEnergyT_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ template<typename EvalT, typename Traits>
void PHAL::ResponseThermalEnergyT<EvalT, Traits>::
preEvaluate(typename Traits::PreEvalData workset)
{
PHAL::set(this->global_response, 0.0);
PHAL::set(this->global_response_eval, 0.0);
// Do global initialization
PHAL::SeparableScatterScalarResponseT<EvalT,Traits>::preEvaluate(workset);
}
Expand All @@ -115,16 +115,16 @@ void PHAL::ResponseThermalEnergyT<EvalT, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
// Zero out local response
PHAL::set(this->local_response, 0.0);
PHAL::set(this->local_response_eval, 0.0);

ScalarT s;
for (std::size_t cell = 0; cell < workset.numCells; ++cell)
{
for (std::size_t qp = 0; qp < numQPs; ++qp)
{
s = density * heat_capacity * field(cell, qp) * weights(cell, qp);
this->local_response(cell, 0) += s;
this->global_response(0) += s;
this->local_response_eval(cell, 0) += s;
this->global_response_eval(0) += s;
}
}

Expand All @@ -138,7 +138,7 @@ void PHAL::ResponseThermalEnergyT<EvalT, Traits>::
postEvaluate(typename Traits::PostEvalData workset)
{
PHAL::reduceAll<ScalarT>(*workset.comm, Teuchos::REDUCE_SUM,
this->global_response);
this->global_response_eval);
PHAL::SeparableScatterScalarResponseT<EvalT,Traits>::postEvaluate(workset);
}

Expand Down
3 changes: 1 addition & 2 deletions src/evaluators/PHAL_ScatterScalarResponse_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ setup(const Teuchos::ParameterList& p, const Teuchos::RCP<Albany::Layouts>& dl)
// Setup fields we require
auto global_response_tag =
p.get<PHX::Tag<ScalarT> >("Global Response Field Tag");
global_response = PHX::MDField<ScalarT>(global_response_tag);
global_response = decltype(global_response)(global_response_tag);
if (stand_alone) {
this->addDependentField(global_response);
Expand Down Expand Up @@ -130,7 +129,7 @@ postEvaluate(typename Traits::PostEvalData workset)
Teuchos::RCP<Tpetra_MultiVector> gpT = workset.dgdpT;
for (PHAL::MDFieldIterator<const ScalarT> gr(this->global_response);
! gr.done(); ++gr) {
typename PHAL::Ref<ScalarT>::type val = *gr;
auto val = *gr;
const int res = gr.idx();
if (gT != Teuchos::null){
Teuchos::ArrayRCP<ST> gT_nonconstView = gT->get1dViewNonConst();
Expand Down
1 change: 1 addition & 0 deletions src/evaluators/PHAL_SeparableScatterScalarResponse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SeparableScatterScalarResponseBase
protected:

typedef typename EvalT::ScalarT ScalarT;
bool stand_alone;
PHX::MDField<const ScalarT> local_response;
PHX::MDField<ScalarT> local_response_eval;
};
Expand Down
3 changes: 1 addition & 2 deletions src/evaluators/PHAL_SeparableScatterScalarResponseT_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ setup(const Teuchos::ParameterList& p, const Teuchos::RCP<Albany::Layouts>& dl)
// Setup fields we require
auto local_response_tag =
p.get<PHX::Tag<ScalarT> >("Local Response Field Tag");
local_response = decltype(local_response)(
local_response_tag.name(), local_response_tag.dataLayout());
local_response = decltype(local_response)(local_response_tag);
if (stand_alone) {
this->addDependentField(local_response);
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/evaluators/PHAL_SeparableScatterScalarResponse_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ void
SeparableScatterScalarResponseBase<EvalT, Traits>::
setup(const Teuchos::ParameterList& p, const Teuchos::RCP<Albany::Layouts>& dl)
{
stand_alone = p.get<bool>("Stand-alone Evaluator");
this->stand_alone = p.get<bool>("Stand-alone Evaluator");

// Setup fields we require
auto local_response_tag =
p.get<PHX::Tag<ScalarT> >("Local Response Field Tag");
local_response = decltype(local_response)(local_response_tag);
if (stand_alone) {
if (this->stand_alone) {
this->addDependentField(local_response);
} else {
local_response_eval = decltype(local_response_eval)(local_response_tag);
Expand Down Expand Up @@ -111,7 +111,7 @@ evaluateFields(typename Traits::EvalData workset)
// Loop over responses

for (std::size_t res = 0; res < this->global_response.size(); res++) {
typename PHAL::Ref<ScalarT>::type val = this->local_response(cell, res);
auto val = this->local_response(cell, res);

// Loop over nodes in cell
for (unsigned int node_dof=0; node_dof<numNodes; node_dof++) {
Expand Down Expand Up @@ -174,7 +174,7 @@ evaluate2DFieldsDerivativesDueToExtrudedSolution(typename Traits::EvalData works

const Teuchos::ArrayRCP<GO>& elNodeID = wsElNodeID[elem_LID];
for (std::size_t res = 0; res < this->global_response.size(); res++) {
typename PHAL::Ref<ScalarT>::type val = this->local_response(elem_LID, res);
auto val = this->local_response(elem_LID, res);
LO base_id, ilayer;
for (int i = 0; i < numSideNodes; ++i) {
std::size_t node = side.node[i];
Expand Down Expand Up @@ -202,7 +202,7 @@ postEvaluate(typename Traits::PostEvalData workset)
Teuchos::RCP<Tpetra_Vector> gT = workset.gT;
if (gT != Teuchos::null) {
Teuchos::ArrayRCP<ST> gT_nonconstView = gT->get1dViewNonConst();
for (PHAL::MDFieldIterator<ScalarT> gr(this->global_response);
for (PHAL::MDFieldIterator<const ScalarT> gr(this->global_response);
! gr.done(); ++gr)
gT_nonconstView[gr.idx()] = gr.ref().val();
}
Expand Down
18 changes: 9 additions & 9 deletions src/evaluators/QCAD_ResponseCenterOfMass_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void QCAD::ResponseCenterOfMass<EvalT, Traits>::
preEvaluate(typename Traits::PreEvalData workset)
{
// Zero out global response
PHAL::set(this->global_response, 0.0);
PHAL::set(this->global_response_eval, 0.0);

// Do global initialization
PHAL::SeparableScatterScalarResponse<EvalT,Traits>::preEvaluate(workset);
Expand All @@ -111,7 +111,7 @@ void QCAD::ResponseCenterOfMass<EvalT, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
// Zero out local response
PHAL::set(this->local_response, 0.0);
PHAL::set(this->local_response_eval, 0.0);

ScalarT integral, moment;

Expand All @@ -125,13 +125,13 @@ evaluateFields(typename Traits::EvalData workset)
// Add to running total volume and mass moment
for (std::size_t qp=0; qp < numQPs; ++qp) {
integral = field(cell,qp) * weights(cell,qp);
this->local_response(cell,3) += integral;
this->global_response(3) += integral;
this->local_response_eval(cell,3) += integral;
this->global_response_eval(3) += integral;

for(std::size_t i=0; i<numDims && i<3; i++) {
moment = field(cell,qp) * weights(cell,qp) * coordVec(cell,qp,i);
this->local_response(cell,i) += moment;
this->global_response(i) += moment;
this->local_response_eval(cell,i) += moment;
this->global_response_eval(i) += moment;
}
}

Expand All @@ -146,15 +146,15 @@ template<typename EvalT, typename Traits>
void QCAD::ResponseCenterOfMass<EvalT, Traits>::
postEvaluate(typename Traits::PostEvalData workset)
{
PHAL::reduceAll(*workset.comm, Teuchos::REDUCE_SUM, this->global_response);
PHAL::reduceAll(*workset.comm, Teuchos::REDUCE_SUM, this->global_response_eval);

int iNormalizer = 3;
if( fabs(this->global_response(iNormalizer)) > 1e-9 ) {
for( int i=0; i < this->global_response.size(); i++) {
if( i == iNormalizer ) continue;
this->global_response(i) /= this->global_response(iNormalizer);
this->global_response_eval(i) /= this->global_response_eval(iNormalizer);
}
this->global_response(iNormalizer) = 1.0;
this->global_response_eval(iNormalizer) = 1.0;
}

// Do global scattering
Expand Down
18 changes: 9 additions & 9 deletions src/evaluators/QCAD_ResponseFieldAverage_Def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void QCAD::ResponseFieldAverage<EvalT, Traits>::
preEvaluate(typename Traits::PreEvalData workset)
{
// Zero out global response
PHAL::set(this->global_response, 0.0);
PHAL::set(this->global_response_eval, 0.0);

// Do global initialization
PHAL::SeparableScatterScalarResponse<EvalT,Traits>::preEvaluate(workset);
Expand All @@ -111,7 +111,7 @@ void QCAD::ResponseFieldAverage<EvalT, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
// Zero out local response
PHAL::set(this->local_response, 0.0);
PHAL::set(this->local_response_eval, 0.0);

ScalarT t;

Expand All @@ -125,12 +125,12 @@ evaluateFields(typename Traits::EvalData workset)
// Add to running total volume and field integral
for (std::size_t qp=0; qp < numQPs; ++qp) {
t = field(cell,qp) * weights(cell,qp); //component of integrated field
this->local_response(cell,0) += t;
this->global_response(0) += t;
this->local_response_eval(cell,0) += t;
this->global_response_eval(0) += t;

t = weights(cell,qp); //component of integrated volume
this->local_response(cell,1) += t;
this->global_response(1) += t;
this->local_response_eval(cell,1) += t;
this->global_response_eval(1) += t;
}

}
Expand All @@ -144,13 +144,13 @@ template<typename EvalT, typename Traits>
void QCAD::ResponseFieldAverage<EvalT, Traits>::
postEvaluate(typename Traits::PostEvalData workset)
{
PHAL::reduceAll(*workset.comm, Teuchos::REDUCE_SUM, this->global_response);
PHAL::reduceAll(*workset.comm, Teuchos::REDUCE_SUM, this->global_response_eval);

int iNormalizer = 1;
if( fabs(this->global_response(iNormalizer)) > 1e-9 ) {
if( fabs(this->global_response_eval(iNormalizer)) > 1e-9 ) {
for( int i=0; i < this->global_response.size(); i++) {
if( i == iNormalizer ) continue;
this->global_response(i) /= this->global_response(iNormalizer);
this->global_response_eval(i) /= this->global_response_eval(iNormalizer);
}
}

Expand Down
Loading

0 comments on commit c2bcef9

Please sign in to comment.