void DependencyResolverTest::ptrTest() { DependencyResolver<int *> resolver; int *mat3 = new int; int *mat1 = new int; int *mat2 = new int; resolver.insertDependency(mat2, mat1); resolver.insertDependency(mat3, mat1); resolver.insertDependency(mat3, mat2); std::vector<int *> sorted(3); sorted[0] = mat1; sorted[1] = mat2; sorted[2] = mat3; /*const std::vector<std::set<int *> > & sets =*/ resolver.getSortedValuesSets(); std::sort(sorted.begin(), sorted.end(), resolver); CPPUNIT_ASSERT( sorted[0] == mat1); CPPUNIT_ASSERT( sorted[1] == mat2); CPPUNIT_ASSERT( sorted[2] == mat3); delete mat1; delete mat2; delete mat3; }
void DependencyResolverTest::simpleTest() { DependencyResolver<int> resolver; int mat3 = 3; int mat1 = 1; int mat2 = 2; resolver.insertDependency(mat2, mat1); resolver.insertDependency(mat3, mat1); resolver.insertDependency(mat3, mat2); std::vector<int> sorted(3); sorted[0] = mat1; sorted[1] = mat2; sorted[2] = mat3; /*const std::vector<std::set<int> > & sets =*/ resolver.getSortedValuesSets(); std::sort(sorted.begin(), sorted.end(), resolver); CPPUNIT_ASSERT( sorted[0] == mat1); CPPUNIT_ASSERT( sorted[1] == mat2); CPPUNIT_ASSERT( sorted[2] == mat3); }
void MooseApp::executeMeshModifiers() { DependencyResolver<MooseSharedPointer<MeshModifier> > resolver; // Add all of the dependencies into the resolver and sort them for (std::map<std::string, MooseSharedPointer<MeshModifier> >::const_iterator it = _mesh_modifiers.begin(); it != _mesh_modifiers.end(); ++it) { // Make sure an item with no dependencies comes out too! resolver.addItem(it->second); std::vector<std::string> & modifiers = it->second->getDependencies(); for (std::vector<std::string>::const_iterator depend_name_it = modifiers.begin(); depend_name_it != modifiers.end(); ++depend_name_it) { std::map<std::string, MooseSharedPointer<MeshModifier> >::const_iterator depend_it = _mesh_modifiers.find(*depend_name_it); if (depend_it == _mesh_modifiers.end()) mooseError("The MeshModifier \"" << *depend_name_it << "\" was not created, did you make a spelling mistake or forget to include it in your input file?"); resolver.insertDependency(it->second, depend_it->second); } } const std::vector<MooseSharedPointer<MeshModifier> > & ordered_modifiers = resolver.getSortedValues(); if (ordered_modifiers.size()) { MooseMesh * mesh = _action_warehouse.mesh().get(); MooseMesh * displaced_mesh = _action_warehouse.displacedMesh().get(); // Run the MeshModifiers in the proper order for (std::vector<MooseSharedPointer<MeshModifier> >::const_iterator it = ordered_modifiers.begin(); it != ordered_modifiers.end(); ++it) { MeshModifier * modifier_ptr = it->get(); modifier_ptr->setMeshPointer(mesh); modifier_ptr->modify(); if (displaced_mesh) { modifier_ptr->setMeshPointer(displaced_mesh); modifier_ptr->modify(); } } mesh->prepared(false); if (displaced_mesh) displaced_mesh->prepared(false); } // Clear the modifiers, they are not used again during the simulation _mesh_modifiers.clear(); }
void MooseApp::executeMeshModifiers() { DependencyResolver<std::shared_ptr<MeshModifier>> resolver; // Add all of the dependencies into the resolver and sort them for (const auto & it : _mesh_modifiers) { // Make sure an item with no dependencies comes out too! resolver.addItem(it.second); std::vector<std::string> & modifiers = it.second->getDependencies(); for (const auto & depend_name : modifiers) { auto depend_it = _mesh_modifiers.find(depend_name); if (depend_it == _mesh_modifiers.end()) mooseError("The MeshModifier \"", depend_name, "\" was not created, did you make a " "spelling mistake or forget to include it " "in your input file?"); resolver.insertDependency(it.second, depend_it->second); } } const auto & ordered_modifiers = resolver.getSortedValues(); if (ordered_modifiers.size()) { MooseMesh * mesh = _action_warehouse.mesh().get(); MooseMesh * displaced_mesh = _action_warehouse.displacedMesh().get(); // Run the MeshModifiers in the proper order for (const auto & modifier : ordered_modifiers) modifier->modifyMesh(mesh, displaced_mesh); /** * Set preparation flag after modifers are run. The final preparation * will be handled by the SetupMeshComplete Action. */ mesh->prepared(false); if (displaced_mesh) displaced_mesh->prepared(false); } }