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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
|
/** Atomic Regulator : a base class class for atom-continuum control */
#ifndef ATOMICREGULATOR_H
#define ATOMICREGULATOR_H
#include "ATC_TypeDefs.h"
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <string>
namespace ATC {
static const int myMaxIterations = 0;
static const double myTolerance = 1.e-10;
// forward declarations
class TimeFilter;
class RegulatorMethod;
class LambdaMatrixSolver;
class ATC_Coupling;
class NodeToSubset;
class SubsetToNode;
class RegulatedNodes;
class ElementMaskNodeSet;
class LargeToSmallAtomMap;
template <typename T>
class PerAtomQuantity;
template <typename T>
class ProtectedAtomQuantity;
template <typename T>
class PerAtomSparseMatrix;
/**
* @class AtomicRegulator
* @brief Base class for atom-continuum control
*/
//--------------------------------------------------------
//--------------------------------------------------------
// Class AtomicRegulator
//--------------------------------------------------------
//--------------------------------------------------------
class AtomicRegulator {
public:
/** linear solver types */
enum LinearSolverType {
NO_SOLVE=0,
CG_SOLVE, // conjugate gradient
RSL_SOLVE // row-sum lumping solution
};
/** regulator target variable */
enum RegulatorTargetType {
NONE=0,
FIELD,
DERIVATIVE,
DYNAMICS
};
enum RegulatorCouplingType {
UNCOUPLED=0,
FLUX,
GHOST_FLUX,
FIXED
};
// constructor
AtomicRegulator(ATC_Coupling * atc,
const std::string & regulatorPrefix = "");
// destructor
virtual ~AtomicRegulator();
/** parser/modifier */
virtual bool modify(int narg, char **arg);
/** instantiate up the desired method(s) */
virtual void construct_methods() = 0;
/** method(s) create all necessary transfer operators */
virtual void construct_transfers();
/** initialization of method data */
virtual void initialize();
/** add output information */
virtual void output(OUTPUT_LIST & outputData) const;
virtual double compute_vector(int /* n */) const {return 0;}
/** final work at the end of a run */
virtual void finish();
/** reset number of local atoms, as well as atomic data */
virtual void reset_nlocal();
/** set up atom to material identification */
virtual void reset_atom_materials(const Array<int> & elementToMaterialMap,
const MatrixDependencyManager<DenseMatrix, int> * atomElement);
// application steps
/** apply the regulator in the pre-predictor phase */
virtual void apply_pre_predictor(double dt, int timeStep);
/** apply the regulator in the mid-predictor phase */
virtual void apply_mid_predictor(double dt, int timeStep);
/** apply the regulator in the post-predictor phase */
virtual void apply_post_predictor(double dt, int timeStep);
/** apply the regulator in the pre-correction phase */
virtual void apply_pre_corrector(double dt, int timeStep);
/** apply the regulator in the post-correction phase */
virtual void apply_post_corrector(double dt, int timeStep);
/** prior to exchanges */
virtual void pre_force();
/** prior to exchanges */
virtual void pre_exchange();
/** pack fields for restart */
virtual void pack_fields(RESTART_LIST & data);
/** thermo output */
virtual int size_vector(int /* s */) const {return 0;};
// coupling to FE state
/** FE state variable regulator is applied to */
virtual RegulatorTargetType regulator_target() const {return regulatorTarget_;};
/** type of boundary coupling */
//TEMP_JAT field variable should be removed
virtual RegulatorCouplingType coupling_mode(const FieldName /* field */) const {return couplingMode_;};
virtual RegulatorCouplingType coupling_mode() const {return couplingMode_;};
/** compute the thermal boundary flux, must be consistent with regulator */
virtual void compute_boundary_flux(FIELDS & fields);
/** add contributions (if any) to the finite element right-hand side */
virtual void add_to_rhs(FIELDS & rhs);
// data access, intended for method objects
/** returns a pointer to the DENS_MAN associated with the tag, creates a new data member if necessary */
DENS_MAN * regulator_data(const std::string tag, int nCols);
/** can externally set regulator dynamic contributions */
virtual void reset_lambda_contribution(const DENS_MAT & /* target */, const FieldName /* field */) {};
virtual void reset_lambda_contribution(const DENS_MAT & target) { reset_lambda_contribution(target,NUM_TOTAL_FIELDS); }
/** returns a const pointer to the DENS_MAN associated with the tag, or nullptr */
const DENS_MAN * regulator_data(const std::string tag) const;
/** return the maximum number of iterations */
int max_iterations() {return maxIterations_;};
/** return the solver tolerance */
double tolerance() {return tolerance_;};
/** access for ATC transfer */
ATC_Coupling * atc_transfer() {return atc_;};
/** access for time filter */
TimeFilter * time_filter() {return timeFilter_;};
/** access for number of nodes */
int num_nodes() {return nNodes_;};
/** access for number of spatial dimensions */
int nsd() {return nsd_;};
/** access for number of local atoms */
int nlocal() {return nLocal_;};
/** access for boundary integration methods */
BoundaryIntegrationType boundary_integration_type()
{return boundaryIntegrationType_;};
/** access for boundary face sets */
const std::set< std::pair<int,int> > * face_sets()
{ return boundaryFaceSet_;};
/** access for needing a reset */
bool need_reset() const {return needReset_;};
/** force a reset to occur */
void force_reset() {needReset_ = true;};
/** check if lambda is localized */
bool use_localized_lambda() const {return useLocalizedLambda_;};
/** check if matrix should be lumpted for lambda solve */
bool use_lumped_lambda_solve() const {return useLumpedLambda_;};
/** check to see if this direction is being used */
bool apply_in_direction(int i) const {return applyInDirection_[i];};
/** checks if there are any fixed nodes in the MD region */
bool md_fixed_nodes(FieldName fieldName = NUM_TOTAL_FIELDS) const;
/** checks if there are any flux nodes in the MD region */
bool md_flux_nodes(FieldName fieldName = NUM_TOTAL_FIELDS) const;
/** returns prefix tag for regulator */
const std::string & regulator_prefix() const {return regulatorPrefix_;};
protected:
// methods
/** deletes the current regulator method */
void delete_method();
/** deletes all unused data */
void delete_unused_data();
/** sets all data to be unused */
void set_all_data_to_unused();
/** sets all data to be used */
void set_all_data_to_used();
// data
/** point to atc_transfer object */
ATC_Coupling * atc_;
/** how often in number of time steps regulator is applied */
int howOften_;
// reset/reinitialize flags
/** flag to reset data */
bool needReset_;
/** reinitialize method */
void reset_method();
// regulator data
/** container for all data, string is tag, bool is false if currently in use */
std::map<std::string, std::pair<bool,DENS_MAN * > > regulatorData_;
/** maximum number of iterations used in solving for lambda */
int maxIterations_;
/** tolerance used in solving for lambda */
double tolerance_;
/** regulator target flag */
RegulatorTargetType regulatorTarget_;
/** regulator fe coupling type flag */
RegulatorCouplingType couplingMode_;
/** number of nodes */
int nNodes_;
/** number of spatial dimensions */
int nsd_;
/** number of local atoms */
int nLocal_;
/** use of localization techniques */
bool useLocalizedLambda_;
bool useLumpedLambda_;
/** restrict application in certain directions */
std::vector<bool> applyInDirection_;
// method pointers
/** time filtering object */
TimeFilter * timeFilter_;
/** sets up and solves the regulator equations */
RegulatorMethod * regulatorMethod_;
// boundary flux information
BoundaryIntegrationType boundaryIntegrationType_;
const std::set< std::pair<int,int> > * boundaryFaceSet_;
/** prefix string for registering data */
const std::string regulatorPrefix_;
private:
// DO NOT define this
AtomicRegulator();
};
/**
* @class RegulatorMethod
* @brief Base class for implementation of control algorithms
*/
//--------------------------------------------------------
//--------------------------------------------------------
// Class RegulatorMethod
//--------------------------------------------------------
//--------------------------------------------------------
class RegulatorMethod {
public:
RegulatorMethod(AtomicRegulator * atomicRegulator,
const std::string & regulatorPrefix = "");
virtual ~RegulatorMethod(){};
/** instantiate all needed data */
virtual void construct_transfers(){};
/** pre-"run" initialization */
virtual void initialize(){};
/** reset number of local atoms, as well as atomic data */
virtual void reset_nlocal(){};
/** set up atom to material identification */
virtual void reset_atom_materials(const Array<int> & /* elementToMaterialMap */,
const MatrixDependencyManager<DenseMatrix, int> * /* atomElement */){};
/** applies regulator to atoms in the pre-predictor phase */
virtual void apply_pre_predictor(double /* dt */){};
/** applies regulator to atoms in the mid-predictor phase */
virtual void apply_mid_predictor(double /* dt */){};
/** applies regulator to atoms in the post-predictor phase */
virtual void apply_post_predictor(double /* dt */){};
/** applies regulator to atoms in the pre-corrector phase */
virtual void apply_pre_corrector(double /* dt */){};
/** applies regulator to atoms in the post-corrector phase */
virtual void apply_post_corrector(double /* dt */){};
/** applies regulator to atoms in the pre-corrector phase */
virtual void apply_pre_force(double /* dt */){};
/** applies regulator to atoms in the post-corrector phase */
virtual void apply_post_force(double /* dt */){};
/** applies regulator in pre-force phase */
virtual void pre_force(){};
/** applies regulator in pre-exchange phase */
virtual void pre_exchange(){};
/** applies regulator in post-exchange phase */
virtual void post_exchange(){};
/** compute boundary flux, requires regulator input since it is part of the coupling scheme */
virtual void compute_boundary_flux(FIELDS & fields);
/** add contributions (if any) to the finite element right-hand side */
virtual void add_to_rhs(FIELDS & /* rhs */){};
/** get data for output */
virtual void output(OUTPUT_LIST & /* outputData */){};
virtual double compute_vector(int /* n */) const {return 0;}
/** final work at the end of a run */
virtual void finish(){};
/** pack fields for restart */
virtual void pack_fields(RESTART_LIST & /* data */){};
protected:
//data
/** pointer to atomic regulator object for data */
AtomicRegulator * atomicRegulator_;
/** pointer to ATC_transfer object */
ATC_Coupling * atc_;
/** boundary flux */
FIELDS & boundaryFlux_;
/** field mask for specifying boundary flux */
Array2D<bool> fieldMask_;
/** number of nodes */
int nNodes_;
/** prefix string for registering data */
const std::string regulatorPrefix_;
/** mapping for atom materials for atomic FE quadrature */
Array<std::set<int> > atomMaterialGroups_;
/** shape function derivative matrices for boundary atoms */
VectorDependencyManager<SPAR_MAT * > * shpFcnDerivs_;
private:
// DO NOT define this
RegulatorMethod();
};
/**
* @class RegulatorShapeFunction
* @brief Base class for implementation of regulation algorithms using the shape function matrices
*/
// DESIGN each regulator handles only one lambda, but solvers and data are added later
// add a new function to set the linear solver based on enum CG_SOLVE or RSL_SOLVE and shape function matrix
// followed by call to compute sparsity pattern
//--------------------------------------------------------
//--------------------------------------------------------
// Class RegulatorShapeFunction
// base class for all regulators of general form
// of N^T w N lambda = rhs
//--------------------------------------------------------
//--------------------------------------------------------
class RegulatorShapeFunction : public RegulatorMethod {
public:
RegulatorShapeFunction(AtomicRegulator * atomicRegulator,
const std::string & regulatorPrefix = "");
virtual ~RegulatorShapeFunction();
/** instantiate all needed data */
virtual void construct_transfers();
/** pre-"run" initialization */
virtual void initialize();
/** sets lambda to an initial value */
virtual void set_lambda_to_value(double value) {*lambda_ = value;}
/** reset number of local atoms, as well as atomic data */
virtual void reset_nlocal();
/** set up atom to material identification */
virtual void reset_atom_materials(const Array<int> & elementToMaterialMap,
const MatrixDependencyManager<DenseMatrix, int> * atomElement);
/** compute boundary flux, requires regulator input since it is part of the coupling scheme */
virtual void compute_boundary_flux(FIELDS & fields);
/** access to nodes the thermostat is applied to */
const SetDependencyManager<int> * application_nodes() const {return applicationNodes_;};
/** determine if local shape function matrices are needed */
virtual bool use_local_shape_functions() const {return false;};
protected:
// methods
/** compute sparsity for matrix */
void compute_sparsity(void);
/** solve matrix equation */
void solve_for_lambda(const DENS_MAT & rhs,
DENS_MAT & lambda);
/** set weighting factor for in matrix Nhat^T * weights * Nhat */
virtual void set_weights() = 0;
/** Mapping between unique nodes and nodes overlapping MD region */
void map_unique_to_overlap(const MATRIX & uniqueData,
MATRIX & overlapData);
/** Mapping between nodes overlapping MD region to unique nodes */
void map_overlap_to_unique(const MATRIX & overlapData,
MATRIX & uniqueData);
/** sets up the transfer which is the set of nodes being regulated */
virtual void construct_regulated_nodes();
/** creates data structure needed for all to regulated node maps */
virtual void create_node_maps();
// member data
/** lambda coupling parameter */
DENS_MAN * lambda_;
/** lambda at atomic locations */
PerAtomQuantity<double> * atomLambdas_;
/** shape function matrix for use in GLC solve */
PerAtomSparseMatrix<double> * shapeFunctionMatrix_;
/** algorithm being used for the linear solver */
AtomicRegulator::LinearSolverType linearSolverType_;
/** pre-templated sparsity pattern for N^T * T * N */
SPAR_MAN matrixTemplate_;
/** maximum number of iterations used in solving for lambda */
int maxIterations_;
/** tolerance used in solving for lambda */
double tolerance_;
/** matrix solver object */
LambdaMatrixSolver * matrixSolver_;
/** set of nodes used to construct matrix */
SetDependencyManager<int> * regulatedNodes_;
/** set of nodes on which lambda is non-zero */
SetDependencyManager<int> * applicationNodes_;
/** set of nodes needed for localized boundary quadrature */
SetDependencyManager<int> * boundaryNodes_;
/** mapping from all nodes to overlap nodes: -1 is no overlap, otherwise entry is overlap index */
NodeToSubset * nodeToOverlapMap_;
/** mapping from overlap nodes to unique nodes */
SubsetToNode * overlapToNodeMap_;
/** shape function matrix for boundary atoms */
SPAR_MAN * shpFcn_;
/** atomic weights for boundary atoms */
DIAG_MAN * atomicWeights_;
/** element mask for boundary elements corresponding to nodeToOverlapMap_ */
MatrixDependencyManager<ATC_matrix::DenseMatrix, bool> * elementMask_;
/** maps atoms from atc indexing to regulator indexing */
LargeToSmallAtomMap * lambdaAtomMap_;
/** weight per-atom transfer */
PerAtomQuantity<double> * weights_;
/** number of spatial dimensions */
int nsd_;
/** number of ATC internal atoms on this processor */
int nLocal_;
private:
// DO NOT define this
RegulatorShapeFunction();
};
//--------------------------------------------------------
//--------------------------------------------------------
// Class LambdaMatrixSolver
//--------------------------------------------------------
//--------------------------------------------------------
class LambdaMatrixSolver {
public:
LambdaMatrixSolver(SPAR_MAN & matrixTemplate, SPAR_MAN * shapeFunctionMatrix, int maxIterations, double tolerance);
virtual ~LambdaMatrixSolver(){};
/** assemble the matrix */
virtual void assemble_matrix(DIAG_MAT & weights);
/** execute the solver */
virtual void execute(VECTOR & rhs, VECTOR & lambda)=0;
protected:
/** sparse template for the matrix */
SPAR_MAN & matrixTemplate_;
/** non-symmetric part of the matrix */
SPAR_MAN * shapeFunctionMatrix_;
/** matrix used to solve for lambda */
SPAR_MAT lambdaMatrix_;
/** maximum number of iterations */
int maxIterations_;
/** relative tolerance to solve to */
double tolerance_;
private:
// DO NOT define this
LambdaMatrixSolver();
};
//--------------------------------------------------------
//--------------------------------------------------------
// Class LambdaMatrixSolverLumped
//--------------------------------------------------------
//--------------------------------------------------------
class LambdaMatrixSolverLumped : public LambdaMatrixSolver {
public:
LambdaMatrixSolverLumped(SPAR_MAN & matrixTemplate, SPAR_MAN * shapeFunctionMatrix, int maxIterations, double tolerance, const SetDependencyManager<int> * applicationNodes, const NodeToSubset * nodeToOverlapMap);
virtual ~LambdaMatrixSolverLumped(){};
/** assemble the matrix */
virtual void assemble_matrix(DIAG_MAT & weights);
/** execute the solver */
virtual void execute(VECTOR & rhs, VECTOR & lambda);
protected:
/** lumped version of the matrix governing lambda */
DIAG_MAT lumpedMatrix_;
/** set of regulated nodes */
const SetDependencyManager<int> * applicationNodes_;
/** mapping from all nodes to overlap nodes: -1 is no overlap, otherwise entry is overlap index */
const NodeToSubset * nodeToOverlapMap_;
private:
// DO NOT define this
LambdaMatrixSolverLumped();
};
//--------------------------------------------------------
//--------------------------------------------------------
// Class LambdaMatrixSolverCg
//--------------------------------------------------------
//--------------------------------------------------------
class LambdaMatrixSolverCg : public LambdaMatrixSolver {
public:
LambdaMatrixSolverCg(SPAR_MAN & matrixTemplate, SPAR_MAN * shapeFunctionMatrix, int maxIterations, double tolerance);
virtual ~LambdaMatrixSolverCg(){};
/** execute the solver */
virtual void execute(VECTOR & rhs, VECTOR & lambda);
protected:
private:
// DO NOT define this
LambdaMatrixSolverCg();
};
};
#endif
|