Hi,
I am trying to create a simulation where I try to add a single element using the AddDiscreteElement plugin. I took the help of the spherical rain demo for the simulation. I was successful in that part. Now I want to Initialise sensors for the the single particle w.r.t time and displacement. I had written my addElement.cpp like this, #include "GranOO3/Core/Problem.hpp" #include "GranOO3/Core/Domain.hpp" #include "PlugIn_AddDiscreteElement.hpp" // Plugin registration definition: REGISTER_GRANOO_PLUGIN(PlugIn_AddElement); PlugIn_AddElement::PlugIn_AddElement() : Core::PlugInInterface<PlugIn_AddElement>(), _x(), _y(), _z(), _r(), _max_number(1) { } PlugIn_AddElement::~PlugIn_AddElement() { } void PlugIn_AddElement::parse_xml() { Core::XmlParser& parser = Core::XmlParser::get(); parser.read_attribute(Attr::GRANOO_REQUIRED, "xPos", _x); parser.read_attribute(Attr::GRANOO_REQUIRED, "yPos", _y); parser.read_attribute(Attr::GRANOO_REQUIRED, "zPos", _z); parser.read_attribute(Attr::GRANOO_REQUIRED, "r1", _r); parser.read_attribute(Attr::GRANOO_REQUIRED, "MaxNumber", _max_number); } void PlugIn_AddElement::init() { } void PlugIn_AddElement::run() { //build discrete element const unsigned int maxTry = 1; const double density = 1000.; for (unsigned int loop = 0; loop < maxTry; loop++) { const double x = _x; const double y = _y; const double z = _z; const double r = _r; Geom::Point p(x, y, z); new DEM::DiscreteElement(p, r, density); } // Get the global discrete element set Core::SetOf<DEM::DiscreteElement>& globalSet = Core::SetOf<DEM::DiscreteElement>::get(); // Create new SetOf named 'right' Core::SetOf<DEM::DiscreteElement>* rightSet = new Core::SetOf<DEM::DiscreteElement>("right"); // Add the first discrete element to the 'right' SetOf DEM::DiscreteElement& firstDE = globalSet.first(); rightSet->add(firstDE); } } and my initsensor.cpp like this, void PlugIn_InitSensor::run() { Physic::Time& time = Physic::Time::get(); // Misc Core::Sensor::new_object(time, &Physic::Time::iteration, "Iteration"); Core::Sensor::new_object(time, &Physic::Time::get_elapsed_time, "Time"); // Access the set "right" Core::SetOf<DEM::DiscreteElement>& rightSet = Core::SetOf<DEM::DiscreteElement>::get("right"); DEM::DiscreteElement& el = rightSet(0); Core::Sensor::new_object(el, &DEM::Tool::get_position, "pos"); Core::Sensor::new_object(el, &DEM::Tool::get_linear_velocity, "vel"); } } I am able to compile all the c++ files, but while building the domain, I am getting this error, [RUN] Starting the running loop #################################################### # An error was encountered ! The program must stop # #################################################### You have to fix this problem, you may browse the source files to get more informations... current iteration : 0 current plugin : STEP line : 73 in file : /Users/hitesharunagiri/desktop/granoo/tags/3.0/Lib/GranOO3/Core/SetOfMap.tpp condition : _map.count(str) == 1 ====================== -- Attached message -- ====================== Can't find setOf named right ====================== -- Backtrace -- ====================== 1: GranOO3::Core::SetOfMap<GranOO3::DEM::DiscreteElement>::get_setof(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) 2: PlugIn_InitSensor::run() 3: GranOO3::Core::PlugIn::run_and_init() 4: GranOO3::Core::PlugIn::run_and_init() 5: GranOO3::Core::Problem::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) 6: GranOO3::Core::Problem::run(int, char**) 7: main 8: start Assertion failed: (0), function RaiseUserAssertion, file Macro.cpp, line 74. zsh: abort ./build_2/Single_Rain_Drop ./inp/Single_Rain_Drop.inp hitesharunagiri@Hiteshs-MacBook-Pro single_rain_drop % Am I doing something wrong, or is there a better way to do it. note that the scenario where I need to add a single element using the addelement plugin is compulsory. |
Administrator
|
hello,
you can use the 'pull' method which is safer than 'get' and 'new'. The 'pull' method create on-the-fly the SetOf if it does not exist. ... // in your add element plugin // Create new SetOf named 'right' Core::SetOf<DEM::DiscreteElement>& rightSet = Core::SetOf<DEM::DiscreteElement>::pull("right"); ... // in your plugin initsensor // Access the set "right" Core::SetOf<DEM::DiscreteElement>& rightSet = Core::SetOf<DEM::DiscreteElement>::pull("right"); ... I give you a tip : note that you can use the 'auto' keyword to reduce your code ... // Create new SetOf named 'right' auto& rightSet = Core::SetOf<DEM::DiscreteElement>::pull("right"); ... // Access the set "right" auto& rightSet = Core::SetOf<DEM::DiscreteElement>::pull("right"); ... Cheers, Damien |
Hi,
Thanks for the solution. I was able to solve the error. But I am facing a new error, [RUN] Starting the running loop #################################################### # An error was encountered ! The program must stop # #################################################### You have to fix this problem, you may browse the source files to get more informations... current iteration : 0 current plugin : STEP line : 106 in file : /Users/hitesharunagiri/desktop/granoo/tags/3.0/Lib/GranOO3/Core/SetOfBase.tpp condition : i < size() ====================== -- Attached message -- ====================== Can't access to item with the given rank ====================== -- Backtrace -- ====================== 1: GranOO3::Core::SetOfBase<GranOO3::DEM::DiscreteElement>::get_item_by_rank(unsigned long) 2: PlugIn_InitSensor::run() 3: GranOO3::Core::PlugIn::run_and_init() 4: GranOO3::Core::PlugIn::run_and_init() 5: GranOO3::Core::Problem::run(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) 6: GranOO3::Core::Problem::run(int, char**) 7: main 8: start Assertion failed: (0), function RaiseUserAssertion, file Macro.cpp, line 74. zsh: abort ./build_2/Single_Rain_Drop ./inp/Single_Rain_Drop.inp Is this because in the input file, we first try to enable the initsensor in the pre-processing step, then add element in the processing step. That is why it is not able to figure out the stored particle ?? If this is the case, is there any solution for this? if not, what might be the reason?? |
Administrator
|
hello, yes this is the reason !
You must create the element before adding a sensor on it. If this is not possible, you can create a function to access the object (you can take a look in the 00010 example) Cheers, Damien |
Free forum by Nabble | Edit this page |