r/CFD • • Jul 03 '19

[July] Software Engineering for CFD

As per the discussion topic vote, July's monthly topic is software engineering for CFD.

Previous discussions: https://www.reddit.com/r/CFD/wiki/index

15 Upvotes

32 comments sorted by

View all comments

Show parent comment

1

u/AgAero Jul 18 '19

My rule of thumb is that any constant data needed to evaluate a particular model gets wrapped up into an object with a constructor that does all necessary initialization, e.g. allocate arrays and populates from file.

If I'm reading this correctly, that seems to be the anti-pattern of 'defining a class with at most one other function besides init'. Do you have entire classes devoted to creating reader objects for each bit of constant data?

some functions now take long lists of argument where before they just reached to global arrays

Is there another way around this you think? You can throw things together into a struct of course and just pass that around, but maybe there's no benefit to doing so.

I run into similar issues regularly and haven't decided on a 'better' way to do things yet.

1

u/bike0121 Jul 19 '19

Is there another way around this you think?

Instead of passing large amounts of data to and from functions, an OO approach would be to have these functions actually be methods belonging to an object holding most of the data that would be operated on.

1

u/AgAero Jul 19 '19

Instead of passing large amounts of data to and from functions,

That's not quite what I intended with that statement. If you've got large amounts of data that you don't want to pass around, just pass references to them instead.

If your argument lists are getting tediously long on the other hand, pass a dictionary object of some sort as your argument. That would be my workaround most likely, but I'll admit there is still probably a better way.

an OO approach would be to have these functions actually be methods belonging to an object holding most of the data that would be operated on.

There are times when you want your algorithm to be decoupled from your data though, correct? I'm not sure I understand what you're saying here exactly.

Suppose you wanted to swap out time integration schemes for example. You could write an integrator class that produces an integrator object given a specified scheme. To make use of this object, you'd have to pass the data in somehow right? You wouldn't want it to have all the field data itself I don't think.