Skip to content
Snippets Groups Projects
Commit 1d495b6b authored by Elias Pipping's avatar Elias Pipping Committed by Elias Pipping
Browse files

Use shared pointers to avoid copying

parent e19e8a1c
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,8 @@ template <int dim, class OuterFunctionType> ...@@ -17,7 +17,8 @@ template <int dim, class OuterFunctionType>
class GlobalLaursenNonlinearity : public GlobalNonlinearity<dim> { class GlobalLaursenNonlinearity : public GlobalNonlinearity<dim> {
public: public:
GlobalLaursenNonlinearity( GlobalLaursenNonlinearity(
std::vector<double> const &mu, std::vector<double> const &normalStress, shared_ptr<std::vector<double> const> mu,
shared_ptr<std::vector<double> const> normalStress,
std::vector<FieldVector<double, 1>> const &nodalIntegrals) std::vector<FieldVector<double, 1>> const &nodalIntegrals)
: mu(mu), normalStress(normalStress), nodalIntegrals(nodalIntegrals) {} : mu(mu), normalStress(normalStress), nodalIntegrals(nodalIntegrals) {}
...@@ -37,8 +38,8 @@ class GlobalLaursenNonlinearity : public GlobalNonlinearity<dim> { ...@@ -37,8 +38,8 @@ class GlobalLaursenNonlinearity : public GlobalNonlinearity<dim> {
*/ */
virtual shared_ptr<LocalNonlinearity<dim> const> restriction(int i) const { virtual shared_ptr<LocalNonlinearity<dim> const> restriction(int i) const {
double coefficient = nodalIntegrals[i][0]; double coefficient = nodalIntegrals[i][0];
coefficient *= normalStress[i]; coefficient *= (*normalStress)[i];
coefficient *= 1 + mu[i]; coefficient *= 1 + (*mu)[i];
shared_ptr<NiceFunction const> const func( shared_ptr<NiceFunction const> const func(
new OuterFunctionType(coefficient)); new OuterFunctionType(coefficient));
...@@ -49,8 +50,8 @@ class GlobalLaursenNonlinearity : public GlobalNonlinearity<dim> { ...@@ -49,8 +50,8 @@ class GlobalLaursenNonlinearity : public GlobalNonlinearity<dim> {
private: private:
// TODO: If we're clever, we only store one vector with the precomputed // TODO: If we're clever, we only store one vector with the precomputed
// results // results
std::vector<double> mu; shared_ptr<std::vector<double> const> mu;
std::vector<double> normalStress; shared_ptr<std::vector<double> const> normalStress;
std::vector<FieldVector<double, 1>> nodalIntegrals; std::vector<FieldVector<double, 1>> nodalIntegrals;
}; };
} }
......
...@@ -17,8 +17,10 @@ class GlobalRuinaNonlinearity : public GlobalNonlinearity<dim> { ...@@ -17,8 +17,10 @@ class GlobalRuinaNonlinearity : public GlobalNonlinearity<dim> {
public: public:
GlobalRuinaNonlinearity( GlobalRuinaNonlinearity(
std::vector<FieldVector<double, 1>> const &nodalIntegrals, std::vector<FieldVector<double, 1>> const &nodalIntegrals,
std::vector<double> const &a, std::vector<double> const &mu, shared_ptr<std::vector<double> const> a,
std::vector<double> const &eta, std::vector<double> const &normalStress) shared_ptr<std::vector<double> const> mu,
shared_ptr<std::vector<double> const> eta,
shared_ptr<std::vector<double> const> normalStress)
: nodalIntegrals(nodalIntegrals), : nodalIntegrals(nodalIntegrals),
a(a), a(a),
mu(mu), mu(mu),
...@@ -34,8 +36,9 @@ class GlobalRuinaNonlinearity : public GlobalNonlinearity<dim> { ...@@ -34,8 +36,9 @@ class GlobalRuinaNonlinearity : public GlobalNonlinearity<dim> {
if (nodalIntegrals[i][0] == 0) if (nodalIntegrals[i][0] == 0)
return trivialNonlinearity; return trivialNonlinearity;
shared_ptr<NiceFunction const> const func(new RuinaFunction( shared_ptr<NiceFunction const> const func(
nodalIntegrals[i][0], a[i], mu[i], eta[i], normalStress[i])); new RuinaFunction(nodalIntegrals[i][0], (*a)[i], (*mu)[i], (*eta)[i],
(*normalStress)[i]));
return shared_ptr<LocalNonlinearity<dim>>(new LocalNonlinearity<dim>(func)); return shared_ptr<LocalNonlinearity<dim>>(new LocalNonlinearity<dim>(func));
} }
...@@ -43,10 +46,10 @@ class GlobalRuinaNonlinearity : public GlobalNonlinearity<dim> { ...@@ -43,10 +46,10 @@ class GlobalRuinaNonlinearity : public GlobalNonlinearity<dim> {
shared_ptr<LocalNonlinearity<dim> const> const trivialNonlinearity; shared_ptr<LocalNonlinearity<dim> const> const trivialNonlinearity;
std::vector<FieldVector<double, 1>> nodalIntegrals; std::vector<FieldVector<double, 1>> nodalIntegrals;
std::vector<double> a; shared_ptr<std::vector<double> const> a;
std::vector<double> mu; shared_ptr<std::vector<double> const> mu;
std::vector<double> eta; shared_ptr<std::vector<double> const> eta;
std::vector<double> normalStress; shared_ptr<std::vector<double> const> normalStress;
}; };
} }
#endif #endif
...@@ -140,26 +140,27 @@ void assemble_nonlinearity( ...@@ -140,26 +140,27 @@ void assemble_nonlinearity(
Dune::shared_ptr<Dune::GlobalNonlinearity<dim> const> &myGlobalNonlinearity, Dune::shared_ptr<Dune::GlobalNonlinearity<dim> const> &myGlobalNonlinearity,
std::vector<Dune::FieldVector<double, 1>> &nodalIntegrals) { std::vector<Dune::FieldVector<double, 1>> &nodalIntegrals) {
// {{{ Assemble terms for the nonlinearity // {{{ Assemble terms for the nonlinearity
std::vector<double> mu; auto mu = Dune::shared_ptr<std::vector<double>>(new std::vector<double>());
mu.resize(size); mu->resize(size);
std::fill(mu.begin(), mu.end(), parset.get<double>("boundary.friction.mu")); std::fill(mu->begin(), mu->end(), parset.get<double>("boundary.friction.mu"));
std::vector<double> normalStress; auto normalStress =
normalStress.resize(size); Dune::shared_ptr<std::vector<double>>(new std::vector<double>());
std::fill(normalStress.begin(), normalStress.end(), normalStress->resize(size);
std::fill(normalStress->begin(), normalStress->end(),
parset.get<double>("boundary.friction.normalstress")); parset.get<double>("boundary.friction.normalstress"));
std::string const friction_model = std::string const friction_model =
parset.get<std::string>("boundary.friction.model"); parset.get<std::string>("boundary.friction.model");
if (friction_model == std::string("Ruina")) { if (friction_model == std::string("Ruina")) {
std::vector<double> a; auto a = Dune::shared_ptr<std::vector<double>>(new std::vector<double>());
a.resize(size); a->resize(size);
std::fill(a.begin(), a.end(), std::fill(a->begin(), a->end(),
parset.get<double>("boundary.friction.ruina.a")); parset.get<double>("boundary.friction.ruina.a"));
std::vector<double> eta; auto eta = Dune::shared_ptr<std::vector<double>>(new std::vector<double>());
eta.resize(size); eta->resize(size);
std::fill(eta.begin(), eta.end(), std::fill(eta->begin(), eta->end(),
parset.get<double>("boundary.friction.eta")); parset.get<double>("boundary.friction.eta"));
auto const tmp = new Dune::GlobalRuinaNonlinearity<dim>( auto const tmp = new Dune::GlobalRuinaNonlinearity<dim>(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment