Skip to content

Commit

Permalink
adding equations to constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
NorbertHofbauer committed Jan 21, 2025
1 parent 1ae46ef commit 8e3e2d8
Showing 18 changed files with 386 additions and 19 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -129,3 +129,4 @@
2025-01-09 working on implementing surface traction load
2025-01-09 working on surface traction load in core
2025-01-20 working on adding equations to constraints in core
2025-01-21 working on equations
10 changes: 10 additions & 0 deletions src/CalculiXPlugin.cpp
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@
#include "ccxSectionMembraneCreateCommand.hpp"
#include "ccxSectionMembraneModifyCommand.hpp"
#include "ccxConstraintDeleteCommand.hpp"
#include "ccxConstraintEquationCreateCommand.hpp"
#include "ccxConstraintEquationModifyCommand.hpp"
#include "ccxConstraintRigidBodyCreateCommand.hpp"
#include "ccxConstraintRigidBody2CreateCommand.hpp"
#include "ccxConstraintRigidBodyModifyCommand.hpp"
@@ -178,6 +180,8 @@ std::vector<std::string> CalculiXPlugin::get_keys()
keys.push_back("ccxSectionMembraneCreateCommand");
keys.push_back("ccxSectionMembraneModifyCommand");
keys.push_back("ccxConstraintDeleteCommand");
keys.push_back("ccxConstraintEquationCreateCommand");
keys.push_back("ccxConstraintEquationModifyCommand");
keys.push_back("ccxConstraintRigidBodyCreateCommand");
keys.push_back("ccxConstraintRigidBody2CreateCommand");
keys.push_back("ccxConstraintRigidBodyModifyCommand");
@@ -382,6 +386,12 @@ CubitCommand* CalculiXPlugin::create_command(const std::string &key)
if(key == "ccxConstraintTieModifyCommand")
return new ccxConstraintTieModifyCommand();

if(key == "ccxConstraintEquationCreateCommand")
return new ccxConstraintEquationCreateCommand();

if(key == "ccxConstraintEquationModifyCommand")
return new ccxConstraintEquationModifyCommand();

if(key == "ccxConstraintTieCreateFromCubitContactPairCommand")
return new ccxConstraintTieCreateFromCubitContactPairCommand();

4 changes: 4 additions & 0 deletions src/Commands/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -41,6 +41,10 @@ set(CMD_SRC
${CMAKE_CURRENT_LIST_DIR}/ccxSectionMembraneModifyCommand.hpp
${CMAKE_CURRENT_LIST_DIR}/ccxConstraintDeleteCommand.cpp
${CMAKE_CURRENT_LIST_DIR}/ccxConstraintDeleteCommand.hpp
${CMAKE_CURRENT_LIST_DIR}/ccxConstraintEquationCreateCommand.cpp
${CMAKE_CURRENT_LIST_DIR}/ccxConstraintEquationCreateCommand.hpp
${CMAKE_CURRENT_LIST_DIR}/ccxConstraintEquationModifyCommand.cpp
${CMAKE_CURRENT_LIST_DIR}/ccxConstraintEquationModifyCommand.hpp
${CMAKE_CURRENT_LIST_DIR}/ccxConstraintRigidBodyCreateCommand.cpp
${CMAKE_CURRENT_LIST_DIR}/ccxConstraintRigidBodyCreateCommand.hpp
${CMAKE_CURRENT_LIST_DIR}/ccxConstraintRigidBody2CreateCommand.cpp
76 changes: 76 additions & 0 deletions src/Commands/ccxConstraintEquationCreateCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "ccxConstraintEquationCreateCommand.hpp"
#include "CubitInterface.hpp"
#include "CubitMessage.hpp"
#include "CalculiXCoreInterface.hpp"

ccxConstraintEquationCreateCommand::ccxConstraintEquationCreateCommand()
{}

ccxConstraintEquationCreateCommand::~ccxConstraintEquationCreateCommand()
{}

std::vector<std::string> ccxConstraintEquationCreateCommand::get_syntax()
{
std::vector<std::string> syntax_list;

std::string syntax = "ccx ";
syntax.append("create constraint equation ");
syntax.append("name <string:type='unquoted', number='1', label='name', help='<name>'> " );
syntax.append("node_dof_coefficient <value:label='node_dof_coefficient',help='<node_dof_coefficient>'>..." );
syntax_list.push_back(syntax);

return syntax_list;
}

std::vector<std::string> ccxConstraintEquationCreateCommand::get_syntax_help()
{
std::vector<std::string> help(5);
help[0] = "ccx create constraint equation name <name> node_dof_coefficient <node_dof_coefficient>...";

return help;
}

std::vector<std::string> ccxConstraintEquationCreateCommand::get_help()
{
std::vector<std::string> help;
return help;
}

bool ccxConstraintEquationCreateCommand::execute(CubitCommandData &data)
{

CalculiXCoreInterface ccx_iface;

std::string output;

std::string name;
std::vector<std::string> options;
std::vector<std::vector<double>> options2;
std::vector<double> node_dof_coefficient;

data.get_string("name", name);
data.get_values("node_dof_coefficient", node_dof_coefficient);

options.push_back(name);

if (node_dof_coefficient.size() % 3 != 0)
{
output = "Failed! node_dof_coefficient must be 3 numbers per node!\n";
PRINT_ERROR(output.c_str());
return false;
}

for (size_t i = 0; i < int(node_dof_coefficient.size()/3); i++)
{
options2.push_back({node_dof_coefficient[i*3+0],node_dof_coefficient[i*3+1],node_dof_coefficient[i*3+2]});
}

if (!ccx_iface.create_constraint("EQUATION",options,options2))
{
output = "Failed!\n";
PRINT_ERROR(output.c_str());
}
options.clear();

return true;
}
21 changes: 21 additions & 0 deletions src/Commands/ccxConstraintEquationCreateCommand.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef CCXCONSTRAINTEQUATIONCREATECOMMAND_HPP
#define CCXCONSTRAINTEQUATIONCREATECOMMAND_HPP

#include "CubitCommandInterface.hpp"

/*!
* \brief The Constraint create command lets you create your desired constraints
*/
class ccxConstraintEquationCreateCommand : public CubitCommand
{
public:
ccxConstraintEquationCreateCommand();
~ccxConstraintEquationCreateCommand();

std::vector<std::string> get_syntax();
std::vector<std::string> get_syntax_help();
std::vector<std::string> get_help();
bool execute(CubitCommandData &data);
};

#endif // CCXCONSTRAINTEQUATIONCREATECOMMAND_HPP
88 changes: 88 additions & 0 deletions src/Commands/ccxConstraintEquationModifyCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "ccxConstraintEquationModifyCommand.hpp"
#include "CubitInterface.hpp"
#include "CubitMessage.hpp"
#include "CalculiXCoreInterface.hpp"

ccxConstraintEquationModifyCommand::ccxConstraintEquationModifyCommand()
{}

ccxConstraintEquationModifyCommand::~ccxConstraintEquationModifyCommand()
{}

std::vector<std::string> ccxConstraintEquationModifyCommand::get_syntax()
{
std::vector<std::string> syntax_list;

std::string syntax = "ccx ";
syntax.append("modify constraint equation <value:label='constraint id',help='<constraint id>'> ");
syntax.append("[name <string:type='unquoted', number='1', label='name', help='<name>'>] " );
syntax.append("[node_dof_coefficient <value:label='node_dof_coefficient',help='<node_dof_coefficient>'>...]" );
syntax_list.push_back(syntax);

return syntax_list;
}

std::vector<std::string> ccxConstraintEquationModifyCommand::get_syntax_help()
{
std::vector<std::string> help(5);
help[0] = "ccx modify constraint equation <constraint id> [name <name>] [node_dof_coefficient <node_dof_coefficient>...]";

return help;
}

std::vector<std::string> ccxConstraintEquationModifyCommand::get_help()
{
std::vector<std::string> help;
return help;
}

bool ccxConstraintEquationModifyCommand::execute(CubitCommandData &data)
{

CalculiXCoreInterface ccx_iface;

std::string output;

std::string name;
std::vector<std::string> options;
std::vector<std::vector<double>> options2;
std::vector<int> options_marker;
std::vector<double> node_dof_coefficient;
int constraint_id;

data.get_value("constraint id", constraint_id);

if (!data.get_string("name", name))
{
name = "";
options_marker.push_back(0);
}
else
{
options_marker.push_back(1);
}
options.push_back(name);

data.get_values("node_dof_coefficient", node_dof_coefficient);

if (node_dof_coefficient.size() % 3 != 0)
{
output = "Failed! node_dof_coefficient must be 3 numbers per node!\n";
PRINT_ERROR(output.c_str());
return false;
}

for (size_t i = 0; i < int(node_dof_coefficient.size()/3); i++)
{
options2.push_back({node_dof_coefficient[i*3+0],node_dof_coefficient[i*3+1],node_dof_coefficient[i*3+2]});
}

if (!ccx_iface.modify_constraint("EQUATION",constraint_id,options,options_marker,options2))
{
output = "Failed with ID " + std::to_string(constraint_id) + "!\n";
PRINT_ERROR(output.c_str());
return false;
}

return true;
}
21 changes: 21 additions & 0 deletions src/Commands/ccxConstraintEquationModifyCommand.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef CCXCONSTRAINTEQUATIONMODIFYCOMMAND_HPP
#define CCXCONSTRAINTEQUATIONMODIFYCOMMAND_HPP

#include "CubitCommandInterface.hpp"

/*!
* \brief The Constraint create command lets you modify your desired constraints
*/
class ccxConstraintEquationModifyCommand : public CubitCommand
{
public:
ccxConstraintEquationModifyCommand();
~ccxConstraintEquationModifyCommand();

std::vector<std::string> get_syntax();
std::vector<std::string> get_syntax_help();
std::vector<std::string> get_help();
bool execute(CubitCommandData &data);
};

#endif // CCXCONSTRAINTEQUATIONMODIFYCOMMAND_HPP
2 changes: 1 addition & 1 deletion src/Commands/ccxConstraintRigidBody2CreateCommand.cpp
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ bool ccxConstraintRigidBody2CreateCommand::execute(CubitCommandData &data)
std::string output;

std::vector<std::string> options;
std::vector<double> options2;
std::vector<std::vector<double>> options2;
int ref_vertex_value;
int rot_vertex_value;
std::string ref_vertex;
2 changes: 1 addition & 1 deletion src/Commands/ccxConstraintRigidBodyCreateCommand.cpp
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ bool ccxConstraintRigidBodyCreateCommand::execute(CubitCommandData &data)
std::string output;

std::vector<std::string> options;
std::vector<double> options2;
std::vector<std::vector<double>> options2;
int ref_vertex_value;
int rot_vertex_value;
std::string ref_vertex;
2 changes: 1 addition & 1 deletion src/Commands/ccxConstraintRigidBodyModifyCommand.cpp
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ bool ccxConstraintRigidBodyModifyCommand::execute(CubitCommandData &data)
std::string output;

std::vector<std::string> options;
std::vector<double> options2;
std::vector<std::vector<double>> options2;
std::vector<int> options_marker;
int ref_vertex_value;
int rot_vertex_value;
2 changes: 1 addition & 1 deletion src/Commands/ccxConstraintTieCreateCommand.cpp
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ bool ccxConstraintTieCreateCommand::execute(CubitCommandData &data)

std::string name;
std::vector<std::string> options;
std::vector<double> options2;
std::vector<std::vector<double>> options2;
double position_tolerance_value;
std::string position_tolerance;
int master_value;
2 changes: 1 addition & 1 deletion src/Commands/ccxConstraintTieModifyCommand.cpp
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ bool ccxConstraintTieModifyCommand::execute(CubitCommandData &data)

std::string name;
std::vector<std::string> options;
std::vector<double> options2;
std::vector<std::vector<double>> options2;
std::vector<int> options_marker;
double position_tolerance_value;
std::string position_tolerance;
20 changes: 17 additions & 3 deletions src/Core/CalculiXCore.cpp
Original file line number Diff line number Diff line change
@@ -3601,12 +3601,12 @@ bool CalculiXCore::delete_section(int section_id)
return sections->delete_section(section_id);
}

bool CalculiXCore::create_constraint(std::string constraint_type, std::vector<std::string> options,std::vector<double> options2)
bool CalculiXCore::create_constraint(std::string constraint_type, std::vector<std::string> options,std::vector<std::vector<double>> options2)
{
return constraints->create_constraint(constraint_type, options,options2);
}

bool CalculiXCore::modify_constraint(std::string constraint_type,int constraint_id, std::vector<std::string> options, std::vector<int> options_marker,std::vector<double> options2)
bool CalculiXCore::modify_constraint(std::string constraint_type,int constraint_id, std::vector<std::string> options, std::vector<int> options_marker,std::vector<std::vector<double>> options2)
{
return constraints->modify_constraint(constraint_type, constraint_id, options, options_marker,options2);
}
@@ -3619,7 +3619,7 @@ bool CalculiXCore::delete_constraint(int constraint_id)
bool CalculiXCore::create_constraint_tie_from_cubitcontactpair(std::string name, std::string position_tolerance) // create constraint tie from cubit contact pairs
{
std::vector<std::string> options;
std::vector<double> options2;
std::vector<std::vector<double>> options2;

std::vector<int> contact_ids;
contact_ids = CubitInterface::get_bc_id_list(CI_BCTYPE_CONTACT_PAIR);
@@ -4945,6 +4945,7 @@ std::vector<std::vector<std::string>> CalculiXCore::get_entities(std::string ent
std::vector<std::vector<std::string>> entities;
int data_id = -1;
int sub_data_id = -1;
std::vector<int> sub_data_ids;

if (entity=="block")
{
@@ -5039,6 +5040,14 @@ std::vector<std::vector<std::string>> CalculiXCore::get_entities(std::string ent
sub_data_id = constraints->get_tie_constraint_data_id_from_tie_constraint_id(constraints->constraints_data[data_id][2]);
entities.push_back({"sideset",constraints->tie_constraint_data[sub_data_id][2]});
entities.push_back({"sideset",constraints->tie_constraint_data[sub_data_id][3]});
}else if (constraints->constraints_data[data_id][1] == 3)
{
//sub_data_id = constraints->get_equation_constraint_data_id_from_equation_constraint_id(constraints->constraints_data[data_id][2]);
sub_data_ids = constraints->get_equation_data_ids_from_equation_constraint_id(constraints->constraints_data[data_id][2]);
for (size_t i = 0; i < sub_data_ids.size(); i++)
{
entities.push_back({"node",std::to_string(int(constraints->equation_data[sub_data_ids[i]][1]))});
}
}
}
}else if (entity=="surfaceinteraction")
@@ -8327,6 +8336,11 @@ std::vector<std::vector<std::string>> CalculiXCore::get_constraints_tree_data()
sub_constraint_data_id = constraints->get_tie_constraint_data_id_from_tie_constraint_id(constraints->constraints_data[i][2]);

constraint_name = "TIE (" + constraints->tie_constraint_data[sub_constraint_data_id][1] + ")";
} else if (constraints->constraints_data[i][1] == 3)
{
sub_constraint_data_id = constraints->get_equation_constraint_data_id_from_equation_constraint_id(constraints->constraints_data[i][2]);

constraint_name = "EQUATION (" + constraints->equation_constraint_data[sub_constraint_data_id][1] + ")";
}

constraints_tree_data_set.push_back(std::to_string(constraints->constraints_data[i][0])); //constraint_id
4 changes: 2 additions & 2 deletions src/Core/CalculiXCore.hpp
Original file line number Diff line number Diff line change
@@ -146,8 +146,8 @@ class CalculiXCore
bool create_section(std::string section_type,int block_id, int material_id, std::vector<std::string> options); // adds a new section
bool modify_section(std::string section_type,int section_id, std::vector<std::string> options, std::vector<int> options_marker); // modify a section
bool delete_section(int section_id); // adds a new section
bool create_constraint(std::string constraint_type, std::vector<std::string> options,std::vector<double> options2); // adds a new constraint
bool modify_constraint(std::string constraint_type,int constraint_id, std::vector<std::string> options, std::vector<int> options_marker,std::vector<double> options2); // modify a constraint
bool create_constraint(std::string constraint_type, std::vector<std::string> options,std::vector<std::vector<double>> options2); // adds a new constraint
bool modify_constraint(std::string constraint_type,int constraint_id, std::vector<std::string> options, std::vector<int> options_marker,std::vector<std::vector<double>> options2); // modify a constraint
bool delete_constraint(int constraint_id); // adds a new constraint
bool create_constraint_tie_from_cubitcontactpair(std::string name, std::string position_tolerance); // create constraint tie from cubit contact pairs
std::vector<int> get_rigidbody_vertex_list(); // get list of rigid body vertices
4 changes: 2 additions & 2 deletions src/Core/CalculiXCoreInterface.cpp
Original file line number Diff line number Diff line change
@@ -375,12 +375,12 @@ bool CalculiXCoreInterface::delete_section(int section_id)
return ccx_core.delete_section(section_id);
}

bool CalculiXCoreInterface::create_constraint(std::string constraint_type, std::vector<std::string> options,std::vector<double> options2)
bool CalculiXCoreInterface::create_constraint(std::string constraint_type, std::vector<std::string> options,std::vector<std::vector<double>> options2)
{
return ccx_core.create_constraint(constraint_type,options, options2);
}

bool CalculiXCoreInterface::modify_constraint(std::string constraint_type,int constraint_id, std::vector<std::string> options, std::vector<int> options_marker,std::vector<double> options2)
bool CalculiXCoreInterface::modify_constraint(std::string constraint_type,int constraint_id, std::vector<std::string> options, std::vector<int> options_marker,std::vector<std::vector<double>> options2)
{
return ccx_core.modify_constraint(constraint_type,constraint_id,options, options_marker,options2);
}
Loading

0 comments on commit 8e3e2d8

Please sign in to comment.