Skip to content
Snippets Groups Projects
Unverified Commit dfc04ef0 authored by Dmitri Naumov's avatar Dmitri Naumov Committed by GitHub
Browse files

Merge pull request #2082 from endJunction/EnableExtrapolationInPetsc

Enable extrapolation in PETSc
parents ecafa757 99232bb1
No related branches found
No related tags found
No related merge requests found
...@@ -308,6 +308,8 @@ void finalizeAssembly(EigenMatrix& x) ...@@ -308,6 +308,8 @@ void finalizeAssembly(EigenMatrix& x)
x.getRawMatrix().makeCompressed(); x.getRawMatrix().makeCompressed();
} }
void finalizeAssembly(EigenVector& x) {}
} // namespace LinAlg } // namespace LinAlg
} // namespace MathLib } // namespace MathLib
......
...@@ -98,11 +98,8 @@ double norm(MatrixOrVector const& x, MathLib::VecNormType type) ...@@ -98,11 +98,8 @@ double norm(MatrixOrVector const& x, MathLib::VecNormType type)
} }
} }
template<typename Matrix> template <typename Matrix>
void finalizeAssembly(Matrix& /*A*/) void finalizeAssembly(Matrix& /*A*/);
{
// By default do nothing.
}
// Matrix and Vector // Matrix and Vector
...@@ -260,6 +257,7 @@ void matMultAdd(EigenMatrix const& A, EigenVector const& v1, ...@@ -260,6 +257,7 @@ void matMultAdd(EigenMatrix const& A, EigenVector const& v1,
EigenVector const& v2, EigenVector& v3); EigenVector const& v2, EigenVector& v3);
void finalizeAssembly(EigenMatrix& A); void finalizeAssembly(EigenMatrix& A);
void finalizeAssembly(EigenVector& A);
} // namespace LinAlg } // namespace LinAlg
......
...@@ -47,12 +47,39 @@ void LocalLinearLeastSquaresExtrapolator::extrapolate( ...@@ -47,12 +47,39 @@ void LocalLinearLeastSquaresExtrapolator::extrapolate(
{ {
auto const num_nodal_dof_result = auto const num_nodal_dof_result =
_dof_table_single_component.dofSizeWithoutGhosts() * num_components; _dof_table_single_component.dofSizeWithoutGhosts() * num_components;
std::vector<GlobalIndexType> ghost_indices;
{ // Create num_components times version of ghost_indices arranged by
// location. For example for 3 components and ghost_indices {5,6,10} we
// compute {15, 16, 17, 18, 19, 20, 30, 31, 32}.
auto const& single_component_ghost_indices =
_dof_table_single_component.getGhostIndices();
auto const single_component_ghost_indices_size =
single_component_ghost_indices.size();
ghost_indices.reserve(single_component_ghost_indices_size *
num_components);
for (unsigned i = 0; i < single_component_ghost_indices_size; ++i)
{
for (unsigned c = 0; c < num_components; ++c)
{
ghost_indices.push_back(
single_component_ghost_indices[i] * num_components + c);
}
}
}
if (!_nodal_values || if (!_nodal_values ||
static_cast<std::size_t>(_nodal_values->size()) != num_nodal_dof_result) #ifdef USE_PETSC
static_cast<std::size_t>(_nodal_values->getLocalSize() +
_nodal_values->getGhostSize())
#else
_nodal_values->size()
#endif
!= num_nodal_dof_result)
{ {
_nodal_values = MathLib::MatrixVectorTraits<GlobalVector>::newInstance( _nodal_values = MathLib::MatrixVectorTraits<GlobalVector>::newInstance(
MathLib::MatrixSpecifications{ {num_nodal_dof_result, num_nodal_dof_result, &ghost_indices,
num_nodal_dof_result, num_nodal_dof_result, nullptr, nullptr}); nullptr});
} }
_nodal_values->setZero(); _nodal_values->setZero();
...@@ -68,6 +95,7 @@ void LocalLinearLeastSquaresExtrapolator::extrapolate( ...@@ -68,6 +95,7 @@ void LocalLinearLeastSquaresExtrapolator::extrapolate(
extrapolateElement(i, num_components, extrapolatables, t, extrapolateElement(i, num_components, extrapolatables, t,
current_solution, dof_table, *counts); current_solution, dof_table, *counts);
} }
MathLib::LinAlg::finalizeAssembly(*_nodal_values);
MathLib::LinAlg::componentwiseDivide(*_nodal_values, *_nodal_values, MathLib::LinAlg::componentwiseDivide(*_nodal_values, *_nodal_values,
*counts); *counts);
...@@ -104,6 +132,7 @@ void LocalLinearLeastSquaresExtrapolator::calculateResiduals( ...@@ -104,6 +132,7 @@ void LocalLinearLeastSquaresExtrapolator::calculateResiduals(
calculateResidualElement(i, num_components, extrapolatables, t, calculateResidualElement(i, num_components, extrapolatables, t,
current_solution, dof_table); current_solution, dof_table);
} }
MathLib::LinAlg::finalizeAssembly(*_residuals);
} }
void LocalLinearLeastSquaresExtrapolator::extrapolateElement( void LocalLinearLeastSquaresExtrapolator::extrapolateElement(
...@@ -272,6 +301,8 @@ void LocalLinearLeastSquaresExtrapolator::calculateResidualElement( ...@@ -272,6 +301,8 @@ void LocalLinearLeastSquaresExtrapolator::calculateResidualElement(
auto const int_pt_vals_mat = auto const int_pt_vals_mat =
MathLib::toMatrix(int_pt_vals, num_components, num_int_pts); MathLib::toMatrix(int_pt_vals, num_components, num_int_pts);
MathLib::LinAlg::setLocalAccessibleVector(
*_nodal_values); // For access in the for-loop.
for (unsigned comp = 0; comp < num_components; ++comp) for (unsigned comp = 0; comp < num_components; ++comp)
{ {
// filter nodal values of the current element // filter nodal values of the current element
...@@ -279,7 +310,7 @@ void LocalLinearLeastSquaresExtrapolator::calculateResidualElement( ...@@ -279,7 +310,7 @@ void LocalLinearLeastSquaresExtrapolator::calculateResidualElement(
{ {
// TODO PETSc negative indices? // TODO PETSc negative indices?
auto const idx = num_components * global_indices[i] + comp; auto const idx = num_components * global_indices[i] + comp;
nodal_vals_element[i] = (*_nodal_values)[idx]; nodal_vals_element[i] = _nodal_values->get(idx);
} }
double const residual = (interpolation_matrix * nodal_vals_element - double const residual = (interpolation_matrix * nodal_vals_element -
......
...@@ -68,6 +68,9 @@ GlobalVector const& CachedSecondaryVariable::evalFieldNoArgs() const ...@@ -68,6 +68,9 @@ GlobalVector const& CachedSecondaryVariable::evalFieldNoArgs() const
1, *_extrapolatables, _t, *_current_solution, *_dof_table); 1, *_extrapolatables, _t, *_current_solution, *_dof_table);
auto const& nodal_values = _extrapolator.getNodalValues(); auto const& nodal_values = _extrapolator.getNodalValues();
MathLib::LinAlg::copy(nodal_values, _cached_nodal_values); MathLib::LinAlg::copy(nodal_values, _cached_nodal_values);
MathLib::LinAlg::setLocalAccessibleVector(
_cached_nodal_values); // For access in the getValue()
_needs_recomputation = false; _needs_recomputation = false;
return nodal_values; return nodal_values;
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ProcessOutput.h" #include "ProcessOutput.h"
#include "BaseLib/BuildInfo.h" #include "BaseLib/BuildInfo.h"
#include "MathLib/LinAlg/LinAlg.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "NumLib/DOF/LocalToGlobalIndexMap.h" #include "NumLib/DOF/LocalToGlobalIndexMap.h"
...@@ -27,7 +28,6 @@ static void addOgsVersion(MeshLib::Mesh& mesh) ...@@ -27,7 +28,6 @@ static void addOgsVersion(MeshLib::Mesh& mesh)
BaseLib::BuildInfo::ogs_version.end()); BaseLib::BuildInfo::ogs_version.end());
} }
#ifndef USE_PETSC // Not used in PETSc case
static void addSecondaryVariableNodes( static void addSecondaryVariableNodes(
double const t, double const t,
GlobalVector const& x, GlobalVector const& x,
...@@ -55,21 +55,22 @@ static void addSecondaryVariableNodes( ...@@ -55,21 +55,22 @@ static void addSecondaryVariableNodes(
std::unique_ptr<GlobalVector> result_cache; std::unique_ptr<GlobalVector> result_cache;
auto const& nodal_values = auto const& nodal_values =
var.fcts.eval_field(t, x, dof_table, result_cache); var.fcts.eval_field(t, x, dof_table, result_cache);
if (nodal_values_mesh.size() != #ifdef USE_PETSC
static_cast<std::size_t>(nodal_values.size())) std::size_t const global_vector_size =
nodal_values.getLocalSize() + nodal_values.getGhostSize();
#else
std::size_t const global_vector_size = nodal_values.size();
#endif
if (nodal_values_mesh.size() != global_vector_size)
{ {
OGS_FATAL( OGS_FATAL(
"Secondary variable `%s' did not evaluate to the right " "Secondary variable `%s' did not evaluate to the right "
"number of components. Expected: %d, actual: %d.", "number of components. Expected: %d, actual: %d.",
var.name.c_str(), nodal_values_mesh.size(), nodal_values.size()); var.name.c_str(), nodal_values_mesh.size(), global_vector_size);
} }
// Copy result // Copy result
for (GlobalIndexType i = 0; i < nodal_values.size(); ++i) nodal_values.copyValues(nodal_values_mesh);
{
assert(!std::isnan(nodal_values[i]));
nodal_values_mesh[i] = nodal_values[i];
}
} }
static void addSecondaryVariableResiduals( static void addSecondaryVariableResiduals(
...@@ -103,22 +104,23 @@ static void addSecondaryVariableResiduals( ...@@ -103,22 +104,23 @@ static void addSecondaryVariableResiduals(
std::unique_ptr<GlobalVector> result_cache; std::unique_ptr<GlobalVector> result_cache;
auto const& residuals = auto const& residuals =
var.fcts.eval_residuals(t, x, dof_table, result_cache); var.fcts.eval_residuals(t, x, dof_table, result_cache);
if (residuals_mesh.size() != static_cast<std::size_t>(residuals.size())) #ifdef USE_PETSC
std::size_t const global_vector_size =
residuals.getLocalSize() + residuals.getGhostSize();
#else
std::size_t const global_vector_size = residuals.size();
#endif
if (residuals_mesh.size() != global_vector_size)
{ {
OGS_FATAL( OGS_FATAL(
"The residual of secondary variable `%s' did not evaluate to the " "The residual of secondary variable `%s' did not evaluate to the "
"right number of components. Expected: %d, actual: %d.", "right number of components. Expected: %d, actual: %d.",
var.name.c_str(), residuals_mesh.size(), residuals.size()); var.name.c_str(), residuals_mesh.size(), global_vector_size);
} }
// Copy result // Copy result
for (GlobalIndexType i = 0; i < residuals.size(); ++i) residuals.copyValues(residuals_mesh);
{
assert(!std::isnan(residuals[i]));
residuals_mesh[i] = residuals[i];
}
} }
#endif // USE_PETSC
namespace ProcessLib namespace ProcessLib
{ {
...@@ -212,8 +214,6 @@ void processOutputData( ...@@ -212,8 +214,6 @@ void processOutputData(
} }
} }
#ifndef USE_PETSC
// Secondary variables output // Secondary variables output
for (auto const& external_variable_name : output_variables) for (auto const& external_variable_name : output_variables)
{ {
...@@ -234,11 +234,6 @@ void processOutputData( ...@@ -234,11 +234,6 @@ void processOutputData(
external_variable_name, mesh); external_variable_name, mesh);
} }
} }
#else
(void)mesh;
(void)secondary_variables;
(void)t;
#endif // USE_PETSC
addIntegrationPointWriter(mesh, integration_point_writer); addIntegrationPointWriter(mesh, integration_point_writer);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment