Пример #1
0
int
LIBeam3dNL :: giveLocalCoordinateSystem(FloatMatrix &answer)
//
// returns a unit vectors of local coordinate system at element
// stored rowwise (mainly used by some materials with ortho and anisotrophy)
//
{
    FloatArray lx(3), ly(3), lz(3), help(3);
    double length = this->computeLength();
    Node *nodeA, *nodeB, *refNode;

    answer.resize(3, 3);
    answer.zero();
    nodeA  = this->giveNode(1);
    nodeB  = this->giveNode(2);
    refNode = this->giveDomain()->giveNode(this->referenceNode);

    for ( int i = 1; i <= 3; i++ ) {
        lx.at(i) = ( nodeB->giveCoordinate(i) - nodeA->giveCoordinate(i) ) / length;
        help.at(i) = ( refNode->giveCoordinate(i) - nodeA->giveCoordinate(i) );
    }

    lz.beVectorProductOf(lx, help);
    lz.normalize();
    ly.beVectorProductOf(lz, lx);
    ly.normalize();

    for ( int i = 1; i <= 3; i++ ) {
        answer.at(1, i) = lx.at(i);
        answer.at(2, i) = ly.at(i);
        answer.at(3, i) = lz.at(i);
    }

    return 1;
}
Пример #2
0
  void testQLDSolver()
  {
    BaseVariable xy("xy",2);
    BaseVariable z("z",1);
    CompositeVariable T("T", xy, z);

    MatrixXd A1(1,1); A1 << 1;
    VectorXd b1(1); b1 << -3;
    LinearFunction lf1(z, A1, b1);
    LinearConstraint c1(&lf1, true);

    MatrixXd A2(1,2); A2 << 3,1 ;
    VectorXd b2(1); b2 << 0;
    LinearFunction lf2(xy, A2, b2);
    LinearConstraint c2(&lf2, true);

    MatrixXd A3(2,2); A3 << 2,1,-0.5,1 ;
    VectorXd b3(2); b3 << 0, 1;
    LinearFunction lf3(xy, A3, b3);
    LinearConstraint c3(&lf3, false);

    QuadraticFunction objFunc(T, Matrix3d::Identity(), Vector3d::Zero(), 0);
    QuadraticObjective obj(&objFunc);
    
    QLDSolver solver;
    solver.addConstraint(c1);
    solver.addConstraint(c2);
    solver.addConstraint(c3);
    solver.addObjective(obj);

    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);


    solver.removeConstraint(c1);
    IdentityFunction id(z);
    VectorXd lz(1); lz << 1;
    VectorXd uz(1); uz << 2;
    IdentityConstraint bnd1(&id, lz, uz);
    solver.addBounds(bnd1);
    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);

    BaseVariable t("t", 2);
    VectorXd ut(2); ut << -4,-1;
    BoundFunction bf(t, ut, BOUND_TYPE_SUPERIOR);
    BoundConstraint bnd2(&bf, false);
    solver.addBounds(bnd2);

    QuadraticFunction objFunc2(t, Matrix2d::Identity(), Vector2d::Constant(2.71828),0);
    QuadraticObjective obj2(&objFunc2);
    solver.addObjective(obj2);
    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);

    Vector2d c3l(-1,-1);
    c3.setL(c3l);
    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);
  }
Пример #3
0
static void reality_check_get_direction_helper(const map_location & loc, const map_location::DIRECTION d)
{
	map_location lz(vz.get_direction(d));

	map_location temp(loc.vector_sum(lz));
	BOOST_CHECK_EQUAL(temp, loc.get_direction(d));
	BOOST_CHECK(tiles_adjacent(loc,temp));
	BOOST_CHECK(tiles_adjacent(temp,loc));
	BOOST_CHECK_EQUAL(distance_between(loc,temp), 1);
}
Пример #4
0
void
IntElPoint :: computeTransformationMatrixAt(GaussPoint *gp, FloatMatrix &answer)
{
    // Computes transformation matrix to local coordinate system.
    setCoordMode();
    switch ( mode ) {
    case ie1d_1d:
        answer.resize(1, 1);
        answer.at(1, 1) = 1.;
        return;

    case ie1d_2d:
        answer.resize(2, 2);
        answer.at(1, 1) =  normal.at(1);
        answer.at(1, 2) =  normal.at(2);
        answer.at(2, 1) = -normal.at(2);
        answer.at(2, 2) =  normal.at(1);
        return;

    case ie1d_3d:
    {
        //FloatMatrix test;
        //test.beLocalCoordSys(normal.normalize());

        FloatArray ly(3), lz(3);
        normal.normalize();
        ly.zero();
        if ( fabs( normal.at(1) ) > fabs( normal.at(2) ) ) {
            ly.at(2) = 1.;
        } else {
            ly.at(1) = 1.;
        }

        lz.beVectorProductOf(normal, ly);
        lz.normalize();
        ly.beVectorProductOf(lz, normal);
        ly.normalize();

        answer.resize(3, 3);
        for ( int i = 1; i <= 3; i++ ) {
            answer.at(1, i) = normal.at(i);
            answer.at(2, i) = ly.at(i);
            answer.at(3, i) = lz.at(i);
        }

        return;
    }

    default:
        OOFEM_ERROR("Unsupported mode");
    }
}
void
InterfaceElem1d :: evaluateLocalCoordinateSystem(FloatMatrix &lcs)
//
// Computes unit vectors of local coordinate system, stored by rows.
//
{
    setCoordMode();
    switch ( mode ) {
    case ie1d_1d:
        lcs.resize(1, 1);
        lcs.at(1, 1) = 1.;
        return;

    case ie1d_2d:
        lcs.resize(2, 2);
        lcs.at(1, 1) =  normal.at(1);
        lcs.at(1, 2) =  normal.at(2);
        lcs.at(2, 1) = -normal.at(2);
        lcs.at(2, 2) =  normal.at(1);
        return;

    case ie1d_3d:
    {
        FloatArray ly(3), lz(3);
        normal.normalize();
        ly.zero();
        if ( fabs( normal.at(1) ) > fabs( normal.at(2) ) ) {
            ly.at(2) = 1.;
        } else {
            ly.at(1) = 1.;
        }

        lz.beVectorProductOf(normal, ly);
        lz.normalize();
        ly.beVectorProductOf(lz, normal);
        ly.normalize();

        lcs.resize(3, 3);
        int i;
        for ( i = 1; i <= 3; i++ ) {
            lcs.at(1, i) = normal.at(i);
            lcs.at(2, i) = ly.at(i);
            lcs.at(3, i) = lz.at(i);
        }

        return;
    }

    default:
        _error("giveDofManDofIDMask: unsupported mode");
    }
}
Пример #6
0
void
CohesiveSurface3d :: evaluateLocalCoordinateSystem()
//
// Computes unit vectors of local coordinate system, stored by rows.
//
{
    FloatArray lx(3), ly(3), lz(3);

    Node *nodeA, *nodeB;
    nodeA  = this->giveNode(1);
    nodeB  = this->giveNode(2);

    switch ( numberOfDofMans ) {
    case 2:
        lx.at(1) = nodeB->giveCoordinate(1) - nodeA->giveCoordinate(1);
        lx.at(2) = nodeB->giveCoordinate(2) - nodeA->giveCoordinate(2);
        lx.at(3) = nodeB->giveCoordinate(3) - nodeA->giveCoordinate(3);
        lx.normalize();
        break;

    case 3:
        lx.at(1) = nodeB->giveCoordinate(1) + kxa - nodeA->giveCoordinate(1);
        lx.at(2) = nodeB->giveCoordinate(2) + kyb - nodeA->giveCoordinate(2);
        lx.at(3) = nodeB->giveCoordinate(3) + kzc - nodeA->giveCoordinate(3);
        lx.normalize();
        break;
    }

    ly.zero();
    if ( fabs( lx.at(1) ) > fabs( lx.at(2) ) ) {
        ly.at(2) = 1.;
    } else {
        ly.at(1) = 1.;
    }

    lz.beVectorProductOf(lx, ly);
    lz.normalize();
    ly.beVectorProductOf(lz, lx);
    ly.normalize();

    lcs.resize(3, 3);
    for ( int i = 1; i <= 3; i++ ) {
        lcs.at(1, i) = lx.at(i);
        lcs.at(2, i) = ly.at(i);
        lcs.at(3, i) = lz.at(i);
    }
}
Пример #7
0
int
Truss3d :: giveLocalCoordinateSystem(FloatMatrix &answer)
//
// returns a unit vectors of local coordinate system at element
// stored rowwise (mainly used by some materials with ortho and anisotrophy)
//
{
    FloatArray lx, ly(3), lz(3), help(3);
    double length = this->computeLength();
    Node *nodeA, *nodeB;

    // if (referenceNode == 0)
    // _error ("instanciateFrom: wrong reference node specified");

    answer.resize(3, 3);
    answer.zero();
    nodeA = this->giveNode(1);
    nodeB = this->giveNode(2);
    // refNode= this->giveDomain()->giveNode (this->referenceNode);

    lx.beDifferenceOf(*nodeB->giveCoordinates(),*nodeA->giveCoordinates());
    lx.times(1.0/length);

    int minIndx = 1;
    for ( int i = 2; i <= 3; i++ ) {
        if ( lx.at(i) < fabs( lx.at(minIndx) ) ) {
            minIndx = i;
        }
    }

    help.zero();
    help.at(minIndx) = 1.0;

    lz.beVectorProductOf(lx, help);
    lz.normalize();
    ly.beVectorProductOf(lz, lx);
    ly.normalize();

    for ( int i = 1; i <= 3; i++ ) {
        answer.at(1, i) = lx.at(i);
        answer.at(2, i) = ly.at(i);
        answer.at(3, i) = lz.at(i);
    }

    return 1;
}
Пример #8
0
void soil_generator::generate(chunk_coordinates pos, chunk& dest)
{
    if (!w_.is_area_data_available(pos, surfacemap_))
    {
        std::cout << "No area data available for soil" << std::endl;
        return;
    }

    auto sm  (w_.get_area_data(pos, surfacemap_));

    chunk_coordinates bot ();
    auto region (w_.lock_region({pos + world_vector(0, 0, -1), pos}, *this));
    int16_t z_offset (convert_height_16bit(pos.z * chunk_size));

    for (uint32_t x (pos.x * chunk_size); x < (pos.x + 1) * chunk_size; ++x)
    {
        for (uint32_t y (pos.x * chunk_size); y < (pos.x + 1) * chunk_size; ++y)
        {
            int16_t lz ((*sm)(x, y));
            if (lz < z_offset || lz >= z_offset + chunk_size)
                continue;

            uint32_t z (water_level + lz);
            if (region(x,y,z) == (uint16_t)16)
            {
                if (lz >= 5)
                {
                    region(x,y,lz  ) = grass_;
                    region(x,y,lz-1) = dirt_;
                    region(x,y,lz-2) = rock_;
                }
                else
                {
                    region(x,y,lz  ) = sand_;
                    region(x,y,lz-1) = sand_;
                    region(x,y,lz-2) = rock_;
                }
            }
        }
    }
}
Пример #9
0
 Dll Frame::dlz() const { return lz().dual(); }    ///< z direction dual line
Пример #10
0
	void GameDataHolder::Impl::Flush()
	{
		if( !FileExist( "save" ) ){
			CreateDirectory( "save" );
		}

		UpdatePlayTime();

		std::vector < char > data;
		data.reserve( 30000 );

		std::ofstream fOut( m_SaveDataFileName, std::ios::binary | std::ios::out );
		if( !fOut ){
			return;
		}

		CopyInt( &data, m_GameFileData.m_PlayTime );
		CopyInt( &data, m_GameFileData.m_Progress );
		for( int i = 0; i < GAME_DIFFICULTY_TOTAL; ++i ){
			// 通常プレイの統計情報の保存
			CopyInt( &data, m_GameFileData.m_Difficulty[ i ].m_NormalPlayStat.m_Play );
			CopyInt( &data, m_GameFileData.m_Difficulty[ i ].m_NormalPlayStat.m_AllClear );
			CopyInt( &data, m_GameFileData.m_Difficulty[ i ].m_NormalPlayStat.m_PlayTime );
			CopyInt( &data, m_GameFileData.m_Difficulty[ i ].m_NormalPlayStat.m_Progress );
			for( int j = 0; j < STAGE_TOTAL; ++j ){
				// 敵情報の保存
				const StageStat& stage = m_GameFileData.m_Difficulty[ i ].m_NormalPlayStat.m_StageStat[ j ];
				StageStat::EnemyStatMap::const_iterator it = stage.m_EnemyStat.begin();
				// エントリ数の保存
				CopyInt( &data, stage.m_EnemyStat.size() );
				for( ; it != stage.m_EnemyStat.end(); ++it ){
					// 敵の名前の長さ保存
					CopyInt( &data, it->first.size() );
					// 敵の名前の保存
					CopyArray( &data, it->first.c_str(), it->first.size() );
					// 情報の保存
					CopyInt( &data, it->second.m_Destroy );
					CopyInt( &data, it->second.m_Damaged );
					CopyInt( &data, it->second.m_KO );
				}
			}

			// ステージ選択プレイの統計情報の保存
			CopyInt( &data, m_GameFileData.m_Difficulty[ i ].m_StageSelectionPlayStat.m_Play );
			CopyInt( &data, m_GameFileData.m_Difficulty[ i ].m_StageSelectionPlayStat.m_Clear );
			CopyInt( &data, m_GameFileData.m_Difficulty[ i ].m_StageSelectionPlayStat.m_PlayTime );
			for( int j = 0; j < STAGE_TOTAL; ++j ){
				// 敵情報の保存
				const StageStat& stage = m_GameFileData.m_Difficulty[ i ].m_StageSelectionPlayStat.m_StageStat[ j ];
				StageStat::EnemyStatMap::const_iterator it = stage.m_EnemyStat.begin();
				// エントリ数の保存
				CopyInt( &data, stage.m_EnemyStat.size() );
				for( ; it != stage.m_EnemyStat.end(); ++it ){
					// 敵の名前の長さ保存
					CopyInt( &data, it->first.size() );
					// 敵の名前の保存
					CopyArray( &data, it->first.c_str(), it->first.size() );
					// 情報の保存
					CopyInt( &data, it->second.m_Destroy );
					CopyInt( &data, it->second.m_Damaged );
					CopyInt( &data, it->second.m_KO );
				}
			}

			// スコアの保存
			for( int j = 0; j < MAX_SCORE_ENTRY; ++j ){
				SaveDataRecord record = m_GameFileData.m_Difficulty[ i ].m_Record[ j ];
				CopyArray( &data, record.m_Name, sizeof( record.m_Name ) );
				CopyInt( &data, record.m_Date.m_Year );
				data.push_back( record.m_Date.m_Month );
				data.push_back( record.m_Date.m_Day );
				data.push_back( record.m_Date.m_Hour );
				data.push_back( record.m_Date.m_Min );
				data.push_back( record.m_Date.m_Sec );
				for( int k = 0; k < STAGE_TOTAL; ++k ){
					SaveDataRecord::StageData stage = record.m_StageData[ k ];
					CopyInt( &data, stage.m_Score );
					CopyInt( &data, stage.m_Killed );
					CopyInt( &data, stage.m_Crystal );
					CopyInt( &data, stage.m_CrystalUsed );
					CopyInt( &data, stage.m_Progress );
				}
				CopyInt( &data, record.m_Score );
				CopyInt( &data, record.m_Progress );
				CopyInt( &data, record.m_Killed );
				CopyInt( &data, record.m_Crystal );
				CopyInt( &data, record.m_CrystalUsed );
			}
		}

		// 圧縮
		char* pBuf = new char [ data.size() * 2 ];
		int compSize = 0;
		MAPIL::LZ lz( 200, 3 );
		lz.Compress( &data[ 0 ], data.size(), &pBuf, data.size() * 2, &compSize );
		// シーザ暗号化
		MAPIL::Caesar caesar( 10 );
		caesar.Encrypt( pBuf, compSize );
		// XOR暗号化
		MAPIL::XOR xor( 60 );
		xor.Encrypt( pBuf, compSize );
		fOut.write( pBuf, compSize );
		fOut.close();
		MAPIL::SafeDeleteArray( pBuf );
	}
Пример #11
0
	void GameDataHolder::Impl::Load( const std::string& fileName )
	{
		// 現在時刻を取得
		m_TimeStamp = ::time( NULL );

		std::fstream fIn( m_SaveDataFileName, std::ios::binary | std::ios::in );
		if( !fIn ){
			return;
		}
		int size = GetFileSize( fIn );
		char* pBuf = new char [ size ];
		fIn.read( pBuf, size * sizeof( char ) );
		fIn.close();

		// XOR暗号復号化
		MAPIL::XOR xor( 60 );
		xor.Decrypt( pBuf, size );
		// シーザ暗号復号化
		MAPIL::Caesar caesar( 10 );
		caesar.Decrypt( pBuf, size );
		// 解凍
		MAPIL::LZ lz( 200, 3 );
		char* pData = new char [ size * 1000 ];
		int dataSize = 0;
		lz.Expand( pBuf, size, &pData, size * 1000, &dataSize );
		MAPIL::SafeDeleteArray( pBuf );

		// データ設定
		char* p = pData;
		m_GameFileData.m_PlayTime = GetInt( &p );
		m_GameFileData.m_Progress = GetInt( &p );
		for( int i = 0; i < GAME_DIFFICULTY_TOTAL; ++i ){
			GameFileData::Difficulty difficulty;

			// 通常プレイのデータを取得
			difficulty.m_NormalPlayStat.m_Play = GetInt( &p );
			difficulty.m_NormalPlayStat.m_AllClear = GetInt( &p );
			difficulty.m_NormalPlayStat.m_PlayTime = GetInt( &p );
			difficulty.m_NormalPlayStat.m_Progress = GetInt( &p );
			for( int j = 0; j < STAGE_TOTAL; ++j ){
				// 敵情報の取得
				StageStat& stage = difficulty.m_NormalPlayStat.m_StageStat[ j ];
				// エントリ数の取得
				int entry = GetInt( &p );
				for( int k = 0; k < entry; ++k ){
					// 敵の名前の長さを取得
					int length = GetInt( &p );
					// 敵の名前の取得
					char* pEnemyName = new char[ length + 1 ];
					::memcpy( pEnemyName, p, sizeof( length ) );
					pEnemyName[ length ] = '\0';
					p += length;
					// 情報の取得
					EnemyStat enemyStat;
					enemyStat.m_Destroy = GetInt( &p );
					enemyStat.m_Damaged = GetInt( &p );
					enemyStat.m_KO = GetInt( &p );
					stage.m_EnemyStat[ pEnemyName ] = enemyStat;
					MAPIL::SafeDeleteArray( pEnemyName );
				}
			}

			// ステージ選択プレイのデータを取得
			difficulty.m_StageSelectionPlayStat.m_Play = GetInt( &p );
			difficulty.m_StageSelectionPlayStat.m_Clear = GetInt( &p );
			difficulty.m_StageSelectionPlayStat.m_PlayTime = GetInt( &p );
			for( int j = 0; j < STAGE_TOTAL; ++j ){
				// 敵情報の取得
				StageStat& stage = difficulty.m_StageSelectionPlayStat.m_StageStat[ j ];
				// エントリ数の取得
				int entry = GetInt( &p );
				for( int k = 0; k < entry; ++k ){
					// 敵の名前の長さを取得
					int length = GetInt( &p );
					// 敵の名前の取得
					char* pEnemyName = new char[ length + 1 ];
					::memcpy( pEnemyName, p, sizeof( length ) );
					pEnemyName[ length ] = '\0';
					p += length;
					// 情報の取得
					EnemyStat enemyStat;
					enemyStat.m_Destroy = GetInt( &p );
					enemyStat.m_Damaged = GetInt( &p );
					enemyStat.m_KO = GetInt( &p );
					stage.m_EnemyStat[ pEnemyName ] = enemyStat;
					MAPIL::SafeDeleteArray( pEnemyName );
				}
			}


			// スコアのロード
			for( int j = 0; j < MAX_SCORE_ENTRY; ++j ){
				SaveDataRecord record;
				::memcpy( record.m_Name, p, sizeof( record.m_Name ) );
				p += sizeof( record.m_Name );
				record.m_Date.m_Year = GetInt( &p );
				record.m_Date.m_Month = *p++;
				record.m_Date.m_Day = *p++;
				record.m_Date.m_Hour = *p++;
				record.m_Date.m_Min = *p++;
				record.m_Date.m_Sec = *p++;
				for( int k = 0; k < STAGE_TOTAL; ++k ){
					SaveDataRecord::StageData stage;
					stage.m_Score = GetInt( &p );
					stage.m_Killed = GetInt( &p );
					stage.m_Crystal = GetInt( &p );
					stage.m_CrystalUsed = GetInt( &p );
					stage.m_Progress = GetInt( &p );
					record.m_StageData[ k ] = stage;
				}
				record.m_Score = GetInt( &p );
				record.m_Progress = GetInt( &p );
				record.m_Killed = GetInt( &p );
				record.m_Crystal = GetInt( &p );
				record.m_CrystalUsed = GetInt( &p );
				difficulty.m_Record[ j ] = record;
			}
			m_GameFileData.m_Difficulty[ i ] = difficulty;
		}

		MAPIL::SafeDeleteArray( pData );
	}