text:
#pragma once

#include "halley/text/halleystring.h"
#include <thread>
#include <gsl/span>
#include <atomic>

#include "halley/data_structures/hash_map.h"
#include "halley/time/halleytime.h"

namespace Halley {
	enum class ProfilerEventType {
	    CorePumpEvents,
		CoreDevConClient,
		CorePumpAudio,
		CoreFixedUpdate,
		CoreVariableUpdate,
		CoreUpdateSystem,
		CoreUpdatePlatform,
		CoreUpdate,
		CoreStartRender,
		CoreRender,
		CoreVSync,

		PainterDrawCall,
		PainterEndRender,
		PainterUpdateProjection,

		WorldVariableUpdate,
		WorldFixedUpdate,
		WorldRender,
		WorldSystemUpdate,
		WorldSystemRender,

		AudioGenerateBuffer,

		DiskIO,

		StatsView,

		Game
    };

    class ProfilerData {
    public:
        using TimePoint = std::chrono::steady_clock::time_point;
    	using Duration = std::chrono::duration<int64_t, std::nano>;

		class Event {
        public:
	        String name;
        	std::thread::id threadId;
			ProfilerEventType type;
			int depth;
        	uint64_t id;
        	TimePoint startTime;
        	TimePoint endTime;
        };

    	class ThreadInfo {
    	public:
    		std::thread::id id;
    		int maxDepth = 0;
    		String name;
    		TimePoint startTime;
    		TimePoint endTime;
    		Duration totalTime;

    		bool operator< (const ThreadInfo& other) const;
    	};

    	ProfilerData() = default;
    	ProfilerData(TimePoint frameStartTime, TimePoint frameEndTime, std::vector<Event> events);

    	TimePoint getStartTime() const;
    	TimePoint getEndTime() const;
    	const std::vector<Event>& getEvents() const;
    	Duration getTotalElapsedTime() const;
		Duration getElapsedTime(ProfilerEventType eventType) const;

    	gsl::span<const ThreadInfo> getThreads() const;

    private:
    	TimePoint frameStartTime;
    	TimePoint frameEndTime;
    	std::vector<Event> events;

    	std::vector<ThreadInfo> threads;

    	void processEvents();
    };

    class ProfilerCapture {
    public:
        using EventId = uint64_t;

        ProfilerCapture(size_t maxEvents = 16384);

    	[[nodiscard]] static ProfilerCapture& get();

    	[[nodiscard]] EventId recordEventStart(ProfilerEventType type, std::string_view name);
    	void recordEventEnd(EventId id);

    	[[nodiscard]] bool isRecording() const;

    	void startFrame(bool record);
    	void endFrame();
		ProfilerData getCapture();

    	Time getFrameTime() const;

    private:
    	enum class State {
    		Idle,
    		FrameStarted,
    		FrameEnded
    	};

    	std::atomic<bool> recording;
    	std::atomic<uint64_t> curId;
    	uint64_t startId;
    	std::atomic<uint64_t> endId;
        State state = State::Idle;

    	std::chrono::steady_clock::time_point frameStartTime;
    	std::chrono::steady_clock::time_point frameEndTime;

    	std::vector<ProfilerData::Event> events;
    };

	class ProfilerEvent {
	public:
		ProfilerEvent(ProfilerEventType type, std::string_view name = "");
		~ProfilerEvent() noexcept;

		ProfilerEvent(const ProfilerEvent& other) = delete;
		ProfilerEvent(ProfilerEvent&& other) = delete;
		ProfilerEvent& operator=(const ProfilerEvent& other) = delete;
		ProfilerEvent& operator=(ProfilerEvent&& other) = delete;

	private:
		ProfilerCapture::EventId id;
	};
}


text:
#include <math.h>
#include <gsl/gsl_sf_bessel.h>
#include <galpy_potentials.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
//Double exponential disk potential
double DoubleExponentialDiskPotentialEval(double R,double z, double phi,
					  double t,
					  struct potentialArg * potentialArgs){
  double * args= potentialArgs->args;
  double amp, alpha;
  int nzeros, glorder;
  if ( R > 6. ) { //Approximate as Keplerian
    nzeros= (int) *(args+4);
    glorder= (int) *(args+5);
    amp= *(args + 6 + 2 * glorder + 4 * (nzeros + 1));
    alpha= *(args + 7 + 2 * glorder + 4 * (nzeros + 1));
    return - *args * amp * pow(R*R+z*z,1.-0.5*alpha) / (alpha - 2.);
  }
  //Get args
  amp= *args++;
  alpha= *args++;
  double beta= *args++;
  double kmaxFac= *args++;
  double kmax= kmaxFac * beta;
  nzeros= (int) *args++;
  glorder= (int) *args++;
  double * glx= args;
  double * glw= args + glorder;
  double * j0zeros= args + 2 * glorder;
  double * dj0zeros= args + 2 * glorder + nzeros + 1;
  //Calculate potential
  double out= 0.;
  double k;
  int ii, jj;
  if ( R < 1. ) kmax= kmax/R;
  for (ii=0; ii < ( nzeros + 1 ); ii++) {
    for (jj=0; jj < glorder; jj++) {
      k= 0.5 * ( *(glx+jj) + 1. ) * *(dj0zeros+ii+1) + *(j0zeros+ii);
      out+= *(glw+jj) * *(dj0zeros+ii+1) * gsl_sf_bessel_J0(k*R)
	* pow(alpha * alpha + k * k,-1.5)
	* (beta * exp(-k * fabs(z) ) - k * exp(-beta * fabs(z) ))
	/ (beta * beta - k * k);
    }
    if ( k > kmax ) break;
  }
  return - amp * 2 * M_PI * alpha * out;
}
double DoubleExponentialDiskPotentialRforce(double R,double z, double phi,
					    double t,
					    struct potentialArg * potentialArgs){
  double * args= potentialArgs->args;
  double amp, alpha;
  int nzeros,glorder;
  if ( R > 6. ) { //Approximate as Keplerian
    nzeros= (int) *(args+4);
    glorder= (int) *(args+5);
    amp= *(args + 6 + 2 * glorder + 4 * (nzeros + 1));
    alpha= *(args + 7 + 2 * glorder + 4 * (nzeros + 1));
    return - *args * amp * R * pow(R*R+z*z,-0.5*alpha);
  }
  //Get args
  amp= *args++;
  alpha= *args++;
  double beta= *args++;
  double kmaxFac= *args++;
  double kmax= 2. * kmaxFac * beta;
  nzeros= (int) *args++;
  glorder= (int) *args++;
  double * glx= args;
  double * glw= args + glorder;
  double * j1zeros= args + 2 * glorder + 2 * (nzeros + 1);
  double * dj1zeros= args + 2 * glorder + 3 * (nzeros + 1);
  //Calculate potential
  double out= 0.;
  double k;
  int ii, jj;
  if ( R < 1. ) kmax= kmax/R;
  for (ii=0; ii < ( nzeros + 1 ); ii++) {
    for (jj=0; jj < glorder; jj++) {
      k= 0.5 * ( *(glx+jj) + 1. ) * *(dj1zeros+ii+1) + *(j1zeros+ii);
      out+= *(glw+jj) * *(dj1zeros+ii+1) * k * gsl_sf_bessel_J1(k*R)
	* pow(alpha * alpha + k * k,-1.5)
	* (beta * exp(-k * fabs(z) ) - k * exp(-beta * fabs(z) ))
	/ (beta * beta - k * k);
    }
    if ( k > kmax ) break;
  }
  return - amp * 2 * M_PI * alpha * out;
}
double DoubleExponentialDiskPotentialPlanarRforce(double R,double phi,
						  double t,
						  struct potentialArg * potentialArgs){
  double * args= potentialArgs->args;
  double amp, alpha;
  int nzeros, glorder;
  if ( R > 6. ) { //Approximate as Keplerian
    nzeros= (int) *(args+4);
    glorder= (int) *(args+5);
    amp= *(args + 6 + 2 * glorder + 4 * (nzeros + 1));
    alpha= *(args + 7 + 2 * glorder + 4 * (nzeros + 1));
    return - *args * amp * pow(R,-alpha + 1.);
  }
  //Get args
  amp= *args++;
  alpha= *args++;
  double beta= *args++;
  double kmaxFac= *args++;
  double kmax= 2. * kmaxFac * beta;
  nzeros= (int) *args++;
  glorder= (int) *args++;
  double * glx= args;
  double * glw= args + glorder;
  double * j1zeros= args + 2 * glorder + 2 * (nzeros + 1);
  double * dj1zeros= args + 2 * glorder + 3 * (nzeros + 1);
  //Calculate potential
  double out= 0.;
  double k;
  int ii, jj;
  if ( R < 1. ) kmax= kmax/R;
  for (ii=0; ii < ( nzeros + 1 ); ii++) {
    for (jj=0; jj < glorder; jj++) {
      k= 0.5 * ( *(glx+jj) + 1. ) * *(dj1zeros+ii+1) + *(j1zeros+ii);
      out+= *(glw+jj) * *(dj1zeros+ii+1) * k * gsl_sf_bessel_J1(k*R)
	* pow(alpha * alpha + k * k,-1.5)
	/ (beta + k);
    }
    if ( k > kmax ) break;
  }
  return - amp * 2 * M_PI * alpha * out;
}
double DoubleExponentialDiskPotentialzforce(double R,double z,double phi,
					    double t,
					    struct potentialArg * potentialArgs){
  double * args= potentialArgs->args;
  double amp, alpha;
  int nzeros, glorder;
  if ( R > 6. ) { //Approximate as Keplerian
    nzeros= (int) *(args+4);
    glorder= (int) *(args+5);
    amp= *(args + 6 + 2 * glorder + 4 * (nzeros + 1));
    alpha= *(args + 7 + 2 * glorder + 4 * (nzeros + 1));
    return - *args * amp * z * pow(R*R+z*z,-0.5*alpha);
  }
  //Get args
  amp= *args++;
  alpha= *args++;
  double beta= *args++;
  double kmaxFac= *args++;
  double kmax= kmaxFac * beta;
  nzeros= (int) *args++;
  glorder= (int) *args++;
  double * glx= args;
  double * glw= args + glorder;
  double * j0zeros= args + 2 * glorder;
  double * dj0zeros= args + 2 * glorder + nzeros + 1;
  //Calculate potential
  double out= 0.;
  double k;
  int ii, jj;
  if ( R < 1. ) kmax= kmax/R;
  for (ii=0; ii < ( nzeros + 1 ); ii++) {
    for (jj=0; jj < glorder; jj++) {
      k= 0.5 * ( *(glx+jj) + 1. ) * *(dj0zeros+ii+1) + *(j0zeros+ii);
      out+= *(glw+jj) * *(dj0zeros+ii+1) * k * gsl_sf_bessel_J0(k*R)
	* pow(alpha * alpha + k * k,-1.5)
	* (exp(-k * fabs(z) ) - exp(-beta * fabs(z) ))
	/ (beta * beta - k * k);
    }
    if ( k > kmax ) break;
  }
  if ( z > 0. )
    return - amp * 2 * M_PI * alpha * beta * out;
  else
    return amp * 2 * M_PI * alpha * beta * out;
}
double DoubleExponentialDiskPotentialDens(double R,double z, double phi,
					  double t,
					  struct potentialArg * potentialArgs){
  double * args= potentialArgs->args;
  //Get args
  double amp= *args++;
  double alpha= *args++;
  double beta= *args;
  // calculate density
  return amp * exp ( - alpha * R - beta * fabs ( z ) );
}

ext: c

max_stars_repo_name: gusbeane/galpy

max_issues_repo_name: gusbeane/galpy

max_forks_repo_name: gusbeane/galpy


text:
#pragma once

#include <gsl.h>

#include <QmitkAbstractView.h>

#include "ui_SolverSetupView.h"
#include "ui_BoundaryConditionTypeSelectionDialog.h"

#include <HierarchyManager.h>

#include <ImmutableRanges.h>

#include "SolverStudyUIDsTableModel.h"

namespace crimson
{
class ISolverSetupManager;
}

/*! \brief   SolverSetupView allows the user to set up the solver and to write the prepared simulation to disk. */
class SolverSetupView : public QmitkAbstractView
{
    Q_OBJECT

public:
    static const std::string VIEW_ID;

    SolverSetupView();
    ~SolverSetupView();

    void OnSelectionChanged(berry::IWorkbenchPart::Pointer source, const QList<mitk::DataNode::Pointer>& nodes) override;
    void NodeRemoved(const mitk::DataNode* node) override;
    void NodeChanged(const mitk::DataNode* node) override;

private slots:
    void writeSolverSetup();
	void runSimulation();
    void loadSolution();
    void showSolution(bool show);
    void createSolverRoot();
    void createSolverParameters();
    void createSolverStudy();
    void createBoundaryConditionSet();
    void createBoundaryCondition();
    void createMaterial();
    void showMaterial();
    void exportMaterials();
    void setMeshNodeForStudy(const mitk::DataNode*);
    void setSolverParametersNodeForStudy(const mitk::DataNode*);

private:
    void CreateQtPartControl(QWidget* parent) override;
    void SetFocus() override;

    void _updateUI();

    template <class T, class... Args>
    void createSolverObject(mitk::DataNode* ownerNode, Args... additionalArgs);

private:
    // Ui and main widget of this view
    Ui::SolverSetupWidget _UI;

    void _setCurrentRootNode(mitk::DataNode* node);
    void _setCurrentSolverRootNode(mitk::DataNode* node);

    void _findCurrentSolverSetupManager();

    void _setCurrentBoundaryConditionSetNode(mitk::DataNode* node);
    void _setCurrentBoundaryConditionNode(mitk::DataNode* node);
    void _setCurrentMaterialNode(mitk::DataNode* node);
    void _setCurrentSolverParametersNode(mitk::DataNode* node);
    void _setCurrentSolverStudyNode(mitk::DataNode* node);
    void _setupSolverStudyComboBoxes();

    void _selectDataNode(mitk::DataNode* node);

    void _serviceChanged(const us::ServiceEvent event);

    void _solverStudyNodeModified();
    unsigned long _solverStudyObserverTag = -1;

    void _ensureApplyToAllWalls(mitk::DataNode* node) const;
    gsl::cstring_span<> _getTypeNameToCreate(crimson::ImmutableValueRange<gsl::cstring_span<>> options);

    mitk::DataNode* _currentSolverRootNode = nullptr;
    mitk::DataNode* _currentRootNode = nullptr;
    crimson::HierarchyManager::NodeType _currentRootNodeType;
    mitk::DataNode* _currentVesselTreeNode = nullptr;
    mitk::DataNode* _currentBoundaryConditionSetNode = nullptr;
    mitk::DataNode* _currentBoundaryConditionNode = nullptr;
    mitk::DataNode* _currentMaterialNode = nullptr;
    mitk::DataNode* _currentSolverStudyNode = nullptr;
    mitk::DataNode* _currentSolverParametersNode = nullptr;
    mitk::DataNode* _currentSolidNode = nullptr;
    crimson::ISolverSetupManager* _currentSolverSetupManager = nullptr;

    struct RemoveNodeDeleter {
        void operator()(mitk::DataNode* node);
    };

    std::unique_ptr<mitk::DataNode, RemoveNodeDeleter> _materialVisNodePtr;

    Ui::boundaryConditionTypeSelectionDialog _typeSelectionDialogUi;
    QDialog _typeSelectionDialog;

    crimson::SolverStudyUIDsTableModel _solverStudyBCSetsModel;
    crimson::SolverStudyUIDsTableModel _solverStudyMaterialsModel;
};

ext: h

max_stars_repo_name: carthurs/CRIMSONGUI

max_issues_repo_name: carthurs/CRIMSONGUI

max_forks_repo_name: carthurs/CRIMSONGUI


text:
/*
 * Barcode
 * Copyright E.G.P. Bos and F.S. Kitaura
 *
 * Distributed under the terms of the MIT License.
 * The full license is in the file LICENSE, distributed with this software.
 */

#pragma once

#include "struct_main.h"
#include <gsl/gsl_rng.h>
#include "define_opt.h"

void barcoderunner(struct DATA *data,gsl_rng * gBaseRand);
void load_initial_fields(struct DATA *data, int resnum, gsl_rng *gBaseRand);
unsigned int initial_iteration_number(struct DATA *data);
void setup_random_test(struct DATA *data, real_prec *delta_lag, real_prec *delta_eul, unsigned int facL,
                       real_prec *posx, real_prec *posy, real_prec *posz, gsl_rng *gBaseRand);
void make_initial_guess(struct DATA *data, gsl_rng *gBaseRand);

max_stars_repo_name: egpbos/barcode

max_issues_repo_name: egpbos/barcode

max_forks_repo_name: egpbos/barcode