18 using namespace basis;
20 using namespace utils;
41 void State::load_mesh(GEO::Mesh &meshin,
const std::function<
int(
const size_t,
const std::vector<int> &,
const RowVectorNd &,
bool)> &boundary_marker,
bool non_conforming,
bool skip_boundary_sideset)
47 logger().info(
"Loading mesh...");
51 logger().error(
"Unable to load the mesh");
56 mesh->bounding_box(min, max);
58 logger().info(
"mesh bb min [{}], max [{}]", min, max);
60 if (!skip_boundary_sideset)
61 mesh->compute_boundary_ids(boundary_marker);
63 std::vector<std::shared_ptr<assembler::Assembler>> assemblers;
74 logger().info(
" took {}s", timer.getElapsedTime());
77 logger().info(
"Loading obstacles...");
83 args[
"root_path"],
mesh->dimension());
86 logger().info(
" took {}s", timer.getElapsedTime());
92 const std::vector<std::string> &names,
93 const std::vector<Eigen::MatrixXi> &cells,
94 const std::vector<Eigen::MatrixXd> &vertices)
96 assert(names.size() == cells.size());
97 assert(vertices.size() == cells.size());
104 logger().info(
"Loading mesh ...");
110 args[
"geometry"],
args[
"root_path"],
111 names, vertices, cells, non_conforming);
127 mesh->bounding_box(min, max);
129 logger().info(
"mesh bb min [{}], max [{}]", min, max);
131 std::vector<std::shared_ptr<assembler::Assembler>> assemblers;
142 logger().info(
" took {}s", timer.getElapsedTime());
147 logger().info(
"Loading obstacles...");
153 args[
"root_path"],
mesh->dimension(), names, vertices, cells);
155 logger().info(
" took {}s", timer.getElapsedTime());
160 assert(
bases.size() ==
mesh->n_elements());
162 const int dim =
mesh->dimension();
164 V.resize(n_vertices, dim);
165 F.resize(
bases.size(), dim + 1);
167 for (
int i = 0; i <
bases.size(); i++)
170 for (
int j = 0; j < element.
bases.size(); j++)
173 assert(basis.
global().size() == 1);
176 F(i, j) = basis.
global()[0].index;
181 std::unordered_map<int, std::array<bool, 3>>
184 assert(
args[
"boundary_conditions"].contains(bc_type));
185 const std::vector<json> json_bcs =
json_as_array(
args[
"boundary_conditions"][bc_type]);
186 std::unordered_map<int, std::array<bool, 3>> bcs;
187 for (
const json &bc : json_bcs)
189 assert(bc[
"dimension"].size() >=
mesh->dimension());
190 std::array<bool, 3> dimension{{
true,
true,
true}};
191 for (
int d = 0; d < bc[
"dimension"].size(); ++d)
192 dimension[d] = bc[
"dimension"][d];
194 assert(bc.contains(
"id") && bc[
"id"].is_number_integer());
195 bcs[bc[
"id"].get<
int>()] = dimension;
int n_bases
number of bases
int n_pressure_bases
number of pressure bases
mesh::Obstacle obstacle
Obstacles used in collisions.
std::shared_ptr< assembler::Assembler > assembler
assemblers
io::OutGeometryData out_geom
visualization stuff
void load_mesh(bool non_conforming=false, const std::vector< std::string > &names=std::vector< std::string >(), const std::vector< Eigen::MatrixXi > &cells=std::vector< Eigen::MatrixXi >(), const std::vector< Eigen::MatrixXd > &vertices=std::vector< Eigen::MatrixXd >())
loads the mesh from the json arguments
std::vector< basis::ElementBases > geom_bases_
Geometric mapping bases, if the elements are isoparametric, this list is empty.
void set_materials(std::vector< std::shared_ptr< assembler::Assembler > > &assemblers) const
set the material and the problem dimension
std::map< int, basis::InterfaceData > poly_edge_to_data
nodes on the boundary of polygonal elements, used for harmonic bases
std::vector< basis::ElementBases > pressure_bases
FE pressure bases for mixed elements, the size is #elements.
std::shared_ptr< assembler::Assembler > pressure_assembler
std::shared_ptr< assembler::Mass > mass_matrix_assembler
std::unique_ptr< mesh::Mesh > mesh
current mesh, it can be a Mesh2D or Mesh3D
void reset_mesh()
Resets the mesh.
std::unordered_map< int, std::array< bool, 3 > > boundary_conditions_ids(const std::string &bc_type) const
Construct a vector of boundary conditions ids with their dimension flags.
StiffnessMatrix mass
Mass matrix, it is computed only for time dependent problems.
json args
main input arguments containing all defaults
std::vector< basis::ElementBases > bases
FE bases, the size is #elements.
std::vector< mesh::LocalBoundary > local_boundary
mapping from elements to nodes for dirichlet boundary conditions
std::vector< int > boundary_nodes
list of boundary nodes
std::vector< mesh::LocalBoundary > local_neumann_boundary
mapping from elements to nodes for neumann boundary conditions
void build_mesh_matrices(Eigen::MatrixXd &V, Eigen::MatrixXi &F)
Build the mesh matrices (vertices and elements) from the mesh using the bases node ordering.
std::shared_ptr< assembler::MixedAssembler > mixed_assembler
std::map< int, Eigen::MatrixXd > polys
polygons, used since poly have no geom mapping
Eigen::MatrixXd rhs
System right-hand side.
Represents one basis function and its gradient.
const std::vector< Local2Global > & global() const
Stores the basis functions for a given element in a mesh (facet in 2d, cell in 3d).
std::vector< Basis > bases
one basis function per node in the element
void init_sampler(const polyfem::mesh::Mesh &mesh, const double vismesh_rel_area)
unitalize the ref element sampler
static std::unique_ptr< Mesh > create(const std::string &path, const bool non_conforming=false)
factory to build the proper mesh
Obstacle read_obstacle_geometry(const Units &units, const json &geometry, const std::vector< json > &displacements, const std::vector< json > &dirichlets, const std::string &root_path, const int dim, const std::vector< std::string > &_names, const std::vector< Eigen::MatrixXd > &_vertices, const std::vector< Eigen::MatrixXi > &_cells, const bool non_conforming)
read a FEM mesh from a geometry JSON
std::unique_ptr< Mesh > read_fem_geometry(const Units &units, const json &geometry, const std::string &root_path, const std::vector< std::string > &_names, const std::vector< Eigen::MatrixXd > &_vertices, const std::vector< Eigen::MatrixXi > &_cells, const bool non_conforming)
read FEM meshes from a geometry JSON array (or single)
std::vector< T > json_as_array(const json &j)
Return the value of a json object as an array.
bool is_param_valid(const json ¶ms, const std::string &key)
Determine if a key exists and is non-null in a json object.
spdlog::logger & logger()
Retrieves the current logger.
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
void log_and_throw_error(const std::string &msg)