libMesh / libmesh

libMesh github repository
http://libmesh.github.io
GNU Lesser General Public License v2.1
653 stars 286 forks source link

How to load multiple nodes? #2490

Closed ermore closed 3 years ago

ermore commented 4 years ago

I have a question about how to use libmesh .I'm not familiar with it at present.

  1. If I load multiple nodes instead of the face, I write the following code, but the corresponding node will be calculated repeatedly for the activate local mesh.
    for (const auto &elem : mesh.active_local_element_ptr_range())
    {
    //1. Calculate element stiffness matrix
    // .......
    // 2. calculate RSH the corresponding node will be calculated repeatedly for the activate local mesh??
    for(auto nodes : elem->node_index_range()){
            if(mesh.get_boundary_info().has_boundary_id(elem->node_ptr(nodes),FORCE_BOUNDARYID)){
                Fe_var[1](nodes) = -100;
            }
        }
    }
  2. How to apply load on edge in 3D problems?

    Is there an example of how to apply boundary conditions and loads (from user specified set nodes or edge or face) in the example or test folder?

jwpeterson commented 4 years ago
for(auto nodes : elem->node_index_range()){

This is a range-based for loop syntax, so the variable "nodes" in this case is poorly named. Within the body of the loop it is a pointer to a single Node node index.

~~Furthermore elem->node_ptr(nodes) doesn't make sense, since the Elem::node_ptr() function takes a single index for its argument. I can't quite understand exactly what you are trying to do, but maybe you are trying to explicitly set values in element rhs vectors, which should be straightforward once you fix the errors I mentioned above...~~

ermore commented 4 years ago

For the whole model, I know the load on some nodes, these nodes may come from different elements, how should I set it up?

jwpeterson commented 4 years ago

I edited my original comment, sorry, it must have been too early in the morning. It looks like what you are doing is actually pretty close. If you want to avoid applying the load multiple times as you encounter the same node from multiple elements, you could keep track of nodes you have already encountered in a separate container (e.g. std::set) and then skip them the next time you come across them?