<commit_before>/*
 * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
 * Copyright (C) 2013-2019  <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

// MAST includes
#include "solver/continuation_solver_base.h"
#include "base/nonlinear_system.h"
#include "base/assembly_base.h"
#include "base/assembly_elem_operation.h"
#include "base/parameter.h"

// libMesh includes
#include "libmesh/linear_solver.h"
#include "libmesh/dof_map.h"
#include "libmesh/petsc_matrix.h"
#include "libmesh/petsc_vector.h"

// PETSc includes
#include <petscmat.h>


MAST::ContinuationSolverBase::ContinuationSolverBase():
max_it                    (10),
abs_tol                   (1.e-8),
rel_tol                   (1.e-8),
arc_length                (0.),
min_step                  (2.),
max_step                  (20.),
step_size_change_exponent (0.5),
step_desired_iters        (5),
schur_factorization       (true),
_initialized              (false),
_elem_ops                 (nullptr),
_assembly                 (nullptr),
_p                        (nullptr),
_p0                       (0.),
_X_scale                  (0.),
_p_scale                  (0.) {
    
}



MAST::ContinuationSolverBase::~ContinuationSolverBase() {
    
}



void
MAST::ContinuationSolverBase::
set_assembly_and_load_parameter(MAST::AssemblyElemOperations&   elem_ops,
                                MAST::AssemblyBase&             assembly,
                                MAST::Parameter&                p) {

    libmesh_assert(!_elem_ops);
    
    _elem_ops  =  &elem_ops;
    _assembly  =  &assembly;
    _p         =  &p;
    
    
}


void
MAST::ContinuationSolverBase::clear_assembly_and_load_parameters() {

    _elem_ops  =  nullptr;
    _assembly  =  nullptr;
    _p         =  nullptr;

}



void
MAST::ContinuationSolverBase::solve()  {
    
    libmesh_assert(_initialized);
    
    unsigned int
    iter    = 0;
    
    libMesh::NumericVector<Real>
    &X = *_assembly->system().solution;

    _p0     = (*_p)();
    _X0.reset(X.clone().release());
    
    Real
    norm0   = _res_norm(X, *_p),
    norm    = norm0;
    
    bool
    cont    = true;

    // save data for possible reuse if the iterations are restarted.
    _save_iteration_data();
    
    while (cont) {
        
        libMesh::out
        << std::setw(10) << "iter: "
        << std::setw(5)  << iter
        << std::setw(10) << "res-l2: "<commit_msg>Bug-fix for restart of continuation solver (#44)<commit_after>/*
 * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
 * Copyright (C) 2013-2019  <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

// MAST includes
#include "solver/continuation_solver_base.h"
#include "base/nonlinear_system.h"
#include "base/assembly_base.h"
#include "base/assembly_elem_operation.h"
#include "base/parameter.h"

// libMesh includes
#include "libmesh/linear_solver.h"
#include "libmesh/dof_map.h"
#include "libmesh/petsc_matrix.h"
#include "libmesh/petsc_vector.h"

// PETSc includes
#include <petscmat.h>


MAST::ContinuationSolverBase::ContinuationSolverBase():
max_it                    (10),
abs_tol                   (1.e-8),
rel_tol                   (1.e-8),
arc_length                (0.),
min_step                  (2.),
max_step                  (20.),
step_size_change_exponent (0.5),
step_desired_iters        (5),
schur_factorization       (true),
_initialized              (false),
_elem_ops                 (nullptr),
_assembly                 (nullptr),
_p                        (nullptr),
_p0                       (0.),
_X_scale                  (0.),
_p_scale                  (0.) {
    
}



MAST::ContinuationSolverBase::~ContinuationSolverBase() {
    
}



void
MAST::ContinuationSolverBase::
set_assembly_and_load_parameter(MAST::AssemblyElemOperations&   elem_ops,
                                MAST::AssemblyBase&             assembly,
                                MAST::Parameter&                p) {

    libmesh_assert(!_elem_ops);
    
    _elem_ops  =  &elem_ops;
    _assembly  =  &assembly;
    _p         =  &p;
    
    
}


void
MAST::ContinuationSolverBase::clear_assembly_and_load_parameters() {

    _elem_ops  =  nullptr;
    _assembly  =  nullptr;
    _p         =  nullptr;

}



void
MAST::ContinuationSolverBase::solve()  {
    
    libmesh_assert(_initialized);
    
    unsigned int
    iter    = 0;
    
    libMesh::NumericVector<Real>
    &X = *_assembly->system().solution;

    _p0     = (*_p)();
    _X0.reset(X.clone().release());
    

    // save data for possible reuse if the iterations are restarted.
    _save_iteration_data();

    Real
    norm0   = _res_norm(X, *_p),
    norm    = norm0;
    
    bool
    cont    = true;
    
    while (cont) {
        
        libMesh::out
        << std::setw(10) << "iter: "
        << std::setw(5)  << iter
        << std::setw(10) << "res-l2: "
{'fraction_non_alphanumeric': 0.10315186246418338, 'fraction_numerical': 0.01591849729385546, 'mean_word_length': 2.2537545313309164, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '962278', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1918, 'n_words': 510}