Comments (11)
Neither case is ownership, just reference.
The EquationSystems
owns the System
, not the other way around, but the System
may need to use the EquationSystems
that owns it, so it keeps a reference. The EquationSystems
thus needs to destroy the System
before it can finish destroying itself, but because it owns the System
that's not so hard.
The System
doesn't own the Mesh
or vice-versa, but the System
needs to use the Mesh
, so it keeps a reference to it. It wouldn't make any sense for the System
to own the Mesh
, since you can have multiple systems on a Mesh
or zero systems on a Mesh
, but as long as the System
needs to access the Mesh
(including during its own destructor) we can't let the latter be destroyed before the former, and in this case since the user code owns both the EquationSystems
and the Mesh
that destruction ordering is unfortunately not in the library's hands.
It'd be awesome if we could avoid the ability to create dangling references, and we could maybe do some shared_ptr
/weak_ptr
trickery in that vein in some cases, but even if we managed to do so in every case we can without creating leaks, I don't think it would buy us much. The bug
Mesh * m = new Mesh(comm);
EquationSystems es(*m);
delete m;
is just fancier names applied to the bug
int * i = new int(42);
int & iref(*i);
delete i;
iref = 5;
and the only fix for the latter is "don't use C++".
from libmesh.
maybe the DisplacedSystem should just keep a shared_ptr to the DisplacedMesh ?
from libmesh.
- or remove shared pointer to displacedProblem from SolveObject
Yea I don't think that the SolveObject
needs to be an owner of the DisplacedProblem
from libmesh.
I agree with that too.
Should the displacedSystem be an owner of the DisplacedMesh to naturally order the destruction?
from libmesh.
I don't think that would be a natural ordering. I think the algebraic objects should destroy before the geometric ones
from libmesh.
Like I believe this is the right kind of ordering in the ActionWarehouse
/// Mesh class
std::shared_ptr<MooseMesh> _mesh;
/// Possible mesh for displaced problem
std::shared_ptr<MooseMesh> _displaced_mesh;
/// Problem class
std::shared_ptr<FEProblemBase> _problem;
from libmesh.
Can you use a Mesh
without a System
? Yes - we do all the time.
Can you use a System
without a Mesh
? No. In a conceptual sense, perhaps you should be able to? But for data locality reasons the System
writes and reads its own data to the Mesh
(putting DoF indexing on each DofObject
), and that's not going to change any time soon. In an API sense, you can't construct an System
without passing the EquationSystems
it should reference to its destructor, you can't construct an EquationSystems
without giving it a reference to the mesh to use, and "destruct things in the opposite order you construct them" is a heuristic so standard that it's literally built into the C++ language for stack objects; you're able to mix up the order when you're manually managing heap objects, but you're not actually supposed to use any of the many footguns C++ provides.
from libmesh.
So System should (co-)own EquationSystem which should (co-)own the Mesh?
or are you saying we should avoid shared pointers (and rely on a healthy ordering in classes) as it's shooting us in the foot here
from libmesh.
We should destroy objects with references to the MeshBase
before we destroy the MeshBase
. We should probably reduce some of the shared_ptr
usage in MOOSE as it does, by definition, remove some clarity of ownership
from libmesh.
Like we should make sure this doesn't happen:
The displaced problem is destructed AFTER the displaced mesh
from libmesh.
Closing this as it should be expected that the mesh should still be around at the time of destruction given the chain of references in construction that @roystgnr pointed out. We can of course keep discussing the topic though
from libmesh.
Related Issues (20)
- Installation error due to petsc compatibility HOT 12
- constrain_element_matrix changes the col_dofs vector size HOT 3
- Investigating the possibility of only having one solution vector in systems HOT 3
- Make Abaqus node/side ID maps available
- DM type 'libmesh' did not attach the DM to the matrix HOT 6
- Issues with latest libmesh devel -> master merge HOT 1
- Operator `()` of a petsc vector is not safe if used together with `set()` in a threaded loop.
- The 'mesh.read()' operation encounters errors when executed with 2048 processors HOT 1
- ExodusII IO has variable ID bug which can prevent coordinates from being read-in from a file HOT 4
- The release v1.7.2 doesn't have the tarballs attached HOT 1
- "No rule to make target..." installation error on Windows HOT 3
- Install FParser `fptypes.hh` header
- Libmesh out-of-date on spack HOT 3
- install error with vcpkg on linux HOT 5
- Setting a variable to zero in a given iteration
- Issue with metaphysicl tests when running "make check" HOT 5
- Issue with libmetis.so.5 while make install HOT 3
- Implement static condensation
- make error src/base/libmesh_opt_la-libmesh.lo error 1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libmesh.