CArl
Code Arlequin / C++ implementation
libmesh_assemble_lin_homogeneous__traction_test.cpp
Go to the documentation of this file.
2 
3 int main(int argc, char** argv) {
4 
5  // [USER] Fixed boudary
7 
8  // [USER] Traction force density
9  std::vector<double> traction_density(3,0);
10  traction_density[0] = 100.;
11 
12  // --- Initialize libMesh
13  libMesh::LibMeshInit init(argc, argv);
14 
15  // Do performance log?
16  const bool MASTER_bPerfLog_carl_libmesh = true;
17  libMesh::PerfLog perf_log("Main program", MASTER_bPerfLog_carl_libmesh);
18 
19  // libMesh's C++ / MPI communicator wrapper
20  libMesh::Parallel::Communicator& WorldComm = init.comm();
21 
22  // Number of processors and processor rank.
23  int rank = WorldComm.rank();
24  int nodes = WorldComm.size();
25 
26  // --- Set up inputs
27 
28  // Command line parser
29  GetPot command_line(argc, argv);
30 
31  // File parser
32  GetPot field_parser;
33 
34  // If there is an input file, parse it to get the parameters. Else, parse the command line
35  std::string input_filename;
36  if (command_line.search(2, "--inputfile", "-i")) {
37  input_filename = command_line.next(input_filename);
38  field_parser.parse_input_file(input_filename, "#", "\n", " \t\n");
39  } else {
40  field_parser = command_line;
41  }
42 
43  libmesh_assemble_input_params input_params;
44  get_input_params(field_parser, input_params);
45 
46  // Check libMesh installation dimension
47  const unsigned int dim = 3;
48 
49  libmesh_example_requires(dim == LIBMESH_DIM, "3D support");
50 
51  // --- Declare the three meshes to be intersected
52 
53  // - Parallelized meshes: A, B, mediator and weight
54  perf_log.push("Meshes - Parallel","Read files:");
55  libMesh::Mesh system_mesh(WorldComm, dim);
56  system_mesh.read(input_params.mesh_file);
57  system_mesh.prepare_for_use();
58 
59  libMesh::Mesh mesh_weight(WorldComm, dim);
60  mesh_weight.allow_renumbering(false);
61  mesh_weight.read(input_params.mesh_weight_file);
62  mesh_weight.prepare_for_use();
63 
64  perf_log.pop("Meshes - Parallel","Read files:");
65 
66  // --- Generate the equation systems
67  perf_log.push("System setup:");
68 
69  // Set the equation systems object
70  libMesh::EquationSystems equation_systems(system_mesh);
71 
72  // Add linear elasticity and physical parameters systems
73  libMesh::LinearImplicitSystem& elasticity_system
74  = add_elasticity(equation_systems);
75 
76  // Set clamped border
77  set_clamped_border(elasticity_system, fixed_bound_id);
78 
79  // Initialize the equation systems
80  equation_systems.init();
81 
82  // Homogeneous properties for the macro system
83  set_homogeneous_physical_properties(equation_systems, input_params.physical_params_file);
84 
85  // Set the weight function object
86  weight_parameter_function system_weight(mesh_weight);
87  system_weight.set_parameters(input_params.weight_domain_idx_file);
88 
89  perf_log.pop("System setup:");
90 
91  // Assemble!
92  assemble_elasticity_with_weight_and_traction(equation_systems,"Elasticity",system_weight,
93  input_params.system_type,
95  traction_density);
96 
97 // Print MatLab debugging output? Variable defined at "carl_headers.h"
98 #ifdef PRINT_MATLAB_DEBUG
99  elasticity_system.matrix->print_matlab(input_params.output_base + "_sys_mat.m");
100  elasticity_system.rhs->print_matlab(input_params.output_base + "_sys_rhs_vec.m");
101 #endif
102 
103  // Export matrix and vector
104  libMesh::PetscMatrix<libMesh::Number> * temp_mat_ptr = libMesh::cast_ptr<libMesh::PetscMatrix<libMesh::Number> * >(elasticity_system.matrix);
105  libMesh::PetscVector<libMesh::Number> * temp_vec_ptr = libMesh::cast_ptr<libMesh::PetscVector<libMesh::Number> * >(elasticity_system.rhs);
106 
107  carl::write_PETSC_matrix(*temp_mat_ptr, input_params.output_base + "_sys_mat.petscmat");
108  carl::write_PETSC_vector(*temp_vec_ptr, input_params.output_base + "_sys_rhs_vec.petscvec");
109 
110  // If needed, print rigid body vectors
111  if(input_params.bCalculateRBVectors)
112  {
113  MatNullSpace nullsp_sys;
114  build_rigid_body_vectors(elasticity_system,nullsp_sys);
115  write_rigid_body_vectors(nullsp_sys,input_params.output_base,WorldComm.rank());
116  MatNullSpaceDestroy(&nullsp_sys);
117  }
118 
119  return 0;
120 }
void set_homogeneous_physical_properties(libMesh::EquationSystems &es, std::string &physicalParamsFile)
Set the homogeneous physical properties from a file.
void write_rigid_body_vectors(MatNullSpace &nullsp_sys, const std::string output_base, int rank)
Export the rigid body mode vectors to a folder.
std::string mesh_weight_file
Path to the mesh containing the weight region indices.
void get_input_params(GetPot &field_parser, feti_iterate_params &input_params)
Parser function for the coupled solver test programs.
bool bCalculateRBVectors
Build and export the rigid body modes vectors?
void set_parameters(double alpha_eps, double alpha_coupling_BIG, int subdomain_idx_BIG, int subdomain_idx_micro, int subdomain_idx_both, int subdomain_idx_coupling)
void assemble_elasticity_with_weight_and_traction(libMesh::EquationSystems &es, const std::string &system_name, weight_parameter_function &weight_mask, WeightFunctionSystemType system_type, int traction_boundary_id, std::vector< double > traction_density)
Assemble homogeneous elasticity with domain weights and traction.
void write_PETSC_vector(libMesh::PetscVector< libMesh::Number > &input_vec, const std::string &filename, int dim=1)
std::string physical_params_file
Physical parameters.
void build_rigid_body_vectors(libMesh::ImplicitSystem &input_system, MatNullSpace &nullsp_sys)
Build the rigid body modes associated to a given system.
void set_clamped_border(libMesh::ImplicitSystem &elasticity_system, int boundary_id)
Set a clamped border.
libMesh::ImplicitSystem & add_elasticity(libMesh::EquationSystems &input_systems, libMesh::Order order=libMesh::FIRST, libMesh::FEFamily family=libMesh::LAGRANGE)
Add a linear elasticity libMesh::LinearImplicitSystem to the input libMesh::EquationSystems& input_sy...
boundary_id_cube
Small enumerate defining a cube's boundary ID's.
std::string weight_domain_idx_file
Path to the file identifying the weight function regions.
WeightFunctionSystemType system_type
Indicates if the system to be assembled is a micro or a macro system (used to choose the proper weigh...
std::string mesh_file
Path to the system mesh.
int main(int argc, char **argv)
std::string output_base
Output filename base.
void write_PETSC_matrix(Mat input_mat, const std::string &filename, int rank, MPI_Comm comm=PETSC_COMM_WORLD, int dim=1)