Skip to content

Commit

Permalink
Code review part III
Browse files Browse the repository at this point in the history
  • Loading branch information
henrij22 committed Jan 17, 2025
1 parent 28c68d3 commit 2e7e11f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
1 change: 0 additions & 1 deletion ikarus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ file(
CONFIGURE_DEPENDS *.cpp
)


dune_enable_all_packages()
dune_add_library(
${PROJECT_NAME}
Expand Down
12 changes: 7 additions & 5 deletions ikarus/io/resultevaluators.hh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct PrincipalStress
const int comp) const {
auto mat = fromVoigt(resultArray, false);
Eigen::SelfAdjointEigenSolver<decltype(mat)> eigensolver(mat, Eigen::EigenvaluesOnly);
return eigensolver.eigenvalues()[dim - 1 - comp];
return eigensolver.eigenvalues().reverse()[comp];
}

/**
Expand Down Expand Up @@ -164,9 +164,9 @@ struct Triaxiality
};

/**
* \brief Struct for calculating the 2d polar stress. The center of the coordinate system is chosen to be the center of
* the corresponding reference geometry.
\ingroup resultevaluators
* \brief Struct for calculating the 2d polar stress. The center of the coordinate system is to be passed to the
* evaluator.
* \ingroup resultevaluators
*/
struct PolarStress
{
Expand Down Expand Up @@ -200,8 +200,10 @@ struct PolarStress
return polarStress(0, 0);
case 1:
return polarStress(1, 1);
default: // 2
case 2:
return polarStress(1, 0);
default:
__builtin_unreachable();
}
}

Expand Down
61 changes: 33 additions & 28 deletions ikarus/io/resultfunction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ namespace Impl {
* \tparam R Type of the matrix
* \return the result
*/
template <typename R>
double operator()(const R& resultArray, const auto& pos, const auto& fe, const int comp) const {};
template <typename R, typename FiniteElement, int dim>
double operator()(const R& resultArray, const Dune::FieldVector<double, dim>& pos, const FiniteElement& fe,
const int comp) const {
return resultArray[comp];
};
};
} // namespace Impl

Expand Down Expand Up @@ -101,7 +104,7 @@ public:
}

/**
* \brief Get the name of the result type.P
* \brief Get the name of the result type.
* \details
* This function is required by the Dune::VTKFunction interface.
*
Expand All @@ -127,14 +130,14 @@ public:
/**
* \brief Construct a new Result Function object
*
* \tparam Args Type of additional arguments passed to the user function
* \tparam UF Type of the user function
* \param assembler shared pointer to the underlying assembler (provides the finite elements and the requested
* results)
* \param prec (optional) specify the used precision (only has an effect when using resultfunciton with
* Dune::VTK::VTKWriter)
* \param userFunction the user function (default is DefaultUserFunction)
*/
template <typename UF>
template <typename UF = UserFunction>
ResultFunction(std::shared_ptr<Assembler> assembler, Dune::VTK::Precision prec = Dune::VTK::Precision::float64,
UF&& userFunction = {})
: assembler_(assembler),
Expand All @@ -146,10 +149,7 @@ private:
const auto& fe = finiteElements().at(eleID);
auto result = fe.template calculateAt<RT>(requirement(), local).asVec();

if constexpr (!std::is_same_v<UserFunction, Impl::DefaultUserFunction>) {
return userFunction_(result, local, fe, comp);
} else
return result(comp);
return userFunction_(result, local, fe, comp);
}

const FEContainer& finiteElements() const { return assembler_->finiteElements(); }
Expand All @@ -166,15 +166,17 @@ private:
* \brief Function to create a ResultFunction as a shared_ptr
* \details
* Constructs a ResultFunction object with given assembler as shared_ptr to be used with the native Dune VTKWriter
*
* \param assembler shared pointer to the underlying assembler (provides the finite elements and the requested
* results) \tparam AS type of the assembler \tparam RT requested result type \tparam UserFunction Type of the
* user-defined function for custom result evaluation (default is DefaultUserFunction) \param assembler shared pointer
* to the underlying assembler (provides the finite elements and the requested results) \param prec (optional) specify
* the used precision \param userFunction (optional) the user function (default is DefaultUserFunction)
* results)
* \tparam AS type of the assembler
* \tparam RT requested result type
* \tparam UserFunction Type of the user-defined function for custom result evaluation (default is DefaultUserFunction)
* \param assembler shared pointer to the underlying assembler (provides the finite elements and the requested results)
* \param prec (optional) specify the used precision
* \param userFunction (optional) the user function (default is DefaultUserFunction)
*/
template <template <typename, int, int> class RT, typename UserFunction = Impl::DefaultUserFunction,
Concepts::FlatAssembler AS, typename... Args>
Concepts::FlatAssembler AS>
auto makeResultFunction(std::shared_ptr<AS> assembler, Dune::VTK::Precision prec = Dune::VTK::Precision::float64,
UserFunction&& userFunction = {}) {
return std::make_shared<ResultFunction<AS, RT, UserFunction>>(assembler, prec,
Expand All @@ -185,32 +187,35 @@ auto makeResultFunction(std::shared_ptr<AS> assembler, Dune::VTK::Precision prec
* \brief Function to create a ResultFunction as a shared_ptr
* \details
* Constructs a ResultFunction object with given assembler as shared_ptr to be used with the native Dune VTKWriter
*
* \param assembler shared pointer to the underlying assembler (provides the finite elements and the requested
* results) \tparam AS type of the assembler \tparam RT requested result type \tparam UserFunction Type of the
* user-defined function for custom result evaluation \param assembler shared pointer to the underlying assembler
* (provides the finite elements and the requested results) \param userFunction the user function
* \tparam AS type of the assembler
* \tparam RT requested result type
* \tparam UserFunction Type of the user-defined function for custom result evaluation (default is DefaultUserFunction)
* \param assembler shared pointer to the underlying assembler (provides the finite elements and the requested results)
* \param userFunction the user function
*/
template <template <typename, int, int> class RT, typename UserFunction = Impl::DefaultUserFunction,
Concepts::FlatAssembler AS, typename... Args>
template <template <typename, int, int> class RT, typename UserFunction, Concepts::FlatAssembler AS>
auto makeResultFunction(std::shared_ptr<AS> assembler, UserFunction&& userFunction) {
return makeResultFunction<RT>(assembler, Dune::VTK::Precision::float64, std::forward<UserFunction>(userFunction));
}

/**
* \brief Function to create a ResultFunction as a gridfunction that can be used with dune-vtk
* \details
* Constructs a ResultFunction object with given assembler as a VTK::Function to be used withdune-vtk It is possible
* to construct a localFunction from this as follows \code auto localResultFunction =
* localFunction(vtkResultFunction); localResultFunction.bind(element); \endcode \tparam AS type of the assembler
* Constructs a ResultFunction object with given finite elements, ferequirements as a VTK::Function to be used with
* dune-vtk It is possible to construct a localFunction from this as follows
* \code
* auto localResultFunction = localFunction(vtkResultFunction);
* localResultFunction.bind(element);
* \endcode
* \tparam AS type of the assembler
* \tparam RT requested result type
* \tparam UserFunction Type of the user-defined function for custom result evaluation (default is
* DefaultUserFunction)
* \param assembler shared pointer to the underlying assembler (provides the finite elements and the requested
* results) \param userFunction the user function (default is DefaultUserFunction)
* \param userFunction (optional) the user function (default is DefaultUserFunction)
* \param assembler shared pointer to the underlying assembler (provides the finite elements and the requested results)
*/
template <template <typename, int, int> class RT, typename UserFunction = Impl::DefaultUserFunction,
Concepts::FlatAssembler AS, typename... Args>
Concepts::FlatAssembler AS>
auto makeResultVtkFunction(std::shared_ptr<AS> assembler, UserFunction&& userFunction = {}) {
return Dune::Vtk::Function<typename AS::GridView>(std::make_shared<ResultFunction<AS, RT, UserFunction>>(
assembler, Dune::VTK::Precision::float64, std::forward<UserFunction>(userFunction)));
Expand Down

0 comments on commit 2e7e11f

Please sign in to comment.