Weird std::map problem

Pages: 12
Thanks @Ness,
I came to the same conclusion about the throwing procedure ... but it took me longer to get there!

If the code is allowed its full random values (i.e. as is) then it can throw at various points within this routine. (You would have to fix the seed for repeatability.)

Somewhere, there are a lot of relevant keys missing in the map atoms[].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//MSD.h:478 init()
	for( unsigned int z = 0; z < depth; z++ )
		for( unsigned int y = 0; y < height; y++ ) {
			// left
			for( unsigned int x = 0; x < molPosL; x++ )
				if (topL <= y && y <= bottomL) { //x={0..4}, y={3..9}, z={0..9}
					a = index(x, y, z);
					indices.push_back(a);
					atoms[a] = initSpin;
					n++;
				}
			// mol
			if( y == topL || z == frontR || y == bottomL || z == backR ) //just the faces, not the interior
				for( unsigned int x = molPosL; x <= molPosR; x++ ) { //x=5
					a = index(x, y, z);
					indices.push_back(a);
					atoms[a] = initSpin;
					n++;
				}
			// right
			for( unsigned int x = molPosR + 1; x < width; x++ )
				if (frontR <= z && z <= backR) { //x={6..10}, y={0..9}, z={0..9}
					a = index(x, y, z);
					indices.push_back(a);
					atoms[a] = initSpin;
					n++;
				}
kind of a weird structure, ¿two welded boxes?

then in setSpin() you either miscommpute the neighbour or get an x,y,z invalid
too many ifs to check

you need to refactor it, consider this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def set_spin(x, y, z, spin):
    if not valid(x, y, z):
        error("not valid atom")

    for K in {-1, 1}:
        for L in {-1, 1}:
            for M in {-1, 1}:
                [xn, yn, zn] = x+K, y+L, z+M
                if not valid(xn, yn, zn):
                    continue
                neighbour = atoms.at(xn, yn, zn)
                [alpha, beta] = parameters(xn, yn, zn)
                deltaU = alpha * f(neighbour, s, spin) + beta * g(neighbour, s, spin)
                result[write_result(xn, yn, zn)] +=  delt

def parameters(x, y, z):
    if x < mol_left:
        return [JL, bL]
    if between(mol_left, x, mol_right):
        return [Jml, bml]
    //...

def write_result(x, y, z):
    //say that result is a vector, then you may return the index to update
    if x < mol_left:
        return {1, 3}
        return [0, 1, 0, 1, 0, 0]

Last edited on
I couldn’t care less about being reported. It means nothing.

I would be surprised in any case if it was @lastchance who did it anyway because, like @dutch, whose approach is a little more direct, presents as someone who acts in good faith to solve a problem created by a dope who writes crap code and just fucks around.

The error message is well known and understood. The crap code has so many fwists, turns and conditions, no wonder the pitifully unreadable and badly formed data sets don’t load.

And, classic of all classics, it doesn’t even compile. What a joke.


too many ifs to check

That's an understatement!

The two procedures that seem to have most bearing on the problem are both in MSD.h
void MSD::init()
void MSD::setSpin(unsigned int a, const Vector &spin)

The problematic map is atoms[].

Bizarre to see so much code in header files.
Why is there a vector file, why all the bullshit code about Mersenne twisters?

This is one of those hobby-horse efforts that’s beyond repair and beyond reason.

My guess is it’s some sort of trivial physics simulation.

It would make a good freshman programming exercise in fixing it up and doing the job in about 200 lines of simple straight forward self documenting code combined with a structured dataset instead of a spreadsheet export from another amateurish waste of time and space. (If the current data is coming from experiment hardware then scrap it and buy some real equipment because this junk doesn’t work.)

Boltzmann and Euler, whoever, will be turning in their graves.

The problem of loading a map of string/vectors of doubles is solved.

OP should green tick this thread and move on.
I got a chance to play with your code a little. It think the problem is in the complicated setSpin function involving access to the atom map. Only some of it's accesses are protected with try/catch blocks. I think one of those unprotected atom.at() accesses is failing. I've finished looking at it, for now at least. My head hurts. :-)
Thank you everyone, so so so much for your help! THANK YOU!!!!

Sorry for being awol, a combination of being busy and catching the flu.

I don't know why at the time I couldn't find the error. You were all right. The issue was in the MSD::setSpin() method. This is where I was changing the code, so it should have been obvious to me... :(

I added in a catch in that method and found the offending coordinates. Then figured out why they were going out of bounds and added a few extra checks to cover the edge cases. Best I can tell it's working now.

Whoever mentioned that it's two welded boxed, not a bad guess. :) It's representing a latices of atoms in a magnetic device, and we needed to change the device's geometry to this weird cross shape. (Before it was just two same-sized rects.)

For those of you who mentioned that I refactor the code, I'm already ahead of you on that one. As I stated before, this is old code that I haven't maintained in over 5 years. Even then I wanted to refactor, but sometimes in practice you just have to use what you've got. My current plan (now that I'm working on this again, is to move to a linked/graph structure instead of just using maps, and storing edge parameters for every edge. This would give us more flexibility, and more practically geometric approximations. So basically, I'm planning to scrap all of this code, and rebuild from the ground up.

To make matters worse, I found out that this isn't the latest version of the code. I will be updating to the actual latest version which I'm sure had some bug fixes in it. :( I should be able to apply all of these changes to the new code, however.

Also, for everyone who failed to compile the code: you just compile each .cpp file separately. They are all independent programs with their own main functions. And, the .bat files were used to fill in the command line parameters. (I also plan to make this program much more user friendly, so this was just a hacked together UI.)

THANK YOU again everyone for your help!



P.S.
@againtry: I don't know you, and I don't know why you are so angry with strangers,
but I sincerely hope yelling at me made you happy.
I'm planning to scrap all of this code, and rebuild from the ground up.

http://www.cplusplus.com/forum/general/267571/#msg1151582
Being totally vindicated by a passive-aggressive permanently in denial makes me very happy.
What a surprise - a pink slip - a Red Shift.
Topic archived. No new replies allowed.
Pages: 12