58 _refine_in_reinit(true),
59 _enable_default_ghosting(true)
63 this->
parameters.
set<
unsigned int>(
"linear solver maximum iterations") = 5000;
86 System * sys = pos->second;
98 const unsigned int n_sys = this->
n_systems();
100 libmesh_assert_not_equal_to (n_sys, 0);
105 node->set_n_systems(n_sys);
108 elem->set_n_systems(n_sys);
110 for (
unsigned int i=0; i != this->
n_systems(); ++i)
113 #ifdef LIBMESH_ENABLE_AMR 135 parallel_object_only();
137 const unsigned int n_sys = this->
n_systems();
138 libmesh_assert_not_equal_to (n_sys, 0);
142 bool _added_new_systems =
false;
143 for (
unsigned int i=0; i != n_sys; ++i)
145 _added_new_systems =
true;
147 if (_added_new_systems)
151 node->set_n_systems(n_sys);
154 elem->set_n_systems(n_sys);
157 for (
unsigned int i=0; i != n_sys; ++i)
173 node->set_n_systems(this->n_systems());
177 elem->set_n_systems(this->n_systems());
181 for (
unsigned int i=0; i != this->
n_systems(); ++i)
184 #ifdef LIBMESH_ENABLE_AMR 186 bool dof_constraints_created =
false;
187 bool mesh_changed =
false;
193 for (
unsigned int i=0; i != this->
n_systems(); ++i)
214 dof_constraints_created =
true;
229 for (
unsigned int i=0; i != this->
n_systems(); ++i)
232 if (!dof_constraints_created)
240 dof_constraints_created =
true;
252 for (
unsigned int i=0; i != this->
n_systems(); ++i)
255 if (!dof_constraints_created)
269 #endif // #ifdef LIBMESH_ENABLE_AMR 278 for (
unsigned int i=0; i != this->
n_systems(); ++i)
290 const unsigned int n_sys = this->
n_systems();
292 libmesh_assert_not_equal_to (n_sys, 0);
300 node->set_n_systems(n_sys);
303 elem->set_n_systems(n_sys);
306 for (
unsigned int i=0; i != this->
n_systems(); ++i)
328 mesh.add_ghosting_functor(
mesh.default_ghosting());
330 mesh.remove_ghosting_functor(
mesh.default_ghosting());
332 for (
unsigned int i=0; i != this->
n_systems(); ++i)
346 LOG_SCOPE(
"update()",
"EquationSystems");
349 for (
unsigned int i=0; i != this->
n_systems(); ++i)
356 const std::string &
name)
367 else if (sys_type ==
"Basic")
368 this->add_system<System> (
name);
371 else if (sys_type ==
"Newmark")
372 this->add_system<NewmarkSystem> (
name);
375 else if ((sys_type ==
"Explicit"))
376 this->add_system<ExplicitSystem> (
name);
379 else if ((sys_type ==
"Implicit") ||
380 (sys_type ==
"Steady" ))
381 this->add_system<ImplicitSystem> (
name);
384 else if ((sys_type ==
"Transient") ||
385 (sys_type ==
"TransientImplicit") ||
386 (sys_type ==
"TransientLinearImplicit"))
387 this->add_system<TransientLinearImplicitSystem> (
name);
390 else if (sys_type ==
"TransientNonlinearImplicit")
391 this->add_system<TransientNonlinearImplicitSystem> (
name);
394 else if (sys_type ==
"TransientExplicit")
395 this->add_system<TransientExplicitSystem> (
name);
398 else if (sys_type ==
"LinearImplicit")
399 this->add_system<LinearImplicitSystem> (
name);
402 else if (sys_type ==
"NonlinearImplicit")
403 this->add_system<NonlinearImplicitSystem> (
name);
406 else if (sys_type ==
"RBConstruction")
407 this->add_system<RBConstruction> (
name);
410 else if (sys_type ==
"TransientRBConstruction")
411 this->add_system<TransientRBConstruction> (
name);
413 #ifdef LIBMESH_HAVE_SLEPC 415 else if (sys_type ==
"Eigen")
416 this->add_system<EigenSystem> (
name);
417 else if (sys_type ==
"TransientEigenSystem")
418 this->add_system<TransientEigenSystem> (
name);
421 #if defined(LIBMESH_USE_COMPLEX_NUMBERS) 423 else if (sys_type ==
"Frequency")
424 this->add_system<FrequencySystem> (
name);
428 libmesh_error_msg(
"ERROR: Unknown system type: " << sys_type);
440 #ifdef LIBMESH_ENABLE_DEPRECATED 443 libmesh_deprecated();
446 libmesh_error_msg(
"ERROR: no system named " <<
name);
460 for (
unsigned int i=0; i != this->
n_systems(); ++i)
470 for (
unsigned int i=0; i != this->
n_systems(); ++i)
471 this->
get_system(i).sensitivity_solve(parameters_in);
480 for (
unsigned int i=this->
n_systems(); i != 0; --i)
481 this->
get_system(i-1).adjoint_solve(qoi_indices);
488 const std::set<std::string> * system_names)
const 490 unsigned int var_num=0;
499 unsigned int n_scalar_vars = 0;
500 unsigned int n_vector_vars = 0;
502 for (; pos !=
end; ++pos)
505 bool use_current_system = (system_names ==
nullptr);
506 if (!use_current_system)
507 use_current_system = system_names->count(pos->first);
508 if (!use_current_system || pos->second->hide_output())
511 for (
unsigned int vn=0; vn<pos->second->n_vars(); vn++)
523 unsigned int nv = n_scalar_vars + dim*n_vector_vars;
526 libmesh_assert_less_equal ( nv, dim*this->
n_vars() );
531 var_names.resize( nv );
537 for (; pos !=
end; ++pos)
540 bool use_current_system = (system_names ==
nullptr);
541 if (!use_current_system)
542 use_current_system = system_names->count(pos->first);
543 if (!use_current_system || pos->second->hide_output())
546 for (
unsigned int vn=0; vn<pos->second->n_vars(); vn++)
548 std::string var_name = pos->second->variable_name(vn);
549 FEType fe_type = pos->second->variable_type(vn);
554 if (type ==
nullptr || (type && *type == fe_type))
562 var_names[var_num++] = var_name;
565 var_names[var_num++] = var_name+
"_x";
566 var_names[var_num++] = var_name+
"_y";
569 var_names[var_num++] = var_name+
"_x";
570 var_names[var_num++] = var_name+
"_y";
571 var_names[var_num++] = var_name+
"_z";
574 libmesh_error_msg(
"Invalid dim in build_variable_names");
578 var_names[var_num++] = var_name;
583 var_names.resize(var_num);
590 const std::string &)
const 593 libmesh_not_implemented();
599 std::unique_ptr<NumericVector<Number>>
602 LOG_SCOPE(
"build_parallel_solution_vector()",
"EquationSystems");
605 parallel_object_only();
625 unsigned int n_scalar_vars = 0;
626 unsigned int n_vector_vars = 0;
630 for (; pos !=
end; ++pos)
633 bool use_current_system = (system_names ==
nullptr);
634 if (!use_current_system)
635 use_current_system = system_names->count(pos->first);
636 if (!use_current_system || pos->second->hide_output())
639 for (
unsigned int vn=0; vn<pos->second->n_vars(); vn++)
649 nv = n_scalar_vars + dim*n_vector_vars;
667 n_local_nodes = n_local_nodes +
674 parallel_soln.
init(max_nn*nv, n_local_nodes*nv,
false,
PARALLEL);
680 repeat_count.
init(max_nn*nv, n_local_nodes*nv,
false,
PARALLEL);
682 repeat_count.
close();
684 unsigned int var_num=0;
694 for (; pos !=
end; ++pos)
697 bool use_current_system = (system_names ==
nullptr);
698 if (!use_current_system)
699 use_current_system = system_names->count(pos->first);
700 if (!use_current_system || pos->second->hide_output())
703 const System & system = *(pos->second);
704 const unsigned int nv_sys = system.
n_vars();
705 const unsigned int sys_num = system.
number();
708 unsigned int n_scalar_vars = 0;
709 unsigned int n_vector_vars = 0;
710 for (
unsigned int vn=0; vn<pos->second->n_vars(); vn++)
720 unsigned int nv_sys_split = n_scalar_vars + dim*n_vector_vars;
730 libmesh_assert(this->
comm().verify(non_const_sys.
solution->closed()));
731 if (!non_const_sys.
solution->closed())
738 std::vector<Number> elem_soln;
739 std::vector<Number> nodal_soln;
740 std::vector<dof_id_type> dof_indices;
742 unsigned var_inc = 0;
743 for (
unsigned int var=0; var<nv_sys; var++)
757 elem_soln.resize(dof_indices.size());
759 for (std::size_t i=0; i<dof_indices.size(); i++)
760 elem_soln[i] = sys_soln(dof_indices[i]);
768 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 770 if (!elem->infinite())
773 libmesh_assert_equal_to (nodal_soln.size(), n_vec_dim*elem->n_nodes());
775 for (
unsigned int n=0; n<elem->n_nodes(); n++)
777 for (
unsigned int d=0; d < n_vec_dim; d++)
781 parallel_soln.
add(nv*(elem->node_id(n)) + (var_inc+d + var_num), nodal_soln[n_vec_dim*n+d]);
784 repeat_count.
add(nv*(elem->node_id(n)) + (var_inc+d + var_num), 1);
790 for (
unsigned int n=0; n<elem->n_nodes(); n++)
792 if (!elem->node_ptr(n)->n_dofs(sys_num, var))
793 for (
unsigned int d=0; d < n_vec_dim; d++)
794 repeat_count.
add(nv*(elem->node_id(n)) + (var+d + var_num), 1);
797 var_inc += n_vec_dim;
800 var_num += nv_sys_split;
804 parallel_soln.
close();
805 repeat_count.
close();
820 repeat_count.
set(i, 1.);
825 repeat_count.
close();
829 parallel_soln /= repeat_count;
831 return std::unique_ptr<NumericVector<Number>>(parallel_soln_ptr.release());
837 const std::set<std::string> * system_names)
const 839 LOG_SCOPE(
"build_solution_vector()",
"EquationSystems");
842 std::unique_ptr<NumericVector<Number>> parallel_soln =
846 parallel_soln->localize_to_one(soln);
852 std::vector<std::set<subdomain_id_type>> & vars_active_subdomains)
const 854 unsigned int var_num=0;
856 vars_active_subdomains.clear();
857 vars_active_subdomains.resize(names.size());
862 for (; pos !=
end; ++pos)
864 for (
unsigned int vn=0; vn<pos->second->n_vars(); vn++)
866 std::string var_name = pos->second->variable_name(vn);
868 auto names_it = std::find(names.begin(), names.end(), var_name);
869 if(names_it != names.end())
871 const Variable & variable = pos->second->variable(vn);
872 const std::set<subdomain_id_type> & active_subdomains = variable.
active_subdomains();
873 vars_active_subdomains[var_num++] = active_subdomains;
878 libmesh_assert_equal_to(var_num, names.size());
884 std::vector<std::string> & names)
const 886 libmesh_deprecated();
894 std::vector<std::string> & names)
const 897 std::unique_ptr<NumericVector<Number>> parallel_soln =
907 parallel_soln->localize_to_one(soln);
912 std::unique_ptr<NumericVector<Number>>
916 parallel_object_only();
927 std::vector<std::string> filter_names = names;
928 bool is_filter_names = !filter_names.empty();
937 std::vector<std::vector<unsigned>> do_output(
_systems.size());
941 unsigned sys_ctr = 0;
943 for (; pos !=
end; ++pos, ++sys_ctr)
945 const System & system = *(pos->second);
946 const unsigned int nv_sys = system.
n_vars();
948 do_output[sys_ctr].resize(nv_sys);
950 for (
unsigned int var=0; var < nv_sys; ++var)
953 (is_filter_names && std::find(filter_names.begin(), filter_names.end(), system.
variable_name(var)) == filter_names.end()))
958 do_output[sys_ctr][var] = 1;
965 return std::unique_ptr<NumericVector<Number>>(
nullptr);
979 parallel_soln_local_size = div+1;
984 parallel_soln.
init(parallel_soln_global_size,
985 parallel_soln_local_size,
997 unsigned sys_ctr = 0;
999 for (; pos !=
end; ++pos, ++sys_ctr)
1001 const System & system = *(pos->second);
1002 const unsigned int nv_sys = system.
n_vars();
1012 libmesh_assert(this->
comm().verify(non_const_sys.
solution->closed()));
1013 if (!non_const_sys.
solution->closed())
1021 std::vector<dof_id_type> dof_indices;
1024 for (
unsigned int var=0; var < nv_sys; ++var)
1027 if (!do_output[sys_ctr][var])
1040 libmesh_assert_equal_to (1, dof_indices.size());
1042 parallel_soln.
set((ne*var_num)+elem->id(), sys_soln(dof_indices[0]));
1049 parallel_soln.
close();
1050 return std::unique_ptr<NumericVector<Number>>(parallel_soln_ptr.release());
1056 const std::set<std::string> * system_names)
const 1058 LOG_SCOPE(
"build_discontinuous_solution_vector()",
"EquationSystems");
1066 unsigned int nv = 0;
1072 for (; pos !=
end; ++pos)
1075 bool use_current_system = (system_names ==
nullptr);
1076 if (!use_current_system)
1077 use_current_system = system_names->count(pos->first);
1078 if (!use_current_system || pos->second->hide_output())
1081 const System & system = *(pos->second);
1090 tw += elem->n_nodes();
1097 std::vector<Number> sys_soln;
1100 unsigned int var_num=0;
1111 for (; pos !=
end; ++pos)
1114 bool use_current_system = (system_names ==
nullptr);
1115 if (!use_current_system)
1116 use_current_system = system_names->count(pos->first);
1117 if (!use_current_system || pos->second->hide_output())
1120 const System & system = *(pos->second);
1121 const unsigned int nv_sys = system.
n_vars();
1127 std::vector<Number> elem_soln;
1128 std::vector<Number> nodal_soln;
1129 std::vector<dof_id_type> dof_indices;
1131 for (
unsigned int var=0; var<nv_sys; var++)
1144 elem_soln.resize(dof_indices.size());
1146 for (std::size_t i=0; i<dof_indices.size(); i++)
1147 elem_soln[i] = sys_soln[dof_indices[i]];
1155 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 1157 if (!elem->infinite())
1160 libmesh_assert_equal_to (nodal_soln.size(), elem->n_nodes());
1162 for (
unsigned int n=0; n<elem->n_nodes(); n++)
1164 soln[nv*(nn++) + (var + var_num)] +=
1170 nn += elem->n_nodes();
1183 const Real threshold,
1184 const bool verbose)
const 1188 std::vector<bool> os_result;
1194 libMesh::out <<
" Fatal difference. This system handles " 1195 << this->
n_systems() <<
" systems," << std::endl
1196 <<
" while the other system handles " 1198 <<
" systems." << std::endl
1199 <<
" Aborting comparison." << std::endl;
1209 for (; pos !=
end; ++pos)
1211 const std::string & sys_name = pos->first;
1212 const System & system = *(pos->second);
1217 os_result.push_back (system.
compare (other_system, threshold, verbose));
1225 if (os_result.size()==0)
1233 os_identical = os_result[n];
1236 while (os_identical && n<os_result.size());
1237 return os_identical;
1245 std::ostringstream oss;
1247 oss <<
" EquationSystems\n" 1248 <<
" n_systems()=" << this->
n_systems() <<
'\n';
1254 for (; pos !=
end; ++pos)
1255 oss << pos->second->get_info();
1303 for (; pos !=
end; ++pos)
1304 tot += pos->second->n_vars();
1318 for (; pos !=
end; ++pos)
1319 tot += pos->second->n_dofs();
1334 for (; pos !=
end; ++pos)
1335 tot += pos->second->n_active_dofs();
1354 this->
get_system(sys_num).get_dof_map().remove_default_ghosting();
EquationSystems(MeshBase &mesh)
std::string name(const ElemQuality q)
Manages the family, order, etc. parameters for a given FE.
Manages multiples systems of equations.
unsigned int n_vars() const
void build_variable_names(std::vector< std::string > &var_names, const FEType *type=nullptr, const std::set< std::string > *system_names=nullptr) const
void update_global_solution(std::vector< Number > &global_soln) const
unsigned int n_systems() const
const Variable & variable(unsigned int var) const
bool _enable_default_ghosting
Specifies parameters for parameter sensitivity calculations.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
std::unique_ptr< NumericVector< Number > > build_parallel_elemental_solution_vector(std::vector< std::string > &names) const
std::size_t n_dofs() const
Used to specify quantities of interest in a simulation.
processor_id_type size() const
void add_default_ghosting()
const T_sys & get_system(const std::string &name) const
virtual ~EquationSystems()
void print_info(std::ostream &os=libMesh::out) const
static FEFieldType field_type(const FEType &fe_type)
std::unique_ptr< NumericVector< Number > > build_parallel_solution_vector(const std::set< std::string > *system_names=nullptr) const
const Parallel::Communicator & comm() const
virtual void enable_default_ghosting(bool enable)
void clean_refinement_flags()
static const Real TOLERANCE
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
virtual void adjoint_solve(const QoISet &qoi_indices=QoISet())
const Parallel::Communicator & _communicator
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
virtual std::string get_info() const
virtual void prolong_vectors()
signed char & underrefined_boundary_limit()
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
Manages the degrees of freedom (DOFs) in a simulation.
void get_vars_active_subdomains(const std::vector< std::string > &names, std::vector< std::set< subdomain_id_type >> &vars_active_subdomains) const
virtual void sensitivity_solve(const ParameterVector ¶meters)
std::map< std::string, System * >::const_iterator const_system_iterator
virtual void reinit_systems()
processor_id_type n_processors() const
virtual bool is_serial() const
unsigned int number() const
A variable which is solved for in a System of equations.
const std::set< subdomain_id_type > & active_subdomains() const
Responsible for mesh refinement algorithms and data.
virtual SimpleRange< element_iterator > element_ptr_range()=0
dof_id_type numeric_index_type
processor_id_type rank() const
virtual node_iterator local_nodes_end()=0
std::map< std::string, System * >::iterator system_iterator
Manages consistently variables, degrees of freedom, and coefficient vectors.
void delete_system(const std::string &name)
virtual SimpleRange< node_iterator > node_ptr_range()=0
virtual dof_id_type max_elem_id() const =0
std::unique_ptr< NumericVector< Number > > solution
void distribute_dofs(MeshBase &)
virtual System & add_system(const std::string &system_type, const std::string &name)
const std::string & variable_name(const unsigned int i) const
virtual void restrict_vectors()
bool active_on_subdomain(subdomain_id_type sid) const
unsigned char & face_level_mismatch_limit()
An object whose state is distributed along a set of processors.
static unsigned int n_vec_dim(const MeshBase &mesh, const FEType &fe_type)
virtual void reinit_constraints()
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
virtual numeric_index_type first_local_index() const =0
virtual node_iterator local_nodes_begin()=0
void get_solution(std::vector< Number > &soln, std::vector< std::string > &names) const
const FEType & variable_type(const unsigned int i) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual bool contract()=0
T & set(const std::string &)
void build_solution_vector(std::vector< Number > &soln, const std::string &system_name, const std::string &variable_name="all_vars") const
signed char & overrefined_boundary_limit()
void remove_default_ghosting()
void _remove_default_ghosting(unsigned int sys_num)
const MeshBase & get_mesh() const
std::size_t n_active_dofs() const
unsigned int mesh_dimension() const
std::unique_ptr< NumericVector< Number > > current_local_solution
virtual bool compare(const System &other_system, const Real threshold, const bool verbose) const
virtual void set(const numeric_index_type i, const T value)=0
static void nodal_soln(const unsigned int dim, const FEType &fe_t, const Elem *elem, const std::vector< Number > &elem_soln, std::vector< Number > &nodal_soln)
virtual bool compare(const EquationSystems &other_es, const Real threshold, const bool verbose) const
unsigned int n_vars() const
virtual dof_id_type max_node_id() const =0
virtual dof_id_type n_elem() const =0
virtual void add(const numeric_index_type i, const T value)=0
processor_id_type processor_id() const
OStreamProxy out(std::cout)
void build_discontinuous_solution_vector(std::vector< Number > &soln, const std::set< std::string > *system_names=nullptr) const
void _add_system_to_nodes_and_elems()
const DofMap & get_dof_map() const
std::ostream & operator<<(std::ostream &os, const FEAbstract &fe)
virtual numeric_index_type last_local_index() const =0
void build_elemental_solution_vector(std::vector< Number > &soln, std::vector< std::string > &names) const
std::map< std::string, System * > _systems