Skip to content

Commit

Permalink
Adapt the code to using new structure SlaybaughLab#10
Browse files Browse the repository at this point in the history
  • Loading branch information
Weixiong Zheng committed Sep 6, 2017
1 parent 6a655db commit 2439eda
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 191 deletions.
20 changes: 12 additions & 8 deletions src/common/bart_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ p_order(prm.get_integer("finite element polynomial degree")),
global_refinements(prm.get_integer("uniform refinements")),
namebase(prm.get("output file name base")),
ho_linear_solver_name(prm.get("HO linear solver name")),
ho_preconditioner_name(prm.get("HO preconditioner name")),
itr_cls(prm),
ho_preconditioner_name(prm.get("HO preconditioner name"))
{

aqd_ptr = build_aq_model (prm)
n_total_ho_vars = aqd_ptr->get_n_total_ho_vars ();
n_azi = aqd_ptr->get_sn_order ();
n_dir = aqd_ptr->get_n_dir ();
msh_ptr = build_mesh (prm);
mat_ptr = build_material (prm);
fe = build_finite_element (prm);
}

Expand Down Expand Up @@ -119,7 +120,7 @@ void BartDriver<dim>::initialize_dealii_objects ()
MPI_COMM_WORLD,
relevant_dofs);

itr_cls.initialize_system_matrices_vectors (dsp, local_dofs);
itr_ptr->initialize_system_matrices_vectors (dsp, local_dofs);
}

template <int dim>
Expand All @@ -129,9 +130,6 @@ void BartDriver<dim>::output_results () const
DataOut<dim> data_out;
data_out.attach_dof_handler (dof_handler);

itr_cls.get_keff (keff);
itr_cls.get_flux_this_proc (sflx_proc);

data_out.add_data_vector (keff, "keff");
for (unsigned int g=0; g<n_group; ++g)
{
Expand Down Expand Up @@ -173,8 +171,14 @@ void BartDriver<dim>::run ()
msh_ptr->make_grid (triangulation);
setup_system ();
report_system ();
itr_cls.solve_problems (msh_ptr, aqd_ptr, sflx_proc);
itr_cls.get_keff (keff);
// get cell iterators on local processors
msh_ptr->get_relevant_cell_iterators (dof_handler,
local_cells,
is_cell_at_bd);
// solve the problem using iterative methods specified in Iterations class
itr_ptr->solve_problems (local_cells, is_cell_at_bd, sflx_proc);
if (is_eigen_problem)
itr_ptr->get_keff (keff);
output_results ();
}

Expand Down
15 changes: 7 additions & 8 deletions src/common/bart_driver.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __transport_base_h__
#define __transport_base_h__
#ifndef __bart_driver_h__
#define __bart_driver_h__
#include <deal.II/lac/generic_linear_algebra.h>

#include <deal.II/lac/petsc_parallel_sparse_matrix.h>
Expand Down Expand Up @@ -48,20 +48,18 @@ class BartDriver
{
public:
BartDriver (ParameterHandler &prm);// : ProblemDefinition<dim> (prm){}
virtual ~BartDriver ();
~BartDriver ();

void run ();
private:
void setup_system ();
void report_system ();
void initialize_dealii_objects ();
void prepare_correction_aflx ();
void output_results () const;
void initialize_aq (ParameterHandler &prm);

const ParameterHandler &prm;

Iterations<dim> itr_cls;
std_cxx11::shared_ptr<Iterations<dim> > itr_ptr;
std_cxx11::shared_ptr<MeshGenerator<dim> > msh_ptr;
std_cxx11::shared_ptr<MaterialProperties> mat_ptr;
std_cxx11::shared_ptr<AQBase<dim> > aqd_ptr;
Expand All @@ -88,7 +86,6 @@ class BartDriver
bool do_nda;
bool have_reflective_bc;


unsigned int n_dir;
unsigned int n_azi;
unsigned int n_total_ho_vars;
Expand All @@ -97,7 +94,9 @@ class BartDriver
unsigned int p_order;
unsigned int global_refinements;

std::vector<Vector<double> > sflx_proc;

ConstraintMatrix constraints;
};

#endif // define __transport_base_h__
#endif // define __bart_driver_h__
37 changes: 24 additions & 13 deletions src/common/bart_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ FE_Poly<TensorProductPolynomials<dim>,dim,dim>* build_finite_element
return new FE_Q<dim> (p_order);
}

template <int dim>
std_cxx11::shared_ptr<PreconditionerSolver> build_linalg
(ParameterHandler &prm,
std::string equation_name,
Expand All @@ -31,19 +30,28 @@ std_cxx11::shared_ptr<PreconditionerSolver> build_linalg
(new PreconditionerSolver(prm, equation_name, n_total_vars));
}

template <int dim>
std_cxx11::shared_ptr<Iterations<dim> > build_iterations
(ParameterHandler &prm,
const std_cxx11::shared_ptr<MeshGenerator<dim> > msh_ptr,
const std_cxx11::shared_ptr<AQBase<dim> > aqd_ptr,
const std_cxx11::shared_ptr<MaterialProperties> mat_ptr)
{
return std_cxx11::shared_ptr<Iterations<dim> >
(new Iterations<dim> (prm, msh_ptr, aqd_ptr, mat_ptr));
}

template <int dim>
std_cxx11::shared_ptr<MeshGenerator<dim> > build_mesh (ParameterHandler &prm)
{
std_cxx11::shared_ptr<MeshGenerator<dim> > mesh_class =
std_cxx11::shared_ptr<MeshGenerator<dim> > (new MeshGenerator<dim>(prm));
return mesh_class;
return std_cxx11::shared_ptr<MeshGenerator<dim> >
(new MeshGenerator<dim>(prm));
}

std_cxx11::shared_ptr<MaterialProperties> build_material (ParameterHandler &prm)
{
std_cxx11::shared_ptr<MaterialProperties> material_class =
std_cxx11::shared_ptr<MaterialProperties> (new MaterialProperties (prm));
return material_class;
return std_cxx11::shared_ptr<MaterialProperties>
(new MaterialProperties (prm));
}

template <int dim>
Expand All @@ -54,12 +62,13 @@ std_cxx11::shared_ptr<EquationBase<dim> > build_equation
const std_cxx11::shared_ptr<AQBase<dim> > aqd_ptr,
const std_cxx11::shared_ptr<MaterialProperties> mat_ptr)
{
std_cxx11::shared_ptr<EquationBase<dim> > equation_class;
// TODO: add NDA to it after having NDA class
std_cxx11::shared_ptr<EquationBase<dim> > equation_pointer;
if (transport_model_name=="ep")
equation_class =
equation_pointer =
std_cxx11::shared_ptr<EquationBase<dim> >
(new EvenParity<dim> (prm, msh_ptr, aqd_ptr, mat_ptr));
return equation_class;
return equation_pointer;
}

template <int dim>
Expand All @@ -69,10 +78,10 @@ build_aq_model (ParameterHandler &prm)
std::string aq_name = prm.get ("angular quadrature name");
AssertThrow (aq_name!="none",
ExcMessage("angular quadrature name incorrect or missing"));
std_cxx11::shared_ptr<AQBase<dim> > aq_class;
std_cxx11::shared_ptr<AQBase<dim> > aq_pointer;
if (aq_name=="lsgc")
aq_class = std_cxx11::shared_ptr<AQBase<dim> > (new LSGC<dim>(prm));
return aq_class;
aq_pointer = std_cxx11::shared_ptr<AQBase<dim> > (new LSGC<dim>(prm));
return aq_pointer;
}

void radio (std::string str)
Expand Down Expand Up @@ -118,6 +127,8 @@ void radio ()
pout << "-------------------------------------" << std::endl << std::endl;
}

template std_cxx11::shared_ptr<Iterations<2> > build_iterations;
template std_cxx11::shared_ptr<Iterations<3> > build_iterations;
template std_cxx11::shared_ptr<EquationBase<2> > build_equation;
template std_cxx11::shared_ptr<EquationBase<3> > build_equation;
template std_cxx11::shared_ptr<AQBase<2> > build_aq_model;
Expand Down
17 changes: 16 additions & 1 deletion src/common/bart_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,27 @@ build_equation (std::string equation_name,
const std_cxx11::shared_ptr<AQBase<dim> > aqd_ptr,
const std_cxx11::shared_ptr<MaterialProperties> mat_ptr);

template <int dim>
/** \brief Build linear algebraic related stuffs for solving linear equations
*/
std_cxx11::shared_ptr<PreconditionerSolver> build_linalg
(ParameterHandler &prm,
std::string equation_name,
unsigned int& n_total_vars);

/** \brief Build iterations to solve the transport problem with iterative methods
*
* This specific iteration classes according to method type will be further detailed
* inside Iteration<dim>::solve_problem. This class is designed as a buffer between
* BartDriver and specific iterative methods s.t. BartDriver will only "drive"
* without knowing what iterative methods are involved.
*/
template <int dim>
std_cxx11::shared_ptr<Iterations<dim> > build_iterations
(ParameterHandler &prm,
const std_cxx11::shared_ptr<MeshGenerator<dim> > msh_ptr,
const std_cxx11::shared_ptr<AQBase<dim> > aqd_ptr,
const std_cxx11::shared_ptr<MaterialProperties> mat_ptr);

/** \brief Function to build angular quadrature for general dimensions
*
* \parameter prm A processed ParameterHandler instance
Expand Down
5 changes: 3 additions & 2 deletions src/iteration/iteration_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ void IterationBase<dim>::initialize_equations
std_cxx11::shared_ptr<AQBase<dim> > aqd_ptr,
std_cxx11::shared_ptr<MaterialProperties> mat_ptr)
{
tra_ptr = build_transport_model (prm, msh_ptr, aqd_ptr, mat_ptr);
std::string space_angle_solver_name = prm.get("transport model");
tra_ptr = build_space_angle_solver (space_angle_solver_name,prm, msh_ptr, aqd_ptr, mat_ptr);
if (do_nda)
nda_ptr = build_nda (prm, msh_ptr, aqd_ptr, mat_ptr);
nda_ptr = build_space_angle_solver ("nda", prm, msh_ptr, aqd_ptr, mat_ptr);
}

template class IterationBase<2>;
Expand Down
12 changes: 1 addition & 11 deletions src/iteration/iteration_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,11 @@ class IterationBase
double estimate_phi_diff
(Vector<double> &phi_newer, Vector<double> &phi_older);

std_cxx11::shared_ptr<EquationBase<dim> > trm_ptr;
std_cxx11::shared_ptr<EquationBase<dim> > nda_ptr;

void initialize_equations ();

std_cxx11::shared_ptr<EquationBase<dim> > tra_ptr;
std_cxx11::shared_ptr<EquationBase<dim> > nda_ptr;

double total_calculation_time; /**< total time for calculations including assembly of rhs*/
unsigned int ct_ho_iters; /**< HO iteration counts*/
unsigned int ct_nda_iters; /**< NDA iteration counts*/

std::vector<Vector<double> > sflx_proc;
std::vector<Vector<double> > sflx_proc_prev_gen;
std::vector<Vector<double> > lo_sflx_proc;
//std::vector<Vector<double> > sflx_proc;
}

#endif // __iteration_base_h__
Loading

0 comments on commit 2439eda

Please sign in to comment.