void ThermoMechanicalCoefficients<EvalT, Traits>::
evaluateFields(typename Traits::EvalData workset)
{
  Intrepid2::Tensor<ScalarT> diffusivity(num_dims_);
  Intrepid2::Tensor<ScalarT> I(Intrepid2::eye<ScalarT>(num_dims_));
  Intrepid2::Tensor<ScalarT> tensor;
  Intrepid2::Tensor<ScalarT> F(num_dims_);

  ScalarT dt = delta_time_(0);
  if (dt == 0.0) dt = 1.e-15;
  Albany::MDArray temperature_old = (*workset.stateArrayPtr)[temperature_name_];
  for (int cell = 0; cell < workset.numCells; ++cell) {
    for (int pt = 0; pt < num_pts_; ++pt) {
      temperature_dot_(cell,pt) =
        (temperature_(cell,pt) - temperature_old(cell,pt)) / dt;
    }
  }

  if (have_mech_) {
    for (int cell = 0; cell < workset.numCells; ++cell) {
      for (int pt = 0; pt < num_pts_; ++pt) {
        F.fill(def_grad_,cell, pt,0,0);
        tensor = Intrepid2::inverse(Intrepid2::transpose(F) * F);
        thermal_transient_coeff_(cell, pt) = transient_coeff_;
        diffusivity = thermal_cond_(cell, pt) / (density_ * heat_capacity_)
            * tensor;
        for (int i = 0; i < num_dims_; ++i) {
          for (int j = 0; j < num_dims_; ++j) {
            thermal_diffusivity_(cell, pt, i, j) = diffusivity(i, j);
          }
        }
      }
    }
  } else {
    for (int cell = 0; cell < workset.numCells; ++cell) {
      for (int pt = 0; pt < num_pts_; ++pt) {
        thermal_transient_coeff_(cell, pt) = transient_coeff_;
        diffusivity = thermal_cond_(cell, pt) / (density_ * heat_capacity_) * I;
        for (int i = 0; i < num_dims_; ++i) {
          for (int j = 0; j < num_dims_; ++j) {
            thermal_diffusivity_(cell, pt, i, j) = diffusivity(i, j);
          }
        }
      }
    }
  }
}
void
ThermoMechanicalCoefficients<EvalT, Traits>::evaluateFields(
    typename Traits::EvalData workset)
{
  if (SolutionType_ == "Continuation") {
    Albany::MDArray const temperature_old =
        (*workset.stateArrayPtr)[temperature_name_];

    ScalarT dt = delta_time_(0);

    if (dt == 0.0) {
      // Initially, transfer the derivatives of temperature_ to the
      // derivatives of temperature_dot_
      dt = 1.0;
    }

    for (int cell = 0; cell < workset.numCells; ++cell) {
      for (int pt = 0; pt < num_pts_; ++pt) {
        temperature_dot_(cell, pt) =
            (temperature_(cell, pt) - temperature_old(cell, pt)) / dt;
      }
    }
  }

  if (have_mech_) {
    for (int cell = 0; cell < workset.numCells; ++cell) {
      for (int pt = 0; pt < num_pts_; ++pt) {
        minitensor::Tensor<ScalarT> F(num_dims_);

        F.fill(def_grad_, cell, pt, 0, 0);

        minitensor::Tensor<ScalarT> tensor =
            minitensor::inverse(minitensor::transpose(F) * F);

        thermal_transient_coeff_(cell, pt) = transient_coeff_;

        minitensor::Tensor<ScalarT> diffusivity =
            thermal_cond_(cell, pt) / (density_ * heat_capacity_) * tensor;

        for (int i = 0; i < num_dims_; ++i) {
          for (int j = 0; j < num_dims_; ++j) {
            thermal_diffusivity_(cell, pt, i, j) = diffusivity(i, j);
          }
        }
      }
    }
  } else {
    for (int cell = 0; cell < workset.numCells; ++cell) {
      for (int pt = 0; pt < num_pts_; ++pt) {
        thermal_transient_coeff_(cell, pt) = transient_coeff_;

        minitensor::Tensor<RealType> I(minitensor::eye<RealType>(num_dims_));

        minitensor::Tensor<ScalarT> diffusivity =
            thermal_cond_(cell, pt) / (density_ * heat_capacity_) * I;

        for (int i = 0; i < num_dims_; ++i) {
          for (int j = 0; j < num_dims_; ++j) {
            thermal_diffusivity_(cell, pt, i, j) = diffusivity(i, j);
          }
        }
      }
    }
  }
}