Skip to content

Commit

Permalink
fee2ccx
Browse files Browse the repository at this point in the history
  • Loading branch information
gtheler committed Mar 1, 2025
1 parent ec022f7 commit aaf7c42
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 6 deletions.
9 changes: 3 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ AS_IF([test "x$CFLAGS" = "x-g -O2"], [CFLAGS="-O3 -flto=auto -no-pie"])

######################
# libraries
#AC_CHECK_LIB([rt],[shm_open])
#AC_CHECK_LIB([pthread],[pthread_create])

#AC_SEARCH_LIBS([dlopen],[dl dld],[])
#AC_CHECK_HEADER([dlfcn.h],[],AC_MSG_ERROR([dlfcn.h not found]))

# check for math
AC_SEARCH_LIBS([cos],[m],[],AC_MSG_ERROR([libm not found]))
Expand Down Expand Up @@ -399,7 +394,9 @@ m4_include(auto_links.m4)

#AC_CONFIG_FILES([Makefile src/Makefile src/benchmark/Makefile doc/Makefile])
#AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile])
AC_CONFIG_FILES([Makefile src/Makefile])
#AC_CONFIG_FILES([Makefile src/Makefile])
AC_CONFIG_FILES([Makefile src/Makefile utils/fee2ccx/Makefile])


AS_BOX([Summary of dependencies])
AS_ECHO( [" GNU Scientific Library ${gsl_version}"])
Expand Down
5 changes: 5 additions & 0 deletions utils/fee2ccx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
configure
configure~
config.log
*.o
fee2ccx
103 changes: 103 additions & 0 deletions utils/fee2ccx/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
if INCLUDE_SLEPC
include $(SLEPC_DIR)/lib/slepc/conf/slepc_variables
endif
if INCLUDE_PETSC
include $(PETSC_DIR)/lib/petsc/conf/variables
endif

# include $(top_srcdir)/aminclude_static.am
AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = $(ACLOCAL_FLAGS)

bin_PROGRAMS = fee2ccx
fee2ccx_CFLAGS = -I../../src $(SLEPC_CC_INCLUDES) $(PETSC_CC_INCLUDES) $(CC_INCLUDES) $(DOWNLOADED_GSL_INCLUDES) $(all_includes)
fee2ccx_LDADD = $(SLEPC_LIB) $(PETSC_LIB) $(DOWNLOADED_GSL_LIBS) $(all_libraries)

fee2ccx_SOURCES = fee2ccx.c \
../../src/flow/init.c \
../../src/flow/cleanup.c \
../../src/flow/error.c \
../../src/flow/define.c \
../../src/flow/getptr.c \
../../src/flow/instruction.c \
../../src/flow/abort.c \
../../src/flow/conditional.c \
../../src/parser/parser.c \
../../src/parser/auxiliary.c \
../../src/math/alias.c \
../../src/math/expressions.c \
../../src/math/function.c \
../../src/math/vector.c \
../../src/math/matrix.c \
../../src/math/fit.c \
../../src/math/assignment.c \
../../src/math/solve.c \
../../src/io/file.c \
../../src/io/print.c \
../../src/io/printf.c \
../../src/version.c \
../../src/mesh/interpolate.c \
../../src/mesh/init.c \
../../src/mesh/calculix.c \
../../src/mesh/geometry.c \
../../src/mesh/mesh.c \
../../src/mesh/cell.c \
../../src/mesh/element.c \
../../src/mesh/neighbors.c \
../../src/mesh/gmsh.c \
../../src/mesh/write.c \
../../src/mesh/physical_group.c \
../../src/mesh/boundary_condition.c \
../../src/mesh/material.c \
../../src/mesh/extrema.c \
../../src/mesh/integrate.c \
../../src/mesh/elements/hexa20.c \
../../src/mesh/elements/hexa27.c \
../../src/mesh/elements/hexa8.c \
../../src/mesh/elements/line2.c \
../../src/mesh/elements/line3.c \
../../src/mesh/elements/point.c \
../../src/mesh/elements/prism15.c \
../../src/mesh/elements/prism6.c \
../../src/mesh/elements/quad4.c \
../../src/mesh/elements/quad8.c \
../../src/mesh/elements/quad9.c \
../../src/mesh/elements/tet10.c \
../../src/mesh/elements/tet4.c \
../../src/mesh/elements/triang3.c \
../../src/mesh/elements/triang6.c \
../../src/mesh/vtk.c \
../../src/math/builtin_functions.c \
../../src/math/builtin_functionals.c \
../../src/math/builtin_vectorfunctions.c \
../../src/math/dae.c \
../../src/contrib/kdtree.c \
../../src/pdes/fem.c \
../../src/pdes/reaction.c \
../../src/pdes/dump.c \
../../src/pdes/init.c \
../../src/pdes/solve.c \
../../src/pdes/gradient.c \
../../src/pdes/dirichlet.c \
../../src/pdes/build.c \
../../src/pdes/blas.c \
../../src/pdes/petsc_ksp.c \
../../src/pdes/distribution.c \
../../src/pdes/mechanical/bc.c \
../../src/pdes/mechanical/bulk.c \
../../src/pdes/mechanical/elastic-isotropic.c \
../../src/pdes/mechanical/elastic-orthotropic.c \
../../src/pdes/mechanical/elastic-plane-strain.c \
../../src/pdes/mechanical/elastic-plane-stress.c \
../../src/pdes/mechanical/expansion-isotropic.c \
../../src/pdes/mechanical/expansion-orthotropic.c \
../../src/pdes/mechanical/init.c \
../../src/pdes/mechanical/linearize.c \
../../src/pdes/mechanical/parser.c \
../../src/pdes/mechanical/post.c \
../../src/pdes/mechanical/stress.c \
../../src/flow/step.c \
./parsepde.c



10 changes: 10 additions & 0 deletions utils/fee2ccx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# FeenoX to CalculiX input file converter


## TODOs

* command-line options to include or not the original input
* do not solve (nor write outputs) in the original problem
* do not repeat nodes in BCs
* multi-volume material properties
* non-uniform material properties
30 changes: 30 additions & 0 deletions utils/fee2ccx/configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
m4_include([../../version.m4])
AC_INIT([fee2ccx],feenoxversion)

AM_INIT_AUTOMAKE([foreign])
AC_PROG_CC

AC_CHECK_FILE([../../src/parser/parser.c],,AC_MSG_ERROR([dlfcn.h not found]))

# check for math
AC_SEARCH_LIBS([cos],[m],[],AC_MSG_ERROR([libm not found]))
AC_CHECK_HEADER([math.h],[],AC_MSG_ERROR([math.h not found]))

# check for sysconf() for page size
AC_CHECK_FUNCS([sysconf],[],[])

# check for clock_gettime() for unix time
AC_CHECK_FUNCS([clock_gettime],[],[])

# check for getrusage() for memory and cpu time
AC_CHECK_FUNCS([getrusage],[],[])

# check for asprintf
AC_CHECK_FUNCS([asprintf],[],[])

# check for feenox_likely
AX_GCC_BUILTIN(__builtin_expect)


AC_CONFIG_FILES([Makefile])
AC_OUTPUT
172 changes: 172 additions & 0 deletions utils/fee2ccx/fee2ccx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*------------ -------------- -------- --- ----- --- -- - -
* FeenoX-to-CalculiX input file converter
*
* Copyright (C) 2025 Jeremy Theler
*
* This file is part of FeenoX.
*
* FeenoX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FeenoX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FeenoX. If not, see <http://www.gnu.org/licenses/>.
*------------------- ------------ ---- -------- -- - - -
*/
#include "feenox.h"
feenox_t feenox;

#include <stdlib.h>
#include <libgen.h>

int main(int argc, char **argv) {

if (argc == 1) {
printf("usage: %s feenox-input.fee\n", argv[0]);
return 0;
}

// TODO: check this ir run in serial
// TODO: particular argc && argv
// e.g. --version
// --do-not-include-original-input
if (feenox_initialize(argc, argv) != FEENOX_OK) {
feenox_pop_errors();
exit(EXIT_FAILURE);
}

if (feenox_step(feenox.instructions, NULL) != FEENOX_OK) {
feenox_pop_errors();
exit(EXIT_FAILURE);
}

mesh_t *mesh = feenox.mesh.mesh_main;
feenox_instruction_mesh_read(mesh);

printf("*NODE\n");
for (size_t j = 0; j < mesh->n_nodes; j++) {
printf("%ld, %g, %g, %g\n", mesh->node[j].tag, mesh->node[j].x[0], mesh->node[j].x[1], mesh->node[j].x[2]);
}
printf("\n");

// TODO: other elements (think how)
// TODO: if all the volumes have the same property we can do
// *Element, TYPE=C3D4, ELSET=volumes
printf("*ELEMENT, TYPE=C3D4, ELSET=tet4\n");
for (size_t i = 0; i < mesh->n_elements; i++) {
if (mesh->element[i].type == &(feenox.mesh.element_types[ELEMENT_TYPE_TETRAHEDRON4])) {
printf("%ld", mesh->element[i].tag);
// the nodes
for (unsigned int j = 0; j < mesh->element[i].type->nodes; j++) {
printf(", %ld", mesh->element[i].node[j]->tag);
}
printf("\n");
}
}
printf("\n");

printf("*ELSET, ELSET=bulk\n");
printf("tet4\n");
printf("\n");

/*
printf("*ELSET, ELSET=bulk\n");
int first = 1;
int n = 0;
for (size_t i = 0; i < mesh->n_elements; i++) {
if (mesh->element[i].type->dim == 3 && strcmp(mesh->element[i].physical_group->name, "bulk") == 0) {
if (first == 0) {
printf(", ");
}
printf("%ld", mesh->element[i].tag);
first = 0;
if (++n == 16) {
printf("\n");
n = 0;
first = 1;
}
}
}
printf("\n");
printf("\n");
*/

printf("*NSET, NSET=left\n");
for (size_t i = 0; i < mesh->n_elements; i++) {
element_t *e = &mesh->element[i];
if (e->physical_group != NULL && strcmp(e->physical_group->name, "left") == 0) {
for (unsigned int j = 0; j < e->type->nodes; j++) {
if (j != 0) {
printf(", ");
}
printf("%ld", e->node[j]->tag);
}
printf("\n");
}
}
printf("\n");

printf("*MATERIAL, NAME=bulk\n");
printf("*ELASTIC\n");
printf("210e9, 0.3\n");
printf("\n");
printf("*SOLID SECTION, ELSET=bulk, MATERIAL=bulk");
printf("\n");

printf("*BOUNDARY\n");
printf("left, 1, 3, 0\n");
printf("\n");

printf("*STEP\n");
printf("\n");
printf("*EL FILE # Commands responsible for saving results\n");
printf("E, S\n");
printf("*NODE FILE\n");
printf("U\n");
printf("\n");

printf("*CLOAD\n");

int dofs = feenox.pde.dofs;

for (size_t i = 0; i < mesh->n_elements; i++) {
element_t *e = &mesh->element[i];
// TODO: compare pointers not strings
if (e->physical_group != NULL && strcmp(e->physical_group->name, "right") == 0) {

// compute the indices of the DOFs to ensamble
PetscInt *l = feenox_fem_compute_dof_indices(e, dofs);
PetscInt size = dofs * e->type->nodes;
PetscScalar values[size];
petsc_call(VecGetValues(feenox.pde.b, size, l, values));

for (unsigned int j = 0; j < e->type->nodes; j++) {
for (unsigned int g = 0; g < dofs; g++) {
if (values[j*dofs + g] != 0) {
printf("%ld, %d, %g\n", e->node[j]->tag, g+1, values[j*dofs + g]);
}
}
}
}
}
printf("\n");

printf("*STATIC\n");
printf("\n");
printf("*END STEP\n");




feenox_finalize();

return 0;
}
13 changes: 13 additions & 0 deletions utils/fee2ccx/parsepde.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "feenox.h"

int feenox_pde_parse_problem_type(const char *token) {

if (strcasecmp(token, "mechanical") == 0) {
feenox.pde.parse_problem = feenox_problem_parse_problem_mechanical;
} else {
feenox_push_error_message("unknown problem type '%s'", token);
return FEENOX_ERROR;
}

return FEENOX_OK;
}

0 comments on commit aaf7c42

Please sign in to comment.