File: FieldEulerIntegrator.cpp

package info (click to toggle)
lammps 20220106.git7586adbb6a%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348,064 kB
  • sloc: cpp: 831,421; python: 24,896; xml: 14,949; f90: 10,845; ansic: 7,967; sh: 4,226; perl: 4,064; fortran: 2,424; makefile: 1,501; objc: 238; lisp: 163; csh: 16; awk: 14; tcl: 6
file content (153 lines) | stat: -rw-r--r-- 5,769 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "FieldEulerIntegrator.h"
#include "ATC_Coupling.h"
#include "FE_Engine.h"
#include "PhysicsModel.h"
#include "PrescribedDataManager.h"
//#include "GMRES.h"
//#include "CG.h"
#include "ImplicitSolveOperator.h"
#include "MatrixDef.h"
#include "LinearSolver.h"

namespace ATC {

// ====================================================================
// FieldEulerIntegrator
// ====================================================================
FieldEulerIntegrator::FieldEulerIntegrator(
  const FieldName fieldName,
  const PhysicsModel * physicsModel,
  /*const*/ FE_Engine * feEngine,
  /*const*/ ATC_Coupling * atc,
  const Array2D< bool > & rhsMask  // copy
)
  : atc_(atc),
    feEngine_(feEngine),
    physicsModel_(physicsModel),
    fieldName_(fieldName),
    rhsMask_(rhsMask)
{
  nNodes_ = feEngine->num_nodes();
}

// ====================================================================
// FieldImplicitIntegrator
// ====================================================================
FieldExplicitEulerIntegrator::FieldExplicitEulerIntegrator(
  const FieldName fieldName,
  const PhysicsModel * physicsModel,
  /*const*/ FE_Engine * feEngine,
  /*const*/ ATC_Coupling * atc,
  const Array2D< bool > & rhsMask  // copy
) : FieldEulerIntegrator(fieldName,physicsModel,feEngine,atc,rhsMask)
{
}

// --------------------------------------------------------------------
// update
// --------------------------------------------------------------------
  void FieldExplicitEulerIntegrator::update(const double dt, double /* time */,
  FIELDS & fields, FIELDS & rhs)
{
  // write and add update mass matrix to handled time variation
  // update mass matrix to be consistent/lumped, and handle this in apply_inverse_mass_matrix
  atc_->compute_rhs_vector(rhsMask_, fields, rhs,
    FULL_DOMAIN, physicsModel_);
  DENS_MAT & myRhs(rhs[fieldName_].set_quantity());
  atc_->apply_inverse_mass_matrix(myRhs,fieldName_);
  fields[fieldName_] += dt*myRhs;
}

// ====================================================================
// FieldImplicitEulerIntegrator
// ====================================================================
FieldImplicitEulerIntegrator::FieldImplicitEulerIntegrator(
  const FieldName fieldName,
  const PhysicsModel * physicsModel,
  /*const*/ FE_Engine * feEngine,
  /*const*/ ATC_Coupling * atc,
  const Array2D< bool > & rhsMask,  // copy
  const double alpha
) : FieldEulerIntegrator(fieldName,physicsModel,feEngine,atc,rhsMask),
  alpha_(alpha),
  dT_(1.0e-6),
  maxRestarts_(50),
  maxIterations_(1000),
  tol_(1.0e-8)
{
}

// --------------------------------------------------------------------
// update
// --------------------------------------------------------------------
void FieldImplicitEulerIntegrator::update(const double dt, double time,
                                          FIELDS & fields, FIELDS & /* rhs */)
{ // solver handles bcs
  FieldImplicitSolveOperator solver(atc_,
    fields, fieldName_, rhsMask_, physicsModel_,
    time, dt, alpha_);
  DiagonalMatrix<double> preconditioner = solver.preconditioner();
  DENS_VEC rT = solver.r();
  DENS_VEC dT(nNodes_); dT = dT_;
  DENS_MAT H(maxRestarts_+1, maxRestarts_);
  double tol = tol_; // tol returns the residual
  int iterations = maxIterations_; // iterations returns number of iterations
  int restarts = maxRestarts_;
  int convergence = GMRES(solver,
    dT, rT, preconditioner, H, restarts, iterations, tol);
  if (convergence != 0) {
    throw ATC_Error(field_to_string(fieldName_) + " evolution did not converge");
  }
  solver.solution(dT,fields[fieldName_].set_quantity());
}

// ====================================================================
// FieldImplicitDirectEulerIntegrator
// ====================================================================
FieldImplicitDirectEulerIntegrator::FieldImplicitDirectEulerIntegrator(
  const FieldName fieldName,
  const PhysicsModel * physicsModel,
  /*const*/ FE_Engine * feEngine,
  /*const*/ ATC_Coupling * atc,
  const Array2D< bool > & rhsMask,  // copy
  const double alpha
) : FieldEulerIntegrator(fieldName,physicsModel,feEngine,atc,rhsMask),
  alpha_(alpha),solver_(nullptr)
{
   rhsMask_(fieldName_,FLUX) = false; // handle laplacian term with stiffness
   const BC_SET & bcs = (atc_->prescribed_data_manager()->bcs(fieldName_))[0];
   solver_ = new LinearSolver(_lhsMK_,bcs);
   solver_->allow_reinitialization();
}
FieldImplicitDirectEulerIntegrator::~FieldImplicitDirectEulerIntegrator()
{
   if (solver_) delete solver_;
}

// --------------------------------------------------------------------
// initialize
// --------------------------------------------------------------------
  void FieldImplicitDirectEulerIntegrator::initialize(const double dt, double /* time */,
                                                      FIELDS & /* fields */)
{
   std::pair<FieldName,FieldName> p(fieldName_,fieldName_);
   Array2D <bool>  rmask = atc_->rhs_mask();
   rmask(fieldName_,FLUX) = true;
   atc_->tangent_matrix(p,rmask,physicsModel_,_K_);
   _lhsMK_ = (1./dt)*(_M_)-     alpha_*(_K_);
   _rhsMK_ = (1./dt)*(_M_)+(1.+alpha_)*(_K_);
}
// --------------------------------------------------------------------
// update
// --------------------------------------------------------------------
  void FieldImplicitDirectEulerIntegrator::update(const double /* dt */, double /* time */,
  FIELDS & fields, FIELDS & rhs)
{
  atc_->compute_rhs_vector(rhsMask_, fields, rhs,
    FULL_DOMAIN, physicsModel_);
  CLON_VEC myRhs   = column(   rhs[fieldName_].set_quantity(),0);
  CLON_VEC myField = column(fields[fieldName_].set_quantity(),0);
  myRhs += _rhsMK_*myField; // f = (1/dt M + (1+alpha) K) T + f
  solver_->solve(myField,myRhs); // (1/dt M -alpha K)^-1 f
}
} // namespace ATC