Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nonlinear Elastic Integrator #34

Open
wants to merge 86 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
4779319
Added integrator classes
larsson4 Mar 26, 2024
b24d8f0
Added cpp file
larsson4 Mar 27, 2024
6cabc46
domain integrator
larsson4 Mar 27, 2024
aaae41d
Boundary integrator and RHS
larsson4 Mar 27, 2024
f091f70
Added matrix and residual test
axla-io Apr 3, 2024
4a59f20
Added nonlinear elastic solver class
axla-io Apr 3, 2024
3dd5eec
Started implementation of nonlinearity in domain integrator
axla-io Apr 3, 2024
ce886ca
Setup template code for linear material model
larsson4 Apr 3, 2024
4acb231
Tests for domainintegrator
larsson4 Apr 3, 2024
7bc7126
Started boundary integrator implementation
larsson4 Apr 3, 2024
446666c
Working on boundary integrator
larsson4 Apr 5, 2024
45970ba
Works for normal only
larsson4 Apr 5, 2024
44c943d
Summing over x = 1.0
larsson4 Apr 5, 2024
819f5df
Sum over arbitrary x
larsson4 Apr 5, 2024
5a7b79c
Print for debugging
larsson4 Apr 5, 2024
3476bae
Works now for boundary face and when mu = 0.0
axla-io Apr 7, 2024
22a47e8
Add tests too
axla-io Apr 7, 2024
c8c2641
Rewritten with tensor dot product
axla-io Apr 7, 2024
8a93076
Tested that it works for arbitrary mu
axla-io Apr 7, 2024
b9192f8
Started interior boundary implementation
axla-io Apr 7, 2024
1cbeb56
Started test
axla-io Apr 7, 2024
270d975
Diagonal terms are working
larsson4 Apr 8, 2024
7c4c1a2
(1,2) block works
larsson4 Apr 8, 2024
dff275f
Interface integrator working
larsson4 Apr 8, 2024
30d69cd
Cleanup before stiffness matrix redevelopment
larsson4 Apr 8, 2024
647a1fc
Proper gradient for lambda
axla-io Apr 9, 2024
7d36a40
Hacky AssembleH now works with domain integrator
axla-io Apr 9, 2024
afd796f
Started redefinition of elmat
larsson4 Apr 9, 2024
8828d50
Nonlinear stiffness matrix, new formulation works for lambda
larsson4 Apr 9, 2024
209e139
Reimplemented AssembleH in terms of Piola derivative
larsson4 Apr 9, 2024
d493dfa
Refactored derivative mat evaluation
larsson4 Apr 9, 2024
1d9e48c
Loop works
larsson4 Apr 10, 2024
0b83343
Renamed variables
larsson4 Apr 10, 2024
26f7bc9
Block assembly
larsson4 Apr 10, 2024
fa2cb20
Interiorfaceintegrator works
larsson4 Apr 10, 2024
dd6b463
Setup jmatcoeff generation
larsson4 Apr 10, 2024
b255718
Stiffness matrix handles kappa
larsson4 Apr 10, 2024
6af883f
Kappa term in integral
larsson4 Apr 10, 2024
0a0d043
RHS done
larsson4 Apr 10, 2024
572dc9e
Implemented St Venant Material Model, EvalP and AssembleH
axla-io Apr 15, 2024
c4aa135
Started implementation of Eval D mat
axla-io Apr 15, 2024
0e1ae81
Started work on neohookean
larsson4 Apr 17, 2024
49a552b
Figured out derivatives
larsson4 Apr 17, 2024
6074fd4
Added MMS tests
larsson4 Apr 17, 2024
dca804d
Refactored testlinmodel
larsson4 Apr 17, 2024
c89a185
Refactored EvalDMat in linear model
larsson4 Apr 17, 2024
4cc53b9
Refactoring of AssembleH
larsson4 Apr 17, 2024
2b67820
Moved AssembleH to be part of integrator
larsson4 Apr 17, 2024
f384ea8
Renamed variablesRenamed material model name and some equations
larsson4 Apr 17, 2024
4a7ed90
Inheritance for hyperelastic models
larsson4 Apr 18, 2024
48b734b
Started mms implementation
larsson4 Apr 18, 2024
99a7890
Error in convergence
axla-io Apr 18, 2024
37d4c0a
Fixed test error
larsson4 Apr 18, 2024
1b223f7
Started implementing nonlinear solution procedure
larsson4 Apr 18, 2024
8bfbe14
Copied over stuff from Steady NSSolver
larsson4 Apr 18, 2024
e93d417
Compiled code now runs
larsson4 Apr 18, 2024
3346f50
Works now
larsson4 Apr 19, 2024
0f66d60
comment
larsson4 Apr 19, 2024
0085842
Working test for nonlinear elasticity with linear model, direct solve
larsson4 Apr 22, 2024
b44c396
Iterative solver tests work
larsson4 Apr 22, 2024
1a97df7
Started MMS testing of NeoHookean material
larsson4 Apr 23, 2024
43204e4
Found out the bug
axla-io Apr 23, 2024
414aae3
Indexing error
larsson4 Apr 23, 2024
7d0c3dd
debugging
larsson4 Apr 23, 2024
0b1b9da
The worst bugs are gone
larsson4 Apr 23, 2024
3840a44
Testing the analytical solution
larsson4 Apr 24, 2024
48fe4dc
Added new rhs
larsson4 Apr 24, 2024
2483697
Starting integratorwise comparison
larsson4 Apr 25, 2024
8dada7c
Convergence for MFEM integrator
larsson4 Apr 25, 2024
c6f8208
Test work for domain integrator
larsson4 Apr 25, 2024
b6abca4
Changed RHS
larsson4 Apr 25, 2024
02d8e05
Working unrefined
larsson4 Apr 29, 2024
a48b2af
Individual testing done
larsson4 Apr 30, 2024
468f749
Added sketch for nlelast simple solver
larsson4 Apr 30, 2024
1178f03
Added gradient test
larsson4 Apr 30, 2024
a919722
Convergence on H1 with RHS
larsson4 Apr 30, 2024
234ad96
Linear elastic convergence
larsson4 May 1, 2024
aa33b8e
Cantilever
larsson4 May 1, 2024
a70600f
Added option for linear
larsson4 May 1, 2024
1cd6af2
Latest mms
larsson4 May 1, 2024
f825bfa
Fixed linear mms
larsson4 May 1, 2024
3c6c209
Debug linear
larsson4 May 1, 2024
70e80e6
Current stand
larsson4 May 2, 2024
359d990
mms sketch can now be run from command line arguments
larsson4 May 6, 2024
1d32a87
Cleaned up some code
larsson4 May 6, 2024
c8601ae
Updated cantilever example
larsson4 May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ set(scaleupROMObj_SOURCES
include/dg_linear.hpp
src/dg_linear.cpp

include/nlelast_integ.hpp
src/nlelast_integ.cpp

include/nonlinear_integ.hpp
src/nonlinear_integ.cpp

Expand All @@ -203,6 +206,9 @@ set(scaleupROMObj_SOURCES
include/linelast_solver.hpp
src/linelast_solver.cpp

include/nlelast_solver.hpp
src/nlelast_solver.cpp

include/stokes_solver.hpp
src/stokes_solver.cpp

Expand Down
3 changes: 2 additions & 1 deletion include/linelast_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class LinElastSolver : public MultiBlockSolver
Array<BilinearForm *> as;

// Lame constants for each subdomain, global boundary attribute ordering
double lambda, mu;
Array<ConstantCoefficient *> lambda_c;
Array<ConstantCoefficient *> mu_c;
Array<VectorFunctionCoefficient *> bdr_coeffs;
Expand All @@ -53,7 +54,7 @@ class LinElastSolver : public MultiBlockSolver
VectorFunctionCoefficient *init_x = NULL;

public:
LinElastSolver();
LinElastSolver(const double lambda_ = 1.0, const double mu_ = 1.0);

virtual ~LinElastSolver();

Expand Down
200 changes: 200 additions & 0 deletions include/nlelast_integ.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
// Copyright 2023 Lawrence Livermore National Security, LLC. See the top-level LICENSE file for details.
//
// SPDX-License-Identifier: MIT

#ifndef SCALEUPROM_NLELAST_INTEG_HPP
#define SCALEUPROM_NLELAST_INTEG_HPP

#include "mfem.hpp"
#include "hyperreduction_integ.hpp"

namespace mfem
{

/// Abstract class for hyperelastic models that work with DG methods
class DGHyperelasticModel
{
protected:
ElementTransformation *Ttr; /**< Reference-element to target-element
transformation. */

public:
DGHyperelasticModel() : Ttr(NULL) {}
virtual ~DGHyperelasticModel() {}

void SetTransformation(ElementTransformation &Ttr_) { Ttr = &Ttr_; }
virtual double EvalW(const DenseMatrix &Jpt) const = 0;
virtual void EvalP(const DenseMatrix &Jpt, DenseMatrix &P) const = 0;
virtual void SetMatParam(ElementTransformation &Trans, const IntegrationPoint &ip)const = 0;
virtual void SetMatParam(FaceElementTransformations &Trans, const IntegrationPoint &ip)const = 0;
virtual void GetMatParam(Vector &params) const = 0;

virtual double EvalDGWeight(const double w, ElementTransformation &Ttr, const IntegrationPoint &ip) const = 0;

virtual void EvalDmat(const int dim, const int dof, const DenseMatrix &DS, const DenseMatrix &J, DenseMatrix &Dmat)const = 0;

};

class LinElastMaterialModel : public DGHyperelasticModel
{
protected:
Coefficient *c_mu, *c_lambda;
mutable double mu, lambda;

public:
LinElastMaterialModel(double mu_, double lambda_)
: mu(mu_), lambda(lambda_) { c_mu = new ConstantCoefficient(mu), c_lambda = new ConstantCoefficient(lambda); }

virtual void SetMatParam(ElementTransformation &Trans, const IntegrationPoint &ip) const;
virtual void SetMatParam(FaceElementTransformations &Trans, const IntegrationPoint &ip) const;
virtual void GetMatParam(Vector &params) const;
virtual double EvalW(const DenseMatrix &J) const;

virtual double EvalDGWeight(const double w, ElementTransformation &Ttr, const IntegrationPoint &ip) const;
virtual void EvalP(const DenseMatrix &J, DenseMatrix &P) const;

virtual void EvalDmat(const int dim, const int dof, const DenseMatrix &DS, const DenseMatrix &J, DenseMatrix &Dmat) const;


};

class NeoHookeanHypModel : public DGHyperelasticModel
{
protected:
mutable double mu, K, g;
Coefficient *c_mu, *c_K, *c_g;
ElementTransformation *Ttr;
//DenseMatrix E, S;
mutable DenseMatrix Z; // dim x dim
mutable DenseMatrix G, C; // dof x dim

public:
NeoHookeanHypModel(double mu_, double K_, double g_ = 1.0)
: mu(mu_), K(K_), g(g_) { c_mu = new ConstantCoefficient(mu), c_K = new ConstantCoefficient(K), c_g = new ConstantCoefficient(g); }

virtual void SetMatParam(ElementTransformation &Trans, const IntegrationPoint &ip) const;
virtual void SetMatParam(FaceElementTransformations &Trans, const IntegrationPoint &ip) const;
virtual void GetMatParam(Vector &params) const;
virtual double EvalW(const DenseMatrix &J) const;

virtual double EvalDGWeight(const double w, ElementTransformation &Ttr, const IntegrationPoint &ip) const;
virtual void EvalP(const DenseMatrix &J, DenseMatrix &P) const;

virtual void EvalDmat(const int dim, const int dof, const DenseMatrix &DS, const DenseMatrix &J, DenseMatrix &Dmat) const;
};

// DG boundary integrator for nonlinear elastic DG.
// For this is just DGElasticityIntegrator with a different name
class DGHyperelasticNLFIntegrator : virtual public HyperReductionIntegrator
{

public:
DGHyperelasticNLFIntegrator(DGHyperelasticModel *m, double alpha_, double kappa_)
: HyperReductionIntegrator(false), model(m), lambda(NULL), mu(NULL), alpha(alpha_), kappa(kappa_) {}

virtual void AssembleFaceVector(const FiniteElement &el1,
const FiniteElement &el2,
FaceElementTransformations &Trans,
const Vector &elfun, Vector &elvect);

virtual void AssembleFaceGrad(const FiniteElement &el1,
const FiniteElement &el2,
FaceElementTransformations &Tr,
const Vector &elfun, DenseMatrix &elmat);
// values of all scalar basis functions for one component of u (which is a
protected:
DGHyperelasticModel *model;
Coefficient *lambda, *mu;
double alpha, kappa; // vector) at the integration point in the reference space
Vector elvect1, elvect2;
Vector elfun1, elfun2;

DenseMatrix Jrt;
DenseMatrix PMatI1, PMatO1, DSh1, DS1, Jpt1, adjJ1, P1, Dmat1;
DenseMatrix PMatI2, PMatO2, DSh2, DS2, Jpt2, adjJ2, P2, Dmat2;
Vector shape1, tau1,wnor1;
Vector shape2, tau2,wnor2;

Vector nor; // nor = |weight(J_face)| n
// 'jmat' corresponds to the term: kappa <h^{-1} {lambda + 2 mu} [u], [v]>
DenseMatrix jmat;

static void AssembleBlock(
const int dim, const int row_ndofs, const int col_ndofs,
const int row_offset, const int col_offset, const Vector &row_shape,
const Vector &col_shape, const double jmatcoef,
const Vector &wnor, const DenseMatrix &Dmat, DenseMatrix &elmat, DenseMatrix &jmat);

static void AssembleJmat(
const int dim, const int row_ndofs, const int col_ndofs,
const int row_offset, const int col_offset, const Vector &row_shape,
const Vector &col_shape, const double jmatcoef, DenseMatrix &jmat);
};

// Domain integrator for nonlinear elastic DG.
class HyperelasticNLFIntegratorHR : virtual public HyperReductionIntegrator
{

private:
DGHyperelasticModel *model;
// Jrt: the Jacobian of the target-to-reference-element transformation.
// Jpr: the Jacobian of the reference-to-physical-element transformation.
// Jpt: the Jacobian of the target-to-physical-element transformation.
// P: represents dW_d(Jtp) (dim x dim).
// DSh: gradients of reference shape functions (dof x dim).
// DS: gradients of the shape functions in the target (stress-free)
// configuration (dof x dim).
// PMatI: coordinates of the deformed configuration (dof x dim).
// PMatO: reshaped view into the local element contribution to the operator
// output - the result of AssembleElementVector() (dof x dim).
DenseMatrix DSh, DS, Jrt, Jpr, Jpt, P, PMatI, PMatO, Dmat;

public:
HyperelasticNLFIntegratorHR(DGHyperelasticModel *m) : HyperReductionIntegrator(false), model(m)
{
}

virtual void AssembleElementVector(const FiniteElement &el,
ElementTransformation &trans,
const Vector &elfun,
Vector &elvect);

virtual void AssembleElementGrad(const FiniteElement &el,
ElementTransformation &trans,
const Vector &elfun,
DenseMatrix &elmat);

virtual void AssembleH(const int dim, const int dof, const double w,
const DenseMatrix &J, DenseMatrix &elmat);
};

// RHS integrator for nonlinear elastic DG.
// For this is just DGElasticityDirichletLFIntegrator with a different name
class DGHyperelasticDirichletLFIntegrator : public LinearFormIntegrator // Should this be a nonlinear form later?
{
protected:
VectorCoefficient &uD;
DGHyperelasticModel *model;
Coefficient *lambda, *mu;
double alpha, kappa;
Vector shape, nor, u_dir;

public:
DGHyperelasticDirichletLFIntegrator(VectorCoefficient &uD_,
DGHyperelasticModel *m,
double alpha_, double kappa_)
: uD(uD_), model(m), lambda(NULL), mu(NULL), alpha(alpha_), kappa(kappa_) {}

virtual void AssembleRHSElementVect(const FiniteElement &el,
ElementTransformation &Tr,
Vector &elvect);
virtual void AssembleRHSElementVect(const FiniteElement &el,
FaceElementTransformations &Tr,
Vector &elvect);

using LinearFormIntegrator::AssembleRHSElementVect;
};

} // namespace mfem

#endif
154 changes: 154 additions & 0 deletions include/nlelast_solver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Copyright 2023 Lawrence Livermore National Security, LLC. See the top-level LICENSE file for details.
//
// SPDX-License-Identifier: MIT

#ifndef SCALEUPROM_NLELAST_SOLVER_HPP
#define SCALEUPROM_NLELAST_SOLVER_HPP

#include "multiblock_solver.hpp"
#include "interfaceinteg.hpp"
#include "mfem.hpp"
#include "nlelast_integ.hpp"

// By convention we only use mfem namespace as default, not CAROM.
using namespace mfem;


// A proxy Operator used for FOM Newton Solver.
// Similar to SteadyNSOperator.
class NLElastOperator : public Operator
{
protected:
bool direct_solve;

mutable Vector x_u, y_u;

Array<int> u_offsets, vblock_offsets;
InterfaceForm *nl_itf = NULL;
Array<NonlinearForm *> hs;
BlockOperator *Hop = NULL;

BlockMatrix *linearOp = NULL;
SparseMatrix *M = NULL, *B = NULL, *Bt = NULL;

// Jacobian matrix objects
mutable BlockMatrix *system_jac = NULL;
mutable Array2D<SparseMatrix *> hs_mats;
mutable BlockMatrix *hs_jac = NULL;
mutable SparseMatrix *uu_mono = NULL;
mutable SparseMatrix *mono_jac = NULL;
mutable HypreParMatrix *jac_hypre = NULL;

HYPRE_BigInt sys_glob_size;
mutable HYPRE_BigInt sys_row_starts[2];
public:
NLElastOperator(const int height_, const int width_, Array<NonlinearForm *> &hs_, InterfaceForm *nl_itf_,
Array<int> &u_offsets_, const bool direct_solve_=true);

virtual ~NLElastOperator();

virtual void Mult(const Vector &x, Vector &y) const;
virtual Operator &GetGradient(const Vector &x) const;
};

class NLElastSolver : public MultiBlockSolver
{

friend class ParameterizedProblem;
friend class NLElastOperator;

protected:
// interface integrator
InterfaceForm *a_itf = NULL;
// int skip_zeros = 1;

// System matrix for Bilinear case.
Array2D<SparseMatrix *> mats;
// For nonlinear problem
// BlockOperator *globalMat;
BlockMatrix *globalMat = NULL;
SparseMatrix *globalMat_mono = NULL;

// variables needed for direct solve
HYPRE_BigInt sys_glob_size;
HYPRE_BigInt sys_row_starts[2];
HypreParMatrix *globalMat_hypre = NULL;
MUMPSSolver *mumps = NULL;

// Temporary for nonlinear solve implementation
Array<int> u_offsets, p_offsets, vblock_offsets;
BlockMatrix *systemOp = NULL;
Array<NonlinearForm *> hs;
InterfaceForm *nl_itf = NULL;
Solver *J_solver = NULL;
GMRESSolver *J_gmres = NULL;
NewtonSolver *newton_solver = NULL;

// operators
Array<LinearForm *> bs;
Array<NonlinearForm *> as;

// Lame constants for each subdomain, global boundary attribute ordering
Array<ConstantCoefficient *> lambda_c;
Array<ConstantCoefficient *> mu_c;
Array<VectorFunctionCoefficient *> bdr_coeffs;
Array<VectorFunctionCoefficient *> rhs_coeffs;

// DG parameters specific to linear elasticity equation.
double alpha = -1.0;
double kappa = -1.0;

DGHyperelasticModel* model;

// Initial positions
VectorFunctionCoefficient *init_x = NULL;

public:
NLElastSolver(DGHyperelasticModel* _model = NULL);

virtual ~NLElastSolver();

static const std::vector<std::string> GetVariableNames()
{
std::vector<std::string> varnames(1);
varnames[0] = "solution";
return varnames;
}

virtual void InitVariables();

virtual void BuildOperators();
virtual void BuildRHSOperators();
virtual void BuildDomainOperators();

virtual void Assemble();
virtual void AssembleRHS();
virtual void AssembleOperator();
// For bilinear case.
// system-specific.
virtual void AssembleInterfaceMatrices();

virtual bool Solve();

virtual void SetupBCVariables() override;
virtual void SetupIC(std::function<void(const Vector &, Vector &)> F);
virtual void AddBCFunction(std::function<void(const Vector &, Vector &)> F, const int battr = -1);
virtual void AddRHSFunction(std::function<void(const Vector &, Vector &)> F);
virtual bool BCExistsOnBdr(const int &global_battr_idx);
virtual void SetupBCOperators();
virtual void SetupRHSBCOperators();
virtual void SetupDomainBCOperators();

// Component-wise assembly
virtual void BuildCompROMElement(Array<FiniteElementSpace *> &fes_comp);
virtual void BuildBdrROMElement(Array<FiniteElementSpace *> &fes_comp);
virtual void BuildInterfaceROMElement(Array<FiniteElementSpace *> &fes_comp);

virtual void ProjectOperatorOnReducedBasis();

void SanityCheckOnCoeffs();

virtual void SetParameterizedProblem(ParameterizedProblem *problem);
};

#endif
Loading