Reading automatically generated documentation for DOLFIN c++ library [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am trying to read the documentation of the DOLFIN c++ library for finite element modelling located on this link:
https://fenicsproject.org/olddocs/dolfin/1.3.0/python/programmers-reference/index.html
but the documentation is hard to read, so for someone without c++ knowledge how you will read the following specification of parameters for the c++ method eval_cell() of the Expression class (https://fenicsproject.org/docs/dolfin/2017.2.0/python/programmers-reference/cpp/function/Expression.html):
Parameters:
double > & values (Array<) – (Array<double>) The values at the point.
Array< double > & x (const) – (Array<double>) The coordinates of the point.
ufc::cell & cell (const) – (ufc::cell) The cell which contains the given point.

After taking a look at the page t.niese linked in the comments I think this is a automatically generated documentation, with a really bad generator (like really really bad).
So, if we fix the butchered first line, realign some braces here and there and fix the position of const it might become clearer:
Parameters
const Array<double>& values1 – The values at the point.
const Array<double> &x – The coordinates of the point.
const ufc::cell &cell – The cell which contains the given point.
Meaning
You are dealing with a function that takes three parameters, the first and second are of type Array<double>, which seems to be generic container. The third parameter is of type ufc::cell, whatever this is. All three parameters are passed by reference (see the & before each variable name) and not by value. But they are not just passed as reference but actually as const reference (see the const), meaning that the function can't modify the objects you give to it.
I can't however say much about the comments for each parameter.
1 I assume the first parameter is also const, because it got the brackets, where the const is noted in the other two parameters, but this is just guessing.

Related

what does this error mean in general? and how I fix it in this case? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
The error message appears on Xcode that says "invalid operands to binary expression.
in my code I'm using an array of a struct, i'm trying to sort input data in an ascending order, and i'm getting this error message at the "if" condition shown in the print screen at this link:
https://www.dropbox.com/s/0mch2gbxcif0a20/Screen%20Shot%202016-04-27%20at%2012.45.45%20PM.png?dl=0
The Code
if (studentsInfo[i] > studentsInfo[i + 1]) {}
The Error
Invalid operands to binary expression ('students' and 'students')
What do you compare in your program? As I see, you have to compare names, but all you do is compare an array element which is a struct data type.
If you are trying to compare names, you have to use dot "." operator to reach names. After yo compare names, you can change the elements's place.
The error means that > only takes two arguments and you are using it for something else. In this case you are comparing an entire data structure that does not have an override for > operator and is an undefined behavior. StudentsInfo[i] is a data structure that has more than one element in it. Replace the StudentsInfo[i] with StudentsInfo[i].GPA or another element whose data type has a defined > operator.

C++ Function Prototype? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I had this on a test this week and got it wrong. I asked the professor for help and he said we'd go over it next Thursday. I really don't want to wait that long. Can any one on here walk me through it?
Perform the task specified by the following statements:
Write the function prototype for function "doit" that takes an integer array parameter "list" and an integer "size" parameter and returns a boolean value.
Thanks in advance for any help
bool doit(int list[], int size);
The function doit takes an array of integers as first parameter, and the size of the array (which is an integer) as second parameter. It returns a boolean (true or false).
This sort of function prototype is typically used to access each element of the array within a for loop (with size as terminating condition). The boolean return value could inform of the presence or absence of some value in the array for example, or if some work could or could not be performed.
A little bit of help is there :
RETURN_TYPE FUNCTION_NAME (ARGUMENT1_TYPE ARGUMENT1,ARGUMENT2_TYPE ARGUMENT2);
It's not a big deal , it's just a prototype :)
I wrote the answer and removed it, u should try looking for the answer in the internet :)
Here you go:
+ doit(list : int[], size : int) : boolean

c++ error: term does not evaluate to a function taking 1 arguments [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm getting the error 'term does not evaluate to a function taking 1 arguments' on the following line in my code:
steerToSpiralRefPoint(m_CentrePos);
But I'm not sure why this is... Is it that the function will only take 1 argument as a parameter, but since the 'm_centrePos' variable holds more than 1 attribute, the function is effectively receiving several parameters?
I have defined 'steerToSpiralRefPoint' with the line:
CDirectOverflyItem steerToSpiralRefPoint = new CDirectOverflyItem::SteerStep(const CHeloData aHeloData);
'm_CentrePos' has been assigned the value 'cCentrePos' at the start of this file ('cCentrePos' is a variable of type 'CCoordinate', which has a number of attributes- latitude, longitude, altitude, etc).
'CDirectOverflyItem's also has a number of attributes- ground speed, wind speed, wind angle, etc.
Can anyone point out to me why I'm getting this error, and how I should correct it?
This expression
steerToSpiralRefPoint(m_CentrePos);
is a postfix expression of a function call. However as it follows from your post steerToSpiralRefPoint is not a function (or function pointer) but a pointer to an object. If you want to assign a value to the pointer then you have to write
steerToSpiralRefPoint = m_CentrePos;
Or if there is an operator function for this type then the code should look as
( *steerToSpiralRefPoint )( m_CentrePos );
And this construction
CDirectOverflyItem steerToSpiralRefPoint = new CDirectOverflyItem::SteerStep(const CHeloData );
is also invalid. You may not use qualifiers before variables in expressions. They may be used only in declarations.
It seems that the issue was that I was trying to pass the wrong data type into the parameter- it was expecting a 'CHeloData', but I was trying to give it a 'CCoordinate'.

How can I tell if a tuple is empty in c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to know how I can identify if my tuple is empty?
Note that I use std::tuble in conjunction with std::map as below:
typedef std::tuple<SDESType,INT32,std::string> SDesItem;
typedef std::map<SDESType,SDesItem> SDesItemMap;
Now I want to check if the second value of SDesItemMap, that is a tuple, is empty or not?
if(SDesItems[SDESType] != NULL) // this is error
std::tuple acts like three values tied together. It has no predefined "empty" or "zero" state, other than empty states of each of its members. Empty value is always contextual, and in general means a value lying outside the domain of the regular type's values.
For example, a natural number can only be 0 (or 1, depending on your definition) upward. Thus, using an int gives you a convenient way to represent a value that's outside of the domain, and should be treated irregularly.
To represent that cleanly in your example, use optional<tuple<...>> as a map value (if you want to specifically state "there's an empty value at a given key"). This type states that the possible values of the type you get by instantiating the optional template are now all of the values of the original type, and a special, nothing (/empty/none) value.
You can also state that parts of the tuple can be empty (nothing), like
tuple <
std::string, // empty string ("") can be treated as "empty state"
optional<int>, // if you don't want to treat 0 (or -1) as "empty"
>
optional<> is not a part of std:: yet, so you have to write your own implementation or use the Boost one. Another way would be using value_ptr (Boost again), but here it wouldn't probably give you any benefits.

Multiple return values in C++ [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
So, before quite some exposition, here comes my question:
Why is there no support for multiple return variables/values in C++ (yet)?
To give you some more notes:
What (if any) is conceptually a problem with multiple return values and c++?
Is there something in the way the compiler implements returing a values from a function which makes multiple return values impossible/inefficient?
Having worked a lot with lua recently I've come to ask myself why C++ does not permit to return multiple values/variables from a function. To illustrate, let me give you a lua example:
-- get the first four values of the fibonacci sequence
local function fib4()
return 1, 1, 2, 3
local fib0, fib1, fib2, fib3 = fib4()
Being able to return multiple variables/values at once is a very useful feature indeed, which I typically emulate in the C++ world by creating structs (essentially collecting the variables in a wrapper) which are returned by the function in question. If one uses this approach a lot, the soure files will be cluttered with structs each containing some variables; none of these struct needs to be an actual object (and is implemented as a complete object). In a way the conceptual problem is somewhat similar the one resulting from using structs for creating functors [instead of lambdas]:
It destroys locality
It introduces objects which are not conceptually objects but rather a helper
On the pro side it increases code readability:
struct point_three_dim_t {
double x;
double y;
double z;
};
point_three_dim_t point = getCollisionPoint();
However, a priori you don't know whether the members representing the coordinates are named x, y and z or first, second and third. So again, you have to check how point_three_dim_t was defined. This would not be the case if
double x, y, z = getCollisionPoint();
were correct syntax.
Using C++11 we can achieve conceptually the same by using either std::tuple or std::tie
std::tuple<double,double,double> getCollisionPoint();
// Using std::tie
double x, y, z;
std::tie( x, y, z ) = getCollisionPoint();
// Using std::tuple
std::tuple<double,double,double> point = getCollisionPoint();
This gets us much closer to clean and local code, however, I think neither syntax is quite as appealing as the one I'm used from scripting languages like lua.