Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geometry class #147

Merged
merged 13 commits into from
Jul 25, 2024
Merged

Geometry class #147

merged 13 commits into from
Jul 25, 2024

Conversation

AliHaider93
Copy link
Contributor

A class to incapsulate the geometry of LS-DYNA part.

@@ -25,12 +25,14 @@

#ifndef KPARSER_INCLUDED
#define KPARSER_INCLUDED
#define FIRST_NODE 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? Where is it used?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You see that you are getting into trouble with the primitives names. How about not having a setName() but setBaseName() and not getName() but getNames() which returns a list of names? In case of the Bot, it would be the base name with a ".bot" attached. In case of the Arbs, it could be a list of base-name + "." + number + ".arb".

Copy link
Contributor Author

@AliHaider93 AliHaider93 Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? Where is it used?

it's not used any more, I was trying to make a loop and I defined it. I will rimove it. Edit: it is used in k_parser.cpp to fill the nodes in the vector using a loop

image

I can just use i_n+2 because it's a fixed format, but this seamed nicer. what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You see that you are getting into trouble with the primitives names. How about not having a setName() but setBaseName() and not getName() but getNames() which returns a list of names? In case of the Bot, it would be the base name with a ".bot" attached. In case of the Arbs, it could be a list of base-name + "." + number + ".arb".

okay, this seems to be more coherent, I am working on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only problem with setBaseName() is in the case of arbs the elements numbers doesn't have to be consequent starting from (1 to n). so if we want to preserve the number of Hex element we have to keep naming the arbs following the .k file. I will update the pull request and then you can tell me what you think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated with getNames() and setBaseName(), I will change also Arbs::write() and Bot::write().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? Where is it used?

it's not used any more, I was trying to make a loop and I defined it. I will remove it. Edit: it is used in k_parser.cpp to fill the nodes in the vector using a loop

image

I can just use i_n+2 because it's a fixed format, but this seamed nicer. what do you think?

Okay, that's a reason. However, in this case, it should be kept in k_parser.cpp (declaration/definition) and a const size_t, e.g.

const size_t FirstNode = 2;

for (std::map<std::string, rt_arb_internal>::iterator it = arbs.begin(); it != arbs.end(); it++) {
std::string arbName = name;
arbName += it->first;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, putting a point "." between the base name and the index?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's better , I will update

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a question about the constructors and destructors, first the arb constructor
image
is RT_ARBN_INTERNAL_MAGIC the one to go even with arb4, arb5, arb6, arb7?
and for Geomtry I think it doesn't need a constructor or a destructor or am I wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then I will handle the other arbs and I can clean the code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need the RT_ARB_INTERNAL_MAGIC here. This is for the rt_arb_internal.

arbn is very different from the arb4 ... arb8.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Geometry class, the standard constructor and destructor should do.


std::string arbNumber = std::to_string(*itr);

geometry.addArb(arbNumber.c_str(), point1, point2, point3, point4, point5, point6, point7, point8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot of duplicated code. How about writing a helper function AddArb(), which gets n1, ..., n8 as parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, working on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also relized that I made a mistake in the condition for arb4, when the nodes.size()==4 it is also the shell element that we devided into two triangles

VSET(temp.pt[4], point5[0], point5[1], point5[2]);
VSET(temp.pt[5], point6[0], point6[1], point6[2]);
VSET(temp.pt[6], point7[0], point7[1], point7[2]);
VSET(temp.pt[7], point8[0], point8[1], point8[2]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible, to use VMOVE() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's possible, I updated the code

Copy link
Contributor Author

@AliHaider93 AliHaider93 Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wrote the function AddArb, let me know what you think about it. for arb4 I will resolve it later, I am trying to undrstand the logic in LS-DYNA Solid elment.

}
else {
bot.addTriangle(point1, point2, point3);
bot.addTriangle(point1, point3, point4);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is here an issue with a closing bracket?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think so, I have tested the code with a solid element and shell element. I will retest now to see if there is something wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it, no problems.

mk_addmember(names[i].c_str(), &(geometry_head.l), NULL, WMOP_UNION);
mk_addmember(names[i].c_str(), &(all_head.l), NULL, WMOP_UNION);
}
mk_lfcomb(wdbp, geometry.getBaseName(), &geometry_head, 0);

if (region_attributes.size() > 0) {
writeAttributes(wdbp, region_name.c_str(), region_attributes);
}

mk_addmember(region_name.c_str(), &(all_head.l), NULL, WMOP_UNION);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a tab in this line, which should not be there.

void setName(const char* value);

void addArb(
const char* arbName,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line break intentionally? (similar in arbs.cpp)


mk_addmember(bot.getName(), &(bot_head.l), NULL, WMOP_UNION);
mk_lfcomb(wdbp, region_name.c_str(), &bot_head, 0);
for (int i = 0; i < names.size(); i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting a compilation error on Debian bookworm here:

/home/rossberg/Devel/BRL-CAD/brlcad.devel_k-g/src/conv/k-g/region_list.cpp: In member function ‘void RegionList::create(rt_wdb*)’:
/home/rossberg/Devel/BRL-CAD/brlcad.devel_k-g/src/conv/k-g/region_list.cpp:111:27: error: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} [-Werror=sign-compare]
  111 |         for (int i = 0; i < names.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~

Changing int to size_t solves this.

@@ -140,7 +142,7 @@ Bot& RegionList::getBot
(
const std::string& name
) {
return m_list[name].bot;
return m_list[name].geometry.getBot();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting a compilation error on Debian bookworm here:

/home/rossberg/Devel/BRL-CAD/brlcad.devel_k-g/src/conv/k-g/region_list.cpp: In member function ‘Bot& RegionList::getBot(const std::string&)’:
/home/rossberg/Devel/BRL-CAD/brlcad.devel_k-g/src/conv/k-g/region_list.cpp:145:40: error: cannot bind non-const lvalue reference of type ‘Bot&’ to an rvalue of type ‘Bot’
  145 |     return m_list[name].geometry.getBot();
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

getBot() doesn't return a reference.

}


Bot Geometry::getBot(void) const{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should change the return type to reference here.

@drossberg drossberg merged commit 91dd7c9 into BRL-CAD:devel_k-g Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants